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 /* Check that printing "mpa" and parsing the output results
124 * in the same expression.
126 static isl_stat
check_reparse_mpa(isl_ctx
*ctx
,
127 __isl_take isl_multi_pw_aff
*mpa
)
131 isl_multi_pw_aff
*mpa2
;
133 str
= isl_multi_pw_aff_to_str(mpa
);
134 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
136 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
137 isl_multi_pw_aff_free(mpa
);
138 isl_multi_pw_aff_free(mpa2
);
140 return isl_stat_error
;
142 isl_die(ctx
, isl_error_unknown
,
143 "parsed function not equal to original",
144 return isl_stat_error
);
149 /* String descriptions of multi piecewise affine expressions
150 * that are used for testing printing and parsing.
152 const char *parse_multi_mpa_tests
[] = {
153 "{ A[x, y] -> [] : x + y >= 0 }",
154 "{ A[x, y] -> B[] : x + y >= 0 }",
155 "{ A[x, y] -> [x] : x + y >= 0 }",
156 "[N] -> { A[x, y] -> [x] : x + y <= N }",
157 "{ A[x, y] -> [x, y] : x + y >= 0 }",
158 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
159 "[N] -> { [] : N >= 0 }",
160 "[N] -> { [] : N >= 0 }",
161 "[N] -> { [N] : N >= 0 }",
162 "[N] -> { [N, N + 1] : N >= 0 }",
163 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
166 /* Test parsing of multi piecewise affine expressions by printing
167 * the expressions and checking that parsing the output results
168 * in the same expression.
169 * Do this for a couple of manually constructed expressions and
170 * a set of expressions parsed from strings.
172 static int test_parse_mpa(isl_ctx
*ctx
)
177 isl_multi_pw_aff
*mpa
;
180 space
= isl_space_set_alloc(ctx
, 0, 0);
181 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
182 mpa
= isl_multi_pw_aff_zero(space
);
183 r
= check_reparse_mpa(ctx
, mpa
);
187 space
= isl_space_set_alloc(ctx
, 1, 0);
188 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
189 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
190 dom
= isl_set_universe(isl_space_params(isl_space_copy(space
)));
191 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
192 mpa
= isl_multi_pw_aff_zero(space
);
193 mpa
= isl_multi_pw_aff_intersect_domain(mpa
, dom
);
194 r
= check_reparse_mpa(ctx
, mpa
);
198 for (i
= 0; i
< ARRAY_SIZE(parse_multi_mpa_tests
); ++i
) {
201 str
= parse_multi_mpa_tests
[i
];
202 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
203 r
= check_reparse_mpa(ctx
, mpa
);
211 /* Check that printing "mupa" and parsing the output results
212 * in the same expression.
214 static isl_stat
check_reparse_mupa(isl_ctx
*ctx
,
215 __isl_take isl_multi_union_pw_aff
*mupa
)
219 isl_multi_union_pw_aff
*mupa2
;
221 str
= isl_multi_union_pw_aff_to_str(mupa
);
222 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
224 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
225 isl_multi_union_pw_aff_free(mupa
);
226 isl_multi_union_pw_aff_free(mupa2
);
228 return isl_stat_error
;
230 isl_die(ctx
, isl_error_unknown
,
231 "parsed function not equal to original",
232 return isl_stat_error
);
237 /* String descriptions of multi union piecewise affine expressions
238 * that are used for testing printing and parsing.
240 const char *parse_multi_mupa_tests
[] = {
244 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
246 "[N] -> (A[] : { })",
247 "[N] -> (A[] : { : N >= 0 })",
248 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
249 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
250 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
251 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
252 "{ S[x] : x > 0; T[y] : y >= 0 })",
255 /* Test parsing of multi union piecewise affine expressions by printing
256 * the expressions and checking that parsing the output results
257 * in the same expression.
258 * Do this for a couple of manually constructed expressions and
259 * a set of expressions parsed from strings.
261 static int test_parse_mupa(isl_ctx
*ctx
)
265 isl_multi_union_pw_aff
*mupa
;
270 space
= isl_space_set_alloc(ctx
, 0, 0);
271 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
272 mupa
= isl_multi_union_pw_aff_zero(space
);
273 r
= check_reparse_mupa(ctx
, mupa
);
277 space
= isl_space_set_alloc(ctx
, 1, 0);
278 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
279 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
280 dom
= isl_set_universe(space
);
281 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
282 uset
= isl_union_set_from_set(dom
);
283 space
= isl_space_set_alloc(ctx
, 1, 0);
284 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
285 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "B");
286 mupa
= isl_multi_union_pw_aff_zero(space
);
287 mupa
= isl_multi_union_pw_aff_intersect_domain(mupa
, uset
);
288 r
= check_reparse_mupa(ctx
, mupa
);
292 for (i
= 0; i
< ARRAY_SIZE(parse_multi_mupa_tests
); ++i
) {
295 str
= parse_multi_mupa_tests
[i
];
296 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
297 r
= check_reparse_mupa(ctx
, mupa
);
305 /* Test parsing of multi expressions.
307 static int test_parse_multi(isl_ctx
*ctx
)
309 if (test_parse_mpa(ctx
) < 0)
311 if (test_parse_mupa(ctx
) < 0)
317 /* Pairs of binary relation representations that should represent
318 * the same binary relations.
323 } parse_map_equal_tests
[] = {
324 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
325 "{ [x, y] : 2y >= 6 - x }" },
326 { "{ [x,y] : x <= min(y, 2*y+3) }",
327 "{ [x,y] : x <= y, 2*y + 3 }" },
328 { "{ [x,y] : x >= min(y, 2*y+3) }",
329 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
330 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
331 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
332 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
333 "{ [i,j] -> [min(i,j)] }" },
334 { "{ [i,j] : i != j }",
335 "{ [i,j] : i < j or i > j }" },
336 { "{ [i,j] : (i+1)*2 >= j }",
337 "{ [i, j] : j <= 2 + 2i }" },
338 { "{ [i] -> [i > 0 ? 4 : 5] }",
339 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
340 { "[N=2,M] -> { [i=[(M+N)/4]] }",
341 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
342 { "{ [x] : x >= 0 }",
343 "{ [x] : x-0 >= 0 }" },
344 { "{ [i] : ((i > 10)) }",
345 "{ [i] : i >= 11 }" },
347 "{ [i] -> [0 * i] }" },
348 { "{ [a] -> [b] : (not false) }",
349 "{ [a] -> [b] : true }" },
350 { "{ [i] : i/2 <= 5 }",
351 "{ [i] : i <= 10 }" },
352 { "{Sym=[n] [i] : i <= n }",
353 "[n] -> { [i] : i <= n }" },
356 { "{ [i] : 2*floor(i/2) = i }",
357 "{ [i] : exists a : i = 2 a }" },
358 { "{ [a] -> [b] : a = 5 implies b = 5 }",
359 "{ [a] -> [b] : a != 5 or b = 5 }" },
360 { "{ [a] -> [a - 1 : a > 0] }",
361 "{ [a] -> [a - 1] : a > 0 }" },
362 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
363 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
364 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
365 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
366 { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
367 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
368 { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
369 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
370 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
371 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
372 { "{ [a,b] -> [i,j] : a,b << i,j }",
373 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
374 { "{ [a,b] -> [i,j] : a,b <<= i,j }",
375 "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" },
376 { "{ [a,b] -> [i,j] : a,b >> i,j }",
377 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
378 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
379 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
380 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
381 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
382 "8c < n - 32a and i < n and c >= 0 and "
383 "c <= 3 and c >= -4a) }",
384 "{ [n] -> [i] : 0 <= i < n }" },
385 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
386 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
387 "{ [x] -> [] : 0 <= x <= 15 }" },
388 { "{ [x] -> [x] : }",
392 int test_parse(struct isl_ctx
*ctx
)
396 const char *str
, *str2
;
398 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
400 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
402 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
404 if (test_parse_multi(ctx
) < 0)
407 str
= "{ [i] -> [-i] }";
408 map
= isl_map_read_from_str(ctx
, str
);
412 str
= "{ A[i] -> L[([i/3])] }";
413 map
= isl_map_read_from_str(ctx
, str
);
417 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
418 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
419 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
421 for (i
= 0; i
< ARRAY_SIZE(parse_map_equal_tests
); ++i
) {
422 str
= parse_map_equal_tests
[i
].map1
;
423 str2
= parse_map_equal_tests
[i
].map2
;
424 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
428 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
429 map
= isl_map_read_from_str(ctx
, str
);
430 str
= "{ [new, old] -> [o0, o1] : "
431 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
432 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
433 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
434 map2
= isl_map_read_from_str(ctx
, str
);
435 assert(isl_map_is_equal(map
, map2
));
439 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
440 map
= isl_map_read_from_str(ctx
, str
);
441 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
442 map2
= isl_map_read_from_str(ctx
, str
);
443 assert(isl_map_is_equal(map
, map2
));
447 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
448 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
449 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
450 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
451 test_parse_pwaff(ctx
, "{ [] -> [(100)] }");
456 static int test_read(isl_ctx
*ctx
)
460 isl_basic_set
*bset1
, *bset2
;
461 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
464 filename
= get_filename(ctx
, "set", "omega");
466 input
= fopen(filename
, "r");
469 bset1
= isl_basic_set_read_from_file(ctx
, input
);
470 bset2
= isl_basic_set_read_from_str(ctx
, str
);
472 equal
= isl_basic_set_is_equal(bset1
, bset2
);
474 isl_basic_set_free(bset1
);
475 isl_basic_set_free(bset2
);
483 isl_die(ctx
, isl_error_unknown
,
484 "read sets not equal", return -1);
489 static int test_bounded(isl_ctx
*ctx
)
494 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
495 bounded
= isl_set_is_bounded(set
);
501 isl_die(ctx
, isl_error_unknown
,
502 "set not considered bounded", return -1);
504 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
505 bounded
= isl_set_is_bounded(set
);
512 isl_die(ctx
, isl_error_unknown
,
513 "set considered bounded", return -1);
515 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
516 bounded
= isl_set_is_bounded(set
);
522 isl_die(ctx
, isl_error_unknown
,
523 "set considered bounded", return -1);
528 /* Construct the basic set { [i] : 5 <= i <= N } */
529 static int test_construction_1(isl_ctx
*ctx
)
536 dim
= isl_space_set_alloc(ctx
, 1, 1);
537 bset
= isl_basic_set_universe(isl_space_copy(dim
));
538 ls
= isl_local_space_from_space(dim
);
540 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
541 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
542 c
= isl_constraint_set_coefficient_si(c
, isl_dim_param
, 0, 1);
543 bset
= isl_basic_set_add_constraint(bset
, c
);
545 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
546 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
547 c
= isl_constraint_set_constant_si(c
, -5);
548 bset
= isl_basic_set_add_constraint(bset
, c
);
550 isl_local_space_free(ls
);
551 isl_basic_set_free(bset
);
556 /* Construct the basic set { [x] : -100 <= x <= 100 }
557 * using isl_basic_set_{lower,upper}_bound_val and
558 * check that it is equal the same basic set parsed from a string.
560 static int test_construction_2(isl_ctx
*ctx
)
565 isl_basic_set
*bset1
, *bset2
;
567 v
= isl_val_int_from_si(ctx
, 100);
568 space
= isl_space_set_alloc(ctx
, 0, 1);
569 bset1
= isl_basic_set_universe(space
);
570 bset1
= isl_basic_set_upper_bound_val(bset1
, isl_dim_set
, 0,
572 bset1
= isl_basic_set_lower_bound_val(bset1
, isl_dim_set
, 0,
574 bset2
= isl_basic_set_read_from_str(ctx
, "{ [x] : -100 <= x <= 100 }");
575 equal
= isl_basic_set_is_equal(bset1
, bset2
);
576 isl_basic_set_free(bset1
);
577 isl_basic_set_free(bset2
);
582 isl_die(ctx
, isl_error_unknown
,
583 "failed construction", return -1);
588 /* Basic tests for constructing basic sets.
590 static int test_construction(isl_ctx
*ctx
)
592 if (test_construction_1(ctx
) < 0)
594 if (test_construction_2(ctx
) < 0)
599 static int test_dim(isl_ctx
*ctx
)
602 isl_map
*map1
, *map2
;
605 map1
= isl_map_read_from_str(ctx
,
606 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
607 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
608 map2
= isl_map_read_from_str(ctx
,
609 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
610 equal
= isl_map_is_equal(map1
, map2
);
613 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
614 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
615 if (equal
>= 0 && equal
)
616 equal
= isl_map_is_equal(map1
, map2
);
624 isl_die(ctx
, isl_error_unknown
,
625 "unexpected result", return -1);
627 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
628 map1
= isl_map_read_from_str(ctx
, str
);
629 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
630 map2
= isl_map_read_from_str(ctx
, str
);
631 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
632 equal
= isl_map_is_equal(map1
, map2
);
639 isl_die(ctx
, isl_error_unknown
,
640 "unexpected result", return -1);
645 /* Check that "val" is equal to the value described by "str".
646 * If "str" is "NaN", then check for a NaN value explicitly.
648 static isl_stat
val_check_equal(__isl_keep isl_val
*val
, const char *str
)
655 return isl_stat_error
;
657 ctx
= isl_val_get_ctx(val
);
658 res
= isl_val_read_from_str(ctx
, str
);
659 is_nan
= isl_val_is_nan(res
);
663 ok
= isl_val_is_nan(val
);
665 ok
= isl_val_eq(val
, res
);
668 return isl_stat_error
;
670 isl_die(ctx
, isl_error_unknown
,
671 "unexpected result", return isl_stat_error
);
676 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
680 { &isl_val_neg
, "0", "0" },
681 { &isl_val_abs
, "0", "0" },
682 { &isl_val_2exp
, "0", "1" },
683 { &isl_val_floor
, "0", "0" },
684 { &isl_val_ceil
, "0", "0" },
685 { &isl_val_neg
, "1", "-1" },
686 { &isl_val_neg
, "-1", "1" },
687 { &isl_val_neg
, "1/2", "-1/2" },
688 { &isl_val_neg
, "-1/2", "1/2" },
689 { &isl_val_neg
, "infty", "-infty" },
690 { &isl_val_neg
, "-infty", "infty" },
691 { &isl_val_neg
, "NaN", "NaN" },
692 { &isl_val_abs
, "1", "1" },
693 { &isl_val_abs
, "-1", "1" },
694 { &isl_val_abs
, "1/2", "1/2" },
695 { &isl_val_abs
, "-1/2", "1/2" },
696 { &isl_val_abs
, "infty", "infty" },
697 { &isl_val_abs
, "-infty", "infty" },
698 { &isl_val_abs
, "NaN", "NaN" },
699 { &isl_val_floor
, "1", "1" },
700 { &isl_val_floor
, "-1", "-1" },
701 { &isl_val_floor
, "1/2", "0" },
702 { &isl_val_floor
, "-1/2", "-1" },
703 { &isl_val_floor
, "infty", "infty" },
704 { &isl_val_floor
, "-infty", "-infty" },
705 { &isl_val_floor
, "NaN", "NaN" },
706 { &isl_val_ceil
, "1", "1" },
707 { &isl_val_ceil
, "-1", "-1" },
708 { &isl_val_ceil
, "1/2", "1" },
709 { &isl_val_ceil
, "-1/2", "0" },
710 { &isl_val_ceil
, "infty", "infty" },
711 { &isl_val_ceil
, "-infty", "-infty" },
712 { &isl_val_ceil
, "NaN", "NaN" },
713 { &isl_val_2exp
, "-3", "1/8" },
714 { &isl_val_2exp
, "-1", "1/2" },
715 { &isl_val_2exp
, "1", "2" },
716 { &isl_val_2exp
, "2", "4" },
717 { &isl_val_2exp
, "3", "8" },
718 { &isl_val_inv
, "1", "1" },
719 { &isl_val_inv
, "2", "1/2" },
720 { &isl_val_inv
, "1/2", "2" },
721 { &isl_val_inv
, "-2", "-1/2" },
722 { &isl_val_inv
, "-1/2", "-2" },
723 { &isl_val_inv
, "0", "NaN" },
724 { &isl_val_inv
, "NaN", "NaN" },
725 { &isl_val_inv
, "infty", "0" },
726 { &isl_val_inv
, "-infty", "0" },
729 /* Perform some basic tests of unary operations on isl_val objects.
731 static int test_un_val(isl_ctx
*ctx
)
735 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
737 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
740 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
741 fn
= val_un_tests
[i
].op
;
743 r
= val_check_equal(v
, val_un_tests
[i
].res
);
753 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
754 __isl_take isl_val
*v2
);
756 ['+'] = { &isl_val_add
},
757 ['-'] = { &isl_val_sub
},
758 ['*'] = { &isl_val_mul
},
759 ['/'] = { &isl_val_div
},
760 ['g'] = { &isl_val_gcd
},
761 ['m'] = { &isl_val_min
},
762 ['M'] = { &isl_val_max
},
770 } val_bin_tests
[] = {
771 { "0", '+', "0", "0" },
772 { "1", '+', "0", "1" },
773 { "1", '+', "1", "2" },
774 { "1", '-', "1", "0" },
775 { "1", '*', "1", "1" },
776 { "1", '/', "1", "1" },
777 { "2", '*', "3", "6" },
778 { "2", '*', "1/2", "1" },
779 { "2", '*', "1/3", "2/3" },
780 { "2/3", '*', "3/5", "2/5" },
781 { "2/3", '*', "7/5", "14/15" },
782 { "2", '/', "1/2", "4" },
783 { "-2", '/', "-1/2", "4" },
784 { "-2", '/', "1/2", "-4" },
785 { "2", '/', "-1/2", "-4" },
786 { "2", '/', "2", "1" },
787 { "2", '/', "3", "2/3" },
788 { "2/3", '/', "5/3", "2/5" },
789 { "2/3", '/', "5/7", "14/15" },
790 { "0", '/', "0", "NaN" },
791 { "42", '/', "0", "NaN" },
792 { "-42", '/', "0", "NaN" },
793 { "infty", '/', "0", "NaN" },
794 { "-infty", '/', "0", "NaN" },
795 { "NaN", '/', "0", "NaN" },
796 { "0", '/', "NaN", "NaN" },
797 { "42", '/', "NaN", "NaN" },
798 { "-42", '/', "NaN", "NaN" },
799 { "infty", '/', "NaN", "NaN" },
800 { "-infty", '/', "NaN", "NaN" },
801 { "NaN", '/', "NaN", "NaN" },
802 { "0", '/', "infty", "0" },
803 { "42", '/', "infty", "0" },
804 { "-42", '/', "infty", "0" },
805 { "infty", '/', "infty", "NaN" },
806 { "-infty", '/', "infty", "NaN" },
807 { "NaN", '/', "infty", "NaN" },
808 { "0", '/', "-infty", "0" },
809 { "42", '/', "-infty", "0" },
810 { "-42", '/', "-infty", "0" },
811 { "infty", '/', "-infty", "NaN" },
812 { "-infty", '/', "-infty", "NaN" },
813 { "NaN", '/', "-infty", "NaN" },
814 { "1", '-', "1/3", "2/3" },
815 { "1/3", '+', "1/2", "5/6" },
816 { "1/2", '+', "1/2", "1" },
817 { "3/4", '-', "1/4", "1/2" },
818 { "1/2", '-', "1/3", "1/6" },
819 { "infty", '+', "42", "infty" },
820 { "infty", '+', "infty", "infty" },
821 { "42", '+', "infty", "infty" },
822 { "infty", '-', "infty", "NaN" },
823 { "infty", '*', "infty", "infty" },
824 { "infty", '*', "-infty", "-infty" },
825 { "-infty", '*', "infty", "-infty" },
826 { "-infty", '*', "-infty", "infty" },
827 { "0", '*', "infty", "NaN" },
828 { "1", '*', "infty", "infty" },
829 { "infty", '*', "0", "NaN" },
830 { "infty", '*', "42", "infty" },
831 { "42", '-', "infty", "-infty" },
832 { "infty", '+', "-infty", "NaN" },
833 { "4", 'g', "6", "2" },
834 { "5", 'g', "6", "1" },
835 { "42", 'm', "3", "3" },
836 { "42", 'M', "3", "42" },
837 { "3", 'm', "42", "3" },
838 { "3", 'M', "42", "42" },
839 { "42", 'm', "infty", "42" },
840 { "42", 'M', "infty", "infty" },
841 { "42", 'm', "-infty", "-infty" },
842 { "42", 'M', "-infty", "42" },
843 { "42", 'm', "NaN", "NaN" },
844 { "42", 'M', "NaN", "NaN" },
845 { "infty", 'm', "-infty", "-infty" },
846 { "infty", 'M', "-infty", "infty" },
849 /* Perform some basic tests of binary operations on isl_val objects.
851 static int test_bin_val(isl_ctx
*ctx
)
854 isl_val
*v1
, *v2
, *res
;
855 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
856 __isl_take isl_val
*v2
);
859 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
860 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
861 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
862 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
863 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
865 if (isl_val_is_nan(res
))
866 ok
= isl_val_is_nan(v1
);
868 ok
= isl_val_eq(v1
, res
);
874 isl_die(ctx
, isl_error_unknown
,
875 "unexpected result", return -1);
881 /* Perform some basic tests on isl_val objects.
883 static int test_val(isl_ctx
*ctx
)
885 if (test_un_val(ctx
) < 0)
887 if (test_bin_val(ctx
) < 0)
892 /* Sets described using existentially quantified variables that
893 * can also be described without.
895 static const char *elimination_tests
[] = {
896 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
897 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
898 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
901 /* Check that redundant existentially quantified variables are
904 static int test_elimination(isl_ctx
*ctx
)
910 for (i
= 0; i
< ARRAY_SIZE(elimination_tests
); ++i
) {
911 bset
= isl_basic_set_read_from_str(ctx
, elimination_tests
[i
]);
912 n
= isl_basic_set_dim(bset
, isl_dim_div
);
913 isl_basic_set_free(bset
);
917 isl_die(ctx
, isl_error_unknown
,
918 "expecting no existentials", return -1);
924 static int test_div(isl_ctx
*ctx
)
931 struct isl_basic_set
*bset
;
932 struct isl_constraint
*c
;
935 dim
= isl_space_set_alloc(ctx
, 0, 3);
936 bset
= isl_basic_set_universe(isl_space_copy(dim
));
937 ls
= isl_local_space_from_space(dim
);
939 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
940 c
= isl_constraint_set_constant_si(c
, -1);
941 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
942 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
943 bset
= isl_basic_set_add_constraint(bset
, c
);
945 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
946 c
= isl_constraint_set_constant_si(c
, 1);
947 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
948 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
949 bset
= isl_basic_set_add_constraint(bset
, c
);
951 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
953 assert(bset
&& bset
->n_div
== 1);
954 isl_local_space_free(ls
);
955 isl_basic_set_free(bset
);
958 dim
= isl_space_set_alloc(ctx
, 0, 3);
959 bset
= isl_basic_set_universe(isl_space_copy(dim
));
960 ls
= isl_local_space_from_space(dim
);
962 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
963 c
= isl_constraint_set_constant_si(c
, 1);
964 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
965 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
966 bset
= isl_basic_set_add_constraint(bset
, c
);
968 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
969 c
= isl_constraint_set_constant_si(c
, -1);
970 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
971 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
972 bset
= isl_basic_set_add_constraint(bset
, c
);
974 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
976 assert(bset
&& bset
->n_div
== 1);
977 isl_local_space_free(ls
);
978 isl_basic_set_free(bset
);
981 dim
= isl_space_set_alloc(ctx
, 0, 3);
982 bset
= isl_basic_set_universe(isl_space_copy(dim
));
983 ls
= isl_local_space_from_space(dim
);
985 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
986 c
= isl_constraint_set_constant_si(c
, 1);
987 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
988 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
989 bset
= isl_basic_set_add_constraint(bset
, c
);
991 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
992 c
= isl_constraint_set_constant_si(c
, -3);
993 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
994 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 4);
995 bset
= isl_basic_set_add_constraint(bset
, c
);
997 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
999 assert(bset
&& bset
->n_div
== 1);
1000 isl_local_space_free(ls
);
1001 isl_basic_set_free(bset
);
1004 dim
= isl_space_set_alloc(ctx
, 0, 3);
1005 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1006 ls
= isl_local_space_from_space(dim
);
1008 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1009 c
= isl_constraint_set_constant_si(c
, 2);
1010 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1011 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1012 bset
= isl_basic_set_add_constraint(bset
, c
);
1014 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1015 c
= isl_constraint_set_constant_si(c
, -1);
1016 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1017 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1018 bset
= isl_basic_set_add_constraint(bset
, c
);
1020 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1022 assert(isl_basic_set_is_empty(bset
));
1023 isl_local_space_free(ls
);
1024 isl_basic_set_free(bset
);
1027 dim
= isl_space_set_alloc(ctx
, 0, 3);
1028 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1029 ls
= isl_local_space_from_space(dim
);
1031 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1032 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1033 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1034 bset
= isl_basic_set_add_constraint(bset
, c
);
1036 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1037 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1038 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1039 bset
= isl_basic_set_add_constraint(bset
, c
);
1041 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1043 assert(bset
&& bset
->n_div
== 0);
1044 isl_basic_set_free(bset
);
1045 isl_local_space_free(ls
);
1048 dim
= isl_space_set_alloc(ctx
, 0, 3);
1049 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1050 ls
= isl_local_space_from_space(dim
);
1052 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1053 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1054 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1055 bset
= isl_basic_set_add_constraint(bset
, c
);
1057 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1058 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1059 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1060 bset
= isl_basic_set_add_constraint(bset
, c
);
1062 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1064 assert(bset
&& bset
->n_div
== 1);
1065 isl_basic_set_free(bset
);
1066 isl_local_space_free(ls
);
1069 /* This test is a bit tricky. We set up an equality
1070 * a + 3b + 3c = 6 e0
1071 * Normalization of divs creates _two_ divs
1074 * Afterwards e0 is removed again because it has coefficient -1
1075 * and we end up with the original equality and div again.
1076 * Perhaps we can avoid the introduction of this temporary div.
1078 dim
= isl_space_set_alloc(ctx
, 0, 4);
1079 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1080 ls
= isl_local_space_from_space(dim
);
1082 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1083 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1084 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1085 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -3);
1086 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 6);
1087 bset
= isl_basic_set_add_constraint(bset
, c
);
1089 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
1091 /* Test disabled for now */
1093 assert(bset && bset->n_div == 1);
1095 isl_local_space_free(ls
);
1096 isl_basic_set_free(bset
);
1099 dim
= isl_space_set_alloc(ctx
, 0, 5);
1100 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1101 ls
= isl_local_space_from_space(dim
);
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 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, -3);
1107 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 4, 6);
1108 bset
= isl_basic_set_add_constraint(bset
, c
);
1110 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1111 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1112 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 1);
1113 c
= isl_constraint_set_constant_si(c
, 1);
1114 bset
= isl_basic_set_add_constraint(bset
, c
);
1116 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
1118 /* Test disabled for now */
1120 assert(bset && bset->n_div == 1);
1122 isl_local_space_free(ls
);
1123 isl_basic_set_free(bset
);
1126 dim
= isl_space_set_alloc(ctx
, 0, 4);
1127 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1128 ls
= isl_local_space_from_space(dim
);
1130 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1131 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1132 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -1);
1133 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1134 bset
= isl_basic_set_add_constraint(bset
, c
);
1136 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1137 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1138 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 3);
1139 c
= isl_constraint_set_constant_si(c
, 2);
1140 bset
= isl_basic_set_add_constraint(bset
, c
);
1142 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
1144 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1146 assert(!isl_basic_set_is_empty(bset
));
1148 isl_local_space_free(ls
);
1149 isl_basic_set_free(bset
);
1152 dim
= isl_space_set_alloc(ctx
, 0, 3);
1153 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1154 ls
= isl_local_space_from_space(dim
);
1156 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1157 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1158 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1159 bset
= isl_basic_set_add_constraint(bset
, c
);
1161 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1163 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1165 isl_local_space_free(ls
);
1166 isl_basic_set_free(bset
);
1168 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1169 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1170 set
= isl_set_read_from_str(ctx
, str
);
1171 set
= isl_set_compute_divs(set
);
1176 if (test_elimination(ctx
) < 0)
1179 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1180 set
= isl_set_read_from_str(ctx
, str
);
1181 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
1182 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
1183 empty
= isl_set_is_empty(set
);
1188 isl_die(ctx
, isl_error_unknown
,
1189 "result not as accurate as expected", return -1);
1194 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
1198 struct isl_basic_set
*bset1
, *bset2
;
1199 struct isl_basic_map
*bmap
;
1201 filename
= get_filename(ctx
, name
, "omega");
1203 input
= fopen(filename
, "r");
1206 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1207 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1209 bset1
= isl_basic_set_apply(bset1
, bmap
);
1211 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1213 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1215 isl_basic_set_free(bset1
);
1216 isl_basic_set_free(bset2
);
1222 static int test_application(isl_ctx
*ctx
)
1224 test_application_case(ctx
, "application");
1225 test_application_case(ctx
, "application2");
1230 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1234 struct isl_basic_set
*bset1
, *bset2
;
1236 filename
= get_filename(ctx
, name
, "polylib");
1238 input
= fopen(filename
, "r");
1241 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1242 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1244 bset1
= isl_basic_set_affine_hull(bset1
);
1246 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1248 isl_basic_set_free(bset1
);
1249 isl_basic_set_free(bset2
);
1255 int test_affine_hull(struct isl_ctx
*ctx
)
1259 isl_basic_set
*bset
, *bset2
;
1263 test_affine_hull_case(ctx
, "affine2");
1264 test_affine_hull_case(ctx
, "affine");
1265 test_affine_hull_case(ctx
, "affine3");
1267 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1268 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1269 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1270 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1271 set
= isl_set_read_from_str(ctx
, str
);
1272 bset
= isl_set_affine_hull(set
);
1273 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1274 isl_basic_set_free(bset
);
1276 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1279 /* Check that isl_map_affine_hull is not confused by
1280 * the reordering of divs in isl_map_align_divs.
1282 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1283 "32e0 = b and 32e1 = c); "
1284 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1285 set
= isl_set_read_from_str(ctx
, str
);
1286 bset
= isl_set_affine_hull(set
);
1287 isl_basic_set_free(bset
);
1291 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1292 "32e2 = 31 + 31e0 }";
1293 set
= isl_set_read_from_str(ctx
, str
);
1294 bset
= isl_set_affine_hull(set
);
1295 str
= "{ [a] : exists e : a = 32 e }";
1296 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1297 subset
= isl_basic_set_is_subset(bset
, bset2
);
1298 isl_basic_set_free(bset
);
1299 isl_basic_set_free(bset2
);
1303 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1309 /* Pairs of maps and the corresponding expected results of
1310 * isl_map_plain_unshifted_simple_hull.
1315 } plain_unshifted_simple_hull_tests
[] = {
1316 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1317 "{ [i] -> [j] : i >= 1 }" },
1318 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1319 "(j mod 4 = 2 and k mod 6 = n) }",
1320 "{ [n] -> [i,j,k] : j mod 4 = 2 }" },
1323 /* Basic tests for isl_map_plain_unshifted_simple_hull.
1325 static int test_plain_unshifted_simple_hull(isl_ctx
*ctx
)
1329 isl_basic_map
*hull
, *expected
;
1332 for (i
= 0; i
< ARRAY_SIZE(plain_unshifted_simple_hull_tests
); ++i
) {
1334 str
= plain_unshifted_simple_hull_tests
[i
].map
;
1335 map
= isl_map_read_from_str(ctx
, str
);
1336 str
= plain_unshifted_simple_hull_tests
[i
].hull
;
1337 expected
= isl_basic_map_read_from_str(ctx
, str
);
1338 hull
= isl_map_plain_unshifted_simple_hull(map
);
1339 equal
= isl_basic_map_is_equal(hull
, expected
);
1340 isl_basic_map_free(hull
);
1341 isl_basic_map_free(expected
);
1345 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1352 /* Pairs of sets and the corresponding expected results of
1353 * isl_set_unshifted_simple_hull.
1358 } unshifted_simple_hull_tests
[] = {
1359 { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1360 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1363 /* Basic tests for isl_set_unshifted_simple_hull.
1365 static int test_unshifted_simple_hull(isl_ctx
*ctx
)
1369 isl_basic_set
*hull
, *expected
;
1372 for (i
= 0; i
< ARRAY_SIZE(unshifted_simple_hull_tests
); ++i
) {
1374 str
= unshifted_simple_hull_tests
[i
].set
;
1375 set
= isl_set_read_from_str(ctx
, str
);
1376 str
= unshifted_simple_hull_tests
[i
].hull
;
1377 expected
= isl_basic_set_read_from_str(ctx
, str
);
1378 hull
= isl_set_unshifted_simple_hull(set
);
1379 equal
= isl_basic_set_is_equal(hull
, expected
);
1380 isl_basic_set_free(hull
);
1381 isl_basic_set_free(expected
);
1385 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1392 static int test_simple_hull(struct isl_ctx
*ctx
)
1396 isl_basic_set
*bset
;
1399 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1400 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1401 set
= isl_set_read_from_str(ctx
, str
);
1402 bset
= isl_set_simple_hull(set
);
1403 is_empty
= isl_basic_set_is_empty(bset
);
1404 isl_basic_set_free(bset
);
1406 if (is_empty
== isl_bool_error
)
1409 if (is_empty
== isl_bool_false
)
1410 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1413 if (test_plain_unshifted_simple_hull(ctx
) < 0)
1415 if (test_unshifted_simple_hull(ctx
) < 0)
1421 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1425 struct isl_basic_set
*bset1
, *bset2
;
1426 struct isl_set
*set
;
1428 filename
= get_filename(ctx
, name
, "polylib");
1430 input
= fopen(filename
, "r");
1433 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1434 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1436 set
= isl_basic_set_union(bset1
, bset2
);
1437 bset1
= isl_set_convex_hull(set
);
1439 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1441 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1443 isl_basic_set_free(bset1
);
1444 isl_basic_set_free(bset2
);
1453 } convex_hull_tests
[] = {
1454 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1455 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1456 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1457 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1458 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1459 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1460 "i2 <= 5 and i2 >= 4; "
1461 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1462 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1463 "i2 <= 5 + i0 and i2 >= i0 }" },
1464 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1465 "{ [x, y] : 1 = 0 }" },
1466 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1467 "[x, y, 0] : x >= 0 and y < 0 }",
1468 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1471 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1474 int orig_convex
= ctx
->opt
->convex
;
1475 ctx
->opt
->convex
= convex
;
1477 test_convex_hull_case(ctx
, "convex0");
1478 test_convex_hull_case(ctx
, "convex1");
1479 test_convex_hull_case(ctx
, "convex2");
1480 test_convex_hull_case(ctx
, "convex3");
1481 test_convex_hull_case(ctx
, "convex4");
1482 test_convex_hull_case(ctx
, "convex5");
1483 test_convex_hull_case(ctx
, "convex6");
1484 test_convex_hull_case(ctx
, "convex7");
1485 test_convex_hull_case(ctx
, "convex8");
1486 test_convex_hull_case(ctx
, "convex9");
1487 test_convex_hull_case(ctx
, "convex10");
1488 test_convex_hull_case(ctx
, "convex11");
1489 test_convex_hull_case(ctx
, "convex12");
1490 test_convex_hull_case(ctx
, "convex13");
1491 test_convex_hull_case(ctx
, "convex14");
1492 test_convex_hull_case(ctx
, "convex15");
1494 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1495 isl_set
*set1
, *set2
;
1498 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1499 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1500 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1501 equal
= isl_set_is_equal(set1
, set2
);
1508 isl_die(ctx
, isl_error_unknown
,
1509 "unexpected convex hull", return -1);
1512 ctx
->opt
->convex
= orig_convex
;
1517 static int test_convex_hull(isl_ctx
*ctx
)
1519 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1521 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1526 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1530 struct isl_basic_set
*bset1
, *bset2
;
1532 filename
= get_filename(ctx
, name
, "polylib");
1534 input
= fopen(filename
, "r");
1537 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1538 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1540 bset1
= isl_basic_set_gist(bset1
, bset2
);
1542 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1544 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1546 isl_basic_set_free(bset1
);
1547 isl_basic_set_free(bset2
);
1553 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1557 const char *context
;
1559 } plain_gist_tests
[] = {
1560 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1561 "{ [i] -> [j] : i >= 1 }",
1562 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1563 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1564 "(j mod 4 = 2 and k mod 6 = n) }",
1565 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1566 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1567 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1568 "{ [i] -> [j] : i > j }",
1569 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1572 /* Basic tests for isl_map_plain_gist_basic_map.
1574 static int test_plain_gist(isl_ctx
*ctx
)
1578 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1581 isl_map
*map
, *gist
;
1582 isl_basic_map
*context
;
1584 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1585 str
= plain_gist_tests
[i
].context
;
1586 context
= isl_basic_map_read_from_str(ctx
, str
);
1587 map
= isl_map_plain_gist_basic_map(map
, context
);
1588 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1589 equal
= isl_map_is_equal(map
, gist
);
1595 isl_die(ctx
, isl_error_unknown
,
1596 "incorrect gist result", return -1);
1604 const char *context
;
1607 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1608 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1609 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1610 "{ [a, b, c] : a <= 15 }" },
1611 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1612 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1613 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1614 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1615 { "{ [m, n, a, b] : a <= 2147 + n }",
1616 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1617 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1618 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1620 "{ [m, n, ku, kl] }" },
1621 { "{ [a, a, b] : a >= 10 }",
1622 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1623 "{ [a, a, b] : a >= 10 }" },
1624 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1625 "{ [0, j] : j >= 0 }" },
1626 /* Check that no constraints on i6 are introduced in the gist */
1627 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1628 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1629 "5e0 <= 381 - t1 and i4 <= 1) }",
1630 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1631 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1632 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1633 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1634 "20e0 >= 1511 - 4t1 - 5i4) }" },
1635 /* Check that no constraints on i6 are introduced in the gist */
1636 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1637 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1638 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1639 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1640 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1641 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1642 "20e1 <= 1530 - 4t1 - 5i4 and "
1643 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1644 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1645 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1646 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1647 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1648 "10e0 <= -91 + 5i4 + 4i6 and "
1649 "10e0 >= -105 + 5i4 + 4i6) }",
1650 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1651 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1652 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1653 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1654 "{ [a, b, q, p] : b >= 1 + a }",
1655 "{ [a, b, q, p] : false }" },
1656 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1657 "[n] -> { [x] : x mod 32 = 0 }",
1658 "[n] -> { [x = n] }" },
1659 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1660 "{ [x] : x mod 2 = 0 }" },
1661 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1662 "{ [x] : x mod 128 = 0 }" },
1663 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1664 "{ [x] : x mod 3200 = 0 }" },
1665 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1666 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1667 "{ [a, b, c = a] }" },
1668 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1669 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1670 "{ [a, b, c = a] : a mod 3 = 0 }" },
1671 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1672 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1674 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1675 "{ [x,y] : 1 <= y <= 3 }",
1679 /* Check that isl_set_gist behaves as expected.
1681 * For the test cases in gist_tests, besides checking that the result
1682 * is as expected, also check that applying the gist operation does
1683 * not modify the input set (an earlier version of isl would do that) and
1684 * that the test case is consistent, i.e., that the gist has the same
1685 * intersection with the context as the input set.
1687 static int test_gist(struct isl_ctx
*ctx
)
1691 isl_basic_set
*bset1
, *bset2
;
1692 isl_map
*map1
, *map2
;
1695 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1696 int equal_input
, equal_intersection
;
1697 isl_set
*set1
, *set2
, *copy
, *context
;
1699 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1700 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1701 copy
= isl_set_copy(set1
);
1702 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1703 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1704 equal
= isl_set_is_equal(set1
, set2
);
1706 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1707 equal_input
= isl_set_is_equal(set1
, copy
);
1709 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1710 set2
= isl_set_intersect(set2
, context
);
1711 equal_intersection
= isl_set_is_equal(set1
, set2
);
1714 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1717 isl_die(ctx
, isl_error_unknown
,
1718 "incorrect gist result", return -1);
1720 isl_die(ctx
, isl_error_unknown
,
1721 "gist modified input", return -1);
1723 isl_die(ctx
, isl_error_unknown
,
1724 "inconsistent gist test case", return -1);
1727 test_gist_case(ctx
, "gist1");
1729 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1730 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1731 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1732 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1733 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1734 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1735 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1736 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1737 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1738 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1739 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1740 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1741 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1742 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1743 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1744 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1745 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1746 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1747 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1748 bset1
= isl_basic_set_gist(bset1
, bset2
);
1749 assert(bset1
&& bset1
->n_div
== 0);
1750 isl_basic_set_free(bset1
);
1752 /* Check that the integer divisions of the second disjunct
1753 * do not spread to the first disjunct.
1755 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1756 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1757 "(exists (e0 = [(-1 + t1)/16], "
1758 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1759 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1760 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1761 "o0 <= 4294967295 and t1 <= -1)) }";
1762 map1
= isl_map_read_from_str(ctx
, str
);
1763 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1764 map2
= isl_map_read_from_str(ctx
, str
);
1765 map1
= isl_map_gist(map1
, map2
);
1769 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1770 isl_map_free(map1
); return -1);
1771 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1772 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1773 isl_map_free(map1
); return -1);
1776 if (test_plain_gist(ctx
) < 0)
1782 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1784 isl_set
*set
, *set2
;
1788 set
= isl_set_read_from_str(ctx
, str
);
1789 set
= isl_set_coalesce(set
);
1790 set2
= isl_set_read_from_str(ctx
, str
);
1791 equal
= isl_set_is_equal(set
, set2
);
1792 one
= set
&& set
->n
== 1;
1799 isl_die(ctx
, isl_error_unknown
,
1800 "coalesced set not equal to input", return -1);
1801 if (check_one
&& !one
)
1802 isl_die(ctx
, isl_error_unknown
,
1803 "coalesced set should not be a union", return -1);
1808 /* Inputs for coalescing tests with unbounded wrapping.
1809 * "str" is a string representation of the input set.
1810 * "single_disjunct" is set if we expect the result to consist of
1811 * a single disjunct.
1814 int single_disjunct
;
1816 } coalesce_unbounded_tests
[] = {
1817 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1818 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1819 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1820 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1822 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1823 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1824 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1825 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1828 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1829 * option turned off.
1831 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1837 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1838 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1840 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
1841 const char *str
= coalesce_unbounded_tests
[i
].str
;
1842 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
1843 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
1849 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1854 /* Inputs for coalescing tests.
1855 * "str" is a string representation of the input set.
1856 * "single_disjunct" is set if we expect the result to consist of
1857 * a single disjunct.
1860 int single_disjunct
;
1862 } coalesce_tests
[] = {
1863 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1864 "y >= x & x >= 2 & 5 >= y }" },
1865 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1866 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1867 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1868 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1869 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1870 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1871 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1872 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1873 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1874 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1875 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1876 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1877 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1878 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1879 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1880 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1881 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1882 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1883 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1884 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1885 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1886 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1887 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1888 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1889 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1890 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1891 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1892 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1893 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1894 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1895 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1896 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1897 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1898 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1899 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1900 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1901 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1902 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1903 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1904 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1905 "[o0, o1, o2, o3, o4, o5, o6]] : "
1906 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1907 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1908 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1909 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1910 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1911 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1912 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1913 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1914 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1915 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1916 "o6 >= i3 + i6 - o3 and M >= 0 and "
1917 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1918 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1919 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1920 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1921 "(o0 = 0 and M >= 2 and N >= 3) or "
1922 "(M = 0 and o0 = 0 and N >= 3) }" },
1923 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1924 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1925 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1926 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1927 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1928 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1929 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1930 "(y = 3 and x = 1) }" },
1931 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1932 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1933 "i1 <= M and i3 <= M and i4 <= M) or "
1934 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1935 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1936 "i4 <= -1 + M) }" },
1937 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1938 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1939 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1940 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1941 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1942 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1943 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1944 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1945 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1946 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1947 { 0, "{ [a, b] : exists e : 2e = a and "
1948 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1949 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1950 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1951 "j >= 1 and j' <= i + j - i' and i >= 1; "
1953 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1954 "[i,j] : exists a : j = 3a }" },
1955 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1956 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1958 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1959 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1960 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1961 "c <= 6 + 8a and a >= 3; "
1962 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1963 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1964 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1965 "[x,0] : 3 <= x <= 4 }" },
1966 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1967 "[x,0] : 4 <= x <= 5 }" },
1968 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1969 "[x,0] : 3 <= x <= 5 }" },
1970 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1971 "[x,0] : 3 <= x <= 4 }" },
1972 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1974 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1975 { 1, "{ [0,0]; [1,1] }" },
1976 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
1977 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
1979 "[k, 0, k] : k <= 6 and k >= 1 }" },
1980 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
1981 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
1982 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
1983 { 1, "[n] -> { [1] : n >= 0;"
1984 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
1985 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
1986 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
1987 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
1988 "2e0 <= x and 2e0 <= n);"
1989 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
1991 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
1992 "128e0 >= -134 + 127t1 and t1 >= 2 and "
1993 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
1995 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
1996 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
1998 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
1999 "t1 >= 13 and t1 <= 16);"
2000 "[t1] : t1 <= 15 and t1 >= 12 }" },
2001 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2002 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2003 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2004 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2005 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2006 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2008 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2009 "(exists (e0 : 3e0 = -2 + c0)) }" },
2010 { 0, "[n, b0, t0] -> "
2011 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2012 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2013 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2014 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2015 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2016 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2017 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2018 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2019 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2020 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2021 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2022 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2023 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2024 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2025 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2026 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2027 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2028 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2029 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2030 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2031 { 0, "{ [i0, i1, i2] : "
2032 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2033 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2034 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2035 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2036 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2037 "32e0 <= 31 + i0)) or "
2039 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2040 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2041 "2*floor((c)/2) = c and 0 <= a <= 192;"
2042 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2044 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2045 "(0 <= a <= b <= n) }" },
2046 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2047 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2048 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2049 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2050 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2051 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2052 "b = 3 and 9e0 <= -19 + 2c)) }" },
2053 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2054 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2055 "(a = 4 and b = 3 and "
2056 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2057 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2058 "(b = -1 + a and 0 < a <= 3 and "
2059 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2060 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2061 "b = 3 and 9e0 <= -19 + 2c)) }" },
2062 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2064 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2066 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2067 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2068 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2069 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2070 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2071 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2072 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2073 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2074 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2075 { 1, "{ [a] : a <= 8 and "
2076 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2077 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2078 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2079 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2080 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2081 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2082 "(a < 0 and 3*floor((a)/3) < a) }" },
2083 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2084 "(a < -1 and 3*floor((a)/3) < a) }" },
2085 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2086 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2087 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2088 "or (2 <= a <= 15 and b < a)) }" },
2089 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2090 "32*floor((a)/32) < a) or a <= 15) }" },
2091 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2092 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2093 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2094 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2095 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2096 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2097 "S_0[n] : n <= m <= 2 + n }" },
2098 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2099 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2101 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2102 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2103 "2e0 < -a + 2b) }" },
2104 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2105 "[i, 0, i] : 0 <= i <= 7 }" },
2106 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2107 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2108 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2109 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2110 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2113 /* A specialized coalescing test case that would result
2114 * in a segmentation fault or a failed assertion in earlier versions of isl.
2116 static int test_coalesce_special(struct isl_ctx
*ctx
)
2119 isl_map
*map1
, *map2
;
2121 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2122 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2123 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2124 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2125 "o1 <= 239 and o1 >= 212)) or "
2126 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2127 "o1 <= 241 and o1 >= 240));"
2128 "[S_L220_OUT[] -> T7[]] -> "
2129 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2130 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2131 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2132 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2133 map1
= isl_map_read_from_str(ctx
, str
);
2134 map1
= isl_map_align_divs_internal(map1
);
2135 map1
= isl_map_coalesce(map1
);
2136 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2137 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2138 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2139 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2140 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2141 map2
= isl_map_read_from_str(ctx
, str
);
2142 map2
= isl_map_union(map2
, map1
);
2143 map2
= isl_map_align_divs_internal(map2
);
2144 map2
= isl_map_coalesce(map2
);
2152 /* A specialized coalescing test case that would result in an assertion
2153 * in an earlier version of isl.
2154 * The explicit call to isl_basic_set_union prevents the implicit
2155 * equality constraints in the first basic map from being detected prior
2156 * to the call to isl_set_coalesce, at least at the point
2157 * where this test case was introduced.
2159 static int test_coalesce_special2(struct isl_ctx
*ctx
)
2162 isl_basic_set
*bset1
, *bset2
;
2165 str
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2166 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2167 str
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2168 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2169 set
= isl_basic_set_union(bset1
, bset2
);
2170 set
= isl_set_coalesce(set
);
2178 /* Check that calling isl_set_coalesce does not leave other sets
2179 * that may share some information with the input to isl_set_coalesce
2180 * in an inconsistent state.
2181 * In particular, older versions of isl would modify all copies
2182 * of the basic sets in the isl_set_coalesce input in a way
2183 * that could leave them in an inconsistent state.
2184 * The result of printing any other set containing one of these
2185 * basic sets would then result in an invalid set description.
2187 static int test_coalesce_special3(isl_ctx
*ctx
)
2191 isl_set
*set1
, *set2
;
2194 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2195 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2196 set2
= isl_set_read_from_str(ctx
, str
);
2197 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2198 set1
= isl_set_coalesce(set1
);
2201 p
= isl_printer_to_str(ctx
);
2202 p
= isl_printer_print_set(p
, set2
);
2204 s
= isl_printer_get_str(p
);
2205 isl_printer_free(p
);
2206 set1
= isl_set_read_from_str(ctx
, s
);
2216 /* Test the functionality of isl_set_coalesce.
2217 * That is, check that the output is always equal to the input
2218 * and in some cases that the result consists of a single disjunct.
2220 static int test_coalesce(struct isl_ctx
*ctx
)
2224 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2225 const char *str
= coalesce_tests
[i
].str
;
2226 int check_one
= coalesce_tests
[i
].single_disjunct
;
2227 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2231 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2233 if (test_coalesce_special(ctx
) < 0)
2235 if (test_coalesce_special2(ctx
) < 0)
2237 if (test_coalesce_special3(ctx
) < 0)
2243 /* Construct a representation of the graph on the right of Figure 1
2244 * in "Computing the Transitive Closure of a Union of
2245 * Affine Integer Tuple Relations".
2247 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2250 isl_map
*up
, *right
;
2252 dom
= isl_set_read_from_str(ctx
,
2253 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2254 "2 x - 3 y + 3 >= 0 }");
2255 right
= isl_map_read_from_str(ctx
,
2256 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2257 up
= isl_map_read_from_str(ctx
,
2258 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2259 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2260 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2261 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2262 up
= isl_map_intersect_range(up
, dom
);
2263 return isl_map_union(up
, right
);
2266 /* Construct a representation of the power of the graph
2267 * on the right of Figure 1 in "Computing the Transitive Closure of
2268 * a Union of Affine Integer Tuple Relations".
2270 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2272 return isl_map_read_from_str(ctx
,
2273 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2274 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2275 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2278 /* Construct a representation of the transitive closure of the graph
2279 * on the right of Figure 1 in "Computing the Transitive Closure of
2280 * a Union of Affine Integer Tuple Relations".
2282 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2284 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2287 static int test_closure(isl_ctx
*ctx
)
2290 isl_map
*map
, *map2
;
2293 /* COCOA example 1 */
2294 map
= isl_map_read_from_str(ctx
,
2295 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2296 "1 <= i and i < n and 1 <= j and j < n or "
2297 "i2 = i + 1 and j2 = j - 1 and "
2298 "1 <= i and i < n and 2 <= j and j <= n }");
2299 map
= isl_map_power(map
, &exact
);
2303 /* COCOA example 1 */
2304 map
= isl_map_read_from_str(ctx
,
2305 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2306 "1 <= i and i < n and 1 <= j and j < n or "
2307 "i2 = i + 1 and j2 = j - 1 and "
2308 "1 <= i and i < n and 2 <= j and j <= n }");
2309 map
= isl_map_transitive_closure(map
, &exact
);
2311 map2
= isl_map_read_from_str(ctx
,
2312 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2313 "1 <= i and i < n and 1 <= j and j <= n and "
2314 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2315 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2316 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2317 assert(isl_map_is_equal(map
, map2
));
2321 map
= isl_map_read_from_str(ctx
,
2322 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2323 " 0 <= y and y <= n }");
2324 map
= isl_map_transitive_closure(map
, &exact
);
2325 map2
= isl_map_read_from_str(ctx
,
2326 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2327 " 0 <= y and y <= n }");
2328 assert(isl_map_is_equal(map
, map2
));
2332 /* COCOA example 2 */
2333 map
= isl_map_read_from_str(ctx
,
2334 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2335 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2336 "i2 = i + 2 and j2 = j - 2 and "
2337 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2338 map
= isl_map_transitive_closure(map
, &exact
);
2340 map2
= isl_map_read_from_str(ctx
,
2341 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2342 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2343 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2344 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2345 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2346 assert(isl_map_is_equal(map
, map2
));
2350 /* COCOA Fig.2 left */
2351 map
= isl_map_read_from_str(ctx
,
2352 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2353 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2355 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2356 "j <= 2 i - 3 and j <= n - 2 or "
2357 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2358 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2359 map
= isl_map_transitive_closure(map
, &exact
);
2363 /* COCOA Fig.2 right */
2364 map
= isl_map_read_from_str(ctx
,
2365 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2366 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2368 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2369 "j <= 2 i - 4 and j <= n - 3 or "
2370 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2371 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2372 map
= isl_map_power(map
, &exact
);
2376 /* COCOA Fig.2 right */
2377 map
= isl_map_read_from_str(ctx
,
2378 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2379 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2381 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2382 "j <= 2 i - 4 and j <= n - 3 or "
2383 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2384 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2385 map
= isl_map_transitive_closure(map
, &exact
);
2387 map2
= isl_map_read_from_str(ctx
,
2388 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2389 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2390 "j <= n and 3 + i + 2 j <= 3 n and "
2391 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2392 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2393 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2394 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2395 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2396 assert(isl_map_is_equal(map
, map2
));
2400 map
= cocoa_fig_1_right_graph(ctx
);
2401 map
= isl_map_transitive_closure(map
, &exact
);
2403 map2
= cocoa_fig_1_right_tc(ctx
);
2404 assert(isl_map_is_equal(map
, map2
));
2408 map
= cocoa_fig_1_right_graph(ctx
);
2409 map
= isl_map_power(map
, &exact
);
2410 map2
= cocoa_fig_1_right_power(ctx
);
2411 equal
= isl_map_is_equal(map
, map2
);
2417 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2419 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2421 /* COCOA Theorem 1 counter example */
2422 map
= isl_map_read_from_str(ctx
,
2423 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2424 "i2 = 1 and j2 = j or "
2425 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2426 map
= isl_map_transitive_closure(map
, &exact
);
2430 map
= isl_map_read_from_str(ctx
,
2431 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2432 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2433 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2434 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2435 map
= isl_map_transitive_closure(map
, &exact
);
2439 /* Kelly et al 1996, fig 12 */
2440 map
= isl_map_read_from_str(ctx
,
2441 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2442 "1 <= i,j,j+1 <= n or "
2443 "j = n and j2 = 1 and i2 = i + 1 and "
2444 "1 <= i,i+1 <= n }");
2445 map
= isl_map_transitive_closure(map
, &exact
);
2447 map2
= isl_map_read_from_str(ctx
,
2448 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2449 "1 <= i <= n and i = i2 or "
2450 "1 <= i < i2 <= n and 1 <= j <= n and "
2452 assert(isl_map_is_equal(map
, map2
));
2456 /* Omega's closure4 */
2457 map
= isl_map_read_from_str(ctx
,
2458 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2459 "1 <= x,y <= 10 or "
2460 "x2 = x + 1 and y2 = y and "
2461 "1 <= x <= 20 && 5 <= y <= 15 }");
2462 map
= isl_map_transitive_closure(map
, &exact
);
2466 map
= isl_map_read_from_str(ctx
,
2467 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2468 map
= isl_map_transitive_closure(map
, &exact
);
2470 map2
= isl_map_read_from_str(ctx
,
2471 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2472 assert(isl_map_is_equal(map
, map2
));
2476 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2477 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2478 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2479 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2480 map
= isl_map_read_from_str(ctx
, str
);
2481 map
= isl_map_transitive_closure(map
, &exact
);
2483 map2
= isl_map_read_from_str(ctx
, str
);
2484 assert(isl_map_is_equal(map
, map2
));
2488 str
= "{[0] -> [1]; [2] -> [3]}";
2489 map
= isl_map_read_from_str(ctx
, str
);
2490 map
= isl_map_transitive_closure(map
, &exact
);
2492 map2
= isl_map_read_from_str(ctx
, str
);
2493 assert(isl_map_is_equal(map
, map2
));
2497 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2498 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2499 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2500 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2501 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2502 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2503 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2504 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2505 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2506 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2507 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2508 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2509 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2510 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2511 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2512 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2513 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2514 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2515 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2516 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2517 map
= isl_map_read_from_str(ctx
, str
);
2518 map
= isl_map_transitive_closure(map
, NULL
);
2525 static int test_lex(struct isl_ctx
*ctx
)
2531 dim
= isl_space_set_alloc(ctx
, 0, 0);
2532 map
= isl_map_lex_le(dim
);
2533 empty
= isl_map_is_empty(map
);
2539 isl_die(ctx
, isl_error_unknown
,
2540 "expecting non-empty result", return -1);
2545 /* Inputs for isl_map_lexmin tests.
2546 * "map" is the input and "lexmin" is the expected result.
2551 } lexmin_tests
[] = {
2552 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2553 "{ [x] -> [5] : 6 <= x <= 8; "
2554 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2555 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2556 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2557 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2558 "{ [x] -> [y] : (4y = x and x >= 0) or "
2559 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2560 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2561 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2562 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2563 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2564 /* Check that empty pieces are properly combined. */
2565 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2566 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2567 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2568 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2569 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2571 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2572 "a <= 255 and c <= 255 and d <= 255 - j and "
2573 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2574 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2575 "247d <= 247 + i and 248 - b <= 248d <= c and "
2576 "254d >= i - a + b and 254d >= -a + b and "
2577 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2579 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2580 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2581 "247j >= 62738 - i and 509j <= 129795 + i and "
2582 "742j >= 188724 - i; "
2583 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2584 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2585 "16*floor((8 + b)/16) <= 7 + b; "
2587 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2588 "[a] -> [b = 0] : 0 < a <= 509 }" },
2589 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2590 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2593 static int test_lexmin(struct isl_ctx
*ctx
)
2598 isl_basic_map
*bmap
;
2599 isl_map
*map
, *map2
;
2602 isl_pw_multi_aff
*pma
;
2604 str
= "[p0, p1] -> { [] -> [] : "
2605 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2606 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2607 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2608 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2609 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2610 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2611 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2612 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2613 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2614 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2615 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2616 map
= isl_map_read_from_str(ctx
, str
);
2617 map
= isl_map_lexmin(map
);
2620 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2621 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2622 set
= isl_set_read_from_str(ctx
, str
);
2623 set
= isl_set_lexmax(set
);
2624 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
2625 set2
= isl_set_read_from_str(ctx
, str
);
2626 set
= isl_set_intersect(set
, set2
);
2627 assert(!isl_set_is_empty(set
));
2630 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
2631 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
2632 map
= isl_map_lexmin(map
);
2633 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
2634 equal
= isl_map_is_equal(map
, map2
);
2641 isl_die(ctx
, isl_error_unknown
,
2642 "unexpected result", return -1);
2645 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2646 " 8i' <= i and 8i' >= -7 + i }";
2647 bmap
= isl_basic_map_read_from_str(ctx
, str
);
2648 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
2649 map2
= isl_map_from_pw_multi_aff(pma
);
2650 map
= isl_map_from_basic_map(bmap
);
2651 assert(isl_map_is_equal(map
, map2
));
2655 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2656 " 8i' <= i and 8i' >= -7 + i }";
2657 set
= isl_set_read_from_str(ctx
, str
);
2658 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
2659 set2
= isl_set_from_pw_multi_aff(pma
);
2660 equal
= isl_set_is_equal(set
, set2
);
2666 isl_die(ctx
, isl_error_unknown
,
2667 "unexpected difference between set and "
2668 "piecewise affine expression", return -1);
2673 /* A specialized isl_set_min_val test case that would return the wrong result
2674 * in earlier versions of isl.
2675 * The explicit call to isl_basic_set_union prevents the second basic set
2676 * from being determined to be empty prior to the call to isl_set_min_val,
2677 * at least at the point where this test case was introduced.
2679 static int test_min_special(isl_ctx
*ctx
)
2682 isl_basic_set
*bset1
, *bset2
;
2688 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
2689 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2690 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
2691 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2692 set
= isl_basic_set_union(bset1
, bset2
);
2693 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
2695 res
= isl_set_min_val(set
, obj
);
2696 ok
= isl_val_cmp_si(res
, 5) == 0;
2705 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
2711 /* A specialized isl_set_min_val test case that would return an error
2712 * in earlier versions of isl.
2714 static int test_min_special2(isl_ctx
*ctx
)
2717 isl_basic_set
*bset
;
2721 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
2722 bset
= isl_basic_set_read_from_str(ctx
, str
);
2724 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
2726 res
= isl_basic_set_max_val(bset
, obj
);
2728 isl_basic_set_free(bset
);
2741 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
2742 __isl_keep isl_aff
*obj
);
2745 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
2746 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
2747 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
2748 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
2749 &isl_set_max_val
, "30" },
2753 /* Perform basic isl_set_min_val and isl_set_max_val tests.
2754 * In particular, check the results on non-convex inputs.
2756 static int test_min(struct isl_ctx
*ctx
)
2764 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
2765 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
2766 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
2767 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
2768 val
= opt_tests
[i
].fn(set
, obj
);
2769 ok
= isl_val_eq(res
, val
);
2778 isl_die(ctx
, isl_error_unknown
,
2779 "unexpected optimum", return -1);
2782 if (test_min_special(ctx
) < 0)
2784 if (test_min_special2(ctx
) < 0)
2795 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
2796 void *dep_user
, void *user
)
2798 struct must_may
*mm
= (struct must_may
*)user
;
2801 mm
->must
= isl_map_union(mm
->must
, dep
);
2803 mm
->may
= isl_map_union(mm
->may
, dep
);
2808 static int common_space(void *first
, void *second
)
2810 int depth
= *(int *)first
;
2814 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
2822 map2
= isl_map_read_from_str(map
->ctx
, str
);
2823 equal
= isl_map_is_equal(map
, map2
);
2829 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
2833 equal
= map_is_equal(map
, str
);
2837 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
2838 "result not as expected", return -1);
2842 static int test_dep(struct isl_ctx
*ctx
)
2847 isl_access_info
*ai
;
2854 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2855 map
= isl_map_read_from_str(ctx
, str
);
2856 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2858 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2859 map
= isl_map_read_from_str(ctx
, str
);
2860 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2862 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2863 map
= isl_map_read_from_str(ctx
, str
);
2864 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2866 flow
= isl_access_info_compute_flow(ai
);
2867 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2868 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2869 mm
.may
= isl_map_empty(dim
);
2871 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2873 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
2874 " [1,10,0] -> [2,5,0] }";
2875 assert(map_is_equal(mm
.must
, str
));
2876 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2877 assert(map_is_equal(mm
.may
, str
));
2879 isl_map_free(mm
.must
);
2880 isl_map_free(mm
.may
);
2881 isl_flow_free(flow
);
2884 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2885 map
= isl_map_read_from_str(ctx
, str
);
2886 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2888 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2889 map
= isl_map_read_from_str(ctx
, str
);
2890 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2892 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2893 map
= isl_map_read_from_str(ctx
, str
);
2894 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2896 flow
= isl_access_info_compute_flow(ai
);
2897 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2898 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2899 mm
.may
= isl_map_empty(dim
);
2901 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2903 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2904 assert(map_is_equal(mm
.must
, str
));
2905 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2906 assert(map_is_equal(mm
.may
, str
));
2908 isl_map_free(mm
.must
);
2909 isl_map_free(mm
.may
);
2910 isl_flow_free(flow
);
2913 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2914 map
= isl_map_read_from_str(ctx
, str
);
2915 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2917 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2918 map
= isl_map_read_from_str(ctx
, str
);
2919 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2921 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2922 map
= isl_map_read_from_str(ctx
, str
);
2923 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2925 flow
= isl_access_info_compute_flow(ai
);
2926 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2927 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2928 mm
.may
= isl_map_empty(dim
);
2930 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2932 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
2933 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2934 assert(map_is_equal(mm
.may
, str
));
2935 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2936 assert(map_is_equal(mm
.must
, str
));
2938 isl_map_free(mm
.must
);
2939 isl_map_free(mm
.may
);
2940 isl_flow_free(flow
);
2943 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
2944 map
= isl_map_read_from_str(ctx
, str
);
2945 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2947 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2948 map
= isl_map_read_from_str(ctx
, str
);
2949 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2951 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
2952 map
= isl_map_read_from_str(ctx
, str
);
2953 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2955 flow
= isl_access_info_compute_flow(ai
);
2956 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2957 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2958 mm
.may
= isl_map_empty(dim
);
2960 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2962 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2963 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2964 assert(map_is_equal(mm
.may
, str
));
2965 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2966 assert(map_is_equal(mm
.must
, str
));
2968 isl_map_free(mm
.must
);
2969 isl_map_free(mm
.may
);
2970 isl_flow_free(flow
);
2973 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2974 map
= isl_map_read_from_str(ctx
, str
);
2975 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2977 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2978 map
= isl_map_read_from_str(ctx
, str
);
2979 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2981 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2982 map
= isl_map_read_from_str(ctx
, str
);
2983 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2985 flow
= isl_access_info_compute_flow(ai
);
2986 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2987 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2988 mm
.may
= isl_map_empty(dim
);
2990 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2992 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2993 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2994 assert(map_is_equal(mm
.may
, str
));
2995 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2996 assert(map_is_equal(mm
.must
, str
));
2998 isl_map_free(mm
.must
);
2999 isl_map_free(mm
.may
);
3000 isl_flow_free(flow
);
3005 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3006 map
= isl_map_read_from_str(ctx
, str
);
3007 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
3009 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3010 map
= isl_map_read_from_str(ctx
, str
);
3011 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3013 flow
= isl_access_info_compute_flow(ai
);
3014 dim
= isl_space_alloc(ctx
, 0, 5, 5);
3015 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3016 mm
.may
= isl_map_empty(dim
);
3018 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3020 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3021 assert(map_is_equal(mm
.must
, str
));
3022 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3023 assert(map_is_equal(mm
.may
, str
));
3025 isl_map_free(mm
.must
);
3026 isl_map_free(mm
.may
);
3027 isl_flow_free(flow
);
3032 /* Check that the dependence analysis proceeds without errors.
3033 * Earlier versions of isl would break down during the analysis
3034 * due to the use of the wrong spaces.
3036 static int test_flow(isl_ctx
*ctx
)
3039 isl_union_map
*access
, *schedule
;
3040 isl_union_map
*must_dep
, *may_dep
;
3043 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3044 access
= isl_union_map_read_from_str(ctx
, str
);
3045 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3046 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3047 "S2[] -> [1,0,0,0]; "
3048 "S3[] -> [-1,0,0,0] }";
3049 schedule
= isl_union_map_read_from_str(ctx
, str
);
3050 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
3051 isl_union_map_copy(access
), schedule
,
3052 &must_dep
, &may_dep
, NULL
, NULL
);
3053 isl_union_map_free(may_dep
);
3054 isl_union_map_free(must_dep
);
3063 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3064 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3065 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3066 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3067 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3068 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3069 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3070 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3071 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3074 int test_sv(isl_ctx
*ctx
)
3076 isl_union_map
*umap
;
3080 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
3081 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
3082 sv
= isl_union_map_is_single_valued(umap
);
3083 isl_union_map_free(umap
);
3086 if (sv_tests
[i
].sv
&& !sv
)
3087 isl_die(ctx
, isl_error_internal
,
3088 "map not detected as single valued", return -1);
3089 if (!sv_tests
[i
].sv
&& sv
)
3090 isl_die(ctx
, isl_error_internal
,
3091 "map detected as single valued", return -1);
3100 } bijective_tests
[] = {
3101 { "[N,M]->{[i,j] -> [i]}", 0 },
3102 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3103 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3104 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3105 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3106 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3107 { "[N,M]->{[i,j] -> []}", 0 },
3108 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3109 { "[N,M]->{[i,j] -> [2i]}", 0 },
3110 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3111 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3112 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3113 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3116 static int test_bijective(struct isl_ctx
*ctx
)
3122 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
3123 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
3124 bijective
= isl_map_is_bijective(map
);
3128 if (bijective_tests
[i
].bijective
&& !bijective
)
3129 isl_die(ctx
, isl_error_internal
,
3130 "map not detected as bijective", return -1);
3131 if (!bijective_tests
[i
].bijective
&& bijective
)
3132 isl_die(ctx
, isl_error_internal
,
3133 "map detected as bijective", return -1);
3139 /* Inputs for isl_pw_qpolynomial_gist tests.
3140 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3146 } pwqp_gist_tests
[] = {
3147 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3148 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3149 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3150 "{ [i] -> -1/2 + 1/2 * i }" },
3151 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3154 static int test_pwqp(struct isl_ctx
*ctx
)
3159 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3162 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3163 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3165 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3168 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3169 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3171 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3173 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3175 isl_pw_qpolynomial_free(pwqp1
);
3177 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3178 str
= pwqp_gist_tests
[i
].pwqp
;
3179 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3180 str
= pwqp_gist_tests
[i
].set
;
3181 set
= isl_set_read_from_str(ctx
, str
);
3182 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3183 str
= pwqp_gist_tests
[i
].gist
;
3184 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3185 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3186 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3187 isl_pw_qpolynomial_free(pwqp1
);
3192 isl_die(ctx
, isl_error_unknown
,
3193 "unexpected result", return -1);
3196 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3197 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3198 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3199 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3201 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3203 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3205 isl_pw_qpolynomial_free(pwqp1
);
3207 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3208 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3209 str
= "{ [x] -> x }";
3210 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3212 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3214 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3216 isl_pw_qpolynomial_free(pwqp1
);
3218 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3219 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3220 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3221 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3222 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3223 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3224 isl_pw_qpolynomial_free(pwqp1
);
3226 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3227 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3228 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3229 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3230 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3231 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3232 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3233 isl_pw_qpolynomial_free(pwqp1
);
3234 isl_pw_qpolynomial_free(pwqp2
);
3238 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3240 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3241 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3242 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3243 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3244 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3246 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3247 isl_pw_qpolynomial_free(pwqp1
);
3248 isl_pw_qpolynomial_free(pwqp2
);
3252 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3257 static int test_split_periods(isl_ctx
*ctx
)
3260 isl_pw_qpolynomial
*pwqp
;
3262 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3263 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3264 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3265 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3267 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3269 isl_pw_qpolynomial_free(pwqp
);
3277 static int test_union(isl_ctx
*ctx
)
3280 isl_union_set
*uset1
, *uset2
;
3281 isl_union_map
*umap1
, *umap2
;
3284 str
= "{ [i] : 0 <= i <= 1 }";
3285 uset1
= isl_union_set_read_from_str(ctx
, str
);
3286 str
= "{ [1] -> [0] }";
3287 umap1
= isl_union_map_read_from_str(ctx
, str
);
3289 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3290 equal
= isl_union_map_is_equal(umap1
, umap2
);
3292 isl_union_map_free(umap1
);
3293 isl_union_map_free(umap2
);
3298 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3301 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3302 umap1
= isl_union_map_read_from_str(ctx
, str
);
3303 str
= "{ A[i]; B[i] }";
3304 uset1
= isl_union_set_read_from_str(ctx
, str
);
3306 uset2
= isl_union_map_domain(umap1
);
3308 equal
= isl_union_set_is_equal(uset1
, uset2
);
3310 isl_union_set_free(uset1
);
3311 isl_union_set_free(uset2
);
3316 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3322 /* Check that computing a bound of a non-zero polynomial over an unbounded
3323 * domain does not produce a rational value.
3324 * In particular, check that the upper bound is infinity.
3326 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
3329 isl_pw_qpolynomial
*pwqp
;
3330 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
3333 str
= "{ [m,n] -> -m * n }";
3334 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3335 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3337 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3338 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3339 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
3340 isl_pw_qpolynomial_fold_free(pwf
);
3341 isl_pw_qpolynomial_fold_free(pwf2
);
3346 isl_die(ctx
, isl_error_unknown
,
3347 "expecting infinite polynomial bound", return -1);
3352 static int test_bound(isl_ctx
*ctx
)
3356 isl_pw_qpolynomial
*pwqp
;
3357 isl_pw_qpolynomial_fold
*pwf
;
3359 if (test_bound_unbounded_domain(ctx
) < 0)
3362 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
3363 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3364 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3365 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3366 isl_pw_qpolynomial_fold_free(pwf
);
3368 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3371 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3372 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3373 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3374 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3375 isl_pw_qpolynomial_fold_free(pwf
);
3377 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3383 static int test_lift(isl_ctx
*ctx
)
3386 isl_basic_map
*bmap
;
3387 isl_basic_set
*bset
;
3389 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
3390 bset
= isl_basic_set_read_from_str(ctx
, str
);
3391 bset
= isl_basic_set_lift(bset
);
3392 bmap
= isl_basic_map_from_range(bset
);
3393 bset
= isl_basic_map_domain(bmap
);
3394 isl_basic_set_free(bset
);
3403 } subset_tests
[] = {
3405 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3406 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3407 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3409 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3410 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3411 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3412 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3413 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3414 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3415 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3416 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3417 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3418 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3419 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3420 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3421 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3422 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3423 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3424 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3425 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3426 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3427 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3428 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3429 "4e0 <= -57 + i0 + i1)) or "
3430 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3431 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3432 "4e0 >= -61 + i0 + i1)) or "
3433 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3434 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3437 static int test_subset(isl_ctx
*ctx
)
3440 isl_set
*set1
, *set2
;
3443 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
3444 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
3445 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
3446 subset
= isl_set_is_subset(set1
, set2
);
3451 if (subset
!= subset_tests
[i
].subset
)
3452 isl_die(ctx
, isl_error_unknown
,
3453 "incorrect subset result", return -1);
3460 const char *minuend
;
3461 const char *subtrahend
;
3462 const char *difference
;
3463 } subtract_domain_tests
[] = {
3464 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
3465 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
3466 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
3469 static int test_subtract(isl_ctx
*ctx
)
3472 isl_union_map
*umap1
, *umap2
;
3473 isl_union_pw_multi_aff
*upma1
, *upma2
;
3474 isl_union_set
*uset
;
3477 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3478 umap1
= isl_union_map_read_from_str(ctx
,
3479 subtract_domain_tests
[i
].minuend
);
3480 uset
= isl_union_set_read_from_str(ctx
,
3481 subtract_domain_tests
[i
].subtrahend
);
3482 umap2
= isl_union_map_read_from_str(ctx
,
3483 subtract_domain_tests
[i
].difference
);
3484 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
3485 equal
= isl_union_map_is_equal(umap1
, umap2
);
3486 isl_union_map_free(umap1
);
3487 isl_union_map_free(umap2
);
3491 isl_die(ctx
, isl_error_unknown
,
3492 "incorrect subtract domain result", return -1);
3495 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3496 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3497 subtract_domain_tests
[i
].minuend
);
3498 uset
= isl_union_set_read_from_str(ctx
,
3499 subtract_domain_tests
[i
].subtrahend
);
3500 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3501 subtract_domain_tests
[i
].difference
);
3502 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
3503 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
3504 isl_union_pw_multi_aff_free(upma1
);
3505 isl_union_pw_multi_aff_free(upma2
);
3509 isl_die(ctx
, isl_error_unknown
,
3510 "incorrect subtract domain result", return -1);
3516 /* Check that intersecting the empty basic set with another basic set
3517 * does not increase the number of constraints. In particular,
3518 * the empty basic set should maintain its canonical representation.
3520 static int test_intersect(isl_ctx
*ctx
)
3523 isl_basic_set
*bset1
, *bset2
;
3525 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
3526 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
3527 n1
= isl_basic_set_n_constraint(bset1
);
3528 bset1
= isl_basic_set_intersect(bset1
, bset2
);
3529 n2
= isl_basic_set_n_constraint(bset1
);
3530 isl_basic_set_free(bset1
);
3534 isl_die(ctx
, isl_error_unknown
,
3535 "number of constraints of empty set changed",
3541 int test_factorize(isl_ctx
*ctx
)
3544 isl_basic_set
*bset
;
3547 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
3548 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
3549 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
3550 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
3551 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
3552 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
3553 "3i5 >= -2i0 - i2 + 3i4 }";
3554 bset
= isl_basic_set_read_from_str(ctx
, str
);
3555 f
= isl_basic_set_factorizer(bset
);
3556 isl_basic_set_free(bset
);
3557 isl_factorizer_free(f
);
3559 isl_die(ctx
, isl_error_unknown
,
3560 "failed to construct factorizer", return -1);
3562 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
3563 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
3564 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
3565 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
3566 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
3567 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
3568 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
3569 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
3570 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
3571 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
3572 bset
= isl_basic_set_read_from_str(ctx
, str
);
3573 f
= isl_basic_set_factorizer(bset
);
3574 isl_basic_set_free(bset
);
3575 isl_factorizer_free(f
);
3577 isl_die(ctx
, isl_error_unknown
,
3578 "failed to construct factorizer", return -1);
3583 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
3585 int *injective
= user
;
3587 *injective
= isl_map_is_injective(map
);
3590 if (*injective
< 0 || !*injective
)
3591 return isl_stat_error
;
3596 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
3597 const char *r
, const char *s
, int tilable
, int parallel
)
3601 isl_union_map
*W
, *R
, *S
;
3602 isl_union_map
*empty
;
3603 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
3604 isl_union_map
*validity
, *proximity
, *coincidence
;
3605 isl_union_map
*schedule
;
3606 isl_union_map
*test
;
3607 isl_union_set
*delta
;
3608 isl_union_set
*domain
;
3612 isl_schedule_constraints
*sc
;
3613 isl_schedule
*sched
;
3614 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
3616 D
= isl_union_set_read_from_str(ctx
, d
);
3617 W
= isl_union_map_read_from_str(ctx
, w
);
3618 R
= isl_union_map_read_from_str(ctx
, r
);
3619 S
= isl_union_map_read_from_str(ctx
, s
);
3621 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
3622 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
3624 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
3625 isl_union_map_compute_flow(isl_union_map_copy(R
),
3626 isl_union_map_copy(W
), empty
,
3627 isl_union_map_copy(S
),
3628 &dep_raw
, NULL
, NULL
, NULL
);
3629 isl_union_map_compute_flow(isl_union_map_copy(W
),
3630 isl_union_map_copy(W
),
3631 isl_union_map_copy(R
),
3632 isl_union_map_copy(S
),
3633 &dep_waw
, &dep_war
, NULL
, NULL
);
3635 dep
= isl_union_map_union(dep_waw
, dep_war
);
3636 dep
= isl_union_map_union(dep
, dep_raw
);
3637 validity
= isl_union_map_copy(dep
);
3638 coincidence
= isl_union_map_copy(dep
);
3639 proximity
= isl_union_map_copy(dep
);
3641 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
3642 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3643 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
3644 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3645 sched
= isl_schedule_constraints_compute_schedule(sc
);
3646 schedule
= isl_schedule_get_map(sched
);
3647 isl_schedule_free(sched
);
3648 isl_union_map_free(W
);
3649 isl_union_map_free(R
);
3650 isl_union_map_free(S
);
3653 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
3655 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
3656 is_complete
= isl_union_set_is_subset(D
, domain
);
3657 isl_union_set_free(D
);
3658 isl_union_set_free(domain
);
3660 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
3661 test
= isl_union_map_apply_range(test
, dep
);
3662 test
= isl_union_map_apply_range(test
, schedule
);
3664 delta
= isl_union_map_deltas(test
);
3665 if (isl_union_set_n_set(delta
) == 0) {
3669 isl_union_set_free(delta
);
3671 delta_set
= isl_set_from_union_set(delta
);
3673 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3674 for (i
= 0; i
< tilable
; ++i
)
3675 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
3676 is_tilable
= isl_set_is_subset(delta_set
, slice
);
3677 isl_set_free(slice
);
3679 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3680 for (i
= 0; i
< parallel
; ++i
)
3681 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
3682 is_parallel
= isl_set_is_subset(delta_set
, slice
);
3683 isl_set_free(slice
);
3685 origin
= isl_set_universe(isl_set_get_space(delta_set
));
3686 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
3687 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
3689 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
3690 delta_set
= isl_set_lexmin(delta_set
);
3692 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
3694 isl_set_free(origin
);
3695 isl_set_free(delta_set
);
3698 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
3699 is_injection
< 0 || is_complete
< 0)
3702 isl_die(ctx
, isl_error_unknown
,
3703 "generated schedule incomplete", return -1);
3705 isl_die(ctx
, isl_error_unknown
,
3706 "generated schedule not injective on each statement",
3709 isl_die(ctx
, isl_error_unknown
,
3710 "negative dependences in generated schedule",
3713 isl_die(ctx
, isl_error_unknown
,
3714 "generated schedule not as tilable as expected",
3717 isl_die(ctx
, isl_error_unknown
,
3718 "generated schedule not as parallel as expected",
3724 /* Compute a schedule for the given instance set, validity constraints,
3725 * proximity constraints and context and return a corresponding union map
3728 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
3729 const char *domain
, const char *validity
, const char *proximity
,
3730 const char *context
)
3735 isl_union_map
*prox
;
3736 isl_schedule_constraints
*sc
;
3737 isl_schedule
*schedule
;
3738 isl_union_map
*sched
;
3740 con
= isl_set_read_from_str(ctx
, context
);
3741 dom
= isl_union_set_read_from_str(ctx
, domain
);
3742 dep
= isl_union_map_read_from_str(ctx
, validity
);
3743 prox
= isl_union_map_read_from_str(ctx
, proximity
);
3744 sc
= isl_schedule_constraints_on_domain(dom
);
3745 sc
= isl_schedule_constraints_set_context(sc
, con
);
3746 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
3747 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
3748 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3749 sched
= isl_schedule_get_map(schedule
);
3750 isl_schedule_free(schedule
);
3755 /* Compute a schedule for the given instance set, validity constraints and
3756 * proximity constraints and return a corresponding union map representation.
3758 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
3759 const char *domain
, const char *validity
, const char *proximity
)
3761 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
3765 /* Check that a schedule can be constructed on the given domain
3766 * with the given validity and proximity constraints.
3768 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
3769 const char *validity
, const char *proximity
)
3771 isl_union_map
*sched
;
3773 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
3777 isl_union_map_free(sched
);
3781 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
3782 const char *validity
, const char *proximity
, const char *expected_sched
)
3784 isl_union_map
*sched1
, *sched2
;
3787 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
3788 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
3790 equal
= isl_union_map_is_equal(sched1
, sched2
);
3791 isl_union_map_free(sched1
);
3792 isl_union_map_free(sched2
);
3797 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
3803 /* Check that the schedule map is properly padded, i.e., that the range
3804 * lives in a single space.
3806 static int test_padded_schedule(isl_ctx
*ctx
)
3810 isl_union_map
*validity
, *proximity
;
3811 isl_schedule_constraints
*sc
;
3812 isl_schedule
*sched
;
3813 isl_union_map
*umap
;
3814 isl_union_set
*range
;
3817 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
3818 D
= isl_union_set_read_from_str(ctx
, str
);
3819 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
3820 proximity
= isl_union_map_copy(validity
);
3821 sc
= isl_schedule_constraints_on_domain(D
);
3822 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3823 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3824 sched
= isl_schedule_constraints_compute_schedule(sc
);
3825 umap
= isl_schedule_get_map(sched
);
3826 isl_schedule_free(sched
);
3827 range
= isl_union_map_range(umap
);
3828 set
= isl_set_from_union_set(range
);
3837 /* Check that conditional validity constraints are also taken into
3838 * account across bands.
3839 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
3840 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
3841 * and then check that the adjacent order constraint C[2,1]->D[2,0]
3842 * is enforced by the rest of the schedule.
3844 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
3847 isl_union_set
*domain
;
3848 isl_union_map
*validity
, *proximity
, *condition
;
3849 isl_union_map
*sink
, *source
, *dep
;
3850 isl_schedule_constraints
*sc
;
3851 isl_schedule
*schedule
;
3852 isl_union_access_info
*access
;
3853 isl_union_flow
*flow
;
3856 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3857 "A[k] : k >= 1 and k <= -1 + n; "
3858 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3859 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
3860 domain
= isl_union_set_read_from_str(ctx
, str
);
3861 sc
= isl_schedule_constraints_on_domain(domain
);
3862 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
3863 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3864 "D[k, i] -> C[1 + k, i] : "
3865 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3866 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
3867 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
3868 validity
= isl_union_map_read_from_str(ctx
, str
);
3869 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3870 str
= "[n] -> { C[k, i] -> D[k, i] : "
3871 "0 <= i <= -1 + k and k <= -1 + n }";
3872 proximity
= isl_union_map_read_from_str(ctx
, str
);
3873 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3874 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
3875 "i <= -1 + k and i >= 1 and k <= -2 + n; "
3876 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
3877 "k <= -1 + n and i >= 0 and i <= -2 + k }";
3878 condition
= isl_union_map_read_from_str(ctx
, str
);
3879 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
3880 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3881 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
3882 "i >= 0 and i <= -1 + k and k <= -1 + n and "
3883 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
3884 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
3885 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3886 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
3887 "k <= -1 + n and i >= 0 and i <= -1 + k and "
3888 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
3889 validity
= isl_union_map_read_from_str(ctx
, str
);
3890 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
3892 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3893 str
= "{ D[2,0] -> [] }";
3894 sink
= isl_union_map_read_from_str(ctx
, str
);
3895 access
= isl_union_access_info_from_sink(sink
);
3896 str
= "{ C[2,1] -> [] }";
3897 source
= isl_union_map_read_from_str(ctx
, str
);
3898 access
= isl_union_access_info_set_must_source(access
, source
);
3899 access
= isl_union_access_info_set_schedule(access
, schedule
);
3900 flow
= isl_union_access_info_compute_flow(access
);
3901 dep
= isl_union_flow_get_must_dependence(flow
);
3902 isl_union_flow_free(flow
);
3903 empty
= isl_union_map_is_empty(dep
);
3904 isl_union_map_free(dep
);
3909 isl_die(ctx
, isl_error_unknown
,
3910 "conditional validity not respected", return -1);
3915 /* Check that the test for violated conditional validity constraints
3916 * is not confused by domain compression.
3917 * In particular, earlier versions of isl would apply
3918 * a schedule on the compressed domains to the original domains,
3919 * resulting in a failure to detect that the default schedule
3920 * violates the conditional validity constraints.
3922 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
3926 isl_union_set
*domain
;
3927 isl_union_map
*validity
, *condition
;
3928 isl_schedule_constraints
*sc
;
3929 isl_schedule
*schedule
;
3930 isl_union_map
*umap
;
3933 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
3934 domain
= isl_union_set_read_from_str(ctx
, str
);
3935 sc
= isl_schedule_constraints_on_domain(domain
);
3936 str
= "{ B[1, i] -> A[0, i + 1] }";
3937 condition
= isl_union_map_read_from_str(ctx
, str
);
3938 str
= "{ A[0, i] -> B[1, i - 1] }";
3939 validity
= isl_union_map_read_from_str(ctx
, str
);
3940 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
3941 isl_union_map_copy(validity
));
3942 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3943 umap
= isl_schedule_get_map(schedule
);
3944 isl_schedule_free(schedule
);
3945 validity
= isl_union_map_apply_domain(validity
,
3946 isl_union_map_copy(umap
));
3947 validity
= isl_union_map_apply_range(validity
, umap
);
3948 map
= isl_map_from_union_map(validity
);
3949 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
3950 map
= isl_map_intersect(map
, ge
);
3951 empty
= isl_map_is_empty(map
);
3957 isl_die(ctx
, isl_error_unknown
,
3958 "conditional validity constraints not satisfied",
3964 /* Input for testing of schedule construction based on
3965 * conditional constraints.
3967 * domain is the iteration domain
3968 * flow are the flow dependences, which determine the validity and
3969 * proximity constraints
3970 * condition are the conditions on the conditional validity constraints
3971 * conditional_validity are the conditional validity constraints
3972 * outer_band_n is the expected number of members in the outer band
3977 const char *condition
;
3978 const char *conditional_validity
;
3980 } live_range_tests
[] = {
3981 /* Contrived example that illustrates that we need to keep
3982 * track of tagged condition dependences and
3983 * tagged conditional validity dependences
3984 * in isl_sched_edge separately.
3985 * In particular, the conditional validity constraints on A
3986 * cannot be satisfied,
3987 * but they can be ignored because there are no corresponding
3988 * condition constraints. However, we do have an additional
3989 * conditional validity constraint that maps to the same
3990 * dependence relation
3991 * as the condition constraint on B. If we did not make a distinction
3992 * between tagged condition and tagged conditional validity
3993 * dependences, then we
3994 * could end up treating this shared dependence as an condition
3995 * constraint on A, forcing a localization of the conditions,
3996 * which is impossible.
3998 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
3999 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4000 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4001 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4002 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4003 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4006 /* TACO 2013 Fig. 7 */
4007 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4008 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4009 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4010 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4011 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4012 "0 <= i < n and 0 <= j < n - 1 }",
4013 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4014 "0 <= i < n and 0 <= j < j' < n;"
4015 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4016 "0 <= i < i' < n and 0 <= j,j' < n;"
4017 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4018 "0 <= i,j,j' < n and j < j' }",
4021 /* TACO 2013 Fig. 7, without tags */
4022 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4023 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4024 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4025 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4026 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4027 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4028 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4029 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4032 /* TACO 2013 Fig. 12 */
4033 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4034 "S3[i,3] : 0 <= i <= 1 }",
4035 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4036 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4037 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4038 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4039 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4040 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4041 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4042 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4043 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4044 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4045 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4050 /* Test schedule construction based on conditional constraints.
4051 * In particular, check the number of members in the outer band node
4052 * as an indication of whether tiling is possible or not.
4054 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4057 isl_union_set
*domain
;
4058 isl_union_map
*condition
;
4059 isl_union_map
*flow
;
4060 isl_union_map
*validity
;
4061 isl_schedule_constraints
*sc
;
4062 isl_schedule
*schedule
;
4063 isl_schedule_node
*node
;
4066 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4068 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4071 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4072 domain
= isl_union_set_read_from_str(ctx
,
4073 live_range_tests
[i
].domain
);
4074 flow
= isl_union_map_read_from_str(ctx
,
4075 live_range_tests
[i
].flow
);
4076 condition
= isl_union_map_read_from_str(ctx
,
4077 live_range_tests
[i
].condition
);
4078 validity
= isl_union_map_read_from_str(ctx
,
4079 live_range_tests
[i
].conditional_validity
);
4080 sc
= isl_schedule_constraints_on_domain(domain
);
4081 sc
= isl_schedule_constraints_set_validity(sc
,
4082 isl_union_map_copy(flow
));
4083 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4084 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4085 condition
, validity
);
4086 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4087 node
= isl_schedule_get_root(schedule
);
4089 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4090 node
= isl_schedule_node_first_child(node
);
4091 n_member
= isl_schedule_node_band_n_member(node
);
4092 isl_schedule_node_free(node
);
4093 isl_schedule_free(schedule
);
4097 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4098 isl_die(ctx
, isl_error_unknown
,
4099 "unexpected number of members in outer band",
4105 /* Check that the schedule computed for the given instance set and
4106 * dependence relation strongly satisfies the dependences.
4107 * In particular, check that no instance is scheduled before
4108 * or together with an instance on which it depends.
4109 * Earlier versions of isl would produce a schedule that
4110 * only weakly satisfies the dependences.
4112 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4114 const char *domain
, *dep
;
4115 isl_union_map
*D
, *schedule
;
4119 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4120 "A[i0] : 0 <= i0 <= 1 }";
4121 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4122 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4123 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
4124 D
= isl_union_map_read_from_str(ctx
, dep
);
4125 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
4126 D
= isl_union_map_apply_range(D
, schedule
);
4127 map
= isl_map_from_union_map(D
);
4128 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4129 map
= isl_map_intersect(map
, ge
);
4130 empty
= isl_map_is_empty(map
);
4136 isl_die(ctx
, isl_error_unknown
,
4137 "dependences not strongly satisfied", return -1);
4142 /* Compute a schedule for input where the instance set constraints
4143 * conflict with the context constraints.
4144 * Earlier versions of isl did not properly handle this situation.
4146 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
4148 isl_union_map
*schedule
;
4149 const char *domain
, *context
;
4151 domain
= "[n] -> { A[] : n >= 0 }";
4152 context
= "[n] -> { : n < 0 }";
4153 schedule
= compute_schedule_with_context(ctx
,
4154 domain
, "{}", "{}", context
);
4155 isl_union_map_free(schedule
);
4163 /* Check that the dependence carrying step is not confused by
4164 * a bound on the coefficient size.
4165 * In particular, force the scheduler to move to a dependence carrying
4166 * step by demanding outer coincidence and bound the size of
4167 * the coefficients. Earlier versions of isl would take this
4168 * bound into account while carrying dependences, breaking
4169 * fundamental assumptions.
4170 * On the other hand, the dependence carrying step now tries
4171 * to prevent loop coalescing by default, so check that indeed
4172 * no loop coalescing occurs by comparing the computed schedule
4173 * to the expected non-coalescing schedule.
4175 static int test_bounded_coefficients_schedule(isl_ctx
*ctx
)
4177 const char *domain
, *dep
;
4180 isl_schedule_constraints
*sc
;
4181 isl_schedule
*schedule
;
4182 isl_union_map
*sched1
, *sched2
;
4185 domain
= "{ C[i0, i1] : 2 <= i0 <= 3999 and 0 <= i1 <= -1 + i0 }";
4186 dep
= "{ C[i0, i1] -> C[i0, 1 + i1] : i0 <= 3999 and i1 >= 0 and "
4188 "C[i0, -1 + i0] -> C[1 + i0, 0] : i0 <= 3998 and i0 >= 1 }";
4189 I
= isl_union_set_read_from_str(ctx
, domain
);
4190 D
= isl_union_map_read_from_str(ctx
, dep
);
4191 sc
= isl_schedule_constraints_on_domain(I
);
4192 sc
= isl_schedule_constraints_set_validity(sc
, isl_union_map_copy(D
));
4193 sc
= isl_schedule_constraints_set_coincidence(sc
, D
);
4194 isl_options_set_schedule_outer_coincidence(ctx
, 1);
4195 isl_options_set_schedule_max_coefficient(ctx
, 20);
4196 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4197 isl_options_set_schedule_max_coefficient(ctx
, -1);
4198 isl_options_set_schedule_outer_coincidence(ctx
, 0);
4199 sched1
= isl_schedule_get_map(schedule
);
4200 isl_schedule_free(schedule
);
4202 sched2
= isl_union_map_read_from_str(ctx
, "{ C[x,y] -> [x,y] }");
4203 equal
= isl_union_map_is_equal(sched1
, sched2
);
4204 isl_union_map_free(sched1
);
4205 isl_union_map_free(sched2
);
4210 isl_die(ctx
, isl_error_unknown
,
4211 "unexpected schedule", return -1);
4216 /* Check that the bounds on the coefficients are respected.
4217 * This function checks for a particular output schedule,
4218 * but the exact output is not important, only that it does
4219 * not contain any coefficients greater than 4.
4220 * It is, however, easier to check for a particular output.
4221 * This test is only run for the whole component scheduler
4222 * because the incremental scheduler produces a slightly different schedule.
4224 static int test_bounded_coefficients_schedule_whole(isl_ctx
*ctx
)
4226 const char *domain
, *dep
, *str
;
4229 isl_schedule_constraints
*sc
;
4230 isl_schedule
*schedule
;
4231 isl_union_map
*sched1
, *sched2
;
4234 domain
= "{ S_4[i, j, k] : 0 <= i < j <= 10 and 0 <= k <= 100; "
4235 "S_2[i, j] : 0 <= i < j <= 10; S_6[i, j] : 0 <= i < j <= 10 }";
4236 dep
= "{ S_2[0, j] -> S_4[0, j, 0] : 0 < j <= 10; "
4237 "S_4[0, j, 100] -> S_6[0, j] : 0 < j <= 10 }";
4238 I
= isl_union_set_read_from_str(ctx
, domain
);
4239 D
= isl_union_map_read_from_str(ctx
, dep
);
4240 sc
= isl_schedule_constraints_on_domain(I
);
4241 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4242 isl_options_set_schedule_max_constant_term(ctx
, 10);
4243 isl_options_set_schedule_max_coefficient(ctx
, 4);
4244 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4245 isl_options_set_schedule_max_coefficient(ctx
, -1);
4246 isl_options_set_schedule_max_constant_term(ctx
, -1);
4247 sched1
= isl_schedule_get_map(schedule
);
4248 isl_schedule_free(schedule
);
4250 str
= "{ S_4[i, j, k] -> [i, j, 10 - k]; "
4251 "S_2[i, j] -> [0, i, j]; S_6[i, j] -> [0, 10 + i, j] }";
4252 sched2
= isl_union_map_read_from_str(ctx
, str
);
4253 equal
= isl_union_map_is_equal(sched1
, sched2
);
4254 isl_union_map_free(sched1
);
4255 isl_union_map_free(sched2
);
4260 isl_die(ctx
, isl_error_unknown
,
4261 "unexpected schedule", return -1);
4266 /* Check that a set of schedule constraints that only allow for
4267 * a coalescing schedule still produces a schedule even if the user
4268 * request a non-coalescing schedule. Earlier versions of isl
4269 * would not handle this case correctly.
4271 static int test_coalescing_schedule(isl_ctx
*ctx
)
4273 const char *domain
, *dep
;
4276 isl_schedule_constraints
*sc
;
4277 isl_schedule
*schedule
;
4278 int treat_coalescing
;
4280 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4281 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
4282 I
= isl_union_set_read_from_str(ctx
, domain
);
4283 D
= isl_union_map_read_from_str(ctx
, dep
);
4284 sc
= isl_schedule_constraints_on_domain(I
);
4285 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4286 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4287 isl_options_set_schedule_treat_coalescing(ctx
, 1);
4288 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4289 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4290 isl_schedule_free(schedule
);
4296 /* Check that the scheduler does not perform any needless
4297 * compound skewing. Earlier versions of isl would compute
4298 * schedules in terms of transformed schedule coefficients and
4299 * would not accurately keep track of the sum of the original
4300 * schedule coefficients. It could then produce the schedule
4301 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4302 * for the input below instead of the schedule below.
4304 static int test_skewing_schedule(isl_ctx
*ctx
)
4306 const char *D
, *V
, *P
, *S
;
4308 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4309 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4310 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4311 "-1 <= a-i + b-j + c-k <= 1 }";
4313 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4315 return test_special_schedule(ctx
, D
, V
, P
, S
);
4318 int test_schedule(isl_ctx
*ctx
)
4320 const char *D
, *W
, *R
, *V
, *P
, *S
;
4321 int max_coincidence
;
4322 int treat_coalescing
;
4324 /* Handle resulting schedule with zero bands. */
4325 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4329 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4330 W
= "{ S1[t,i] -> a[t,i] }";
4331 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4332 "S1[t,i] -> a[t-1,i+1] }";
4333 S
= "{ S1[t,i] -> [t,i] }";
4334 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4337 /* Fig. 5 of CC2008 */
4338 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4340 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4341 "j >= 2 and j <= -1 + N }";
4342 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4343 "j >= 2 and j <= -1 + N; "
4344 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4345 "j >= 2 and j <= -1 + N }";
4346 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4347 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4350 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4351 W
= "{ S1[i] -> a[i] }";
4352 R
= "{ S2[i] -> a[i+1] }";
4353 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4354 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4357 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4358 W
= "{ S1[i] -> a[i] }";
4359 R
= "{ S2[i] -> a[9-i] }";
4360 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4361 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4364 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4365 W
= "{ S1[i] -> a[i] }";
4366 R
= "[N] -> { S2[i] -> a[N-1-i] }";
4367 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4368 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4371 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4372 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4373 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4374 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4375 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4378 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4379 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4380 R
= "{ S2[i,j] -> a[i-1,j] }";
4381 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4382 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4385 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4386 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4387 R
= "{ S2[i,j] -> a[i,j-1] }";
4388 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4389 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4392 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4393 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4394 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4395 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4396 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4397 "S_0[] -> [0, 0, 0] }";
4398 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
4400 ctx
->opt
->schedule_parametric
= 0;
4401 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4403 ctx
->opt
->schedule_parametric
= 1;
4405 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4406 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4407 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4408 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4409 "S4[i] -> a[i,N] }";
4410 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4411 "S4[i] -> [4,i,0] }";
4412 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
4413 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
4414 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4416 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
4418 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4419 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4421 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4423 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4425 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4426 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4429 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4430 " S_2[t] : t >= 0 and t <= -1 + N; "
4431 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4433 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4434 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4435 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4436 "i >= 0 and i <= -1 + N }";
4437 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4438 "i >= 0 and i <= -1 + N; "
4439 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4440 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4441 " S_0[t] -> [0, t, 0] }";
4443 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4445 ctx
->opt
->schedule_parametric
= 0;
4446 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4448 ctx
->opt
->schedule_parametric
= 1;
4450 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4451 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4452 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
4455 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4456 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4457 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4458 "j >= 0 and j <= -1 + N; "
4459 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4460 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4461 "j >= 0 and j <= -1 + N; "
4462 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4463 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4464 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4467 D
= "{ S_0[i] : i >= 0 }";
4468 W
= "{ S_0[i] -> a[i] : i >= 0 }";
4469 R
= "{ S_0[i] -> a[0] : i >= 0 }";
4470 S
= "{ S_0[i] -> [0, i, 0] }";
4471 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4474 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
4475 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
4476 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
4477 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
4478 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4481 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
4482 "k <= -1 + n and k >= 0 }";
4483 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
4484 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
4485 "k <= -1 + n and k >= 0; "
4486 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
4487 "k <= -1 + n and k >= 0; "
4488 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
4489 "k <= -1 + n and k >= 0 }";
4490 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
4491 ctx
->opt
->schedule_outer_coincidence
= 1;
4492 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4494 ctx
->opt
->schedule_outer_coincidence
= 0;
4496 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
4497 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
4498 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
4499 "Stmt_for_body24[i0, i1, 1, 0]:"
4500 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
4501 "Stmt_for_body7[i0, i1, i2]:"
4502 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
4505 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
4506 "Stmt_for_body24[1, i1, i2, i3]:"
4507 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
4509 "Stmt_for_body24[0, i1, i2, i3] -> "
4510 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
4511 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
4513 "Stmt_for_body24[0, i1, i2, i3] ->"
4514 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
4515 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
4516 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
4517 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
4518 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
4519 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
4520 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
4521 "i1 <= 6 and i1 >= 0;"
4522 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
4523 "Stmt_for_body7[i0, i1, i2] -> "
4524 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
4525 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
4526 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
4527 "Stmt_for_body7[i0, i1, i2] -> "
4528 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
4529 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
4530 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
4533 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4534 isl_options_set_schedule_treat_coalescing(ctx
, 0);
4535 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4537 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4539 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
4540 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
4541 "j >= 1 and j <= 7;"
4542 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
4543 "j >= 1 and j <= 8 }";
4545 S
= "{ S_0[i, j] -> [i + j, i] }";
4546 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4547 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4549 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4551 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
4552 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
4553 "j >= 0 and j <= -1 + i }";
4554 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
4555 "i <= -1 + N and j >= 0;"
4556 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
4559 S
= "{ S_0[i, j] -> [i, j] }";
4560 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4561 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4563 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4565 /* Test both algorithms on a case with only proximity dependences. */
4566 D
= "{ S[i,j] : 0 <= i <= 10 }";
4568 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
4569 S
= "{ S[i, j] -> [j, i] }";
4570 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4571 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4573 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4574 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4577 D
= "{ A[a]; B[] }";
4579 P
= "{ A[a] -> B[] }";
4580 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4583 if (test_padded_schedule(ctx
) < 0)
4586 /* Check that check for progress is not confused by rational
4589 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
4590 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
4592 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
4593 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
4595 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4596 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4598 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4600 /* Check that we allow schedule rows that are only non-trivial
4601 * on some full-dimensional domains.
4603 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
4604 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
4605 "S1[j] -> S2[1] : 0 <= j <= 1 }";
4607 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4608 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4610 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4612 if (test_conditional_schedule_constraints(ctx
) < 0)
4615 if (test_strongly_satisfying_schedule(ctx
) < 0)
4618 if (test_conflicting_context_schedule(ctx
) < 0)
4621 if (test_bounded_coefficients_schedule(ctx
) < 0)
4623 if (test_coalescing_schedule(ctx
) < 0)
4625 if (test_skewing_schedule(ctx
) < 0)
4631 /* Perform scheduling tests using the whole component scheduler.
4633 static int test_schedule_whole(isl_ctx
*ctx
)
4638 whole
= isl_options_get_schedule_whole_component(ctx
);
4639 isl_options_set_schedule_whole_component(ctx
, 1);
4640 r
= test_schedule(ctx
);
4642 r
= test_bounded_coefficients_schedule_whole(ctx
);
4643 isl_options_set_schedule_whole_component(ctx
, whole
);
4648 /* Perform scheduling tests using the incremental scheduler.
4650 static int test_schedule_incremental(isl_ctx
*ctx
)
4655 whole
= isl_options_get_schedule_whole_component(ctx
);
4656 isl_options_set_schedule_whole_component(ctx
, 0);
4657 r
= test_schedule(ctx
);
4658 isl_options_set_schedule_whole_component(ctx
, whole
);
4663 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
4665 isl_union_map
*umap
;
4668 umap
= isl_union_map_read_from_str(ctx
, str
);
4669 test
= isl_union_map_plain_is_injective(umap
);
4670 isl_union_map_free(umap
);
4673 if (test
== injective
)
4676 isl_die(ctx
, isl_error_unknown
,
4677 "map not detected as injective", return -1);
4679 isl_die(ctx
, isl_error_unknown
,
4680 "map detected as injective", return -1);
4683 int test_injective(isl_ctx
*ctx
)
4687 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
4689 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
4691 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
4693 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
4695 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
4697 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
4699 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
4701 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
4704 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
4705 if (test_plain_injective(ctx
, str
, 1))
4707 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
4708 if (test_plain_injective(ctx
, str
, 0))
4714 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
4722 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
4723 equal
= isl_aff_plain_is_equal(aff
, aff2
);
4729 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
4733 equal
= aff_plain_is_equal(aff
, str
);
4737 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
4738 "result not as expected", return -1);
4742 /* Is "upa" obviously equal to the isl_union_pw_aff represented by "str"?
4744 static isl_bool
union_pw_aff_plain_is_equal(__isl_keep isl_union_pw_aff
*upa
,
4748 isl_union_pw_aff
*upa2
;
4752 return isl_bool_error
;
4754 ctx
= isl_union_pw_aff_get_ctx(upa
);
4755 upa2
= isl_union_pw_aff_read_from_str(ctx
, str
);
4756 equal
= isl_union_pw_aff_plain_is_equal(upa
, upa2
);
4757 isl_union_pw_aff_free(upa2
);
4762 /* Check that "upa" is obviously equal to the isl_union_pw_aff
4763 * represented by "str".
4765 static isl_stat
union_pw_aff_check_plain_equal(__isl_keep isl_union_pw_aff
*upa
,
4770 equal
= union_pw_aff_plain_is_equal(upa
, str
);
4772 return isl_stat_error
;
4774 isl_die(isl_union_pw_aff_get_ctx(upa
), isl_error_unknown
,
4775 "result not as expected", return isl_stat_error
);
4779 /* Basic tests on isl_union_pw_aff.
4781 * In particular, check that isl_union_pw_aff_aff_on_domain
4782 * aligns the parameters of the input objects and
4783 * that isl_union_pw_aff_param_on_domain_id properly
4784 * introduces the parameter.
4786 static int test_upa(isl_ctx
*ctx
)
4791 isl_union_set
*domain
;
4792 isl_union_pw_aff
*upa
;
4795 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
4796 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
4797 domain
= isl_union_set_read_from_str(ctx
, str
);
4798 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
4799 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
4800 ok
= union_pw_aff_check_plain_equal(upa
, str
);
4801 isl_union_pw_aff_free(upa
);
4805 id
= isl_id_alloc(ctx
, "N", NULL
);
4806 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
4807 domain
= isl_union_set_read_from_str(ctx
, str
);
4808 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
4809 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
4810 ok
= union_pw_aff_check_plain_equal(upa
, str
);
4811 isl_union_pw_aff_free(upa
);
4819 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
4820 __isl_take isl_aff
*aff2
);
4822 ['+'] = { &isl_aff_add
},
4823 ['-'] = { &isl_aff_sub
},
4824 ['*'] = { &isl_aff_mul
},
4825 ['/'] = { &isl_aff_div
},
4833 } aff_bin_tests
[] = {
4834 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
4835 "{ [i] -> [2i] }" },
4836 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
4838 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
4839 "{ [i] -> [2i] }" },
4840 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
4841 "{ [i] -> [2i] }" },
4842 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
4843 "{ [i] -> [i/2] }" },
4844 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
4846 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
4847 "{ [i] -> [NaN] }" },
4848 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
4849 "{ [i] -> [NaN] }" },
4850 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
4851 "{ [i] -> [NaN] }" },
4852 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
4853 "{ [i] -> [NaN] }" },
4854 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
4855 "{ [i] -> [NaN] }" },
4856 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
4857 "{ [i] -> [NaN] }" },
4858 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
4859 "{ [i] -> [NaN] }" },
4860 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
4861 "{ [i] -> [NaN] }" },
4862 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
4863 "{ [i] -> [NaN] }" },
4864 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
4865 "{ [i] -> [NaN] }" },
4866 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
4867 "{ [i] -> [NaN] }" },
4868 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
4869 "{ [i] -> [NaN] }" },
4872 /* Perform some basic tests of binary operations on isl_aff objects.
4874 static int test_bin_aff(isl_ctx
*ctx
)
4877 isl_aff
*aff1
, *aff2
, *res
;
4878 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
4879 __isl_take isl_aff
*aff2
);
4882 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
4883 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
4884 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
4885 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
4886 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
4887 aff1
= fn(aff1
, aff2
);
4888 if (isl_aff_is_nan(res
))
4889 ok
= isl_aff_is_nan(aff1
);
4891 ok
= isl_aff_plain_is_equal(aff1
, res
);
4897 isl_die(ctx
, isl_error_unknown
,
4898 "unexpected result", return -1);
4905 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
4906 __isl_take isl_pw_aff
*pa2
);
4907 } pw_aff_bin_op
[] = {
4908 ['m'] = { &isl_pw_aff_min
},
4909 ['M'] = { &isl_pw_aff_max
},
4912 /* Inputs for binary isl_pw_aff operation tests.
4913 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
4914 * defined by pw_aff_bin_op, and "res" is the expected result.
4921 } pw_aff_bin_tests
[] = {
4922 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
4924 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
4926 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
4927 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
4928 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
4929 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
4930 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
4931 "{ [i] -> [NaN] }" },
4932 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
4933 "{ [i] -> [NaN] }" },
4936 /* Perform some basic tests of binary operations on isl_pw_aff objects.
4938 static int test_bin_pw_aff(isl_ctx
*ctx
)
4942 isl_pw_aff
*pa1
, *pa2
, *res
;
4944 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
4945 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
4946 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
4947 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
4948 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
4949 if (isl_pw_aff_involves_nan(res
))
4950 ok
= isl_pw_aff_involves_nan(pa1
);
4952 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
4953 isl_pw_aff_free(pa1
);
4954 isl_pw_aff_free(res
);
4958 isl_die(ctx
, isl_error_unknown
,
4959 "unexpected result", return -1);
4966 __isl_give isl_union_pw_multi_aff
*(*fn
)(
4967 __isl_take isl_union_pw_multi_aff
*upma1
,
4968 __isl_take isl_union_pw_multi_aff
*upma2
);
4972 } upma_bin_tests
[] = {
4973 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
4974 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
4975 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
4976 "{ B[x] -> [2] : x >= 0 }",
4977 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
4978 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
4979 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
4980 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
4981 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
4982 "D[i] -> B[2] : i >= 5 }" },
4983 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
4984 "{ B[x] -> C[2] : x > 0 }",
4985 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
4986 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
4987 "{ B[x] -> A[2] : x >= 0 }",
4988 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
4991 /* Perform some basic tests of binary operations on
4992 * isl_union_pw_multi_aff objects.
4994 static int test_bin_upma(isl_ctx
*ctx
)
4997 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
5000 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
5001 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5002 upma_bin_tests
[i
].arg1
);
5003 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5004 upma_bin_tests
[i
].arg2
);
5005 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5006 upma_bin_tests
[i
].res
);
5007 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
5008 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
5009 isl_union_pw_multi_aff_free(upma1
);
5010 isl_union_pw_multi_aff_free(res
);
5014 isl_die(ctx
, isl_error_unknown
,
5015 "unexpected result", return -1);
5022 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5023 __isl_take isl_union_pw_multi_aff
*upma1
,
5024 __isl_take isl_union_pw_multi_aff
*upma2
);
5027 } upma_bin_fail_tests
[] = {
5028 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5029 "{ B[x] -> C[2] : x >= 0 }" },
5032 /* Perform some basic tests of binary operations on
5033 * isl_union_pw_multi_aff objects that are expected to fail.
5035 static int test_bin_upma_fail(isl_ctx
*ctx
)
5038 isl_union_pw_multi_aff
*upma1
, *upma2
;
5041 on_error
= isl_options_get_on_error(ctx
);
5042 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5043 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5044 for (i
= 0; i
< n
; ++i
) {
5045 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5046 upma_bin_fail_tests
[i
].arg1
);
5047 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5048 upma_bin_fail_tests
[i
].arg2
);
5049 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5050 isl_union_pw_multi_aff_free(upma1
);
5054 isl_options_set_on_error(ctx
, on_error
);
5056 isl_die(ctx
, isl_error_unknown
,
5057 "operation not expected to succeed", return -1);
5062 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5063 * "fn" is the function that is tested.
5064 * "arg" is a string description of the input.
5065 * "res" is a string description of the expected result.
5068 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5071 } mpa_un_tests
[] = {
5072 { &isl_multi_pw_aff_range_factor_domain
,
5073 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5074 "{ A[x] -> B[(1 : x >= 5)] }" },
5075 { &isl_multi_pw_aff_range_factor_range
,
5076 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5077 "{ A[y] -> C[(2 : y <= 10)] }" },
5078 { &isl_multi_pw_aff_range_factor_domain
,
5079 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5080 "{ A[x] -> B[(1 : x >= 5)] }" },
5081 { &isl_multi_pw_aff_range_factor_range
,
5082 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5083 "{ A[y] -> C[] }" },
5084 { &isl_multi_pw_aff_range_factor_domain
,
5085 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5086 "{ A[x] -> B[] }" },
5087 { &isl_multi_pw_aff_range_factor_range
,
5088 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5089 "{ A[y] -> C[(2 : y <= 10)] }" },
5090 { &isl_multi_pw_aff_range_factor_domain
,
5091 "{ A[x] -> [B[] -> C[]] }",
5092 "{ A[x] -> B[] }" },
5093 { &isl_multi_pw_aff_range_factor_range
,
5094 "{ A[x] -> [B[] -> C[]] }",
5095 "{ A[y] -> C[] }" },
5096 { &isl_multi_pw_aff_factor_range
,
5099 { &isl_multi_pw_aff_range_factor_domain
,
5100 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5101 "{ A[x] -> B[] : x >= 0 }" },
5102 { &isl_multi_pw_aff_range_factor_range
,
5103 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5104 "{ A[y] -> C[] : y >= 0 }" },
5105 { &isl_multi_pw_aff_factor_range
,
5106 "[N] -> { [B[] -> C[]] : N >= 0 }",
5107 "[N] -> { C[] : N >= 0 }" },
5110 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5112 static int test_un_mpa(isl_ctx
*ctx
)
5116 isl_multi_pw_aff
*mpa
, *res
;
5118 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5119 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5120 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5121 mpa
= mpa_un_tests
[i
].fn(mpa
);
5122 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5123 isl_multi_pw_aff_free(mpa
);
5124 isl_multi_pw_aff_free(res
);
5128 isl_die(ctx
, isl_error_unknown
,
5129 "unexpected result", return -1);
5135 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5136 * "fn" is the function that is tested.
5137 * "arg1" and "arg2" are string descriptions of the inputs.
5138 * "res" is a string description of the expected result.
5141 __isl_give isl_multi_pw_aff
*(*fn
)(
5142 __isl_take isl_multi_pw_aff
*mpa1
,
5143 __isl_take isl_multi_pw_aff
*mpa2
);
5147 } mpa_bin_tests
[] = {
5148 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
5150 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
5151 "{ A[x] -> [(x : x <= 10)] }",
5152 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5153 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5154 "{ A[x] -> [] : x <= 10 }",
5155 "{ A[x] -> [] : 5 <= x <= 10 }" },
5156 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5157 "[N] -> { A[x] -> [] : x <= N }",
5158 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5159 { &isl_multi_pw_aff_add
,
5160 "[N] -> { A[x] -> [] : x <= N }",
5161 "{ A[x] -> [] : x >= 5 }",
5162 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5163 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5164 "{ A[y] -> C[(2 : y <= 10)] }",
5165 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5166 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5167 "{ A[y] -> C[2] : y <= 10 }",
5168 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5169 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5170 "[N] -> { A[y] -> C[2] : y <= N }",
5171 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5172 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
5173 "{ A[y] -> C[2] : y <= 10 }",
5174 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5175 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5176 "{ A[] -> [B[1] -> C[2]] }" },
5177 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5178 "{ A[] -> [B[] -> C[]] }" },
5179 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5180 "{ A[y] -> C[] : y <= 10 }",
5181 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5182 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
5183 "{ A[x] -> B[(1 : x >= 5)] }",
5184 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5185 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5186 "{ A[y] -> C[(2 : y <= 10)] }",
5187 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5188 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5189 "{ A[y] -> C[] : y <= 10 }",
5190 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5191 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
5192 "{ A[x] -> B[(1 : x >= 5)] }",
5193 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5194 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5195 "[N] -> { A[y] -> C[] : y <= N }",
5196 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5197 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
5198 "{ A[x] -> B[(1 : x >= 5)] }",
5199 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5200 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
5201 "{ A[y] -> C[] : y <= 10 }",
5202 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5203 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5204 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5205 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5206 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5207 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5208 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5209 "{ A[a,b] -> C[b + 2a] }" },
5210 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5211 "{ B[i,j] -> C[i + 2j] }",
5212 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5213 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5214 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5215 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5216 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5217 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5218 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5219 "{ B[i,j] -> C[] }",
5220 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5221 "{ A[a,b] -> C[] }" },
5222 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5223 "{ B[i,j] -> C[] : i > j }",
5224 "{ A[a,b] -> B[b,a] }",
5225 "{ A[a,b] -> C[] : b > a }" },
5226 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5227 "{ B[i,j] -> C[] : j > 5 }",
5228 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5229 "{ A[a,b] -> C[] : b > a > 5 }" },
5230 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5231 "[N] -> { B[i,j] -> C[] : j > N }",
5232 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5233 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5234 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5235 "[M,N] -> { B[] -> C[] : N > 5 }",
5236 "[M,N] -> { A[] -> B[] : M > N }",
5237 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5240 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5242 static int test_bin_mpa(isl_ctx
*ctx
)
5246 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
5248 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
5249 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
5250 mpa_bin_tests
[i
].arg1
);
5251 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
5252 mpa_bin_tests
[i
].arg2
);
5253 res
= isl_multi_pw_aff_read_from_str(ctx
,
5254 mpa_bin_tests
[i
].res
);
5255 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
5256 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
5257 isl_multi_pw_aff_free(mpa1
);
5258 isl_multi_pw_aff_free(res
);
5262 isl_die(ctx
, isl_error_unknown
,
5263 "unexpected result", return -1);
5269 /* Inputs for basic tests of unary operations on
5270 * isl_multi_union_pw_aff objects.
5271 * "fn" is the function that is tested.
5272 * "arg" is a string description of the input.
5273 * "res" is a string description of the expected result.
5276 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5277 __isl_take isl_multi_union_pw_aff
*mupa
);
5280 } mupa_un_tests
[] = {
5281 { &isl_multi_union_pw_aff_factor_range
,
5282 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5283 "C[{ A[] -> [2] }]" },
5284 { &isl_multi_union_pw_aff_factor_range
,
5285 "[B[] -> C[{ A[] -> [2] }]]",
5286 "C[{ A[] -> [2] }]" },
5287 { &isl_multi_union_pw_aff_factor_range
,
5288 "[B[{ A[] -> [1] }] -> C[]]",
5290 { &isl_multi_union_pw_aff_factor_range
,
5293 { &isl_multi_union_pw_aff_factor_range
,
5294 "([B[] -> C[]] : { A[x] : x >= 0 })",
5295 "(C[] : { A[x] : x >= 0 })" },
5296 { &isl_multi_union_pw_aff_factor_range
,
5297 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
5298 "[N] -> (C[] : { A[x] : x <= N })" },
5299 { &isl_multi_union_pw_aff_factor_range
,
5300 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
5301 "[N] -> (C[] : { : N >= 0 })" },
5304 /* Perform some basic tests of unary operations on
5305 * isl_multi_union_pw_aff objects.
5307 static int test_un_mupa(isl_ctx
*ctx
)
5311 isl_multi_union_pw_aff
*mupa
, *res
;
5313 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
5314 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5315 mupa_un_tests
[i
].arg
);
5316 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5317 mupa_un_tests
[i
].res
);
5318 mupa
= mupa_un_tests
[i
].fn(mupa
);
5319 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5320 isl_multi_union_pw_aff_free(mupa
);
5321 isl_multi_union_pw_aff_free(res
);
5325 isl_die(ctx
, isl_error_unknown
,
5326 "unexpected result", return -1);
5332 /* Inputs for basic tests of binary operations on
5333 * isl_multi_union_pw_aff objects.
5334 * "fn" is the function that is tested.
5335 * "arg1" and "arg2" are string descriptions of the inputs.
5336 * "res" is a string description of the expected result.
5339 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5340 __isl_take isl_multi_union_pw_aff
*mupa1
,
5341 __isl_take isl_multi_union_pw_aff
*mupa2
);
5345 } mupa_bin_tests
[] = {
5346 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5347 "[{ A[] -> [3] }]" },
5348 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5349 "[{ A[] -> [-1] }]" },
5350 { &isl_multi_union_pw_aff_add
,
5351 "[{ A[] -> [1]; B[] -> [4] }]",
5352 "[{ A[] -> [2]; C[] -> [5] }]",
5353 "[{ A[] -> [3] }]" },
5354 { &isl_multi_union_pw_aff_union_add
,
5355 "[{ A[] -> [1]; B[] -> [4] }]",
5356 "[{ A[] -> [2]; C[] -> [5] }]",
5357 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
5358 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5359 "[{ A[x] -> [(x)] : x <= 10 }]",
5360 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
5361 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5362 "([] : { A[x] : x <= 10 })",
5363 "([] : { A[x] : 5 <= x <= 10 })" },
5364 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5365 "[N] -> ([] : { A[x] : x <= N })",
5366 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
5367 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
5368 "([] : { A[x] : x <= 10 })",
5369 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
5370 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5371 "[{ A[x] -> [(x)] : x <= 10 }]",
5372 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
5373 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
5374 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
5375 "([] : { A[x] : x <= 10 })",
5376 "([] : { A[x] })" },
5377 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
5378 "[N] -> ([] : { A[x] : x >= N })",
5379 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
5380 { &isl_multi_union_pw_aff_union_add
,
5381 "[N] -> ([] : { A[] : N >= 0})",
5382 "[N] -> ([] : { A[] : N <= 0})",
5383 "[N] -> ([] : { A[] })" },
5384 { &isl_multi_union_pw_aff_union_add
,
5385 "[N] -> ([] : { A[] })",
5386 "[N] -> ([] : { : })",
5387 "[N] -> ([] : { : })" },
5388 { &isl_multi_union_pw_aff_union_add
,
5389 "[N] -> ([] : { : })",
5390 "[N] -> ([] : { A[] })",
5391 "[N] -> ([] : { : })" },
5392 { &isl_multi_union_pw_aff_union_add
,
5393 "[N] -> ([] : { : N >= 0})",
5394 "[N] -> ([] : { : N <= 0})",
5395 "[N] -> ([] : { : })" },
5396 { &isl_multi_union_pw_aff_range_product
,
5397 "B[{ A[] -> [1] }]",
5398 "C[{ A[] -> [2] }]",
5399 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
5400 { &isl_multi_union_pw_aff_range_product
,
5401 "(B[] : { A[x] : x >= 5 })",
5402 "(C[] : { A[x] : x <= 10 })",
5403 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
5404 { &isl_multi_union_pw_aff_range_product
,
5405 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5406 "(C[] : { A[x] : x <= 10 })",
5407 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
5408 { &isl_multi_union_pw_aff_range_product
,
5409 "(C[] : { A[x] : x <= 10 })",
5410 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5411 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
5412 { &isl_multi_union_pw_aff_range_product
,
5413 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5414 "[N] -> (C[] : { A[x] : x <= N })",
5415 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
5416 { &isl_multi_union_pw_aff_range_product
,
5417 "[N] -> (C[] : { A[x] : x <= N })",
5418 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5419 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
5420 { &isl_multi_union_pw_aff_range_product
,
5421 "B[{ A[] -> [1]; D[] -> [3] }]",
5422 "C[{ A[] -> [2] }]",
5423 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
5426 /* Perform some basic tests of binary operations on
5427 * isl_multi_union_pw_aff objects.
5429 static int test_bin_mupa(isl_ctx
*ctx
)
5433 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
5435 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
5436 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
5437 mupa_bin_tests
[i
].arg1
);
5438 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
5439 mupa_bin_tests
[i
].arg2
);
5440 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5441 mupa_bin_tests
[i
].res
);
5442 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
5443 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
5444 isl_multi_union_pw_aff_free(mupa1
);
5445 isl_multi_union_pw_aff_free(res
);
5449 isl_die(ctx
, isl_error_unknown
,
5450 "unexpected result", return -1);
5456 /* Inputs for basic tests of binary operations on
5457 * pairs of isl_multi_union_pw_aff and isl_set objects.
5458 * "fn" is the function that is tested.
5459 * "arg1" and "arg2" are string descriptions of the inputs.
5460 * "res" is a string description of the expected result.
5463 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5464 __isl_take isl_multi_union_pw_aff
*mupa
,
5465 __isl_take isl_set
*set
);
5469 } mupa_set_tests
[] = {
5470 { &isl_multi_union_pw_aff_intersect_range
,
5471 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
5472 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
5473 { &isl_multi_union_pw_aff_intersect_range
,
5474 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
5475 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
5476 { &isl_multi_union_pw_aff_intersect_range
,
5477 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
5478 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
5479 { &isl_multi_union_pw_aff_intersect_range
,
5480 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
5481 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
5482 { &isl_multi_union_pw_aff_intersect_range
,
5483 "C[]", "{ C[] }", "C[]" },
5484 { &isl_multi_union_pw_aff_intersect_range
,
5485 "[N] -> (C[] : { : N >= 0 })",
5487 "[N] -> (C[] : { : N >= 0 })" },
5488 { &isl_multi_union_pw_aff_intersect_range
,
5489 "(C[] : { A[a,b] })",
5491 "(C[] : { A[a,b] })" },
5492 { &isl_multi_union_pw_aff_intersect_range
,
5493 "[N] -> (C[] : { A[a,b] : a,b <= N })",
5495 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
5496 { &isl_multi_union_pw_aff_intersect_range
,
5498 "[N] -> { C[] : N >= 0 }",
5499 "[N] -> (C[] : { : N >= 0 })" },
5500 { &isl_multi_union_pw_aff_intersect_range
,
5501 "(C[] : { A[a,b] })",
5502 "[N] -> { C[] : N >= 0 }",
5503 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5504 { &isl_multi_union_pw_aff_intersect_range
,
5505 "[N] -> (C[] : { : N >= 0 })",
5506 "[N] -> { C[] : N < 1024 }",
5507 "[N] -> (C[] : { : 0 <= N < 1024 })" },
5508 { &isl_multi_union_pw_aff_intersect_params
,
5509 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
5510 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
5511 { &isl_multi_union_pw_aff_intersect_params
,
5512 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
5513 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
5514 { &isl_multi_union_pw_aff_intersect_params
,
5515 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
5516 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
5517 { &isl_multi_union_pw_aff_intersect_params
,
5518 "C[]", "[N] -> { : N >= 0 }",
5519 "[N] -> (C[] : { : N >= 0 })" },
5520 { &isl_multi_union_pw_aff_intersect_params
,
5521 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
5522 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5523 { &isl_multi_union_pw_aff_intersect_params
,
5524 "[N] -> (C[] : { A[a,N] })", "{ : }",
5525 "[N] -> (C[] : { A[a,N] })" },
5526 { &isl_multi_union_pw_aff_intersect_params
,
5527 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
5528 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
5531 /* Perform some basic tests of binary operations on
5532 * pairs of isl_multi_union_pw_aff and isl_set objects.
5534 static int test_mupa_set(isl_ctx
*ctx
)
5538 isl_multi_union_pw_aff
*mupa
, *res
;
5541 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
5542 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5543 mupa_set_tests
[i
].arg1
);
5544 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
5545 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5546 mupa_set_tests
[i
].res
);
5547 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
5548 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5549 isl_multi_union_pw_aff_free(mupa
);
5550 isl_multi_union_pw_aff_free(res
);
5554 isl_die(ctx
, isl_error_unknown
,
5555 "unexpected result", return -1);
5561 /* Inputs for basic tests of binary operations on
5562 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5563 * "fn" is the function that is tested.
5564 * "arg1" and "arg2" are string descriptions of the inputs.
5565 * "res" is a string description of the expected result.
5568 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5569 __isl_take isl_multi_union_pw_aff
*mupa
,
5570 __isl_take isl_union_set
*uset
);
5574 } mupa_uset_tests
[] = {
5575 { &isl_multi_union_pw_aff_intersect_domain
,
5576 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
5577 "C[{ B[i,i] -> [3i] }]" },
5578 { &isl_multi_union_pw_aff_intersect_domain
,
5579 "(C[] : { B[i,j] })", "{ B[i,i] }",
5580 "(C[] : { B[i,i] })" },
5581 { &isl_multi_union_pw_aff_intersect_domain
,
5582 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
5583 "[N] -> (C[] : { B[N,N] })" },
5584 { &isl_multi_union_pw_aff_intersect_domain
,
5585 "C[]", "{ B[i,i] }",
5586 "(C[] : { B[i,i] })" },
5587 { &isl_multi_union_pw_aff_intersect_domain
,
5588 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
5589 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
5592 /* Perform some basic tests of binary operations on
5593 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5595 static int test_mupa_uset(isl_ctx
*ctx
)
5599 isl_multi_union_pw_aff
*mupa
, *res
;
5600 isl_union_set
*uset
;
5602 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
5603 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5604 mupa_uset_tests
[i
].arg1
);
5605 uset
= isl_union_set_read_from_str(ctx
,
5606 mupa_uset_tests
[i
].arg2
);
5607 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5608 mupa_uset_tests
[i
].res
);
5609 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
5610 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5611 isl_multi_union_pw_aff_free(mupa
);
5612 isl_multi_union_pw_aff_free(res
);
5616 isl_die(ctx
, isl_error_unknown
,
5617 "unexpected result", return -1);
5623 /* Inputs for basic tests of binary operations on
5624 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5625 * "fn" is the function that is tested.
5626 * "arg1" and "arg2" are string descriptions of the inputs.
5627 * "res" is a string description of the expected result.
5630 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5631 __isl_take isl_multi_union_pw_aff
*mupa
,
5632 __isl_take isl_multi_aff
*ma
);
5636 } mupa_ma_tests
[] = {
5637 { &isl_multi_union_pw_aff_apply_multi_aff
,
5638 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5639 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5640 "{ C[a,b] -> D[b,a] }",
5641 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
5642 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
5643 { &isl_multi_union_pw_aff_apply_multi_aff
,
5644 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
5645 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5646 "{ C[a,b] -> D[b,a] }",
5647 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
5648 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
5649 { &isl_multi_union_pw_aff_apply_multi_aff
,
5650 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5651 "[N] -> { C[a] -> D[a + N] }",
5652 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
5653 { &isl_multi_union_pw_aff_apply_multi_aff
,
5657 { &isl_multi_union_pw_aff_apply_multi_aff
,
5658 "[N] -> (C[] : { : N >= 0 })",
5660 "[N] -> (D[] : { : N >= 0 })" },
5661 { &isl_multi_union_pw_aff_apply_multi_aff
,
5663 "[N] -> { C[] -> D[N] }",
5664 "[N] -> D[{ [N] }]" },
5665 { &isl_multi_union_pw_aff_apply_multi_aff
,
5666 "(C[] : { A[i,j] : i >= j })",
5668 "(D[] : { A[i,j] : i >= j })" },
5669 { &isl_multi_union_pw_aff_apply_multi_aff
,
5670 "[N] -> (C[] : { A[i,j] : N >= 0 })",
5672 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
5673 { &isl_multi_union_pw_aff_apply_multi_aff
,
5674 "(C[] : { A[i,j] : i >= j })",
5675 "[N] -> { C[] -> D[N] }",
5676 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
5679 /* Perform some basic tests of binary operations on
5680 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5682 static int test_mupa_ma(isl_ctx
*ctx
)
5686 isl_multi_union_pw_aff
*mupa
, *res
;
5689 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
5690 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5691 mupa_ma_tests
[i
].arg1
);
5692 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
5693 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5694 mupa_ma_tests
[i
].res
);
5695 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
5696 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5697 isl_multi_union_pw_aff_free(mupa
);
5698 isl_multi_union_pw_aff_free(res
);
5702 isl_die(ctx
, isl_error_unknown
,
5703 "unexpected result", return -1);
5709 /* Inputs for basic tests of binary operations on
5710 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
5711 * "fn" is the function that is tested.
5712 * "arg1" and "arg2" are string descriptions of the inputs.
5713 * "res" is a string description of the expected result.
5716 __isl_give isl_union_pw_aff
*(*fn
)(
5717 __isl_take isl_multi_union_pw_aff
*mupa
,
5718 __isl_take isl_pw_aff
*pa
);
5722 } mupa_pa_tests
[] = {
5723 { &isl_multi_union_pw_aff_apply_pw_aff
,
5724 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5725 "[N] -> { C[a] -> [a + N] }",
5726 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
5727 { &isl_multi_union_pw_aff_apply_pw_aff
,
5728 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5729 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
5730 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
5731 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
5732 { &isl_multi_union_pw_aff_apply_pw_aff
,
5734 "[N] -> { C[] -> [N] }",
5736 { &isl_multi_union_pw_aff_apply_pw_aff
,
5738 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5739 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
5740 { &isl_multi_union_pw_aff_apply_pw_aff
,
5741 "[N] -> (C[] : { : N >= 0 })",
5742 "[N] -> { C[] -> [N] }",
5743 "[N] -> { [N] : N >= 0 }" },
5744 { &isl_multi_union_pw_aff_apply_pw_aff
,
5745 "[N] -> (C[] : { : N >= 0 })",
5746 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5747 "[N] -> { [N] : N >= 0 }" },
5748 { &isl_multi_union_pw_aff_apply_pw_aff
,
5749 "[N] -> (C[] : { : N >= 0 })",
5751 "[N] -> { [0] : N >= 0 }" },
5752 { &isl_multi_union_pw_aff_apply_pw_aff
,
5753 "(C[] : { A[i,j] : i >= j })",
5754 "[N] -> { C[] -> [N] }",
5755 "[N] -> { A[i,j] -> [N] : i >= j }" },
5756 { &isl_multi_union_pw_aff_apply_pw_aff
,
5757 "(C[] : { A[i,j] : i >= j })",
5758 "[N] -> { C[] -> [N] : N >= 0 }",
5759 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
5762 /* Perform some basic tests of binary operations on
5763 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
5765 static int test_mupa_pa(isl_ctx
*ctx
)
5769 isl_multi_union_pw_aff
*mupa
;
5770 isl_union_pw_aff
*upa
, *res
;
5773 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
5774 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5775 mupa_pa_tests
[i
].arg1
);
5776 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
5777 res
= isl_union_pw_aff_read_from_str(ctx
,
5778 mupa_pa_tests
[i
].res
);
5779 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
5780 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
5781 isl_union_pw_aff_free(upa
);
5782 isl_union_pw_aff_free(res
);
5786 isl_die(ctx
, isl_error_unknown
,
5787 "unexpected result", return -1);
5793 /* Inputs for basic tests of binary operations on
5794 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
5795 * "fn" is the function that is tested.
5796 * "arg1" and "arg2" are string descriptions of the inputs.
5797 * "res" is a string description of the expected result.
5800 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5801 __isl_take isl_multi_union_pw_aff
*mupa
,
5802 __isl_take isl_pw_multi_aff
*pma
);
5806 } mupa_pma_tests
[] = {
5807 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5808 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5809 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5810 "{ C[a,b] -> D[b,a] }",
5811 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
5812 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
5813 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5814 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
5815 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5816 "{ C[a,b] -> D[b,a] }",
5817 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
5818 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
5819 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5820 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5821 "[N] -> { C[a] -> D[a + N] }",
5822 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
5823 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5824 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5825 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
5826 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
5827 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
5828 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5829 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5830 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5831 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
5832 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
5833 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
5834 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
5835 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
5836 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5840 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5841 "[N] -> (C[] : { : N >= 0 })",
5843 "[N] -> (D[] : { : N >= 0 })" },
5844 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5846 "[N] -> { C[] -> D[N] }",
5847 "[N] -> D[{ [N] }]" },
5848 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5849 "(C[] : { A[i,j] : i >= j })",
5851 "(D[] : { A[i,j] : i >= j })" },
5852 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5853 "[N] -> (C[] : { A[i,j] : N >= 0 })",
5855 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
5856 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5857 "(C[] : { A[i,j] : i >= j })",
5858 "[N] -> { C[] -> D[N] }",
5859 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
5860 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5862 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
5863 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
5864 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5865 "[N] -> (C[] : { : N >= 0 })",
5866 "[N] -> { C[] -> D[N] }",
5867 "[N] -> D[{ [N] : N >= 0 }]" },
5868 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5869 "[N] -> (C[] : { : N >= 0 })",
5870 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
5871 "[N] -> D[{ [N] : N >= 0 }]" },
5872 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5873 "[N] -> (C[] : { : N >= 0 })",
5875 "[N] -> D[{ [0] : N >= 0 }]" },
5876 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
5877 "(C[] : { A[i,j] : i >= j })",
5878 "[N] -> { C[] -> D[N] : N >= 0 }",
5879 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
5882 /* Perform some basic tests of binary operations on
5883 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
5885 static int test_mupa_pma(isl_ctx
*ctx
)
5889 isl_multi_union_pw_aff
*mupa
, *res
;
5890 isl_pw_multi_aff
*pma
;
5892 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
5893 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5894 mupa_pma_tests
[i
].arg1
);
5895 pma
= isl_pw_multi_aff_read_from_str(ctx
,
5896 mupa_pma_tests
[i
].arg2
);
5897 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5898 mupa_pma_tests
[i
].res
);
5899 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
5900 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5901 isl_multi_union_pw_aff_free(mupa
);
5902 isl_multi_union_pw_aff_free(res
);
5906 isl_die(ctx
, isl_error_unknown
,
5907 "unexpected result", return -1);
5913 /* Inputs for basic tests of binary operations on
5914 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
5915 * "fn" is the function that is tested.
5916 * "arg1" and "arg2" are string descriptions of the inputs.
5917 * "res" is a string description of the expected result.
5920 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5921 __isl_take isl_multi_union_pw_aff
*mupa
,
5922 __isl_take isl_union_pw_multi_aff
*upma
);
5926 } mupa_upma_tests
[] = {
5927 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5928 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
5929 "C[{ A[a,b] -> [b + 2a] }]" },
5930 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5931 "C[{ B[i,j] -> [i + 2j] }]",
5932 "{ A[a,b] -> B[b,a] : b > a }",
5933 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
5934 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5935 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
5936 "{ A[a,b] -> B[b,a] : b > a }",
5937 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
5938 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5939 "C[{ B[i,j] -> [i + 2j] }]",
5940 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
5941 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
5942 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5943 "(C[] : { B[a,b] })",
5944 "{ A[a,b] -> B[b,a] }",
5945 "(C[] : { A[a,b] })" },
5946 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5947 "(C[] : { B[a,b] })",
5948 "{ B[a,b] -> A[b,a] }",
5950 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5951 "(C[] : { B[a,b] })",
5952 "{ A[a,b] -> B[b,a] : a > b }",
5953 "(C[] : { A[a,b] : a > b })" },
5954 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5955 "(C[] : { B[a,b] : a > b })",
5956 "{ A[a,b] -> B[b,a] }",
5957 "(C[] : { A[a,b] : b > a })" },
5958 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5959 "[N] -> (C[] : { B[a,b] : a > N })",
5960 "{ A[a,b] -> B[b,a] : a > b }",
5961 "[N] -> (C[] : { A[a,b] : a > b > N })" },
5962 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5963 "(C[] : { B[a,b] : a > b })",
5964 "[N] -> { A[a,b] -> B[b,a] : a > N }",
5965 "[N] -> (C[] : { A[a,b] : b > a > N })" },
5966 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5968 "{ A[a,b] -> B[b,a] }",
5970 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5971 "[N] -> (C[] : { : N >= 0 })",
5972 "{ A[a,b] -> B[b,a] }",
5973 "[N] -> (C[] : { : N >= 0 })" },
5974 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
5976 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
5977 "[N] -> (C[] : { : N >= 0 })" },
5980 /* Perform some basic tests of binary operations on
5981 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
5983 static int test_mupa_upma(isl_ctx
*ctx
)
5987 isl_multi_union_pw_aff
*mupa
, *res
;
5988 isl_union_pw_multi_aff
*upma
;
5990 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
5991 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5992 mupa_upma_tests
[i
].arg1
);
5993 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
5994 mupa_upma_tests
[i
].arg2
);
5995 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5996 mupa_upma_tests
[i
].res
);
5997 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
5998 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5999 isl_multi_union_pw_aff_free(mupa
);
6000 isl_multi_union_pw_aff_free(res
);
6004 isl_die(ctx
, isl_error_unknown
,
6005 "unexpected result", return -1);
6011 int test_aff(isl_ctx
*ctx
)
6016 isl_local_space
*ls
;
6020 if (test_upa(ctx
) < 0)
6022 if (test_bin_aff(ctx
) < 0)
6024 if (test_bin_pw_aff(ctx
) < 0)
6026 if (test_bin_upma(ctx
) < 0)
6028 if (test_bin_upma_fail(ctx
) < 0)
6030 if (test_un_mpa(ctx
) < 0)
6032 if (test_bin_mpa(ctx
) < 0)
6034 if (test_un_mupa(ctx
) < 0)
6036 if (test_bin_mupa(ctx
) < 0)
6038 if (test_mupa_set(ctx
) < 0)
6040 if (test_mupa_uset(ctx
) < 0)
6042 if (test_mupa_ma(ctx
) < 0)
6044 if (test_mupa_pa(ctx
) < 0)
6046 if (test_mupa_pma(ctx
) < 0)
6048 if (test_mupa_upma(ctx
) < 0)
6051 space
= isl_space_set_alloc(ctx
, 0, 1);
6052 ls
= isl_local_space_from_space(space
);
6053 aff
= isl_aff_zero_on_domain(ls
);
6055 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6056 aff
= isl_aff_scale_down_ui(aff
, 3);
6057 aff
= isl_aff_floor(aff
);
6058 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6059 aff
= isl_aff_scale_down_ui(aff
, 2);
6060 aff
= isl_aff_floor(aff
);
6061 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6064 set
= isl_set_read_from_str(ctx
, str
);
6065 aff
= isl_aff_gist(aff
, set
);
6067 aff
= isl_aff_add_constant_si(aff
, -16);
6068 zero
= isl_aff_plain_is_zero(aff
);
6074 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6076 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6077 aff
= isl_aff_scale_down_ui(aff
, 64);
6078 aff
= isl_aff_floor(aff
);
6079 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6087 /* Check that "pa" consists of a single expression.
6089 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
6093 n
= isl_pw_aff_n_piece(pa
);
6094 isl_pw_aff_free(pa
);
6099 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
6105 /* Check that the computation below results in a single expression.
6106 * One or two expressions may result depending on which constraint
6107 * ends up being considered as redundant with respect to the other
6108 * constraints after the projection that is performed internally
6109 * by isl_set_dim_min.
6111 static int test_dim_max_1(isl_ctx
*ctx
)
6117 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
6118 "-4a <= b <= 3 and b < n - 4a }";
6119 set
= isl_set_read_from_str(ctx
, str
);
6120 pa
= isl_set_dim_min(set
, 0);
6121 return check_single_piece(ctx
, pa
);
6124 /* Check that the computation below results in a single expression.
6125 * The PIP problem corresponding to these constraints has a row
6126 * that causes a split of the solution domain. The solver should
6127 * first pick rows that split off empty parts such that the actual
6128 * solution domain does not get split.
6129 * Note that the description contains some redundant constraints.
6130 * If these constraints get removed first, then the row mentioned
6131 * above does not appear in the PIP problem.
6133 static int test_dim_max_2(isl_ctx
*ctx
)
6139 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
6140 "N > 0 and P >= 0 }";
6141 set
= isl_set_read_from_str(ctx
, str
);
6142 pa
= isl_set_dim_max(set
, 0);
6143 return check_single_piece(ctx
, pa
);
6146 int test_dim_max(isl_ctx
*ctx
)
6150 isl_set
*set1
, *set2
;
6155 if (test_dim_max_1(ctx
) < 0)
6157 if (test_dim_max_2(ctx
) < 0)
6160 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
6161 set
= isl_set_read_from_str(ctx
, str
);
6162 pwaff
= isl_set_dim_max(set
, 0);
6163 set1
= isl_set_from_pw_aff(pwaff
);
6164 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
6165 set2
= isl_set_read_from_str(ctx
, str
);
6166 equal
= isl_set_is_equal(set1
, set2
);
6172 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6174 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
6175 set
= isl_set_read_from_str(ctx
, str
);
6176 pwaff
= isl_set_dim_max(set
, 0);
6177 set1
= isl_set_from_pw_aff(pwaff
);
6178 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6179 set2
= isl_set_read_from_str(ctx
, str
);
6180 equal
= isl_set_is_equal(set1
, set2
);
6186 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6188 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
6189 set
= isl_set_read_from_str(ctx
, str
);
6190 pwaff
= isl_set_dim_max(set
, 0);
6191 set1
= isl_set_from_pw_aff(pwaff
);
6192 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6193 set2
= isl_set_read_from_str(ctx
, str
);
6194 equal
= isl_set_is_equal(set1
, set2
);
6200 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6202 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
6203 "0 <= i < N and 0 <= j < M }";
6204 map
= isl_map_read_from_str(ctx
, str
);
6205 set
= isl_map_range(map
);
6207 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
6208 set1
= isl_set_from_pw_aff(pwaff
);
6209 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
6210 set2
= isl_set_read_from_str(ctx
, str
);
6211 equal
= isl_set_is_equal(set1
, set2
);
6215 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
6216 set1
= isl_set_from_pw_aff(pwaff
);
6217 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
6218 set2
= isl_set_read_from_str(ctx
, str
);
6219 if (equal
>= 0 && equal
)
6220 equal
= isl_set_is_equal(set1
, set2
);
6229 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6231 /* Check that solutions are properly merged. */
6232 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
6233 "c <= -1 + n - 4a - 2b and c >= -2b and "
6234 "4a >= -4 + n and c >= 0 }";
6235 set
= isl_set_read_from_str(ctx
, str
);
6236 pwaff
= isl_set_dim_min(set
, 2);
6237 set1
= isl_set_from_pw_aff(pwaff
);
6238 str
= "[n] -> { [(0)] : n >= 1 }";
6239 set2
= isl_set_read_from_str(ctx
, str
);
6240 equal
= isl_set_is_equal(set1
, set2
);
6247 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6249 /* Check that empty solution lie in the right space. */
6250 str
= "[n] -> { [t,a] : 1 = 0 }";
6251 set
= isl_set_read_from_str(ctx
, str
);
6252 pwaff
= isl_set_dim_max(set
, 0);
6253 set1
= isl_set_from_pw_aff(pwaff
);
6254 str
= "[n] -> { [t] : 1 = 0 }";
6255 set2
= isl_set_read_from_str(ctx
, str
);
6256 equal
= isl_set_is_equal(set1
, set2
);
6263 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6268 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
6270 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
6274 isl_pw_multi_aff
*pma2
;
6280 ctx
= isl_pw_multi_aff_get_ctx(pma
);
6281 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6282 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
6283 isl_pw_multi_aff_free(pma2
);
6288 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
6289 * represented by "str".
6291 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
6296 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
6300 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
6301 "result not as expected", return -1);
6305 /* Basic test for isl_pw_multi_aff_product.
6307 * Check that multiple pieces are properly handled.
6309 static int test_product_pma(isl_ctx
*ctx
)
6313 isl_pw_multi_aff
*pma1
, *pma2
;
6315 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
6316 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6317 str
= "{ C[] -> D[] }";
6318 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6319 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
6320 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
6321 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
6322 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
6323 isl_pw_multi_aff_free(pma1
);
6330 int test_product(isl_ctx
*ctx
)
6334 isl_union_set
*uset1
, *uset2
;
6338 set
= isl_set_read_from_str(ctx
, str
);
6339 set
= isl_set_product(set
, isl_set_copy(set
));
6340 ok
= isl_set_is_wrapping(set
);
6345 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6348 uset1
= isl_union_set_read_from_str(ctx
, str
);
6349 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
6350 str
= "{ [[] -> []] }";
6351 uset2
= isl_union_set_read_from_str(ctx
, str
);
6352 ok
= isl_union_set_is_equal(uset1
, uset2
);
6353 isl_union_set_free(uset1
);
6354 isl_union_set_free(uset2
);
6358 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6360 if (test_product_pma(ctx
) < 0)
6366 /* Check that two sets are not considered disjoint just because
6367 * they have a different set of (named) parameters.
6369 static int test_disjoint(isl_ctx
*ctx
)
6372 isl_set
*set
, *set2
;
6375 str
= "[n] -> { [[]->[]] }";
6376 set
= isl_set_read_from_str(ctx
, str
);
6377 str
= "{ [[]->[]] }";
6378 set2
= isl_set_read_from_str(ctx
, str
);
6379 disjoint
= isl_set_is_disjoint(set
, set2
);
6385 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6390 /* Inputs for isl_pw_multi_aff_is_equal tests.
6391 * "f1" and "f2" are the two function that need to be compared.
6392 * "equal" is the expected result.
6398 } pma_equal_tests
[] = {
6399 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
6400 "[N] -> { [0] : 0 <= N <= 1 }" },
6401 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6402 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
6403 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6404 "[N] -> { [0] : 0 <= N <= 1 }" },
6405 { 0, "{ [NaN] }", "{ [NaN] }" },
6408 int test_equal(isl_ctx
*ctx
)
6412 isl_set
*set
, *set2
;
6416 set
= isl_set_read_from_str(ctx
, str
);
6418 set2
= isl_set_read_from_str(ctx
, str
);
6419 equal
= isl_set_is_equal(set
, set2
);
6425 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6427 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
6428 int expected
= pma_equal_tests
[i
].equal
;
6429 isl_pw_multi_aff
*f1
, *f2
;
6431 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
6432 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
6433 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
6434 isl_pw_multi_aff_free(f1
);
6435 isl_pw_multi_aff_free(f2
);
6438 if (equal
!= expected
)
6439 isl_die(ctx
, isl_error_unknown
,
6440 "unexpected equality result", return -1);
6446 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
6447 enum isl_dim_type type
, unsigned pos
, int fixed
)
6451 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
6458 isl_die(ctx
, isl_error_unknown
,
6459 "map not detected as fixed", return -1);
6461 isl_die(ctx
, isl_error_unknown
,
6462 "map detected as fixed", return -1);
6465 int test_fixed(isl_ctx
*ctx
)
6470 str
= "{ [i] -> [i] }";
6471 map
= isl_map_read_from_str(ctx
, str
);
6472 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
6474 str
= "{ [i] -> [1] }";
6475 map
= isl_map_read_from_str(ctx
, str
);
6476 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6478 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
6479 map
= isl_map_read_from_str(ctx
, str
);
6480 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6482 map
= isl_map_read_from_str(ctx
, str
);
6483 map
= isl_map_neg(map
);
6484 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6490 struct isl_vertices_test_data
{
6493 const char *vertex
[6];
6494 } vertices_tests
[] = {
6495 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
6496 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
6497 { "{ A[t, i] : t = 14 and i = 1 }",
6498 1, { "{ A[14, 1] }" } },
6499 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
6500 "c <= m and m <= n and m > 0 }",
6502 "[n, m] -> { [n, m, m] : 0 < m <= n }",
6503 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
6504 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
6505 "[n, m] -> { [m, m, m] : 0 < m <= n }",
6506 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
6507 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
6511 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
6513 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
6515 struct isl_vertices_test_data
*data
= user
;
6518 isl_basic_set
*bset
;
6519 isl_pw_multi_aff
*pma
;
6523 ctx
= isl_vertex_get_ctx(vertex
);
6524 bset
= isl_vertex_get_domain(vertex
);
6525 ma
= isl_vertex_get_expr(vertex
);
6526 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
6528 for (i
= 0; i
< data
->n
; ++i
) {
6529 isl_pw_multi_aff
*pma_i
;
6531 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
6532 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
6533 isl_pw_multi_aff_free(pma_i
);
6535 if (equal
< 0 || equal
)
6539 isl_pw_multi_aff_free(pma
);
6540 isl_vertex_free(vertex
);
6543 return isl_stat_error
;
6545 return equal
? isl_stat_ok
: isl_stat_error
;
6548 int test_vertices(isl_ctx
*ctx
)
6552 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
6553 isl_basic_set
*bset
;
6554 isl_vertices
*vertices
;
6558 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
6559 vertices
= isl_basic_set_compute_vertices(bset
);
6560 n
= isl_vertices_get_n_vertices(vertices
);
6561 if (vertices_tests
[i
].n
!= n
)
6563 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
6564 &vertices_tests
[i
]) < 0)
6566 isl_vertices_free(vertices
);
6567 isl_basic_set_free(bset
);
6572 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
6579 int test_union_pw(isl_ctx
*ctx
)
6583 isl_union_set
*uset
;
6584 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
6586 str
= "{ [x] -> x^2 }";
6587 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
6588 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
6589 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
6590 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
6591 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
6592 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
6593 isl_union_pw_qpolynomial_free(upwqp1
);
6594 isl_union_pw_qpolynomial_free(upwqp2
);
6598 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6603 /* Inputs for basic tests of functions that select
6604 * subparts of the domain of an isl_multi_union_pw_aff.
6605 * "fn" is the function that is tested.
6606 * "arg" is a string description of the input.
6607 * "res" is a string description of the expected result.
6610 __isl_give isl_union_set
*(*fn
)(
6611 __isl_take isl_multi_union_pw_aff
*mupa
);
6614 } un_locus_tests
[] = {
6615 { &isl_multi_union_pw_aff_zero_union_set
,
6616 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6617 "{ A[0,j]; B[0,j] }" },
6618 { &isl_multi_union_pw_aff_zero_union_set
,
6619 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
6620 "{ A[i,i]; B[i,i] : i >= 0 }" },
6621 { &isl_multi_union_pw_aff_zero_union_set
,
6622 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
6623 "{ A[i,j]; B[i,i] : i >= 0 }" },
6626 /* Perform some basic tests of functions that select
6627 * subparts of the domain of an isl_multi_union_pw_aff.
6629 static int test_un_locus(isl_ctx
*ctx
)
6633 isl_union_set
*uset
, *res
;
6634 isl_multi_union_pw_aff
*mupa
;
6636 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
6637 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6638 un_locus_tests
[i
].arg
);
6639 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
6640 uset
= un_locus_tests
[i
].fn(mupa
);
6641 ok
= isl_union_set_is_equal(uset
, res
);
6642 isl_union_set_free(uset
);
6643 isl_union_set_free(res
);
6647 isl_die(ctx
, isl_error_unknown
,
6648 "unexpected result", return -1);
6654 /* Inputs for basic tests of functions that select
6655 * subparts of an isl_union_map based on a relation
6656 * specified by an isl_multi_union_pw_aff.
6657 * "fn" is the function that is tested.
6658 * "arg1" and "arg2" are string descriptions of the inputs.
6659 * "res" is a string description of the expected result.
6662 __isl_give isl_union_map
*(*fn
)(
6663 __isl_take isl_union_map
*umap
,
6664 __isl_take isl_multi_union_pw_aff
*mupa
);
6668 } bin_locus_tests
[] = {
6669 { &isl_union_map_eq_at_multi_union_pw_aff
,
6670 "{ A[i,j] -> B[i',j'] }",
6671 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6672 "{ A[i,j] -> B[i,j'] }" },
6673 { &isl_union_map_eq_at_multi_union_pw_aff
,
6674 "{ A[i,j] -> B[i',j'] }",
6675 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6676 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6677 "{ A[i,j] -> B[i,j] }" },
6678 { &isl_union_map_eq_at_multi_union_pw_aff
,
6679 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6680 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6681 "{ A[i,j] -> B[i,j'] }" },
6682 { &isl_union_map_eq_at_multi_union_pw_aff
,
6683 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6684 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
6685 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
6686 { &isl_union_map_eq_at_multi_union_pw_aff
,
6687 "{ A[i,j] -> B[i',j'] }",
6688 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
6689 "{ A[i,j] -> B[i,j'] : i > j }" },
6690 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
6691 "{ A[i,j] -> B[i',j'] }",
6692 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6693 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6694 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
6695 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
6696 "{ A[i,j] -> B[i',j'] }",
6697 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6698 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6699 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
6700 { &isl_union_map_eq_at_multi_union_pw_aff
,
6701 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6702 "(F[] : { A[i,j]; B[i,j] })",
6703 "{ A[i,j] -> B[i',j'] }" },
6704 { &isl_union_map_eq_at_multi_union_pw_aff
,
6705 "{ A[i,j] -> B[i',j'] }",
6706 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6707 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
6708 { &isl_union_map_eq_at_multi_union_pw_aff
,
6709 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
6710 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6711 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
6712 { &isl_union_map_eq_at_multi_union_pw_aff
,
6713 "{ A[i,j] -> B[i',j'] }",
6714 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
6715 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
6716 { &isl_union_map_eq_at_multi_union_pw_aff
,
6717 "{ A[i,j] -> B[i',j'] }",
6718 "[N] -> (F[] : { : N >= 0 })",
6719 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
6722 /* Perform some basic tests of functions that select
6723 * subparts of an isl_union_map based on a relation
6724 * specified by an isl_multi_union_pw_aff.
6726 static int test_bin_locus(isl_ctx
*ctx
)
6730 isl_union_map
*umap
, *res
;
6731 isl_multi_union_pw_aff
*mupa
;
6733 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
6734 umap
= isl_union_map_read_from_str(ctx
,
6735 bin_locus_tests
[i
].arg1
);
6736 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6737 bin_locus_tests
[i
].arg2
);
6738 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
6739 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
6740 ok
= isl_union_map_is_equal(umap
, res
);
6741 isl_union_map_free(umap
);
6742 isl_union_map_free(res
);
6746 isl_die(ctx
, isl_error_unknown
,
6747 "unexpected result", return -1);
6753 /* Perform basic locus tests.
6755 static int test_locus(isl_ctx
*ctx
)
6757 if (test_un_locus(ctx
) < 0)
6759 if (test_bin_locus(ctx
) < 0)
6764 /* Test that isl_union_pw_qpolynomial_eval picks up the function
6765 * defined over the correct domain space.
6767 static int test_eval_1(isl_ctx
*ctx
)
6772 isl_union_pw_qpolynomial
*upwqp
;
6776 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
6777 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
6779 set
= isl_set_read_from_str(ctx
, str
);
6780 pnt
= isl_set_sample_point(set
);
6781 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
6782 cmp
= isl_val_cmp_si(v
, 36);
6788 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
6793 /* Check that isl_qpolynomial_eval handles getting called on a void point.
6795 static int test_eval_2(isl_ctx
*ctx
)
6800 isl_qpolynomial
*qp
;
6804 str
= "{ A[x] -> [x] }";
6805 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
6806 str
= "{ A[x] : false }";
6807 set
= isl_set_read_from_str(ctx
, str
);
6808 pnt
= isl_set_sample_point(set
);
6809 v
= isl_qpolynomial_eval(qp
, pnt
);
6810 ok
= isl_val_is_nan(v
);
6816 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
6821 /* Inputs for isl_pw_aff_eval test.
6822 * "f" is the affine function.
6823 * "p" is the point where the function should be evaluated.
6824 * "res" is the expected result.
6830 } aff_eval_tests
[] = {
6831 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
6832 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
6833 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
6834 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
6835 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
6836 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
6837 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
6838 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
6839 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
6840 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
6841 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
6842 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
6843 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
6844 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
6845 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
6846 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
6847 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
6848 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
6849 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
6850 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
6851 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
6852 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
6853 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
6856 /* Perform basic isl_pw_aff_eval tests.
6858 static int test_eval_aff(isl_ctx
*ctx
)
6862 for (i
= 0; i
< ARRAY_SIZE(aff_eval_tests
); ++i
) {
6869 pa
= isl_pw_aff_read_from_str(ctx
, aff_eval_tests
[i
].f
);
6870 set
= isl_set_read_from_str(ctx
, aff_eval_tests
[i
].p
);
6871 pnt
= isl_set_sample_point(set
);
6872 v
= isl_pw_aff_eval(pa
, pnt
);
6873 r
= val_check_equal(v
, aff_eval_tests
[i
].res
);
6881 /* Perform basic evaluation tests.
6883 static int test_eval(isl_ctx
*ctx
)
6885 if (test_eval_1(ctx
) < 0)
6887 if (test_eval_2(ctx
) < 0)
6889 if (test_eval_aff(ctx
) < 0)
6894 /* Descriptions of sets that are tested for reparsing after printing.
6896 const char *output_tests
[] = {
6897 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
6900 "{ [x] : x mod 2 = 0 }",
6901 "{ [x] : x mod 2 = 1 }",
6902 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
6903 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
6904 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
6905 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
6906 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
6907 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
6910 /* Check that printing a set and reparsing a set from the printed output
6911 * results in the same set.
6913 static int test_output_set(isl_ctx
*ctx
)
6917 isl_set
*set1
, *set2
;
6920 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
6921 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
6922 str
= isl_set_to_str(set1
);
6923 set2
= isl_set_read_from_str(ctx
, str
);
6925 equal
= isl_set_is_equal(set1
, set2
);
6931 isl_die(ctx
, isl_error_unknown
,
6932 "parsed output not the same", return -1);
6938 int test_output(isl_ctx
*ctx
)
6946 if (test_output_set(ctx
) < 0)
6949 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
6950 pa
= isl_pw_aff_read_from_str(ctx
, str
);
6952 p
= isl_printer_to_str(ctx
);
6953 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
6954 p
= isl_printer_print_pw_aff(p
, pa
);
6955 s
= isl_printer_get_str(p
);
6956 isl_printer_free(p
);
6957 isl_pw_aff_free(pa
);
6961 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
6966 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6971 int test_sample(isl_ctx
*ctx
)
6974 isl_basic_set
*bset1
, *bset2
;
6977 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
6978 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
6979 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
6980 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
6981 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
6982 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
6983 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
6984 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
6985 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
6986 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
6987 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
6988 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
6989 "d - 1073741821e and "
6990 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
6991 "3j >= 1 - a + b + 2e and "
6992 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
6993 "3i <= 4 - a + 4b - e and "
6994 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
6995 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
6996 "c <= -1 + a and 3i >= -2 - a + 3e and "
6997 "1073741822e <= 1073741823 - a + 1073741822b + c and "
6998 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
6999 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
7000 "1073741823e >= 1 + 1073741823b - d and "
7001 "3i >= 1073741823b + c - 1073741823e - f and "
7002 "3i >= 1 + 2b + e + 3g }";
7003 bset1
= isl_basic_set_read_from_str(ctx
, str
);
7004 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
7005 empty
= isl_basic_set_is_empty(bset2
);
7006 subset
= isl_basic_set_is_subset(bset2
, bset1
);
7007 isl_basic_set_free(bset1
);
7008 isl_basic_set_free(bset2
);
7009 if (empty
< 0 || subset
< 0)
7012 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
7014 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
7019 int test_fixed_power(isl_ctx
*ctx
)
7026 str
= "{ [i] -> [i + 1] }";
7027 map
= isl_map_read_from_str(ctx
, str
);
7028 exp
= isl_val_int_from_si(ctx
, 23);
7029 map
= isl_map_fixed_power_val(map
, exp
);
7030 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
7038 int test_slice(isl_ctx
*ctx
)
7044 str
= "{ [i] -> [j] }";
7045 map
= isl_map_read_from_str(ctx
, str
);
7046 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7047 equal
= map_check_equal(map
, "{ [i] -> [i] }");
7052 str
= "{ [i] -> [j] }";
7053 map
= isl_map_read_from_str(ctx
, str
);
7054 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7055 equal
= map_check_equal(map
, "{ [i] -> [j] }");
7060 str
= "{ [i] -> [j] }";
7061 map
= isl_map_read_from_str(ctx
, str
);
7062 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7063 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
7068 str
= "{ [i] -> [j] }";
7069 map
= isl_map_read_from_str(ctx
, str
);
7070 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7071 equal
= map_check_equal(map
, "{ [0] -> [j] }");
7076 str
= "{ [i] -> [j] }";
7077 map
= isl_map_read_from_str(ctx
, str
);
7078 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7079 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
7084 str
= "{ [i] -> [j] }";
7085 map
= isl_map_read_from_str(ctx
, str
);
7086 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7087 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
7095 int test_eliminate(isl_ctx
*ctx
)
7101 str
= "{ [i] -> [j] : i = 2j }";
7102 map
= isl_map_read_from_str(ctx
, str
);
7103 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
7104 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
7112 /* Check that isl_set_dim_residue_class detects that the values of j
7113 * in the set below are all odd and that it does not detect any spurious
7116 static int test_residue_class(isl_ctx
*ctx
)
7123 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
7124 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
7125 set
= isl_set_read_from_str(ctx
, str
);
7128 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
7130 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
7131 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
7132 res
= isl_stat_error
);
7140 int test_align_parameters(isl_ctx
*ctx
)
7144 isl_multi_aff
*ma1
, *ma2
;
7147 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
7148 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
7150 space
= isl_space_params_alloc(ctx
, 1);
7151 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
7152 ma1
= isl_multi_aff_align_params(ma1
, space
);
7154 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
7155 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
7157 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
7159 isl_multi_aff_free(ma1
);
7160 isl_multi_aff_free(ma2
);
7165 isl_die(ctx
, isl_error_unknown
,
7166 "result not as expected", return -1);
7171 /* Check that isl_*_drop_unused_params actually drops the unused parameters
7172 * by comparing the result using isl_*_plain_is_equal.
7173 * Note that this assumes that isl_*_plain_is_equal does not consider
7174 * objects that only differ by unused parameters to be equal.
7176 int test_drop_unused_parameters(isl_ctx
*ctx
)
7178 const char *str_with
, *str_without
;
7179 isl_basic_set
*bset1
, *bset2
;
7180 isl_set
*set1
, *set2
;
7181 isl_pw_aff
*pwa1
, *pwa2
;
7184 str_with
= "[n, m, o] -> { [m] }";
7185 str_without
= "[m] -> { [m] }";
7187 bset1
= isl_basic_set_read_from_str(ctx
, str_with
);
7188 bset2
= isl_basic_set_read_from_str(ctx
, str_without
);
7189 bset1
= isl_basic_set_drop_unused_params(bset1
);
7190 equal
= isl_basic_set_plain_is_equal(bset1
, bset2
);
7191 isl_basic_set_free(bset1
);
7192 isl_basic_set_free(bset2
);
7197 isl_die(ctx
, isl_error_unknown
,
7198 "result not as expected", return -1);
7200 set1
= isl_set_read_from_str(ctx
, str_with
);
7201 set2
= isl_set_read_from_str(ctx
, str_without
);
7202 set1
= isl_set_drop_unused_params(set1
);
7203 equal
= isl_set_plain_is_equal(set1
, set2
);
7210 isl_die(ctx
, isl_error_unknown
,
7211 "result not as expected", return -1);
7213 pwa1
= isl_pw_aff_read_from_str(ctx
, str_with
);
7214 pwa2
= isl_pw_aff_read_from_str(ctx
, str_without
);
7215 pwa1
= isl_pw_aff_drop_unused_params(pwa1
);
7216 equal
= isl_pw_aff_plain_is_equal(pwa1
, pwa2
);
7217 isl_pw_aff_free(pwa1
);
7218 isl_pw_aff_free(pwa2
);
7223 isl_die(ctx
, isl_error_unknown
,
7224 "result not as expected", return -1);
7229 static int test_list(isl_ctx
*ctx
)
7231 isl_id
*a
, *b
, *c
, *d
, *id
;
7235 a
= isl_id_alloc(ctx
, "a", NULL
);
7236 b
= isl_id_alloc(ctx
, "b", NULL
);
7237 c
= isl_id_alloc(ctx
, "c", NULL
);
7238 d
= isl_id_alloc(ctx
, "d", NULL
);
7240 list
= isl_id_list_alloc(ctx
, 4);
7241 list
= isl_id_list_add(list
, b
);
7242 list
= isl_id_list_insert(list
, 0, a
);
7243 list
= isl_id_list_add(list
, c
);
7244 list
= isl_id_list_add(list
, d
);
7245 list
= isl_id_list_drop(list
, 1, 1);
7249 if (isl_id_list_n_id(list
) != 3) {
7250 isl_id_list_free(list
);
7251 isl_die(ctx
, isl_error_unknown
,
7252 "unexpected number of elements in list", return -1);
7255 id
= isl_id_list_get_id(list
, 0);
7258 id
= isl_id_list_get_id(list
, 1);
7261 id
= isl_id_list_get_id(list
, 2);
7265 isl_id_list_free(list
);
7268 isl_die(ctx
, isl_error_unknown
,
7269 "unexpected elements in list", return -1);
7274 const char *set_conversion_tests
[] = {
7275 "[N] -> { [i] : N - 1 <= 2 i <= N }",
7276 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
7277 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7278 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7279 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
7280 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
7281 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
7282 "-3 + c <= d <= 28 + c) }",
7285 /* Check that converting from isl_set to isl_pw_multi_aff and back
7286 * to isl_set produces the original isl_set.
7288 static int test_set_conversion(isl_ctx
*ctx
)
7292 isl_set
*set1
, *set2
;
7293 isl_pw_multi_aff
*pma
;
7296 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
7297 str
= set_conversion_tests
[i
];
7298 set1
= isl_set_read_from_str(ctx
, str
);
7299 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
7300 set2
= isl_set_from_pw_multi_aff(pma
);
7301 equal
= isl_set_is_equal(set1
, set2
);
7308 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7315 const char *conversion_tests
[] = {
7316 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7317 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7318 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7319 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7321 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7322 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7323 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7326 /* Check that converting from isl_map to isl_pw_multi_aff and back
7327 * to isl_map produces the original isl_map.
7329 static int test_map_conversion(isl_ctx
*ctx
)
7332 isl_map
*map1
, *map2
;
7333 isl_pw_multi_aff
*pma
;
7336 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
7337 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
7338 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
7339 map2
= isl_map_from_pw_multi_aff(pma
);
7340 equal
= isl_map_is_equal(map1
, map2
);
7347 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7354 /* Descriptions of isl_pw_multi_aff objects for testing conversion
7355 * to isl_multi_pw_aff and back.
7357 const char *mpa_conversion_tests
[] = {
7359 "{ [x] -> A[x] : x >= 0 }",
7360 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
7361 "{ [x] -> A[x, x + 1] }",
7363 "{ [x] -> A[] : x >= 0 }",
7366 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
7367 * back to isl_pw_multi_aff preserves the original meaning.
7369 static int test_mpa_conversion(isl_ctx
*ctx
)
7372 isl_pw_multi_aff
*pma1
, *pma2
;
7373 isl_multi_pw_aff
*mpa
;
7376 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
7378 str
= mpa_conversion_tests
[i
];
7379 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7380 pma2
= isl_pw_multi_aff_copy(pma1
);
7381 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
7382 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
7383 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
7384 isl_pw_multi_aff_free(pma1
);
7385 isl_pw_multi_aff_free(pma2
);
7390 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7397 /* Descriptions of union maps that should be convertible
7398 * to an isl_multi_union_pw_aff.
7400 const char *umap_mupa_conversion_tests
[] = {
7401 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7402 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7403 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7404 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7406 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7407 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7408 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7409 "{ A[] -> B[0]; C[] -> B[1] }",
7410 "{ A[] -> B[]; C[] -> B[] }",
7413 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
7414 * to isl_union_map produces the original isl_union_map.
7416 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
7419 isl_union_map
*umap1
, *umap2
;
7420 isl_multi_union_pw_aff
*mupa
;
7423 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
7425 str
= umap_mupa_conversion_tests
[i
];
7426 umap1
= isl_union_map_read_from_str(ctx
, str
);
7427 umap2
= isl_union_map_copy(umap1
);
7428 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
7429 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
7430 equal
= isl_union_map_is_equal(umap1
, umap2
);
7431 isl_union_map_free(umap1
);
7432 isl_union_map_free(umap2
);
7437 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7444 static int test_conversion(isl_ctx
*ctx
)
7446 if (test_set_conversion(ctx
) < 0)
7448 if (test_map_conversion(ctx
) < 0)
7450 if (test_mpa_conversion(ctx
) < 0)
7452 if (test_union_map_mupa_conversion(ctx
) < 0)
7457 /* Check that isl_basic_map_curry does not modify input.
7459 static int test_curry(isl_ctx
*ctx
)
7462 isl_basic_map
*bmap1
, *bmap2
;
7465 str
= "{ [A[] -> B[]] -> C[] }";
7466 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
7467 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
7468 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
7469 isl_basic_map_free(bmap1
);
7470 isl_basic_map_free(bmap2
);
7475 isl_die(ctx
, isl_error_unknown
,
7476 "curried map should not be equal to original",
7486 } preimage_tests
[] = {
7487 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
7488 "{ A[j,i] -> B[i,j] }",
7489 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
7490 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7491 "{ A[a,b] -> B[a/2,b/6] }",
7492 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
7493 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7494 "{ A[a,b] -> B[a/2,b/6] }",
7495 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
7496 "exists i,j : a = 2 i and b = 6 j }" },
7497 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
7498 "[n] -> { : 0 <= n <= 100 }" },
7499 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7500 "{ A[a] -> B[2a] }",
7501 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
7502 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7503 "{ A[a] -> B[([a/2])] }",
7504 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
7505 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
7506 "{ A[a] -> B[a,a,a/3] }",
7507 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
7508 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
7509 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
7512 static int test_preimage_basic_set(isl_ctx
*ctx
)
7515 isl_basic_set
*bset1
, *bset2
;
7519 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
7520 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
7521 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
7522 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
7523 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
7524 equal
= isl_basic_set_is_equal(bset1
, bset2
);
7525 isl_basic_set_free(bset1
);
7526 isl_basic_set_free(bset2
);
7530 isl_die(ctx
, isl_error_unknown
, "bad preimage",
7541 } preimage_domain_tests
[] = {
7542 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
7543 "{ A[j,i] -> B[i,j] }",
7544 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
7545 { "{ B[i] -> C[i]; D[i] -> E[i] }",
7546 "{ A[i] -> B[i + 1] }",
7547 "{ A[i] -> C[i + 1] }" },
7548 { "{ B[i] -> C[i]; B[i] -> E[i] }",
7549 "{ A[i] -> B[i + 1] }",
7550 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
7551 { "{ B[i] -> C[([i/2])] }",
7552 "{ A[i] -> B[2i] }",
7553 "{ A[i] -> C[i] }" },
7554 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
7555 "{ A[i] -> B[([i/5]), ([i/7])] }",
7556 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
7557 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
7558 "[N] -> { A[] -> B[([N/5])] }",
7559 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
7560 { "{ B[i] -> C[i] : exists a : i = 5 a }",
7561 "{ A[i] -> B[2i] }",
7562 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
7563 { "{ B[i] -> C[i] : exists a : i = 2 a; "
7564 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
7565 "{ A[i] -> B[2i] }",
7566 "{ A[i] -> C[2i] }" },
7567 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
7568 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
7571 static int test_preimage_union_map(isl_ctx
*ctx
)
7574 isl_union_map
*umap1
, *umap2
;
7578 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
7579 umap1
= isl_union_map_read_from_str(ctx
,
7580 preimage_domain_tests
[i
].map
);
7581 ma
= isl_multi_aff_read_from_str(ctx
,
7582 preimage_domain_tests
[i
].ma
);
7583 umap2
= isl_union_map_read_from_str(ctx
,
7584 preimage_domain_tests
[i
].res
);
7585 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
7586 equal
= isl_union_map_is_equal(umap1
, umap2
);
7587 isl_union_map_free(umap1
);
7588 isl_union_map_free(umap2
);
7592 isl_die(ctx
, isl_error_unknown
, "bad preimage",
7599 static int test_preimage(isl_ctx
*ctx
)
7601 if (test_preimage_basic_set(ctx
) < 0)
7603 if (test_preimage_union_map(ctx
) < 0)
7613 } pullback_tests
[] = {
7614 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
7615 "{ A[a,b] -> C[b + 2a] }" },
7616 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
7617 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
7618 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
7619 "{ A[a] -> C[(a)/6] }" },
7620 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
7621 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
7622 "{ A[a] -> C[(2a)/3] }" },
7623 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
7624 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
7625 "{ A[i,j] -> C[i + j, i + j] }"},
7626 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
7627 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
7628 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
7629 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
7630 "{ [i, j] -> [floor((i)/3), j] }",
7631 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
7634 static int test_pullback(isl_ctx
*ctx
)
7637 isl_multi_aff
*ma1
, *ma2
;
7641 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
7642 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
7643 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
7644 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
7645 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
7646 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
7647 isl_multi_aff_free(ma1
);
7648 isl_multi_aff_free(ma2
);
7652 isl_die(ctx
, isl_error_unknown
, "bad pullback",
7659 /* Check that negation is printed correctly and that equal expressions
7660 * are correctly identified.
7662 static int test_ast(isl_ctx
*ctx
)
7664 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
7668 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
7669 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
7670 expr
= isl_ast_expr_add(expr1
, expr2
);
7671 expr2
= isl_ast_expr_copy(expr
);
7672 expr
= isl_ast_expr_neg(expr
);
7673 expr2
= isl_ast_expr_neg(expr2
);
7674 equal
= isl_ast_expr_is_equal(expr
, expr2
);
7675 str
= isl_ast_expr_to_C_str(expr
);
7676 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
7678 isl_ast_expr_free(expr
);
7679 isl_ast_expr_free(expr2
);
7681 if (ok
< 0 || equal
< 0)
7684 isl_die(ctx
, isl_error_unknown
,
7685 "equal expressions not considered equal", return -1);
7687 isl_die(ctx
, isl_error_unknown
,
7688 "isl_ast_expr printed incorrectly", return -1);
7690 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
7691 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
7692 expr
= isl_ast_expr_add(expr1
, expr2
);
7693 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
7694 expr
= isl_ast_expr_sub(expr3
, expr
);
7695 str
= isl_ast_expr_to_C_str(expr
);
7696 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
7698 isl_ast_expr_free(expr
);
7703 isl_die(ctx
, isl_error_unknown
,
7704 "isl_ast_expr printed incorrectly", return -1);
7709 /* Check that isl_ast_build_expr_from_set returns a valid expression
7710 * for an empty set. Note that isl_ast_build_expr_from_set getting
7711 * called on an empty set probably indicates a bug in the caller.
7713 static int test_ast_build(isl_ctx
*ctx
)
7716 isl_ast_build
*build
;
7719 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
7720 build
= isl_ast_build_from_context(set
);
7722 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
7723 expr
= isl_ast_build_expr_from_set(build
, set
);
7725 isl_ast_expr_free(expr
);
7726 isl_ast_build_free(build
);
7734 /* Internal data structure for before_for and after_for callbacks.
7736 * depth is the current depth
7737 * before is the number of times before_for has been called
7738 * after is the number of times after_for has been called
7740 struct isl_test_codegen_data
{
7746 /* This function is called before each for loop in the AST generated
7747 * from test_ast_gen1.
7749 * Increment the number of calls and the depth.
7750 * Check that the space returned by isl_ast_build_get_schedule_space
7751 * matches the target space of the schedule returned by
7752 * isl_ast_build_get_schedule.
7753 * Return an isl_id that is checked by the corresponding call
7756 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
7759 struct isl_test_codegen_data
*data
= user
;
7762 isl_union_map
*schedule
;
7763 isl_union_set
*uset
;
7768 ctx
= isl_ast_build_get_ctx(build
);
7770 if (data
->before
>= 3)
7771 isl_die(ctx
, isl_error_unknown
,
7772 "unexpected number of for nodes", return NULL
);
7773 if (data
->depth
>= 2)
7774 isl_die(ctx
, isl_error_unknown
,
7775 "unexpected depth", return NULL
);
7777 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
7781 schedule
= isl_ast_build_get_schedule(build
);
7782 uset
= isl_union_map_range(schedule
);
7785 if (isl_union_set_n_set(uset
) != 1) {
7786 isl_union_set_free(uset
);
7787 isl_die(ctx
, isl_error_unknown
,
7788 "expecting single range space", return NULL
);
7791 space
= isl_ast_build_get_schedule_space(build
);
7792 set
= isl_union_set_extract_set(uset
, space
);
7793 isl_union_set_free(uset
);
7794 empty
= isl_set_is_empty(set
);
7800 isl_die(ctx
, isl_error_unknown
,
7801 "spaces don't match", return NULL
);
7803 return isl_id_alloc(ctx
, name
, NULL
);
7806 /* This function is called after each for loop in the AST generated
7807 * from test_ast_gen1.
7809 * Increment the number of calls and decrement the depth.
7810 * Check that the annotation attached to the node matches
7811 * the isl_id returned by the corresponding call to before_for.
7813 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
7814 __isl_keep isl_ast_build
*build
, void *user
)
7816 struct isl_test_codegen_data
*data
= user
;
7824 if (data
->after
> data
->before
)
7825 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
7826 "mismatch in number of for nodes",
7827 return isl_ast_node_free(node
));
7829 id
= isl_ast_node_get_annotation(node
);
7831 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
7832 "missing annotation", return isl_ast_node_free(node
));
7834 name
= isl_id_get_name(id
);
7835 valid
= name
&& atoi(name
+ 1) == data
->depth
;
7839 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
7840 "wrong annotation", return isl_ast_node_free(node
));
7845 /* Check that the before_each_for and after_each_for callbacks
7846 * are called for each for loop in the generated code,
7847 * that they are called in the right order and that the isl_id
7848 * returned from the before_each_for callback is attached to
7849 * the isl_ast_node passed to the corresponding after_each_for call.
7851 static int test_ast_gen1(isl_ctx
*ctx
)
7855 isl_union_map
*schedule
;
7856 isl_ast_build
*build
;
7858 struct isl_test_codegen_data data
;
7860 str
= "[N] -> { : N >= 10 }";
7861 set
= isl_set_read_from_str(ctx
, str
);
7862 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
7863 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
7864 schedule
= isl_union_map_read_from_str(ctx
, str
);
7869 build
= isl_ast_build_from_context(set
);
7870 build
= isl_ast_build_set_before_each_for(build
,
7871 &before_for
, &data
);
7872 build
= isl_ast_build_set_after_each_for(build
,
7874 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
7875 isl_ast_build_free(build
);
7879 isl_ast_node_free(tree
);
7881 if (data
.before
!= 3 || data
.after
!= 3)
7882 isl_die(ctx
, isl_error_unknown
,
7883 "unexpected number of for nodes", return -1);
7888 /* Check that the AST generator handles domains that are integrally disjoint
7889 * but not rationally disjoint.
7891 static int test_ast_gen2(isl_ctx
*ctx
)
7895 isl_union_map
*schedule
;
7896 isl_union_map
*options
;
7897 isl_ast_build
*build
;
7900 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
7901 schedule
= isl_union_map_read_from_str(ctx
, str
);
7902 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
7903 build
= isl_ast_build_from_context(set
);
7905 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
7906 options
= isl_union_map_read_from_str(ctx
, str
);
7907 build
= isl_ast_build_set_options(build
, options
);
7908 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
7909 isl_ast_build_free(build
);
7912 isl_ast_node_free(tree
);
7917 /* Increment *user on each call.
7919 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
7920 __isl_keep isl_ast_build
*build
, void *user
)
7929 /* Test that unrolling tries to minimize the number of instances.
7930 * In particular, for the schedule given below, make sure it generates
7931 * 3 nodes (rather than 101).
7933 static int test_ast_gen3(isl_ctx
*ctx
)
7937 isl_union_map
*schedule
;
7938 isl_union_map
*options
;
7939 isl_ast_build
*build
;
7943 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
7944 schedule
= isl_union_map_read_from_str(ctx
, str
);
7945 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
7947 str
= "{ [i] -> unroll[0] }";
7948 options
= isl_union_map_read_from_str(ctx
, str
);
7950 build
= isl_ast_build_from_context(set
);
7951 build
= isl_ast_build_set_options(build
, options
);
7952 build
= isl_ast_build_set_at_each_domain(build
,
7953 &count_domains
, &n_domain
);
7954 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
7955 isl_ast_build_free(build
);
7959 isl_ast_node_free(tree
);
7962 isl_die(ctx
, isl_error_unknown
,
7963 "unexpected number of for nodes", return -1);
7968 /* Check that if the ast_build_exploit_nested_bounds options is set,
7969 * we do not get an outer if node in the generated AST,
7970 * while we do get such an outer if node if the options is not set.
7972 static int test_ast_gen4(isl_ctx
*ctx
)
7976 isl_union_map
*schedule
;
7977 isl_ast_build
*build
;
7979 enum isl_ast_node_type type
;
7982 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
7983 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
7985 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
7987 schedule
= isl_union_map_read_from_str(ctx
, str
);
7988 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
7989 build
= isl_ast_build_from_context(set
);
7990 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
7991 isl_ast_build_free(build
);
7995 type
= isl_ast_node_get_type(tree
);
7996 isl_ast_node_free(tree
);
7998 if (type
== isl_ast_node_if
)
7999 isl_die(ctx
, isl_error_unknown
,
8000 "not expecting if node", return -1);
8002 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
8004 schedule
= isl_union_map_read_from_str(ctx
, str
);
8005 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8006 build
= isl_ast_build_from_context(set
);
8007 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8008 isl_ast_build_free(build
);
8012 type
= isl_ast_node_get_type(tree
);
8013 isl_ast_node_free(tree
);
8015 if (type
!= isl_ast_node_if
)
8016 isl_die(ctx
, isl_error_unknown
,
8017 "expecting if node", return -1);
8019 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
8024 /* This function is called for each leaf in the AST generated
8025 * from test_ast_gen5.
8027 * We finalize the AST generation by extending the outer schedule
8028 * with a zero-dimensional schedule. If this results in any for loops,
8029 * then this means that we did not pass along enough information
8030 * about the outer schedule to the inner AST generation.
8032 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
8035 isl_union_map
*schedule
, *extra
;
8038 schedule
= isl_ast_build_get_schedule(build
);
8039 extra
= isl_union_map_copy(schedule
);
8040 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
8041 schedule
= isl_union_map_range_product(schedule
, extra
);
8042 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8043 isl_ast_build_free(build
);
8048 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
8049 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
8050 "code should not contain any for loop",
8051 return isl_ast_node_free(tree
));
8056 /* Check that we do not lose any information when going back and
8057 * forth between internal and external schedule.
8059 * In particular, we create an AST where we unroll the only
8060 * non-constant dimension in the schedule. We therefore do
8061 * not expect any for loops in the AST. However, older versions
8062 * of isl would not pass along enough information about the outer
8063 * schedule when performing an inner code generation from a create_leaf
8064 * callback, resulting in the inner code generation producing a for loop.
8066 static int test_ast_gen5(isl_ctx
*ctx
)
8070 isl_union_map
*schedule
, *options
;
8071 isl_ast_build
*build
;
8074 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
8075 schedule
= isl_union_map_read_from_str(ctx
, str
);
8077 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
8078 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
8079 options
= isl_union_map_read_from_str(ctx
, str
);
8081 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8082 build
= isl_ast_build_from_context(set
);
8083 build
= isl_ast_build_set_options(build
, options
);
8084 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
8085 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8086 isl_ast_build_free(build
);
8087 isl_ast_node_free(tree
);
8094 /* Check that the expression
8096 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
8098 * is not combined into
8102 * as this would result in n/2 being evaluated in parts of
8103 * the definition domain where n is not a multiple of 2.
8105 static int test_ast_expr(isl_ctx
*ctx
)
8109 isl_ast_build
*build
;
8114 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
8115 isl_options_set_ast_build_detect_min_max(ctx
, 1);
8117 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
8118 pa
= isl_pw_aff_read_from_str(ctx
, str
);
8119 build
= isl_ast_build_alloc(ctx
);
8120 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
8121 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
8122 isl_ast_expr_get_op_type(expr
) == isl_ast_op_min
;
8123 isl_ast_build_free(build
);
8124 isl_ast_expr_free(expr
);
8126 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
8131 isl_die(ctx
, isl_error_unknown
,
8132 "expressions should not be combined", return -1);
8137 static int test_ast_gen(isl_ctx
*ctx
)
8139 if (test_ast_gen1(ctx
) < 0)
8141 if (test_ast_gen2(ctx
) < 0)
8143 if (test_ast_gen3(ctx
) < 0)
8145 if (test_ast_gen4(ctx
) < 0)
8147 if (test_ast_gen5(ctx
) < 0)
8149 if (test_ast_expr(ctx
) < 0)
8154 /* Check if dropping output dimensions from an isl_pw_multi_aff
8157 static int test_pw_multi_aff(isl_ctx
*ctx
)
8160 isl_pw_multi_aff
*pma1
, *pma2
;
8163 str
= "{ [i,j] -> [i+j, 4i-j] }";
8164 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8165 str
= "{ [i,j] -> [4i-j] }";
8166 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8168 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
8170 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
8172 isl_pw_multi_aff_free(pma1
);
8173 isl_pw_multi_aff_free(pma2
);
8177 isl_die(ctx
, isl_error_unknown
,
8178 "expressions not equal", return -1);
8183 /* Check that we can properly parse multi piecewise affine expressions
8184 * where the piecewise affine expressions have different domains.
8186 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
8189 isl_set
*dom
, *dom2
;
8190 isl_multi_pw_aff
*mpa1
, *mpa2
;
8195 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
8196 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
8197 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
8198 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
8199 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
8200 str
= "{ [i] -> [(i : i > 0), 2i] }";
8201 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8203 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
8205 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
8206 dom
= isl_pw_aff_domain(pa
);
8207 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
8208 dom2
= isl_pw_aff_domain(pa
);
8209 equal_domain
= isl_set_is_equal(dom
, dom2
);
8213 isl_multi_pw_aff_free(mpa1
);
8214 isl_multi_pw_aff_free(mpa2
);
8219 isl_die(ctx
, isl_error_unknown
,
8220 "expressions not equal", return -1);
8222 if (equal_domain
< 0)
8225 isl_die(ctx
, isl_error_unknown
,
8226 "domains unexpectedly equal", return -1);
8231 /* Check that the dimensions in the explicit domain
8232 * of a multi piecewise affine expression are properly
8233 * taken into account.
8235 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
8238 isl_bool involves1
, involves2
, involves3
, equal
;
8239 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
8241 str
= "{ A[x,y] -> B[] : x >= y }";
8242 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8243 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
8244 mpa1
= isl_multi_pw_aff_copy(mpa
);
8246 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
8247 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
8248 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
8249 str
= "{ [a,x,y] -> B[] : x >= y }";
8250 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8251 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
8252 isl_multi_pw_aff_free(mpa2
);
8254 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
8255 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
8256 if (equal
>= 0 && equal
)
8257 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
8258 isl_multi_pw_aff_free(mpa1
);
8259 isl_multi_pw_aff_free(mpa
);
8261 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
8264 isl_die(ctx
, isl_error_unknown
,
8265 "incorrect result of dimension insertion/removal",
8266 return isl_stat_error
);
8267 if (!involves1
|| involves2
|| !involves3
)
8268 isl_die(ctx
, isl_error_unknown
,
8269 "incorrect characterization of involved dimensions",
8270 return isl_stat_error
);
8275 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
8276 * sets the explicit domain of a zero-dimensional result,
8277 * such that it can be converted to an isl_union_map.
8279 static isl_stat
test_multi_pw_aff_3(isl_ctx
*ctx
)
8284 isl_multi_union_pw_aff
*mupa
;
8285 isl_union_map
*umap
;
8287 dom
= isl_union_set_read_from_str(ctx
, "{ A[]; B[] }");
8288 space
= isl_union_set_get_space(dom
);
8289 mv
= isl_multi_val_zero(isl_space_set_from_params(space
));
8290 mupa
= isl_multi_union_pw_aff_multi_val_on_domain(dom
, mv
);
8291 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
8292 isl_union_map_free(umap
);
8294 return isl_stat_error
;
8299 /* Perform some tests on multi piecewise affine expressions.
8301 static int test_multi_pw_aff(isl_ctx
*ctx
)
8303 if (test_multi_pw_aff_1(ctx
) < 0)
8305 if (test_multi_pw_aff_2(ctx
) < 0)
8307 if (test_multi_pw_aff_3(ctx
) < 0)
8312 /* This is a regression test for a bug where isl_basic_map_simplify
8313 * would end up in an infinite loop. In particular, we construct
8314 * an empty basic set that is not obviously empty.
8315 * isl_basic_set_is_empty marks the basic set as empty.
8316 * After projecting out i3, the variable can be dropped completely,
8317 * but isl_basic_map_simplify refrains from doing so if the basic set
8318 * is empty and would end up in an infinite loop if it didn't test
8319 * explicitly for empty basic maps in the outer loop.
8321 static int test_simplify_1(isl_ctx
*ctx
)
8324 isl_basic_set
*bset
;
8327 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
8328 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
8329 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
8331 bset
= isl_basic_set_read_from_str(ctx
, str
);
8332 empty
= isl_basic_set_is_empty(bset
);
8333 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
8334 isl_basic_set_free(bset
);
8338 isl_die(ctx
, isl_error_unknown
,
8339 "basic set should be empty", return -1);
8344 /* Check that the equality in the set description below
8345 * is simplified away.
8347 static int test_simplify_2(isl_ctx
*ctx
)
8350 isl_basic_set
*bset
;
8353 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
8354 bset
= isl_basic_set_read_from_str(ctx
, str
);
8355 universe
= isl_basic_set_plain_is_universe(bset
);
8356 isl_basic_set_free(bset
);
8361 isl_die(ctx
, isl_error_unknown
,
8362 "equality not simplified away", return -1);
8366 /* Some simplification tests.
8368 static int test_simplify(isl_ctx
*ctx
)
8370 if (test_simplify_1(ctx
) < 0)
8372 if (test_simplify_2(ctx
) < 0)
8377 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
8378 * with gbr context would fail to disable the use of the shifted tableau
8379 * when transferring equalities for the input to the context, resulting
8380 * in invalid sample values.
8382 static int test_partial_lexmin(isl_ctx
*ctx
)
8385 isl_basic_set
*bset
;
8386 isl_basic_map
*bmap
;
8389 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
8390 bmap
= isl_basic_map_read_from_str(ctx
, str
);
8391 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
8392 bset
= isl_basic_set_read_from_str(ctx
, str
);
8393 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
8402 /* Check that the variable compression performed on the existentially
8403 * quantified variables inside isl_basic_set_compute_divs is not confused
8404 * by the implicit equalities among the parameters.
8406 static int test_compute_divs(isl_ctx
*ctx
)
8409 isl_basic_set
*bset
;
8412 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
8413 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
8414 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
8415 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
8416 bset
= isl_basic_set_read_from_str(ctx
, str
);
8417 set
= isl_basic_set_compute_divs(bset
);
8425 /* Check that isl_schedule_get_map is not confused by a schedule tree
8426 * with divergent filter node parameters, as can result from a call
8427 * to isl_schedule_intersect_domain.
8429 static int test_schedule_tree(isl_ctx
*ctx
)
8432 isl_union_set
*uset
;
8433 isl_schedule
*sched1
, *sched2
;
8434 isl_union_map
*umap
;
8436 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
8437 sched1
= isl_schedule_from_domain(uset
);
8438 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
8439 sched2
= isl_schedule_from_domain(uset
);
8441 sched1
= isl_schedule_sequence(sched1
, sched2
);
8442 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
8443 uset
= isl_union_set_read_from_str(ctx
, str
);
8444 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
8445 umap
= isl_schedule_get_map(sched1
);
8446 isl_schedule_free(sched1
);
8447 isl_union_map_free(umap
);
8454 /* Check that a zero-dimensional prefix schedule keeps track
8455 * of the domain and outer filters.
8457 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
8461 isl_union_set
*uset
;
8462 isl_union_set_list
*filters
;
8463 isl_multi_union_pw_aff
*mupa
, *mupa2
;
8464 isl_schedule_node
*node
;
8466 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8467 uset
= isl_union_set_read_from_str(ctx
, str
);
8468 node
= isl_schedule_node_from_domain(uset
);
8469 node
= isl_schedule_node_child(node
, 0);
8471 str
= "{ S1[i,j] : i > j }";
8472 uset
= isl_union_set_read_from_str(ctx
, str
);
8473 filters
= isl_union_set_list_from_union_set(uset
);
8474 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
8475 uset
= isl_union_set_read_from_str(ctx
, str
);
8476 filters
= isl_union_set_list_add(filters
, uset
);
8477 node
= isl_schedule_node_insert_sequence(node
, filters
);
8479 node
= isl_schedule_node_child(node
, 0);
8480 node
= isl_schedule_node_child(node
, 0);
8481 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
8482 str
= "([] : { S1[i,j] : i > j })";
8483 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8484 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
8485 isl_multi_union_pw_aff_free(mupa2
);
8486 isl_multi_union_pw_aff_free(mupa
);
8487 isl_schedule_node_free(node
);
8492 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
8498 /* Check that the reaching domain elements and the prefix schedule
8499 * at a leaf node are the same before and after grouping.
8501 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
8506 isl_union_set
*uset
;
8507 isl_multi_union_pw_aff
*mupa
;
8508 isl_union_pw_multi_aff
*upma1
, *upma2
;
8509 isl_union_set
*domain1
, *domain2
;
8510 isl_union_map
*umap1
, *umap2
;
8511 isl_schedule_node
*node
;
8513 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8514 uset
= isl_union_set_read_from_str(ctx
, str
);
8515 node
= isl_schedule_node_from_domain(uset
);
8516 node
= isl_schedule_node_child(node
, 0);
8517 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
8518 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8519 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8520 node
= isl_schedule_node_child(node
, 0);
8521 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
8522 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8523 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8524 node
= isl_schedule_node_child(node
, 0);
8525 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
8526 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
8527 domain1
= isl_schedule_node_get_domain(node
);
8528 id
= isl_id_alloc(ctx
, "group", NULL
);
8529 node
= isl_schedule_node_parent(node
);
8530 node
= isl_schedule_node_group(node
, id
);
8531 node
= isl_schedule_node_child(node
, 0);
8532 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
8533 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
8534 domain2
= isl_schedule_node_get_domain(node
);
8535 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
8536 if (equal
>= 0 && equal
)
8537 equal
= isl_union_set_is_equal(domain1
, domain2
);
8538 if (equal
>= 0 && equal
)
8539 equal
= isl_union_map_is_equal(umap1
, umap2
);
8540 isl_union_map_free(umap1
);
8541 isl_union_map_free(umap2
);
8542 isl_union_set_free(domain1
);
8543 isl_union_set_free(domain2
);
8544 isl_union_pw_multi_aff_free(upma1
);
8545 isl_union_pw_multi_aff_free(upma2
);
8546 isl_schedule_node_free(node
);
8551 isl_die(ctx
, isl_error_unknown
,
8552 "expressions not equal", return -1);
8557 /* Check that we can have nested groupings and that the union map
8558 * schedule representation is the same before and after the grouping.
8559 * Note that after the grouping, the union map representation contains
8560 * the domain constraints from the ranges of the expansion nodes,
8561 * while they are missing from the union map representation of
8562 * the tree without expansion nodes.
8564 * Also check that the global expansion is as expected.
8566 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
8568 int equal
, equal_expansion
;
8571 isl_union_set
*uset
;
8572 isl_union_map
*umap1
, *umap2
;
8573 isl_union_map
*expansion1
, *expansion2
;
8574 isl_union_set_list
*filters
;
8575 isl_multi_union_pw_aff
*mupa
;
8576 isl_schedule
*schedule
;
8577 isl_schedule_node
*node
;
8579 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
8580 "S3[i,j] : 0 <= i,j < 10 }";
8581 uset
= isl_union_set_read_from_str(ctx
, str
);
8582 node
= isl_schedule_node_from_domain(uset
);
8583 node
= isl_schedule_node_child(node
, 0);
8584 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
8585 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8586 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8587 node
= isl_schedule_node_child(node
, 0);
8588 str
= "{ S1[i,j] }";
8589 uset
= isl_union_set_read_from_str(ctx
, str
);
8590 filters
= isl_union_set_list_from_union_set(uset
);
8591 str
= "{ S2[i,j]; S3[i,j] }";
8592 uset
= isl_union_set_read_from_str(ctx
, str
);
8593 filters
= isl_union_set_list_add(filters
, uset
);
8594 node
= isl_schedule_node_insert_sequence(node
, filters
);
8595 node
= isl_schedule_node_child(node
, 1);
8596 node
= isl_schedule_node_child(node
, 0);
8597 str
= "{ S2[i,j] }";
8598 uset
= isl_union_set_read_from_str(ctx
, str
);
8599 filters
= isl_union_set_list_from_union_set(uset
);
8600 str
= "{ S3[i,j] }";
8601 uset
= isl_union_set_read_from_str(ctx
, str
);
8602 filters
= isl_union_set_list_add(filters
, uset
);
8603 node
= isl_schedule_node_insert_sequence(node
, filters
);
8605 schedule
= isl_schedule_node_get_schedule(node
);
8606 umap1
= isl_schedule_get_map(schedule
);
8607 uset
= isl_schedule_get_domain(schedule
);
8608 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
8609 isl_schedule_free(schedule
);
8611 node
= isl_schedule_node_parent(node
);
8612 node
= isl_schedule_node_parent(node
);
8613 id
= isl_id_alloc(ctx
, "group1", NULL
);
8614 node
= isl_schedule_node_group(node
, id
);
8615 node
= isl_schedule_node_child(node
, 1);
8616 node
= isl_schedule_node_child(node
, 0);
8617 id
= isl_id_alloc(ctx
, "group2", NULL
);
8618 node
= isl_schedule_node_group(node
, id
);
8620 schedule
= isl_schedule_node_get_schedule(node
);
8621 umap2
= isl_schedule_get_map(schedule
);
8622 isl_schedule_free(schedule
);
8624 node
= isl_schedule_node_root(node
);
8625 node
= isl_schedule_node_child(node
, 0);
8626 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
8627 isl_schedule_node_free(node
);
8629 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
8630 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
8631 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
8633 expansion2
= isl_union_map_read_from_str(ctx
, str
);
8635 equal
= isl_union_map_is_equal(umap1
, umap2
);
8636 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
8638 isl_union_map_free(umap1
);
8639 isl_union_map_free(umap2
);
8640 isl_union_map_free(expansion1
);
8641 isl_union_map_free(expansion2
);
8643 if (equal
< 0 || equal_expansion
< 0)
8646 isl_die(ctx
, isl_error_unknown
,
8647 "expressions not equal", return -1);
8648 if (!equal_expansion
)
8649 isl_die(ctx
, isl_error_unknown
,
8650 "unexpected expansion", return -1);
8655 /* Some tests for the isl_schedule_node_group function.
8657 static int test_schedule_tree_group(isl_ctx
*ctx
)
8659 if (test_schedule_tree_group_1(ctx
) < 0)
8661 if (test_schedule_tree_group_2(ctx
) < 0)
8670 { "{ rat: [i] : 0 <= i <= 10 }",
8671 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
8672 { "{ rat: [i] : FALSE }",
8673 "{ rat: coefficients[[cst] -> [a]] }" },
8675 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
8682 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
8683 "{ rat: [i] : 0 <= i <= 10 }" },
8684 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
8686 { "{ rat: coefficients[[cst] -> [a]] }",
8687 "{ rat: [i] : FALSE }" },
8690 /* Test the basic functionality of isl_basic_set_coefficients and
8691 * isl_basic_set_solutions.
8693 static int test_dual(isl_ctx
*ctx
)
8697 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
8699 isl_basic_set
*bset1
, *bset2
;
8701 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
8702 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
8703 bset1
= isl_basic_set_coefficients(bset1
);
8704 equal
= isl_basic_set_is_equal(bset1
, bset2
);
8705 isl_basic_set_free(bset1
);
8706 isl_basic_set_free(bset2
);
8710 isl_die(ctx
, isl_error_unknown
,
8711 "incorrect dual", return -1);
8714 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
8716 isl_basic_set
*bset1
, *bset2
;
8718 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
8719 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
8720 bset1
= isl_basic_set_solutions(bset1
);
8721 equal
= isl_basic_set_is_equal(bset1
, bset2
);
8722 isl_basic_set_free(bset1
);
8723 isl_basic_set_free(bset2
);
8727 isl_die(ctx
, isl_error_unknown
,
8728 "incorrect dual", return -1);
8738 const char *schedule
;
8743 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
8744 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8746 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
8747 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8749 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
8750 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8752 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
8753 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8755 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
8756 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8758 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
8759 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
8761 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
8762 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8764 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
8765 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
8769 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
8770 * tile the band and then check if the tile and point bands have the
8771 * expected partial schedule.
8773 static int test_tile(isl_ctx
*ctx
)
8779 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
8780 shift
= isl_options_get_tile_shift_point_loops(ctx
);
8782 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
8786 isl_union_set
*domain
;
8787 isl_multi_union_pw_aff
*mupa
, *mupa2
;
8788 isl_schedule_node
*node
;
8789 isl_multi_val
*sizes
;
8791 opt
= tile_tests
[i
].scale_tile
;
8792 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
8793 opt
= tile_tests
[i
].shift_point
;
8794 isl_options_set_tile_shift_point_loops(ctx
, opt
);
8796 str
= tile_tests
[i
].domain
;
8797 domain
= isl_union_set_read_from_str(ctx
, str
);
8798 node
= isl_schedule_node_from_domain(domain
);
8799 node
= isl_schedule_node_child(node
, 0);
8800 str
= tile_tests
[i
].schedule
;
8801 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8802 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8803 str
= tile_tests
[i
].sizes
;
8804 sizes
= isl_multi_val_read_from_str(ctx
, str
);
8805 node
= isl_schedule_node_band_tile(node
, sizes
);
8807 str
= tile_tests
[i
].tile
;
8808 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8809 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
8810 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
8811 isl_multi_union_pw_aff_free(mupa
);
8812 isl_multi_union_pw_aff_free(mupa2
);
8814 node
= isl_schedule_node_child(node
, 0);
8816 str
= tile_tests
[i
].point
;
8817 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8818 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
8819 if (equal
>= 0 && equal
)
8820 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
8822 isl_multi_union_pw_aff_free(mupa
);
8823 isl_multi_union_pw_aff_free(mupa2
);
8825 isl_schedule_node_free(node
);
8830 isl_die(ctx
, isl_error_unknown
,
8831 "unexpected result", return -1);
8834 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
8835 isl_options_set_tile_shift_point_loops(ctx
, shift
);
8840 /* Check that the domain hash of a space is equal to the hash
8841 * of the domain of the space.
8843 static int test_domain_hash(isl_ctx
*ctx
)
8847 uint32_t hash1
, hash2
;
8849 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
8850 space
= isl_map_get_space(map
);
8852 hash1
= isl_space_get_domain_hash(space
);
8853 space
= isl_space_domain(space
);
8854 hash2
= isl_space_get_hash(space
);
8855 isl_space_free(space
);
8860 isl_die(ctx
, isl_error_unknown
,
8861 "domain hash not equal to hash of domain", return -1);
8866 /* Check that a universe basic set that is not obviously equal to the universe
8867 * is still recognized as being equal to the universe.
8869 static int test_universe(isl_ctx
*ctx
)
8872 isl_basic_set
*bset
;
8875 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
8876 bset
= isl_basic_set_read_from_str(ctx
, s
);
8877 is_univ
= isl_basic_set_is_universe(bset
);
8878 isl_basic_set_free(bset
);
8883 isl_die(ctx
, isl_error_unknown
,
8884 "not recognized as universe set", return -1);
8889 /* Sets for which chambers are computed and checked.
8891 const char *chambers_tests
[] = {
8892 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
8893 "z >= 0 and z <= C - y and z <= B - x - y }",
8896 /* Add the domain of "cell" to "cells".
8898 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
8900 isl_basic_set_list
**cells
= user
;
8903 dom
= isl_cell_get_domain(cell
);
8904 isl_cell_free(cell
);
8905 *cells
= isl_basic_set_list_add(*cells
, dom
);
8907 return *cells
? isl_stat_ok
: isl_stat_error
;
8910 /* Check that the elements of "list" are pairwise disjoint.
8912 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
8917 return isl_stat_error
;
8919 n
= isl_basic_set_list_n_basic_set(list
);
8920 for (i
= 0; i
< n
; ++i
) {
8921 isl_basic_set
*bset_i
;
8923 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
8924 for (j
= i
+ 1; j
< n
; ++j
) {
8925 isl_basic_set
*bset_j
;
8928 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
8929 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
8930 isl_basic_set_free(bset_j
);
8932 isl_die(isl_basic_set_list_get_ctx(list
),
8933 isl_error_unknown
, "not disjoint",
8935 if (disjoint
< 0 || !disjoint
)
8938 isl_basic_set_free(bset_i
);
8940 return isl_stat_error
;
8946 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
8947 * are pairwise disjoint.
8949 static int test_chambers(isl_ctx
*ctx
)
8953 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
8954 isl_basic_set
*bset
;
8955 isl_vertices
*vertices
;
8956 isl_basic_set_list
*cells
;
8959 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
8960 vertices
= isl_basic_set_compute_vertices(bset
);
8961 cells
= isl_basic_set_list_alloc(ctx
, 0);
8962 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
8964 cells
= isl_basic_set_list_free(cells
);
8965 ok
= check_pairwise_disjoint(cells
);
8966 isl_basic_set_list_free(cells
);
8967 isl_vertices_free(vertices
);
8968 isl_basic_set_free(bset
);
8979 int (*fn
)(isl_ctx
*ctx
);
8981 { "universe", &test_universe
},
8982 { "domain hash", &test_domain_hash
},
8983 { "dual", &test_dual
},
8984 { "dependence analysis", &test_flow
},
8985 { "val", &test_val
},
8986 { "compute divs", &test_compute_divs
},
8987 { "partial lexmin", &test_partial_lexmin
},
8988 { "simplify", &test_simplify
},
8989 { "curry", &test_curry
},
8990 { "piecewise multi affine expressions", &test_pw_multi_aff
},
8991 { "multi piecewise affine expressions", &test_multi_pw_aff
},
8992 { "conversion", &test_conversion
},
8993 { "list", &test_list
},
8994 { "align parameters", &test_align_parameters
},
8995 { "drop unused parameters", &test_drop_unused_parameters
},
8996 { "preimage", &test_preimage
},
8997 { "pullback", &test_pullback
},
8998 { "AST", &test_ast
},
8999 { "AST build", &test_ast_build
},
9000 { "AST generation", &test_ast_gen
},
9001 { "eliminate", &test_eliminate
},
9002 { "residue class", &test_residue_class
},
9003 { "div", &test_div
},
9004 { "slice", &test_slice
},
9005 { "fixed power", &test_fixed_power
},
9006 { "sample", &test_sample
},
9007 { "output", &test_output
},
9008 { "vertices", &test_vertices
},
9009 { "chambers", &test_chambers
},
9010 { "fixed", &test_fixed
},
9011 { "equal", &test_equal
},
9012 { "disjoint", &test_disjoint
},
9013 { "product", &test_product
},
9014 { "dim_max", &test_dim_max
},
9015 { "affine", &test_aff
},
9016 { "injective", &test_injective
},
9017 { "schedule (whole component)", &test_schedule_whole
},
9018 { "schedule (incremental)", &test_schedule_incremental
},
9019 { "schedule tree", &test_schedule_tree
},
9020 { "schedule tree prefix", &test_schedule_tree_prefix
},
9021 { "schedule tree grouping", &test_schedule_tree_group
},
9022 { "tile", &test_tile
},
9023 { "union_pw", &test_union_pw
},
9024 { "locus", &test_locus
},
9025 { "eval", &test_eval
},
9026 { "parse", &test_parse
},
9027 { "single-valued", &test_sv
},
9028 { "affine hull", &test_affine_hull
},
9029 { "simple_hull", &test_simple_hull
},
9030 { "coalesce", &test_coalesce
},
9031 { "factorize", &test_factorize
},
9032 { "subset", &test_subset
},
9033 { "subtract", &test_subtract
},
9034 { "intersect", &test_intersect
},
9035 { "lexmin", &test_lexmin
},
9036 { "min", &test_min
},
9037 { "gist", &test_gist
},
9038 { "piecewise quasi-polynomials", &test_pwqp
},
9039 { "lift", &test_lift
},
9040 { "bound", &test_bound
},
9041 { "union", &test_union
},
9042 { "split periods", &test_split_periods
},
9043 { "lexicographic order", &test_lex
},
9044 { "bijectivity", &test_bijective
},
9045 { "dataflow analysis", &test_dep
},
9046 { "reading", &test_read
},
9047 { "bounded", &test_bounded
},
9048 { "construction", &test_construction
},
9049 { "dimension manipulation", &test_dim
},
9050 { "map application", &test_application
},
9051 { "convex hull", &test_convex_hull
},
9052 { "transitive closure", &test_closure
},
9055 int main(int argc
, char **argv
)
9058 struct isl_ctx
*ctx
;
9059 struct isl_options
*options
;
9061 options
= isl_options_new_with_defaults();
9063 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
9065 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
9066 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
9067 printf("%s\n", tests
[i
].name
);
9068 if (tests
[i
].fn(ctx
) < 0)