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 /* Test the functionality of isl_set_coalesce.
2268 * That is, check that the output is always equal to the input
2269 * and in some cases that the result consists of a single disjunct.
2271 static int test_coalesce(struct isl_ctx
*ctx
)
2275 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2276 const char *str
= coalesce_tests
[i
].str
;
2277 int check_one
= coalesce_tests
[i
].single_disjunct
;
2278 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2282 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2284 if (test_coalesce_special(ctx
) < 0)
2286 if (test_coalesce_special2(ctx
) < 0)
2288 if (test_coalesce_special3(ctx
) < 0)
2294 /* Construct a representation of the graph on the right of Figure 1
2295 * in "Computing the Transitive Closure of a Union of
2296 * Affine Integer Tuple Relations".
2298 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2301 isl_map
*up
, *right
;
2303 dom
= isl_set_read_from_str(ctx
,
2304 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2305 "2 x - 3 y + 3 >= 0 }");
2306 right
= isl_map_read_from_str(ctx
,
2307 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2308 up
= isl_map_read_from_str(ctx
,
2309 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2310 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2311 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2312 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2313 up
= isl_map_intersect_range(up
, dom
);
2314 return isl_map_union(up
, right
);
2317 /* Construct a representation of the power of the graph
2318 * on the right of Figure 1 in "Computing the Transitive Closure of
2319 * a Union of Affine Integer Tuple Relations".
2321 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2323 return isl_map_read_from_str(ctx
,
2324 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2325 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2326 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2329 /* Construct a representation of the transitive closure of the graph
2330 * on the right of Figure 1 in "Computing the Transitive Closure of
2331 * a Union of Affine Integer Tuple Relations".
2333 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2335 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2338 static int test_closure(isl_ctx
*ctx
)
2341 isl_map
*map
, *map2
;
2344 /* COCOA example 1 */
2345 map
= isl_map_read_from_str(ctx
,
2346 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2347 "1 <= i and i < n and 1 <= j and j < n or "
2348 "i2 = i + 1 and j2 = j - 1 and "
2349 "1 <= i and i < n and 2 <= j and j <= n }");
2350 map
= isl_map_power(map
, &exact
);
2354 /* COCOA example 1 */
2355 map
= isl_map_read_from_str(ctx
,
2356 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2357 "1 <= i and i < n and 1 <= j and j < n or "
2358 "i2 = i + 1 and j2 = j - 1 and "
2359 "1 <= i and i < n and 2 <= j and j <= n }");
2360 map
= isl_map_transitive_closure(map
, &exact
);
2362 map2
= isl_map_read_from_str(ctx
,
2363 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2364 "1 <= i and i < n and 1 <= j and j <= n and "
2365 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2366 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2367 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2368 assert(isl_map_is_equal(map
, map2
));
2372 map
= isl_map_read_from_str(ctx
,
2373 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2374 " 0 <= y and y <= n }");
2375 map
= isl_map_transitive_closure(map
, &exact
);
2376 map2
= isl_map_read_from_str(ctx
,
2377 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2378 " 0 <= y and y <= n }");
2379 assert(isl_map_is_equal(map
, map2
));
2383 /* COCOA example 2 */
2384 map
= isl_map_read_from_str(ctx
,
2385 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2386 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2387 "i2 = i + 2 and j2 = j - 2 and "
2388 "1 <= i and i < n - 1 and 3 <= 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 - 1 and 1 <= j and j <= n and "
2394 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2395 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2396 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2397 assert(isl_map_is_equal(map
, map2
));
2401 /* COCOA Fig.2 left */
2402 map
= isl_map_read_from_str(ctx
,
2403 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2404 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2406 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2407 "j <= 2 i - 3 and j <= n - 2 or "
2408 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2409 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2410 map
= isl_map_transitive_closure(map
, &exact
);
2414 /* COCOA Fig.2 right */
2415 map
= isl_map_read_from_str(ctx
,
2416 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2417 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2419 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2420 "j <= 2 i - 4 and j <= n - 3 or "
2421 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2422 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2423 map
= isl_map_power(map
, &exact
);
2427 /* COCOA Fig.2 right */
2428 map
= isl_map_read_from_str(ctx
,
2429 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2430 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2432 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2433 "j <= 2 i - 4 and j <= n - 3 or "
2434 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2435 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2436 map
= isl_map_transitive_closure(map
, &exact
);
2438 map2
= isl_map_read_from_str(ctx
,
2439 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2440 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2441 "j <= n and 3 + i + 2 j <= 3 n and "
2442 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2443 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2444 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2445 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2446 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2447 assert(isl_map_is_equal(map
, map2
));
2451 map
= cocoa_fig_1_right_graph(ctx
);
2452 map
= isl_map_transitive_closure(map
, &exact
);
2454 map2
= cocoa_fig_1_right_tc(ctx
);
2455 assert(isl_map_is_equal(map
, map2
));
2459 map
= cocoa_fig_1_right_graph(ctx
);
2460 map
= isl_map_power(map
, &exact
);
2461 map2
= cocoa_fig_1_right_power(ctx
);
2462 equal
= isl_map_is_equal(map
, map2
);
2468 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2470 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2472 /* COCOA Theorem 1 counter example */
2473 map
= isl_map_read_from_str(ctx
,
2474 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2475 "i2 = 1 and j2 = j or "
2476 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2477 map
= isl_map_transitive_closure(map
, &exact
);
2481 map
= isl_map_read_from_str(ctx
,
2482 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2483 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2484 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2485 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2486 map
= isl_map_transitive_closure(map
, &exact
);
2490 /* Kelly et al 1996, fig 12 */
2491 map
= isl_map_read_from_str(ctx
,
2492 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2493 "1 <= i,j,j+1 <= n or "
2494 "j = n and j2 = 1 and i2 = i + 1 and "
2495 "1 <= i,i+1 <= n }");
2496 map
= isl_map_transitive_closure(map
, &exact
);
2498 map2
= isl_map_read_from_str(ctx
,
2499 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2500 "1 <= i <= n and i = i2 or "
2501 "1 <= i < i2 <= n and 1 <= j <= n and "
2503 assert(isl_map_is_equal(map
, map2
));
2507 /* Omega's closure4 */
2508 map
= isl_map_read_from_str(ctx
,
2509 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2510 "1 <= x,y <= 10 or "
2511 "x2 = x + 1 and y2 = y and "
2512 "1 <= x <= 20 && 5 <= y <= 15 }");
2513 map
= isl_map_transitive_closure(map
, &exact
);
2517 map
= isl_map_read_from_str(ctx
,
2518 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2519 map
= isl_map_transitive_closure(map
, &exact
);
2521 map2
= isl_map_read_from_str(ctx
,
2522 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2523 assert(isl_map_is_equal(map
, map2
));
2527 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2528 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2529 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2530 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2531 map
= isl_map_read_from_str(ctx
, str
);
2532 map
= isl_map_transitive_closure(map
, &exact
);
2534 map2
= isl_map_read_from_str(ctx
, str
);
2535 assert(isl_map_is_equal(map
, map2
));
2539 str
= "{[0] -> [1]; [2] -> [3]}";
2540 map
= isl_map_read_from_str(ctx
, str
);
2541 map
= isl_map_transitive_closure(map
, &exact
);
2543 map2
= isl_map_read_from_str(ctx
, str
);
2544 assert(isl_map_is_equal(map
, map2
));
2548 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2549 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2550 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2551 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2552 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2553 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2554 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2555 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2556 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2557 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2558 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2559 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2560 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2561 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2562 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2563 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2564 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2565 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2566 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2567 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2568 map
= isl_map_read_from_str(ctx
, str
);
2569 map
= isl_map_transitive_closure(map
, NULL
);
2576 static int test_lex(struct isl_ctx
*ctx
)
2582 dim
= isl_space_set_alloc(ctx
, 0, 0);
2583 map
= isl_map_lex_le(dim
);
2584 empty
= isl_map_is_empty(map
);
2590 isl_die(ctx
, isl_error_unknown
,
2591 "expecting non-empty result", return -1);
2596 /* Inputs for isl_map_lexmin tests.
2597 * "map" is the input and "lexmin" is the expected result.
2602 } lexmin_tests
[] = {
2603 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2604 "{ [x] -> [5] : 6 <= x <= 8; "
2605 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2606 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2607 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2608 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2609 "{ [x] -> [y] : (4y = x and x >= 0) or "
2610 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2611 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2612 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2613 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2614 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2615 /* Check that empty pieces are properly combined. */
2616 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2617 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2618 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2619 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2620 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2622 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2623 "a <= 255 and c <= 255 and d <= 255 - j and "
2624 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2625 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2626 "247d <= 247 + i and 248 - b <= 248d <= c and "
2627 "254d >= i - a + b and 254d >= -a + b and "
2628 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2630 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2631 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2632 "247j >= 62738 - i and 509j <= 129795 + i and "
2633 "742j >= 188724 - i; "
2634 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2635 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2636 "16*floor((8 + b)/16) <= 7 + b; "
2638 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2639 "[a] -> [b = 0] : 0 < a <= 509 }" },
2640 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2641 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2644 static int test_lexmin(struct isl_ctx
*ctx
)
2649 isl_basic_map
*bmap
;
2650 isl_map
*map
, *map2
;
2653 isl_pw_multi_aff
*pma
;
2655 str
= "[p0, p1] -> { [] -> [] : "
2656 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2657 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2658 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2659 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2660 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2661 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2662 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2663 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2664 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2665 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2666 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2667 map
= isl_map_read_from_str(ctx
, str
);
2668 map
= isl_map_lexmin(map
);
2671 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2672 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2673 set
= isl_set_read_from_str(ctx
, str
);
2674 set
= isl_set_lexmax(set
);
2675 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
2676 set2
= isl_set_read_from_str(ctx
, str
);
2677 set
= isl_set_intersect(set
, set2
);
2678 assert(!isl_set_is_empty(set
));
2681 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
2682 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
2683 map
= isl_map_lexmin(map
);
2684 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
2685 equal
= isl_map_is_equal(map
, map2
);
2692 isl_die(ctx
, isl_error_unknown
,
2693 "unexpected result", return -1);
2696 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2697 " 8i' <= i and 8i' >= -7 + i }";
2698 bmap
= isl_basic_map_read_from_str(ctx
, str
);
2699 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
2700 map2
= isl_map_from_pw_multi_aff(pma
);
2701 map
= isl_map_from_basic_map(bmap
);
2702 assert(isl_map_is_equal(map
, map2
));
2706 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2707 " 8i' <= i and 8i' >= -7 + i }";
2708 set
= isl_set_read_from_str(ctx
, str
);
2709 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
2710 set2
= isl_set_from_pw_multi_aff(pma
);
2711 equal
= isl_set_is_equal(set
, set2
);
2717 isl_die(ctx
, isl_error_unknown
,
2718 "unexpected difference between set and "
2719 "piecewise affine expression", return -1);
2724 /* A specialized isl_set_min_val test case that would return the wrong result
2725 * in earlier versions of isl.
2726 * The explicit call to isl_basic_set_union prevents the second basic set
2727 * from being determined to be empty prior to the call to isl_set_min_val,
2728 * at least at the point where this test case was introduced.
2730 static int test_min_special(isl_ctx
*ctx
)
2733 isl_basic_set
*bset1
, *bset2
;
2739 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
2740 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2741 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
2742 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2743 set
= isl_basic_set_union(bset1
, bset2
);
2744 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
2746 res
= isl_set_min_val(set
, obj
);
2747 ok
= isl_val_cmp_si(res
, 5) == 0;
2756 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
2762 /* A specialized isl_set_min_val test case that would return an error
2763 * in earlier versions of isl.
2765 static int test_min_special2(isl_ctx
*ctx
)
2768 isl_basic_set
*bset
;
2772 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
2773 bset
= isl_basic_set_read_from_str(ctx
, str
);
2775 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
2777 res
= isl_basic_set_max_val(bset
, obj
);
2779 isl_basic_set_free(bset
);
2792 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
2793 __isl_keep isl_aff
*obj
);
2796 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
2797 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
2798 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
2799 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
2800 &isl_set_max_val
, "30" },
2804 /* Perform basic isl_set_min_val and isl_set_max_val tests.
2805 * In particular, check the results on non-convex inputs.
2807 static int test_min(struct isl_ctx
*ctx
)
2815 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
2816 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
2817 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
2818 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
2819 val
= opt_tests
[i
].fn(set
, obj
);
2820 ok
= isl_val_eq(res
, val
);
2829 isl_die(ctx
, isl_error_unknown
,
2830 "unexpected optimum", return -1);
2833 if (test_min_special(ctx
) < 0)
2835 if (test_min_special2(ctx
) < 0)
2846 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
2847 void *dep_user
, void *user
)
2849 struct must_may
*mm
= (struct must_may
*)user
;
2852 mm
->must
= isl_map_union(mm
->must
, dep
);
2854 mm
->may
= isl_map_union(mm
->may
, dep
);
2859 static int common_space(void *first
, void *second
)
2861 int depth
= *(int *)first
;
2865 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
2873 map2
= isl_map_read_from_str(map
->ctx
, str
);
2874 equal
= isl_map_is_equal(map
, map2
);
2880 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
2884 equal
= map_is_equal(map
, str
);
2888 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
2889 "result not as expected", return -1);
2893 static int test_dep(struct isl_ctx
*ctx
)
2898 isl_access_info
*ai
;
2905 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2906 map
= isl_map_read_from_str(ctx
, str
);
2907 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2909 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2910 map
= isl_map_read_from_str(ctx
, str
);
2911 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2913 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2914 map
= isl_map_read_from_str(ctx
, str
);
2915 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2917 flow
= isl_access_info_compute_flow(ai
);
2918 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2919 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2920 mm
.may
= isl_map_empty(dim
);
2922 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2924 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
2925 " [1,10,0] -> [2,5,0] }";
2926 assert(map_is_equal(mm
.must
, str
));
2927 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2928 assert(map_is_equal(mm
.may
, str
));
2930 isl_map_free(mm
.must
);
2931 isl_map_free(mm
.may
);
2932 isl_flow_free(flow
);
2935 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2936 map
= isl_map_read_from_str(ctx
, str
);
2937 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2939 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2940 map
= isl_map_read_from_str(ctx
, str
);
2941 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2943 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2944 map
= isl_map_read_from_str(ctx
, str
);
2945 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2947 flow
= isl_access_info_compute_flow(ai
);
2948 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2949 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2950 mm
.may
= isl_map_empty(dim
);
2952 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2954 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2955 assert(map_is_equal(mm
.must
, str
));
2956 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
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
, 0, &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 <= 10; "
2984 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2985 assert(map_is_equal(mm
.may
, str
));
2986 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2987 assert(map_is_equal(mm
.must
, str
));
2989 isl_map_free(mm
.must
);
2990 isl_map_free(mm
.may
);
2991 isl_flow_free(flow
);
2994 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
2995 map
= isl_map_read_from_str(ctx
, str
);
2996 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2998 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2999 map
= isl_map_read_from_str(ctx
, str
);
3000 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3002 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3003 map
= isl_map_read_from_str(ctx
, str
);
3004 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3006 flow
= isl_access_info_compute_flow(ai
);
3007 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3008 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3009 mm
.may
= isl_map_empty(dim
);
3011 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3013 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3014 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3015 assert(map_is_equal(mm
.may
, str
));
3016 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3017 assert(map_is_equal(mm
.must
, str
));
3019 isl_map_free(mm
.must
);
3020 isl_map_free(mm
.may
);
3021 isl_flow_free(flow
);
3024 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3025 map
= isl_map_read_from_str(ctx
, str
);
3026 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3028 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3029 map
= isl_map_read_from_str(ctx
, str
);
3030 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3032 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3033 map
= isl_map_read_from_str(ctx
, str
);
3034 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3036 flow
= isl_access_info_compute_flow(ai
);
3037 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3038 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3039 mm
.may
= isl_map_empty(dim
);
3041 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3043 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3044 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3045 assert(map_is_equal(mm
.may
, str
));
3046 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3047 assert(map_is_equal(mm
.must
, str
));
3049 isl_map_free(mm
.must
);
3050 isl_map_free(mm
.may
);
3051 isl_flow_free(flow
);
3056 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3057 map
= isl_map_read_from_str(ctx
, str
);
3058 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
3060 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3061 map
= isl_map_read_from_str(ctx
, str
);
3062 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3064 flow
= isl_access_info_compute_flow(ai
);
3065 dim
= isl_space_alloc(ctx
, 0, 5, 5);
3066 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3067 mm
.may
= isl_map_empty(dim
);
3069 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3071 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3072 assert(map_is_equal(mm
.must
, str
));
3073 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3074 assert(map_is_equal(mm
.may
, str
));
3076 isl_map_free(mm
.must
);
3077 isl_map_free(mm
.may
);
3078 isl_flow_free(flow
);
3083 /* Check that the dependence analysis proceeds without errors.
3084 * Earlier versions of isl would break down during the analysis
3085 * due to the use of the wrong spaces.
3087 static int test_flow(isl_ctx
*ctx
)
3090 isl_union_map
*access
, *schedule
;
3091 isl_union_map
*must_dep
, *may_dep
;
3094 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3095 access
= isl_union_map_read_from_str(ctx
, str
);
3096 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3097 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3098 "S2[] -> [1,0,0,0]; "
3099 "S3[] -> [-1,0,0,0] }";
3100 schedule
= isl_union_map_read_from_str(ctx
, str
);
3101 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
3102 isl_union_map_copy(access
), schedule
,
3103 &must_dep
, &may_dep
, NULL
, NULL
);
3104 isl_union_map_free(may_dep
);
3105 isl_union_map_free(must_dep
);
3114 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3115 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3116 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3117 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3118 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3119 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3120 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3121 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3122 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3125 int test_sv(isl_ctx
*ctx
)
3127 isl_union_map
*umap
;
3131 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
3132 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
3133 sv
= isl_union_map_is_single_valued(umap
);
3134 isl_union_map_free(umap
);
3137 if (sv_tests
[i
].sv
&& !sv
)
3138 isl_die(ctx
, isl_error_internal
,
3139 "map not detected as single valued", return -1);
3140 if (!sv_tests
[i
].sv
&& sv
)
3141 isl_die(ctx
, isl_error_internal
,
3142 "map detected as single valued", return -1);
3151 } bijective_tests
[] = {
3152 { "[N,M]->{[i,j] -> [i]}", 0 },
3153 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3154 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3155 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3156 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3157 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3158 { "[N,M]->{[i,j] -> []}", 0 },
3159 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3160 { "[N,M]->{[i,j] -> [2i]}", 0 },
3161 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3162 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3163 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3164 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3167 static int test_bijective(struct isl_ctx
*ctx
)
3173 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
3174 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
3175 bijective
= isl_map_is_bijective(map
);
3179 if (bijective_tests
[i
].bijective
&& !bijective
)
3180 isl_die(ctx
, isl_error_internal
,
3181 "map not detected as bijective", return -1);
3182 if (!bijective_tests
[i
].bijective
&& bijective
)
3183 isl_die(ctx
, isl_error_internal
,
3184 "map detected as bijective", return -1);
3190 /* Inputs for isl_pw_qpolynomial_gist tests.
3191 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3197 } pwqp_gist_tests
[] = {
3198 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3199 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3200 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3201 "{ [i] -> -1/2 + 1/2 * i }" },
3202 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3205 static int test_pwqp(struct isl_ctx
*ctx
)
3210 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3213 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3214 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3216 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3219 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3220 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3222 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3224 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3226 isl_pw_qpolynomial_free(pwqp1
);
3228 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3229 str
= pwqp_gist_tests
[i
].pwqp
;
3230 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3231 str
= pwqp_gist_tests
[i
].set
;
3232 set
= isl_set_read_from_str(ctx
, str
);
3233 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3234 str
= pwqp_gist_tests
[i
].gist
;
3235 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3236 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3237 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3238 isl_pw_qpolynomial_free(pwqp1
);
3243 isl_die(ctx
, isl_error_unknown
,
3244 "unexpected result", return -1);
3247 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3248 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3249 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3250 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3252 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3254 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3256 isl_pw_qpolynomial_free(pwqp1
);
3258 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3259 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3260 str
= "{ [x] -> x }";
3261 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3263 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3265 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3267 isl_pw_qpolynomial_free(pwqp1
);
3269 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3270 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3271 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3272 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3273 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3274 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3275 isl_pw_qpolynomial_free(pwqp1
);
3277 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3278 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3279 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3280 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3281 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3282 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3283 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3284 isl_pw_qpolynomial_free(pwqp1
);
3285 isl_pw_qpolynomial_free(pwqp2
);
3289 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3291 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3292 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3293 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3294 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3295 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3297 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3298 isl_pw_qpolynomial_free(pwqp1
);
3299 isl_pw_qpolynomial_free(pwqp2
);
3303 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3308 static int test_split_periods(isl_ctx
*ctx
)
3311 isl_pw_qpolynomial
*pwqp
;
3313 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3314 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3315 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3316 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3318 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3320 isl_pw_qpolynomial_free(pwqp
);
3328 static int test_union(isl_ctx
*ctx
)
3331 isl_union_set
*uset1
, *uset2
;
3332 isl_union_map
*umap1
, *umap2
;
3335 str
= "{ [i] : 0 <= i <= 1 }";
3336 uset1
= isl_union_set_read_from_str(ctx
, str
);
3337 str
= "{ [1] -> [0] }";
3338 umap1
= isl_union_map_read_from_str(ctx
, str
);
3340 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3341 equal
= isl_union_map_is_equal(umap1
, umap2
);
3343 isl_union_map_free(umap1
);
3344 isl_union_map_free(umap2
);
3349 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3352 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3353 umap1
= isl_union_map_read_from_str(ctx
, str
);
3354 str
= "{ A[i]; B[i] }";
3355 uset1
= isl_union_set_read_from_str(ctx
, str
);
3357 uset2
= isl_union_map_domain(umap1
);
3359 equal
= isl_union_set_is_equal(uset1
, uset2
);
3361 isl_union_set_free(uset1
);
3362 isl_union_set_free(uset2
);
3367 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3373 /* Check that computing a bound of a non-zero polynomial over an unbounded
3374 * domain does not produce a rational value.
3375 * In particular, check that the upper bound is infinity.
3377 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
3380 isl_pw_qpolynomial
*pwqp
;
3381 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
3384 str
= "{ [m,n] -> -m * n }";
3385 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3386 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3388 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3389 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3390 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
3391 isl_pw_qpolynomial_fold_free(pwf
);
3392 isl_pw_qpolynomial_fold_free(pwf2
);
3397 isl_die(ctx
, isl_error_unknown
,
3398 "expecting infinite polynomial bound", return -1);
3403 static int test_bound(isl_ctx
*ctx
)
3407 isl_pw_qpolynomial
*pwqp
;
3408 isl_pw_qpolynomial_fold
*pwf
;
3410 if (test_bound_unbounded_domain(ctx
) < 0)
3413 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
3414 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3415 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3416 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3417 isl_pw_qpolynomial_fold_free(pwf
);
3419 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3422 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3423 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3424 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3425 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3426 isl_pw_qpolynomial_fold_free(pwf
);
3428 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3434 /* Check that the conversion from 'set' to 'basic set list' works as expected.
3436 static isl_stat
test_get_list_bset_from_set(isl_ctx
*ctx
)
3440 isl_set
*set
, *set2
;
3441 isl_basic_set_list
*bset_list
;
3443 set
= isl_set_read_from_str(ctx
, "{ [0]; [2]; [3] }");
3444 bset_list
= isl_set_get_basic_set_list(set
);
3446 set2
= isl_set_empty(isl_set_get_space(set
));
3448 for (i
= 0; i
< isl_basic_set_list_n_basic_set(bset_list
); i
++) {
3449 isl_basic_set
*bset
;
3450 bset
= isl_basic_set_list_get_basic_set(bset_list
, i
);
3451 set2
= isl_set_union(set2
, isl_set_from_basic_set(bset
));
3454 equal
= isl_set_is_equal(set
, set2
);
3458 isl_basic_set_list_free(bset_list
);
3461 return isl_stat_error
;
3464 isl_die(ctx
, isl_error_unknown
, "sets are not equal",
3465 return isl_stat_error
);
3470 /* Check that the conversion from 'union set' to 'basic set list' works as
3473 static isl_stat
test_get_list_bset_from_uset(isl_ctx
*ctx
)
3477 isl_union_set
*uset
, *uset2
;
3478 isl_basic_set_list
*bset_list
;
3480 uset
= isl_union_set_read_from_str(ctx
, "{ A[0]; B[2]; B[3] }");
3481 bset_list
= isl_union_set_get_basic_set_list(uset
);
3483 uset2
= isl_union_set_empty(isl_union_set_get_space(uset
));
3485 for (i
= 0; i
< isl_basic_set_list_n_basic_set(bset_list
); i
++) {
3486 isl_basic_set
*bset
;
3487 bset
= isl_basic_set_list_get_basic_set(bset_list
, i
);
3488 uset2
= isl_union_set_union(uset2
,
3489 isl_union_set_from_basic_set(bset
));
3492 equal
= isl_union_set_is_equal(uset
, uset2
);
3494 isl_union_set_free(uset
);
3495 isl_union_set_free(uset2
);
3496 isl_basic_set_list_free(bset_list
);
3499 return isl_stat_error
;
3502 isl_die(ctx
, isl_error_unknown
, "sets are not equal",
3503 return isl_stat_error
);
3508 /* Check that the conversion from 'union set' to 'set list' works as expected.
3510 static isl_stat
test_get_list_set_from_uset(isl_ctx
*ctx
)
3514 isl_union_set
*uset
, *uset2
;
3515 isl_set_list
*set_list
;
3517 uset
= isl_union_set_read_from_str(ctx
, "{ A[0]; A[2]; B[3] }");
3518 set_list
= isl_union_set_get_set_list(uset
);
3520 uset2
= isl_union_set_empty(isl_union_set_get_space(uset
));
3522 for (i
= 0; i
< isl_set_list_n_set(set_list
); i
++) {
3524 set
= isl_set_list_get_set(set_list
, i
);
3525 uset2
= isl_union_set_union(uset2
, isl_union_set_from_set(set
));
3528 equal
= isl_union_set_is_equal(uset
, uset2
);
3530 isl_union_set_free(uset
);
3531 isl_union_set_free(uset2
);
3532 isl_set_list_free(set_list
);
3535 return isl_stat_error
;
3538 isl_die(ctx
, isl_error_unknown
, "union sets are not equal",
3539 return isl_stat_error
);
3544 /* Check that the conversion from 'map' to 'basic map list' works as expected.
3546 static isl_stat
test_get_list_bmap_from_map(isl_ctx
*ctx
)
3550 isl_map
*map
, *map2
;
3551 isl_basic_map_list
*bmap_list
;
3553 map
= isl_map_read_from_str(ctx
,
3554 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }");
3555 bmap_list
= isl_map_get_basic_map_list(map
);
3557 map2
= isl_map_empty(isl_map_get_space(map
));
3559 for (i
= 0; i
< isl_basic_map_list_n_basic_map(bmap_list
); i
++) {
3560 isl_basic_map
*bmap
;
3561 bmap
= isl_basic_map_list_get_basic_map(bmap_list
, i
);
3562 map2
= isl_map_union(map2
, isl_map_from_basic_map(bmap
));
3565 equal
= isl_map_is_equal(map
, map2
);
3569 isl_basic_map_list_free(bmap_list
);
3572 return isl_stat_error
;
3575 isl_die(ctx
, isl_error_unknown
, "maps are not equal",
3576 return isl_stat_error
);
3581 /* Check that the conversion from 'union map' to 'map list' works as expected.
3583 static isl_stat
test_get_list_map_from_umap(isl_ctx
*ctx
)
3587 isl_union_map
*umap
, *umap2
;
3588 isl_map_list
*map_list
;
3590 umap
= isl_union_map_read_from_str(ctx
,
3591 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }");
3592 map_list
= isl_union_map_get_map_list(umap
);
3594 umap2
= isl_union_map_empty(isl_union_map_get_space(umap
));
3596 for (i
= 0; i
< isl_map_list_n_map(map_list
); i
++) {
3598 map
= isl_map_list_get_map(map_list
, i
);
3599 umap2
= isl_union_map_union(umap2
, isl_union_map_from_map(map
));
3602 equal
= isl_union_map_is_equal(umap
, umap2
);
3604 isl_union_map_free(umap
);
3605 isl_union_map_free(umap2
);
3606 isl_map_list_free(map_list
);
3609 return isl_stat_error
;
3612 isl_die(ctx
, isl_error_unknown
, "union maps are not equal",
3613 return isl_stat_error
);
3618 /* Check that the conversion from isl objects to lists works as expected.
3620 static int test_get_list(isl_ctx
*ctx
)
3622 if (test_get_list_bset_from_set(ctx
))
3624 if (test_get_list_bset_from_uset(ctx
))
3626 if (test_get_list_set_from_uset(ctx
))
3628 if (test_get_list_bmap_from_map(ctx
))
3630 if (test_get_list_map_from_umap(ctx
))
3636 static int test_lift(isl_ctx
*ctx
)
3639 isl_basic_map
*bmap
;
3640 isl_basic_set
*bset
;
3642 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
3643 bset
= isl_basic_set_read_from_str(ctx
, str
);
3644 bset
= isl_basic_set_lift(bset
);
3645 bmap
= isl_basic_map_from_range(bset
);
3646 bset
= isl_basic_map_domain(bmap
);
3647 isl_basic_set_free(bset
);
3652 /* Check that isl_set_is_subset is not confused by identical
3653 * integer divisions.
3654 * The call to isl_set_normalize ensures that the equality constraints
3655 * a = b = 0 are discovered, turning e0 and e1 into identical
3656 * integer divisions. Any further simplification would remove
3657 * the duplicate integer divisions.
3659 static isl_stat
test_subset_duplicate_integer_divisions(isl_ctx
*ctx
)
3663 isl_set
*set1
, *set2
;
3665 str
= "{ [a, b, c, d] : "
3666 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
3667 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
3668 "e3 = floor((-d + 4*floor((d)/4))/10): "
3669 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
3670 "b >= 0 and a <= 0 and b <= a) }";
3671 set1
= isl_set_read_from_str(ctx
, str
);
3672 set2
= isl_set_read_from_str(ctx
, str
);
3673 set2
= isl_set_normalize(set2
);
3675 is_subset
= isl_set_is_subset(set1
, set2
);
3681 return isl_stat_error
;
3683 isl_die(ctx
, isl_error_unknown
,
3684 "set is not considered to be a subset of itself",
3685 return isl_stat_error
);
3694 } subset_tests
[] = {
3696 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3697 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3698 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3700 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3701 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3702 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3703 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3704 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3705 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3706 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3707 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3708 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3709 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3710 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3711 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3712 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3713 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3714 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3715 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3716 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3717 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3718 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3719 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3720 "4e0 <= -57 + i0 + i1)) or "
3721 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3722 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3723 "4e0 >= -61 + i0 + i1)) or "
3724 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3725 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3728 static int test_subset(isl_ctx
*ctx
)
3731 isl_set
*set1
, *set2
;
3734 if (test_subset_duplicate_integer_divisions(ctx
) < 0)
3737 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
3738 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
3739 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
3740 subset
= isl_set_is_subset(set1
, set2
);
3745 if (subset
!= subset_tests
[i
].subset
)
3746 isl_die(ctx
, isl_error_unknown
,
3747 "incorrect subset result", return -1);
3754 const char *minuend
;
3755 const char *subtrahend
;
3756 const char *difference
;
3757 } subtract_domain_tests
[] = {
3758 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
3759 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
3760 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
3763 static int test_subtract(isl_ctx
*ctx
)
3766 isl_union_map
*umap1
, *umap2
;
3767 isl_union_pw_multi_aff
*upma1
, *upma2
;
3768 isl_union_set
*uset
;
3771 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3772 umap1
= isl_union_map_read_from_str(ctx
,
3773 subtract_domain_tests
[i
].minuend
);
3774 uset
= isl_union_set_read_from_str(ctx
,
3775 subtract_domain_tests
[i
].subtrahend
);
3776 umap2
= isl_union_map_read_from_str(ctx
,
3777 subtract_domain_tests
[i
].difference
);
3778 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
3779 equal
= isl_union_map_is_equal(umap1
, umap2
);
3780 isl_union_map_free(umap1
);
3781 isl_union_map_free(umap2
);
3785 isl_die(ctx
, isl_error_unknown
,
3786 "incorrect subtract domain result", return -1);
3789 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3790 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3791 subtract_domain_tests
[i
].minuend
);
3792 uset
= isl_union_set_read_from_str(ctx
,
3793 subtract_domain_tests
[i
].subtrahend
);
3794 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3795 subtract_domain_tests
[i
].difference
);
3796 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
3797 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
3798 isl_union_pw_multi_aff_free(upma1
);
3799 isl_union_pw_multi_aff_free(upma2
);
3803 isl_die(ctx
, isl_error_unknown
,
3804 "incorrect subtract domain result", return -1);
3810 /* Check that intersecting the empty basic set with another basic set
3811 * does not increase the number of constraints. In particular,
3812 * the empty basic set should maintain its canonical representation.
3814 static int test_intersect_1(isl_ctx
*ctx
)
3817 isl_basic_set
*bset1
, *bset2
;
3819 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
3820 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
3821 n1
= isl_basic_set_n_constraint(bset1
);
3822 bset1
= isl_basic_set_intersect(bset1
, bset2
);
3823 n2
= isl_basic_set_n_constraint(bset1
);
3824 isl_basic_set_free(bset1
);
3828 isl_die(ctx
, isl_error_unknown
,
3829 "number of constraints of empty set changed",
3835 /* Check that intersecting a set with itself does not cause
3836 * an explosion in the number of disjuncts.
3838 static isl_stat
test_intersect_2(isl_ctx
*ctx
)
3843 set
= isl_set_read_from_str(ctx
, "{ [x,y] : x >= 0 or y >= 0 }");
3844 for (i
= 0; i
< 100; ++i
)
3845 set
= isl_set_intersect(set
, isl_set_copy(set
));
3848 return isl_stat_error
;
3852 /* Perform some intersection tests.
3854 static int test_intersect(isl_ctx
*ctx
)
3856 if (test_intersect_1(ctx
) < 0)
3858 if (test_intersect_2(ctx
) < 0)
3864 int test_factorize(isl_ctx
*ctx
)
3867 isl_basic_set
*bset
;
3870 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
3871 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
3872 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
3873 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
3874 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
3875 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
3876 "3i5 >= -2i0 - i2 + 3i4 }";
3877 bset
= isl_basic_set_read_from_str(ctx
, str
);
3878 f
= isl_basic_set_factorizer(bset
);
3879 isl_basic_set_free(bset
);
3880 isl_factorizer_free(f
);
3882 isl_die(ctx
, isl_error_unknown
,
3883 "failed to construct factorizer", return -1);
3885 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
3886 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
3887 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
3888 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
3889 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
3890 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
3891 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
3892 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
3893 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
3894 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
3895 bset
= isl_basic_set_read_from_str(ctx
, str
);
3896 f
= isl_basic_set_factorizer(bset
);
3897 isl_basic_set_free(bset
);
3898 isl_factorizer_free(f
);
3900 isl_die(ctx
, isl_error_unknown
,
3901 "failed to construct factorizer", return -1);
3906 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
3908 int *injective
= user
;
3910 *injective
= isl_map_is_injective(map
);
3913 if (*injective
< 0 || !*injective
)
3914 return isl_stat_error
;
3919 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
3920 const char *r
, const char *s
, int tilable
, int parallel
)
3924 isl_union_map
*W
, *R
, *S
;
3925 isl_union_map
*empty
;
3926 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
3927 isl_union_map
*validity
, *proximity
, *coincidence
;
3928 isl_union_map
*schedule
;
3929 isl_union_map
*test
;
3930 isl_union_set
*delta
;
3931 isl_union_set
*domain
;
3935 isl_schedule_constraints
*sc
;
3936 isl_schedule
*sched
;
3937 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
3939 D
= isl_union_set_read_from_str(ctx
, d
);
3940 W
= isl_union_map_read_from_str(ctx
, w
);
3941 R
= isl_union_map_read_from_str(ctx
, r
);
3942 S
= isl_union_map_read_from_str(ctx
, s
);
3944 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
3945 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
3947 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
3948 isl_union_map_compute_flow(isl_union_map_copy(R
),
3949 isl_union_map_copy(W
), empty
,
3950 isl_union_map_copy(S
),
3951 &dep_raw
, NULL
, NULL
, NULL
);
3952 isl_union_map_compute_flow(isl_union_map_copy(W
),
3953 isl_union_map_copy(W
),
3954 isl_union_map_copy(R
),
3955 isl_union_map_copy(S
),
3956 &dep_waw
, &dep_war
, NULL
, NULL
);
3958 dep
= isl_union_map_union(dep_waw
, dep_war
);
3959 dep
= isl_union_map_union(dep
, dep_raw
);
3960 validity
= isl_union_map_copy(dep
);
3961 coincidence
= isl_union_map_copy(dep
);
3962 proximity
= isl_union_map_copy(dep
);
3964 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
3965 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3966 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
3967 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3968 sched
= isl_schedule_constraints_compute_schedule(sc
);
3969 schedule
= isl_schedule_get_map(sched
);
3970 isl_schedule_free(sched
);
3971 isl_union_map_free(W
);
3972 isl_union_map_free(R
);
3973 isl_union_map_free(S
);
3976 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
3978 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
3979 is_complete
= isl_union_set_is_subset(D
, domain
);
3980 isl_union_set_free(D
);
3981 isl_union_set_free(domain
);
3983 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
3984 test
= isl_union_map_apply_range(test
, dep
);
3985 test
= isl_union_map_apply_range(test
, schedule
);
3987 delta
= isl_union_map_deltas(test
);
3988 if (isl_union_set_n_set(delta
) == 0) {
3992 isl_union_set_free(delta
);
3994 delta_set
= isl_set_from_union_set(delta
);
3996 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3997 for (i
= 0; i
< tilable
; ++i
)
3998 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
3999 is_tilable
= isl_set_is_subset(delta_set
, slice
);
4000 isl_set_free(slice
);
4002 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4003 for (i
= 0; i
< parallel
; ++i
)
4004 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
4005 is_parallel
= isl_set_is_subset(delta_set
, slice
);
4006 isl_set_free(slice
);
4008 origin
= isl_set_universe(isl_set_get_space(delta_set
));
4009 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
4010 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
4012 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
4013 delta_set
= isl_set_lexmin(delta_set
);
4015 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
4017 isl_set_free(origin
);
4018 isl_set_free(delta_set
);
4021 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
4022 is_injection
< 0 || is_complete
< 0)
4025 isl_die(ctx
, isl_error_unknown
,
4026 "generated schedule incomplete", return -1);
4028 isl_die(ctx
, isl_error_unknown
,
4029 "generated schedule not injective on each statement",
4032 isl_die(ctx
, isl_error_unknown
,
4033 "negative dependences in generated schedule",
4036 isl_die(ctx
, isl_error_unknown
,
4037 "generated schedule not as tilable as expected",
4040 isl_die(ctx
, isl_error_unknown
,
4041 "generated schedule not as parallel as expected",
4047 /* Compute a schedule for the given instance set, validity constraints,
4048 * proximity constraints and context and return a corresponding union map
4051 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
4052 const char *domain
, const char *validity
, const char *proximity
,
4053 const char *context
)
4058 isl_union_map
*prox
;
4059 isl_schedule_constraints
*sc
;
4060 isl_schedule
*schedule
;
4061 isl_union_map
*sched
;
4063 con
= isl_set_read_from_str(ctx
, context
);
4064 dom
= isl_union_set_read_from_str(ctx
, domain
);
4065 dep
= isl_union_map_read_from_str(ctx
, validity
);
4066 prox
= isl_union_map_read_from_str(ctx
, proximity
);
4067 sc
= isl_schedule_constraints_on_domain(dom
);
4068 sc
= isl_schedule_constraints_set_context(sc
, con
);
4069 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
4070 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
4071 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4072 sched
= isl_schedule_get_map(schedule
);
4073 isl_schedule_free(schedule
);
4078 /* Compute a schedule for the given instance set, validity constraints and
4079 * proximity constraints and return a corresponding union map representation.
4081 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
4082 const char *domain
, const char *validity
, const char *proximity
)
4084 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
4088 /* Check that a schedule can be constructed on the given domain
4089 * with the given validity and proximity constraints.
4091 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
4092 const char *validity
, const char *proximity
)
4094 isl_union_map
*sched
;
4096 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
4100 isl_union_map_free(sched
);
4104 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
4105 const char *validity
, const char *proximity
, const char *expected_sched
)
4107 isl_union_map
*sched1
, *sched2
;
4110 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
4111 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
4113 equal
= isl_union_map_is_equal(sched1
, sched2
);
4114 isl_union_map_free(sched1
);
4115 isl_union_map_free(sched2
);
4120 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
4126 /* Check that the schedule map is properly padded, i.e., that the range
4127 * lives in a single space.
4129 static int test_padded_schedule(isl_ctx
*ctx
)
4133 isl_union_map
*validity
, *proximity
;
4134 isl_schedule_constraints
*sc
;
4135 isl_schedule
*sched
;
4136 isl_union_map
*umap
;
4137 isl_union_set
*range
;
4140 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4141 D
= isl_union_set_read_from_str(ctx
, str
);
4142 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
4143 proximity
= isl_union_map_copy(validity
);
4144 sc
= isl_schedule_constraints_on_domain(D
);
4145 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4146 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4147 sched
= isl_schedule_constraints_compute_schedule(sc
);
4148 umap
= isl_schedule_get_map(sched
);
4149 isl_schedule_free(sched
);
4150 range
= isl_union_map_range(umap
);
4151 set
= isl_set_from_union_set(range
);
4160 /* Check that conditional validity constraints are also taken into
4161 * account across bands.
4162 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4163 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4164 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4165 * is enforced by the rest of the schedule.
4167 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
4170 isl_union_set
*domain
;
4171 isl_union_map
*validity
, *proximity
, *condition
;
4172 isl_union_map
*sink
, *source
, *dep
;
4173 isl_schedule_constraints
*sc
;
4174 isl_schedule
*schedule
;
4175 isl_union_access_info
*access
;
4176 isl_union_flow
*flow
;
4179 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4180 "A[k] : k >= 1 and k <= -1 + n; "
4181 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4182 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4183 domain
= isl_union_set_read_from_str(ctx
, str
);
4184 sc
= isl_schedule_constraints_on_domain(domain
);
4185 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4186 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4187 "D[k, i] -> C[1 + k, i] : "
4188 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4189 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4190 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4191 validity
= isl_union_map_read_from_str(ctx
, str
);
4192 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4193 str
= "[n] -> { C[k, i] -> D[k, i] : "
4194 "0 <= i <= -1 + k and k <= -1 + n }";
4195 proximity
= isl_union_map_read_from_str(ctx
, str
);
4196 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4197 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4198 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4199 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4200 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4201 condition
= isl_union_map_read_from_str(ctx
, str
);
4202 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4203 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4204 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4205 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4206 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4207 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4208 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4209 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4210 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4211 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4212 validity
= isl_union_map_read_from_str(ctx
, str
);
4213 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4215 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4216 str
= "{ D[2,0] -> [] }";
4217 sink
= isl_union_map_read_from_str(ctx
, str
);
4218 access
= isl_union_access_info_from_sink(sink
);
4219 str
= "{ C[2,1] -> [] }";
4220 source
= isl_union_map_read_from_str(ctx
, str
);
4221 access
= isl_union_access_info_set_must_source(access
, source
);
4222 access
= isl_union_access_info_set_schedule(access
, schedule
);
4223 flow
= isl_union_access_info_compute_flow(access
);
4224 dep
= isl_union_flow_get_must_dependence(flow
);
4225 isl_union_flow_free(flow
);
4226 empty
= isl_union_map_is_empty(dep
);
4227 isl_union_map_free(dep
);
4232 isl_die(ctx
, isl_error_unknown
,
4233 "conditional validity not respected", return -1);
4238 /* Check that the test for violated conditional validity constraints
4239 * is not confused by domain compression.
4240 * In particular, earlier versions of isl would apply
4241 * a schedule on the compressed domains to the original domains,
4242 * resulting in a failure to detect that the default schedule
4243 * violates the conditional validity constraints.
4245 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
4249 isl_union_set
*domain
;
4250 isl_union_map
*validity
, *condition
;
4251 isl_schedule_constraints
*sc
;
4252 isl_schedule
*schedule
;
4253 isl_union_map
*umap
;
4256 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4257 domain
= isl_union_set_read_from_str(ctx
, str
);
4258 sc
= isl_schedule_constraints_on_domain(domain
);
4259 str
= "{ B[1, i] -> A[0, i + 1] }";
4260 condition
= isl_union_map_read_from_str(ctx
, str
);
4261 str
= "{ A[0, i] -> B[1, i - 1] }";
4262 validity
= isl_union_map_read_from_str(ctx
, str
);
4263 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4264 isl_union_map_copy(validity
));
4265 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4266 umap
= isl_schedule_get_map(schedule
);
4267 isl_schedule_free(schedule
);
4268 validity
= isl_union_map_apply_domain(validity
,
4269 isl_union_map_copy(umap
));
4270 validity
= isl_union_map_apply_range(validity
, umap
);
4271 map
= isl_map_from_union_map(validity
);
4272 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4273 map
= isl_map_intersect(map
, ge
);
4274 empty
= isl_map_is_empty(map
);
4280 isl_die(ctx
, isl_error_unknown
,
4281 "conditional validity constraints not satisfied",
4287 /* Input for testing of schedule construction based on
4288 * conditional constraints.
4290 * domain is the iteration domain
4291 * flow are the flow dependences, which determine the validity and
4292 * proximity constraints
4293 * condition are the conditions on the conditional validity constraints
4294 * conditional_validity are the conditional validity constraints
4295 * outer_band_n is the expected number of members in the outer band
4300 const char *condition
;
4301 const char *conditional_validity
;
4303 } live_range_tests
[] = {
4304 /* Contrived example that illustrates that we need to keep
4305 * track of tagged condition dependences and
4306 * tagged conditional validity dependences
4307 * in isl_sched_edge separately.
4308 * In particular, the conditional validity constraints on A
4309 * cannot be satisfied,
4310 * but they can be ignored because there are no corresponding
4311 * condition constraints. However, we do have an additional
4312 * conditional validity constraint that maps to the same
4313 * dependence relation
4314 * as the condition constraint on B. If we did not make a distinction
4315 * between tagged condition and tagged conditional validity
4316 * dependences, then we
4317 * could end up treating this shared dependence as an condition
4318 * constraint on A, forcing a localization of the conditions,
4319 * which is impossible.
4321 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4322 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4323 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4324 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4325 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4326 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4329 /* TACO 2013 Fig. 7 */
4330 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4331 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4332 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4333 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4334 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4335 "0 <= i < n and 0 <= j < n - 1 }",
4336 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4337 "0 <= i < n and 0 <= j < j' < n;"
4338 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4339 "0 <= i < i' < n and 0 <= j,j' < n;"
4340 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4341 "0 <= i,j,j' < n and j < j' }",
4344 /* TACO 2013 Fig. 7, without tags */
4345 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4346 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4347 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4348 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4349 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4350 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4351 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4352 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4355 /* TACO 2013 Fig. 12 */
4356 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4357 "S3[i,3] : 0 <= i <= 1 }",
4358 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4359 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4360 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4361 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4362 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4363 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4364 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4365 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4366 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4367 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4368 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4373 /* Test schedule construction based on conditional constraints.
4374 * In particular, check the number of members in the outer band node
4375 * as an indication of whether tiling is possible or not.
4377 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4380 isl_union_set
*domain
;
4381 isl_union_map
*condition
;
4382 isl_union_map
*flow
;
4383 isl_union_map
*validity
;
4384 isl_schedule_constraints
*sc
;
4385 isl_schedule
*schedule
;
4386 isl_schedule_node
*node
;
4389 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4391 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4394 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4395 domain
= isl_union_set_read_from_str(ctx
,
4396 live_range_tests
[i
].domain
);
4397 flow
= isl_union_map_read_from_str(ctx
,
4398 live_range_tests
[i
].flow
);
4399 condition
= isl_union_map_read_from_str(ctx
,
4400 live_range_tests
[i
].condition
);
4401 validity
= isl_union_map_read_from_str(ctx
,
4402 live_range_tests
[i
].conditional_validity
);
4403 sc
= isl_schedule_constraints_on_domain(domain
);
4404 sc
= isl_schedule_constraints_set_validity(sc
,
4405 isl_union_map_copy(flow
));
4406 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4407 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4408 condition
, validity
);
4409 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4410 node
= isl_schedule_get_root(schedule
);
4412 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4413 node
= isl_schedule_node_first_child(node
);
4414 n_member
= isl_schedule_node_band_n_member(node
);
4415 isl_schedule_node_free(node
);
4416 isl_schedule_free(schedule
);
4420 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4421 isl_die(ctx
, isl_error_unknown
,
4422 "unexpected number of members in outer band",
4428 /* Check that the schedule computed for the given instance set and
4429 * dependence relation strongly satisfies the dependences.
4430 * In particular, check that no instance is scheduled before
4431 * or together with an instance on which it depends.
4432 * Earlier versions of isl would produce a schedule that
4433 * only weakly satisfies the dependences.
4435 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4437 const char *domain
, *dep
;
4438 isl_union_map
*D
, *schedule
;
4442 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4443 "A[i0] : 0 <= i0 <= 1 }";
4444 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4445 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4446 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
4447 D
= isl_union_map_read_from_str(ctx
, dep
);
4448 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
4449 D
= isl_union_map_apply_range(D
, schedule
);
4450 map
= isl_map_from_union_map(D
);
4451 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4452 map
= isl_map_intersect(map
, ge
);
4453 empty
= isl_map_is_empty(map
);
4459 isl_die(ctx
, isl_error_unknown
,
4460 "dependences not strongly satisfied", return -1);
4465 /* Compute a schedule for input where the instance set constraints
4466 * conflict with the context constraints.
4467 * Earlier versions of isl did not properly handle this situation.
4469 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
4471 isl_union_map
*schedule
;
4472 const char *domain
, *context
;
4474 domain
= "[n] -> { A[] : n >= 0 }";
4475 context
= "[n] -> { : n < 0 }";
4476 schedule
= compute_schedule_with_context(ctx
,
4477 domain
, "{}", "{}", context
);
4478 isl_union_map_free(schedule
);
4486 /* Check that a set of schedule constraints that only allow for
4487 * a coalescing schedule still produces a schedule even if the user
4488 * request a non-coalescing schedule. Earlier versions of isl
4489 * would not handle this case correctly.
4491 static int test_coalescing_schedule(isl_ctx
*ctx
)
4493 const char *domain
, *dep
;
4496 isl_schedule_constraints
*sc
;
4497 isl_schedule
*schedule
;
4498 int treat_coalescing
;
4500 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4501 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
4502 I
= isl_union_set_read_from_str(ctx
, domain
);
4503 D
= isl_union_map_read_from_str(ctx
, dep
);
4504 sc
= isl_schedule_constraints_on_domain(I
);
4505 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4506 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4507 isl_options_set_schedule_treat_coalescing(ctx
, 1);
4508 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4509 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4510 isl_schedule_free(schedule
);
4516 /* Check that the scheduler does not perform any needless
4517 * compound skewing. Earlier versions of isl would compute
4518 * schedules in terms of transformed schedule coefficients and
4519 * would not accurately keep track of the sum of the original
4520 * schedule coefficients. It could then produce the schedule
4521 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4522 * for the input below instead of the schedule below.
4524 static int test_skewing_schedule(isl_ctx
*ctx
)
4526 const char *D
, *V
, *P
, *S
;
4528 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4529 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4530 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4531 "-1 <= a-i + b-j + c-k <= 1 }";
4533 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4535 return test_special_schedule(ctx
, D
, V
, P
, S
);
4538 int test_schedule(isl_ctx
*ctx
)
4540 const char *D
, *W
, *R
, *V
, *P
, *S
;
4541 int max_coincidence
;
4542 int treat_coalescing
;
4544 /* Handle resulting schedule with zero bands. */
4545 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4549 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4550 W
= "{ S1[t,i] -> a[t,i] }";
4551 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4552 "S1[t,i] -> a[t-1,i+1] }";
4553 S
= "{ S1[t,i] -> [t,i] }";
4554 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4557 /* Fig. 5 of CC2008 */
4558 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4560 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4561 "j >= 2 and j <= -1 + N }";
4562 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4563 "j >= 2 and j <= -1 + N; "
4564 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4565 "j >= 2 and j <= -1 + N }";
4566 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4567 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4570 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4571 W
= "{ S1[i] -> a[i] }";
4572 R
= "{ S2[i] -> a[i+1] }";
4573 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4574 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4577 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4578 W
= "{ S1[i] -> a[i] }";
4579 R
= "{ S2[i] -> a[9-i] }";
4580 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4581 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4584 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4585 W
= "{ S1[i] -> a[i] }";
4586 R
= "[N] -> { S2[i] -> a[N-1-i] }";
4587 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4588 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4591 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4592 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4593 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4594 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4595 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4598 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4599 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4600 R
= "{ S2[i,j] -> a[i-1,j] }";
4601 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4602 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4605 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4606 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4607 R
= "{ S2[i,j] -> a[i,j-1] }";
4608 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4609 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4612 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4613 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4614 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4615 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4616 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4617 "S_0[] -> [0, 0, 0] }";
4618 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
4620 ctx
->opt
->schedule_parametric
= 0;
4621 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4623 ctx
->opt
->schedule_parametric
= 1;
4625 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4626 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4627 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4628 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4629 "S4[i] -> a[i,N] }";
4630 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4631 "S4[i] -> [4,i,0] }";
4632 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
4633 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
4634 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4636 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
4638 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4639 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4641 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4643 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4645 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4646 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4649 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4650 " S_2[t] : t >= 0 and t <= -1 + N; "
4651 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4653 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4654 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4655 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4656 "i >= 0 and i <= -1 + N }";
4657 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4658 "i >= 0 and i <= -1 + N; "
4659 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4660 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4661 " S_0[t] -> [0, t, 0] }";
4663 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4665 ctx
->opt
->schedule_parametric
= 0;
4666 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4668 ctx
->opt
->schedule_parametric
= 1;
4670 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4671 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4672 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
4675 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4676 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4677 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4678 "j >= 0 and j <= -1 + N; "
4679 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4680 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4681 "j >= 0 and j <= -1 + N; "
4682 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4683 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4684 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4687 D
= "{ S_0[i] : i >= 0 }";
4688 W
= "{ S_0[i] -> a[i] : i >= 0 }";
4689 R
= "{ S_0[i] -> a[0] : i >= 0 }";
4690 S
= "{ S_0[i] -> [0, i, 0] }";
4691 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4694 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
4695 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
4696 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
4697 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
4698 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4701 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
4702 "k <= -1 + n and k >= 0 }";
4703 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
4704 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
4705 "k <= -1 + n and k >= 0; "
4706 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
4707 "k <= -1 + n and k >= 0; "
4708 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
4709 "k <= -1 + n and k >= 0 }";
4710 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
4711 ctx
->opt
->schedule_outer_coincidence
= 1;
4712 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4714 ctx
->opt
->schedule_outer_coincidence
= 0;
4716 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
4717 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
4718 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
4719 "Stmt_for_body24[i0, i1, 1, 0]:"
4720 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
4721 "Stmt_for_body7[i0, i1, i2]:"
4722 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
4725 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
4726 "Stmt_for_body24[1, i1, i2, i3]:"
4727 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
4729 "Stmt_for_body24[0, i1, i2, i3] -> "
4730 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
4731 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
4733 "Stmt_for_body24[0, i1, i2, i3] ->"
4734 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
4735 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
4736 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
4737 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
4738 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
4739 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
4740 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
4741 "i1 <= 6 and i1 >= 0;"
4742 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
4743 "Stmt_for_body7[i0, i1, i2] -> "
4744 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
4745 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
4746 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
4747 "Stmt_for_body7[i0, i1, i2] -> "
4748 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
4749 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
4750 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
4753 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4754 isl_options_set_schedule_treat_coalescing(ctx
, 0);
4755 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4757 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4759 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
4760 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
4761 "j >= 1 and j <= 7;"
4762 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
4763 "j >= 1 and j <= 8 }";
4765 S
= "{ S_0[i, j] -> [i + j, i] }";
4766 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4767 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4769 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4771 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
4772 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
4773 "j >= 0 and j <= -1 + i }";
4774 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
4775 "i <= -1 + N and j >= 0;"
4776 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
4779 S
= "{ S_0[i, j] -> [i, j] }";
4780 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4781 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4783 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4785 /* Test both algorithms on a case with only proximity dependences. */
4786 D
= "{ S[i,j] : 0 <= i <= 10 }";
4788 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
4789 S
= "{ S[i, j] -> [j, i] }";
4790 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4791 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4793 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4794 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4797 D
= "{ A[a]; B[] }";
4799 P
= "{ A[a] -> B[] }";
4800 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4803 if (test_padded_schedule(ctx
) < 0)
4806 /* Check that check for progress is not confused by rational
4809 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
4810 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
4812 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
4813 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
4815 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4816 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4818 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4820 /* Check that we allow schedule rows that are only non-trivial
4821 * on some full-dimensional domains.
4823 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
4824 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
4825 "S1[j] -> S2[1] : 0 <= j <= 1 }";
4827 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4828 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4830 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4832 if (test_conditional_schedule_constraints(ctx
) < 0)
4835 if (test_strongly_satisfying_schedule(ctx
) < 0)
4838 if (test_conflicting_context_schedule(ctx
) < 0)
4841 if (test_coalescing_schedule(ctx
) < 0)
4843 if (test_skewing_schedule(ctx
) < 0)
4849 /* Perform scheduling tests using the whole component scheduler.
4851 static int test_schedule_whole(isl_ctx
*ctx
)
4856 whole
= isl_options_get_schedule_whole_component(ctx
);
4857 isl_options_set_schedule_whole_component(ctx
, 1);
4858 r
= test_schedule(ctx
);
4859 isl_options_set_schedule_whole_component(ctx
, whole
);
4864 /* Perform scheduling tests using the incremental scheduler.
4866 static int test_schedule_incremental(isl_ctx
*ctx
)
4871 whole
= isl_options_get_schedule_whole_component(ctx
);
4872 isl_options_set_schedule_whole_component(ctx
, 0);
4873 r
= test_schedule(ctx
);
4874 isl_options_set_schedule_whole_component(ctx
, whole
);
4879 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
4881 isl_union_map
*umap
;
4884 umap
= isl_union_map_read_from_str(ctx
, str
);
4885 test
= isl_union_map_plain_is_injective(umap
);
4886 isl_union_map_free(umap
);
4889 if (test
== injective
)
4892 isl_die(ctx
, isl_error_unknown
,
4893 "map not detected as injective", return -1);
4895 isl_die(ctx
, isl_error_unknown
,
4896 "map detected as injective", return -1);
4899 int test_injective(isl_ctx
*ctx
)
4903 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
4905 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
4907 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
4909 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
4911 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
4913 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
4915 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
4917 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
4920 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
4921 if (test_plain_injective(ctx
, str
, 1))
4923 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
4924 if (test_plain_injective(ctx
, str
, 0))
4930 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
4938 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
4939 equal
= isl_aff_plain_is_equal(aff
, aff2
);
4945 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
4949 equal
= aff_plain_is_equal(aff
, str
);
4953 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
4954 "result not as expected", return -1);
4958 /* Is "upa" obviously equal to the isl_union_pw_aff represented by "str"?
4960 static isl_bool
union_pw_aff_plain_is_equal(__isl_keep isl_union_pw_aff
*upa
,
4964 isl_union_pw_aff
*upa2
;
4968 return isl_bool_error
;
4970 ctx
= isl_union_pw_aff_get_ctx(upa
);
4971 upa2
= isl_union_pw_aff_read_from_str(ctx
, str
);
4972 equal
= isl_union_pw_aff_plain_is_equal(upa
, upa2
);
4973 isl_union_pw_aff_free(upa2
);
4978 /* Check that "upa" is obviously equal to the isl_union_pw_aff
4979 * represented by "str".
4981 static isl_stat
union_pw_aff_check_plain_equal(__isl_keep isl_union_pw_aff
*upa
,
4986 equal
= union_pw_aff_plain_is_equal(upa
, str
);
4988 return isl_stat_error
;
4990 isl_die(isl_union_pw_aff_get_ctx(upa
), isl_error_unknown
,
4991 "result not as expected", return isl_stat_error
);
4995 /* Basic tests on isl_union_pw_aff.
4997 * In particular, check that isl_union_pw_aff_aff_on_domain
4998 * aligns the parameters of the input objects and
4999 * that isl_union_pw_aff_param_on_domain_id properly
5000 * introduces the parameter.
5002 static int test_upa(isl_ctx
*ctx
)
5007 isl_union_set
*domain
;
5008 isl_union_pw_aff
*upa
;
5011 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
5012 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5013 domain
= isl_union_set_read_from_str(ctx
, str
);
5014 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
5015 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5016 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5017 isl_union_pw_aff_free(upa
);
5021 id
= isl_id_alloc(ctx
, "N", NULL
);
5022 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5023 domain
= isl_union_set_read_from_str(ctx
, str
);
5024 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
5025 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5026 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5027 isl_union_pw_aff_free(upa
);
5035 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5036 __isl_take isl_aff
*aff2
);
5038 ['+'] = { &isl_aff_add
},
5039 ['-'] = { &isl_aff_sub
},
5040 ['*'] = { &isl_aff_mul
},
5041 ['/'] = { &isl_aff_div
},
5049 } aff_bin_tests
[] = {
5050 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5051 "{ [i] -> [2i] }" },
5052 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5054 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5055 "{ [i] -> [2i] }" },
5056 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5057 "{ [i] -> [2i] }" },
5058 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5059 "{ [i] -> [i/2] }" },
5060 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5062 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5063 "{ [i] -> [NaN] }" },
5064 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5065 "{ [i] -> [NaN] }" },
5066 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5067 "{ [i] -> [NaN] }" },
5068 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5069 "{ [i] -> [NaN] }" },
5070 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5071 "{ [i] -> [NaN] }" },
5072 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5073 "{ [i] -> [NaN] }" },
5074 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5075 "{ [i] -> [NaN] }" },
5076 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5077 "{ [i] -> [NaN] }" },
5078 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5079 "{ [i] -> [NaN] }" },
5080 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5081 "{ [i] -> [NaN] }" },
5082 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5083 "{ [i] -> [NaN] }" },
5084 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5085 "{ [i] -> [NaN] }" },
5088 /* Perform some basic tests of binary operations on isl_aff objects.
5090 static int test_bin_aff(isl_ctx
*ctx
)
5093 isl_aff
*aff1
, *aff2
, *res
;
5094 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5095 __isl_take isl_aff
*aff2
);
5098 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
5099 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
5100 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
5101 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
5102 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
5103 aff1
= fn(aff1
, aff2
);
5104 if (isl_aff_is_nan(res
))
5105 ok
= isl_aff_is_nan(aff1
);
5107 ok
= isl_aff_plain_is_equal(aff1
, res
);
5113 isl_die(ctx
, isl_error_unknown
,
5114 "unexpected result", return -1);
5121 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
5122 __isl_take isl_pw_aff
*pa2
);
5123 } pw_aff_bin_op
[] = {
5124 ['m'] = { &isl_pw_aff_min
},
5125 ['M'] = { &isl_pw_aff_max
},
5128 /* Inputs for binary isl_pw_aff operation tests.
5129 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5130 * defined by pw_aff_bin_op, and "res" is the expected result.
5137 } pw_aff_bin_tests
[] = {
5138 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5140 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5142 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5143 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5144 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5145 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5146 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5147 "{ [i] -> [NaN] }" },
5148 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5149 "{ [i] -> [NaN] }" },
5152 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5154 static int test_bin_pw_aff(isl_ctx
*ctx
)
5158 isl_pw_aff
*pa1
, *pa2
, *res
;
5160 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
5161 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
5162 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
5163 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
5164 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
5165 if (isl_pw_aff_involves_nan(res
))
5166 ok
= isl_pw_aff_involves_nan(pa1
);
5168 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
5169 isl_pw_aff_free(pa1
);
5170 isl_pw_aff_free(res
);
5174 isl_die(ctx
, isl_error_unknown
,
5175 "unexpected result", return -1);
5182 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5183 __isl_take isl_union_pw_multi_aff
*upma1
,
5184 __isl_take isl_union_pw_multi_aff
*upma2
);
5188 } upma_bin_tests
[] = {
5189 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
5190 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5191 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
5192 "{ B[x] -> [2] : x >= 0 }",
5193 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5194 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
5195 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5196 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5197 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5198 "D[i] -> B[2] : i >= 5 }" },
5199 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5200 "{ B[x] -> C[2] : x > 0 }",
5201 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5202 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5203 "{ B[x] -> A[2] : x >= 0 }",
5204 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5207 /* Perform some basic tests of binary operations on
5208 * isl_union_pw_multi_aff objects.
5210 static int test_bin_upma(isl_ctx
*ctx
)
5213 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
5216 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
5217 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5218 upma_bin_tests
[i
].arg1
);
5219 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5220 upma_bin_tests
[i
].arg2
);
5221 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5222 upma_bin_tests
[i
].res
);
5223 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
5224 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
5225 isl_union_pw_multi_aff_free(upma1
);
5226 isl_union_pw_multi_aff_free(res
);
5230 isl_die(ctx
, isl_error_unknown
,
5231 "unexpected result", return -1);
5238 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5239 __isl_take isl_union_pw_multi_aff
*upma1
,
5240 __isl_take isl_union_pw_multi_aff
*upma2
);
5243 } upma_bin_fail_tests
[] = {
5244 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5245 "{ B[x] -> C[2] : x >= 0 }" },
5248 /* Perform some basic tests of binary operations on
5249 * isl_union_pw_multi_aff objects that are expected to fail.
5251 static int test_bin_upma_fail(isl_ctx
*ctx
)
5254 isl_union_pw_multi_aff
*upma1
, *upma2
;
5257 on_error
= isl_options_get_on_error(ctx
);
5258 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5259 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5260 for (i
= 0; i
< n
; ++i
) {
5261 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5262 upma_bin_fail_tests
[i
].arg1
);
5263 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5264 upma_bin_fail_tests
[i
].arg2
);
5265 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5266 isl_union_pw_multi_aff_free(upma1
);
5270 isl_options_set_on_error(ctx
, on_error
);
5272 isl_die(ctx
, isl_error_unknown
,
5273 "operation not expected to succeed", return -1);
5278 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5279 * "fn" is the function that is tested.
5280 * "arg" is a string description of the input.
5281 * "res" is a string description of the expected result.
5284 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5287 } mpa_un_tests
[] = {
5288 { &isl_multi_pw_aff_range_factor_domain
,
5289 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5290 "{ A[x] -> B[(1 : x >= 5)] }" },
5291 { &isl_multi_pw_aff_range_factor_range
,
5292 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5293 "{ A[y] -> C[(2 : y <= 10)] }" },
5294 { &isl_multi_pw_aff_range_factor_domain
,
5295 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5296 "{ A[x] -> B[(1 : x >= 5)] }" },
5297 { &isl_multi_pw_aff_range_factor_range
,
5298 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5299 "{ A[y] -> C[] }" },
5300 { &isl_multi_pw_aff_range_factor_domain
,
5301 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5302 "{ A[x] -> B[] }" },
5303 { &isl_multi_pw_aff_range_factor_range
,
5304 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5305 "{ A[y] -> C[(2 : y <= 10)] }" },
5306 { &isl_multi_pw_aff_range_factor_domain
,
5307 "{ A[x] -> [B[] -> C[]] }",
5308 "{ A[x] -> B[] }" },
5309 { &isl_multi_pw_aff_range_factor_range
,
5310 "{ A[x] -> [B[] -> C[]] }",
5311 "{ A[y] -> C[] }" },
5312 { &isl_multi_pw_aff_factor_range
,
5315 { &isl_multi_pw_aff_range_factor_domain
,
5316 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5317 "{ A[x] -> B[] : x >= 0 }" },
5318 { &isl_multi_pw_aff_range_factor_range
,
5319 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5320 "{ A[y] -> C[] : y >= 0 }" },
5321 { &isl_multi_pw_aff_factor_range
,
5322 "[N] -> { [B[] -> C[]] : N >= 0 }",
5323 "[N] -> { C[] : N >= 0 }" },
5326 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5328 static int test_un_mpa(isl_ctx
*ctx
)
5332 isl_multi_pw_aff
*mpa
, *res
;
5334 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5335 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5336 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5337 mpa
= mpa_un_tests
[i
].fn(mpa
);
5338 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5339 isl_multi_pw_aff_free(mpa
);
5340 isl_multi_pw_aff_free(res
);
5344 isl_die(ctx
, isl_error_unknown
,
5345 "unexpected result", return -1);
5351 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5352 * "fn" is the function that is tested.
5353 * "arg1" and "arg2" are string descriptions of the inputs.
5354 * "res" is a string description of the expected result.
5357 __isl_give isl_multi_pw_aff
*(*fn
)(
5358 __isl_take isl_multi_pw_aff
*mpa1
,
5359 __isl_take isl_multi_pw_aff
*mpa2
);
5363 } mpa_bin_tests
[] = {
5364 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
5366 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
5367 "{ A[x] -> [(x : x <= 10)] }",
5368 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5369 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5370 "{ A[x] -> [] : x <= 10 }",
5371 "{ A[x] -> [] : 5 <= x <= 10 }" },
5372 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5373 "[N] -> { A[x] -> [] : x <= N }",
5374 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5375 { &isl_multi_pw_aff_add
,
5376 "[N] -> { A[x] -> [] : x <= N }",
5377 "{ A[x] -> [] : x >= 5 }",
5378 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5379 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5380 "{ A[y] -> C[(2 : y <= 10)] }",
5381 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5382 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5383 "{ A[y] -> C[2] : y <= 10 }",
5384 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5385 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5386 "[N] -> { A[y] -> C[2] : y <= N }",
5387 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5388 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
5389 "{ A[y] -> C[2] : y <= 10 }",
5390 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5391 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5392 "{ A[] -> [B[1] -> C[2]] }" },
5393 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5394 "{ A[] -> [B[] -> C[]] }" },
5395 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5396 "{ A[y] -> C[] : y <= 10 }",
5397 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5398 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
5399 "{ A[x] -> B[(1 : x >= 5)] }",
5400 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5401 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5402 "{ A[y] -> C[(2 : y <= 10)] }",
5403 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5404 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5405 "{ A[y] -> C[] : y <= 10 }",
5406 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5407 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
5408 "{ A[x] -> B[(1 : x >= 5)] }",
5409 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5410 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5411 "[N] -> { A[y] -> C[] : y <= N }",
5412 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5413 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
5414 "{ A[x] -> B[(1 : x >= 5)] }",
5415 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5416 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
5417 "{ A[y] -> C[] : y <= 10 }",
5418 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5419 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5420 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5421 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5422 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5423 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5424 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5425 "{ A[a,b] -> C[b + 2a] }" },
5426 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5427 "{ B[i,j] -> C[i + 2j] }",
5428 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5429 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5430 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5431 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5432 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5433 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5434 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5435 "{ B[i,j] -> C[] }",
5436 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5437 "{ A[a,b] -> C[] }" },
5438 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5439 "{ B[i,j] -> C[] : i > j }",
5440 "{ A[a,b] -> B[b,a] }",
5441 "{ A[a,b] -> C[] : b > a }" },
5442 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5443 "{ B[i,j] -> C[] : j > 5 }",
5444 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5445 "{ A[a,b] -> C[] : b > a > 5 }" },
5446 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5447 "[N] -> { B[i,j] -> C[] : j > N }",
5448 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5449 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5450 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5451 "[M,N] -> { B[] -> C[] : N > 5 }",
5452 "[M,N] -> { A[] -> B[] : M > N }",
5453 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5456 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5458 static int test_bin_mpa(isl_ctx
*ctx
)
5462 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
5464 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
5465 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
5466 mpa_bin_tests
[i
].arg1
);
5467 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
5468 mpa_bin_tests
[i
].arg2
);
5469 res
= isl_multi_pw_aff_read_from_str(ctx
,
5470 mpa_bin_tests
[i
].res
);
5471 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
5472 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
5473 isl_multi_pw_aff_free(mpa1
);
5474 isl_multi_pw_aff_free(res
);
5478 isl_die(ctx
, isl_error_unknown
,
5479 "unexpected result", return -1);
5485 /* Inputs for basic tests of unary operations on
5486 * isl_multi_union_pw_aff objects.
5487 * "fn" is the function that is tested.
5488 * "arg" is a string description of the input.
5489 * "res" is a string description of the expected result.
5492 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5493 __isl_take isl_multi_union_pw_aff
*mupa
);
5496 } mupa_un_tests
[] = {
5497 { &isl_multi_union_pw_aff_factor_range
,
5498 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5499 "C[{ A[] -> [2] }]" },
5500 { &isl_multi_union_pw_aff_factor_range
,
5501 "[B[] -> C[{ A[] -> [2] }]]",
5502 "C[{ A[] -> [2] }]" },
5503 { &isl_multi_union_pw_aff_factor_range
,
5504 "[B[{ A[] -> [1] }] -> C[]]",
5506 { &isl_multi_union_pw_aff_factor_range
,
5509 { &isl_multi_union_pw_aff_factor_range
,
5510 "([B[] -> C[]] : { A[x] : x >= 0 })",
5511 "(C[] : { A[x] : x >= 0 })" },
5512 { &isl_multi_union_pw_aff_factor_range
,
5513 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
5514 "[N] -> (C[] : { A[x] : x <= N })" },
5515 { &isl_multi_union_pw_aff_factor_range
,
5516 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
5517 "[N] -> (C[] : { : N >= 0 })" },
5520 /* Perform some basic tests of unary operations on
5521 * isl_multi_union_pw_aff objects.
5523 static int test_un_mupa(isl_ctx
*ctx
)
5527 isl_multi_union_pw_aff
*mupa
, *res
;
5529 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
5530 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5531 mupa_un_tests
[i
].arg
);
5532 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5533 mupa_un_tests
[i
].res
);
5534 mupa
= mupa_un_tests
[i
].fn(mupa
);
5535 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5536 isl_multi_union_pw_aff_free(mupa
);
5537 isl_multi_union_pw_aff_free(res
);
5541 isl_die(ctx
, isl_error_unknown
,
5542 "unexpected result", return -1);
5548 /* Inputs for basic tests of binary operations on
5549 * isl_multi_union_pw_aff objects.
5550 * "fn" is the function that is tested.
5551 * "arg1" and "arg2" are string descriptions of the inputs.
5552 * "res" is a string description of the expected result.
5555 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5556 __isl_take isl_multi_union_pw_aff
*mupa1
,
5557 __isl_take isl_multi_union_pw_aff
*mupa2
);
5561 } mupa_bin_tests
[] = {
5562 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5563 "[{ A[] -> [3] }]" },
5564 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5565 "[{ A[] -> [-1] }]" },
5566 { &isl_multi_union_pw_aff_add
,
5567 "[{ A[] -> [1]; B[] -> [4] }]",
5568 "[{ A[] -> [2]; C[] -> [5] }]",
5569 "[{ A[] -> [3] }]" },
5570 { &isl_multi_union_pw_aff_union_add
,
5571 "[{ A[] -> [1]; B[] -> [4] }]",
5572 "[{ A[] -> [2]; C[] -> [5] }]",
5573 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
5574 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5575 "[{ A[x] -> [(x)] : x <= 10 }]",
5576 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
5577 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5578 "([] : { A[x] : x <= 10 })",
5579 "([] : { A[x] : 5 <= x <= 10 })" },
5580 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5581 "[N] -> ([] : { A[x] : x <= N })",
5582 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
5583 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
5584 "([] : { A[x] : x <= 10 })",
5585 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
5586 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5587 "[{ A[x] -> [(x)] : x <= 10 }]",
5588 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
5589 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
5590 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
5591 "([] : { A[x] : x <= 10 })",
5592 "([] : { A[x] })" },
5593 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
5594 "[N] -> ([] : { A[x] : x >= N })",
5595 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
5596 { &isl_multi_union_pw_aff_union_add
,
5597 "[N] -> ([] : { A[] : N >= 0})",
5598 "[N] -> ([] : { A[] : N <= 0})",
5599 "[N] -> ([] : { A[] })" },
5600 { &isl_multi_union_pw_aff_union_add
,
5601 "[N] -> ([] : { A[] })",
5602 "[N] -> ([] : { : })",
5603 "[N] -> ([] : { : })" },
5604 { &isl_multi_union_pw_aff_union_add
,
5605 "[N] -> ([] : { : })",
5606 "[N] -> ([] : { A[] })",
5607 "[N] -> ([] : { : })" },
5608 { &isl_multi_union_pw_aff_union_add
,
5609 "[N] -> ([] : { : N >= 0})",
5610 "[N] -> ([] : { : N <= 0})",
5611 "[N] -> ([] : { : })" },
5612 { &isl_multi_union_pw_aff_range_product
,
5613 "B[{ A[] -> [1] }]",
5614 "C[{ A[] -> [2] }]",
5615 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
5616 { &isl_multi_union_pw_aff_range_product
,
5617 "(B[] : { A[x] : x >= 5 })",
5618 "(C[] : { A[x] : x <= 10 })",
5619 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
5620 { &isl_multi_union_pw_aff_range_product
,
5621 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5622 "(C[] : { A[x] : x <= 10 })",
5623 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
5624 { &isl_multi_union_pw_aff_range_product
,
5625 "(C[] : { A[x] : x <= 10 })",
5626 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5627 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
5628 { &isl_multi_union_pw_aff_range_product
,
5629 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5630 "[N] -> (C[] : { A[x] : x <= N })",
5631 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
5632 { &isl_multi_union_pw_aff_range_product
,
5633 "[N] -> (C[] : { A[x] : x <= N })",
5634 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5635 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
5636 { &isl_multi_union_pw_aff_range_product
,
5637 "B[{ A[] -> [1]; D[] -> [3] }]",
5638 "C[{ A[] -> [2] }]",
5639 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
5640 { &isl_multi_union_pw_aff_range_product
,
5643 "([B[] -> C[]] : { A[x] })" },
5644 { &isl_multi_union_pw_aff_range_product
,
5647 "([B[] -> C[]] : { A[x] })" },
5650 /* Perform some basic tests of binary operations on
5651 * isl_multi_union_pw_aff objects.
5653 static int test_bin_mupa(isl_ctx
*ctx
)
5657 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
5659 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
5660 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
5661 mupa_bin_tests
[i
].arg1
);
5662 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
5663 mupa_bin_tests
[i
].arg2
);
5664 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5665 mupa_bin_tests
[i
].res
);
5666 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
5667 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
5668 isl_multi_union_pw_aff_free(mupa1
);
5669 isl_multi_union_pw_aff_free(res
);
5673 isl_die(ctx
, isl_error_unknown
,
5674 "unexpected result", return -1);
5680 /* Inputs for basic tests of binary operations on
5681 * pairs of isl_multi_union_pw_aff and isl_set objects.
5682 * "fn" is the function that is tested.
5683 * "arg1" and "arg2" are string descriptions of the inputs.
5684 * "res" is a string description of the expected result.
5687 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5688 __isl_take isl_multi_union_pw_aff
*mupa
,
5689 __isl_take isl_set
*set
);
5693 } mupa_set_tests
[] = {
5694 { &isl_multi_union_pw_aff_intersect_range
,
5695 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
5696 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
5697 { &isl_multi_union_pw_aff_intersect_range
,
5698 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
5699 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
5700 { &isl_multi_union_pw_aff_intersect_range
,
5701 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
5702 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
5703 { &isl_multi_union_pw_aff_intersect_range
,
5704 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
5705 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
5706 { &isl_multi_union_pw_aff_intersect_range
,
5707 "C[]", "{ C[] }", "C[]" },
5708 { &isl_multi_union_pw_aff_intersect_range
,
5709 "[N] -> (C[] : { : N >= 0 })",
5711 "[N] -> (C[] : { : N >= 0 })" },
5712 { &isl_multi_union_pw_aff_intersect_range
,
5713 "(C[] : { A[a,b] })",
5715 "(C[] : { A[a,b] })" },
5716 { &isl_multi_union_pw_aff_intersect_range
,
5717 "[N] -> (C[] : { A[a,b] : a,b <= N })",
5719 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
5720 { &isl_multi_union_pw_aff_intersect_range
,
5722 "[N] -> { C[] : N >= 0 }",
5723 "[N] -> (C[] : { : N >= 0 })" },
5724 { &isl_multi_union_pw_aff_intersect_range
,
5725 "(C[] : { A[a,b] })",
5726 "[N] -> { C[] : N >= 0 }",
5727 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5728 { &isl_multi_union_pw_aff_intersect_range
,
5729 "[N] -> (C[] : { : N >= 0 })",
5730 "[N] -> { C[] : N < 1024 }",
5731 "[N] -> (C[] : { : 0 <= N < 1024 })" },
5732 { &isl_multi_union_pw_aff_intersect_params
,
5733 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
5734 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
5735 { &isl_multi_union_pw_aff_intersect_params
,
5736 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
5737 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
5738 { &isl_multi_union_pw_aff_intersect_params
,
5739 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
5740 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
5741 { &isl_multi_union_pw_aff_intersect_params
,
5742 "C[]", "[N] -> { : N >= 0 }",
5743 "[N] -> (C[] : { : N >= 0 })" },
5744 { &isl_multi_union_pw_aff_intersect_params
,
5745 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
5746 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5747 { &isl_multi_union_pw_aff_intersect_params
,
5748 "[N] -> (C[] : { A[a,N] })", "{ : }",
5749 "[N] -> (C[] : { A[a,N] })" },
5750 { &isl_multi_union_pw_aff_intersect_params
,
5751 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
5752 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
5755 /* Perform some basic tests of binary operations on
5756 * pairs of isl_multi_union_pw_aff and isl_set objects.
5758 static int test_mupa_set(isl_ctx
*ctx
)
5762 isl_multi_union_pw_aff
*mupa
, *res
;
5765 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
5766 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5767 mupa_set_tests
[i
].arg1
);
5768 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
5769 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5770 mupa_set_tests
[i
].res
);
5771 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
5772 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5773 isl_multi_union_pw_aff_free(mupa
);
5774 isl_multi_union_pw_aff_free(res
);
5778 isl_die(ctx
, isl_error_unknown
,
5779 "unexpected result", return -1);
5785 /* Inputs for basic tests of binary operations on
5786 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5787 * "fn" is the function that is tested.
5788 * "arg1" and "arg2" are string descriptions of the inputs.
5789 * "res" is a string description of the expected result.
5792 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5793 __isl_take isl_multi_union_pw_aff
*mupa
,
5794 __isl_take isl_union_set
*uset
);
5798 } mupa_uset_tests
[] = {
5799 { &isl_multi_union_pw_aff_intersect_domain
,
5800 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
5801 "C[{ B[i,i] -> [3i] }]" },
5802 { &isl_multi_union_pw_aff_intersect_domain
,
5803 "(C[] : { B[i,j] })", "{ B[i,i] }",
5804 "(C[] : { B[i,i] })" },
5805 { &isl_multi_union_pw_aff_intersect_domain
,
5806 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
5807 "[N] -> (C[] : { B[N,N] })" },
5808 { &isl_multi_union_pw_aff_intersect_domain
,
5809 "C[]", "{ B[i,i] }",
5810 "(C[] : { B[i,i] })" },
5811 { &isl_multi_union_pw_aff_intersect_domain
,
5812 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
5813 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
5816 /* Perform some basic tests of binary operations on
5817 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5819 static int test_mupa_uset(isl_ctx
*ctx
)
5823 isl_multi_union_pw_aff
*mupa
, *res
;
5824 isl_union_set
*uset
;
5826 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
5827 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5828 mupa_uset_tests
[i
].arg1
);
5829 uset
= isl_union_set_read_from_str(ctx
,
5830 mupa_uset_tests
[i
].arg2
);
5831 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5832 mupa_uset_tests
[i
].res
);
5833 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
5834 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5835 isl_multi_union_pw_aff_free(mupa
);
5836 isl_multi_union_pw_aff_free(res
);
5840 isl_die(ctx
, isl_error_unknown
,
5841 "unexpected result", return -1);
5847 /* Inputs for basic tests of binary operations on
5848 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5849 * "fn" is the function that is tested.
5850 * "arg1" and "arg2" are string descriptions of the inputs.
5851 * "res" is a string description of the expected result.
5854 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5855 __isl_take isl_multi_union_pw_aff
*mupa
,
5856 __isl_take isl_multi_aff
*ma
);
5860 } mupa_ma_tests
[] = {
5861 { &isl_multi_union_pw_aff_apply_multi_aff
,
5862 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5863 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5864 "{ C[a,b] -> D[b,a] }",
5865 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
5866 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
5867 { &isl_multi_union_pw_aff_apply_multi_aff
,
5868 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
5869 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5870 "{ C[a,b] -> D[b,a] }",
5871 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
5872 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
5873 { &isl_multi_union_pw_aff_apply_multi_aff
,
5874 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5875 "[N] -> { C[a] -> D[a + N] }",
5876 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
5877 { &isl_multi_union_pw_aff_apply_multi_aff
,
5881 { &isl_multi_union_pw_aff_apply_multi_aff
,
5882 "[N] -> (C[] : { : N >= 0 })",
5884 "[N] -> (D[] : { : N >= 0 })" },
5885 { &isl_multi_union_pw_aff_apply_multi_aff
,
5887 "[N] -> { C[] -> D[N] }",
5888 "[N] -> D[{ [N] }]" },
5889 { &isl_multi_union_pw_aff_apply_multi_aff
,
5890 "(C[] : { A[i,j] : i >= j })",
5892 "(D[] : { A[i,j] : i >= j })" },
5893 { &isl_multi_union_pw_aff_apply_multi_aff
,
5894 "[N] -> (C[] : { A[i,j] : N >= 0 })",
5896 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
5897 { &isl_multi_union_pw_aff_apply_multi_aff
,
5898 "(C[] : { A[i,j] : i >= j })",
5899 "[N] -> { C[] -> D[N] }",
5900 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
5903 /* Perform some basic tests of binary operations on
5904 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5906 static int test_mupa_ma(isl_ctx
*ctx
)
5910 isl_multi_union_pw_aff
*mupa
, *res
;
5913 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
5914 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5915 mupa_ma_tests
[i
].arg1
);
5916 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
5917 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5918 mupa_ma_tests
[i
].res
);
5919 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
5920 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5921 isl_multi_union_pw_aff_free(mupa
);
5922 isl_multi_union_pw_aff_free(res
);
5926 isl_die(ctx
, isl_error_unknown
,
5927 "unexpected result", return -1);
5933 /* Inputs for basic tests of binary operations on
5934 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
5935 * "fn" is the function that is tested.
5936 * "arg1" and "arg2" are string descriptions of the inputs.
5937 * "res" is a string description of the expected result.
5940 __isl_give isl_union_pw_aff
*(*fn
)(
5941 __isl_take isl_multi_union_pw_aff
*mupa
,
5942 __isl_take isl_pw_aff
*pa
);
5946 } mupa_pa_tests
[] = {
5947 { &isl_multi_union_pw_aff_apply_pw_aff
,
5948 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5949 "[N] -> { C[a] -> [a + N] }",
5950 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
5951 { &isl_multi_union_pw_aff_apply_pw_aff
,
5952 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5953 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
5954 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
5955 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
5956 { &isl_multi_union_pw_aff_apply_pw_aff
,
5958 "[N] -> { C[] -> [N] }",
5960 { &isl_multi_union_pw_aff_apply_pw_aff
,
5962 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5963 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
5964 { &isl_multi_union_pw_aff_apply_pw_aff
,
5965 "[N] -> (C[] : { : N >= 0 })",
5966 "[N] -> { C[] -> [N] }",
5967 "[N] -> { [N] : N >= 0 }" },
5968 { &isl_multi_union_pw_aff_apply_pw_aff
,
5969 "[N] -> (C[] : { : N >= 0 })",
5970 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5971 "[N] -> { [N] : N >= 0 }" },
5972 { &isl_multi_union_pw_aff_apply_pw_aff
,
5973 "[N] -> (C[] : { : N >= 0 })",
5975 "[N] -> { [0] : N >= 0 }" },
5976 { &isl_multi_union_pw_aff_apply_pw_aff
,
5977 "(C[] : { A[i,j] : i >= j })",
5978 "[N] -> { C[] -> [N] }",
5979 "[N] -> { A[i,j] -> [N] : i >= j }" },
5980 { &isl_multi_union_pw_aff_apply_pw_aff
,
5981 "(C[] : { A[i,j] : i >= j })",
5982 "[N] -> { C[] -> [N] : N >= 0 }",
5983 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
5986 /* Perform some basic tests of binary operations on
5987 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
5989 static int test_mupa_pa(isl_ctx
*ctx
)
5993 isl_multi_union_pw_aff
*mupa
;
5994 isl_union_pw_aff
*upa
, *res
;
5997 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
5998 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5999 mupa_pa_tests
[i
].arg1
);
6000 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
6001 res
= isl_union_pw_aff_read_from_str(ctx
,
6002 mupa_pa_tests
[i
].res
);
6003 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
6004 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
6005 isl_union_pw_aff_free(upa
);
6006 isl_union_pw_aff_free(res
);
6010 isl_die(ctx
, isl_error_unknown
,
6011 "unexpected result", return -1);
6017 /* Inputs for basic tests of binary operations on
6018 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6019 * "fn" is the function that is tested.
6020 * "arg1" and "arg2" are string descriptions of the inputs.
6021 * "res" is a string description of the expected result.
6024 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6025 __isl_take isl_multi_union_pw_aff
*mupa
,
6026 __isl_take isl_pw_multi_aff
*pma
);
6030 } mupa_pma_tests
[] = {
6031 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6032 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6033 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6034 "{ C[a,b] -> D[b,a] }",
6035 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6036 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6037 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6038 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6039 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6040 "{ C[a,b] -> D[b,a] }",
6041 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6042 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6043 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6044 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6045 "[N] -> { C[a] -> D[a + N] }",
6046 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6047 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6048 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6049 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6050 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6051 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6052 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6053 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6054 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6055 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6056 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6057 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6058 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6059 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6060 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6064 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6065 "[N] -> (C[] : { : N >= 0 })",
6067 "[N] -> (D[] : { : N >= 0 })" },
6068 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6070 "[N] -> { C[] -> D[N] }",
6071 "[N] -> D[{ [N] }]" },
6072 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6073 "(C[] : { A[i,j] : i >= j })",
6075 "(D[] : { A[i,j] : i >= j })" },
6076 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6077 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6079 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6080 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6081 "(C[] : { A[i,j] : i >= j })",
6082 "[N] -> { C[] -> D[N] }",
6083 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6084 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6086 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6087 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6088 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6089 "[N] -> (C[] : { : N >= 0 })",
6090 "[N] -> { C[] -> D[N] }",
6091 "[N] -> D[{ [N] : N >= 0 }]" },
6092 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6093 "[N] -> (C[] : { : N >= 0 })",
6094 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6095 "[N] -> D[{ [N] : N >= 0 }]" },
6096 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6097 "[N] -> (C[] : { : N >= 0 })",
6099 "[N] -> D[{ [0] : N >= 0 }]" },
6100 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6101 "(C[] : { A[i,j] : i >= j })",
6102 "[N] -> { C[] -> D[N] : N >= 0 }",
6103 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6106 /* Perform some basic tests of binary operations on
6107 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6109 static int test_mupa_pma(isl_ctx
*ctx
)
6113 isl_multi_union_pw_aff
*mupa
, *res
;
6114 isl_pw_multi_aff
*pma
;
6116 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
6117 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6118 mupa_pma_tests
[i
].arg1
);
6119 pma
= isl_pw_multi_aff_read_from_str(ctx
,
6120 mupa_pma_tests
[i
].arg2
);
6121 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6122 mupa_pma_tests
[i
].res
);
6123 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
6124 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6125 isl_multi_union_pw_aff_free(mupa
);
6126 isl_multi_union_pw_aff_free(res
);
6130 isl_die(ctx
, isl_error_unknown
,
6131 "unexpected result", return -1);
6137 /* Inputs for basic tests of binary operations on
6138 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6139 * "fn" is the function that is tested.
6140 * "arg1" and "arg2" are string descriptions of the inputs.
6141 * "res" is a string description of the expected result.
6144 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6145 __isl_take isl_multi_union_pw_aff
*mupa
,
6146 __isl_take isl_union_pw_multi_aff
*upma
);
6150 } mupa_upma_tests
[] = {
6151 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6152 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6153 "C[{ A[a,b] -> [b + 2a] }]" },
6154 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6155 "C[{ B[i,j] -> [i + 2j] }]",
6156 "{ A[a,b] -> B[b,a] : b > a }",
6157 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6158 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6159 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6160 "{ A[a,b] -> B[b,a] : b > a }",
6161 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6162 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6163 "C[{ B[i,j] -> [i + 2j] }]",
6164 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6165 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6166 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6167 "(C[] : { B[a,b] })",
6168 "{ A[a,b] -> B[b,a] }",
6169 "(C[] : { A[a,b] })" },
6170 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6171 "(C[] : { B[a,b] })",
6172 "{ B[a,b] -> A[b,a] }",
6174 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6175 "(C[] : { B[a,b] })",
6176 "{ A[a,b] -> B[b,a] : a > b }",
6177 "(C[] : { A[a,b] : a > b })" },
6178 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6179 "(C[] : { B[a,b] : a > b })",
6180 "{ A[a,b] -> B[b,a] }",
6181 "(C[] : { A[a,b] : b > a })" },
6182 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6183 "[N] -> (C[] : { B[a,b] : a > N })",
6184 "{ A[a,b] -> B[b,a] : a > b }",
6185 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6186 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6187 "(C[] : { B[a,b] : a > b })",
6188 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6189 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6190 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6192 "{ A[a,b] -> B[b,a] }",
6194 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6195 "[N] -> (C[] : { : N >= 0 })",
6196 "{ A[a,b] -> B[b,a] }",
6197 "[N] -> (C[] : { : N >= 0 })" },
6198 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6200 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6201 "[N] -> (C[] : { : N >= 0 })" },
6204 /* Perform some basic tests of binary operations on
6205 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6207 static int test_mupa_upma(isl_ctx
*ctx
)
6211 isl_multi_union_pw_aff
*mupa
, *res
;
6212 isl_union_pw_multi_aff
*upma
;
6214 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
6215 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6216 mupa_upma_tests
[i
].arg1
);
6217 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
6218 mupa_upma_tests
[i
].arg2
);
6219 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6220 mupa_upma_tests
[i
].res
);
6221 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
6222 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6223 isl_multi_union_pw_aff_free(mupa
);
6224 isl_multi_union_pw_aff_free(res
);
6228 isl_die(ctx
, isl_error_unknown
,
6229 "unexpected result", return -1);
6235 /* Check that the input tuple of an isl_aff can be set properly.
6237 static isl_stat
test_aff_set_tuple_id(isl_ctx
*ctx
)
6243 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x + 1] }");
6244 id
= isl_id_alloc(ctx
, "A", NULL
);
6245 aff
= isl_aff_set_tuple_id(aff
, isl_dim_in
, id
);
6246 equal
= aff_check_plain_equal(aff
, "{ A[x] -> [x + 1] }");
6249 return isl_stat_error
;
6254 int test_aff(isl_ctx
*ctx
)
6259 isl_local_space
*ls
;
6263 if (test_upa(ctx
) < 0)
6265 if (test_bin_aff(ctx
) < 0)
6267 if (test_bin_pw_aff(ctx
) < 0)
6269 if (test_bin_upma(ctx
) < 0)
6271 if (test_bin_upma_fail(ctx
) < 0)
6273 if (test_un_mpa(ctx
) < 0)
6275 if (test_bin_mpa(ctx
) < 0)
6277 if (test_un_mupa(ctx
) < 0)
6279 if (test_bin_mupa(ctx
) < 0)
6281 if (test_mupa_set(ctx
) < 0)
6283 if (test_mupa_uset(ctx
) < 0)
6285 if (test_mupa_ma(ctx
) < 0)
6287 if (test_mupa_pa(ctx
) < 0)
6289 if (test_mupa_pma(ctx
) < 0)
6291 if (test_mupa_upma(ctx
) < 0)
6294 space
= isl_space_set_alloc(ctx
, 0, 1);
6295 ls
= isl_local_space_from_space(space
);
6296 aff
= isl_aff_zero_on_domain(ls
);
6298 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6299 aff
= isl_aff_scale_down_ui(aff
, 3);
6300 aff
= isl_aff_floor(aff
);
6301 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6302 aff
= isl_aff_scale_down_ui(aff
, 2);
6303 aff
= isl_aff_floor(aff
);
6304 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6307 set
= isl_set_read_from_str(ctx
, str
);
6308 aff
= isl_aff_gist(aff
, set
);
6310 aff
= isl_aff_add_constant_si(aff
, -16);
6311 zero
= isl_aff_plain_is_zero(aff
);
6317 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6319 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6320 aff
= isl_aff_scale_down_ui(aff
, 64);
6321 aff
= isl_aff_floor(aff
);
6322 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6327 if (test_aff_set_tuple_id(ctx
) < 0)
6333 /* Check that "pa" consists of a single expression.
6335 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
6339 n
= isl_pw_aff_n_piece(pa
);
6340 isl_pw_aff_free(pa
);
6345 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
6351 /* Check that the computation below results in a single expression.
6352 * One or two expressions may result depending on which constraint
6353 * ends up being considered as redundant with respect to the other
6354 * constraints after the projection that is performed internally
6355 * by isl_set_dim_min.
6357 static int test_dim_max_1(isl_ctx
*ctx
)
6363 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
6364 "-4a <= b <= 3 and b < n - 4a }";
6365 set
= isl_set_read_from_str(ctx
, str
);
6366 pa
= isl_set_dim_min(set
, 0);
6367 return check_single_piece(ctx
, pa
);
6370 /* Check that the computation below results in a single expression.
6371 * The PIP problem corresponding to these constraints has a row
6372 * that causes a split of the solution domain. The solver should
6373 * first pick rows that split off empty parts such that the actual
6374 * solution domain does not get split.
6375 * Note that the description contains some redundant constraints.
6376 * If these constraints get removed first, then the row mentioned
6377 * above does not appear in the PIP problem.
6379 static int test_dim_max_2(isl_ctx
*ctx
)
6385 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
6386 "N > 0 and P >= 0 }";
6387 set
= isl_set_read_from_str(ctx
, str
);
6388 pa
= isl_set_dim_max(set
, 0);
6389 return check_single_piece(ctx
, pa
);
6392 int test_dim_max(isl_ctx
*ctx
)
6396 isl_set
*set1
, *set2
;
6401 if (test_dim_max_1(ctx
) < 0)
6403 if (test_dim_max_2(ctx
) < 0)
6406 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
6407 set
= isl_set_read_from_str(ctx
, str
);
6408 pwaff
= isl_set_dim_max(set
, 0);
6409 set1
= isl_set_from_pw_aff(pwaff
);
6410 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
6411 set2
= isl_set_read_from_str(ctx
, str
);
6412 equal
= isl_set_is_equal(set1
, set2
);
6418 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6420 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
6421 set
= isl_set_read_from_str(ctx
, str
);
6422 pwaff
= isl_set_dim_max(set
, 0);
6423 set1
= isl_set_from_pw_aff(pwaff
);
6424 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6425 set2
= isl_set_read_from_str(ctx
, str
);
6426 equal
= isl_set_is_equal(set1
, set2
);
6432 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6434 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
6435 set
= isl_set_read_from_str(ctx
, str
);
6436 pwaff
= isl_set_dim_max(set
, 0);
6437 set1
= isl_set_from_pw_aff(pwaff
);
6438 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6439 set2
= isl_set_read_from_str(ctx
, str
);
6440 equal
= isl_set_is_equal(set1
, set2
);
6446 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6448 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
6449 "0 <= i < N and 0 <= j < M }";
6450 map
= isl_map_read_from_str(ctx
, str
);
6451 set
= isl_map_range(map
);
6453 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
6454 set1
= isl_set_from_pw_aff(pwaff
);
6455 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
6456 set2
= isl_set_read_from_str(ctx
, str
);
6457 equal
= isl_set_is_equal(set1
, set2
);
6461 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
6462 set1
= isl_set_from_pw_aff(pwaff
);
6463 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
6464 set2
= isl_set_read_from_str(ctx
, str
);
6465 if (equal
>= 0 && equal
)
6466 equal
= isl_set_is_equal(set1
, set2
);
6475 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6477 /* Check that solutions are properly merged. */
6478 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
6479 "c <= -1 + n - 4a - 2b and c >= -2b and "
6480 "4a >= -4 + n and c >= 0 }";
6481 set
= isl_set_read_from_str(ctx
, str
);
6482 pwaff
= isl_set_dim_min(set
, 2);
6483 set1
= isl_set_from_pw_aff(pwaff
);
6484 str
= "[n] -> { [(0)] : n >= 1 }";
6485 set2
= isl_set_read_from_str(ctx
, str
);
6486 equal
= isl_set_is_equal(set1
, set2
);
6493 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6495 /* Check that empty solution lie in the right space. */
6496 str
= "[n] -> { [t,a] : 1 = 0 }";
6497 set
= isl_set_read_from_str(ctx
, str
);
6498 pwaff
= isl_set_dim_max(set
, 0);
6499 set1
= isl_set_from_pw_aff(pwaff
);
6500 str
= "[n] -> { [t] : 1 = 0 }";
6501 set2
= isl_set_read_from_str(ctx
, str
);
6502 equal
= isl_set_is_equal(set1
, set2
);
6509 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6514 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
6516 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
6520 isl_pw_multi_aff
*pma2
;
6526 ctx
= isl_pw_multi_aff_get_ctx(pma
);
6527 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6528 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
6529 isl_pw_multi_aff_free(pma2
);
6534 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
6535 * represented by "str".
6537 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
6542 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
6546 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
6547 "result not as expected", return -1);
6551 /* Basic test for isl_pw_multi_aff_product.
6553 * Check that multiple pieces are properly handled.
6555 static int test_product_pma(isl_ctx
*ctx
)
6559 isl_pw_multi_aff
*pma1
, *pma2
;
6561 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
6562 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6563 str
= "{ C[] -> D[] }";
6564 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6565 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
6566 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
6567 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
6568 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
6569 isl_pw_multi_aff_free(pma1
);
6576 int test_product(isl_ctx
*ctx
)
6580 isl_union_set
*uset1
, *uset2
;
6584 set
= isl_set_read_from_str(ctx
, str
);
6585 set
= isl_set_product(set
, isl_set_copy(set
));
6586 ok
= isl_set_is_wrapping(set
);
6591 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6594 uset1
= isl_union_set_read_from_str(ctx
, str
);
6595 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
6596 str
= "{ [[] -> []] }";
6597 uset2
= isl_union_set_read_from_str(ctx
, str
);
6598 ok
= isl_union_set_is_equal(uset1
, uset2
);
6599 isl_union_set_free(uset1
);
6600 isl_union_set_free(uset2
);
6604 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6606 if (test_product_pma(ctx
) < 0)
6612 /* Check that two sets are not considered disjoint just because
6613 * they have a different set of (named) parameters.
6615 static int test_disjoint(isl_ctx
*ctx
)
6618 isl_set
*set
, *set2
;
6621 str
= "[n] -> { [[]->[]] }";
6622 set
= isl_set_read_from_str(ctx
, str
);
6623 str
= "{ [[]->[]] }";
6624 set2
= isl_set_read_from_str(ctx
, str
);
6625 disjoint
= isl_set_is_disjoint(set
, set2
);
6631 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6636 /* Inputs for isl_pw_multi_aff_is_equal tests.
6637 * "f1" and "f2" are the two function that need to be compared.
6638 * "equal" is the expected result.
6644 } pma_equal_tests
[] = {
6645 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
6646 "[N] -> { [0] : 0 <= N <= 1 }" },
6647 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6648 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
6649 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6650 "[N] -> { [0] : 0 <= N <= 1 }" },
6651 { 0, "{ [NaN] }", "{ [NaN] }" },
6654 int test_equal(isl_ctx
*ctx
)
6658 isl_set
*set
, *set2
;
6662 set
= isl_set_read_from_str(ctx
, str
);
6664 set2
= isl_set_read_from_str(ctx
, str
);
6665 equal
= isl_set_is_equal(set
, set2
);
6671 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6673 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
6674 int expected
= pma_equal_tests
[i
].equal
;
6675 isl_pw_multi_aff
*f1
, *f2
;
6677 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
6678 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
6679 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
6680 isl_pw_multi_aff_free(f1
);
6681 isl_pw_multi_aff_free(f2
);
6684 if (equal
!= expected
)
6685 isl_die(ctx
, isl_error_unknown
,
6686 "unexpected equality result", return -1);
6692 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
6693 enum isl_dim_type type
, unsigned pos
, int fixed
)
6697 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
6704 isl_die(ctx
, isl_error_unknown
,
6705 "map not detected as fixed", return -1);
6707 isl_die(ctx
, isl_error_unknown
,
6708 "map detected as fixed", return -1);
6711 int test_fixed(isl_ctx
*ctx
)
6716 str
= "{ [i] -> [i] }";
6717 map
= isl_map_read_from_str(ctx
, str
);
6718 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
6720 str
= "{ [i] -> [1] }";
6721 map
= isl_map_read_from_str(ctx
, str
);
6722 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6724 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
6725 map
= isl_map_read_from_str(ctx
, str
);
6726 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6728 map
= isl_map_read_from_str(ctx
, str
);
6729 map
= isl_map_neg(map
);
6730 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6736 struct isl_vertices_test_data
{
6739 const char *vertex
[6];
6740 } vertices_tests
[] = {
6741 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
6742 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
6743 { "{ A[t, i] : t = 14 and i = 1 }",
6744 1, { "{ A[14, 1] }" } },
6745 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
6746 "c <= m and m <= n and m > 0 }",
6748 "[n, m] -> { [n, m, m] : 0 < m <= n }",
6749 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
6750 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
6751 "[n, m] -> { [m, m, m] : 0 < m <= n }",
6752 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
6753 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
6757 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
6759 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
6761 struct isl_vertices_test_data
*data
= user
;
6764 isl_basic_set
*bset
;
6765 isl_pw_multi_aff
*pma
;
6769 ctx
= isl_vertex_get_ctx(vertex
);
6770 bset
= isl_vertex_get_domain(vertex
);
6771 ma
= isl_vertex_get_expr(vertex
);
6772 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
6774 for (i
= 0; i
< data
->n
; ++i
) {
6775 isl_pw_multi_aff
*pma_i
;
6777 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
6778 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
6779 isl_pw_multi_aff_free(pma_i
);
6781 if (equal
< 0 || equal
)
6785 isl_pw_multi_aff_free(pma
);
6786 isl_vertex_free(vertex
);
6789 return isl_stat_error
;
6791 return equal
? isl_stat_ok
: isl_stat_error
;
6794 int test_vertices(isl_ctx
*ctx
)
6798 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
6799 isl_basic_set
*bset
;
6800 isl_vertices
*vertices
;
6804 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
6805 vertices
= isl_basic_set_compute_vertices(bset
);
6806 n
= isl_vertices_get_n_vertices(vertices
);
6807 if (vertices_tests
[i
].n
!= n
)
6809 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
6810 &vertices_tests
[i
]) < 0)
6812 isl_vertices_free(vertices
);
6813 isl_basic_set_free(bset
);
6818 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
6825 int test_union_pw(isl_ctx
*ctx
)
6829 isl_union_set
*uset
;
6830 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
6832 str
= "{ [x] -> x^2 }";
6833 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
6834 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
6835 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
6836 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
6837 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
6838 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
6839 isl_union_pw_qpolynomial_free(upwqp1
);
6840 isl_union_pw_qpolynomial_free(upwqp2
);
6844 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6849 /* Inputs for basic tests of functions that select
6850 * subparts of the domain of an isl_multi_union_pw_aff.
6851 * "fn" is the function that is tested.
6852 * "arg" is a string description of the input.
6853 * "res" is a string description of the expected result.
6856 __isl_give isl_union_set
*(*fn
)(
6857 __isl_take isl_multi_union_pw_aff
*mupa
);
6860 } un_locus_tests
[] = {
6861 { &isl_multi_union_pw_aff_zero_union_set
,
6862 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6863 "{ A[0,j]; B[0,j] }" },
6864 { &isl_multi_union_pw_aff_zero_union_set
,
6865 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
6866 "{ A[i,i]; B[i,i] : i >= 0 }" },
6867 { &isl_multi_union_pw_aff_zero_union_set
,
6868 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
6869 "{ A[i,j]; B[i,i] : i >= 0 }" },
6872 /* Perform some basic tests of functions that select
6873 * subparts of the domain of an isl_multi_union_pw_aff.
6875 static int test_un_locus(isl_ctx
*ctx
)
6879 isl_union_set
*uset
, *res
;
6880 isl_multi_union_pw_aff
*mupa
;
6882 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
6883 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6884 un_locus_tests
[i
].arg
);
6885 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
6886 uset
= un_locus_tests
[i
].fn(mupa
);
6887 ok
= isl_union_set_is_equal(uset
, res
);
6888 isl_union_set_free(uset
);
6889 isl_union_set_free(res
);
6893 isl_die(ctx
, isl_error_unknown
,
6894 "unexpected result", return -1);
6900 /* Inputs for basic tests of functions that select
6901 * subparts of an isl_union_map based on a relation
6902 * specified by an isl_multi_union_pw_aff.
6903 * "fn" is the function that is tested.
6904 * "arg1" and "arg2" are string descriptions of the inputs.
6905 * "res" is a string description of the expected result.
6908 __isl_give isl_union_map
*(*fn
)(
6909 __isl_take isl_union_map
*umap
,
6910 __isl_take isl_multi_union_pw_aff
*mupa
);
6914 } bin_locus_tests
[] = {
6915 { &isl_union_map_eq_at_multi_union_pw_aff
,
6916 "{ A[i,j] -> B[i',j'] }",
6917 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6918 "{ A[i,j] -> B[i,j'] }" },
6919 { &isl_union_map_eq_at_multi_union_pw_aff
,
6920 "{ A[i,j] -> B[i',j'] }",
6921 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6922 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6923 "{ A[i,j] -> B[i,j] }" },
6924 { &isl_union_map_eq_at_multi_union_pw_aff
,
6925 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6926 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6927 "{ A[i,j] -> B[i,j'] }" },
6928 { &isl_union_map_eq_at_multi_union_pw_aff
,
6929 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6930 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
6931 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
6932 { &isl_union_map_eq_at_multi_union_pw_aff
,
6933 "{ A[i,j] -> B[i',j'] }",
6934 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
6935 "{ A[i,j] -> B[i,j'] : i > j }" },
6936 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
6937 "{ A[i,j] -> B[i',j'] }",
6938 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6939 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6940 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
6941 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
6942 "{ A[i,j] -> B[i',j'] }",
6943 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6944 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6945 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
6946 { &isl_union_map_eq_at_multi_union_pw_aff
,
6947 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6948 "(F[] : { A[i,j]; B[i,j] })",
6949 "{ A[i,j] -> B[i',j'] }" },
6950 { &isl_union_map_eq_at_multi_union_pw_aff
,
6951 "{ A[i,j] -> B[i',j'] }",
6952 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6953 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
6954 { &isl_union_map_eq_at_multi_union_pw_aff
,
6955 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
6956 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6957 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
6958 { &isl_union_map_eq_at_multi_union_pw_aff
,
6959 "{ A[i,j] -> B[i',j'] }",
6960 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
6961 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
6962 { &isl_union_map_eq_at_multi_union_pw_aff
,
6963 "{ A[i,j] -> B[i',j'] }",
6964 "[N] -> (F[] : { : N >= 0 })",
6965 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
6968 /* Perform some basic tests of functions that select
6969 * subparts of an isl_union_map based on a relation
6970 * specified by an isl_multi_union_pw_aff.
6972 static int test_bin_locus(isl_ctx
*ctx
)
6976 isl_union_map
*umap
, *res
;
6977 isl_multi_union_pw_aff
*mupa
;
6979 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
6980 umap
= isl_union_map_read_from_str(ctx
,
6981 bin_locus_tests
[i
].arg1
);
6982 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6983 bin_locus_tests
[i
].arg2
);
6984 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
6985 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
6986 ok
= isl_union_map_is_equal(umap
, res
);
6987 isl_union_map_free(umap
);
6988 isl_union_map_free(res
);
6992 isl_die(ctx
, isl_error_unknown
,
6993 "unexpected result", return -1);
6999 /* Perform basic locus tests.
7001 static int test_locus(isl_ctx
*ctx
)
7003 if (test_un_locus(ctx
) < 0)
7005 if (test_bin_locus(ctx
) < 0)
7010 /* Test that isl_union_pw_qpolynomial_eval picks up the function
7011 * defined over the correct domain space.
7013 static int test_eval_1(isl_ctx
*ctx
)
7018 isl_union_pw_qpolynomial
*upwqp
;
7022 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
7023 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
7025 set
= isl_set_read_from_str(ctx
, str
);
7026 pnt
= isl_set_sample_point(set
);
7027 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
7028 cmp
= isl_val_cmp_si(v
, 36);
7034 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
7039 /* Check that isl_qpolynomial_eval handles getting called on a void point.
7041 static int test_eval_2(isl_ctx
*ctx
)
7046 isl_qpolynomial
*qp
;
7050 str
= "{ A[x] -> [x] }";
7051 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
7052 str
= "{ A[x] : false }";
7053 set
= isl_set_read_from_str(ctx
, str
);
7054 pnt
= isl_set_sample_point(set
);
7055 v
= isl_qpolynomial_eval(qp
, pnt
);
7056 ok
= isl_val_is_nan(v
);
7062 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
7067 /* Inputs for isl_pw_aff_eval test.
7068 * "f" is the affine function.
7069 * "p" is the point where the function should be evaluated.
7070 * "res" is the expected result.
7076 } aff_eval_tests
[] = {
7077 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
7078 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
7079 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
7080 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
7081 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
7082 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
7083 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
7084 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
7085 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
7086 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
7087 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
7088 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
7089 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
7090 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
7091 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
7092 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
7093 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
7094 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
7095 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
7096 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
7097 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
7098 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
7099 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
7102 /* Perform basic isl_pw_aff_eval tests.
7104 static int test_eval_aff(isl_ctx
*ctx
)
7108 for (i
= 0; i
< ARRAY_SIZE(aff_eval_tests
); ++i
) {
7115 pa
= isl_pw_aff_read_from_str(ctx
, aff_eval_tests
[i
].f
);
7116 set
= isl_set_read_from_str(ctx
, aff_eval_tests
[i
].p
);
7117 pnt
= isl_set_sample_point(set
);
7118 v
= isl_pw_aff_eval(pa
, pnt
);
7119 r
= val_check_equal(v
, aff_eval_tests
[i
].res
);
7127 /* Perform basic evaluation tests.
7129 static int test_eval(isl_ctx
*ctx
)
7131 if (test_eval_1(ctx
) < 0)
7133 if (test_eval_2(ctx
) < 0)
7135 if (test_eval_aff(ctx
) < 0)
7140 /* Descriptions of sets that are tested for reparsing after printing.
7142 const char *output_tests
[] = {
7143 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
7146 "{ [x] : x mod 2 = 0 }",
7147 "{ [x] : x mod 2 = 1 }",
7148 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
7149 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
7150 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
7151 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
7152 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
7153 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
7156 /* Check that printing a set and reparsing a set from the printed output
7157 * results in the same set.
7159 static int test_output_set(isl_ctx
*ctx
)
7163 isl_set
*set1
, *set2
;
7166 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
7167 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
7168 str
= isl_set_to_str(set1
);
7169 set2
= isl_set_read_from_str(ctx
, str
);
7171 equal
= isl_set_is_equal(set1
, set2
);
7177 isl_die(ctx
, isl_error_unknown
,
7178 "parsed output not the same", return -1);
7184 /* Check that an isl_multi_aff is printed using a consistent space.
7186 static isl_stat
test_output_ma(isl_ctx
*ctx
)
7191 isl_multi_aff
*ma
, *ma2
;
7193 ma
= isl_multi_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
7194 aff
= isl_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
7195 ma
= isl_multi_aff_set_aff(ma
, 0, aff
);
7196 str
= isl_multi_aff_to_str(ma
);
7197 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
7199 equal
= isl_multi_aff_plain_is_equal(ma
, ma2
);
7200 isl_multi_aff_free(ma2
);
7201 isl_multi_aff_free(ma
);
7204 return isl_stat_error
;
7206 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7207 return isl_stat_error
);
7212 /* Check that an isl_multi_pw_aff is printed using a consistent space.
7214 static isl_stat
test_output_mpa(isl_ctx
*ctx
)
7219 isl_multi_pw_aff
*mpa
, *mpa2
;
7221 mpa
= isl_multi_pw_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
7222 pa
= isl_pw_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
7223 mpa
= isl_multi_pw_aff_set_pw_aff(mpa
, 0, pa
);
7224 str
= isl_multi_pw_aff_to_str(mpa
);
7225 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
7227 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
7228 isl_multi_pw_aff_free(mpa2
);
7229 isl_multi_pw_aff_free(mpa
);
7232 return isl_stat_error
;
7234 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7235 return isl_stat_error
);
7240 int test_output(isl_ctx
*ctx
)
7248 if (test_output_set(ctx
) < 0)
7250 if (test_output_ma(ctx
) < 0)
7252 if (test_output_mpa(ctx
) < 0)
7255 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
7256 pa
= isl_pw_aff_read_from_str(ctx
, str
);
7258 p
= isl_printer_to_str(ctx
);
7259 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
7260 p
= isl_printer_print_pw_aff(p
, pa
);
7261 s
= isl_printer_get_str(p
);
7262 isl_printer_free(p
);
7263 isl_pw_aff_free(pa
);
7267 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
7272 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7277 int test_sample(isl_ctx
*ctx
)
7280 isl_basic_set
*bset1
, *bset2
;
7283 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
7284 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
7285 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
7286 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
7287 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
7288 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
7289 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
7290 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
7291 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
7292 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
7293 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
7294 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
7295 "d - 1073741821e and "
7296 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
7297 "3j >= 1 - a + b + 2e and "
7298 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
7299 "3i <= 4 - a + 4b - e and "
7300 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
7301 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
7302 "c <= -1 + a and 3i >= -2 - a + 3e and "
7303 "1073741822e <= 1073741823 - a + 1073741822b + c and "
7304 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
7305 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
7306 "1073741823e >= 1 + 1073741823b - d and "
7307 "3i >= 1073741823b + c - 1073741823e - f and "
7308 "3i >= 1 + 2b + e + 3g }";
7309 bset1
= isl_basic_set_read_from_str(ctx
, str
);
7310 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
7311 empty
= isl_basic_set_is_empty(bset2
);
7312 subset
= isl_basic_set_is_subset(bset2
, bset1
);
7313 isl_basic_set_free(bset1
);
7314 isl_basic_set_free(bset2
);
7315 if (empty
< 0 || subset
< 0)
7318 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
7320 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
7325 int test_fixed_power(isl_ctx
*ctx
)
7332 str
= "{ [i] -> [i + 1] }";
7333 map
= isl_map_read_from_str(ctx
, str
);
7334 exp
= isl_val_int_from_si(ctx
, 23);
7335 map
= isl_map_fixed_power_val(map
, exp
);
7336 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
7344 int test_slice(isl_ctx
*ctx
)
7350 str
= "{ [i] -> [j] }";
7351 map
= isl_map_read_from_str(ctx
, str
);
7352 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7353 equal
= map_check_equal(map
, "{ [i] -> [i] }");
7358 str
= "{ [i] -> [j] }";
7359 map
= isl_map_read_from_str(ctx
, str
);
7360 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7361 equal
= map_check_equal(map
, "{ [i] -> [j] }");
7366 str
= "{ [i] -> [j] }";
7367 map
= isl_map_read_from_str(ctx
, str
);
7368 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7369 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
7374 str
= "{ [i] -> [j] }";
7375 map
= isl_map_read_from_str(ctx
, str
);
7376 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7377 equal
= map_check_equal(map
, "{ [0] -> [j] }");
7382 str
= "{ [i] -> [j] }";
7383 map
= isl_map_read_from_str(ctx
, str
);
7384 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7385 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
7390 str
= "{ [i] -> [j] }";
7391 map
= isl_map_read_from_str(ctx
, str
);
7392 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7393 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
7401 int test_eliminate(isl_ctx
*ctx
)
7407 str
= "{ [i] -> [j] : i = 2j }";
7408 map
= isl_map_read_from_str(ctx
, str
);
7409 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
7410 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
7418 /* Check that isl_set_dim_residue_class detects that the values of j
7419 * in the set below are all odd and that it does not detect any spurious
7422 static int test_residue_class(isl_ctx
*ctx
)
7429 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
7430 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
7431 set
= isl_set_read_from_str(ctx
, str
);
7434 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
7436 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
7437 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
7438 res
= isl_stat_error
);
7446 static int test_align_parameters_1(isl_ctx
*ctx
)
7450 isl_multi_aff
*ma1
, *ma2
;
7453 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
7454 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
7456 space
= isl_space_params_alloc(ctx
, 1);
7457 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
7458 ma1
= isl_multi_aff_align_params(ma1
, space
);
7460 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
7461 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
7463 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
7465 isl_multi_aff_free(ma1
);
7466 isl_multi_aff_free(ma2
);
7471 isl_die(ctx
, isl_error_unknown
,
7472 "result not as expected", return -1);
7477 /* Check the isl_multi_*_from_*_list operation in case inputs
7478 * have unaligned parameters.
7479 * In particular, older versions of isl would simply fail
7480 * (without printing any error message).
7482 static isl_stat
test_align_parameters_2(isl_ctx
*ctx
)
7489 map
= isl_map_read_from_str(ctx
, "{ A[] -> M[x] }");
7490 space
= isl_map_get_space(map
);
7493 aff
= isl_aff_read_from_str(ctx
, "[N] -> { A[] -> [N] }");
7494 ma
= isl_multi_aff_from_aff_list(space
, isl_aff_list_from_aff(aff
));
7495 isl_multi_aff_free(ma
);
7498 return isl_stat_error
;
7502 /* Perform basic parameter alignment tests.
7504 static int test_align_parameters(isl_ctx
*ctx
)
7506 if (test_align_parameters_1(ctx
) < 0)
7508 if (test_align_parameters_2(ctx
) < 0)
7514 /* Check that isl_*_drop_unused_params actually drops the unused parameters
7515 * by comparing the result using isl_*_plain_is_equal.
7516 * Note that this assumes that isl_*_plain_is_equal does not consider
7517 * objects that only differ by unused parameters to be equal.
7519 int test_drop_unused_parameters(isl_ctx
*ctx
)
7521 const char *str_with
, *str_without
;
7522 isl_basic_set
*bset1
, *bset2
;
7523 isl_set
*set1
, *set2
;
7524 isl_pw_aff
*pwa1
, *pwa2
;
7527 str_with
= "[n, m, o] -> { [m] }";
7528 str_without
= "[m] -> { [m] }";
7530 bset1
= isl_basic_set_read_from_str(ctx
, str_with
);
7531 bset2
= isl_basic_set_read_from_str(ctx
, str_without
);
7532 bset1
= isl_basic_set_drop_unused_params(bset1
);
7533 equal
= isl_basic_set_plain_is_equal(bset1
, bset2
);
7534 isl_basic_set_free(bset1
);
7535 isl_basic_set_free(bset2
);
7540 isl_die(ctx
, isl_error_unknown
,
7541 "result not as expected", return -1);
7543 set1
= isl_set_read_from_str(ctx
, str_with
);
7544 set2
= isl_set_read_from_str(ctx
, str_without
);
7545 set1
= isl_set_drop_unused_params(set1
);
7546 equal
= isl_set_plain_is_equal(set1
, set2
);
7553 isl_die(ctx
, isl_error_unknown
,
7554 "result not as expected", return -1);
7556 pwa1
= isl_pw_aff_read_from_str(ctx
, str_with
);
7557 pwa2
= isl_pw_aff_read_from_str(ctx
, str_without
);
7558 pwa1
= isl_pw_aff_drop_unused_params(pwa1
);
7559 equal
= isl_pw_aff_plain_is_equal(pwa1
, pwa2
);
7560 isl_pw_aff_free(pwa1
);
7561 isl_pw_aff_free(pwa2
);
7566 isl_die(ctx
, isl_error_unknown
,
7567 "result not as expected", return -1);
7572 static int test_list(isl_ctx
*ctx
)
7574 isl_id
*a
, *b
, *c
, *d
, *id
;
7578 a
= isl_id_alloc(ctx
, "a", NULL
);
7579 b
= isl_id_alloc(ctx
, "b", NULL
);
7580 c
= isl_id_alloc(ctx
, "c", NULL
);
7581 d
= isl_id_alloc(ctx
, "d", NULL
);
7583 list
= isl_id_list_alloc(ctx
, 4);
7584 list
= isl_id_list_add(list
, b
);
7585 list
= isl_id_list_insert(list
, 0, a
);
7586 list
= isl_id_list_add(list
, c
);
7587 list
= isl_id_list_add(list
, d
);
7588 list
= isl_id_list_drop(list
, 1, 1);
7592 if (isl_id_list_n_id(list
) != 3) {
7593 isl_id_list_free(list
);
7594 isl_die(ctx
, isl_error_unknown
,
7595 "unexpected number of elements in list", return -1);
7598 id
= isl_id_list_get_id(list
, 0);
7601 id
= isl_id_list_get_id(list
, 1);
7604 id
= isl_id_list_get_id(list
, 2);
7608 isl_id_list_free(list
);
7611 isl_die(ctx
, isl_error_unknown
,
7612 "unexpected elements in list", return -1);
7617 const char *set_conversion_tests
[] = {
7618 "[N] -> { [i] : N - 1 <= 2 i <= N }",
7619 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
7620 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7621 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7622 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
7623 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
7624 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
7625 "-3 + c <= d <= 28 + c) }",
7628 /* Check that converting from isl_set to isl_pw_multi_aff and back
7629 * to isl_set produces the original isl_set.
7631 static int test_set_conversion(isl_ctx
*ctx
)
7635 isl_set
*set1
, *set2
;
7636 isl_pw_multi_aff
*pma
;
7639 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
7640 str
= set_conversion_tests
[i
];
7641 set1
= isl_set_read_from_str(ctx
, str
);
7642 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
7643 set2
= isl_set_from_pw_multi_aff(pma
);
7644 equal
= isl_set_is_equal(set1
, set2
);
7651 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7658 const char *conversion_tests
[] = {
7659 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7660 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7661 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7662 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7664 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7665 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7666 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7669 /* Check that converting from isl_map to isl_pw_multi_aff and back
7670 * to isl_map produces the original isl_map.
7672 static int test_map_conversion(isl_ctx
*ctx
)
7675 isl_map
*map1
, *map2
;
7676 isl_pw_multi_aff
*pma
;
7679 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
7680 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
7681 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
7682 map2
= isl_map_from_pw_multi_aff(pma
);
7683 equal
= isl_map_is_equal(map1
, map2
);
7690 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7697 /* Descriptions of isl_pw_multi_aff objects for testing conversion
7698 * to isl_multi_pw_aff and back.
7700 const char *mpa_conversion_tests
[] = {
7702 "{ [x] -> A[x] : x >= 0 }",
7703 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
7704 "{ [x] -> A[x, x + 1] }",
7706 "{ [x] -> A[] : x >= 0 }",
7709 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
7710 * back to isl_pw_multi_aff preserves the original meaning.
7712 static int test_mpa_conversion(isl_ctx
*ctx
)
7715 isl_pw_multi_aff
*pma1
, *pma2
;
7716 isl_multi_pw_aff
*mpa
;
7719 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
7721 str
= mpa_conversion_tests
[i
];
7722 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7723 pma2
= isl_pw_multi_aff_copy(pma1
);
7724 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
7725 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
7726 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
7727 isl_pw_multi_aff_free(pma1
);
7728 isl_pw_multi_aff_free(pma2
);
7733 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7740 /* Descriptions of union maps that should be convertible
7741 * to an isl_multi_union_pw_aff.
7743 const char *umap_mupa_conversion_tests
[] = {
7744 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7745 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7746 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7747 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7749 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7750 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7751 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7752 "{ A[] -> B[0]; C[] -> B[1] }",
7753 "{ A[] -> B[]; C[] -> B[] }",
7756 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
7757 * to isl_union_map produces the original isl_union_map.
7759 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
7762 isl_union_map
*umap1
, *umap2
;
7763 isl_multi_union_pw_aff
*mupa
;
7766 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
7768 str
= umap_mupa_conversion_tests
[i
];
7769 umap1
= isl_union_map_read_from_str(ctx
, str
);
7770 umap2
= isl_union_map_copy(umap1
);
7771 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
7772 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
7773 equal
= isl_union_map_is_equal(umap1
, umap2
);
7774 isl_union_map_free(umap1
);
7775 isl_union_map_free(umap2
);
7780 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7787 static int test_conversion(isl_ctx
*ctx
)
7789 if (test_set_conversion(ctx
) < 0)
7791 if (test_map_conversion(ctx
) < 0)
7793 if (test_mpa_conversion(ctx
) < 0)
7795 if (test_union_map_mupa_conversion(ctx
) < 0)
7800 /* Check that isl_basic_map_curry does not modify input.
7802 static int test_curry(isl_ctx
*ctx
)
7805 isl_basic_map
*bmap1
, *bmap2
;
7808 str
= "{ [A[] -> B[]] -> C[] }";
7809 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
7810 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
7811 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
7812 isl_basic_map_free(bmap1
);
7813 isl_basic_map_free(bmap2
);
7818 isl_die(ctx
, isl_error_unknown
,
7819 "curried map should not be equal to original",
7829 } preimage_tests
[] = {
7830 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
7831 "{ A[j,i] -> B[i,j] }",
7832 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
7833 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7834 "{ A[a,b] -> B[a/2,b/6] }",
7835 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
7836 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7837 "{ A[a,b] -> B[a/2,b/6] }",
7838 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
7839 "exists i,j : a = 2 i and b = 6 j }" },
7840 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
7841 "[n] -> { : 0 <= n <= 100 }" },
7842 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7843 "{ A[a] -> B[2a] }",
7844 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
7845 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7846 "{ A[a] -> B[([a/2])] }",
7847 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
7848 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
7849 "{ A[a] -> B[a,a,a/3] }",
7850 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
7851 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
7852 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
7855 static int test_preimage_basic_set(isl_ctx
*ctx
)
7858 isl_basic_set
*bset1
, *bset2
;
7862 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
7863 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
7864 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
7865 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
7866 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
7867 equal
= isl_basic_set_is_equal(bset1
, bset2
);
7868 isl_basic_set_free(bset1
);
7869 isl_basic_set_free(bset2
);
7873 isl_die(ctx
, isl_error_unknown
, "bad preimage",
7884 } preimage_domain_tests
[] = {
7885 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
7886 "{ A[j,i] -> B[i,j] }",
7887 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
7888 { "{ B[i] -> C[i]; D[i] -> E[i] }",
7889 "{ A[i] -> B[i + 1] }",
7890 "{ A[i] -> C[i + 1] }" },
7891 { "{ B[i] -> C[i]; B[i] -> E[i] }",
7892 "{ A[i] -> B[i + 1] }",
7893 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
7894 { "{ B[i] -> C[([i/2])] }",
7895 "{ A[i] -> B[2i] }",
7896 "{ A[i] -> C[i] }" },
7897 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
7898 "{ A[i] -> B[([i/5]), ([i/7])] }",
7899 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
7900 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
7901 "[N] -> { A[] -> B[([N/5])] }",
7902 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
7903 { "{ B[i] -> C[i] : exists a : i = 5 a }",
7904 "{ A[i] -> B[2i] }",
7905 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
7906 { "{ B[i] -> C[i] : exists a : i = 2 a; "
7907 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
7908 "{ A[i] -> B[2i] }",
7909 "{ A[i] -> C[2i] }" },
7910 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
7911 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
7914 static int test_preimage_union_map(isl_ctx
*ctx
)
7917 isl_union_map
*umap1
, *umap2
;
7921 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
7922 umap1
= isl_union_map_read_from_str(ctx
,
7923 preimage_domain_tests
[i
].map
);
7924 ma
= isl_multi_aff_read_from_str(ctx
,
7925 preimage_domain_tests
[i
].ma
);
7926 umap2
= isl_union_map_read_from_str(ctx
,
7927 preimage_domain_tests
[i
].res
);
7928 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
7929 equal
= isl_union_map_is_equal(umap1
, umap2
);
7930 isl_union_map_free(umap1
);
7931 isl_union_map_free(umap2
);
7935 isl_die(ctx
, isl_error_unknown
, "bad preimage",
7942 static int test_preimage(isl_ctx
*ctx
)
7944 if (test_preimage_basic_set(ctx
) < 0)
7946 if (test_preimage_union_map(ctx
) < 0)
7956 } pullback_tests
[] = {
7957 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
7958 "{ A[a,b] -> C[b + 2a] }" },
7959 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
7960 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
7961 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
7962 "{ A[a] -> C[(a)/6] }" },
7963 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
7964 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
7965 "{ A[a] -> C[(2a)/3] }" },
7966 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
7967 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
7968 "{ A[i,j] -> C[i + j, i + j] }"},
7969 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
7970 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
7971 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
7972 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
7973 "{ [i, j] -> [floor((i)/3), j] }",
7974 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
7977 static int test_pullback(isl_ctx
*ctx
)
7980 isl_multi_aff
*ma1
, *ma2
;
7984 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
7985 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
7986 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
7987 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
7988 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
7989 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
7990 isl_multi_aff_free(ma1
);
7991 isl_multi_aff_free(ma2
);
7995 isl_die(ctx
, isl_error_unknown
, "bad pullback",
8002 /* Check that negation is printed correctly and that equal expressions
8003 * are correctly identified.
8005 static int test_ast(isl_ctx
*ctx
)
8007 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
8011 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
8012 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
8013 expr
= isl_ast_expr_add(expr1
, expr2
);
8014 expr2
= isl_ast_expr_copy(expr
);
8015 expr
= isl_ast_expr_neg(expr
);
8016 expr2
= isl_ast_expr_neg(expr2
);
8017 equal
= isl_ast_expr_is_equal(expr
, expr2
);
8018 str
= isl_ast_expr_to_C_str(expr
);
8019 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
8021 isl_ast_expr_free(expr
);
8022 isl_ast_expr_free(expr2
);
8024 if (ok
< 0 || equal
< 0)
8027 isl_die(ctx
, isl_error_unknown
,
8028 "equal expressions not considered equal", return -1);
8030 isl_die(ctx
, isl_error_unknown
,
8031 "isl_ast_expr printed incorrectly", return -1);
8033 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
8034 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
8035 expr
= isl_ast_expr_add(expr1
, expr2
);
8036 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
8037 expr
= isl_ast_expr_sub(expr3
, expr
);
8038 str
= isl_ast_expr_to_C_str(expr
);
8039 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
8041 isl_ast_expr_free(expr
);
8046 isl_die(ctx
, isl_error_unknown
,
8047 "isl_ast_expr printed incorrectly", return -1);
8052 /* Check that isl_ast_build_expr_from_set returns a valid expression
8053 * for an empty set. Note that isl_ast_build_expr_from_set getting
8054 * called on an empty set probably indicates a bug in the caller.
8056 static int test_ast_build(isl_ctx
*ctx
)
8059 isl_ast_build
*build
;
8062 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8063 build
= isl_ast_build_from_context(set
);
8065 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
8066 expr
= isl_ast_build_expr_from_set(build
, set
);
8068 isl_ast_expr_free(expr
);
8069 isl_ast_build_free(build
);
8077 /* Internal data structure for before_for and after_for callbacks.
8079 * depth is the current depth
8080 * before is the number of times before_for has been called
8081 * after is the number of times after_for has been called
8083 struct isl_test_codegen_data
{
8089 /* This function is called before each for loop in the AST generated
8090 * from test_ast_gen1.
8092 * Increment the number of calls and the depth.
8093 * Check that the space returned by isl_ast_build_get_schedule_space
8094 * matches the target space of the schedule returned by
8095 * isl_ast_build_get_schedule.
8096 * Return an isl_id that is checked by the corresponding call
8099 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
8102 struct isl_test_codegen_data
*data
= user
;
8105 isl_union_map
*schedule
;
8106 isl_union_set
*uset
;
8111 ctx
= isl_ast_build_get_ctx(build
);
8113 if (data
->before
>= 3)
8114 isl_die(ctx
, isl_error_unknown
,
8115 "unexpected number of for nodes", return NULL
);
8116 if (data
->depth
>= 2)
8117 isl_die(ctx
, isl_error_unknown
,
8118 "unexpected depth", return NULL
);
8120 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
8124 schedule
= isl_ast_build_get_schedule(build
);
8125 uset
= isl_union_map_range(schedule
);
8128 if (isl_union_set_n_set(uset
) != 1) {
8129 isl_union_set_free(uset
);
8130 isl_die(ctx
, isl_error_unknown
,
8131 "expecting single range space", return NULL
);
8134 space
= isl_ast_build_get_schedule_space(build
);
8135 set
= isl_union_set_extract_set(uset
, space
);
8136 isl_union_set_free(uset
);
8137 empty
= isl_set_is_empty(set
);
8143 isl_die(ctx
, isl_error_unknown
,
8144 "spaces don't match", return NULL
);
8146 return isl_id_alloc(ctx
, name
, NULL
);
8149 /* This function is called after each for loop in the AST generated
8150 * from test_ast_gen1.
8152 * Increment the number of calls and decrement the depth.
8153 * Check that the annotation attached to the node matches
8154 * the isl_id returned by the corresponding call to before_for.
8156 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
8157 __isl_keep isl_ast_build
*build
, void *user
)
8159 struct isl_test_codegen_data
*data
= user
;
8167 if (data
->after
> data
->before
)
8168 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8169 "mismatch in number of for nodes",
8170 return isl_ast_node_free(node
));
8172 id
= isl_ast_node_get_annotation(node
);
8174 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8175 "missing annotation", return isl_ast_node_free(node
));
8177 name
= isl_id_get_name(id
);
8178 valid
= name
&& atoi(name
+ 1) == data
->depth
;
8182 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8183 "wrong annotation", return isl_ast_node_free(node
));
8188 /* Check that the before_each_for and after_each_for callbacks
8189 * are called for each for loop in the generated code,
8190 * that they are called in the right order and that the isl_id
8191 * returned from the before_each_for callback is attached to
8192 * the isl_ast_node passed to the corresponding after_each_for call.
8194 static int test_ast_gen1(isl_ctx
*ctx
)
8198 isl_union_map
*schedule
;
8199 isl_ast_build
*build
;
8201 struct isl_test_codegen_data data
;
8203 str
= "[N] -> { : N >= 10 }";
8204 set
= isl_set_read_from_str(ctx
, str
);
8205 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
8206 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
8207 schedule
= isl_union_map_read_from_str(ctx
, str
);
8212 build
= isl_ast_build_from_context(set
);
8213 build
= isl_ast_build_set_before_each_for(build
,
8214 &before_for
, &data
);
8215 build
= isl_ast_build_set_after_each_for(build
,
8217 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8218 isl_ast_build_free(build
);
8222 isl_ast_node_free(tree
);
8224 if (data
.before
!= 3 || data
.after
!= 3)
8225 isl_die(ctx
, isl_error_unknown
,
8226 "unexpected number of for nodes", return -1);
8231 /* Check that the AST generator handles domains that are integrally disjoint
8232 * but not rationally disjoint.
8234 static int test_ast_gen2(isl_ctx
*ctx
)
8238 isl_union_map
*schedule
;
8239 isl_union_map
*options
;
8240 isl_ast_build
*build
;
8243 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
8244 schedule
= isl_union_map_read_from_str(ctx
, str
);
8245 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8246 build
= isl_ast_build_from_context(set
);
8248 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
8249 options
= isl_union_map_read_from_str(ctx
, str
);
8250 build
= isl_ast_build_set_options(build
, options
);
8251 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8252 isl_ast_build_free(build
);
8255 isl_ast_node_free(tree
);
8260 /* Increment *user on each call.
8262 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
8263 __isl_keep isl_ast_build
*build
, void *user
)
8272 /* Test that unrolling tries to minimize the number of instances.
8273 * In particular, for the schedule given below, make sure it generates
8274 * 3 nodes (rather than 101).
8276 static int test_ast_gen3(isl_ctx
*ctx
)
8280 isl_union_map
*schedule
;
8281 isl_union_map
*options
;
8282 isl_ast_build
*build
;
8286 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
8287 schedule
= isl_union_map_read_from_str(ctx
, str
);
8288 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8290 str
= "{ [i] -> unroll[0] }";
8291 options
= isl_union_map_read_from_str(ctx
, str
);
8293 build
= isl_ast_build_from_context(set
);
8294 build
= isl_ast_build_set_options(build
, options
);
8295 build
= isl_ast_build_set_at_each_domain(build
,
8296 &count_domains
, &n_domain
);
8297 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8298 isl_ast_build_free(build
);
8302 isl_ast_node_free(tree
);
8305 isl_die(ctx
, isl_error_unknown
,
8306 "unexpected number of for nodes", return -1);
8311 /* Check that if the ast_build_exploit_nested_bounds options is set,
8312 * we do not get an outer if node in the generated AST,
8313 * while we do get such an outer if node if the options is not set.
8315 static int test_ast_gen4(isl_ctx
*ctx
)
8319 isl_union_map
*schedule
;
8320 isl_ast_build
*build
;
8322 enum isl_ast_node_type type
;
8325 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
8326 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
8328 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
8330 schedule
= isl_union_map_read_from_str(ctx
, str
);
8331 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8332 build
= isl_ast_build_from_context(set
);
8333 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8334 isl_ast_build_free(build
);
8338 type
= isl_ast_node_get_type(tree
);
8339 isl_ast_node_free(tree
);
8341 if (type
== isl_ast_node_if
)
8342 isl_die(ctx
, isl_error_unknown
,
8343 "not expecting if node", return -1);
8345 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
8347 schedule
= isl_union_map_read_from_str(ctx
, str
);
8348 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8349 build
= isl_ast_build_from_context(set
);
8350 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8351 isl_ast_build_free(build
);
8355 type
= isl_ast_node_get_type(tree
);
8356 isl_ast_node_free(tree
);
8358 if (type
!= isl_ast_node_if
)
8359 isl_die(ctx
, isl_error_unknown
,
8360 "expecting if node", return -1);
8362 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
8367 /* This function is called for each leaf in the AST generated
8368 * from test_ast_gen5.
8370 * We finalize the AST generation by extending the outer schedule
8371 * with a zero-dimensional schedule. If this results in any for loops,
8372 * then this means that we did not pass along enough information
8373 * about the outer schedule to the inner AST generation.
8375 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
8378 isl_union_map
*schedule
, *extra
;
8381 schedule
= isl_ast_build_get_schedule(build
);
8382 extra
= isl_union_map_copy(schedule
);
8383 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
8384 schedule
= isl_union_map_range_product(schedule
, extra
);
8385 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8386 isl_ast_build_free(build
);
8391 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
8392 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
8393 "code should not contain any for loop",
8394 return isl_ast_node_free(tree
));
8399 /* Check that we do not lose any information when going back and
8400 * forth between internal and external schedule.
8402 * In particular, we create an AST where we unroll the only
8403 * non-constant dimension in the schedule. We therefore do
8404 * not expect any for loops in the AST. However, older versions
8405 * of isl would not pass along enough information about the outer
8406 * schedule when performing an inner code generation from a create_leaf
8407 * callback, resulting in the inner code generation producing a for loop.
8409 static int test_ast_gen5(isl_ctx
*ctx
)
8413 isl_union_map
*schedule
, *options
;
8414 isl_ast_build
*build
;
8417 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
8418 schedule
= isl_union_map_read_from_str(ctx
, str
);
8420 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
8421 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
8422 options
= isl_union_map_read_from_str(ctx
, str
);
8424 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8425 build
= isl_ast_build_from_context(set
);
8426 build
= isl_ast_build_set_options(build
, options
);
8427 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
8428 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8429 isl_ast_build_free(build
);
8430 isl_ast_node_free(tree
);
8437 /* Check that the expression
8439 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
8441 * is not combined into
8445 * as this would result in n/2 being evaluated in parts of
8446 * the definition domain where n is not a multiple of 2.
8448 static int test_ast_expr(isl_ctx
*ctx
)
8452 isl_ast_build
*build
;
8457 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
8458 isl_options_set_ast_build_detect_min_max(ctx
, 1);
8460 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
8461 pa
= isl_pw_aff_read_from_str(ctx
, str
);
8462 build
= isl_ast_build_alloc(ctx
);
8463 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
8464 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
8465 isl_ast_expr_get_op_type(expr
) == isl_ast_op_min
;
8466 isl_ast_build_free(build
);
8467 isl_ast_expr_free(expr
);
8469 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
8474 isl_die(ctx
, isl_error_unknown
,
8475 "expressions should not be combined", return -1);
8480 static int test_ast_gen(isl_ctx
*ctx
)
8482 if (test_ast_gen1(ctx
) < 0)
8484 if (test_ast_gen2(ctx
) < 0)
8486 if (test_ast_gen3(ctx
) < 0)
8488 if (test_ast_gen4(ctx
) < 0)
8490 if (test_ast_gen5(ctx
) < 0)
8492 if (test_ast_expr(ctx
) < 0)
8497 /* Check if dropping output dimensions from an isl_pw_multi_aff
8500 static int test_pw_multi_aff(isl_ctx
*ctx
)
8503 isl_pw_multi_aff
*pma1
, *pma2
;
8506 str
= "{ [i,j] -> [i+j, 4i-j] }";
8507 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8508 str
= "{ [i,j] -> [4i-j] }";
8509 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8511 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
8513 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
8515 isl_pw_multi_aff_free(pma1
);
8516 isl_pw_multi_aff_free(pma2
);
8520 isl_die(ctx
, isl_error_unknown
,
8521 "expressions not equal", return -1);
8526 /* Check that we can properly parse multi piecewise affine expressions
8527 * where the piecewise affine expressions have different domains.
8529 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
8532 isl_set
*dom
, *dom2
;
8533 isl_multi_pw_aff
*mpa1
, *mpa2
;
8538 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
8539 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
8540 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
8541 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
8542 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
8543 str
= "{ [i] -> [(i : i > 0), 2i] }";
8544 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8546 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
8548 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
8549 dom
= isl_pw_aff_domain(pa
);
8550 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
8551 dom2
= isl_pw_aff_domain(pa
);
8552 equal_domain
= isl_set_is_equal(dom
, dom2
);
8556 isl_multi_pw_aff_free(mpa1
);
8557 isl_multi_pw_aff_free(mpa2
);
8562 isl_die(ctx
, isl_error_unknown
,
8563 "expressions not equal", return -1);
8565 if (equal_domain
< 0)
8568 isl_die(ctx
, isl_error_unknown
,
8569 "domains unexpectedly equal", return -1);
8574 /* Check that the dimensions in the explicit domain
8575 * of a multi piecewise affine expression are properly
8576 * taken into account.
8578 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
8581 isl_bool involves1
, involves2
, involves3
, equal
;
8582 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
8584 str
= "{ A[x,y] -> B[] : x >= y }";
8585 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8586 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
8587 mpa1
= isl_multi_pw_aff_copy(mpa
);
8589 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
8590 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
8591 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
8592 str
= "{ [a,x,y] -> B[] : x >= y }";
8593 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8594 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
8595 isl_multi_pw_aff_free(mpa2
);
8597 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
8598 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
8599 if (equal
>= 0 && equal
)
8600 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
8601 isl_multi_pw_aff_free(mpa1
);
8602 isl_multi_pw_aff_free(mpa
);
8604 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
8607 isl_die(ctx
, isl_error_unknown
,
8608 "incorrect result of dimension insertion/removal",
8609 return isl_stat_error
);
8610 if (!involves1
|| involves2
|| !involves3
)
8611 isl_die(ctx
, isl_error_unknown
,
8612 "incorrect characterization of involved dimensions",
8613 return isl_stat_error
);
8618 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
8619 * sets the explicit domain of a zero-dimensional result,
8620 * such that it can be converted to an isl_union_map.
8622 static isl_stat
test_multi_pw_aff_3(isl_ctx
*ctx
)
8627 isl_multi_union_pw_aff
*mupa
;
8628 isl_union_map
*umap
;
8630 dom
= isl_union_set_read_from_str(ctx
, "{ A[]; B[] }");
8631 space
= isl_union_set_get_space(dom
);
8632 mv
= isl_multi_val_zero(isl_space_set_from_params(space
));
8633 mupa
= isl_multi_union_pw_aff_multi_val_on_domain(dom
, mv
);
8634 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
8635 isl_union_map_free(umap
);
8637 return isl_stat_error
;
8642 /* Perform some tests on multi piecewise affine expressions.
8644 static int test_multi_pw_aff(isl_ctx
*ctx
)
8646 if (test_multi_pw_aff_1(ctx
) < 0)
8648 if (test_multi_pw_aff_2(ctx
) < 0)
8650 if (test_multi_pw_aff_3(ctx
) < 0)
8655 /* This is a regression test for a bug where isl_basic_map_simplify
8656 * would end up in an infinite loop. In particular, we construct
8657 * an empty basic set that is not obviously empty.
8658 * isl_basic_set_is_empty marks the basic set as empty.
8659 * After projecting out i3, the variable can be dropped completely,
8660 * but isl_basic_map_simplify refrains from doing so if the basic set
8661 * is empty and would end up in an infinite loop if it didn't test
8662 * explicitly for empty basic maps in the outer loop.
8664 static int test_simplify_1(isl_ctx
*ctx
)
8667 isl_basic_set
*bset
;
8670 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
8671 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
8672 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
8674 bset
= isl_basic_set_read_from_str(ctx
, str
);
8675 empty
= isl_basic_set_is_empty(bset
);
8676 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
8677 isl_basic_set_free(bset
);
8681 isl_die(ctx
, isl_error_unknown
,
8682 "basic set should be empty", return -1);
8687 /* Check that the equality in the set description below
8688 * is simplified away.
8690 static int test_simplify_2(isl_ctx
*ctx
)
8693 isl_basic_set
*bset
;
8696 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
8697 bset
= isl_basic_set_read_from_str(ctx
, str
);
8698 universe
= isl_basic_set_plain_is_universe(bset
);
8699 isl_basic_set_free(bset
);
8704 isl_die(ctx
, isl_error_unknown
,
8705 "equality not simplified away", return -1);
8709 /* Some simplification tests.
8711 static int test_simplify(isl_ctx
*ctx
)
8713 if (test_simplify_1(ctx
) < 0)
8715 if (test_simplify_2(ctx
) < 0)
8720 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
8721 * with gbr context would fail to disable the use of the shifted tableau
8722 * when transferring equalities for the input to the context, resulting
8723 * in invalid sample values.
8725 static int test_partial_lexmin(isl_ctx
*ctx
)
8728 isl_basic_set
*bset
;
8729 isl_basic_map
*bmap
;
8732 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
8733 bmap
= isl_basic_map_read_from_str(ctx
, str
);
8734 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
8735 bset
= isl_basic_set_read_from_str(ctx
, str
);
8736 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
8745 /* Check that the variable compression performed on the existentially
8746 * quantified variables inside isl_basic_set_compute_divs is not confused
8747 * by the implicit equalities among the parameters.
8749 static int test_compute_divs(isl_ctx
*ctx
)
8752 isl_basic_set
*bset
;
8755 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
8756 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
8757 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
8758 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
8759 bset
= isl_basic_set_read_from_str(ctx
, str
);
8760 set
= isl_basic_set_compute_divs(bset
);
8768 /* Check that isl_schedule_get_map is not confused by a schedule tree
8769 * with divergent filter node parameters, as can result from a call
8770 * to isl_schedule_intersect_domain.
8772 static int test_schedule_tree(isl_ctx
*ctx
)
8775 isl_union_set
*uset
;
8776 isl_schedule
*sched1
, *sched2
;
8777 isl_union_map
*umap
;
8779 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
8780 sched1
= isl_schedule_from_domain(uset
);
8781 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
8782 sched2
= isl_schedule_from_domain(uset
);
8784 sched1
= isl_schedule_sequence(sched1
, sched2
);
8785 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
8786 uset
= isl_union_set_read_from_str(ctx
, str
);
8787 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
8788 umap
= isl_schedule_get_map(sched1
);
8789 isl_schedule_free(sched1
);
8790 isl_union_map_free(umap
);
8797 /* Check that a zero-dimensional prefix schedule keeps track
8798 * of the domain and outer filters.
8800 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
8804 isl_union_set
*uset
;
8805 isl_union_set_list
*filters
;
8806 isl_multi_union_pw_aff
*mupa
, *mupa2
;
8807 isl_schedule_node
*node
;
8809 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8810 uset
= isl_union_set_read_from_str(ctx
, str
);
8811 node
= isl_schedule_node_from_domain(uset
);
8812 node
= isl_schedule_node_child(node
, 0);
8814 str
= "{ S1[i,j] : i > j }";
8815 uset
= isl_union_set_read_from_str(ctx
, str
);
8816 filters
= isl_union_set_list_from_union_set(uset
);
8817 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
8818 uset
= isl_union_set_read_from_str(ctx
, str
);
8819 filters
= isl_union_set_list_add(filters
, uset
);
8820 node
= isl_schedule_node_insert_sequence(node
, filters
);
8822 node
= isl_schedule_node_child(node
, 0);
8823 node
= isl_schedule_node_child(node
, 0);
8824 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
8825 str
= "([] : { S1[i,j] : i > j })";
8826 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8827 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
8828 isl_multi_union_pw_aff_free(mupa2
);
8829 isl_multi_union_pw_aff_free(mupa
);
8830 isl_schedule_node_free(node
);
8835 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
8841 /* Check that the reaching domain elements and the prefix schedule
8842 * at a leaf node are the same before and after grouping.
8844 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
8849 isl_union_set
*uset
;
8850 isl_multi_union_pw_aff
*mupa
;
8851 isl_union_pw_multi_aff
*upma1
, *upma2
;
8852 isl_union_set
*domain1
, *domain2
;
8853 isl_union_map
*umap1
, *umap2
;
8854 isl_schedule_node
*node
;
8856 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8857 uset
= isl_union_set_read_from_str(ctx
, str
);
8858 node
= isl_schedule_node_from_domain(uset
);
8859 node
= isl_schedule_node_child(node
, 0);
8860 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
8861 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8862 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8863 node
= isl_schedule_node_child(node
, 0);
8864 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
8865 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8866 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8867 node
= isl_schedule_node_child(node
, 0);
8868 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
8869 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
8870 domain1
= isl_schedule_node_get_domain(node
);
8871 id
= isl_id_alloc(ctx
, "group", NULL
);
8872 node
= isl_schedule_node_parent(node
);
8873 node
= isl_schedule_node_group(node
, id
);
8874 node
= isl_schedule_node_child(node
, 0);
8875 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
8876 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
8877 domain2
= isl_schedule_node_get_domain(node
);
8878 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
8879 if (equal
>= 0 && equal
)
8880 equal
= isl_union_set_is_equal(domain1
, domain2
);
8881 if (equal
>= 0 && equal
)
8882 equal
= isl_union_map_is_equal(umap1
, umap2
);
8883 isl_union_map_free(umap1
);
8884 isl_union_map_free(umap2
);
8885 isl_union_set_free(domain1
);
8886 isl_union_set_free(domain2
);
8887 isl_union_pw_multi_aff_free(upma1
);
8888 isl_union_pw_multi_aff_free(upma2
);
8889 isl_schedule_node_free(node
);
8894 isl_die(ctx
, isl_error_unknown
,
8895 "expressions not equal", return -1);
8900 /* Check that we can have nested groupings and that the union map
8901 * schedule representation is the same before and after the grouping.
8902 * Note that after the grouping, the union map representation contains
8903 * the domain constraints from the ranges of the expansion nodes,
8904 * while they are missing from the union map representation of
8905 * the tree without expansion nodes.
8907 * Also check that the global expansion is as expected.
8909 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
8911 int equal
, equal_expansion
;
8914 isl_union_set
*uset
;
8915 isl_union_map
*umap1
, *umap2
;
8916 isl_union_map
*expansion1
, *expansion2
;
8917 isl_union_set_list
*filters
;
8918 isl_multi_union_pw_aff
*mupa
;
8919 isl_schedule
*schedule
;
8920 isl_schedule_node
*node
;
8922 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
8923 "S3[i,j] : 0 <= i,j < 10 }";
8924 uset
= isl_union_set_read_from_str(ctx
, str
);
8925 node
= isl_schedule_node_from_domain(uset
);
8926 node
= isl_schedule_node_child(node
, 0);
8927 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
8928 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8929 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8930 node
= isl_schedule_node_child(node
, 0);
8931 str
= "{ S1[i,j] }";
8932 uset
= isl_union_set_read_from_str(ctx
, str
);
8933 filters
= isl_union_set_list_from_union_set(uset
);
8934 str
= "{ S2[i,j]; S3[i,j] }";
8935 uset
= isl_union_set_read_from_str(ctx
, str
);
8936 filters
= isl_union_set_list_add(filters
, uset
);
8937 node
= isl_schedule_node_insert_sequence(node
, filters
);
8938 node
= isl_schedule_node_child(node
, 1);
8939 node
= isl_schedule_node_child(node
, 0);
8940 str
= "{ S2[i,j] }";
8941 uset
= isl_union_set_read_from_str(ctx
, str
);
8942 filters
= isl_union_set_list_from_union_set(uset
);
8943 str
= "{ S3[i,j] }";
8944 uset
= isl_union_set_read_from_str(ctx
, str
);
8945 filters
= isl_union_set_list_add(filters
, uset
);
8946 node
= isl_schedule_node_insert_sequence(node
, filters
);
8948 schedule
= isl_schedule_node_get_schedule(node
);
8949 umap1
= isl_schedule_get_map(schedule
);
8950 uset
= isl_schedule_get_domain(schedule
);
8951 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
8952 isl_schedule_free(schedule
);
8954 node
= isl_schedule_node_parent(node
);
8955 node
= isl_schedule_node_parent(node
);
8956 id
= isl_id_alloc(ctx
, "group1", NULL
);
8957 node
= isl_schedule_node_group(node
, id
);
8958 node
= isl_schedule_node_child(node
, 1);
8959 node
= isl_schedule_node_child(node
, 0);
8960 id
= isl_id_alloc(ctx
, "group2", NULL
);
8961 node
= isl_schedule_node_group(node
, id
);
8963 schedule
= isl_schedule_node_get_schedule(node
);
8964 umap2
= isl_schedule_get_map(schedule
);
8965 isl_schedule_free(schedule
);
8967 node
= isl_schedule_node_root(node
);
8968 node
= isl_schedule_node_child(node
, 0);
8969 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
8970 isl_schedule_node_free(node
);
8972 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
8973 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
8974 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
8976 expansion2
= isl_union_map_read_from_str(ctx
, str
);
8978 equal
= isl_union_map_is_equal(umap1
, umap2
);
8979 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
8981 isl_union_map_free(umap1
);
8982 isl_union_map_free(umap2
);
8983 isl_union_map_free(expansion1
);
8984 isl_union_map_free(expansion2
);
8986 if (equal
< 0 || equal_expansion
< 0)
8989 isl_die(ctx
, isl_error_unknown
,
8990 "expressions not equal", return -1);
8991 if (!equal_expansion
)
8992 isl_die(ctx
, isl_error_unknown
,
8993 "unexpected expansion", return -1);
8998 /* Some tests for the isl_schedule_node_group function.
9000 static int test_schedule_tree_group(isl_ctx
*ctx
)
9002 if (test_schedule_tree_group_1(ctx
) < 0)
9004 if (test_schedule_tree_group_2(ctx
) < 0)
9013 { "{ rat: [i] : 0 <= i <= 10 }",
9014 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
9015 { "{ rat: [i] : FALSE }",
9016 "{ rat: coefficients[[cst] -> [a]] }" },
9018 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
9025 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
9026 "{ rat: [i] : 0 <= i <= 10 }" },
9027 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
9029 { "{ rat: coefficients[[cst] -> [a]] }",
9030 "{ rat: [i] : FALSE }" },
9033 /* Test the basic functionality of isl_basic_set_coefficients and
9034 * isl_basic_set_solutions.
9036 static int test_dual(isl_ctx
*ctx
)
9040 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
9042 isl_basic_set
*bset1
, *bset2
;
9044 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
9045 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
9046 bset1
= isl_basic_set_coefficients(bset1
);
9047 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9048 isl_basic_set_free(bset1
);
9049 isl_basic_set_free(bset2
);
9053 isl_die(ctx
, isl_error_unknown
,
9054 "incorrect dual", return -1);
9057 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
9059 isl_basic_set
*bset1
, *bset2
;
9061 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
9062 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
9063 bset1
= isl_basic_set_solutions(bset1
);
9064 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9065 isl_basic_set_free(bset1
);
9066 isl_basic_set_free(bset2
);
9070 isl_die(ctx
, isl_error_unknown
,
9071 "incorrect dual", return -1);
9081 const char *schedule
;
9086 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
9087 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9089 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
9090 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9092 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
9093 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9095 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
9096 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9098 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
9099 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9101 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
9102 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
9104 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
9105 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9107 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
9108 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
9112 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
9113 * tile the band and then check if the tile and point bands have the
9114 * expected partial schedule.
9116 static int test_tile(isl_ctx
*ctx
)
9122 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
9123 shift
= isl_options_get_tile_shift_point_loops(ctx
);
9125 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
9129 isl_union_set
*domain
;
9130 isl_multi_union_pw_aff
*mupa
, *mupa2
;
9131 isl_schedule_node
*node
;
9132 isl_multi_val
*sizes
;
9134 opt
= tile_tests
[i
].scale_tile
;
9135 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
9136 opt
= tile_tests
[i
].shift_point
;
9137 isl_options_set_tile_shift_point_loops(ctx
, opt
);
9139 str
= tile_tests
[i
].domain
;
9140 domain
= isl_union_set_read_from_str(ctx
, str
);
9141 node
= isl_schedule_node_from_domain(domain
);
9142 node
= isl_schedule_node_child(node
, 0);
9143 str
= tile_tests
[i
].schedule
;
9144 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9145 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
9146 str
= tile_tests
[i
].sizes
;
9147 sizes
= isl_multi_val_read_from_str(ctx
, str
);
9148 node
= isl_schedule_node_band_tile(node
, sizes
);
9150 str
= tile_tests
[i
].tile
;
9151 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9152 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
9153 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
9154 isl_multi_union_pw_aff_free(mupa
);
9155 isl_multi_union_pw_aff_free(mupa2
);
9157 node
= isl_schedule_node_child(node
, 0);
9159 str
= tile_tests
[i
].point
;
9160 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9161 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
9162 if (equal
>= 0 && equal
)
9163 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
9165 isl_multi_union_pw_aff_free(mupa
);
9166 isl_multi_union_pw_aff_free(mupa2
);
9168 isl_schedule_node_free(node
);
9173 isl_die(ctx
, isl_error_unknown
,
9174 "unexpected result", return -1);
9177 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
9178 isl_options_set_tile_shift_point_loops(ctx
, shift
);
9183 /* Check that the domain hash of a space is equal to the hash
9184 * of the domain of the space.
9186 static int test_domain_hash(isl_ctx
*ctx
)
9190 uint32_t hash1
, hash2
;
9192 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
9193 space
= isl_map_get_space(map
);
9195 hash1
= isl_space_get_domain_hash(space
);
9196 space
= isl_space_domain(space
);
9197 hash2
= isl_space_get_hash(space
);
9198 isl_space_free(space
);
9203 isl_die(ctx
, isl_error_unknown
,
9204 "domain hash not equal to hash of domain", return -1);
9209 /* Check that a universe basic set that is not obviously equal to the universe
9210 * is still recognized as being equal to the universe.
9212 static int test_universe(isl_ctx
*ctx
)
9215 isl_basic_set
*bset
;
9218 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
9219 bset
= isl_basic_set_read_from_str(ctx
, s
);
9220 is_univ
= isl_basic_set_is_universe(bset
);
9221 isl_basic_set_free(bset
);
9226 isl_die(ctx
, isl_error_unknown
,
9227 "not recognized as universe set", return -1);
9232 /* Sets for which chambers are computed and checked.
9234 const char *chambers_tests
[] = {
9235 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
9236 "z >= 0 and z <= C - y and z <= B - x - y }",
9239 /* Add the domain of "cell" to "cells".
9241 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
9243 isl_basic_set_list
**cells
= user
;
9246 dom
= isl_cell_get_domain(cell
);
9247 isl_cell_free(cell
);
9248 *cells
= isl_basic_set_list_add(*cells
, dom
);
9250 return *cells
? isl_stat_ok
: isl_stat_error
;
9253 /* Check that the elements of "list" are pairwise disjoint.
9255 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
9260 return isl_stat_error
;
9262 n
= isl_basic_set_list_n_basic_set(list
);
9263 for (i
= 0; i
< n
; ++i
) {
9264 isl_basic_set
*bset_i
;
9266 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
9267 for (j
= i
+ 1; j
< n
; ++j
) {
9268 isl_basic_set
*bset_j
;
9271 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
9272 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
9273 isl_basic_set_free(bset_j
);
9275 isl_die(isl_basic_set_list_get_ctx(list
),
9276 isl_error_unknown
, "not disjoint",
9278 if (disjoint
< 0 || !disjoint
)
9281 isl_basic_set_free(bset_i
);
9283 return isl_stat_error
;
9289 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
9290 * are pairwise disjoint.
9292 static int test_chambers(isl_ctx
*ctx
)
9296 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
9297 isl_basic_set
*bset
;
9298 isl_vertices
*vertices
;
9299 isl_basic_set_list
*cells
;
9302 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
9303 vertices
= isl_basic_set_compute_vertices(bset
);
9304 cells
= isl_basic_set_list_alloc(ctx
, 0);
9305 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
9307 cells
= isl_basic_set_list_free(cells
);
9308 ok
= check_pairwise_disjoint(cells
);
9309 isl_basic_set_list_free(cells
);
9310 isl_vertices_free(vertices
);
9311 isl_basic_set_free(bset
);
9322 int (*fn
)(isl_ctx
*ctx
);
9324 { "universe", &test_universe
},
9325 { "domain hash", &test_domain_hash
},
9326 { "dual", &test_dual
},
9327 { "dependence analysis", &test_flow
},
9328 { "val", &test_val
},
9329 { "compute divs", &test_compute_divs
},
9330 { "partial lexmin", &test_partial_lexmin
},
9331 { "simplify", &test_simplify
},
9332 { "curry", &test_curry
},
9333 { "piecewise multi affine expressions", &test_pw_multi_aff
},
9334 { "multi piecewise affine expressions", &test_multi_pw_aff
},
9335 { "conversion", &test_conversion
},
9336 { "list", &test_list
},
9337 { "align parameters", &test_align_parameters
},
9338 { "drop unused parameters", &test_drop_unused_parameters
},
9339 { "preimage", &test_preimage
},
9340 { "pullback", &test_pullback
},
9341 { "AST", &test_ast
},
9342 { "AST build", &test_ast_build
},
9343 { "AST generation", &test_ast_gen
},
9344 { "eliminate", &test_eliminate
},
9345 { "residue class", &test_residue_class
},
9346 { "div", &test_div
},
9347 { "slice", &test_slice
},
9348 { "fixed power", &test_fixed_power
},
9349 { "sample", &test_sample
},
9350 { "output", &test_output
},
9351 { "vertices", &test_vertices
},
9352 { "chambers", &test_chambers
},
9353 { "fixed", &test_fixed
},
9354 { "equal", &test_equal
},
9355 { "disjoint", &test_disjoint
},
9356 { "product", &test_product
},
9357 { "dim_max", &test_dim_max
},
9358 { "affine", &test_aff
},
9359 { "injective", &test_injective
},
9360 { "schedule (whole component)", &test_schedule_whole
},
9361 { "schedule (incremental)", &test_schedule_incremental
},
9362 { "schedule tree", &test_schedule_tree
},
9363 { "schedule tree prefix", &test_schedule_tree_prefix
},
9364 { "schedule tree grouping", &test_schedule_tree_group
},
9365 { "tile", &test_tile
},
9366 { "union_pw", &test_union_pw
},
9367 { "locus", &test_locus
},
9368 { "eval", &test_eval
},
9369 { "parse", &test_parse
},
9370 { "single-valued", &test_sv
},
9371 { "affine hull", &test_affine_hull
},
9372 { "simple_hull", &test_simple_hull
},
9373 { "coalesce", &test_coalesce
},
9374 { "factorize", &test_factorize
},
9375 { "subset", &test_subset
},
9376 { "subtract", &test_subtract
},
9377 { "intersect", &test_intersect
},
9378 { "lexmin", &test_lexmin
},
9379 { "min", &test_min
},
9380 { "gist", &test_gist
},
9381 { "piecewise quasi-polynomials", &test_pwqp
},
9382 { "lift", &test_lift
},
9383 { "bound", &test_bound
},
9384 { "get lists", &test_get_list
},
9385 { "union", &test_union
},
9386 { "split periods", &test_split_periods
},
9387 { "lexicographic order", &test_lex
},
9388 { "bijectivity", &test_bijective
},
9389 { "dataflow analysis", &test_dep
},
9390 { "reading", &test_read
},
9391 { "bounded", &test_bounded
},
9392 { "construction", &test_construction
},
9393 { "dimension manipulation", &test_dim
},
9394 { "map application", &test_application
},
9395 { "convex hull", &test_convex_hull
},
9396 { "transitive closure", &test_closure
},
9399 int main(int argc
, char **argv
)
9402 struct isl_ctx
*ctx
;
9403 struct isl_options
*options
;
9405 options
= isl_options_new_with_defaults();
9407 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
9409 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
9410 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
9411 printf("%s\n", tests
[i
].name
);
9412 if (tests
[i
].fn(ctx
) < 0)