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_pow2
, "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_pow2
, "-3", "1/8" },
714 { &isl_val_pow2
, "-1", "1/2" },
715 { &isl_val_pow2
, "1", "2" },
716 { &isl_val_pow2
, "2", "4" },
717 { &isl_val_pow2
, "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);
1602 /* Inputs for isl_basic_set_gist tests that are expected to fail.
1606 const char *context
;
1607 } gist_fail_tests
[] = {
1608 { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1609 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1610 "{ [i] : i >= 0 }" },
1613 /* Check that isl_basic_set_gist fails (gracefully) when expected.
1614 * In particular, the user should be able to recover from the failure.
1616 static isl_stat
test_gist_fail(struct isl_ctx
*ctx
)
1621 on_error
= isl_options_get_on_error(ctx
);
1622 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
1623 n
= ARRAY_SIZE(gist_fail_tests
);
1624 for (i
= 0; i
< n
; ++i
) {
1626 isl_basic_set
*bset
, *context
;
1628 bset
= isl_basic_set_read_from_str(ctx
, gist_fail_tests
[i
].set
);
1629 str
= gist_fail_tests
[i
].context
;
1630 context
= isl_basic_set_read_from_str(ctx
, str
);
1631 bset
= isl_basic_set_gist(bset
, context
);
1632 isl_basic_set_free(bset
);
1636 isl_options_set_on_error(ctx
, on_error
);
1638 isl_die(ctx
, isl_error_unknown
,
1639 "operation not expected to succeed",
1640 return isl_stat_error
);
1647 const char *context
;
1650 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1651 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1652 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1653 "{ [a, b, c] : a <= 15 }" },
1654 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1655 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1656 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1657 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1658 { "{ [m, n, a, b] : a <= 2147 + n }",
1659 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1660 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1661 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1663 "{ [m, n, ku, kl] }" },
1664 { "{ [a, a, b] : a >= 10 }",
1665 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1666 "{ [a, a, b] : a >= 10 }" },
1667 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1668 "{ [0, j] : j >= 0 }" },
1669 /* Check that no constraints on i6 are introduced in the gist */
1670 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1671 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1672 "5e0 <= 381 - t1 and i4 <= 1) }",
1673 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1674 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1675 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1676 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1677 "20e0 >= 1511 - 4t1 - 5i4) }" },
1678 /* Check that no constraints on i6 are introduced in the gist */
1679 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1680 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1681 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1682 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1683 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1684 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1685 "20e1 <= 1530 - 4t1 - 5i4 and "
1686 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1687 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1688 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1689 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1690 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1691 "10e0 <= -91 + 5i4 + 4i6 and "
1692 "10e0 >= -105 + 5i4 + 4i6) }",
1693 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1694 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1695 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1696 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1697 "{ [a, b, q, p] : b >= 1 + a }",
1698 "{ [a, b, q, p] : false }" },
1699 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1700 "[n] -> { [x] : x mod 32 = 0 }",
1701 "[n] -> { [x = n] }" },
1702 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1703 "{ [x] : x mod 2 = 0 }" },
1704 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1705 "{ [x] : x mod 128 = 0 }" },
1706 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1707 "{ [x] : x mod 3200 = 0 }" },
1708 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1709 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1710 "{ [a, b, c = a] }" },
1711 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1712 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1713 "{ [a, b, c = a] : a mod 3 = 0 }" },
1714 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1715 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1717 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1718 "{ [x,y] : 1 <= y <= 3 }",
1722 /* Check that isl_set_gist behaves as expected.
1724 * For the test cases in gist_tests, besides checking that the result
1725 * is as expected, also check that applying the gist operation does
1726 * not modify the input set (an earlier version of isl would do that) and
1727 * that the test case is consistent, i.e., that the gist has the same
1728 * intersection with the context as the input set.
1730 static int test_gist(struct isl_ctx
*ctx
)
1734 isl_basic_set
*bset1
, *bset2
;
1735 isl_map
*map1
, *map2
;
1738 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1739 int equal_input
, equal_intersection
;
1740 isl_set
*set1
, *set2
, *copy
, *context
;
1742 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1743 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1744 copy
= isl_set_copy(set1
);
1745 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1746 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1747 equal
= isl_set_is_equal(set1
, set2
);
1749 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1750 equal_input
= isl_set_is_equal(set1
, copy
);
1752 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1753 set2
= isl_set_intersect(set2
, context
);
1754 equal_intersection
= isl_set_is_equal(set1
, set2
);
1757 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1760 isl_die(ctx
, isl_error_unknown
,
1761 "incorrect gist result", return -1);
1763 isl_die(ctx
, isl_error_unknown
,
1764 "gist modified input", return -1);
1766 isl_die(ctx
, isl_error_unknown
,
1767 "inconsistent gist test case", return -1);
1770 if (test_gist_fail(ctx
) < 0)
1773 test_gist_case(ctx
, "gist1");
1775 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1776 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1777 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1778 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1779 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1780 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1781 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1782 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1783 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1784 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1785 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1786 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1787 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1788 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1789 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1790 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1791 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1792 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1793 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1794 bset1
= isl_basic_set_gist(bset1
, bset2
);
1795 assert(bset1
&& bset1
->n_div
== 0);
1796 isl_basic_set_free(bset1
);
1798 /* Check that the integer divisions of the second disjunct
1799 * do not spread to the first disjunct.
1801 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1802 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1803 "(exists (e0 = [(-1 + t1)/16], "
1804 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1805 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1806 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1807 "o0 <= 4294967295 and t1 <= -1)) }";
1808 map1
= isl_map_read_from_str(ctx
, str
);
1809 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1810 map2
= isl_map_read_from_str(ctx
, str
);
1811 map1
= isl_map_gist(map1
, map2
);
1815 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1816 isl_map_free(map1
); return -1);
1817 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1818 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1819 isl_map_free(map1
); return -1);
1822 if (test_plain_gist(ctx
) < 0)
1828 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1830 isl_set
*set
, *set2
;
1834 set
= isl_set_read_from_str(ctx
, str
);
1835 set
= isl_set_coalesce(set
);
1836 set2
= isl_set_read_from_str(ctx
, str
);
1837 equal
= isl_set_is_equal(set
, set2
);
1838 one
= set
&& set
->n
== 1;
1845 isl_die(ctx
, isl_error_unknown
,
1846 "coalesced set not equal to input", return -1);
1847 if (check_one
&& !one
)
1848 isl_die(ctx
, isl_error_unknown
,
1849 "coalesced set should not be a union", return -1);
1854 /* Inputs for coalescing tests with unbounded wrapping.
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_unbounded_tests
[] = {
1863 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1864 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1865 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1866 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1868 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1869 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1870 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1871 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1874 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1875 * option turned off.
1877 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1883 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1884 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1886 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
1887 const char *str
= coalesce_unbounded_tests
[i
].str
;
1888 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
1889 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
1895 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1900 /* Inputs for coalescing tests.
1901 * "str" is a string representation of the input set.
1902 * "single_disjunct" is set if we expect the result to consist of
1903 * a single disjunct.
1906 int single_disjunct
;
1908 } coalesce_tests
[] = {
1909 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1910 "y >= x & x >= 2 & 5 >= y }" },
1911 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1912 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1913 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1914 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1915 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1916 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1917 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1918 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1919 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1920 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1921 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1922 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1923 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1924 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1925 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1926 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1927 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1928 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1929 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1930 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1931 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1932 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1933 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1934 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1935 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1936 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1937 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1938 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1939 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1940 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1941 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1942 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1943 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1944 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1945 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1946 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1947 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1948 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1949 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1950 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1951 "[o0, o1, o2, o3, o4, o5, o6]] : "
1952 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1953 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1954 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1955 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1956 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1957 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1958 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1959 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1960 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1961 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1962 "o6 >= i3 + i6 - o3 and M >= 0 and "
1963 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1964 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1965 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1966 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1967 "(o0 = 0 and M >= 2 and N >= 3) or "
1968 "(M = 0 and o0 = 0 and N >= 3) }" },
1969 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1970 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1971 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1972 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1973 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1974 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1975 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1976 "(y = 3 and x = 1) }" },
1977 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1978 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1979 "i1 <= M and i3 <= M and i4 <= M) or "
1980 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1981 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1982 "i4 <= -1 + M) }" },
1983 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1984 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1985 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1986 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1987 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1988 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1989 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1990 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1991 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1992 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1993 { 0, "{ [a, b] : exists e : 2e = a and "
1994 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1995 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1996 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1997 "j >= 1 and j' <= i + j - i' and i >= 1; "
1999 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
2000 "[i,j] : exists a : j = 3a }" },
2001 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
2002 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
2004 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
2005 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
2006 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
2007 "c <= 6 + 8a and a >= 3; "
2008 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
2009 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
2010 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2011 "[x,0] : 3 <= x <= 4 }" },
2012 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
2013 "[x,0] : 4 <= x <= 5 }" },
2014 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2015 "[x,0] : 3 <= x <= 5 }" },
2016 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
2017 "[x,0] : 3 <= x <= 4 }" },
2018 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
2020 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
2021 { 1, "{ [0,0]; [1,1] }" },
2022 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
2023 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
2025 "[k, 0, k] : k <= 6 and k >= 1 }" },
2026 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
2027 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
2028 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
2029 { 1, "[n] -> { [1] : n >= 0;"
2030 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
2031 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
2032 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
2033 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
2034 "2e0 <= x and 2e0 <= n);"
2035 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
2037 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
2038 "128e0 >= -134 + 127t1 and t1 >= 2 and "
2039 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
2041 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
2042 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
2044 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
2045 "t1 >= 13 and t1 <= 16);"
2046 "[t1] : t1 <= 15 and t1 >= 12 }" },
2047 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2048 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2049 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2050 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2051 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2052 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2054 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2055 "(exists (e0 : 3e0 = -2 + c0)) }" },
2056 { 0, "[n, b0, t0] -> "
2057 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2058 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2059 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2060 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2061 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2062 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2063 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2064 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2065 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2066 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2067 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2068 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2069 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2070 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2071 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2072 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2073 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2074 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2075 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2076 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2077 { 0, "{ [i0, i1, i2] : "
2078 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2079 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2080 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2081 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2082 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2083 "32e0 <= 31 + i0)) or "
2085 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2086 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2087 "2*floor((c)/2) = c and 0 <= a <= 192;"
2088 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2090 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2091 "(0 <= a <= b <= n) }" },
2092 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2093 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2094 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2095 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2096 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2097 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2098 "b = 3 and 9e0 <= -19 + 2c)) }" },
2099 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2100 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2101 "(a = 4 and b = 3 and "
2102 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2103 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2104 "(b = -1 + a and 0 < a <= 3 and "
2105 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2106 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2107 "b = 3 and 9e0 <= -19 + 2c)) }" },
2108 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2110 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2112 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2113 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2114 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2115 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2116 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2117 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2118 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2119 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2120 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2121 { 1, "{ [a] : a <= 8 and "
2122 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2123 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2124 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2125 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2126 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2127 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2128 "(a < 0 and 3*floor((a)/3) < a) }" },
2129 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2130 "(a < -1 and 3*floor((a)/3) < a) }" },
2131 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2132 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2133 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2134 "or (2 <= a <= 15 and b < a)) }" },
2135 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2136 "32*floor((a)/32) < a) or a <= 15) }" },
2137 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2138 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2139 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2140 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2141 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2142 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2143 "S_0[n] : n <= m <= 2 + n }" },
2144 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2145 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2147 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2148 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2149 "2e0 < -a + 2b) }" },
2150 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2151 "[i, 0, i] : 0 <= i <= 7 }" },
2152 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2153 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2154 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2155 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2156 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2157 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2158 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2159 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2160 "a > 0 and a <= 5) }" },
2161 { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" },
2164 /* A specialized coalescing test case that would result
2165 * in a segmentation fault or a failed assertion in earlier versions of isl.
2167 static int test_coalesce_special(struct isl_ctx
*ctx
)
2170 isl_map
*map1
, *map2
;
2172 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2173 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2174 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2175 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2176 "o1 <= 239 and o1 >= 212)) or "
2177 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2178 "o1 <= 241 and o1 >= 240));"
2179 "[S_L220_OUT[] -> T7[]] -> "
2180 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2181 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2182 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2183 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2184 map1
= isl_map_read_from_str(ctx
, str
);
2185 map1
= isl_map_align_divs_internal(map1
);
2186 map1
= isl_map_coalesce(map1
);
2187 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2188 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2189 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2190 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2191 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2192 map2
= isl_map_read_from_str(ctx
, str
);
2193 map2
= isl_map_union(map2
, map1
);
2194 map2
= isl_map_align_divs_internal(map2
);
2195 map2
= isl_map_coalesce(map2
);
2203 /* A specialized coalescing test case that would result in an assertion
2204 * in an earlier version of isl.
2205 * The explicit call to isl_basic_set_union prevents the implicit
2206 * equality constraints in the first basic map from being detected prior
2207 * to the call to isl_set_coalesce, at least at the point
2208 * where this test case was introduced.
2210 static int test_coalesce_special2(struct isl_ctx
*ctx
)
2213 isl_basic_set
*bset1
, *bset2
;
2216 str
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2217 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2218 str
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2219 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2220 set
= isl_basic_set_union(bset1
, bset2
);
2221 set
= isl_set_coalesce(set
);
2229 /* Check that calling isl_set_coalesce does not leave other sets
2230 * that may share some information with the input to isl_set_coalesce
2231 * in an inconsistent state.
2232 * In particular, older versions of isl would modify all copies
2233 * of the basic sets in the isl_set_coalesce input in a way
2234 * that could leave them in an inconsistent state.
2235 * The result of printing any other set containing one of these
2236 * basic sets would then result in an invalid set description.
2238 static int test_coalesce_special3(isl_ctx
*ctx
)
2242 isl_set
*set1
, *set2
;
2245 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2246 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2247 set2
= isl_set_read_from_str(ctx
, str
);
2248 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2249 set1
= isl_set_coalesce(set1
);
2252 p
= isl_printer_to_str(ctx
);
2253 p
= isl_printer_print_set(p
, set2
);
2255 s
= isl_printer_get_str(p
);
2256 isl_printer_free(p
);
2257 set1
= isl_set_read_from_str(ctx
, s
);
2267 /* Check that calling isl_set_coalesce does not leave other sets
2268 * that may share some information with the input to isl_set_coalesce
2269 * in an inconsistent state.
2270 * In particular, when isl_set_coalesce detects equality constraints,
2271 * it does not immediately perform Gaussian elimination on them,
2272 * but then it needs to ensure that it is performed at some point.
2273 * The input set has implicit equality constraints in the first disjunct.
2274 * It is constructed as an intersection, because otherwise
2275 * those equality constraints would already be detected during parsing.
2277 static isl_stat
test_coalesce_special4(isl_ctx
*ctx
)
2279 isl_set
*set1
, *set2
;
2281 set1
= isl_set_read_from_str(ctx
, "{ [a, b] : b <= 0 or a <= 1 }");
2282 set2
= isl_set_read_from_str(ctx
, "{ [a, b] : -1 <= -a < b }");
2283 set1
= isl_set_intersect(set1
, set2
);
2284 isl_set_free(isl_set_coalesce(isl_set_copy(set1
)));
2285 set1
= isl_set_coalesce(set1
);
2289 return isl_stat_error
;
2294 /* Test the functionality of isl_set_coalesce.
2295 * That is, check that the output is always equal to the input
2296 * and in some cases that the result consists of a single disjunct.
2298 static int test_coalesce(struct isl_ctx
*ctx
)
2302 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2303 const char *str
= coalesce_tests
[i
].str
;
2304 int check_one
= coalesce_tests
[i
].single_disjunct
;
2305 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2309 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2311 if (test_coalesce_special(ctx
) < 0)
2313 if (test_coalesce_special2(ctx
) < 0)
2315 if (test_coalesce_special3(ctx
) < 0)
2317 if (test_coalesce_special4(ctx
) < 0)
2323 /* Construct a representation of the graph on the right of Figure 1
2324 * in "Computing the Transitive Closure of a Union of
2325 * Affine Integer Tuple Relations".
2327 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2330 isl_map
*up
, *right
;
2332 dom
= isl_set_read_from_str(ctx
,
2333 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2334 "2 x - 3 y + 3 >= 0 }");
2335 right
= isl_map_read_from_str(ctx
,
2336 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2337 up
= isl_map_read_from_str(ctx
,
2338 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2339 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2340 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2341 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2342 up
= isl_map_intersect_range(up
, dom
);
2343 return isl_map_union(up
, right
);
2346 /* Construct a representation of the power of the graph
2347 * on the right of Figure 1 in "Computing the Transitive Closure of
2348 * a Union of Affine Integer Tuple Relations".
2350 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2352 return isl_map_read_from_str(ctx
,
2353 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2354 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2355 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2358 /* Construct a representation of the transitive closure of the graph
2359 * on the right of Figure 1 in "Computing the Transitive Closure of
2360 * a Union of Affine Integer Tuple Relations".
2362 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2364 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2367 static int test_closure(isl_ctx
*ctx
)
2370 isl_map
*map
, *map2
;
2373 /* COCOA example 1 */
2374 map
= isl_map_read_from_str(ctx
,
2375 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2376 "1 <= i and i < n and 1 <= j and j < n or "
2377 "i2 = i + 1 and j2 = j - 1 and "
2378 "1 <= i and i < n and 2 <= j and j <= n }");
2379 map
= isl_map_power(map
, &exact
);
2383 /* COCOA example 1 */
2384 map
= isl_map_read_from_str(ctx
,
2385 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2386 "1 <= i and i < n and 1 <= j and j < n or "
2387 "i2 = i + 1 and j2 = j - 1 and "
2388 "1 <= i and i < n and 2 <= j and j <= n }");
2389 map
= isl_map_transitive_closure(map
, &exact
);
2391 map2
= isl_map_read_from_str(ctx
,
2392 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2393 "1 <= i and i < n and 1 <= j and j <= n and "
2394 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2395 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2396 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2397 assert(isl_map_is_equal(map
, map2
));
2401 map
= isl_map_read_from_str(ctx
,
2402 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2403 " 0 <= y and y <= n }");
2404 map
= isl_map_transitive_closure(map
, &exact
);
2405 map2
= isl_map_read_from_str(ctx
,
2406 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2407 " 0 <= y and y <= n }");
2408 assert(isl_map_is_equal(map
, map2
));
2412 /* COCOA example 2 */
2413 map
= isl_map_read_from_str(ctx
,
2414 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2415 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2416 "i2 = i + 2 and j2 = j - 2 and "
2417 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2418 map
= isl_map_transitive_closure(map
, &exact
);
2420 map2
= isl_map_read_from_str(ctx
,
2421 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2422 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2423 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2424 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2425 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2426 assert(isl_map_is_equal(map
, map2
));
2430 /* COCOA Fig.2 left */
2431 map
= isl_map_read_from_str(ctx
,
2432 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2433 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2435 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2436 "j <= 2 i - 3 and j <= n - 2 or "
2437 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2438 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2439 map
= isl_map_transitive_closure(map
, &exact
);
2443 /* COCOA Fig.2 right */
2444 map
= isl_map_read_from_str(ctx
,
2445 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2446 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2448 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2449 "j <= 2 i - 4 and j <= n - 3 or "
2450 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2451 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2452 map
= isl_map_power(map
, &exact
);
2456 /* COCOA Fig.2 right */
2457 map
= isl_map_read_from_str(ctx
,
2458 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2459 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2461 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2462 "j <= 2 i - 4 and j <= n - 3 or "
2463 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2464 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2465 map
= isl_map_transitive_closure(map
, &exact
);
2467 map2
= isl_map_read_from_str(ctx
,
2468 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2469 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2470 "j <= n and 3 + i + 2 j <= 3 n and "
2471 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2472 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2473 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2474 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2475 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2476 assert(isl_map_is_equal(map
, map2
));
2480 map
= cocoa_fig_1_right_graph(ctx
);
2481 map
= isl_map_transitive_closure(map
, &exact
);
2483 map2
= cocoa_fig_1_right_tc(ctx
);
2484 assert(isl_map_is_equal(map
, map2
));
2488 map
= cocoa_fig_1_right_graph(ctx
);
2489 map
= isl_map_power(map
, &exact
);
2490 map2
= cocoa_fig_1_right_power(ctx
);
2491 equal
= isl_map_is_equal(map
, map2
);
2497 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2499 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2501 /* COCOA Theorem 1 counter example */
2502 map
= isl_map_read_from_str(ctx
,
2503 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2504 "i2 = 1 and j2 = j or "
2505 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2506 map
= isl_map_transitive_closure(map
, &exact
);
2510 map
= isl_map_read_from_str(ctx
,
2511 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2512 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2513 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2514 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2515 map
= isl_map_transitive_closure(map
, &exact
);
2519 /* Kelly et al 1996, fig 12 */
2520 map
= isl_map_read_from_str(ctx
,
2521 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2522 "1 <= i,j,j+1 <= n or "
2523 "j = n and j2 = 1 and i2 = i + 1 and "
2524 "1 <= i,i+1 <= n }");
2525 map
= isl_map_transitive_closure(map
, &exact
);
2527 map2
= isl_map_read_from_str(ctx
,
2528 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2529 "1 <= i <= n and i = i2 or "
2530 "1 <= i < i2 <= n and 1 <= j <= n and "
2532 assert(isl_map_is_equal(map
, map2
));
2536 /* Omega's closure4 */
2537 map
= isl_map_read_from_str(ctx
,
2538 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2539 "1 <= x,y <= 10 or "
2540 "x2 = x + 1 and y2 = y and "
2541 "1 <= x <= 20 && 5 <= y <= 15 }");
2542 map
= isl_map_transitive_closure(map
, &exact
);
2546 map
= isl_map_read_from_str(ctx
,
2547 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2548 map
= isl_map_transitive_closure(map
, &exact
);
2550 map2
= isl_map_read_from_str(ctx
,
2551 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2552 assert(isl_map_is_equal(map
, map2
));
2556 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2557 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2558 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2559 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2560 map
= isl_map_read_from_str(ctx
, str
);
2561 map
= isl_map_transitive_closure(map
, &exact
);
2563 map2
= isl_map_read_from_str(ctx
, str
);
2564 assert(isl_map_is_equal(map
, map2
));
2568 str
= "{[0] -> [1]; [2] -> [3]}";
2569 map
= isl_map_read_from_str(ctx
, str
);
2570 map
= isl_map_transitive_closure(map
, &exact
);
2572 map2
= isl_map_read_from_str(ctx
, str
);
2573 assert(isl_map_is_equal(map
, map2
));
2577 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2578 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2579 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2580 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2581 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2582 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2583 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2584 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2585 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2586 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2587 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2588 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2589 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2590 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2591 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2592 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2593 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2594 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2595 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2596 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2597 map
= isl_map_read_from_str(ctx
, str
);
2598 map
= isl_map_transitive_closure(map
, NULL
);
2605 static int test_lex(struct isl_ctx
*ctx
)
2611 dim
= isl_space_set_alloc(ctx
, 0, 0);
2612 map
= isl_map_lex_le(dim
);
2613 empty
= isl_map_is_empty(map
);
2619 isl_die(ctx
, isl_error_unknown
,
2620 "expecting non-empty result", return -1);
2625 /* Inputs for isl_map_lexmin tests.
2626 * "map" is the input and "lexmin" is the expected result.
2631 } lexmin_tests
[] = {
2632 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2633 "{ [x] -> [5] : 6 <= x <= 8; "
2634 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2635 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2636 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2637 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2638 "{ [x] -> [y] : (4y = x and x >= 0) or "
2639 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2640 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2641 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2642 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2643 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2644 /* Check that empty pieces are properly combined. */
2645 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2646 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2647 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2648 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2649 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2651 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2652 "a <= 255 and c <= 255 and d <= 255 - j and "
2653 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2654 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2655 "247d <= 247 + i and 248 - b <= 248d <= c and "
2656 "254d >= i - a + b and 254d >= -a + b and "
2657 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2659 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2660 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2661 "247j >= 62738 - i and 509j <= 129795 + i and "
2662 "742j >= 188724 - i; "
2663 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2664 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2665 "16*floor((8 + b)/16) <= 7 + b; "
2667 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2668 "[a] -> [b = 0] : 0 < a <= 509 }" },
2669 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2670 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2673 static int test_lexmin(struct isl_ctx
*ctx
)
2678 isl_basic_map
*bmap
;
2679 isl_map
*map
, *map2
;
2682 isl_pw_multi_aff
*pma
;
2684 str
= "[p0, p1] -> { [] -> [] : "
2685 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2686 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2687 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2688 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2689 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2690 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2691 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2692 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2693 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2694 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2695 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2696 map
= isl_map_read_from_str(ctx
, str
);
2697 map
= isl_map_lexmin(map
);
2700 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2701 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2702 set
= isl_set_read_from_str(ctx
, str
);
2703 set
= isl_set_lexmax(set
);
2704 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
2705 set2
= isl_set_read_from_str(ctx
, str
);
2706 set
= isl_set_intersect(set
, set2
);
2707 assert(!isl_set_is_empty(set
));
2710 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
2711 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
2712 map
= isl_map_lexmin(map
);
2713 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
2714 equal
= isl_map_is_equal(map
, map2
);
2721 isl_die(ctx
, isl_error_unknown
,
2722 "unexpected result", return -1);
2725 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2726 " 8i' <= i and 8i' >= -7 + i }";
2727 bmap
= isl_basic_map_read_from_str(ctx
, str
);
2728 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
2729 map2
= isl_map_from_pw_multi_aff(pma
);
2730 map
= isl_map_from_basic_map(bmap
);
2731 assert(isl_map_is_equal(map
, map2
));
2735 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2736 " 8i' <= i and 8i' >= -7 + i }";
2737 set
= isl_set_read_from_str(ctx
, str
);
2738 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
2739 set2
= isl_set_from_pw_multi_aff(pma
);
2740 equal
= isl_set_is_equal(set
, set2
);
2746 isl_die(ctx
, isl_error_unknown
,
2747 "unexpected difference between set and "
2748 "piecewise affine expression", return -1);
2753 /* A specialized isl_set_min_val test case that would return the wrong result
2754 * in earlier versions of isl.
2755 * The explicit call to isl_basic_set_union prevents the second basic set
2756 * from being determined to be empty prior to the call to isl_set_min_val,
2757 * at least at the point where this test case was introduced.
2759 static int test_min_special(isl_ctx
*ctx
)
2762 isl_basic_set
*bset1
, *bset2
;
2768 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
2769 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2770 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
2771 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2772 set
= isl_basic_set_union(bset1
, bset2
);
2773 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
2775 res
= isl_set_min_val(set
, obj
);
2776 ok
= isl_val_cmp_si(res
, 5) == 0;
2785 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
2791 /* A specialized isl_set_min_val test case that would return an error
2792 * in earlier versions of isl.
2794 static int test_min_special2(isl_ctx
*ctx
)
2797 isl_basic_set
*bset
;
2801 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
2802 bset
= isl_basic_set_read_from_str(ctx
, str
);
2804 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
2806 res
= isl_basic_set_max_val(bset
, obj
);
2808 isl_basic_set_free(bset
);
2821 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
2822 __isl_keep isl_aff
*obj
);
2825 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
2826 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
2827 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
2828 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
2829 &isl_set_max_val
, "30" },
2833 /* Perform basic isl_set_min_val and isl_set_max_val tests.
2834 * In particular, check the results on non-convex inputs.
2836 static int test_min(struct isl_ctx
*ctx
)
2844 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
2845 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
2846 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
2847 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
2848 val
= opt_tests
[i
].fn(set
, obj
);
2849 ok
= isl_val_eq(res
, val
);
2858 isl_die(ctx
, isl_error_unknown
,
2859 "unexpected optimum", return -1);
2862 if (test_min_special(ctx
) < 0)
2864 if (test_min_special2(ctx
) < 0)
2875 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
2876 void *dep_user
, void *user
)
2878 struct must_may
*mm
= (struct must_may
*)user
;
2881 mm
->must
= isl_map_union(mm
->must
, dep
);
2883 mm
->may
= isl_map_union(mm
->may
, dep
);
2888 static int common_space(void *first
, void *second
)
2890 int depth
= *(int *)first
;
2894 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
2902 map2
= isl_map_read_from_str(map
->ctx
, str
);
2903 equal
= isl_map_is_equal(map
, map2
);
2909 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
2913 equal
= map_is_equal(map
, str
);
2917 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
2918 "result not as expected", return -1);
2922 static int test_dep(struct isl_ctx
*ctx
)
2927 isl_access_info
*ai
;
2934 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2935 map
= isl_map_read_from_str(ctx
, str
);
2936 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2938 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2939 map
= isl_map_read_from_str(ctx
, str
);
2940 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2942 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2943 map
= isl_map_read_from_str(ctx
, str
);
2944 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2946 flow
= isl_access_info_compute_flow(ai
);
2947 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2948 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2949 mm
.may
= isl_map_empty(dim
);
2951 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2953 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
2954 " [1,10,0] -> [2,5,0] }";
2955 assert(map_is_equal(mm
.must
, str
));
2956 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2957 assert(map_is_equal(mm
.may
, str
));
2959 isl_map_free(mm
.must
);
2960 isl_map_free(mm
.may
);
2961 isl_flow_free(flow
);
2964 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2965 map
= isl_map_read_from_str(ctx
, str
);
2966 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2968 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2969 map
= isl_map_read_from_str(ctx
, str
);
2970 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2972 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2973 map
= isl_map_read_from_str(ctx
, str
);
2974 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2976 flow
= isl_access_info_compute_flow(ai
);
2977 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2978 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2979 mm
.may
= isl_map_empty(dim
);
2981 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2983 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2984 assert(map_is_equal(mm
.must
, str
));
2985 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2986 assert(map_is_equal(mm
.may
, str
));
2988 isl_map_free(mm
.must
);
2989 isl_map_free(mm
.may
);
2990 isl_flow_free(flow
);
2993 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2994 map
= isl_map_read_from_str(ctx
, str
);
2995 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2997 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2998 map
= isl_map_read_from_str(ctx
, str
);
2999 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3001 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3002 map
= isl_map_read_from_str(ctx
, str
);
3003 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3005 flow
= isl_access_info_compute_flow(ai
);
3006 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3007 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3008 mm
.may
= isl_map_empty(dim
);
3010 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3012 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
3013 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3014 assert(map_is_equal(mm
.may
, str
));
3015 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3016 assert(map_is_equal(mm
.must
, str
));
3018 isl_map_free(mm
.must
);
3019 isl_map_free(mm
.may
);
3020 isl_flow_free(flow
);
3023 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
3024 map
= isl_map_read_from_str(ctx
, str
);
3025 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3027 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3028 map
= isl_map_read_from_str(ctx
, str
);
3029 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3031 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3032 map
= isl_map_read_from_str(ctx
, str
);
3033 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3035 flow
= isl_access_info_compute_flow(ai
);
3036 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3037 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3038 mm
.may
= isl_map_empty(dim
);
3040 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3042 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3043 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3044 assert(map_is_equal(mm
.may
, str
));
3045 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3046 assert(map_is_equal(mm
.must
, str
));
3048 isl_map_free(mm
.must
);
3049 isl_map_free(mm
.may
);
3050 isl_flow_free(flow
);
3053 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3054 map
= isl_map_read_from_str(ctx
, str
);
3055 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3057 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3058 map
= isl_map_read_from_str(ctx
, str
);
3059 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3061 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3062 map
= isl_map_read_from_str(ctx
, str
);
3063 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3065 flow
= isl_access_info_compute_flow(ai
);
3066 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3067 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3068 mm
.may
= isl_map_empty(dim
);
3070 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3072 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3073 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3074 assert(map_is_equal(mm
.may
, str
));
3075 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3076 assert(map_is_equal(mm
.must
, str
));
3078 isl_map_free(mm
.must
);
3079 isl_map_free(mm
.may
);
3080 isl_flow_free(flow
);
3085 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3086 map
= isl_map_read_from_str(ctx
, str
);
3087 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
3089 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3090 map
= isl_map_read_from_str(ctx
, str
);
3091 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3093 flow
= isl_access_info_compute_flow(ai
);
3094 dim
= isl_space_alloc(ctx
, 0, 5, 5);
3095 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3096 mm
.may
= isl_map_empty(dim
);
3098 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3100 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3101 assert(map_is_equal(mm
.must
, str
));
3102 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3103 assert(map_is_equal(mm
.may
, str
));
3105 isl_map_free(mm
.must
);
3106 isl_map_free(mm
.may
);
3107 isl_flow_free(flow
);
3112 /* Check that the dependence analysis proceeds without errors.
3113 * Earlier versions of isl would break down during the analysis
3114 * due to the use of the wrong spaces.
3116 static int test_flow(isl_ctx
*ctx
)
3119 isl_union_map
*access
, *schedule
;
3120 isl_union_map
*must_dep
, *may_dep
;
3123 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3124 access
= isl_union_map_read_from_str(ctx
, str
);
3125 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3126 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3127 "S2[] -> [1,0,0,0]; "
3128 "S3[] -> [-1,0,0,0] }";
3129 schedule
= isl_union_map_read_from_str(ctx
, str
);
3130 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
3131 isl_union_map_copy(access
), schedule
,
3132 &must_dep
, &may_dep
, NULL
, NULL
);
3133 isl_union_map_free(may_dep
);
3134 isl_union_map_free(must_dep
);
3143 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3144 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3145 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3146 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3147 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3148 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3149 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3150 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3151 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3154 int test_sv(isl_ctx
*ctx
)
3156 isl_union_map
*umap
;
3160 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
3161 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
3162 sv
= isl_union_map_is_single_valued(umap
);
3163 isl_union_map_free(umap
);
3166 if (sv_tests
[i
].sv
&& !sv
)
3167 isl_die(ctx
, isl_error_internal
,
3168 "map not detected as single valued", return -1);
3169 if (!sv_tests
[i
].sv
&& sv
)
3170 isl_die(ctx
, isl_error_internal
,
3171 "map detected as single valued", return -1);
3180 } bijective_tests
[] = {
3181 { "[N,M]->{[i,j] -> [i]}", 0 },
3182 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3183 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3184 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3185 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3186 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3187 { "[N,M]->{[i,j] -> []}", 0 },
3188 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3189 { "[N,M]->{[i,j] -> [2i]}", 0 },
3190 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3191 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3192 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3193 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3196 static int test_bijective(struct isl_ctx
*ctx
)
3202 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
3203 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
3204 bijective
= isl_map_is_bijective(map
);
3208 if (bijective_tests
[i
].bijective
&& !bijective
)
3209 isl_die(ctx
, isl_error_internal
,
3210 "map not detected as bijective", return -1);
3211 if (!bijective_tests
[i
].bijective
&& bijective
)
3212 isl_die(ctx
, isl_error_internal
,
3213 "map detected as bijective", return -1);
3219 /* Inputs for isl_pw_qpolynomial_gist tests.
3220 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3226 } pwqp_gist_tests
[] = {
3227 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3228 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3229 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3230 "{ [i] -> -1/2 + 1/2 * i }" },
3231 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3234 static int test_pwqp(struct isl_ctx
*ctx
)
3239 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3242 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3243 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3245 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3248 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3249 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3251 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3253 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3255 isl_pw_qpolynomial_free(pwqp1
);
3257 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3258 str
= pwqp_gist_tests
[i
].pwqp
;
3259 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3260 str
= pwqp_gist_tests
[i
].set
;
3261 set
= isl_set_read_from_str(ctx
, str
);
3262 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3263 str
= pwqp_gist_tests
[i
].gist
;
3264 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3265 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3266 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3267 isl_pw_qpolynomial_free(pwqp1
);
3272 isl_die(ctx
, isl_error_unknown
,
3273 "unexpected result", return -1);
3276 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3277 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3278 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3279 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3281 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3283 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3285 isl_pw_qpolynomial_free(pwqp1
);
3287 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3288 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3289 str
= "{ [x] -> x }";
3290 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3292 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3294 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3296 isl_pw_qpolynomial_free(pwqp1
);
3298 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3299 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3300 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3301 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3302 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3303 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3304 isl_pw_qpolynomial_free(pwqp1
);
3306 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3307 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3308 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3309 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3310 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3311 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3312 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3313 isl_pw_qpolynomial_free(pwqp1
);
3314 isl_pw_qpolynomial_free(pwqp2
);
3318 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3320 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3321 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3322 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3323 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3324 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3326 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3327 isl_pw_qpolynomial_free(pwqp1
);
3328 isl_pw_qpolynomial_free(pwqp2
);
3332 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3337 static int test_split_periods(isl_ctx
*ctx
)
3340 isl_pw_qpolynomial
*pwqp
;
3342 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3343 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3344 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3345 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3347 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3349 isl_pw_qpolynomial_free(pwqp
);
3357 static int test_union(isl_ctx
*ctx
)
3360 isl_union_set
*uset1
, *uset2
;
3361 isl_union_map
*umap1
, *umap2
;
3364 str
= "{ [i] : 0 <= i <= 1 }";
3365 uset1
= isl_union_set_read_from_str(ctx
, str
);
3366 str
= "{ [1] -> [0] }";
3367 umap1
= isl_union_map_read_from_str(ctx
, str
);
3369 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3370 equal
= isl_union_map_is_equal(umap1
, umap2
);
3372 isl_union_map_free(umap1
);
3373 isl_union_map_free(umap2
);
3378 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3381 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3382 umap1
= isl_union_map_read_from_str(ctx
, str
);
3383 str
= "{ A[i]; B[i] }";
3384 uset1
= isl_union_set_read_from_str(ctx
, str
);
3386 uset2
= isl_union_map_domain(umap1
);
3388 equal
= isl_union_set_is_equal(uset1
, uset2
);
3390 isl_union_set_free(uset1
);
3391 isl_union_set_free(uset2
);
3396 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3402 /* Check that computing a bound of a non-zero polynomial over an unbounded
3403 * domain does not produce a rational value.
3404 * In particular, check that the upper bound is infinity.
3406 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
3409 isl_pw_qpolynomial
*pwqp
;
3410 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
3413 str
= "{ [m,n] -> -m * n }";
3414 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3415 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3417 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3418 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3419 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
3420 isl_pw_qpolynomial_fold_free(pwf
);
3421 isl_pw_qpolynomial_fold_free(pwf2
);
3426 isl_die(ctx
, isl_error_unknown
,
3427 "expecting infinite polynomial bound", return -1);
3432 static int test_bound(isl_ctx
*ctx
)
3436 isl_pw_qpolynomial
*pwqp
;
3437 isl_pw_qpolynomial_fold
*pwf
;
3439 if (test_bound_unbounded_domain(ctx
) < 0)
3442 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
3443 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3444 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3445 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3446 isl_pw_qpolynomial_fold_free(pwf
);
3448 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3451 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3452 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3453 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3454 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3455 isl_pw_qpolynomial_fold_free(pwf
);
3457 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3463 /* Check that the conversion from 'set' to 'basic set list' works as expected.
3465 static isl_stat
test_get_list_bset_from_set(isl_ctx
*ctx
)
3469 isl_set
*set
, *set2
;
3470 isl_basic_set_list
*bset_list
;
3472 set
= isl_set_read_from_str(ctx
, "{ [0]; [2]; [3] }");
3473 bset_list
= isl_set_get_basic_set_list(set
);
3475 set2
= isl_set_empty(isl_set_get_space(set
));
3477 for (i
= 0; i
< isl_basic_set_list_n_basic_set(bset_list
); i
++) {
3478 isl_basic_set
*bset
;
3479 bset
= isl_basic_set_list_get_basic_set(bset_list
, i
);
3480 set2
= isl_set_union(set2
, isl_set_from_basic_set(bset
));
3483 equal
= isl_set_is_equal(set
, set2
);
3487 isl_basic_set_list_free(bset_list
);
3490 return isl_stat_error
;
3493 isl_die(ctx
, isl_error_unknown
, "sets are not equal",
3494 return isl_stat_error
);
3499 /* Check that the conversion from 'union set' to 'basic set list' works as
3502 static isl_stat
test_get_list_bset_from_uset(isl_ctx
*ctx
)
3506 isl_union_set
*uset
, *uset2
;
3507 isl_basic_set_list
*bset_list
;
3509 uset
= isl_union_set_read_from_str(ctx
, "{ A[0]; B[2]; B[3] }");
3510 bset_list
= isl_union_set_get_basic_set_list(uset
);
3512 uset2
= isl_union_set_empty(isl_union_set_get_space(uset
));
3514 for (i
= 0; i
< isl_basic_set_list_n_basic_set(bset_list
); i
++) {
3515 isl_basic_set
*bset
;
3516 bset
= isl_basic_set_list_get_basic_set(bset_list
, i
);
3517 uset2
= isl_union_set_union(uset2
,
3518 isl_union_set_from_basic_set(bset
));
3521 equal
= isl_union_set_is_equal(uset
, uset2
);
3523 isl_union_set_free(uset
);
3524 isl_union_set_free(uset2
);
3525 isl_basic_set_list_free(bset_list
);
3528 return isl_stat_error
;
3531 isl_die(ctx
, isl_error_unknown
, "sets are not equal",
3532 return isl_stat_error
);
3537 /* Check that the conversion from 'union set' to 'set list' works as expected.
3539 static isl_stat
test_get_list_set_from_uset(isl_ctx
*ctx
)
3543 isl_union_set
*uset
, *uset2
;
3544 isl_set_list
*set_list
;
3546 uset
= isl_union_set_read_from_str(ctx
, "{ A[0]; A[2]; B[3] }");
3547 set_list
= isl_union_set_get_set_list(uset
);
3549 uset2
= isl_union_set_empty(isl_union_set_get_space(uset
));
3551 for (i
= 0; i
< isl_set_list_n_set(set_list
); i
++) {
3553 set
= isl_set_list_get_set(set_list
, i
);
3554 uset2
= isl_union_set_union(uset2
, isl_union_set_from_set(set
));
3557 equal
= isl_union_set_is_equal(uset
, uset2
);
3559 isl_union_set_free(uset
);
3560 isl_union_set_free(uset2
);
3561 isl_set_list_free(set_list
);
3564 return isl_stat_error
;
3567 isl_die(ctx
, isl_error_unknown
, "union sets are not equal",
3568 return isl_stat_error
);
3573 /* Check that the conversion from 'map' to 'basic map list' works as expected.
3575 static isl_stat
test_get_list_bmap_from_map(isl_ctx
*ctx
)
3579 isl_map
*map
, *map2
;
3580 isl_basic_map_list
*bmap_list
;
3582 map
= isl_map_read_from_str(ctx
,
3583 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }");
3584 bmap_list
= isl_map_get_basic_map_list(map
);
3586 map2
= isl_map_empty(isl_map_get_space(map
));
3588 for (i
= 0; i
< isl_basic_map_list_n_basic_map(bmap_list
); i
++) {
3589 isl_basic_map
*bmap
;
3590 bmap
= isl_basic_map_list_get_basic_map(bmap_list
, i
);
3591 map2
= isl_map_union(map2
, isl_map_from_basic_map(bmap
));
3594 equal
= isl_map_is_equal(map
, map2
);
3598 isl_basic_map_list_free(bmap_list
);
3601 return isl_stat_error
;
3604 isl_die(ctx
, isl_error_unknown
, "maps are not equal",
3605 return isl_stat_error
);
3610 /* Check that the conversion from 'union map' to 'map list' works as expected.
3612 static isl_stat
test_get_list_map_from_umap(isl_ctx
*ctx
)
3616 isl_union_map
*umap
, *umap2
;
3617 isl_map_list
*map_list
;
3619 umap
= isl_union_map_read_from_str(ctx
,
3620 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }");
3621 map_list
= isl_union_map_get_map_list(umap
);
3623 umap2
= isl_union_map_empty(isl_union_map_get_space(umap
));
3625 for (i
= 0; i
< isl_map_list_n_map(map_list
); i
++) {
3627 map
= isl_map_list_get_map(map_list
, i
);
3628 umap2
= isl_union_map_union(umap2
, isl_union_map_from_map(map
));
3631 equal
= isl_union_map_is_equal(umap
, umap2
);
3633 isl_union_map_free(umap
);
3634 isl_union_map_free(umap2
);
3635 isl_map_list_free(map_list
);
3638 return isl_stat_error
;
3641 isl_die(ctx
, isl_error_unknown
, "union maps are not equal",
3642 return isl_stat_error
);
3647 /* Check that the conversion from isl objects to lists works as expected.
3649 static int test_get_list(isl_ctx
*ctx
)
3651 if (test_get_list_bset_from_set(ctx
))
3653 if (test_get_list_bset_from_uset(ctx
))
3655 if (test_get_list_set_from_uset(ctx
))
3657 if (test_get_list_bmap_from_map(ctx
))
3659 if (test_get_list_map_from_umap(ctx
))
3665 static int test_lift(isl_ctx
*ctx
)
3668 isl_basic_map
*bmap
;
3669 isl_basic_set
*bset
;
3671 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
3672 bset
= isl_basic_set_read_from_str(ctx
, str
);
3673 bset
= isl_basic_set_lift(bset
);
3674 bmap
= isl_basic_map_from_range(bset
);
3675 bset
= isl_basic_map_domain(bmap
);
3676 isl_basic_set_free(bset
);
3681 /* Check that isl_set_is_subset is not confused by identical
3682 * integer divisions.
3683 * The call to isl_set_normalize ensures that the equality constraints
3684 * a = b = 0 are discovered, turning e0 and e1 into identical
3685 * integer divisions. Any further simplification would remove
3686 * the duplicate integer divisions.
3688 static isl_stat
test_subset_duplicate_integer_divisions(isl_ctx
*ctx
)
3692 isl_set
*set1
, *set2
;
3694 str
= "{ [a, b, c, d] : "
3695 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
3696 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
3697 "e3 = floor((-d + 4*floor((d)/4))/10): "
3698 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
3699 "b >= 0 and a <= 0 and b <= a) }";
3700 set1
= isl_set_read_from_str(ctx
, str
);
3701 set2
= isl_set_read_from_str(ctx
, str
);
3702 set2
= isl_set_normalize(set2
);
3704 is_subset
= isl_set_is_subset(set1
, set2
);
3710 return isl_stat_error
;
3712 isl_die(ctx
, isl_error_unknown
,
3713 "set is not considered to be a subset of itself",
3714 return isl_stat_error
);
3723 } subset_tests
[] = {
3725 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3726 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3727 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3729 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3730 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3731 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3732 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3733 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3734 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3735 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3736 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3737 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3738 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3739 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3740 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3741 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3742 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3743 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3744 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3745 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3746 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3747 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3748 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3749 "4e0 <= -57 + i0 + i1)) or "
3750 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3751 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3752 "4e0 >= -61 + i0 + i1)) or "
3753 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3754 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3757 static int test_subset(isl_ctx
*ctx
)
3760 isl_set
*set1
, *set2
;
3763 if (test_subset_duplicate_integer_divisions(ctx
) < 0)
3766 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
3767 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
3768 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
3769 subset
= isl_set_is_subset(set1
, set2
);
3774 if (subset
!= subset_tests
[i
].subset
)
3775 isl_die(ctx
, isl_error_unknown
,
3776 "incorrect subset result", return -1);
3783 const char *minuend
;
3784 const char *subtrahend
;
3785 const char *difference
;
3786 } subtract_domain_tests
[] = {
3787 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
3788 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
3789 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
3792 static int test_subtract(isl_ctx
*ctx
)
3795 isl_union_map
*umap1
, *umap2
;
3796 isl_union_pw_multi_aff
*upma1
, *upma2
;
3797 isl_union_set
*uset
;
3800 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3801 umap1
= isl_union_map_read_from_str(ctx
,
3802 subtract_domain_tests
[i
].minuend
);
3803 uset
= isl_union_set_read_from_str(ctx
,
3804 subtract_domain_tests
[i
].subtrahend
);
3805 umap2
= isl_union_map_read_from_str(ctx
,
3806 subtract_domain_tests
[i
].difference
);
3807 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
3808 equal
= isl_union_map_is_equal(umap1
, umap2
);
3809 isl_union_map_free(umap1
);
3810 isl_union_map_free(umap2
);
3814 isl_die(ctx
, isl_error_unknown
,
3815 "incorrect subtract domain result", return -1);
3818 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3819 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3820 subtract_domain_tests
[i
].minuend
);
3821 uset
= isl_union_set_read_from_str(ctx
,
3822 subtract_domain_tests
[i
].subtrahend
);
3823 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3824 subtract_domain_tests
[i
].difference
);
3825 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
3826 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
3827 isl_union_pw_multi_aff_free(upma1
);
3828 isl_union_pw_multi_aff_free(upma2
);
3832 isl_die(ctx
, isl_error_unknown
,
3833 "incorrect subtract domain result", return -1);
3839 /* Check that intersecting the empty basic set with another basic set
3840 * does not increase the number of constraints. In particular,
3841 * the empty basic set should maintain its canonical representation.
3843 static int test_intersect_1(isl_ctx
*ctx
)
3846 isl_basic_set
*bset1
, *bset2
;
3848 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
3849 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
3850 n1
= isl_basic_set_n_constraint(bset1
);
3851 bset1
= isl_basic_set_intersect(bset1
, bset2
);
3852 n2
= isl_basic_set_n_constraint(bset1
);
3853 isl_basic_set_free(bset1
);
3857 isl_die(ctx
, isl_error_unknown
,
3858 "number of constraints of empty set changed",
3864 /* Check that intersecting a set with itself does not cause
3865 * an explosion in the number of disjuncts.
3867 static isl_stat
test_intersect_2(isl_ctx
*ctx
)
3872 set
= isl_set_read_from_str(ctx
, "{ [x,y] : x >= 0 or y >= 0 }");
3873 for (i
= 0; i
< 100; ++i
)
3874 set
= isl_set_intersect(set
, isl_set_copy(set
));
3877 return isl_stat_error
;
3881 /* Perform some intersection tests.
3883 static int test_intersect(isl_ctx
*ctx
)
3885 if (test_intersect_1(ctx
) < 0)
3887 if (test_intersect_2(ctx
) < 0)
3893 int test_factorize(isl_ctx
*ctx
)
3896 isl_basic_set
*bset
;
3899 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
3900 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
3901 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
3902 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
3903 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
3904 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
3905 "3i5 >= -2i0 - i2 + 3i4 }";
3906 bset
= isl_basic_set_read_from_str(ctx
, str
);
3907 f
= isl_basic_set_factorizer(bset
);
3908 isl_basic_set_free(bset
);
3909 isl_factorizer_free(f
);
3911 isl_die(ctx
, isl_error_unknown
,
3912 "failed to construct factorizer", return -1);
3914 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
3915 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
3916 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
3917 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
3918 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
3919 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
3920 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
3921 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
3922 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
3923 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
3924 bset
= isl_basic_set_read_from_str(ctx
, str
);
3925 f
= isl_basic_set_factorizer(bset
);
3926 isl_basic_set_free(bset
);
3927 isl_factorizer_free(f
);
3929 isl_die(ctx
, isl_error_unknown
,
3930 "failed to construct factorizer", return -1);
3935 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
3937 int *injective
= user
;
3939 *injective
= isl_map_is_injective(map
);
3942 if (*injective
< 0 || !*injective
)
3943 return isl_stat_error
;
3948 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
3949 const char *r
, const char *s
, int tilable
, int parallel
)
3953 isl_union_map
*W
, *R
, *S
;
3954 isl_union_map
*empty
;
3955 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
3956 isl_union_map
*validity
, *proximity
, *coincidence
;
3957 isl_union_map
*schedule
;
3958 isl_union_map
*test
;
3959 isl_union_set
*delta
;
3960 isl_union_set
*domain
;
3964 isl_schedule_constraints
*sc
;
3965 isl_schedule
*sched
;
3966 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
3968 D
= isl_union_set_read_from_str(ctx
, d
);
3969 W
= isl_union_map_read_from_str(ctx
, w
);
3970 R
= isl_union_map_read_from_str(ctx
, r
);
3971 S
= isl_union_map_read_from_str(ctx
, s
);
3973 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
3974 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
3976 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
3977 isl_union_map_compute_flow(isl_union_map_copy(R
),
3978 isl_union_map_copy(W
), empty
,
3979 isl_union_map_copy(S
),
3980 &dep_raw
, NULL
, NULL
, NULL
);
3981 isl_union_map_compute_flow(isl_union_map_copy(W
),
3982 isl_union_map_copy(W
),
3983 isl_union_map_copy(R
),
3984 isl_union_map_copy(S
),
3985 &dep_waw
, &dep_war
, NULL
, NULL
);
3987 dep
= isl_union_map_union(dep_waw
, dep_war
);
3988 dep
= isl_union_map_union(dep
, dep_raw
);
3989 validity
= isl_union_map_copy(dep
);
3990 coincidence
= isl_union_map_copy(dep
);
3991 proximity
= isl_union_map_copy(dep
);
3993 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
3994 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3995 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
3996 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3997 sched
= isl_schedule_constraints_compute_schedule(sc
);
3998 schedule
= isl_schedule_get_map(sched
);
3999 isl_schedule_free(sched
);
4000 isl_union_map_free(W
);
4001 isl_union_map_free(R
);
4002 isl_union_map_free(S
);
4005 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
4007 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
4008 is_complete
= isl_union_set_is_subset(D
, domain
);
4009 isl_union_set_free(D
);
4010 isl_union_set_free(domain
);
4012 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
4013 test
= isl_union_map_apply_range(test
, dep
);
4014 test
= isl_union_map_apply_range(test
, schedule
);
4016 delta
= isl_union_map_deltas(test
);
4017 if (isl_union_set_n_set(delta
) == 0) {
4021 isl_union_set_free(delta
);
4023 delta_set
= isl_set_from_union_set(delta
);
4025 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4026 for (i
= 0; i
< tilable
; ++i
)
4027 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
4028 is_tilable
= isl_set_is_subset(delta_set
, slice
);
4029 isl_set_free(slice
);
4031 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4032 for (i
= 0; i
< parallel
; ++i
)
4033 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
4034 is_parallel
= isl_set_is_subset(delta_set
, slice
);
4035 isl_set_free(slice
);
4037 origin
= isl_set_universe(isl_set_get_space(delta_set
));
4038 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
4039 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
4041 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
4042 delta_set
= isl_set_lexmin(delta_set
);
4044 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
4046 isl_set_free(origin
);
4047 isl_set_free(delta_set
);
4050 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
4051 is_injection
< 0 || is_complete
< 0)
4054 isl_die(ctx
, isl_error_unknown
,
4055 "generated schedule incomplete", return -1);
4057 isl_die(ctx
, isl_error_unknown
,
4058 "generated schedule not injective on each statement",
4061 isl_die(ctx
, isl_error_unknown
,
4062 "negative dependences in generated schedule",
4065 isl_die(ctx
, isl_error_unknown
,
4066 "generated schedule not as tilable as expected",
4069 isl_die(ctx
, isl_error_unknown
,
4070 "generated schedule not as parallel as expected",
4076 /* Compute a schedule for the given instance set, validity constraints,
4077 * proximity constraints and context and return a corresponding union map
4080 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
4081 const char *domain
, const char *validity
, const char *proximity
,
4082 const char *context
)
4087 isl_union_map
*prox
;
4088 isl_schedule_constraints
*sc
;
4089 isl_schedule
*schedule
;
4090 isl_union_map
*sched
;
4092 con
= isl_set_read_from_str(ctx
, context
);
4093 dom
= isl_union_set_read_from_str(ctx
, domain
);
4094 dep
= isl_union_map_read_from_str(ctx
, validity
);
4095 prox
= isl_union_map_read_from_str(ctx
, proximity
);
4096 sc
= isl_schedule_constraints_on_domain(dom
);
4097 sc
= isl_schedule_constraints_set_context(sc
, con
);
4098 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
4099 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
4100 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4101 sched
= isl_schedule_get_map(schedule
);
4102 isl_schedule_free(schedule
);
4107 /* Compute a schedule for the given instance set, validity constraints and
4108 * proximity constraints and return a corresponding union map representation.
4110 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
4111 const char *domain
, const char *validity
, const char *proximity
)
4113 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
4117 /* Check that a schedule can be constructed on the given domain
4118 * with the given validity and proximity constraints.
4120 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
4121 const char *validity
, const char *proximity
)
4123 isl_union_map
*sched
;
4125 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
4129 isl_union_map_free(sched
);
4133 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
4134 const char *validity
, const char *proximity
, const char *expected_sched
)
4136 isl_union_map
*sched1
, *sched2
;
4139 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
4140 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
4142 equal
= isl_union_map_is_equal(sched1
, sched2
);
4143 isl_union_map_free(sched1
);
4144 isl_union_map_free(sched2
);
4149 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
4155 /* Check that the schedule map is properly padded, i.e., that the range
4156 * lives in a single space.
4158 static int test_padded_schedule(isl_ctx
*ctx
)
4162 isl_union_map
*validity
, *proximity
;
4163 isl_schedule_constraints
*sc
;
4164 isl_schedule
*sched
;
4165 isl_union_map
*umap
;
4166 isl_union_set
*range
;
4169 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4170 D
= isl_union_set_read_from_str(ctx
, str
);
4171 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
4172 proximity
= isl_union_map_copy(validity
);
4173 sc
= isl_schedule_constraints_on_domain(D
);
4174 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4175 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4176 sched
= isl_schedule_constraints_compute_schedule(sc
);
4177 umap
= isl_schedule_get_map(sched
);
4178 isl_schedule_free(sched
);
4179 range
= isl_union_map_range(umap
);
4180 set
= isl_set_from_union_set(range
);
4189 /* Check that conditional validity constraints are also taken into
4190 * account across bands.
4191 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4192 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4193 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4194 * is enforced by the rest of the schedule.
4196 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
4199 isl_union_set
*domain
;
4200 isl_union_map
*validity
, *proximity
, *condition
;
4201 isl_union_map
*sink
, *source
, *dep
;
4202 isl_schedule_constraints
*sc
;
4203 isl_schedule
*schedule
;
4204 isl_union_access_info
*access
;
4205 isl_union_flow
*flow
;
4208 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4209 "A[k] : k >= 1 and k <= -1 + n; "
4210 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4211 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4212 domain
= isl_union_set_read_from_str(ctx
, str
);
4213 sc
= isl_schedule_constraints_on_domain(domain
);
4214 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4215 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4216 "D[k, i] -> C[1 + k, i] : "
4217 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4218 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4219 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4220 validity
= isl_union_map_read_from_str(ctx
, str
);
4221 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4222 str
= "[n] -> { C[k, i] -> D[k, i] : "
4223 "0 <= i <= -1 + k and k <= -1 + n }";
4224 proximity
= isl_union_map_read_from_str(ctx
, str
);
4225 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4226 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4227 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4228 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4229 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4230 condition
= isl_union_map_read_from_str(ctx
, str
);
4231 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4232 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4233 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4234 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4235 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4236 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4237 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4238 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4239 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4240 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4241 validity
= isl_union_map_read_from_str(ctx
, str
);
4242 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4244 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4245 str
= "{ D[2,0] -> [] }";
4246 sink
= isl_union_map_read_from_str(ctx
, str
);
4247 access
= isl_union_access_info_from_sink(sink
);
4248 str
= "{ C[2,1] -> [] }";
4249 source
= isl_union_map_read_from_str(ctx
, str
);
4250 access
= isl_union_access_info_set_must_source(access
, source
);
4251 access
= isl_union_access_info_set_schedule(access
, schedule
);
4252 flow
= isl_union_access_info_compute_flow(access
);
4253 dep
= isl_union_flow_get_must_dependence(flow
);
4254 isl_union_flow_free(flow
);
4255 empty
= isl_union_map_is_empty(dep
);
4256 isl_union_map_free(dep
);
4261 isl_die(ctx
, isl_error_unknown
,
4262 "conditional validity not respected", return -1);
4267 /* Check that the test for violated conditional validity constraints
4268 * is not confused by domain compression.
4269 * In particular, earlier versions of isl would apply
4270 * a schedule on the compressed domains to the original domains,
4271 * resulting in a failure to detect that the default schedule
4272 * violates the conditional validity constraints.
4274 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
4278 isl_union_set
*domain
;
4279 isl_union_map
*validity
, *condition
;
4280 isl_schedule_constraints
*sc
;
4281 isl_schedule
*schedule
;
4282 isl_union_map
*umap
;
4285 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4286 domain
= isl_union_set_read_from_str(ctx
, str
);
4287 sc
= isl_schedule_constraints_on_domain(domain
);
4288 str
= "{ B[1, i] -> A[0, i + 1] }";
4289 condition
= isl_union_map_read_from_str(ctx
, str
);
4290 str
= "{ A[0, i] -> B[1, i - 1] }";
4291 validity
= isl_union_map_read_from_str(ctx
, str
);
4292 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4293 isl_union_map_copy(validity
));
4294 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4295 umap
= isl_schedule_get_map(schedule
);
4296 isl_schedule_free(schedule
);
4297 validity
= isl_union_map_apply_domain(validity
,
4298 isl_union_map_copy(umap
));
4299 validity
= isl_union_map_apply_range(validity
, umap
);
4300 map
= isl_map_from_union_map(validity
);
4301 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4302 map
= isl_map_intersect(map
, ge
);
4303 empty
= isl_map_is_empty(map
);
4309 isl_die(ctx
, isl_error_unknown
,
4310 "conditional validity constraints not satisfied",
4316 /* Input for testing of schedule construction based on
4317 * conditional constraints.
4319 * domain is the iteration domain
4320 * flow are the flow dependences, which determine the validity and
4321 * proximity constraints
4322 * condition are the conditions on the conditional validity constraints
4323 * conditional_validity are the conditional validity constraints
4324 * outer_band_n is the expected number of members in the outer band
4329 const char *condition
;
4330 const char *conditional_validity
;
4332 } live_range_tests
[] = {
4333 /* Contrived example that illustrates that we need to keep
4334 * track of tagged condition dependences and
4335 * tagged conditional validity dependences
4336 * in isl_sched_edge separately.
4337 * In particular, the conditional validity constraints on A
4338 * cannot be satisfied,
4339 * but they can be ignored because there are no corresponding
4340 * condition constraints. However, we do have an additional
4341 * conditional validity constraint that maps to the same
4342 * dependence relation
4343 * as the condition constraint on B. If we did not make a distinction
4344 * between tagged condition and tagged conditional validity
4345 * dependences, then we
4346 * could end up treating this shared dependence as an condition
4347 * constraint on A, forcing a localization of the conditions,
4348 * which is impossible.
4350 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4351 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4352 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4353 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4354 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4355 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4358 /* TACO 2013 Fig. 7 */
4359 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4360 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4361 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4362 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4363 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4364 "0 <= i < n and 0 <= j < n - 1 }",
4365 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4366 "0 <= i < n and 0 <= j < j' < n;"
4367 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4368 "0 <= i < i' < n and 0 <= j,j' < n;"
4369 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4370 "0 <= i,j,j' < n and j < j' }",
4373 /* TACO 2013 Fig. 7, without tags */
4374 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4375 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4376 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4377 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4378 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4379 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4380 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4381 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4384 /* TACO 2013 Fig. 12 */
4385 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4386 "S3[i,3] : 0 <= i <= 1 }",
4387 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4388 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4389 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4390 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4391 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4392 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4393 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4394 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4395 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4396 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4397 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4402 /* Test schedule construction based on conditional constraints.
4403 * In particular, check the number of members in the outer band node
4404 * as an indication of whether tiling is possible or not.
4406 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4409 isl_union_set
*domain
;
4410 isl_union_map
*condition
;
4411 isl_union_map
*flow
;
4412 isl_union_map
*validity
;
4413 isl_schedule_constraints
*sc
;
4414 isl_schedule
*schedule
;
4415 isl_schedule_node
*node
;
4418 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4420 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4423 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4424 domain
= isl_union_set_read_from_str(ctx
,
4425 live_range_tests
[i
].domain
);
4426 flow
= isl_union_map_read_from_str(ctx
,
4427 live_range_tests
[i
].flow
);
4428 condition
= isl_union_map_read_from_str(ctx
,
4429 live_range_tests
[i
].condition
);
4430 validity
= isl_union_map_read_from_str(ctx
,
4431 live_range_tests
[i
].conditional_validity
);
4432 sc
= isl_schedule_constraints_on_domain(domain
);
4433 sc
= isl_schedule_constraints_set_validity(sc
,
4434 isl_union_map_copy(flow
));
4435 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4436 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4437 condition
, validity
);
4438 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4439 node
= isl_schedule_get_root(schedule
);
4441 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4442 node
= isl_schedule_node_first_child(node
);
4443 n_member
= isl_schedule_node_band_n_member(node
);
4444 isl_schedule_node_free(node
);
4445 isl_schedule_free(schedule
);
4449 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4450 isl_die(ctx
, isl_error_unknown
,
4451 "unexpected number of members in outer band",
4457 /* Check that the schedule computed for the given instance set and
4458 * dependence relation strongly satisfies the dependences.
4459 * In particular, check that no instance is scheduled before
4460 * or together with an instance on which it depends.
4461 * Earlier versions of isl would produce a schedule that
4462 * only weakly satisfies the dependences.
4464 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4466 const char *domain
, *dep
;
4467 isl_union_map
*D
, *schedule
;
4471 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4472 "A[i0] : 0 <= i0 <= 1 }";
4473 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4474 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4475 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
4476 D
= isl_union_map_read_from_str(ctx
, dep
);
4477 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
4478 D
= isl_union_map_apply_range(D
, schedule
);
4479 map
= isl_map_from_union_map(D
);
4480 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4481 map
= isl_map_intersect(map
, ge
);
4482 empty
= isl_map_is_empty(map
);
4488 isl_die(ctx
, isl_error_unknown
,
4489 "dependences not strongly satisfied", return -1);
4494 /* Compute a schedule for input where the instance set constraints
4495 * conflict with the context constraints.
4496 * Earlier versions of isl did not properly handle this situation.
4498 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
4500 isl_union_map
*schedule
;
4501 const char *domain
, *context
;
4503 domain
= "[n] -> { A[] : n >= 0 }";
4504 context
= "[n] -> { : n < 0 }";
4505 schedule
= compute_schedule_with_context(ctx
,
4506 domain
, "{}", "{}", context
);
4507 isl_union_map_free(schedule
);
4515 /* Check that a set of schedule constraints that only allow for
4516 * a coalescing schedule still produces a schedule even if the user
4517 * request a non-coalescing schedule. Earlier versions of isl
4518 * would not handle this case correctly.
4520 static int test_coalescing_schedule(isl_ctx
*ctx
)
4522 const char *domain
, *dep
;
4525 isl_schedule_constraints
*sc
;
4526 isl_schedule
*schedule
;
4527 int treat_coalescing
;
4529 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4530 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
4531 I
= isl_union_set_read_from_str(ctx
, domain
);
4532 D
= isl_union_map_read_from_str(ctx
, dep
);
4533 sc
= isl_schedule_constraints_on_domain(I
);
4534 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4535 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4536 isl_options_set_schedule_treat_coalescing(ctx
, 1);
4537 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4538 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4539 isl_schedule_free(schedule
);
4545 /* Check that the scheduler does not perform any needless
4546 * compound skewing. Earlier versions of isl would compute
4547 * schedules in terms of transformed schedule coefficients and
4548 * would not accurately keep track of the sum of the original
4549 * schedule coefficients. It could then produce the schedule
4550 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4551 * for the input below instead of the schedule below.
4553 static int test_skewing_schedule(isl_ctx
*ctx
)
4555 const char *D
, *V
, *P
, *S
;
4557 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4558 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4559 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4560 "-1 <= a-i + b-j + c-k <= 1 }";
4562 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4564 return test_special_schedule(ctx
, D
, V
, P
, S
);
4567 int test_schedule(isl_ctx
*ctx
)
4569 const char *D
, *W
, *R
, *V
, *P
, *S
;
4570 int max_coincidence
;
4571 int treat_coalescing
;
4573 /* Handle resulting schedule with zero bands. */
4574 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4578 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4579 W
= "{ S1[t,i] -> a[t,i] }";
4580 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4581 "S1[t,i] -> a[t-1,i+1] }";
4582 S
= "{ S1[t,i] -> [t,i] }";
4583 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4586 /* Fig. 5 of CC2008 */
4587 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4589 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4590 "j >= 2 and j <= -1 + N }";
4591 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4592 "j >= 2 and j <= -1 + N; "
4593 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4594 "j >= 2 and j <= -1 + N }";
4595 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4596 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4599 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4600 W
= "{ S1[i] -> a[i] }";
4601 R
= "{ S2[i] -> a[i+1] }";
4602 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4603 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4606 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4607 W
= "{ S1[i] -> a[i] }";
4608 R
= "{ S2[i] -> a[9-i] }";
4609 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4610 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4613 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4614 W
= "{ S1[i] -> a[i] }";
4615 R
= "[N] -> { S2[i] -> a[N-1-i] }";
4616 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4617 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4620 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4621 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4622 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4623 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4624 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4627 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4628 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4629 R
= "{ S2[i,j] -> a[i-1,j] }";
4630 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4631 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4634 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4635 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4636 R
= "{ S2[i,j] -> a[i,j-1] }";
4637 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4638 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4641 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4642 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4643 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4644 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4645 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4646 "S_0[] -> [0, 0, 0] }";
4647 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
4649 ctx
->opt
->schedule_parametric
= 0;
4650 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4652 ctx
->opt
->schedule_parametric
= 1;
4654 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4655 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4656 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4657 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4658 "S4[i] -> a[i,N] }";
4659 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4660 "S4[i] -> [4,i,0] }";
4661 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
4662 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
4663 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4665 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
4667 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4668 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4670 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4672 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4674 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4675 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4678 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4679 " S_2[t] : t >= 0 and t <= -1 + N; "
4680 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4682 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4683 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4684 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4685 "i >= 0 and i <= -1 + N }";
4686 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4687 "i >= 0 and i <= -1 + N; "
4688 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4689 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4690 " S_0[t] -> [0, t, 0] }";
4692 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4694 ctx
->opt
->schedule_parametric
= 0;
4695 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4697 ctx
->opt
->schedule_parametric
= 1;
4699 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4700 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4701 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
4704 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4705 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4706 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4707 "j >= 0 and j <= -1 + N; "
4708 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4709 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4710 "j >= 0 and j <= -1 + N; "
4711 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4712 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4713 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4716 D
= "{ S_0[i] : i >= 0 }";
4717 W
= "{ S_0[i] -> a[i] : i >= 0 }";
4718 R
= "{ S_0[i] -> a[0] : i >= 0 }";
4719 S
= "{ S_0[i] -> [0, i, 0] }";
4720 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4723 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
4724 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
4725 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
4726 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
4727 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4730 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
4731 "k <= -1 + n and k >= 0 }";
4732 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
4733 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
4734 "k <= -1 + n and k >= 0; "
4735 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
4736 "k <= -1 + n and k >= 0; "
4737 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
4738 "k <= -1 + n and k >= 0 }";
4739 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
4740 ctx
->opt
->schedule_outer_coincidence
= 1;
4741 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4743 ctx
->opt
->schedule_outer_coincidence
= 0;
4745 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
4746 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
4747 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
4748 "Stmt_for_body24[i0, i1, 1, 0]:"
4749 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
4750 "Stmt_for_body7[i0, i1, i2]:"
4751 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
4754 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
4755 "Stmt_for_body24[1, i1, i2, i3]:"
4756 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
4758 "Stmt_for_body24[0, i1, i2, i3] -> "
4759 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
4760 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
4762 "Stmt_for_body24[0, i1, i2, i3] ->"
4763 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
4764 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
4765 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
4766 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
4767 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
4768 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
4769 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
4770 "i1 <= 6 and i1 >= 0;"
4771 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
4772 "Stmt_for_body7[i0, i1, i2] -> "
4773 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
4774 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
4775 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
4776 "Stmt_for_body7[i0, i1, i2] -> "
4777 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
4778 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
4779 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
4782 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4783 isl_options_set_schedule_treat_coalescing(ctx
, 0);
4784 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4786 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4788 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
4789 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
4790 "j >= 1 and j <= 7;"
4791 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
4792 "j >= 1 and j <= 8 }";
4794 S
= "{ S_0[i, j] -> [i + j, i] }";
4795 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4796 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4798 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4800 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
4801 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
4802 "j >= 0 and j <= -1 + i }";
4803 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
4804 "i <= -1 + N and j >= 0;"
4805 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
4808 S
= "{ S_0[i, j] -> [i, j] }";
4809 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4810 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4812 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4814 /* Test both algorithms on a case with only proximity dependences. */
4815 D
= "{ S[i,j] : 0 <= i <= 10 }";
4817 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
4818 S
= "{ S[i, j] -> [j, i] }";
4819 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4820 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4822 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4823 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4826 D
= "{ A[a]; B[] }";
4828 P
= "{ A[a] -> B[] }";
4829 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4832 if (test_padded_schedule(ctx
) < 0)
4835 /* Check that check for progress is not confused by rational
4838 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
4839 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
4841 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
4842 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
4844 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4845 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4847 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4849 /* Check that we allow schedule rows that are only non-trivial
4850 * on some full-dimensional domains.
4852 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
4853 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
4854 "S1[j] -> S2[1] : 0 <= j <= 1 }";
4856 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4857 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4859 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4861 if (test_conditional_schedule_constraints(ctx
) < 0)
4864 if (test_strongly_satisfying_schedule(ctx
) < 0)
4867 if (test_conflicting_context_schedule(ctx
) < 0)
4870 if (test_coalescing_schedule(ctx
) < 0)
4872 if (test_skewing_schedule(ctx
) < 0)
4878 /* Perform scheduling tests using the whole component scheduler.
4880 static int test_schedule_whole(isl_ctx
*ctx
)
4885 whole
= isl_options_get_schedule_whole_component(ctx
);
4886 isl_options_set_schedule_whole_component(ctx
, 1);
4887 r
= test_schedule(ctx
);
4888 isl_options_set_schedule_whole_component(ctx
, whole
);
4893 /* Perform scheduling tests using the incremental scheduler.
4895 static int test_schedule_incremental(isl_ctx
*ctx
)
4900 whole
= isl_options_get_schedule_whole_component(ctx
);
4901 isl_options_set_schedule_whole_component(ctx
, 0);
4902 r
= test_schedule(ctx
);
4903 isl_options_set_schedule_whole_component(ctx
, whole
);
4908 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
4910 isl_union_map
*umap
;
4913 umap
= isl_union_map_read_from_str(ctx
, str
);
4914 test
= isl_union_map_plain_is_injective(umap
);
4915 isl_union_map_free(umap
);
4918 if (test
== injective
)
4921 isl_die(ctx
, isl_error_unknown
,
4922 "map not detected as injective", return -1);
4924 isl_die(ctx
, isl_error_unknown
,
4925 "map detected as injective", return -1);
4928 int test_injective(isl_ctx
*ctx
)
4932 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
4934 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
4936 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
4938 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
4940 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
4942 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
4944 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
4946 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
4949 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
4950 if (test_plain_injective(ctx
, str
, 1))
4952 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
4953 if (test_plain_injective(ctx
, str
, 0))
4959 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
4967 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
4968 equal
= isl_aff_plain_is_equal(aff
, aff2
);
4974 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
4978 equal
= aff_plain_is_equal(aff
, str
);
4982 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
4983 "result not as expected", return -1);
4987 /* Is "upa" obviously equal to the isl_union_pw_aff represented by "str"?
4989 static isl_bool
union_pw_aff_plain_is_equal(__isl_keep isl_union_pw_aff
*upa
,
4993 isl_union_pw_aff
*upa2
;
4997 return isl_bool_error
;
4999 ctx
= isl_union_pw_aff_get_ctx(upa
);
5000 upa2
= isl_union_pw_aff_read_from_str(ctx
, str
);
5001 equal
= isl_union_pw_aff_plain_is_equal(upa
, upa2
);
5002 isl_union_pw_aff_free(upa2
);
5007 /* Check that "upa" is obviously equal to the isl_union_pw_aff
5008 * represented by "str".
5010 static isl_stat
union_pw_aff_check_plain_equal(__isl_keep isl_union_pw_aff
*upa
,
5015 equal
= union_pw_aff_plain_is_equal(upa
, str
);
5017 return isl_stat_error
;
5019 isl_die(isl_union_pw_aff_get_ctx(upa
), isl_error_unknown
,
5020 "result not as expected", return isl_stat_error
);
5024 /* Basic tests on isl_union_pw_aff.
5026 * In particular, check that isl_union_pw_aff_aff_on_domain
5027 * aligns the parameters of the input objects and
5028 * that isl_union_pw_aff_param_on_domain_id properly
5029 * introduces the parameter.
5031 static int test_upa(isl_ctx
*ctx
)
5036 isl_union_set
*domain
;
5037 isl_union_pw_aff
*upa
;
5040 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
5041 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5042 domain
= isl_union_set_read_from_str(ctx
, str
);
5043 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
5044 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5045 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5046 isl_union_pw_aff_free(upa
);
5050 id
= isl_id_alloc(ctx
, "N", NULL
);
5051 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5052 domain
= isl_union_set_read_from_str(ctx
, str
);
5053 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
5054 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5055 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5056 isl_union_pw_aff_free(upa
);
5064 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5065 __isl_take isl_aff
*aff2
);
5067 ['+'] = { &isl_aff_add
},
5068 ['-'] = { &isl_aff_sub
},
5069 ['*'] = { &isl_aff_mul
},
5070 ['/'] = { &isl_aff_div
},
5078 } aff_bin_tests
[] = {
5079 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5080 "{ [i] -> [2i] }" },
5081 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5083 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5084 "{ [i] -> [2i] }" },
5085 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5086 "{ [i] -> [2i] }" },
5087 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5088 "{ [i] -> [i/2] }" },
5089 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5091 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5092 "{ [i] -> [NaN] }" },
5093 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5094 "{ [i] -> [NaN] }" },
5095 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5096 "{ [i] -> [NaN] }" },
5097 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5098 "{ [i] -> [NaN] }" },
5099 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5100 "{ [i] -> [NaN] }" },
5101 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5102 "{ [i] -> [NaN] }" },
5103 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5104 "{ [i] -> [NaN] }" },
5105 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5106 "{ [i] -> [NaN] }" },
5107 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5108 "{ [i] -> [NaN] }" },
5109 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5110 "{ [i] -> [NaN] }" },
5111 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5112 "{ [i] -> [NaN] }" },
5113 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5114 "{ [i] -> [NaN] }" },
5117 /* Perform some basic tests of binary operations on isl_aff objects.
5119 static int test_bin_aff(isl_ctx
*ctx
)
5122 isl_aff
*aff1
, *aff2
, *res
;
5123 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5124 __isl_take isl_aff
*aff2
);
5127 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
5128 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
5129 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
5130 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
5131 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
5132 aff1
= fn(aff1
, aff2
);
5133 if (isl_aff_is_nan(res
))
5134 ok
= isl_aff_is_nan(aff1
);
5136 ok
= isl_aff_plain_is_equal(aff1
, res
);
5142 isl_die(ctx
, isl_error_unknown
,
5143 "unexpected result", return -1);
5150 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
5151 __isl_take isl_pw_aff
*pa2
);
5152 } pw_aff_bin_op
[] = {
5153 ['m'] = { &isl_pw_aff_min
},
5154 ['M'] = { &isl_pw_aff_max
},
5157 /* Inputs for binary isl_pw_aff operation tests.
5158 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5159 * defined by pw_aff_bin_op, and "res" is the expected result.
5166 } pw_aff_bin_tests
[] = {
5167 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5169 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5171 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5172 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5173 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5174 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5175 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5176 "{ [i] -> [NaN] }" },
5177 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5178 "{ [i] -> [NaN] }" },
5181 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5183 static int test_bin_pw_aff(isl_ctx
*ctx
)
5187 isl_pw_aff
*pa1
, *pa2
, *res
;
5189 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
5190 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
5191 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
5192 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
5193 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
5194 if (isl_pw_aff_involves_nan(res
))
5195 ok
= isl_pw_aff_involves_nan(pa1
);
5197 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
5198 isl_pw_aff_free(pa1
);
5199 isl_pw_aff_free(res
);
5203 isl_die(ctx
, isl_error_unknown
,
5204 "unexpected result", return -1);
5211 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5212 __isl_take isl_union_pw_multi_aff
*upma1
,
5213 __isl_take isl_union_pw_multi_aff
*upma2
);
5217 } upma_bin_tests
[] = {
5218 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
5219 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5220 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
5221 "{ B[x] -> [2] : x >= 0 }",
5222 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5223 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
5224 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5225 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5226 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5227 "D[i] -> B[2] : i >= 5 }" },
5228 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5229 "{ B[x] -> C[2] : x > 0 }",
5230 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5231 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5232 "{ B[x] -> A[2] : x >= 0 }",
5233 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5236 /* Perform some basic tests of binary operations on
5237 * isl_union_pw_multi_aff objects.
5239 static int test_bin_upma(isl_ctx
*ctx
)
5242 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
5245 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
5246 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5247 upma_bin_tests
[i
].arg1
);
5248 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5249 upma_bin_tests
[i
].arg2
);
5250 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5251 upma_bin_tests
[i
].res
);
5252 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
5253 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
5254 isl_union_pw_multi_aff_free(upma1
);
5255 isl_union_pw_multi_aff_free(res
);
5259 isl_die(ctx
, isl_error_unknown
,
5260 "unexpected result", return -1);
5267 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5268 __isl_take isl_union_pw_multi_aff
*upma1
,
5269 __isl_take isl_union_pw_multi_aff
*upma2
);
5272 } upma_bin_fail_tests
[] = {
5273 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5274 "{ B[x] -> C[2] : x >= 0 }" },
5277 /* Perform some basic tests of binary operations on
5278 * isl_union_pw_multi_aff objects that are expected to fail.
5280 static int test_bin_upma_fail(isl_ctx
*ctx
)
5283 isl_union_pw_multi_aff
*upma1
, *upma2
;
5286 on_error
= isl_options_get_on_error(ctx
);
5287 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5288 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5289 for (i
= 0; i
< n
; ++i
) {
5290 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5291 upma_bin_fail_tests
[i
].arg1
);
5292 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5293 upma_bin_fail_tests
[i
].arg2
);
5294 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5295 isl_union_pw_multi_aff_free(upma1
);
5299 isl_options_set_on_error(ctx
, on_error
);
5301 isl_die(ctx
, isl_error_unknown
,
5302 "operation not expected to succeed", return -1);
5307 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5308 * "fn" is the function that is tested.
5309 * "arg" is a string description of the input.
5310 * "res" is a string description of the expected result.
5313 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5316 } mpa_un_tests
[] = {
5317 { &isl_multi_pw_aff_range_factor_domain
,
5318 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5319 "{ A[x] -> B[(1 : x >= 5)] }" },
5320 { &isl_multi_pw_aff_range_factor_range
,
5321 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5322 "{ A[y] -> C[(2 : y <= 10)] }" },
5323 { &isl_multi_pw_aff_range_factor_domain
,
5324 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5325 "{ A[x] -> B[(1 : x >= 5)] }" },
5326 { &isl_multi_pw_aff_range_factor_range
,
5327 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5328 "{ A[y] -> C[] }" },
5329 { &isl_multi_pw_aff_range_factor_domain
,
5330 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5331 "{ A[x] -> B[] }" },
5332 { &isl_multi_pw_aff_range_factor_range
,
5333 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5334 "{ A[y] -> C[(2 : y <= 10)] }" },
5335 { &isl_multi_pw_aff_range_factor_domain
,
5336 "{ A[x] -> [B[] -> C[]] }",
5337 "{ A[x] -> B[] }" },
5338 { &isl_multi_pw_aff_range_factor_range
,
5339 "{ A[x] -> [B[] -> C[]] }",
5340 "{ A[y] -> C[] }" },
5341 { &isl_multi_pw_aff_factor_range
,
5344 { &isl_multi_pw_aff_range_factor_domain
,
5345 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5346 "{ A[x] -> B[] : x >= 0 }" },
5347 { &isl_multi_pw_aff_range_factor_range
,
5348 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5349 "{ A[y] -> C[] : y >= 0 }" },
5350 { &isl_multi_pw_aff_factor_range
,
5351 "[N] -> { [B[] -> C[]] : N >= 0 }",
5352 "[N] -> { C[] : N >= 0 }" },
5355 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5357 static int test_un_mpa(isl_ctx
*ctx
)
5361 isl_multi_pw_aff
*mpa
, *res
;
5363 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5364 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5365 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5366 mpa
= mpa_un_tests
[i
].fn(mpa
);
5367 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5368 isl_multi_pw_aff_free(mpa
);
5369 isl_multi_pw_aff_free(res
);
5373 isl_die(ctx
, isl_error_unknown
,
5374 "unexpected result", return -1);
5380 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5381 * "fn" is the function that is tested.
5382 * "arg1" and "arg2" are string descriptions of the inputs.
5383 * "res" is a string description of the expected result.
5386 __isl_give isl_multi_pw_aff
*(*fn
)(
5387 __isl_take isl_multi_pw_aff
*mpa1
,
5388 __isl_take isl_multi_pw_aff
*mpa2
);
5392 } mpa_bin_tests
[] = {
5393 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
5395 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
5396 "{ A[x] -> [(x : x <= 10)] }",
5397 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5398 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5399 "{ A[x] -> [] : x <= 10 }",
5400 "{ A[x] -> [] : 5 <= x <= 10 }" },
5401 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5402 "[N] -> { A[x] -> [] : x <= N }",
5403 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5404 { &isl_multi_pw_aff_add
,
5405 "[N] -> { A[x] -> [] : x <= N }",
5406 "{ A[x] -> [] : x >= 5 }",
5407 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5408 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5409 "{ A[y] -> C[(2 : y <= 10)] }",
5410 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5411 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5412 "{ A[y] -> C[2] : y <= 10 }",
5413 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5414 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5415 "[N] -> { A[y] -> C[2] : y <= N }",
5416 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5417 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
5418 "{ A[y] -> C[2] : y <= 10 }",
5419 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5420 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5421 "{ A[] -> [B[1] -> C[2]] }" },
5422 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5423 "{ A[] -> [B[] -> C[]] }" },
5424 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5425 "{ A[y] -> C[] : y <= 10 }",
5426 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5427 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
5428 "{ A[x] -> B[(1 : x >= 5)] }",
5429 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5430 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5431 "{ A[y] -> C[(2 : y <= 10)] }",
5432 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5433 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5434 "{ A[y] -> C[] : y <= 10 }",
5435 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5436 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
5437 "{ A[x] -> B[(1 : x >= 5)] }",
5438 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5439 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5440 "[N] -> { A[y] -> C[] : y <= N }",
5441 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5442 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
5443 "{ A[x] -> B[(1 : x >= 5)] }",
5444 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5445 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
5446 "{ A[y] -> C[] : y <= 10 }",
5447 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5448 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5449 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5450 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5451 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5452 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5453 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5454 "{ A[a,b] -> C[b + 2a] }" },
5455 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5456 "{ B[i,j] -> C[i + 2j] }",
5457 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5458 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5459 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5460 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5461 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5462 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5463 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5464 "{ B[i,j] -> C[] }",
5465 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5466 "{ A[a,b] -> C[] }" },
5467 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5468 "{ B[i,j] -> C[] : i > j }",
5469 "{ A[a,b] -> B[b,a] }",
5470 "{ A[a,b] -> C[] : b > a }" },
5471 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5472 "{ B[i,j] -> C[] : j > 5 }",
5473 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5474 "{ A[a,b] -> C[] : b > a > 5 }" },
5475 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5476 "[N] -> { B[i,j] -> C[] : j > N }",
5477 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5478 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5479 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5480 "[M,N] -> { B[] -> C[] : N > 5 }",
5481 "[M,N] -> { A[] -> B[] : M > N }",
5482 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5485 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5487 static int test_bin_mpa(isl_ctx
*ctx
)
5491 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
5493 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
5494 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
5495 mpa_bin_tests
[i
].arg1
);
5496 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
5497 mpa_bin_tests
[i
].arg2
);
5498 res
= isl_multi_pw_aff_read_from_str(ctx
,
5499 mpa_bin_tests
[i
].res
);
5500 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
5501 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
5502 isl_multi_pw_aff_free(mpa1
);
5503 isl_multi_pw_aff_free(res
);
5507 isl_die(ctx
, isl_error_unknown
,
5508 "unexpected result", return -1);
5514 /* Inputs for basic tests of unary operations on
5515 * isl_multi_union_pw_aff objects.
5516 * "fn" is the function that is tested.
5517 * "arg" is a string description of the input.
5518 * "res" is a string description of the expected result.
5521 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5522 __isl_take isl_multi_union_pw_aff
*mupa
);
5525 } mupa_un_tests
[] = {
5526 { &isl_multi_union_pw_aff_factor_range
,
5527 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5528 "C[{ A[] -> [2] }]" },
5529 { &isl_multi_union_pw_aff_factor_range
,
5530 "[B[] -> C[{ A[] -> [2] }]]",
5531 "C[{ A[] -> [2] }]" },
5532 { &isl_multi_union_pw_aff_factor_range
,
5533 "[B[{ A[] -> [1] }] -> C[]]",
5535 { &isl_multi_union_pw_aff_factor_range
,
5538 { &isl_multi_union_pw_aff_factor_range
,
5539 "([B[] -> C[]] : { A[x] : x >= 0 })",
5540 "(C[] : { A[x] : x >= 0 })" },
5541 { &isl_multi_union_pw_aff_factor_range
,
5542 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
5543 "[N] -> (C[] : { A[x] : x <= N })" },
5544 { &isl_multi_union_pw_aff_factor_range
,
5545 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
5546 "[N] -> (C[] : { : N >= 0 })" },
5549 /* Perform some basic tests of unary operations on
5550 * isl_multi_union_pw_aff objects.
5552 static int test_un_mupa(isl_ctx
*ctx
)
5556 isl_multi_union_pw_aff
*mupa
, *res
;
5558 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
5559 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5560 mupa_un_tests
[i
].arg
);
5561 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5562 mupa_un_tests
[i
].res
);
5563 mupa
= mupa_un_tests
[i
].fn(mupa
);
5564 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5565 isl_multi_union_pw_aff_free(mupa
);
5566 isl_multi_union_pw_aff_free(res
);
5570 isl_die(ctx
, isl_error_unknown
,
5571 "unexpected result", return -1);
5577 /* Inputs for basic tests of binary operations on
5578 * isl_multi_union_pw_aff objects.
5579 * "fn" is the function that is tested.
5580 * "arg1" and "arg2" are string descriptions of the inputs.
5581 * "res" is a string description of the expected result.
5584 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5585 __isl_take isl_multi_union_pw_aff
*mupa1
,
5586 __isl_take isl_multi_union_pw_aff
*mupa2
);
5590 } mupa_bin_tests
[] = {
5591 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5592 "[{ A[] -> [3] }]" },
5593 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5594 "[{ A[] -> [-1] }]" },
5595 { &isl_multi_union_pw_aff_add
,
5596 "[{ A[] -> [1]; B[] -> [4] }]",
5597 "[{ A[] -> [2]; C[] -> [5] }]",
5598 "[{ A[] -> [3] }]" },
5599 { &isl_multi_union_pw_aff_union_add
,
5600 "[{ A[] -> [1]; B[] -> [4] }]",
5601 "[{ A[] -> [2]; C[] -> [5] }]",
5602 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
5603 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5604 "[{ A[x] -> [(x)] : x <= 10 }]",
5605 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
5606 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5607 "([] : { A[x] : x <= 10 })",
5608 "([] : { A[x] : 5 <= x <= 10 })" },
5609 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5610 "[N] -> ([] : { A[x] : x <= N })",
5611 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
5612 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
5613 "([] : { A[x] : x <= 10 })",
5614 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
5615 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5616 "[{ A[x] -> [(x)] : x <= 10 }]",
5617 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
5618 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
5619 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
5620 "([] : { A[x] : x <= 10 })",
5621 "([] : { A[x] })" },
5622 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
5623 "[N] -> ([] : { A[x] : x >= N })",
5624 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
5625 { &isl_multi_union_pw_aff_union_add
,
5626 "[N] -> ([] : { A[] : N >= 0})",
5627 "[N] -> ([] : { A[] : N <= 0})",
5628 "[N] -> ([] : { A[] })" },
5629 { &isl_multi_union_pw_aff_union_add
,
5630 "[N] -> ([] : { A[] })",
5631 "[N] -> ([] : { : })",
5632 "[N] -> ([] : { : })" },
5633 { &isl_multi_union_pw_aff_union_add
,
5634 "[N] -> ([] : { : })",
5635 "[N] -> ([] : { A[] })",
5636 "[N] -> ([] : { : })" },
5637 { &isl_multi_union_pw_aff_union_add
,
5638 "[N] -> ([] : { : N >= 0})",
5639 "[N] -> ([] : { : N <= 0})",
5640 "[N] -> ([] : { : })" },
5641 { &isl_multi_union_pw_aff_range_product
,
5642 "B[{ A[] -> [1] }]",
5643 "C[{ A[] -> [2] }]",
5644 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
5645 { &isl_multi_union_pw_aff_range_product
,
5646 "(B[] : { A[x] : x >= 5 })",
5647 "(C[] : { A[x] : x <= 10 })",
5648 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
5649 { &isl_multi_union_pw_aff_range_product
,
5650 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5651 "(C[] : { A[x] : x <= 10 })",
5652 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
5653 { &isl_multi_union_pw_aff_range_product
,
5654 "(C[] : { A[x] : x <= 10 })",
5655 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5656 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
5657 { &isl_multi_union_pw_aff_range_product
,
5658 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5659 "[N] -> (C[] : { A[x] : x <= N })",
5660 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
5661 { &isl_multi_union_pw_aff_range_product
,
5662 "[N] -> (C[] : { A[x] : x <= N })",
5663 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5664 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
5665 { &isl_multi_union_pw_aff_range_product
,
5666 "B[{ A[] -> [1]; D[] -> [3] }]",
5667 "C[{ A[] -> [2] }]",
5668 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
5669 { &isl_multi_union_pw_aff_range_product
,
5672 "([B[] -> C[]] : { A[x] })" },
5673 { &isl_multi_union_pw_aff_range_product
,
5676 "([B[] -> C[]] : { A[x] })" },
5679 /* Perform some basic tests of binary operations on
5680 * isl_multi_union_pw_aff objects.
5682 static int test_bin_mupa(isl_ctx
*ctx
)
5686 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
5688 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
5689 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
5690 mupa_bin_tests
[i
].arg1
);
5691 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
5692 mupa_bin_tests
[i
].arg2
);
5693 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5694 mupa_bin_tests
[i
].res
);
5695 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
5696 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
5697 isl_multi_union_pw_aff_free(mupa1
);
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_set 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_multi_union_pw_aff
*(*fn
)(
5717 __isl_take isl_multi_union_pw_aff
*mupa
,
5718 __isl_take isl_set
*set
);
5722 } mupa_set_tests
[] = {
5723 { &isl_multi_union_pw_aff_intersect_range
,
5724 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
5725 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
5726 { &isl_multi_union_pw_aff_intersect_range
,
5727 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
5728 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
5729 { &isl_multi_union_pw_aff_intersect_range
,
5730 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
5731 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
5732 { &isl_multi_union_pw_aff_intersect_range
,
5733 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
5734 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
5735 { &isl_multi_union_pw_aff_intersect_range
,
5736 "C[]", "{ C[] }", "C[]" },
5737 { &isl_multi_union_pw_aff_intersect_range
,
5738 "[N] -> (C[] : { : N >= 0 })",
5740 "[N] -> (C[] : { : N >= 0 })" },
5741 { &isl_multi_union_pw_aff_intersect_range
,
5742 "(C[] : { A[a,b] })",
5744 "(C[] : { A[a,b] })" },
5745 { &isl_multi_union_pw_aff_intersect_range
,
5746 "[N] -> (C[] : { A[a,b] : a,b <= N })",
5748 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
5749 { &isl_multi_union_pw_aff_intersect_range
,
5751 "[N] -> { C[] : N >= 0 }",
5752 "[N] -> (C[] : { : N >= 0 })" },
5753 { &isl_multi_union_pw_aff_intersect_range
,
5754 "(C[] : { A[a,b] })",
5755 "[N] -> { C[] : N >= 0 }",
5756 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5757 { &isl_multi_union_pw_aff_intersect_range
,
5758 "[N] -> (C[] : { : N >= 0 })",
5759 "[N] -> { C[] : N < 1024 }",
5760 "[N] -> (C[] : { : 0 <= N < 1024 })" },
5761 { &isl_multi_union_pw_aff_intersect_params
,
5762 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
5763 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
5764 { &isl_multi_union_pw_aff_intersect_params
,
5765 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
5766 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
5767 { &isl_multi_union_pw_aff_intersect_params
,
5768 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
5769 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
5770 { &isl_multi_union_pw_aff_intersect_params
,
5771 "C[]", "[N] -> { : N >= 0 }",
5772 "[N] -> (C[] : { : N >= 0 })" },
5773 { &isl_multi_union_pw_aff_intersect_params
,
5774 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
5775 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5776 { &isl_multi_union_pw_aff_intersect_params
,
5777 "[N] -> (C[] : { A[a,N] })", "{ : }",
5778 "[N] -> (C[] : { A[a,N] })" },
5779 { &isl_multi_union_pw_aff_intersect_params
,
5780 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
5781 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
5784 /* Perform some basic tests of binary operations on
5785 * pairs of isl_multi_union_pw_aff and isl_set objects.
5787 static int test_mupa_set(isl_ctx
*ctx
)
5791 isl_multi_union_pw_aff
*mupa
, *res
;
5794 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
5795 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5796 mupa_set_tests
[i
].arg1
);
5797 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
5798 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5799 mupa_set_tests
[i
].res
);
5800 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
5801 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5802 isl_multi_union_pw_aff_free(mupa
);
5803 isl_multi_union_pw_aff_free(res
);
5807 isl_die(ctx
, isl_error_unknown
,
5808 "unexpected result", return -1);
5814 /* Inputs for basic tests of binary operations on
5815 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5816 * "fn" is the function that is tested.
5817 * "arg1" and "arg2" are string descriptions of the inputs.
5818 * "res" is a string description of the expected result.
5821 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5822 __isl_take isl_multi_union_pw_aff
*mupa
,
5823 __isl_take isl_union_set
*uset
);
5827 } mupa_uset_tests
[] = {
5828 { &isl_multi_union_pw_aff_intersect_domain
,
5829 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
5830 "C[{ B[i,i] -> [3i] }]" },
5831 { &isl_multi_union_pw_aff_intersect_domain
,
5832 "(C[] : { B[i,j] })", "{ B[i,i] }",
5833 "(C[] : { B[i,i] })" },
5834 { &isl_multi_union_pw_aff_intersect_domain
,
5835 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
5836 "[N] -> (C[] : { B[N,N] })" },
5837 { &isl_multi_union_pw_aff_intersect_domain
,
5838 "C[]", "{ B[i,i] }",
5839 "(C[] : { B[i,i] })" },
5840 { &isl_multi_union_pw_aff_intersect_domain
,
5841 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
5842 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
5845 /* Perform some basic tests of binary operations on
5846 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5848 static int test_mupa_uset(isl_ctx
*ctx
)
5852 isl_multi_union_pw_aff
*mupa
, *res
;
5853 isl_union_set
*uset
;
5855 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
5856 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5857 mupa_uset_tests
[i
].arg1
);
5858 uset
= isl_union_set_read_from_str(ctx
,
5859 mupa_uset_tests
[i
].arg2
);
5860 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5861 mupa_uset_tests
[i
].res
);
5862 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
5863 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5864 isl_multi_union_pw_aff_free(mupa
);
5865 isl_multi_union_pw_aff_free(res
);
5869 isl_die(ctx
, isl_error_unknown
,
5870 "unexpected result", return -1);
5876 /* Inputs for basic tests of binary operations on
5877 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5878 * "fn" is the function that is tested.
5879 * "arg1" and "arg2" are string descriptions of the inputs.
5880 * "res" is a string description of the expected result.
5883 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5884 __isl_take isl_multi_union_pw_aff
*mupa
,
5885 __isl_take isl_multi_aff
*ma
);
5889 } mupa_ma_tests
[] = {
5890 { &isl_multi_union_pw_aff_apply_multi_aff
,
5891 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5892 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5893 "{ C[a,b] -> D[b,a] }",
5894 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
5895 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
5896 { &isl_multi_union_pw_aff_apply_multi_aff
,
5897 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
5898 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5899 "{ C[a,b] -> D[b,a] }",
5900 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
5901 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
5902 { &isl_multi_union_pw_aff_apply_multi_aff
,
5903 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5904 "[N] -> { C[a] -> D[a + N] }",
5905 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
5906 { &isl_multi_union_pw_aff_apply_multi_aff
,
5910 { &isl_multi_union_pw_aff_apply_multi_aff
,
5911 "[N] -> (C[] : { : N >= 0 })",
5913 "[N] -> (D[] : { : N >= 0 })" },
5914 { &isl_multi_union_pw_aff_apply_multi_aff
,
5916 "[N] -> { C[] -> D[N] }",
5917 "[N] -> D[{ [N] }]" },
5918 { &isl_multi_union_pw_aff_apply_multi_aff
,
5919 "(C[] : { A[i,j] : i >= j })",
5921 "(D[] : { A[i,j] : i >= j })" },
5922 { &isl_multi_union_pw_aff_apply_multi_aff
,
5923 "[N] -> (C[] : { A[i,j] : N >= 0 })",
5925 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
5926 { &isl_multi_union_pw_aff_apply_multi_aff
,
5927 "(C[] : { A[i,j] : i >= j })",
5928 "[N] -> { C[] -> D[N] }",
5929 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
5932 /* Perform some basic tests of binary operations on
5933 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5935 static int test_mupa_ma(isl_ctx
*ctx
)
5939 isl_multi_union_pw_aff
*mupa
, *res
;
5942 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
5943 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5944 mupa_ma_tests
[i
].arg1
);
5945 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
5946 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5947 mupa_ma_tests
[i
].res
);
5948 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
5949 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5950 isl_multi_union_pw_aff_free(mupa
);
5951 isl_multi_union_pw_aff_free(res
);
5955 isl_die(ctx
, isl_error_unknown
,
5956 "unexpected result", return -1);
5962 /* Inputs for basic tests of binary operations on
5963 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
5964 * "fn" is the function that is tested.
5965 * "arg1" and "arg2" are string descriptions of the inputs.
5966 * "res" is a string description of the expected result.
5969 __isl_give isl_union_pw_aff
*(*fn
)(
5970 __isl_take isl_multi_union_pw_aff
*mupa
,
5971 __isl_take isl_pw_aff
*pa
);
5975 } mupa_pa_tests
[] = {
5976 { &isl_multi_union_pw_aff_apply_pw_aff
,
5977 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5978 "[N] -> { C[a] -> [a + N] }",
5979 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
5980 { &isl_multi_union_pw_aff_apply_pw_aff
,
5981 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5982 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
5983 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
5984 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
5985 { &isl_multi_union_pw_aff_apply_pw_aff
,
5987 "[N] -> { C[] -> [N] }",
5989 { &isl_multi_union_pw_aff_apply_pw_aff
,
5991 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5992 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
5993 { &isl_multi_union_pw_aff_apply_pw_aff
,
5994 "[N] -> (C[] : { : N >= 0 })",
5995 "[N] -> { C[] -> [N] }",
5996 "[N] -> { [N] : N >= 0 }" },
5997 { &isl_multi_union_pw_aff_apply_pw_aff
,
5998 "[N] -> (C[] : { : N >= 0 })",
5999 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6000 "[N] -> { [N] : N >= 0 }" },
6001 { &isl_multi_union_pw_aff_apply_pw_aff
,
6002 "[N] -> (C[] : { : N >= 0 })",
6004 "[N] -> { [0] : N >= 0 }" },
6005 { &isl_multi_union_pw_aff_apply_pw_aff
,
6006 "(C[] : { A[i,j] : i >= j })",
6007 "[N] -> { C[] -> [N] }",
6008 "[N] -> { A[i,j] -> [N] : i >= j }" },
6009 { &isl_multi_union_pw_aff_apply_pw_aff
,
6010 "(C[] : { A[i,j] : i >= j })",
6011 "[N] -> { C[] -> [N] : N >= 0 }",
6012 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6015 /* Perform some basic tests of binary operations on
6016 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6018 static int test_mupa_pa(isl_ctx
*ctx
)
6022 isl_multi_union_pw_aff
*mupa
;
6023 isl_union_pw_aff
*upa
, *res
;
6026 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
6027 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6028 mupa_pa_tests
[i
].arg1
);
6029 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
6030 res
= isl_union_pw_aff_read_from_str(ctx
,
6031 mupa_pa_tests
[i
].res
);
6032 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
6033 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
6034 isl_union_pw_aff_free(upa
);
6035 isl_union_pw_aff_free(res
);
6039 isl_die(ctx
, isl_error_unknown
,
6040 "unexpected result", return -1);
6046 /* Inputs for basic tests of binary operations on
6047 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6048 * "fn" is the function that is tested.
6049 * "arg1" and "arg2" are string descriptions of the inputs.
6050 * "res" is a string description of the expected result.
6053 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6054 __isl_take isl_multi_union_pw_aff
*mupa
,
6055 __isl_take isl_pw_multi_aff
*pma
);
6059 } mupa_pma_tests
[] = {
6060 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6061 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6062 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6063 "{ C[a,b] -> D[b,a] }",
6064 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6065 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6066 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6067 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6068 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6069 "{ C[a,b] -> D[b,a] }",
6070 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6071 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6072 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6073 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6074 "[N] -> { C[a] -> D[a + N] }",
6075 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6076 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6077 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6078 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6079 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6080 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6081 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6082 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6083 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6084 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6085 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6086 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6087 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6088 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6089 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6093 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6094 "[N] -> (C[] : { : N >= 0 })",
6096 "[N] -> (D[] : { : N >= 0 })" },
6097 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6099 "[N] -> { C[] -> D[N] }",
6100 "[N] -> D[{ [N] }]" },
6101 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6102 "(C[] : { A[i,j] : i >= j })",
6104 "(D[] : { A[i,j] : i >= j })" },
6105 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6106 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6108 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6109 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6110 "(C[] : { A[i,j] : i >= j })",
6111 "[N] -> { C[] -> D[N] }",
6112 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6113 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6115 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6116 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6117 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6118 "[N] -> (C[] : { : N >= 0 })",
6119 "[N] -> { C[] -> D[N] }",
6120 "[N] -> D[{ [N] : N >= 0 }]" },
6121 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6122 "[N] -> (C[] : { : N >= 0 })",
6123 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6124 "[N] -> D[{ [N] : N >= 0 }]" },
6125 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6126 "[N] -> (C[] : { : N >= 0 })",
6128 "[N] -> D[{ [0] : N >= 0 }]" },
6129 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6130 "(C[] : { A[i,j] : i >= j })",
6131 "[N] -> { C[] -> D[N] : N >= 0 }",
6132 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6135 /* Perform some basic tests of binary operations on
6136 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6138 static int test_mupa_pma(isl_ctx
*ctx
)
6142 isl_multi_union_pw_aff
*mupa
, *res
;
6143 isl_pw_multi_aff
*pma
;
6145 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
6146 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6147 mupa_pma_tests
[i
].arg1
);
6148 pma
= isl_pw_multi_aff_read_from_str(ctx
,
6149 mupa_pma_tests
[i
].arg2
);
6150 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6151 mupa_pma_tests
[i
].res
);
6152 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
6153 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6154 isl_multi_union_pw_aff_free(mupa
);
6155 isl_multi_union_pw_aff_free(res
);
6159 isl_die(ctx
, isl_error_unknown
,
6160 "unexpected result", return -1);
6166 /* Inputs for basic tests of binary operations on
6167 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6168 * "fn" is the function that is tested.
6169 * "arg1" and "arg2" are string descriptions of the inputs.
6170 * "res" is a string description of the expected result.
6173 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6174 __isl_take isl_multi_union_pw_aff
*mupa
,
6175 __isl_take isl_union_pw_multi_aff
*upma
);
6179 } mupa_upma_tests
[] = {
6180 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6181 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6182 "C[{ A[a,b] -> [b + 2a] }]" },
6183 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6184 "C[{ B[i,j] -> [i + 2j] }]",
6185 "{ A[a,b] -> B[b,a] : b > a }",
6186 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6187 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6188 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6189 "{ A[a,b] -> B[b,a] : b > a }",
6190 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6191 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6192 "C[{ B[i,j] -> [i + 2j] }]",
6193 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6194 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6195 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6196 "(C[] : { B[a,b] })",
6197 "{ A[a,b] -> B[b,a] }",
6198 "(C[] : { A[a,b] })" },
6199 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6200 "(C[] : { B[a,b] })",
6201 "{ B[a,b] -> A[b,a] }",
6203 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6204 "(C[] : { B[a,b] })",
6205 "{ A[a,b] -> B[b,a] : a > b }",
6206 "(C[] : { A[a,b] : a > b })" },
6207 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6208 "(C[] : { B[a,b] : a > b })",
6209 "{ A[a,b] -> B[b,a] }",
6210 "(C[] : { A[a,b] : b > a })" },
6211 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6212 "[N] -> (C[] : { B[a,b] : a > N })",
6213 "{ A[a,b] -> B[b,a] : a > b }",
6214 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6215 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6216 "(C[] : { B[a,b] : a > b })",
6217 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6218 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6219 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6221 "{ A[a,b] -> B[b,a] }",
6223 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6224 "[N] -> (C[] : { : N >= 0 })",
6225 "{ A[a,b] -> B[b,a] }",
6226 "[N] -> (C[] : { : N >= 0 })" },
6227 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6229 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6230 "[N] -> (C[] : { : N >= 0 })" },
6233 /* Perform some basic tests of binary operations on
6234 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6236 static int test_mupa_upma(isl_ctx
*ctx
)
6240 isl_multi_union_pw_aff
*mupa
, *res
;
6241 isl_union_pw_multi_aff
*upma
;
6243 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
6244 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6245 mupa_upma_tests
[i
].arg1
);
6246 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
6247 mupa_upma_tests
[i
].arg2
);
6248 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6249 mupa_upma_tests
[i
].res
);
6250 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
6251 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6252 isl_multi_union_pw_aff_free(mupa
);
6253 isl_multi_union_pw_aff_free(res
);
6257 isl_die(ctx
, isl_error_unknown
,
6258 "unexpected result", return -1);
6264 /* Check that the input tuple of an isl_aff can be set properly.
6266 static isl_stat
test_aff_set_tuple_id(isl_ctx
*ctx
)
6272 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x + 1] }");
6273 id
= isl_id_alloc(ctx
, "A", NULL
);
6274 aff
= isl_aff_set_tuple_id(aff
, isl_dim_in
, id
);
6275 equal
= aff_check_plain_equal(aff
, "{ A[x] -> [x + 1] }");
6278 return isl_stat_error
;
6283 int test_aff(isl_ctx
*ctx
)
6288 isl_local_space
*ls
;
6292 if (test_upa(ctx
) < 0)
6294 if (test_bin_aff(ctx
) < 0)
6296 if (test_bin_pw_aff(ctx
) < 0)
6298 if (test_bin_upma(ctx
) < 0)
6300 if (test_bin_upma_fail(ctx
) < 0)
6302 if (test_un_mpa(ctx
) < 0)
6304 if (test_bin_mpa(ctx
) < 0)
6306 if (test_un_mupa(ctx
) < 0)
6308 if (test_bin_mupa(ctx
) < 0)
6310 if (test_mupa_set(ctx
) < 0)
6312 if (test_mupa_uset(ctx
) < 0)
6314 if (test_mupa_ma(ctx
) < 0)
6316 if (test_mupa_pa(ctx
) < 0)
6318 if (test_mupa_pma(ctx
) < 0)
6320 if (test_mupa_upma(ctx
) < 0)
6323 space
= isl_space_set_alloc(ctx
, 0, 1);
6324 ls
= isl_local_space_from_space(space
);
6325 aff
= isl_aff_zero_on_domain(ls
);
6327 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6328 aff
= isl_aff_scale_down_ui(aff
, 3);
6329 aff
= isl_aff_floor(aff
);
6330 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6331 aff
= isl_aff_scale_down_ui(aff
, 2);
6332 aff
= isl_aff_floor(aff
);
6333 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6336 set
= isl_set_read_from_str(ctx
, str
);
6337 aff
= isl_aff_gist(aff
, set
);
6339 aff
= isl_aff_add_constant_si(aff
, -16);
6340 zero
= isl_aff_plain_is_zero(aff
);
6346 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6348 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6349 aff
= isl_aff_scale_down_ui(aff
, 64);
6350 aff
= isl_aff_floor(aff
);
6351 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6356 if (test_aff_set_tuple_id(ctx
) < 0)
6362 /* Check that "pa" consists of a single expression.
6364 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
6368 n
= isl_pw_aff_n_piece(pa
);
6369 isl_pw_aff_free(pa
);
6374 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
6380 /* Check that the computation below results in a single expression.
6381 * One or two expressions may result depending on which constraint
6382 * ends up being considered as redundant with respect to the other
6383 * constraints after the projection that is performed internally
6384 * by isl_set_dim_min.
6386 static int test_dim_max_1(isl_ctx
*ctx
)
6392 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
6393 "-4a <= b <= 3 and b < n - 4a }";
6394 set
= isl_set_read_from_str(ctx
, str
);
6395 pa
= isl_set_dim_min(set
, 0);
6396 return check_single_piece(ctx
, pa
);
6399 /* Check that the computation below results in a single expression.
6400 * The PIP problem corresponding to these constraints has a row
6401 * that causes a split of the solution domain. The solver should
6402 * first pick rows that split off empty parts such that the actual
6403 * solution domain does not get split.
6404 * Note that the description contains some redundant constraints.
6405 * If these constraints get removed first, then the row mentioned
6406 * above does not appear in the PIP problem.
6408 static int test_dim_max_2(isl_ctx
*ctx
)
6414 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
6415 "N > 0 and P >= 0 }";
6416 set
= isl_set_read_from_str(ctx
, str
);
6417 pa
= isl_set_dim_max(set
, 0);
6418 return check_single_piece(ctx
, pa
);
6421 int test_dim_max(isl_ctx
*ctx
)
6425 isl_set
*set1
, *set2
;
6430 if (test_dim_max_1(ctx
) < 0)
6432 if (test_dim_max_2(ctx
) < 0)
6435 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
6436 set
= isl_set_read_from_str(ctx
, str
);
6437 pwaff
= isl_set_dim_max(set
, 0);
6438 set1
= isl_set_from_pw_aff(pwaff
);
6439 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
6440 set2
= isl_set_read_from_str(ctx
, str
);
6441 equal
= isl_set_is_equal(set1
, set2
);
6447 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6449 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
6450 set
= isl_set_read_from_str(ctx
, str
);
6451 pwaff
= isl_set_dim_max(set
, 0);
6452 set1
= isl_set_from_pw_aff(pwaff
);
6453 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6454 set2
= isl_set_read_from_str(ctx
, str
);
6455 equal
= isl_set_is_equal(set1
, set2
);
6461 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6463 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
6464 set
= isl_set_read_from_str(ctx
, str
);
6465 pwaff
= isl_set_dim_max(set
, 0);
6466 set1
= isl_set_from_pw_aff(pwaff
);
6467 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6468 set2
= isl_set_read_from_str(ctx
, str
);
6469 equal
= isl_set_is_equal(set1
, set2
);
6475 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6477 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
6478 "0 <= i < N and 0 <= j < M }";
6479 map
= isl_map_read_from_str(ctx
, str
);
6480 set
= isl_map_range(map
);
6482 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
6483 set1
= isl_set_from_pw_aff(pwaff
);
6484 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
6485 set2
= isl_set_read_from_str(ctx
, str
);
6486 equal
= isl_set_is_equal(set1
, set2
);
6490 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
6491 set1
= isl_set_from_pw_aff(pwaff
);
6492 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
6493 set2
= isl_set_read_from_str(ctx
, str
);
6494 if (equal
>= 0 && equal
)
6495 equal
= isl_set_is_equal(set1
, set2
);
6504 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6506 /* Check that solutions are properly merged. */
6507 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
6508 "c <= -1 + n - 4a - 2b and c >= -2b and "
6509 "4a >= -4 + n and c >= 0 }";
6510 set
= isl_set_read_from_str(ctx
, str
);
6511 pwaff
= isl_set_dim_min(set
, 2);
6512 set1
= isl_set_from_pw_aff(pwaff
);
6513 str
= "[n] -> { [(0)] : n >= 1 }";
6514 set2
= isl_set_read_from_str(ctx
, str
);
6515 equal
= isl_set_is_equal(set1
, set2
);
6522 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6524 /* Check that empty solution lie in the right space. */
6525 str
= "[n] -> { [t,a] : 1 = 0 }";
6526 set
= isl_set_read_from_str(ctx
, str
);
6527 pwaff
= isl_set_dim_max(set
, 0);
6528 set1
= isl_set_from_pw_aff(pwaff
);
6529 str
= "[n] -> { [t] : 1 = 0 }";
6530 set2
= isl_set_read_from_str(ctx
, str
);
6531 equal
= isl_set_is_equal(set1
, set2
);
6538 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6543 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
6545 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
6549 isl_pw_multi_aff
*pma2
;
6555 ctx
= isl_pw_multi_aff_get_ctx(pma
);
6556 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6557 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
6558 isl_pw_multi_aff_free(pma2
);
6563 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
6564 * represented by "str".
6566 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
6571 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
6575 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
6576 "result not as expected", return -1);
6580 /* Basic test for isl_pw_multi_aff_product.
6582 * Check that multiple pieces are properly handled.
6584 static int test_product_pma(isl_ctx
*ctx
)
6588 isl_pw_multi_aff
*pma1
, *pma2
;
6590 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
6591 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6592 str
= "{ C[] -> D[] }";
6593 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6594 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
6595 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
6596 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
6597 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
6598 isl_pw_multi_aff_free(pma1
);
6605 int test_product(isl_ctx
*ctx
)
6609 isl_union_set
*uset1
, *uset2
;
6613 set
= isl_set_read_from_str(ctx
, str
);
6614 set
= isl_set_product(set
, isl_set_copy(set
));
6615 ok
= isl_set_is_wrapping(set
);
6620 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6623 uset1
= isl_union_set_read_from_str(ctx
, str
);
6624 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
6625 str
= "{ [[] -> []] }";
6626 uset2
= isl_union_set_read_from_str(ctx
, str
);
6627 ok
= isl_union_set_is_equal(uset1
, uset2
);
6628 isl_union_set_free(uset1
);
6629 isl_union_set_free(uset2
);
6633 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6635 if (test_product_pma(ctx
) < 0)
6641 /* Check that two sets are not considered disjoint just because
6642 * they have a different set of (named) parameters.
6644 static int test_disjoint(isl_ctx
*ctx
)
6647 isl_set
*set
, *set2
;
6650 str
= "[n] -> { [[]->[]] }";
6651 set
= isl_set_read_from_str(ctx
, str
);
6652 str
= "{ [[]->[]] }";
6653 set2
= isl_set_read_from_str(ctx
, str
);
6654 disjoint
= isl_set_is_disjoint(set
, set2
);
6660 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6665 /* Inputs for isl_pw_multi_aff_is_equal tests.
6666 * "f1" and "f2" are the two function that need to be compared.
6667 * "equal" is the expected result.
6673 } pma_equal_tests
[] = {
6674 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
6675 "[N] -> { [0] : 0 <= N <= 1 }" },
6676 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6677 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
6678 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6679 "[N] -> { [0] : 0 <= N <= 1 }" },
6680 { 0, "{ [NaN] }", "{ [NaN] }" },
6683 int test_equal(isl_ctx
*ctx
)
6687 isl_set
*set
, *set2
;
6691 set
= isl_set_read_from_str(ctx
, str
);
6693 set2
= isl_set_read_from_str(ctx
, str
);
6694 equal
= isl_set_is_equal(set
, set2
);
6700 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6702 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
6703 int expected
= pma_equal_tests
[i
].equal
;
6704 isl_pw_multi_aff
*f1
, *f2
;
6706 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
6707 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
6708 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
6709 isl_pw_multi_aff_free(f1
);
6710 isl_pw_multi_aff_free(f2
);
6713 if (equal
!= expected
)
6714 isl_die(ctx
, isl_error_unknown
,
6715 "unexpected equality result", return -1);
6721 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
6722 enum isl_dim_type type
, unsigned pos
, int fixed
)
6726 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
6733 isl_die(ctx
, isl_error_unknown
,
6734 "map not detected as fixed", return -1);
6736 isl_die(ctx
, isl_error_unknown
,
6737 "map detected as fixed", return -1);
6740 int test_fixed(isl_ctx
*ctx
)
6745 str
= "{ [i] -> [i] }";
6746 map
= isl_map_read_from_str(ctx
, str
);
6747 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
6749 str
= "{ [i] -> [1] }";
6750 map
= isl_map_read_from_str(ctx
, str
);
6751 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6753 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
6754 map
= isl_map_read_from_str(ctx
, str
);
6755 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6757 map
= isl_map_read_from_str(ctx
, str
);
6758 map
= isl_map_neg(map
);
6759 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6765 struct isl_vertices_test_data
{
6768 const char *vertex
[6];
6769 } vertices_tests
[] = {
6770 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
6771 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
6772 { "{ A[t, i] : t = 14 and i = 1 }",
6773 1, { "{ A[14, 1] }" } },
6774 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
6775 "c <= m and m <= n and m > 0 }",
6777 "[n, m] -> { [n, m, m] : 0 < m <= n }",
6778 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
6779 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
6780 "[n, m] -> { [m, m, m] : 0 < m <= n }",
6781 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
6782 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
6786 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
6788 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
6790 struct isl_vertices_test_data
*data
= user
;
6793 isl_basic_set
*bset
;
6794 isl_pw_multi_aff
*pma
;
6798 ctx
= isl_vertex_get_ctx(vertex
);
6799 bset
= isl_vertex_get_domain(vertex
);
6800 ma
= isl_vertex_get_expr(vertex
);
6801 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
6803 for (i
= 0; i
< data
->n
; ++i
) {
6804 isl_pw_multi_aff
*pma_i
;
6806 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
6807 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
6808 isl_pw_multi_aff_free(pma_i
);
6810 if (equal
< 0 || equal
)
6814 isl_pw_multi_aff_free(pma
);
6815 isl_vertex_free(vertex
);
6818 return isl_stat_error
;
6820 return equal
? isl_stat_ok
: isl_stat_error
;
6823 int test_vertices(isl_ctx
*ctx
)
6827 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
6828 isl_basic_set
*bset
;
6829 isl_vertices
*vertices
;
6833 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
6834 vertices
= isl_basic_set_compute_vertices(bset
);
6835 n
= isl_vertices_get_n_vertices(vertices
);
6836 if (vertices_tests
[i
].n
!= n
)
6838 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
6839 &vertices_tests
[i
]) < 0)
6841 isl_vertices_free(vertices
);
6842 isl_basic_set_free(bset
);
6847 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
6854 int test_union_pw(isl_ctx
*ctx
)
6858 isl_union_set
*uset
;
6859 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
6861 str
= "{ [x] -> x^2 }";
6862 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
6863 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
6864 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
6865 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
6866 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
6867 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
6868 isl_union_pw_qpolynomial_free(upwqp1
);
6869 isl_union_pw_qpolynomial_free(upwqp2
);
6873 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6878 /* Inputs for basic tests of functions that select
6879 * subparts of the domain of an isl_multi_union_pw_aff.
6880 * "fn" is the function that is tested.
6881 * "arg" is a string description of the input.
6882 * "res" is a string description of the expected result.
6885 __isl_give isl_union_set
*(*fn
)(
6886 __isl_take isl_multi_union_pw_aff
*mupa
);
6889 } un_locus_tests
[] = {
6890 { &isl_multi_union_pw_aff_zero_union_set
,
6891 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6892 "{ A[0,j]; B[0,j] }" },
6893 { &isl_multi_union_pw_aff_zero_union_set
,
6894 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
6895 "{ A[i,i]; B[i,i] : i >= 0 }" },
6896 { &isl_multi_union_pw_aff_zero_union_set
,
6897 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
6898 "{ A[i,j]; B[i,i] : i >= 0 }" },
6901 /* Perform some basic tests of functions that select
6902 * subparts of the domain of an isl_multi_union_pw_aff.
6904 static int test_un_locus(isl_ctx
*ctx
)
6908 isl_union_set
*uset
, *res
;
6909 isl_multi_union_pw_aff
*mupa
;
6911 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
6912 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6913 un_locus_tests
[i
].arg
);
6914 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
6915 uset
= un_locus_tests
[i
].fn(mupa
);
6916 ok
= isl_union_set_is_equal(uset
, res
);
6917 isl_union_set_free(uset
);
6918 isl_union_set_free(res
);
6922 isl_die(ctx
, isl_error_unknown
,
6923 "unexpected result", return -1);
6929 /* Inputs for basic tests of functions that select
6930 * subparts of an isl_union_map based on a relation
6931 * specified by an isl_multi_union_pw_aff.
6932 * "fn" is the function that is tested.
6933 * "arg1" and "arg2" are string descriptions of the inputs.
6934 * "res" is a string description of the expected result.
6937 __isl_give isl_union_map
*(*fn
)(
6938 __isl_take isl_union_map
*umap
,
6939 __isl_take isl_multi_union_pw_aff
*mupa
);
6943 } bin_locus_tests
[] = {
6944 { &isl_union_map_eq_at_multi_union_pw_aff
,
6945 "{ A[i,j] -> B[i',j'] }",
6946 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6947 "{ A[i,j] -> B[i,j'] }" },
6948 { &isl_union_map_eq_at_multi_union_pw_aff
,
6949 "{ A[i,j] -> B[i',j'] }",
6950 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6951 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6952 "{ A[i,j] -> B[i,j] }" },
6953 { &isl_union_map_eq_at_multi_union_pw_aff
,
6954 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6955 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6956 "{ A[i,j] -> B[i,j'] }" },
6957 { &isl_union_map_eq_at_multi_union_pw_aff
,
6958 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6959 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
6960 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
6961 { &isl_union_map_eq_at_multi_union_pw_aff
,
6962 "{ A[i,j] -> B[i',j'] }",
6963 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
6964 "{ A[i,j] -> B[i,j'] : i > j }" },
6965 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
6966 "{ A[i,j] -> B[i',j'] }",
6967 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6968 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6969 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
6970 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
6971 "{ A[i,j] -> B[i',j'] }",
6972 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6973 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6974 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
6975 { &isl_union_map_eq_at_multi_union_pw_aff
,
6976 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6977 "(F[] : { A[i,j]; B[i,j] })",
6978 "{ A[i,j] -> B[i',j'] }" },
6979 { &isl_union_map_eq_at_multi_union_pw_aff
,
6980 "{ A[i,j] -> B[i',j'] }",
6981 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6982 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
6983 { &isl_union_map_eq_at_multi_union_pw_aff
,
6984 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
6985 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6986 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
6987 { &isl_union_map_eq_at_multi_union_pw_aff
,
6988 "{ A[i,j] -> B[i',j'] }",
6989 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
6990 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
6991 { &isl_union_map_eq_at_multi_union_pw_aff
,
6992 "{ A[i,j] -> B[i',j'] }",
6993 "[N] -> (F[] : { : N >= 0 })",
6994 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
6997 /* Perform some basic tests of functions that select
6998 * subparts of an isl_union_map based on a relation
6999 * specified by an isl_multi_union_pw_aff.
7001 static int test_bin_locus(isl_ctx
*ctx
)
7005 isl_union_map
*umap
, *res
;
7006 isl_multi_union_pw_aff
*mupa
;
7008 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
7009 umap
= isl_union_map_read_from_str(ctx
,
7010 bin_locus_tests
[i
].arg1
);
7011 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
7012 bin_locus_tests
[i
].arg2
);
7013 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
7014 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
7015 ok
= isl_union_map_is_equal(umap
, res
);
7016 isl_union_map_free(umap
);
7017 isl_union_map_free(res
);
7021 isl_die(ctx
, isl_error_unknown
,
7022 "unexpected result", return -1);
7028 /* Perform basic locus tests.
7030 static int test_locus(isl_ctx
*ctx
)
7032 if (test_un_locus(ctx
) < 0)
7034 if (test_bin_locus(ctx
) < 0)
7039 /* Test that isl_union_pw_qpolynomial_eval picks up the function
7040 * defined over the correct domain space.
7042 static int test_eval_1(isl_ctx
*ctx
)
7047 isl_union_pw_qpolynomial
*upwqp
;
7051 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
7052 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
7054 set
= isl_set_read_from_str(ctx
, str
);
7055 pnt
= isl_set_sample_point(set
);
7056 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
7057 cmp
= isl_val_cmp_si(v
, 36);
7063 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
7068 /* Check that isl_qpolynomial_eval handles getting called on a void point.
7070 static int test_eval_2(isl_ctx
*ctx
)
7075 isl_qpolynomial
*qp
;
7079 str
= "{ A[x] -> [x] }";
7080 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
7081 str
= "{ A[x] : false }";
7082 set
= isl_set_read_from_str(ctx
, str
);
7083 pnt
= isl_set_sample_point(set
);
7084 v
= isl_qpolynomial_eval(qp
, pnt
);
7085 ok
= isl_val_is_nan(v
);
7091 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
7096 /* Inputs for isl_pw_aff_eval test.
7097 * "f" is the affine function.
7098 * "p" is the point where the function should be evaluated.
7099 * "res" is the expected result.
7105 } aff_eval_tests
[] = {
7106 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
7107 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
7108 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
7109 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
7110 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
7111 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
7112 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
7113 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
7114 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
7115 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
7116 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
7117 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
7118 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
7119 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
7120 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
7121 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
7122 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
7123 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
7124 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
7125 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
7126 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
7127 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
7128 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
7131 /* Perform basic isl_pw_aff_eval tests.
7133 static int test_eval_aff(isl_ctx
*ctx
)
7137 for (i
= 0; i
< ARRAY_SIZE(aff_eval_tests
); ++i
) {
7144 pa
= isl_pw_aff_read_from_str(ctx
, aff_eval_tests
[i
].f
);
7145 set
= isl_set_read_from_str(ctx
, aff_eval_tests
[i
].p
);
7146 pnt
= isl_set_sample_point(set
);
7147 v
= isl_pw_aff_eval(pa
, pnt
);
7148 r
= val_check_equal(v
, aff_eval_tests
[i
].res
);
7156 /* Perform basic evaluation tests.
7158 static int test_eval(isl_ctx
*ctx
)
7160 if (test_eval_1(ctx
) < 0)
7162 if (test_eval_2(ctx
) < 0)
7164 if (test_eval_aff(ctx
) < 0)
7169 /* Descriptions of sets that are tested for reparsing after printing.
7171 const char *output_tests
[] = {
7172 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
7175 "{ [x] : x mod 2 = 0 }",
7176 "{ [x] : x mod 2 = 1 }",
7177 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
7178 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
7179 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
7180 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
7181 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
7182 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
7185 /* Check that printing a set and reparsing a set from the printed output
7186 * results in the same set.
7188 static int test_output_set(isl_ctx
*ctx
)
7192 isl_set
*set1
, *set2
;
7195 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
7196 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
7197 str
= isl_set_to_str(set1
);
7198 set2
= isl_set_read_from_str(ctx
, str
);
7200 equal
= isl_set_is_equal(set1
, set2
);
7206 isl_die(ctx
, isl_error_unknown
,
7207 "parsed output not the same", return -1);
7213 /* Check that an isl_multi_aff is printed using a consistent space.
7215 static isl_stat
test_output_ma(isl_ctx
*ctx
)
7220 isl_multi_aff
*ma
, *ma2
;
7222 ma
= isl_multi_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
7223 aff
= isl_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
7224 ma
= isl_multi_aff_set_aff(ma
, 0, aff
);
7225 str
= isl_multi_aff_to_str(ma
);
7226 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
7228 equal
= isl_multi_aff_plain_is_equal(ma
, ma2
);
7229 isl_multi_aff_free(ma2
);
7230 isl_multi_aff_free(ma
);
7233 return isl_stat_error
;
7235 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7236 return isl_stat_error
);
7241 /* Check that an isl_multi_pw_aff is printed using a consistent space.
7243 static isl_stat
test_output_mpa(isl_ctx
*ctx
)
7248 isl_multi_pw_aff
*mpa
, *mpa2
;
7250 mpa
= isl_multi_pw_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
7251 pa
= isl_pw_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
7252 mpa
= isl_multi_pw_aff_set_pw_aff(mpa
, 0, pa
);
7253 str
= isl_multi_pw_aff_to_str(mpa
);
7254 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
7256 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
7257 isl_multi_pw_aff_free(mpa2
);
7258 isl_multi_pw_aff_free(mpa
);
7261 return isl_stat_error
;
7263 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7264 return isl_stat_error
);
7269 int test_output(isl_ctx
*ctx
)
7277 if (test_output_set(ctx
) < 0)
7279 if (test_output_ma(ctx
) < 0)
7281 if (test_output_mpa(ctx
) < 0)
7284 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
7285 pa
= isl_pw_aff_read_from_str(ctx
, str
);
7287 p
= isl_printer_to_str(ctx
);
7288 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
7289 p
= isl_printer_print_pw_aff(p
, pa
);
7290 s
= isl_printer_get_str(p
);
7291 isl_printer_free(p
);
7292 isl_pw_aff_free(pa
);
7296 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
7301 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7306 int test_sample(isl_ctx
*ctx
)
7309 isl_basic_set
*bset1
, *bset2
;
7312 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
7313 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
7314 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
7315 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
7316 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
7317 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
7318 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
7319 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
7320 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
7321 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
7322 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
7323 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
7324 "d - 1073741821e and "
7325 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
7326 "3j >= 1 - a + b + 2e and "
7327 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
7328 "3i <= 4 - a + 4b - e and "
7329 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
7330 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
7331 "c <= -1 + a and 3i >= -2 - a + 3e and "
7332 "1073741822e <= 1073741823 - a + 1073741822b + c and "
7333 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
7334 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
7335 "1073741823e >= 1 + 1073741823b - d and "
7336 "3i >= 1073741823b + c - 1073741823e - f and "
7337 "3i >= 1 + 2b + e + 3g }";
7338 bset1
= isl_basic_set_read_from_str(ctx
, str
);
7339 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
7340 empty
= isl_basic_set_is_empty(bset2
);
7341 subset
= isl_basic_set_is_subset(bset2
, bset1
);
7342 isl_basic_set_free(bset1
);
7343 isl_basic_set_free(bset2
);
7344 if (empty
< 0 || subset
< 0)
7347 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
7349 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
7354 int test_fixed_power(isl_ctx
*ctx
)
7361 str
= "{ [i] -> [i + 1] }";
7362 map
= isl_map_read_from_str(ctx
, str
);
7363 exp
= isl_val_int_from_si(ctx
, 23);
7364 map
= isl_map_fixed_power_val(map
, exp
);
7365 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
7373 int test_slice(isl_ctx
*ctx
)
7379 str
= "{ [i] -> [j] }";
7380 map
= isl_map_read_from_str(ctx
, str
);
7381 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7382 equal
= map_check_equal(map
, "{ [i] -> [i] }");
7387 str
= "{ [i] -> [j] }";
7388 map
= isl_map_read_from_str(ctx
, str
);
7389 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7390 equal
= map_check_equal(map
, "{ [i] -> [j] }");
7395 str
= "{ [i] -> [j] }";
7396 map
= isl_map_read_from_str(ctx
, str
);
7397 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7398 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
7403 str
= "{ [i] -> [j] }";
7404 map
= isl_map_read_from_str(ctx
, str
);
7405 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7406 equal
= map_check_equal(map
, "{ [0] -> [j] }");
7411 str
= "{ [i] -> [j] }";
7412 map
= isl_map_read_from_str(ctx
, str
);
7413 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7414 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
7419 str
= "{ [i] -> [j] }";
7420 map
= isl_map_read_from_str(ctx
, str
);
7421 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7422 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
7430 int test_eliminate(isl_ctx
*ctx
)
7436 str
= "{ [i] -> [j] : i = 2j }";
7437 map
= isl_map_read_from_str(ctx
, str
);
7438 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
7439 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
7447 /* Check that isl_set_dim_residue_class detects that the values of j
7448 * in the set below are all odd and that it does not detect any spurious
7451 static int test_residue_class(isl_ctx
*ctx
)
7458 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
7459 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
7460 set
= isl_set_read_from_str(ctx
, str
);
7463 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
7465 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
7466 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
7467 res
= isl_stat_error
);
7475 static int test_align_parameters_1(isl_ctx
*ctx
)
7479 isl_multi_aff
*ma1
, *ma2
;
7482 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
7483 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
7485 space
= isl_space_params_alloc(ctx
, 1);
7486 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
7487 ma1
= isl_multi_aff_align_params(ma1
, space
);
7489 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
7490 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
7492 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
7494 isl_multi_aff_free(ma1
);
7495 isl_multi_aff_free(ma2
);
7500 isl_die(ctx
, isl_error_unknown
,
7501 "result not as expected", return -1);
7506 /* Check the isl_multi_*_from_*_list operation in case inputs
7507 * have unaligned parameters.
7508 * In particular, older versions of isl would simply fail
7509 * (without printing any error message).
7511 static isl_stat
test_align_parameters_2(isl_ctx
*ctx
)
7518 map
= isl_map_read_from_str(ctx
, "{ A[] -> M[x] }");
7519 space
= isl_map_get_space(map
);
7522 aff
= isl_aff_read_from_str(ctx
, "[N] -> { A[] -> [N] }");
7523 ma
= isl_multi_aff_from_aff_list(space
, isl_aff_list_from_aff(aff
));
7524 isl_multi_aff_free(ma
);
7527 return isl_stat_error
;
7531 /* Perform basic parameter alignment tests.
7533 static int test_align_parameters(isl_ctx
*ctx
)
7535 if (test_align_parameters_1(ctx
) < 0)
7537 if (test_align_parameters_2(ctx
) < 0)
7543 /* Check that isl_*_drop_unused_params actually drops the unused parameters
7544 * by comparing the result using isl_*_plain_is_equal.
7545 * Note that this assumes that isl_*_plain_is_equal does not consider
7546 * objects that only differ by unused parameters to be equal.
7548 int test_drop_unused_parameters(isl_ctx
*ctx
)
7550 const char *str_with
, *str_without
;
7551 isl_basic_set
*bset1
, *bset2
;
7552 isl_set
*set1
, *set2
;
7553 isl_pw_aff
*pwa1
, *pwa2
;
7556 str_with
= "[n, m, o] -> { [m] }";
7557 str_without
= "[m] -> { [m] }";
7559 bset1
= isl_basic_set_read_from_str(ctx
, str_with
);
7560 bset2
= isl_basic_set_read_from_str(ctx
, str_without
);
7561 bset1
= isl_basic_set_drop_unused_params(bset1
);
7562 equal
= isl_basic_set_plain_is_equal(bset1
, bset2
);
7563 isl_basic_set_free(bset1
);
7564 isl_basic_set_free(bset2
);
7569 isl_die(ctx
, isl_error_unknown
,
7570 "result not as expected", return -1);
7572 set1
= isl_set_read_from_str(ctx
, str_with
);
7573 set2
= isl_set_read_from_str(ctx
, str_without
);
7574 set1
= isl_set_drop_unused_params(set1
);
7575 equal
= isl_set_plain_is_equal(set1
, set2
);
7582 isl_die(ctx
, isl_error_unknown
,
7583 "result not as expected", return -1);
7585 pwa1
= isl_pw_aff_read_from_str(ctx
, str_with
);
7586 pwa2
= isl_pw_aff_read_from_str(ctx
, str_without
);
7587 pwa1
= isl_pw_aff_drop_unused_params(pwa1
);
7588 equal
= isl_pw_aff_plain_is_equal(pwa1
, pwa2
);
7589 isl_pw_aff_free(pwa1
);
7590 isl_pw_aff_free(pwa2
);
7595 isl_die(ctx
, isl_error_unknown
,
7596 "result not as expected", return -1);
7601 static int test_list(isl_ctx
*ctx
)
7603 isl_id
*a
, *b
, *c
, *d
, *id
;
7607 a
= isl_id_alloc(ctx
, "a", NULL
);
7608 b
= isl_id_alloc(ctx
, "b", NULL
);
7609 c
= isl_id_alloc(ctx
, "c", NULL
);
7610 d
= isl_id_alloc(ctx
, "d", NULL
);
7612 list
= isl_id_list_alloc(ctx
, 4);
7613 list
= isl_id_list_add(list
, b
);
7614 list
= isl_id_list_insert(list
, 0, a
);
7615 list
= isl_id_list_add(list
, c
);
7616 list
= isl_id_list_add(list
, d
);
7617 list
= isl_id_list_drop(list
, 1, 1);
7621 if (isl_id_list_n_id(list
) != 3) {
7622 isl_id_list_free(list
);
7623 isl_die(ctx
, isl_error_unknown
,
7624 "unexpected number of elements in list", return -1);
7627 id
= isl_id_list_get_id(list
, 0);
7630 id
= isl_id_list_get_id(list
, 1);
7633 id
= isl_id_list_get_id(list
, 2);
7637 isl_id_list_free(list
);
7640 isl_die(ctx
, isl_error_unknown
,
7641 "unexpected elements in list", return -1);
7646 const char *set_conversion_tests
[] = {
7647 "[N] -> { [i] : N - 1 <= 2 i <= N }",
7648 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
7649 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7650 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7651 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
7652 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
7653 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
7654 "-3 + c <= d <= 28 + c) }",
7657 /* Check that converting from isl_set to isl_pw_multi_aff and back
7658 * to isl_set produces the original isl_set.
7660 static int test_set_conversion(isl_ctx
*ctx
)
7664 isl_set
*set1
, *set2
;
7665 isl_pw_multi_aff
*pma
;
7668 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
7669 str
= set_conversion_tests
[i
];
7670 set1
= isl_set_read_from_str(ctx
, str
);
7671 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
7672 set2
= isl_set_from_pw_multi_aff(pma
);
7673 equal
= isl_set_is_equal(set1
, set2
);
7680 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7687 const char *conversion_tests
[] = {
7688 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7689 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7690 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7691 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7693 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7694 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7695 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7698 /* Check that converting from isl_map to isl_pw_multi_aff and back
7699 * to isl_map produces the original isl_map.
7701 static int test_map_conversion(isl_ctx
*ctx
)
7704 isl_map
*map1
, *map2
;
7705 isl_pw_multi_aff
*pma
;
7708 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
7709 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
7710 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
7711 map2
= isl_map_from_pw_multi_aff(pma
);
7712 equal
= isl_map_is_equal(map1
, map2
);
7719 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7726 /* Descriptions of isl_pw_multi_aff objects for testing conversion
7727 * to isl_multi_pw_aff and back.
7729 const char *mpa_conversion_tests
[] = {
7731 "{ [x] -> A[x] : x >= 0 }",
7732 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
7733 "{ [x] -> A[x, x + 1] }",
7735 "{ [x] -> A[] : x >= 0 }",
7738 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
7739 * back to isl_pw_multi_aff preserves the original meaning.
7741 static int test_mpa_conversion(isl_ctx
*ctx
)
7744 isl_pw_multi_aff
*pma1
, *pma2
;
7745 isl_multi_pw_aff
*mpa
;
7748 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
7750 str
= mpa_conversion_tests
[i
];
7751 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7752 pma2
= isl_pw_multi_aff_copy(pma1
);
7753 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
7754 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
7755 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
7756 isl_pw_multi_aff_free(pma1
);
7757 isl_pw_multi_aff_free(pma2
);
7762 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7769 /* Descriptions of union maps that should be convertible
7770 * to an isl_multi_union_pw_aff.
7772 const char *umap_mupa_conversion_tests
[] = {
7773 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7774 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7775 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7776 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7778 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7779 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7780 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7781 "{ A[] -> B[0]; C[] -> B[1] }",
7782 "{ A[] -> B[]; C[] -> B[] }",
7785 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
7786 * to isl_union_map produces the original isl_union_map.
7788 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
7791 isl_union_map
*umap1
, *umap2
;
7792 isl_multi_union_pw_aff
*mupa
;
7795 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
7797 str
= umap_mupa_conversion_tests
[i
];
7798 umap1
= isl_union_map_read_from_str(ctx
, str
);
7799 umap2
= isl_union_map_copy(umap1
);
7800 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
7801 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
7802 equal
= isl_union_map_is_equal(umap1
, umap2
);
7803 isl_union_map_free(umap1
);
7804 isl_union_map_free(umap2
);
7809 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7816 static int test_conversion(isl_ctx
*ctx
)
7818 if (test_set_conversion(ctx
) < 0)
7820 if (test_map_conversion(ctx
) < 0)
7822 if (test_mpa_conversion(ctx
) < 0)
7824 if (test_union_map_mupa_conversion(ctx
) < 0)
7829 /* Check that isl_basic_map_curry does not modify input.
7831 static int test_curry(isl_ctx
*ctx
)
7834 isl_basic_map
*bmap1
, *bmap2
;
7837 str
= "{ [A[] -> B[]] -> C[] }";
7838 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
7839 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
7840 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
7841 isl_basic_map_free(bmap1
);
7842 isl_basic_map_free(bmap2
);
7847 isl_die(ctx
, isl_error_unknown
,
7848 "curried map should not be equal to original",
7858 } preimage_tests
[] = {
7859 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
7860 "{ A[j,i] -> B[i,j] }",
7861 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
7862 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7863 "{ A[a,b] -> B[a/2,b/6] }",
7864 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
7865 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7866 "{ A[a,b] -> B[a/2,b/6] }",
7867 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
7868 "exists i,j : a = 2 i and b = 6 j }" },
7869 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
7870 "[n] -> { : 0 <= n <= 100 }" },
7871 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7872 "{ A[a] -> B[2a] }",
7873 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
7874 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7875 "{ A[a] -> B[([a/2])] }",
7876 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
7877 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
7878 "{ A[a] -> B[a,a,a/3] }",
7879 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
7880 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
7881 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
7884 static int test_preimage_basic_set(isl_ctx
*ctx
)
7887 isl_basic_set
*bset1
, *bset2
;
7891 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
7892 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
7893 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
7894 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
7895 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
7896 equal
= isl_basic_set_is_equal(bset1
, bset2
);
7897 isl_basic_set_free(bset1
);
7898 isl_basic_set_free(bset2
);
7902 isl_die(ctx
, isl_error_unknown
, "bad preimage",
7913 } preimage_domain_tests
[] = {
7914 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
7915 "{ A[j,i] -> B[i,j] }",
7916 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
7917 { "{ B[i] -> C[i]; D[i] -> E[i] }",
7918 "{ A[i] -> B[i + 1] }",
7919 "{ A[i] -> C[i + 1] }" },
7920 { "{ B[i] -> C[i]; B[i] -> E[i] }",
7921 "{ A[i] -> B[i + 1] }",
7922 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
7923 { "{ B[i] -> C[([i/2])] }",
7924 "{ A[i] -> B[2i] }",
7925 "{ A[i] -> C[i] }" },
7926 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
7927 "{ A[i] -> B[([i/5]), ([i/7])] }",
7928 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
7929 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
7930 "[N] -> { A[] -> B[([N/5])] }",
7931 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
7932 { "{ B[i] -> C[i] : exists a : i = 5 a }",
7933 "{ A[i] -> B[2i] }",
7934 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
7935 { "{ B[i] -> C[i] : exists a : i = 2 a; "
7936 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
7937 "{ A[i] -> B[2i] }",
7938 "{ A[i] -> C[2i] }" },
7939 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
7940 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
7943 static int test_preimage_union_map(isl_ctx
*ctx
)
7946 isl_union_map
*umap1
, *umap2
;
7950 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
7951 umap1
= isl_union_map_read_from_str(ctx
,
7952 preimage_domain_tests
[i
].map
);
7953 ma
= isl_multi_aff_read_from_str(ctx
,
7954 preimage_domain_tests
[i
].ma
);
7955 umap2
= isl_union_map_read_from_str(ctx
,
7956 preimage_domain_tests
[i
].res
);
7957 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
7958 equal
= isl_union_map_is_equal(umap1
, umap2
);
7959 isl_union_map_free(umap1
);
7960 isl_union_map_free(umap2
);
7964 isl_die(ctx
, isl_error_unknown
, "bad preimage",
7971 static int test_preimage(isl_ctx
*ctx
)
7973 if (test_preimage_basic_set(ctx
) < 0)
7975 if (test_preimage_union_map(ctx
) < 0)
7985 } pullback_tests
[] = {
7986 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
7987 "{ A[a,b] -> C[b + 2a] }" },
7988 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
7989 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
7990 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
7991 "{ A[a] -> C[(a)/6] }" },
7992 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
7993 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
7994 "{ A[a] -> C[(2a)/3] }" },
7995 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
7996 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
7997 "{ A[i,j] -> C[i + j, i + j] }"},
7998 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
7999 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
8000 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
8001 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
8002 "{ [i, j] -> [floor((i)/3), j] }",
8003 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
8006 static int test_pullback(isl_ctx
*ctx
)
8009 isl_multi_aff
*ma1
, *ma2
;
8013 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
8014 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
8015 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
8016 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
8017 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
8018 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
8019 isl_multi_aff_free(ma1
);
8020 isl_multi_aff_free(ma2
);
8024 isl_die(ctx
, isl_error_unknown
, "bad pullback",
8031 /* Check that negation is printed correctly and that equal expressions
8032 * are correctly identified.
8034 static int test_ast(isl_ctx
*ctx
)
8036 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
8040 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
8041 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
8042 expr
= isl_ast_expr_add(expr1
, expr2
);
8043 expr2
= isl_ast_expr_copy(expr
);
8044 expr
= isl_ast_expr_neg(expr
);
8045 expr2
= isl_ast_expr_neg(expr2
);
8046 equal
= isl_ast_expr_is_equal(expr
, expr2
);
8047 str
= isl_ast_expr_to_C_str(expr
);
8048 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
8050 isl_ast_expr_free(expr
);
8051 isl_ast_expr_free(expr2
);
8053 if (ok
< 0 || equal
< 0)
8056 isl_die(ctx
, isl_error_unknown
,
8057 "equal expressions not considered equal", return -1);
8059 isl_die(ctx
, isl_error_unknown
,
8060 "isl_ast_expr printed incorrectly", return -1);
8062 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
8063 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
8064 expr
= isl_ast_expr_add(expr1
, expr2
);
8065 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
8066 expr
= isl_ast_expr_sub(expr3
, expr
);
8067 str
= isl_ast_expr_to_C_str(expr
);
8068 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
8070 isl_ast_expr_free(expr
);
8075 isl_die(ctx
, isl_error_unknown
,
8076 "isl_ast_expr printed incorrectly", return -1);
8081 /* Check that isl_ast_build_expr_from_set returns a valid expression
8082 * for an empty set. Note that isl_ast_build_expr_from_set getting
8083 * called on an empty set probably indicates a bug in the caller.
8085 static int test_ast_build(isl_ctx
*ctx
)
8088 isl_ast_build
*build
;
8091 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8092 build
= isl_ast_build_from_context(set
);
8094 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
8095 expr
= isl_ast_build_expr_from_set(build
, set
);
8097 isl_ast_expr_free(expr
);
8098 isl_ast_build_free(build
);
8106 /* Internal data structure for before_for and after_for callbacks.
8108 * depth is the current depth
8109 * before is the number of times before_for has been called
8110 * after is the number of times after_for has been called
8112 struct isl_test_codegen_data
{
8118 /* This function is called before each for loop in the AST generated
8119 * from test_ast_gen1.
8121 * Increment the number of calls and the depth.
8122 * Check that the space returned by isl_ast_build_get_schedule_space
8123 * matches the target space of the schedule returned by
8124 * isl_ast_build_get_schedule.
8125 * Return an isl_id that is checked by the corresponding call
8128 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
8131 struct isl_test_codegen_data
*data
= user
;
8134 isl_union_map
*schedule
;
8135 isl_union_set
*uset
;
8140 ctx
= isl_ast_build_get_ctx(build
);
8142 if (data
->before
>= 3)
8143 isl_die(ctx
, isl_error_unknown
,
8144 "unexpected number of for nodes", return NULL
);
8145 if (data
->depth
>= 2)
8146 isl_die(ctx
, isl_error_unknown
,
8147 "unexpected depth", return NULL
);
8149 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
8153 schedule
= isl_ast_build_get_schedule(build
);
8154 uset
= isl_union_map_range(schedule
);
8157 if (isl_union_set_n_set(uset
) != 1) {
8158 isl_union_set_free(uset
);
8159 isl_die(ctx
, isl_error_unknown
,
8160 "expecting single range space", return NULL
);
8163 space
= isl_ast_build_get_schedule_space(build
);
8164 set
= isl_union_set_extract_set(uset
, space
);
8165 isl_union_set_free(uset
);
8166 empty
= isl_set_is_empty(set
);
8172 isl_die(ctx
, isl_error_unknown
,
8173 "spaces don't match", return NULL
);
8175 return isl_id_alloc(ctx
, name
, NULL
);
8178 /* This function is called after each for loop in the AST generated
8179 * from test_ast_gen1.
8181 * Increment the number of calls and decrement the depth.
8182 * Check that the annotation attached to the node matches
8183 * the isl_id returned by the corresponding call to before_for.
8185 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
8186 __isl_keep isl_ast_build
*build
, void *user
)
8188 struct isl_test_codegen_data
*data
= user
;
8196 if (data
->after
> data
->before
)
8197 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8198 "mismatch in number of for nodes",
8199 return isl_ast_node_free(node
));
8201 id
= isl_ast_node_get_annotation(node
);
8203 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8204 "missing annotation", return isl_ast_node_free(node
));
8206 name
= isl_id_get_name(id
);
8207 valid
= name
&& atoi(name
+ 1) == data
->depth
;
8211 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8212 "wrong annotation", return isl_ast_node_free(node
));
8217 /* Check that the before_each_for and after_each_for callbacks
8218 * are called for each for loop in the generated code,
8219 * that they are called in the right order and that the isl_id
8220 * returned from the before_each_for callback is attached to
8221 * the isl_ast_node passed to the corresponding after_each_for call.
8223 static int test_ast_gen1(isl_ctx
*ctx
)
8227 isl_union_map
*schedule
;
8228 isl_ast_build
*build
;
8230 struct isl_test_codegen_data data
;
8232 str
= "[N] -> { : N >= 10 }";
8233 set
= isl_set_read_from_str(ctx
, str
);
8234 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
8235 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
8236 schedule
= isl_union_map_read_from_str(ctx
, str
);
8241 build
= isl_ast_build_from_context(set
);
8242 build
= isl_ast_build_set_before_each_for(build
,
8243 &before_for
, &data
);
8244 build
= isl_ast_build_set_after_each_for(build
,
8246 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8247 isl_ast_build_free(build
);
8251 isl_ast_node_free(tree
);
8253 if (data
.before
!= 3 || data
.after
!= 3)
8254 isl_die(ctx
, isl_error_unknown
,
8255 "unexpected number of for nodes", return -1);
8260 /* Check that the AST generator handles domains that are integrally disjoint
8261 * but not rationally disjoint.
8263 static int test_ast_gen2(isl_ctx
*ctx
)
8267 isl_union_map
*schedule
;
8268 isl_union_map
*options
;
8269 isl_ast_build
*build
;
8272 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
8273 schedule
= isl_union_map_read_from_str(ctx
, str
);
8274 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8275 build
= isl_ast_build_from_context(set
);
8277 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
8278 options
= isl_union_map_read_from_str(ctx
, str
);
8279 build
= isl_ast_build_set_options(build
, options
);
8280 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8281 isl_ast_build_free(build
);
8284 isl_ast_node_free(tree
);
8289 /* Increment *user on each call.
8291 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
8292 __isl_keep isl_ast_build
*build
, void *user
)
8301 /* Test that unrolling tries to minimize the number of instances.
8302 * In particular, for the schedule given below, make sure it generates
8303 * 3 nodes (rather than 101).
8305 static int test_ast_gen3(isl_ctx
*ctx
)
8309 isl_union_map
*schedule
;
8310 isl_union_map
*options
;
8311 isl_ast_build
*build
;
8315 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
8316 schedule
= isl_union_map_read_from_str(ctx
, str
);
8317 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8319 str
= "{ [i] -> unroll[0] }";
8320 options
= isl_union_map_read_from_str(ctx
, str
);
8322 build
= isl_ast_build_from_context(set
);
8323 build
= isl_ast_build_set_options(build
, options
);
8324 build
= isl_ast_build_set_at_each_domain(build
,
8325 &count_domains
, &n_domain
);
8326 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8327 isl_ast_build_free(build
);
8331 isl_ast_node_free(tree
);
8334 isl_die(ctx
, isl_error_unknown
,
8335 "unexpected number of for nodes", return -1);
8340 /* Check that if the ast_build_exploit_nested_bounds options is set,
8341 * we do not get an outer if node in the generated AST,
8342 * while we do get such an outer if node if the options is not set.
8344 static int test_ast_gen4(isl_ctx
*ctx
)
8348 isl_union_map
*schedule
;
8349 isl_ast_build
*build
;
8351 enum isl_ast_node_type type
;
8354 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
8355 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
8357 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
8359 schedule
= isl_union_map_read_from_str(ctx
, str
);
8360 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8361 build
= isl_ast_build_from_context(set
);
8362 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8363 isl_ast_build_free(build
);
8367 type
= isl_ast_node_get_type(tree
);
8368 isl_ast_node_free(tree
);
8370 if (type
== isl_ast_node_if
)
8371 isl_die(ctx
, isl_error_unknown
,
8372 "not expecting if node", return -1);
8374 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
8376 schedule
= isl_union_map_read_from_str(ctx
, str
);
8377 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8378 build
= isl_ast_build_from_context(set
);
8379 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8380 isl_ast_build_free(build
);
8384 type
= isl_ast_node_get_type(tree
);
8385 isl_ast_node_free(tree
);
8387 if (type
!= isl_ast_node_if
)
8388 isl_die(ctx
, isl_error_unknown
,
8389 "expecting if node", return -1);
8391 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
8396 /* This function is called for each leaf in the AST generated
8397 * from test_ast_gen5.
8399 * We finalize the AST generation by extending the outer schedule
8400 * with a zero-dimensional schedule. If this results in any for loops,
8401 * then this means that we did not pass along enough information
8402 * about the outer schedule to the inner AST generation.
8404 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
8407 isl_union_map
*schedule
, *extra
;
8410 schedule
= isl_ast_build_get_schedule(build
);
8411 extra
= isl_union_map_copy(schedule
);
8412 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
8413 schedule
= isl_union_map_range_product(schedule
, extra
);
8414 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8415 isl_ast_build_free(build
);
8420 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
8421 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
8422 "code should not contain any for loop",
8423 return isl_ast_node_free(tree
));
8428 /* Check that we do not lose any information when going back and
8429 * forth between internal and external schedule.
8431 * In particular, we create an AST where we unroll the only
8432 * non-constant dimension in the schedule. We therefore do
8433 * not expect any for loops in the AST. However, older versions
8434 * of isl would not pass along enough information about the outer
8435 * schedule when performing an inner code generation from a create_leaf
8436 * callback, resulting in the inner code generation producing a for loop.
8438 static int test_ast_gen5(isl_ctx
*ctx
)
8442 isl_union_map
*schedule
, *options
;
8443 isl_ast_build
*build
;
8446 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
8447 schedule
= isl_union_map_read_from_str(ctx
, str
);
8449 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
8450 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
8451 options
= isl_union_map_read_from_str(ctx
, str
);
8453 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8454 build
= isl_ast_build_from_context(set
);
8455 build
= isl_ast_build_set_options(build
, options
);
8456 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
8457 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8458 isl_ast_build_free(build
);
8459 isl_ast_node_free(tree
);
8466 /* Check that the expression
8468 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
8470 * is not combined into
8474 * as this would result in n/2 being evaluated in parts of
8475 * the definition domain where n is not a multiple of 2.
8477 static int test_ast_expr(isl_ctx
*ctx
)
8481 isl_ast_build
*build
;
8486 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
8487 isl_options_set_ast_build_detect_min_max(ctx
, 1);
8489 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
8490 pa
= isl_pw_aff_read_from_str(ctx
, str
);
8491 build
= isl_ast_build_alloc(ctx
);
8492 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
8493 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
8494 isl_ast_expr_get_op_type(expr
) == isl_ast_op_min
;
8495 isl_ast_build_free(build
);
8496 isl_ast_expr_free(expr
);
8498 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
8503 isl_die(ctx
, isl_error_unknown
,
8504 "expressions should not be combined", return -1);
8509 static int test_ast_gen(isl_ctx
*ctx
)
8511 if (test_ast_gen1(ctx
) < 0)
8513 if (test_ast_gen2(ctx
) < 0)
8515 if (test_ast_gen3(ctx
) < 0)
8517 if (test_ast_gen4(ctx
) < 0)
8519 if (test_ast_gen5(ctx
) < 0)
8521 if (test_ast_expr(ctx
) < 0)
8526 /* Check if dropping output dimensions from an isl_pw_multi_aff
8529 static int test_pw_multi_aff(isl_ctx
*ctx
)
8532 isl_pw_multi_aff
*pma1
, *pma2
;
8535 str
= "{ [i,j] -> [i+j, 4i-j] }";
8536 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8537 str
= "{ [i,j] -> [4i-j] }";
8538 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8540 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
8542 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
8544 isl_pw_multi_aff_free(pma1
);
8545 isl_pw_multi_aff_free(pma2
);
8549 isl_die(ctx
, isl_error_unknown
,
8550 "expressions not equal", return -1);
8555 /* Check that we can properly parse multi piecewise affine expressions
8556 * where the piecewise affine expressions have different domains.
8558 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
8561 isl_set
*dom
, *dom2
;
8562 isl_multi_pw_aff
*mpa1
, *mpa2
;
8567 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
8568 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
8569 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
8570 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
8571 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
8572 str
= "{ [i] -> [(i : i > 0), 2i] }";
8573 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8575 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
8577 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
8578 dom
= isl_pw_aff_domain(pa
);
8579 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
8580 dom2
= isl_pw_aff_domain(pa
);
8581 equal_domain
= isl_set_is_equal(dom
, dom2
);
8585 isl_multi_pw_aff_free(mpa1
);
8586 isl_multi_pw_aff_free(mpa2
);
8591 isl_die(ctx
, isl_error_unknown
,
8592 "expressions not equal", return -1);
8594 if (equal_domain
< 0)
8597 isl_die(ctx
, isl_error_unknown
,
8598 "domains unexpectedly equal", return -1);
8603 /* Check that the dimensions in the explicit domain
8604 * of a multi piecewise affine expression are properly
8605 * taken into account.
8607 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
8610 isl_bool involves1
, involves2
, involves3
, equal
;
8611 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
8613 str
= "{ A[x,y] -> B[] : x >= y }";
8614 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8615 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
8616 mpa1
= isl_multi_pw_aff_copy(mpa
);
8618 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
8619 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
8620 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
8621 str
= "{ [a,x,y] -> B[] : x >= y }";
8622 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8623 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
8624 isl_multi_pw_aff_free(mpa2
);
8626 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
8627 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
8628 if (equal
>= 0 && equal
)
8629 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
8630 isl_multi_pw_aff_free(mpa1
);
8631 isl_multi_pw_aff_free(mpa
);
8633 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
8636 isl_die(ctx
, isl_error_unknown
,
8637 "incorrect result of dimension insertion/removal",
8638 return isl_stat_error
);
8639 if (!involves1
|| involves2
|| !involves3
)
8640 isl_die(ctx
, isl_error_unknown
,
8641 "incorrect characterization of involved dimensions",
8642 return isl_stat_error
);
8647 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
8648 * sets the explicit domain of a zero-dimensional result,
8649 * such that it can be converted to an isl_union_map.
8651 static isl_stat
test_multi_pw_aff_3(isl_ctx
*ctx
)
8656 isl_multi_union_pw_aff
*mupa
;
8657 isl_union_map
*umap
;
8659 dom
= isl_union_set_read_from_str(ctx
, "{ A[]; B[] }");
8660 space
= isl_union_set_get_space(dom
);
8661 mv
= isl_multi_val_zero(isl_space_set_from_params(space
));
8662 mupa
= isl_multi_union_pw_aff_multi_val_on_domain(dom
, mv
);
8663 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
8664 isl_union_map_free(umap
);
8666 return isl_stat_error
;
8671 /* Perform some tests on multi piecewise affine expressions.
8673 static int test_multi_pw_aff(isl_ctx
*ctx
)
8675 if (test_multi_pw_aff_1(ctx
) < 0)
8677 if (test_multi_pw_aff_2(ctx
) < 0)
8679 if (test_multi_pw_aff_3(ctx
) < 0)
8684 /* This is a regression test for a bug where isl_basic_map_simplify
8685 * would end up in an infinite loop. In particular, we construct
8686 * an empty basic set that is not obviously empty.
8687 * isl_basic_set_is_empty marks the basic set as empty.
8688 * After projecting out i3, the variable can be dropped completely,
8689 * but isl_basic_map_simplify refrains from doing so if the basic set
8690 * is empty and would end up in an infinite loop if it didn't test
8691 * explicitly for empty basic maps in the outer loop.
8693 static int test_simplify_1(isl_ctx
*ctx
)
8696 isl_basic_set
*bset
;
8699 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
8700 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
8701 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
8703 bset
= isl_basic_set_read_from_str(ctx
, str
);
8704 empty
= isl_basic_set_is_empty(bset
);
8705 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
8706 isl_basic_set_free(bset
);
8710 isl_die(ctx
, isl_error_unknown
,
8711 "basic set should be empty", return -1);
8716 /* Check that the equality in the set description below
8717 * is simplified away.
8719 static int test_simplify_2(isl_ctx
*ctx
)
8722 isl_basic_set
*bset
;
8725 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
8726 bset
= isl_basic_set_read_from_str(ctx
, str
);
8727 universe
= isl_basic_set_plain_is_universe(bset
);
8728 isl_basic_set_free(bset
);
8733 isl_die(ctx
, isl_error_unknown
,
8734 "equality not simplified away", return -1);
8738 /* Some simplification tests.
8740 static int test_simplify(isl_ctx
*ctx
)
8742 if (test_simplify_1(ctx
) < 0)
8744 if (test_simplify_2(ctx
) < 0)
8749 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
8750 * with gbr context would fail to disable the use of the shifted tableau
8751 * when transferring equalities for the input to the context, resulting
8752 * in invalid sample values.
8754 static int test_partial_lexmin(isl_ctx
*ctx
)
8757 isl_basic_set
*bset
;
8758 isl_basic_map
*bmap
;
8761 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
8762 bmap
= isl_basic_map_read_from_str(ctx
, str
);
8763 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
8764 bset
= isl_basic_set_read_from_str(ctx
, str
);
8765 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
8774 /* Check that the variable compression performed on the existentially
8775 * quantified variables inside isl_basic_set_compute_divs is not confused
8776 * by the implicit equalities among the parameters.
8778 static int test_compute_divs(isl_ctx
*ctx
)
8781 isl_basic_set
*bset
;
8784 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
8785 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
8786 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
8787 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
8788 bset
= isl_basic_set_read_from_str(ctx
, str
);
8789 set
= isl_basic_set_compute_divs(bset
);
8797 /* Check that isl_schedule_get_map is not confused by a schedule tree
8798 * with divergent filter node parameters, as can result from a call
8799 * to isl_schedule_intersect_domain.
8801 static int test_schedule_tree(isl_ctx
*ctx
)
8804 isl_union_set
*uset
;
8805 isl_schedule
*sched1
, *sched2
;
8806 isl_union_map
*umap
;
8808 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
8809 sched1
= isl_schedule_from_domain(uset
);
8810 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
8811 sched2
= isl_schedule_from_domain(uset
);
8813 sched1
= isl_schedule_sequence(sched1
, sched2
);
8814 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
8815 uset
= isl_union_set_read_from_str(ctx
, str
);
8816 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
8817 umap
= isl_schedule_get_map(sched1
);
8818 isl_schedule_free(sched1
);
8819 isl_union_map_free(umap
);
8826 /* Check that a zero-dimensional prefix schedule keeps track
8827 * of the domain and outer filters.
8829 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
8833 isl_union_set
*uset
;
8834 isl_union_set_list
*filters
;
8835 isl_multi_union_pw_aff
*mupa
, *mupa2
;
8836 isl_schedule_node
*node
;
8838 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8839 uset
= isl_union_set_read_from_str(ctx
, str
);
8840 node
= isl_schedule_node_from_domain(uset
);
8841 node
= isl_schedule_node_child(node
, 0);
8843 str
= "{ S1[i,j] : i > j }";
8844 uset
= isl_union_set_read_from_str(ctx
, str
);
8845 filters
= isl_union_set_list_from_union_set(uset
);
8846 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
8847 uset
= isl_union_set_read_from_str(ctx
, str
);
8848 filters
= isl_union_set_list_add(filters
, uset
);
8849 node
= isl_schedule_node_insert_sequence(node
, filters
);
8851 node
= isl_schedule_node_child(node
, 0);
8852 node
= isl_schedule_node_child(node
, 0);
8853 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
8854 str
= "([] : { S1[i,j] : i > j })";
8855 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8856 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
8857 isl_multi_union_pw_aff_free(mupa2
);
8858 isl_multi_union_pw_aff_free(mupa
);
8859 isl_schedule_node_free(node
);
8864 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
8870 /* Check that the reaching domain elements and the prefix schedule
8871 * at a leaf node are the same before and after grouping.
8873 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
8878 isl_union_set
*uset
;
8879 isl_multi_union_pw_aff
*mupa
;
8880 isl_union_pw_multi_aff
*upma1
, *upma2
;
8881 isl_union_set
*domain1
, *domain2
;
8882 isl_union_map
*umap1
, *umap2
;
8883 isl_schedule_node
*node
;
8885 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8886 uset
= isl_union_set_read_from_str(ctx
, str
);
8887 node
= isl_schedule_node_from_domain(uset
);
8888 node
= isl_schedule_node_child(node
, 0);
8889 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
8890 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8891 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8892 node
= isl_schedule_node_child(node
, 0);
8893 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
8894 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8895 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8896 node
= isl_schedule_node_child(node
, 0);
8897 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
8898 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
8899 domain1
= isl_schedule_node_get_domain(node
);
8900 id
= isl_id_alloc(ctx
, "group", NULL
);
8901 node
= isl_schedule_node_parent(node
);
8902 node
= isl_schedule_node_group(node
, id
);
8903 node
= isl_schedule_node_child(node
, 0);
8904 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
8905 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
8906 domain2
= isl_schedule_node_get_domain(node
);
8907 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
8908 if (equal
>= 0 && equal
)
8909 equal
= isl_union_set_is_equal(domain1
, domain2
);
8910 if (equal
>= 0 && equal
)
8911 equal
= isl_union_map_is_equal(umap1
, umap2
);
8912 isl_union_map_free(umap1
);
8913 isl_union_map_free(umap2
);
8914 isl_union_set_free(domain1
);
8915 isl_union_set_free(domain2
);
8916 isl_union_pw_multi_aff_free(upma1
);
8917 isl_union_pw_multi_aff_free(upma2
);
8918 isl_schedule_node_free(node
);
8923 isl_die(ctx
, isl_error_unknown
,
8924 "expressions not equal", return -1);
8929 /* Check that we can have nested groupings and that the union map
8930 * schedule representation is the same before and after the grouping.
8931 * Note that after the grouping, the union map representation contains
8932 * the domain constraints from the ranges of the expansion nodes,
8933 * while they are missing from the union map representation of
8934 * the tree without expansion nodes.
8936 * Also check that the global expansion is as expected.
8938 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
8940 int equal
, equal_expansion
;
8943 isl_union_set
*uset
;
8944 isl_union_map
*umap1
, *umap2
;
8945 isl_union_map
*expansion1
, *expansion2
;
8946 isl_union_set_list
*filters
;
8947 isl_multi_union_pw_aff
*mupa
;
8948 isl_schedule
*schedule
;
8949 isl_schedule_node
*node
;
8951 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
8952 "S3[i,j] : 0 <= i,j < 10 }";
8953 uset
= isl_union_set_read_from_str(ctx
, str
);
8954 node
= isl_schedule_node_from_domain(uset
);
8955 node
= isl_schedule_node_child(node
, 0);
8956 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
8957 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8958 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8959 node
= isl_schedule_node_child(node
, 0);
8960 str
= "{ S1[i,j] }";
8961 uset
= isl_union_set_read_from_str(ctx
, str
);
8962 filters
= isl_union_set_list_from_union_set(uset
);
8963 str
= "{ S2[i,j]; S3[i,j] }";
8964 uset
= isl_union_set_read_from_str(ctx
, str
);
8965 filters
= isl_union_set_list_add(filters
, uset
);
8966 node
= isl_schedule_node_insert_sequence(node
, filters
);
8967 node
= isl_schedule_node_child(node
, 1);
8968 node
= isl_schedule_node_child(node
, 0);
8969 str
= "{ S2[i,j] }";
8970 uset
= isl_union_set_read_from_str(ctx
, str
);
8971 filters
= isl_union_set_list_from_union_set(uset
);
8972 str
= "{ S3[i,j] }";
8973 uset
= isl_union_set_read_from_str(ctx
, str
);
8974 filters
= isl_union_set_list_add(filters
, uset
);
8975 node
= isl_schedule_node_insert_sequence(node
, filters
);
8977 schedule
= isl_schedule_node_get_schedule(node
);
8978 umap1
= isl_schedule_get_map(schedule
);
8979 uset
= isl_schedule_get_domain(schedule
);
8980 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
8981 isl_schedule_free(schedule
);
8983 node
= isl_schedule_node_parent(node
);
8984 node
= isl_schedule_node_parent(node
);
8985 id
= isl_id_alloc(ctx
, "group1", NULL
);
8986 node
= isl_schedule_node_group(node
, id
);
8987 node
= isl_schedule_node_child(node
, 1);
8988 node
= isl_schedule_node_child(node
, 0);
8989 id
= isl_id_alloc(ctx
, "group2", NULL
);
8990 node
= isl_schedule_node_group(node
, id
);
8992 schedule
= isl_schedule_node_get_schedule(node
);
8993 umap2
= isl_schedule_get_map(schedule
);
8994 isl_schedule_free(schedule
);
8996 node
= isl_schedule_node_root(node
);
8997 node
= isl_schedule_node_child(node
, 0);
8998 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
8999 isl_schedule_node_free(node
);
9001 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
9002 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
9003 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
9005 expansion2
= isl_union_map_read_from_str(ctx
, str
);
9007 equal
= isl_union_map_is_equal(umap1
, umap2
);
9008 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
9010 isl_union_map_free(umap1
);
9011 isl_union_map_free(umap2
);
9012 isl_union_map_free(expansion1
);
9013 isl_union_map_free(expansion2
);
9015 if (equal
< 0 || equal_expansion
< 0)
9018 isl_die(ctx
, isl_error_unknown
,
9019 "expressions not equal", return -1);
9020 if (!equal_expansion
)
9021 isl_die(ctx
, isl_error_unknown
,
9022 "unexpected expansion", return -1);
9027 /* Some tests for the isl_schedule_node_group function.
9029 static int test_schedule_tree_group(isl_ctx
*ctx
)
9031 if (test_schedule_tree_group_1(ctx
) < 0)
9033 if (test_schedule_tree_group_2(ctx
) < 0)
9042 { "{ rat: [i] : 0 <= i <= 10 }",
9043 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
9044 { "{ rat: [i] : FALSE }",
9045 "{ rat: coefficients[[cst] -> [a]] }" },
9047 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
9054 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
9055 "{ rat: [i] : 0 <= i <= 10 }" },
9056 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
9058 { "{ rat: coefficients[[cst] -> [a]] }",
9059 "{ rat: [i] : FALSE }" },
9062 /* Test the basic functionality of isl_basic_set_coefficients and
9063 * isl_basic_set_solutions.
9065 static int test_dual(isl_ctx
*ctx
)
9069 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
9071 isl_basic_set
*bset1
, *bset2
;
9073 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
9074 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
9075 bset1
= isl_basic_set_coefficients(bset1
);
9076 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9077 isl_basic_set_free(bset1
);
9078 isl_basic_set_free(bset2
);
9082 isl_die(ctx
, isl_error_unknown
,
9083 "incorrect dual", return -1);
9086 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
9088 isl_basic_set
*bset1
, *bset2
;
9090 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
9091 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
9092 bset1
= isl_basic_set_solutions(bset1
);
9093 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9094 isl_basic_set_free(bset1
);
9095 isl_basic_set_free(bset2
);
9099 isl_die(ctx
, isl_error_unknown
,
9100 "incorrect dual", return -1);
9110 const char *schedule
;
9115 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
9116 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9118 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
9119 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9121 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
9122 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9124 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
9125 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9127 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
9128 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9130 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
9131 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
9133 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
9134 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9136 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
9137 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
9141 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
9142 * tile the band and then check if the tile and point bands have the
9143 * expected partial schedule.
9145 static int test_tile(isl_ctx
*ctx
)
9151 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
9152 shift
= isl_options_get_tile_shift_point_loops(ctx
);
9154 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
9158 isl_union_set
*domain
;
9159 isl_multi_union_pw_aff
*mupa
, *mupa2
;
9160 isl_schedule_node
*node
;
9161 isl_multi_val
*sizes
;
9163 opt
= tile_tests
[i
].scale_tile
;
9164 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
9165 opt
= tile_tests
[i
].shift_point
;
9166 isl_options_set_tile_shift_point_loops(ctx
, opt
);
9168 str
= tile_tests
[i
].domain
;
9169 domain
= isl_union_set_read_from_str(ctx
, str
);
9170 node
= isl_schedule_node_from_domain(domain
);
9171 node
= isl_schedule_node_child(node
, 0);
9172 str
= tile_tests
[i
].schedule
;
9173 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9174 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
9175 str
= tile_tests
[i
].sizes
;
9176 sizes
= isl_multi_val_read_from_str(ctx
, str
);
9177 node
= isl_schedule_node_band_tile(node
, sizes
);
9179 str
= tile_tests
[i
].tile
;
9180 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9181 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
9182 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
9183 isl_multi_union_pw_aff_free(mupa
);
9184 isl_multi_union_pw_aff_free(mupa2
);
9186 node
= isl_schedule_node_child(node
, 0);
9188 str
= tile_tests
[i
].point
;
9189 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9190 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
9191 if (equal
>= 0 && equal
)
9192 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
9194 isl_multi_union_pw_aff_free(mupa
);
9195 isl_multi_union_pw_aff_free(mupa2
);
9197 isl_schedule_node_free(node
);
9202 isl_die(ctx
, isl_error_unknown
,
9203 "unexpected result", return -1);
9206 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
9207 isl_options_set_tile_shift_point_loops(ctx
, shift
);
9212 /* Check that the domain hash of a space is equal to the hash
9213 * of the domain of the space.
9215 static int test_domain_hash(isl_ctx
*ctx
)
9219 uint32_t hash1
, hash2
;
9221 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
9222 space
= isl_map_get_space(map
);
9224 hash1
= isl_space_get_domain_hash(space
);
9225 space
= isl_space_domain(space
);
9226 hash2
= isl_space_get_hash(space
);
9227 isl_space_free(space
);
9232 isl_die(ctx
, isl_error_unknown
,
9233 "domain hash not equal to hash of domain", return -1);
9238 /* Check that a universe basic set that is not obviously equal to the universe
9239 * is still recognized as being equal to the universe.
9241 static int test_universe(isl_ctx
*ctx
)
9244 isl_basic_set
*bset
;
9247 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
9248 bset
= isl_basic_set_read_from_str(ctx
, s
);
9249 is_univ
= isl_basic_set_is_universe(bset
);
9250 isl_basic_set_free(bset
);
9255 isl_die(ctx
, isl_error_unknown
,
9256 "not recognized as universe set", return -1);
9261 /* Sets for which chambers are computed and checked.
9263 const char *chambers_tests
[] = {
9264 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
9265 "z >= 0 and z <= C - y and z <= B - x - y }",
9268 /* Add the domain of "cell" to "cells".
9270 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
9272 isl_basic_set_list
**cells
= user
;
9275 dom
= isl_cell_get_domain(cell
);
9276 isl_cell_free(cell
);
9277 *cells
= isl_basic_set_list_add(*cells
, dom
);
9279 return *cells
? isl_stat_ok
: isl_stat_error
;
9282 /* Check that the elements of "list" are pairwise disjoint.
9284 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
9289 return isl_stat_error
;
9291 n
= isl_basic_set_list_n_basic_set(list
);
9292 for (i
= 0; i
< n
; ++i
) {
9293 isl_basic_set
*bset_i
;
9295 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
9296 for (j
= i
+ 1; j
< n
; ++j
) {
9297 isl_basic_set
*bset_j
;
9300 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
9301 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
9302 isl_basic_set_free(bset_j
);
9304 isl_die(isl_basic_set_list_get_ctx(list
),
9305 isl_error_unknown
, "not disjoint",
9307 if (disjoint
< 0 || !disjoint
)
9310 isl_basic_set_free(bset_i
);
9312 return isl_stat_error
;
9318 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
9319 * are pairwise disjoint.
9321 static int test_chambers(isl_ctx
*ctx
)
9325 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
9326 isl_basic_set
*bset
;
9327 isl_vertices
*vertices
;
9328 isl_basic_set_list
*cells
;
9331 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
9332 vertices
= isl_basic_set_compute_vertices(bset
);
9333 cells
= isl_basic_set_list_alloc(ctx
, 0);
9334 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
9336 cells
= isl_basic_set_list_free(cells
);
9337 ok
= check_pairwise_disjoint(cells
);
9338 isl_basic_set_list_free(cells
);
9339 isl_vertices_free(vertices
);
9340 isl_basic_set_free(bset
);
9351 int (*fn
)(isl_ctx
*ctx
);
9353 { "universe", &test_universe
},
9354 { "domain hash", &test_domain_hash
},
9355 { "dual", &test_dual
},
9356 { "dependence analysis", &test_flow
},
9357 { "val", &test_val
},
9358 { "compute divs", &test_compute_divs
},
9359 { "partial lexmin", &test_partial_lexmin
},
9360 { "simplify", &test_simplify
},
9361 { "curry", &test_curry
},
9362 { "piecewise multi affine expressions", &test_pw_multi_aff
},
9363 { "multi piecewise affine expressions", &test_multi_pw_aff
},
9364 { "conversion", &test_conversion
},
9365 { "list", &test_list
},
9366 { "align parameters", &test_align_parameters
},
9367 { "drop unused parameters", &test_drop_unused_parameters
},
9368 { "preimage", &test_preimage
},
9369 { "pullback", &test_pullback
},
9370 { "AST", &test_ast
},
9371 { "AST build", &test_ast_build
},
9372 { "AST generation", &test_ast_gen
},
9373 { "eliminate", &test_eliminate
},
9374 { "residue class", &test_residue_class
},
9375 { "div", &test_div
},
9376 { "slice", &test_slice
},
9377 { "fixed power", &test_fixed_power
},
9378 { "sample", &test_sample
},
9379 { "output", &test_output
},
9380 { "vertices", &test_vertices
},
9381 { "chambers", &test_chambers
},
9382 { "fixed", &test_fixed
},
9383 { "equal", &test_equal
},
9384 { "disjoint", &test_disjoint
},
9385 { "product", &test_product
},
9386 { "dim_max", &test_dim_max
},
9387 { "affine", &test_aff
},
9388 { "injective", &test_injective
},
9389 { "schedule (whole component)", &test_schedule_whole
},
9390 { "schedule (incremental)", &test_schedule_incremental
},
9391 { "schedule tree", &test_schedule_tree
},
9392 { "schedule tree prefix", &test_schedule_tree_prefix
},
9393 { "schedule tree grouping", &test_schedule_tree_group
},
9394 { "tile", &test_tile
},
9395 { "union_pw", &test_union_pw
},
9396 { "locus", &test_locus
},
9397 { "eval", &test_eval
},
9398 { "parse", &test_parse
},
9399 { "single-valued", &test_sv
},
9400 { "affine hull", &test_affine_hull
},
9401 { "simple_hull", &test_simple_hull
},
9402 { "coalesce", &test_coalesce
},
9403 { "factorize", &test_factorize
},
9404 { "subset", &test_subset
},
9405 { "subtract", &test_subtract
},
9406 { "intersect", &test_intersect
},
9407 { "lexmin", &test_lexmin
},
9408 { "min", &test_min
},
9409 { "gist", &test_gist
},
9410 { "piecewise quasi-polynomials", &test_pwqp
},
9411 { "lift", &test_lift
},
9412 { "bound", &test_bound
},
9413 { "get lists", &test_get_list
},
9414 { "union", &test_union
},
9415 { "split periods", &test_split_periods
},
9416 { "lexicographic order", &test_lex
},
9417 { "bijectivity", &test_bijective
},
9418 { "dataflow analysis", &test_dep
},
9419 { "reading", &test_read
},
9420 { "bounded", &test_bounded
},
9421 { "construction", &test_construction
},
9422 { "dimension manipulation", &test_dim
},
9423 { "map application", &test_application
},
9424 { "convex hull", &test_convex_hull
},
9425 { "transitive closure", &test_closure
},
9428 int main(int argc
, char **argv
)
9431 struct isl_ctx
*ctx
;
9432 struct isl_options
*options
;
9434 options
= isl_options_new_with_defaults();
9436 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
9438 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
9439 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
9440 printf("%s\n", tests
[i
].name
);
9441 if (tests
[i
].fn(ctx
) < 0)