2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
5 * Copyright 2014 INRIA Rocquencourt
7 * Use of this software is governed by the MIT license
9 * Written by Sven Verdoolaege, K.U.Leuven, Departement
10 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
11 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
12 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
14 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
15 * B.P. 105 - 78153 Le Chesnay, France
21 #include <isl_ctx_private.h>
22 #include <isl_map_private.h>
23 #include <isl_aff_private.h>
24 #include <isl_space_private.h>
28 #include <isl_constraint_private.h>
29 #include <isl/polynomial.h>
30 #include <isl/union_set.h>
31 #include <isl/union_map.h>
32 #include <isl_factorization.h>
33 #include <isl/schedule.h>
34 #include <isl/schedule_node.h>
35 #include <isl_options_private.h>
36 #include <isl_vertices_private.h>
37 #include <isl/ast_build.h>
40 #include <isl_ast_build_expr.h>
41 #include <isl/options.h>
43 #include "isl_srcdir.c"
45 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
47 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
50 char *pattern
= "%s/test_inputs/%s.%s";
52 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
54 filename
= isl_alloc_array(ctx
, char, length
);
59 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
64 void test_parse_map(isl_ctx
*ctx
, const char *str
)
68 map
= isl_map_read_from_str(ctx
, str
);
73 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
78 map
= isl_map_read_from_str(ctx
, str
);
79 map2
= isl_map_read_from_str(ctx
, str2
);
80 equal
= isl_map_is_equal(map
, map2
);
87 isl_die(ctx
, isl_error_unknown
, "maps not equal",
93 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
95 isl_pw_qpolynomial
*pwqp
;
97 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
99 isl_pw_qpolynomial_free(pwqp
);
102 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
106 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
108 isl_pw_aff_free(pwaff
);
111 /* Check that we can read an isl_multi_val from "str" without errors.
113 static int test_parse_multi_val(isl_ctx
*ctx
, const char *str
)
117 mv
= isl_multi_val_read_from_str(ctx
, str
);
118 isl_multi_val_free(mv
);
123 /* Check that printing "mpa" and parsing the output results
124 * in the same expression.
126 static isl_stat
check_reparse_mpa(isl_ctx
*ctx
,
127 __isl_take isl_multi_pw_aff
*mpa
)
131 isl_multi_pw_aff
*mpa2
;
133 str
= isl_multi_pw_aff_to_str(mpa
);
134 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
136 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
137 isl_multi_pw_aff_free(mpa
);
138 isl_multi_pw_aff_free(mpa2
);
140 return isl_stat_error
;
142 isl_die(ctx
, isl_error_unknown
,
143 "parsed function not equal to original",
144 return isl_stat_error
);
149 /* String descriptions of multi piecewise affine expressions
150 * that are used for testing printing and parsing.
152 const char *parse_multi_mpa_tests
[] = {
153 "{ A[x, y] -> [] : x + y >= 0 }",
154 "{ A[x, y] -> B[] : x + y >= 0 }",
155 "{ A[x, y] -> [x] : x + y >= 0 }",
156 "[N] -> { A[x, y] -> [x] : x + y <= N }",
157 "{ A[x, y] -> [x, y] : x + y >= 0 }",
158 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
159 "[N] -> { [] : N >= 0 }",
160 "[N] -> { [] : N >= 0 }",
161 "[N] -> { [N] : N >= 0 }",
162 "[N] -> { [N, N + 1] : N >= 0 }",
163 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
166 /* Test parsing of multi piecewise affine expressions by printing
167 * the expressions and checking that parsing the output results
168 * in the same expression.
169 * Do this for a couple of manually constructed expressions and
170 * a set of expressions parsed from strings.
172 static int test_parse_mpa(isl_ctx
*ctx
)
177 isl_multi_pw_aff
*mpa
;
180 space
= isl_space_set_alloc(ctx
, 0, 0);
181 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
182 mpa
= isl_multi_pw_aff_zero(space
);
183 r
= check_reparse_mpa(ctx
, mpa
);
187 space
= isl_space_set_alloc(ctx
, 1, 0);
188 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
189 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
190 dom
= isl_set_universe(isl_space_params(isl_space_copy(space
)));
191 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
192 mpa
= isl_multi_pw_aff_zero(space
);
193 mpa
= isl_multi_pw_aff_intersect_domain(mpa
, dom
);
194 r
= check_reparse_mpa(ctx
, mpa
);
198 for (i
= 0; i
< ARRAY_SIZE(parse_multi_mpa_tests
); ++i
) {
201 str
= parse_multi_mpa_tests
[i
];
202 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
203 r
= check_reparse_mpa(ctx
, mpa
);
211 /* Check that printing "mupa" and parsing the output results
212 * in the same expression.
214 static isl_stat
check_reparse_mupa(isl_ctx
*ctx
,
215 __isl_take isl_multi_union_pw_aff
*mupa
)
219 isl_multi_union_pw_aff
*mupa2
;
221 str
= isl_multi_union_pw_aff_to_str(mupa
);
222 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
224 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
225 isl_multi_union_pw_aff_free(mupa
);
226 isl_multi_union_pw_aff_free(mupa2
);
228 return isl_stat_error
;
230 isl_die(ctx
, isl_error_unknown
,
231 "parsed function not equal to original",
232 return isl_stat_error
);
237 /* String descriptions of multi union piecewise affine expressions
238 * that are used for testing printing and parsing.
240 const char *parse_multi_mupa_tests
[] = {
244 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
246 "[N] -> (A[] : { })",
247 "[N] -> (A[] : { : N >= 0 })",
248 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
249 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
250 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
251 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
252 "{ S[x] : x > 0; T[y] : y >= 0 })",
255 /* Test parsing of multi union piecewise affine expressions by printing
256 * the expressions and checking that parsing the output results
257 * in the same expression.
258 * Do this for a couple of manually constructed expressions and
259 * a set of expressions parsed from strings.
261 static int test_parse_mupa(isl_ctx
*ctx
)
265 isl_multi_union_pw_aff
*mupa
;
270 space
= isl_space_set_alloc(ctx
, 0, 0);
271 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
272 mupa
= isl_multi_union_pw_aff_zero(space
);
273 r
= check_reparse_mupa(ctx
, mupa
);
277 space
= isl_space_set_alloc(ctx
, 1, 0);
278 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
279 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
280 dom
= isl_set_universe(space
);
281 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
282 uset
= isl_union_set_from_set(dom
);
283 space
= isl_space_set_alloc(ctx
, 1, 0);
284 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
285 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "B");
286 mupa
= isl_multi_union_pw_aff_zero(space
);
287 mupa
= isl_multi_union_pw_aff_intersect_domain(mupa
, uset
);
288 r
= check_reparse_mupa(ctx
, mupa
);
292 for (i
= 0; i
< ARRAY_SIZE(parse_multi_mupa_tests
); ++i
) {
295 str
= parse_multi_mupa_tests
[i
];
296 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
297 r
= check_reparse_mupa(ctx
, mupa
);
305 /* Test parsing of multi expressions.
307 static int test_parse_multi(isl_ctx
*ctx
)
309 if (test_parse_mpa(ctx
) < 0)
311 if (test_parse_mupa(ctx
) < 0)
317 /* Pairs of binary relation representations that should represent
318 * the same binary relations.
323 } parse_map_equal_tests
[] = {
324 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
325 "{ [x, y] : 2y >= 6 - x }" },
326 { "{ [x,y] : x <= min(y, 2*y+3) }",
327 "{ [x,y] : x <= y, 2*y + 3 }" },
328 { "{ [x,y] : x >= min(y, 2*y+3) }",
329 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
330 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
331 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
332 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
333 "{ [i,j] -> [min(i,j)] }" },
334 { "{ [i,j] : i != j }",
335 "{ [i,j] : i < j or i > j }" },
336 { "{ [i,j] : (i+1)*2 >= j }",
337 "{ [i, j] : j <= 2 + 2i }" },
338 { "{ [i] -> [i > 0 ? 4 : 5] }",
339 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
340 { "[N=2,M] -> { [i=[(M+N)/4]] }",
341 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
342 { "{ [x] : x >= 0 }",
343 "{ [x] : x-0 >= 0 }" },
344 { "{ [i] : ((i > 10)) }",
345 "{ [i] : i >= 11 }" },
347 "{ [i] -> [0 * i] }" },
348 { "{ [a] -> [b] : (not false) }",
349 "{ [a] -> [b] : true }" },
350 { "{ [i] : i/2 <= 5 }",
351 "{ [i] : i <= 10 }" },
352 { "{Sym=[n] [i] : i <= n }",
353 "[n] -> { [i] : i <= n }" },
356 { "{ [i] : 2*floor(i/2) = i }",
357 "{ [i] : exists a : i = 2 a }" },
358 { "{ [a] -> [b] : a = 5 implies b = 5 }",
359 "{ [a] -> [b] : a != 5 or b = 5 }" },
360 { "{ [a] -> [a - 1 : a > 0] }",
361 "{ [a] -> [a - 1] : a > 0 }" },
362 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
363 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
364 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
365 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
366 { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
367 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
368 { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
369 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
370 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
371 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
372 { "{ [a,b] -> [i,j] : a,b << i,j }",
373 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
374 { "{ [a,b] -> [i,j] : a,b <<= i,j }",
375 "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" },
376 { "{ [a,b] -> [i,j] : a,b >> i,j }",
377 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
378 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
379 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
380 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
381 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
382 "8c < n - 32a and i < n and c >= 0 and "
383 "c <= 3 and c >= -4a) }",
384 "{ [n] -> [i] : 0 <= i < n }" },
385 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
386 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
387 "{ [x] -> [] : 0 <= x <= 15 }" },
388 { "{ [x] -> [x] : }",
392 int test_parse(struct isl_ctx
*ctx
)
396 const char *str
, *str2
;
398 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
400 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
402 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
404 if (test_parse_multi(ctx
) < 0)
407 str
= "{ [i] -> [-i] }";
408 map
= isl_map_read_from_str(ctx
, str
);
412 str
= "{ A[i] -> L[([i/3])] }";
413 map
= isl_map_read_from_str(ctx
, str
);
417 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
418 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
419 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
421 for (i
= 0; i
< ARRAY_SIZE(parse_map_equal_tests
); ++i
) {
422 str
= parse_map_equal_tests
[i
].map1
;
423 str2
= parse_map_equal_tests
[i
].map2
;
424 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
428 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
429 map
= isl_map_read_from_str(ctx
, str
);
430 str
= "{ [new, old] -> [o0, o1] : "
431 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
432 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
433 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
434 map2
= isl_map_read_from_str(ctx
, str
);
435 assert(isl_map_is_equal(map
, map2
));
439 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
440 map
= isl_map_read_from_str(ctx
, str
);
441 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
442 map2
= isl_map_read_from_str(ctx
, str
);
443 assert(isl_map_is_equal(map
, map2
));
447 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
448 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
449 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
450 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
451 test_parse_pwaff(ctx
, "{ [] -> [(100)] }");
456 static int test_read(isl_ctx
*ctx
)
460 isl_basic_set
*bset1
, *bset2
;
461 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
464 filename
= get_filename(ctx
, "set", "omega");
466 input
= fopen(filename
, "r");
469 bset1
= isl_basic_set_read_from_file(ctx
, input
);
470 bset2
= isl_basic_set_read_from_str(ctx
, str
);
472 equal
= isl_basic_set_is_equal(bset1
, bset2
);
474 isl_basic_set_free(bset1
);
475 isl_basic_set_free(bset2
);
483 isl_die(ctx
, isl_error_unknown
,
484 "read sets not equal", return -1);
489 static int test_bounded(isl_ctx
*ctx
)
494 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
495 bounded
= isl_set_is_bounded(set
);
501 isl_die(ctx
, isl_error_unknown
,
502 "set not considered bounded", return -1);
504 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
505 bounded
= isl_set_is_bounded(set
);
512 isl_die(ctx
, isl_error_unknown
,
513 "set considered bounded", return -1);
515 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
516 bounded
= isl_set_is_bounded(set
);
522 isl_die(ctx
, isl_error_unknown
,
523 "set considered bounded", return -1);
528 /* Construct the basic set { [i] : 5 <= i <= N } */
529 static int test_construction_1(isl_ctx
*ctx
)
536 dim
= isl_space_set_alloc(ctx
, 1, 1);
537 bset
= isl_basic_set_universe(isl_space_copy(dim
));
538 ls
= isl_local_space_from_space(dim
);
540 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
541 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
542 c
= isl_constraint_set_coefficient_si(c
, isl_dim_param
, 0, 1);
543 bset
= isl_basic_set_add_constraint(bset
, c
);
545 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
546 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
547 c
= isl_constraint_set_constant_si(c
, -5);
548 bset
= isl_basic_set_add_constraint(bset
, c
);
550 isl_local_space_free(ls
);
551 isl_basic_set_free(bset
);
556 /* Construct the basic set { [x] : -100 <= x <= 100 }
557 * using isl_basic_set_{lower,upper}_bound_val and
558 * check that it is equal the same basic set parsed from a string.
560 static int test_construction_2(isl_ctx
*ctx
)
565 isl_basic_set
*bset1
, *bset2
;
567 v
= isl_val_int_from_si(ctx
, 100);
568 space
= isl_space_set_alloc(ctx
, 0, 1);
569 bset1
= isl_basic_set_universe(space
);
570 bset1
= isl_basic_set_upper_bound_val(bset1
, isl_dim_set
, 0,
572 bset1
= isl_basic_set_lower_bound_val(bset1
, isl_dim_set
, 0,
574 bset2
= isl_basic_set_read_from_str(ctx
, "{ [x] : -100 <= x <= 100 }");
575 equal
= isl_basic_set_is_equal(bset1
, bset2
);
576 isl_basic_set_free(bset1
);
577 isl_basic_set_free(bset2
);
582 isl_die(ctx
, isl_error_unknown
,
583 "failed construction", return -1);
588 /* Basic tests for constructing basic sets.
590 static int test_construction(isl_ctx
*ctx
)
592 if (test_construction_1(ctx
) < 0)
594 if (test_construction_2(ctx
) < 0)
599 static int test_dim(isl_ctx
*ctx
)
602 isl_map
*map1
, *map2
;
605 map1
= isl_map_read_from_str(ctx
,
606 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
607 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
608 map2
= isl_map_read_from_str(ctx
,
609 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
610 equal
= isl_map_is_equal(map1
, map2
);
613 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
614 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
615 if (equal
>= 0 && equal
)
616 equal
= isl_map_is_equal(map1
, map2
);
624 isl_die(ctx
, isl_error_unknown
,
625 "unexpected result", return -1);
627 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
628 map1
= isl_map_read_from_str(ctx
, str
);
629 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
630 map2
= isl_map_read_from_str(ctx
, str
);
631 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
632 equal
= isl_map_is_equal(map1
, map2
);
639 isl_die(ctx
, isl_error_unknown
,
640 "unexpected result", return -1);
645 /* Check that "val" is equal to the value described by "str".
646 * If "str" is "NaN", then check for a NaN value explicitly.
648 static isl_stat
val_check_equal(__isl_keep isl_val
*val
, const char *str
)
655 return isl_stat_error
;
657 ctx
= isl_val_get_ctx(val
);
658 res
= isl_val_read_from_str(ctx
, str
);
659 is_nan
= isl_val_is_nan(res
);
663 ok
= isl_val_is_nan(val
);
665 ok
= isl_val_eq(val
, res
);
668 return isl_stat_error
;
670 isl_die(ctx
, isl_error_unknown
,
671 "unexpected result", return isl_stat_error
);
676 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
680 { &isl_val_neg
, "0", "0" },
681 { &isl_val_abs
, "0", "0" },
682 { &isl_val_2exp
, "0", "1" },
683 { &isl_val_floor
, "0", "0" },
684 { &isl_val_ceil
, "0", "0" },
685 { &isl_val_neg
, "1", "-1" },
686 { &isl_val_neg
, "-1", "1" },
687 { &isl_val_neg
, "1/2", "-1/2" },
688 { &isl_val_neg
, "-1/2", "1/2" },
689 { &isl_val_neg
, "infty", "-infty" },
690 { &isl_val_neg
, "-infty", "infty" },
691 { &isl_val_neg
, "NaN", "NaN" },
692 { &isl_val_abs
, "1", "1" },
693 { &isl_val_abs
, "-1", "1" },
694 { &isl_val_abs
, "1/2", "1/2" },
695 { &isl_val_abs
, "-1/2", "1/2" },
696 { &isl_val_abs
, "infty", "infty" },
697 { &isl_val_abs
, "-infty", "infty" },
698 { &isl_val_abs
, "NaN", "NaN" },
699 { &isl_val_floor
, "1", "1" },
700 { &isl_val_floor
, "-1", "-1" },
701 { &isl_val_floor
, "1/2", "0" },
702 { &isl_val_floor
, "-1/2", "-1" },
703 { &isl_val_floor
, "infty", "infty" },
704 { &isl_val_floor
, "-infty", "-infty" },
705 { &isl_val_floor
, "NaN", "NaN" },
706 { &isl_val_ceil
, "1", "1" },
707 { &isl_val_ceil
, "-1", "-1" },
708 { &isl_val_ceil
, "1/2", "1" },
709 { &isl_val_ceil
, "-1/2", "0" },
710 { &isl_val_ceil
, "infty", "infty" },
711 { &isl_val_ceil
, "-infty", "-infty" },
712 { &isl_val_ceil
, "NaN", "NaN" },
713 { &isl_val_2exp
, "-3", "1/8" },
714 { &isl_val_2exp
, "-1", "1/2" },
715 { &isl_val_2exp
, "1", "2" },
716 { &isl_val_2exp
, "2", "4" },
717 { &isl_val_2exp
, "3", "8" },
718 { &isl_val_inv
, "1", "1" },
719 { &isl_val_inv
, "2", "1/2" },
720 { &isl_val_inv
, "1/2", "2" },
721 { &isl_val_inv
, "-2", "-1/2" },
722 { &isl_val_inv
, "-1/2", "-2" },
723 { &isl_val_inv
, "0", "NaN" },
724 { &isl_val_inv
, "NaN", "NaN" },
725 { &isl_val_inv
, "infty", "0" },
726 { &isl_val_inv
, "-infty", "0" },
729 /* Perform some basic tests of unary operations on isl_val objects.
731 static int test_un_val(isl_ctx
*ctx
)
735 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
737 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
740 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
741 fn
= val_un_tests
[i
].op
;
743 r
= val_check_equal(v
, val_un_tests
[i
].res
);
753 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
754 __isl_take isl_val
*v2
);
756 ['+'] = { &isl_val_add
},
757 ['-'] = { &isl_val_sub
},
758 ['*'] = { &isl_val_mul
},
759 ['/'] = { &isl_val_div
},
760 ['g'] = { &isl_val_gcd
},
761 ['m'] = { &isl_val_min
},
762 ['M'] = { &isl_val_max
},
770 } val_bin_tests
[] = {
771 { "0", '+', "0", "0" },
772 { "1", '+', "0", "1" },
773 { "1", '+', "1", "2" },
774 { "1", '-', "1", "0" },
775 { "1", '*', "1", "1" },
776 { "1", '/', "1", "1" },
777 { "2", '*', "3", "6" },
778 { "2", '*', "1/2", "1" },
779 { "2", '*', "1/3", "2/3" },
780 { "2/3", '*', "3/5", "2/5" },
781 { "2/3", '*', "7/5", "14/15" },
782 { "2", '/', "1/2", "4" },
783 { "-2", '/', "-1/2", "4" },
784 { "-2", '/', "1/2", "-4" },
785 { "2", '/', "-1/2", "-4" },
786 { "2", '/', "2", "1" },
787 { "2", '/', "3", "2/3" },
788 { "2/3", '/', "5/3", "2/5" },
789 { "2/3", '/', "5/7", "14/15" },
790 { "0", '/', "0", "NaN" },
791 { "42", '/', "0", "NaN" },
792 { "-42", '/', "0", "NaN" },
793 { "infty", '/', "0", "NaN" },
794 { "-infty", '/', "0", "NaN" },
795 { "NaN", '/', "0", "NaN" },
796 { "0", '/', "NaN", "NaN" },
797 { "42", '/', "NaN", "NaN" },
798 { "-42", '/', "NaN", "NaN" },
799 { "infty", '/', "NaN", "NaN" },
800 { "-infty", '/', "NaN", "NaN" },
801 { "NaN", '/', "NaN", "NaN" },
802 { "0", '/', "infty", "0" },
803 { "42", '/', "infty", "0" },
804 { "-42", '/', "infty", "0" },
805 { "infty", '/', "infty", "NaN" },
806 { "-infty", '/', "infty", "NaN" },
807 { "NaN", '/', "infty", "NaN" },
808 { "0", '/', "-infty", "0" },
809 { "42", '/', "-infty", "0" },
810 { "-42", '/', "-infty", "0" },
811 { "infty", '/', "-infty", "NaN" },
812 { "-infty", '/', "-infty", "NaN" },
813 { "NaN", '/', "-infty", "NaN" },
814 { "1", '-', "1/3", "2/3" },
815 { "1/3", '+', "1/2", "5/6" },
816 { "1/2", '+', "1/2", "1" },
817 { "3/4", '-', "1/4", "1/2" },
818 { "1/2", '-', "1/3", "1/6" },
819 { "infty", '+', "42", "infty" },
820 { "infty", '+', "infty", "infty" },
821 { "42", '+', "infty", "infty" },
822 { "infty", '-', "infty", "NaN" },
823 { "infty", '*', "infty", "infty" },
824 { "infty", '*', "-infty", "-infty" },
825 { "-infty", '*', "infty", "-infty" },
826 { "-infty", '*', "-infty", "infty" },
827 { "0", '*', "infty", "NaN" },
828 { "1", '*', "infty", "infty" },
829 { "infty", '*', "0", "NaN" },
830 { "infty", '*', "42", "infty" },
831 { "42", '-', "infty", "-infty" },
832 { "infty", '+', "-infty", "NaN" },
833 { "4", 'g', "6", "2" },
834 { "5", 'g', "6", "1" },
835 { "42", 'm', "3", "3" },
836 { "42", 'M', "3", "42" },
837 { "3", 'm', "42", "3" },
838 { "3", 'M', "42", "42" },
839 { "42", 'm', "infty", "42" },
840 { "42", 'M', "infty", "infty" },
841 { "42", 'm', "-infty", "-infty" },
842 { "42", 'M', "-infty", "42" },
843 { "42", 'm', "NaN", "NaN" },
844 { "42", 'M', "NaN", "NaN" },
845 { "infty", 'm', "-infty", "-infty" },
846 { "infty", 'M', "-infty", "infty" },
849 /* Perform some basic tests of binary operations on isl_val objects.
851 static int test_bin_val(isl_ctx
*ctx
)
854 isl_val
*v1
, *v2
, *res
;
855 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
856 __isl_take isl_val
*v2
);
859 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
860 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
861 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
862 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
863 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
865 if (isl_val_is_nan(res
))
866 ok
= isl_val_is_nan(v1
);
868 ok
= isl_val_eq(v1
, res
);
874 isl_die(ctx
, isl_error_unknown
,
875 "unexpected result", return -1);
881 /* Perform some basic tests on isl_val objects.
883 static int test_val(isl_ctx
*ctx
)
885 if (test_un_val(ctx
) < 0)
887 if (test_bin_val(ctx
) < 0)
892 /* Sets described using existentially quantified variables that
893 * can also be described without.
895 static const char *elimination_tests
[] = {
896 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
897 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
898 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
901 /* Check that redundant existentially quantified variables are
904 static int test_elimination(isl_ctx
*ctx
)
910 for (i
= 0; i
< ARRAY_SIZE(elimination_tests
); ++i
) {
911 bset
= isl_basic_set_read_from_str(ctx
, elimination_tests
[i
]);
912 n
= isl_basic_set_dim(bset
, isl_dim_div
);
913 isl_basic_set_free(bset
);
917 isl_die(ctx
, isl_error_unknown
,
918 "expecting no existentials", return -1);
924 static int test_div(isl_ctx
*ctx
)
931 struct isl_basic_set
*bset
;
932 struct isl_constraint
*c
;
935 dim
= isl_space_set_alloc(ctx
, 0, 3);
936 bset
= isl_basic_set_universe(isl_space_copy(dim
));
937 ls
= isl_local_space_from_space(dim
);
939 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
940 c
= isl_constraint_set_constant_si(c
, -1);
941 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
942 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
943 bset
= isl_basic_set_add_constraint(bset
, c
);
945 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
946 c
= isl_constraint_set_constant_si(c
, 1);
947 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
948 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
949 bset
= isl_basic_set_add_constraint(bset
, c
);
951 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
953 assert(bset
&& bset
->n_div
== 1);
954 isl_local_space_free(ls
);
955 isl_basic_set_free(bset
);
958 dim
= isl_space_set_alloc(ctx
, 0, 3);
959 bset
= isl_basic_set_universe(isl_space_copy(dim
));
960 ls
= isl_local_space_from_space(dim
);
962 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
963 c
= isl_constraint_set_constant_si(c
, 1);
964 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
965 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
966 bset
= isl_basic_set_add_constraint(bset
, c
);
968 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
969 c
= isl_constraint_set_constant_si(c
, -1);
970 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
971 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
972 bset
= isl_basic_set_add_constraint(bset
, c
);
974 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
976 assert(bset
&& bset
->n_div
== 1);
977 isl_local_space_free(ls
);
978 isl_basic_set_free(bset
);
981 dim
= isl_space_set_alloc(ctx
, 0, 3);
982 bset
= isl_basic_set_universe(isl_space_copy(dim
));
983 ls
= isl_local_space_from_space(dim
);
985 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
986 c
= isl_constraint_set_constant_si(c
, 1);
987 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
988 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
989 bset
= isl_basic_set_add_constraint(bset
, c
);
991 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
992 c
= isl_constraint_set_constant_si(c
, -3);
993 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
994 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 4);
995 bset
= isl_basic_set_add_constraint(bset
, c
);
997 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
999 assert(bset
&& bset
->n_div
== 1);
1000 isl_local_space_free(ls
);
1001 isl_basic_set_free(bset
);
1004 dim
= isl_space_set_alloc(ctx
, 0, 3);
1005 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1006 ls
= isl_local_space_from_space(dim
);
1008 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1009 c
= isl_constraint_set_constant_si(c
, 2);
1010 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1011 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1012 bset
= isl_basic_set_add_constraint(bset
, c
);
1014 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1015 c
= isl_constraint_set_constant_si(c
, -1);
1016 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1017 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1018 bset
= isl_basic_set_add_constraint(bset
, c
);
1020 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1022 assert(isl_basic_set_is_empty(bset
));
1023 isl_local_space_free(ls
);
1024 isl_basic_set_free(bset
);
1027 dim
= isl_space_set_alloc(ctx
, 0, 3);
1028 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1029 ls
= isl_local_space_from_space(dim
);
1031 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1032 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1033 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1034 bset
= isl_basic_set_add_constraint(bset
, c
);
1036 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1037 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1038 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1039 bset
= isl_basic_set_add_constraint(bset
, c
);
1041 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1043 assert(bset
&& bset
->n_div
== 0);
1044 isl_basic_set_free(bset
);
1045 isl_local_space_free(ls
);
1048 dim
= isl_space_set_alloc(ctx
, 0, 3);
1049 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1050 ls
= isl_local_space_from_space(dim
);
1052 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1053 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1054 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1055 bset
= isl_basic_set_add_constraint(bset
, c
);
1057 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1058 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1059 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1060 bset
= isl_basic_set_add_constraint(bset
, c
);
1062 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1064 assert(bset
&& bset
->n_div
== 1);
1065 isl_basic_set_free(bset
);
1066 isl_local_space_free(ls
);
1069 /* This test is a bit tricky. We set up an equality
1070 * a + 3b + 3c = 6 e0
1071 * Normalization of divs creates _two_ divs
1074 * Afterwards e0 is removed again because it has coefficient -1
1075 * and we end up with the original equality and div again.
1076 * Perhaps we can avoid the introduction of this temporary div.
1078 dim
= isl_space_set_alloc(ctx
, 0, 4);
1079 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1080 ls
= isl_local_space_from_space(dim
);
1082 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1083 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1084 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1085 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -3);
1086 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 6);
1087 bset
= isl_basic_set_add_constraint(bset
, c
);
1089 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
1091 /* Test disabled for now */
1093 assert(bset && bset->n_div == 1);
1095 isl_local_space_free(ls
);
1096 isl_basic_set_free(bset
);
1099 dim
= isl_space_set_alloc(ctx
, 0, 5);
1100 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1101 ls
= isl_local_space_from_space(dim
);
1103 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1104 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1105 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1106 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, -3);
1107 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 4, 6);
1108 bset
= isl_basic_set_add_constraint(bset
, c
);
1110 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1111 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1112 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 1);
1113 c
= isl_constraint_set_constant_si(c
, 1);
1114 bset
= isl_basic_set_add_constraint(bset
, c
);
1116 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
1118 /* Test disabled for now */
1120 assert(bset && bset->n_div == 1);
1122 isl_local_space_free(ls
);
1123 isl_basic_set_free(bset
);
1126 dim
= isl_space_set_alloc(ctx
, 0, 4);
1127 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1128 ls
= isl_local_space_from_space(dim
);
1130 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1131 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1132 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -1);
1133 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1134 bset
= isl_basic_set_add_constraint(bset
, c
);
1136 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1137 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1138 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 3);
1139 c
= isl_constraint_set_constant_si(c
, 2);
1140 bset
= isl_basic_set_add_constraint(bset
, c
);
1142 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
1144 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1146 assert(!isl_basic_set_is_empty(bset
));
1148 isl_local_space_free(ls
);
1149 isl_basic_set_free(bset
);
1152 dim
= isl_space_set_alloc(ctx
, 0, 3);
1153 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1154 ls
= isl_local_space_from_space(dim
);
1156 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1157 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1158 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1159 bset
= isl_basic_set_add_constraint(bset
, c
);
1161 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1163 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1165 isl_local_space_free(ls
);
1166 isl_basic_set_free(bset
);
1168 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1169 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1170 set
= isl_set_read_from_str(ctx
, str
);
1171 set
= isl_set_compute_divs(set
);
1176 if (test_elimination(ctx
) < 0)
1179 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1180 set
= isl_set_read_from_str(ctx
, str
);
1181 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
1182 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
1183 empty
= isl_set_is_empty(set
);
1188 isl_die(ctx
, isl_error_unknown
,
1189 "result not as accurate as expected", return -1);
1194 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
1198 struct isl_basic_set
*bset1
, *bset2
;
1199 struct isl_basic_map
*bmap
;
1201 filename
= get_filename(ctx
, name
, "omega");
1203 input
= fopen(filename
, "r");
1206 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1207 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1209 bset1
= isl_basic_set_apply(bset1
, bmap
);
1211 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1213 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1215 isl_basic_set_free(bset1
);
1216 isl_basic_set_free(bset2
);
1222 static int test_application(isl_ctx
*ctx
)
1224 test_application_case(ctx
, "application");
1225 test_application_case(ctx
, "application2");
1230 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1234 struct isl_basic_set
*bset1
, *bset2
;
1236 filename
= get_filename(ctx
, name
, "polylib");
1238 input
= fopen(filename
, "r");
1241 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1242 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1244 bset1
= isl_basic_set_affine_hull(bset1
);
1246 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1248 isl_basic_set_free(bset1
);
1249 isl_basic_set_free(bset2
);
1255 int test_affine_hull(struct isl_ctx
*ctx
)
1259 isl_basic_set
*bset
, *bset2
;
1263 test_affine_hull_case(ctx
, "affine2");
1264 test_affine_hull_case(ctx
, "affine");
1265 test_affine_hull_case(ctx
, "affine3");
1267 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1268 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1269 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1270 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1271 set
= isl_set_read_from_str(ctx
, str
);
1272 bset
= isl_set_affine_hull(set
);
1273 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1274 isl_basic_set_free(bset
);
1276 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1279 /* Check that isl_map_affine_hull is not confused by
1280 * the reordering of divs in isl_map_align_divs.
1282 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1283 "32e0 = b and 32e1 = c); "
1284 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1285 set
= isl_set_read_from_str(ctx
, str
);
1286 bset
= isl_set_affine_hull(set
);
1287 isl_basic_set_free(bset
);
1291 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1292 "32e2 = 31 + 31e0 }";
1293 set
= isl_set_read_from_str(ctx
, str
);
1294 bset
= isl_set_affine_hull(set
);
1295 str
= "{ [a] : exists e : a = 32 e }";
1296 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1297 subset
= isl_basic_set_is_subset(bset
, bset2
);
1298 isl_basic_set_free(bset
);
1299 isl_basic_set_free(bset2
);
1303 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1309 /* Pairs of maps and the corresponding expected results of
1310 * isl_map_plain_unshifted_simple_hull.
1315 } plain_unshifted_simple_hull_tests
[] = {
1316 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1317 "{ [i] -> [j] : i >= 1 }" },
1318 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1319 "(j mod 4 = 2 and k mod 6 = n) }",
1320 "{ [n] -> [i,j,k] : j mod 4 = 2 }" },
1323 /* Basic tests for isl_map_plain_unshifted_simple_hull.
1325 static int test_plain_unshifted_simple_hull(isl_ctx
*ctx
)
1329 isl_basic_map
*hull
, *expected
;
1332 for (i
= 0; i
< ARRAY_SIZE(plain_unshifted_simple_hull_tests
); ++i
) {
1334 str
= plain_unshifted_simple_hull_tests
[i
].map
;
1335 map
= isl_map_read_from_str(ctx
, str
);
1336 str
= plain_unshifted_simple_hull_tests
[i
].hull
;
1337 expected
= isl_basic_map_read_from_str(ctx
, str
);
1338 hull
= isl_map_plain_unshifted_simple_hull(map
);
1339 equal
= isl_basic_map_is_equal(hull
, expected
);
1340 isl_basic_map_free(hull
);
1341 isl_basic_map_free(expected
);
1345 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1352 /* Pairs of sets and the corresponding expected results of
1353 * isl_set_unshifted_simple_hull.
1358 } unshifted_simple_hull_tests
[] = {
1359 { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1360 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1363 /* Basic tests for isl_set_unshifted_simple_hull.
1365 static int test_unshifted_simple_hull(isl_ctx
*ctx
)
1369 isl_basic_set
*hull
, *expected
;
1372 for (i
= 0; i
< ARRAY_SIZE(unshifted_simple_hull_tests
); ++i
) {
1374 str
= unshifted_simple_hull_tests
[i
].set
;
1375 set
= isl_set_read_from_str(ctx
, str
);
1376 str
= unshifted_simple_hull_tests
[i
].hull
;
1377 expected
= isl_basic_set_read_from_str(ctx
, str
);
1378 hull
= isl_set_unshifted_simple_hull(set
);
1379 equal
= isl_basic_set_is_equal(hull
, expected
);
1380 isl_basic_set_free(hull
);
1381 isl_basic_set_free(expected
);
1385 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1392 static int test_simple_hull(struct isl_ctx
*ctx
)
1396 isl_basic_set
*bset
;
1399 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1400 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1401 set
= isl_set_read_from_str(ctx
, str
);
1402 bset
= isl_set_simple_hull(set
);
1403 is_empty
= isl_basic_set_is_empty(bset
);
1404 isl_basic_set_free(bset
);
1406 if (is_empty
== isl_bool_error
)
1409 if (is_empty
== isl_bool_false
)
1410 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1413 if (test_plain_unshifted_simple_hull(ctx
) < 0)
1415 if (test_unshifted_simple_hull(ctx
) < 0)
1421 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1425 struct isl_basic_set
*bset1
, *bset2
;
1426 struct isl_set
*set
;
1428 filename
= get_filename(ctx
, name
, "polylib");
1430 input
= fopen(filename
, "r");
1433 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1434 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1436 set
= isl_basic_set_union(bset1
, bset2
);
1437 bset1
= isl_set_convex_hull(set
);
1439 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1441 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1443 isl_basic_set_free(bset1
);
1444 isl_basic_set_free(bset2
);
1453 } convex_hull_tests
[] = {
1454 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1455 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1456 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1457 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1458 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1459 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1460 "i2 <= 5 and i2 >= 4; "
1461 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1462 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1463 "i2 <= 5 + i0 and i2 >= i0 }" },
1464 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1465 "{ [x, y] : 1 = 0 }" },
1466 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1467 "[x, y, 0] : x >= 0 and y < 0 }",
1468 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1471 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1474 int orig_convex
= ctx
->opt
->convex
;
1475 ctx
->opt
->convex
= convex
;
1477 test_convex_hull_case(ctx
, "convex0");
1478 test_convex_hull_case(ctx
, "convex1");
1479 test_convex_hull_case(ctx
, "convex2");
1480 test_convex_hull_case(ctx
, "convex3");
1481 test_convex_hull_case(ctx
, "convex4");
1482 test_convex_hull_case(ctx
, "convex5");
1483 test_convex_hull_case(ctx
, "convex6");
1484 test_convex_hull_case(ctx
, "convex7");
1485 test_convex_hull_case(ctx
, "convex8");
1486 test_convex_hull_case(ctx
, "convex9");
1487 test_convex_hull_case(ctx
, "convex10");
1488 test_convex_hull_case(ctx
, "convex11");
1489 test_convex_hull_case(ctx
, "convex12");
1490 test_convex_hull_case(ctx
, "convex13");
1491 test_convex_hull_case(ctx
, "convex14");
1492 test_convex_hull_case(ctx
, "convex15");
1494 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1495 isl_set
*set1
, *set2
;
1498 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1499 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1500 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1501 equal
= isl_set_is_equal(set1
, set2
);
1508 isl_die(ctx
, isl_error_unknown
,
1509 "unexpected convex hull", return -1);
1512 ctx
->opt
->convex
= orig_convex
;
1517 static int test_convex_hull(isl_ctx
*ctx
)
1519 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1521 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1526 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1530 struct isl_basic_set
*bset1
, *bset2
;
1532 filename
= get_filename(ctx
, name
, "polylib");
1534 input
= fopen(filename
, "r");
1537 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1538 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1540 bset1
= isl_basic_set_gist(bset1
, bset2
);
1542 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1544 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1546 isl_basic_set_free(bset1
);
1547 isl_basic_set_free(bset2
);
1553 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1557 const char *context
;
1559 } plain_gist_tests
[] = {
1560 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1561 "{ [i] -> [j] : i >= 1 }",
1562 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1563 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1564 "(j mod 4 = 2 and k mod 6 = n) }",
1565 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1566 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1567 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1568 "{ [i] -> [j] : i > j }",
1569 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1572 /* Basic tests for isl_map_plain_gist_basic_map.
1574 static int test_plain_gist(isl_ctx
*ctx
)
1578 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1581 isl_map
*map
, *gist
;
1582 isl_basic_map
*context
;
1584 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1585 str
= plain_gist_tests
[i
].context
;
1586 context
= isl_basic_map_read_from_str(ctx
, str
);
1587 map
= isl_map_plain_gist_basic_map(map
, context
);
1588 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1589 equal
= isl_map_is_equal(map
, gist
);
1595 isl_die(ctx
, isl_error_unknown
,
1596 "incorrect gist result", return -1);
1604 const char *context
;
1607 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1608 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1609 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1610 "{ [a, b, c] : a <= 15 }" },
1611 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1612 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1613 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1614 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1615 { "{ [m, n, a, b] : a <= 2147 + n }",
1616 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1617 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1618 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1620 "{ [m, n, ku, kl] }" },
1621 { "{ [a, a, b] : a >= 10 }",
1622 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1623 "{ [a, a, b] : a >= 10 }" },
1624 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1625 "{ [0, j] : j >= 0 }" },
1626 /* Check that no constraints on i6 are introduced in the gist */
1627 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1628 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1629 "5e0 <= 381 - t1 and i4 <= 1) }",
1630 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1631 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1632 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1633 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1634 "20e0 >= 1511 - 4t1 - 5i4) }" },
1635 /* Check that no constraints on i6 are introduced in the gist */
1636 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1637 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1638 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1639 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1640 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1641 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1642 "20e1 <= 1530 - 4t1 - 5i4 and "
1643 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1644 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1645 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1646 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1647 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1648 "10e0 <= -91 + 5i4 + 4i6 and "
1649 "10e0 >= -105 + 5i4 + 4i6) }",
1650 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1651 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1652 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1653 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1654 "{ [a, b, q, p] : b >= 1 + a }",
1655 "{ [a, b, q, p] : false }" },
1656 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1657 "[n] -> { [x] : x mod 32 = 0 }",
1658 "[n] -> { [x = n] }" },
1659 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1660 "{ [x] : x mod 2 = 0 }" },
1661 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1662 "{ [x] : x mod 128 = 0 }" },
1663 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1664 "{ [x] : x mod 3200 = 0 }" },
1665 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1666 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1667 "{ [a, b, c = a] }" },
1668 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1669 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1670 "{ [a, b, c = a] : a mod 3 = 0 }" },
1671 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1672 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1674 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1675 "{ [x,y] : 1 <= y <= 3 }",
1679 /* Check that isl_set_gist behaves as expected.
1681 * For the test cases in gist_tests, besides checking that the result
1682 * is as expected, also check that applying the gist operation does
1683 * not modify the input set (an earlier version of isl would do that) and
1684 * that the test case is consistent, i.e., that the gist has the same
1685 * intersection with the context as the input set.
1687 static int test_gist(struct isl_ctx
*ctx
)
1691 isl_basic_set
*bset1
, *bset2
;
1692 isl_map
*map1
, *map2
;
1695 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1696 int equal_input
, equal_intersection
;
1697 isl_set
*set1
, *set2
, *copy
, *context
;
1699 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1700 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1701 copy
= isl_set_copy(set1
);
1702 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1703 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1704 equal
= isl_set_is_equal(set1
, set2
);
1706 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1707 equal_input
= isl_set_is_equal(set1
, copy
);
1709 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1710 set2
= isl_set_intersect(set2
, context
);
1711 equal_intersection
= isl_set_is_equal(set1
, set2
);
1714 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1717 isl_die(ctx
, isl_error_unknown
,
1718 "incorrect gist result", return -1);
1720 isl_die(ctx
, isl_error_unknown
,
1721 "gist modified input", return -1);
1723 isl_die(ctx
, isl_error_unknown
,
1724 "inconsistent gist test case", return -1);
1727 test_gist_case(ctx
, "gist1");
1729 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1730 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1731 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1732 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1733 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1734 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1735 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1736 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1737 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1738 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1739 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1740 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1741 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1742 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1743 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1744 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1745 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1746 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1747 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1748 bset1
= isl_basic_set_gist(bset1
, bset2
);
1749 assert(bset1
&& bset1
->n_div
== 0);
1750 isl_basic_set_free(bset1
);
1752 /* Check that the integer divisions of the second disjunct
1753 * do not spread to the first disjunct.
1755 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1756 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1757 "(exists (e0 = [(-1 + t1)/16], "
1758 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1759 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1760 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1761 "o0 <= 4294967295 and t1 <= -1)) }";
1762 map1
= isl_map_read_from_str(ctx
, str
);
1763 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1764 map2
= isl_map_read_from_str(ctx
, str
);
1765 map1
= isl_map_gist(map1
, map2
);
1769 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1770 isl_map_free(map1
); return -1);
1771 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1772 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1773 isl_map_free(map1
); return -1);
1776 if (test_plain_gist(ctx
) < 0)
1782 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1784 isl_set
*set
, *set2
;
1788 set
= isl_set_read_from_str(ctx
, str
);
1789 set
= isl_set_coalesce(set
);
1790 set2
= isl_set_read_from_str(ctx
, str
);
1791 equal
= isl_set_is_equal(set
, set2
);
1792 one
= set
&& set
->n
== 1;
1799 isl_die(ctx
, isl_error_unknown
,
1800 "coalesced set not equal to input", return -1);
1801 if (check_one
&& !one
)
1802 isl_die(ctx
, isl_error_unknown
,
1803 "coalesced set should not be a union", return -1);
1808 /* Inputs for coalescing tests with unbounded wrapping.
1809 * "str" is a string representation of the input set.
1810 * "single_disjunct" is set if we expect the result to consist of
1811 * a single disjunct.
1814 int single_disjunct
;
1816 } coalesce_unbounded_tests
[] = {
1817 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1818 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1819 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1820 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1822 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1823 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1824 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1825 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1828 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1829 * option turned off.
1831 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1837 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1838 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1840 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
1841 const char *str
= coalesce_unbounded_tests
[i
].str
;
1842 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
1843 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
1849 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1854 /* Inputs for coalescing tests.
1855 * "str" is a string representation of the input set.
1856 * "single_disjunct" is set if we expect the result to consist of
1857 * a single disjunct.
1860 int single_disjunct
;
1862 } coalesce_tests
[] = {
1863 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1864 "y >= x & x >= 2 & 5 >= y }" },
1865 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1866 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1867 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1868 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1869 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1870 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1871 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1872 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1873 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1874 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1875 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1876 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1877 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1878 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1879 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1880 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1881 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1882 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1883 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1884 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1885 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1886 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1887 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1888 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1889 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1890 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1891 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1892 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1893 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1894 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1895 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1896 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1897 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1898 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1899 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1900 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1901 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1902 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1903 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1904 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1905 "[o0, o1, o2, o3, o4, o5, o6]] : "
1906 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1907 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1908 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1909 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1910 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1911 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1912 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1913 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1914 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1915 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1916 "o6 >= i3 + i6 - o3 and M >= 0 and "
1917 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1918 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1919 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1920 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1921 "(o0 = 0 and M >= 2 and N >= 3) or "
1922 "(M = 0 and o0 = 0 and N >= 3) }" },
1923 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1924 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1925 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1926 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1927 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1928 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1929 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1930 "(y = 3 and x = 1) }" },
1931 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1932 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1933 "i1 <= M and i3 <= M and i4 <= M) or "
1934 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1935 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1936 "i4 <= -1 + M) }" },
1937 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1938 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1939 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1940 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1941 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1942 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1943 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1944 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1945 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1946 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1947 { 0, "{ [a, b] : exists e : 2e = a and "
1948 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1949 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1950 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1951 "j >= 1 and j' <= i + j - i' and i >= 1; "
1953 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1954 "[i,j] : exists a : j = 3a }" },
1955 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1956 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1958 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1959 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1960 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1961 "c <= 6 + 8a and a >= 3; "
1962 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1963 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1964 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1965 "[x,0] : 3 <= x <= 4 }" },
1966 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1967 "[x,0] : 4 <= x <= 5 }" },
1968 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1969 "[x,0] : 3 <= x <= 5 }" },
1970 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1971 "[x,0] : 3 <= x <= 4 }" },
1972 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1974 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1975 { 1, "{ [0,0]; [1,1] }" },
1976 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
1977 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
1979 "[k, 0, k] : k <= 6 and k >= 1 }" },
1980 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
1981 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
1982 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
1983 { 1, "[n] -> { [1] : n >= 0;"
1984 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
1985 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
1986 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
1987 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
1988 "2e0 <= x and 2e0 <= n);"
1989 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
1991 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
1992 "128e0 >= -134 + 127t1 and t1 >= 2 and "
1993 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
1995 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
1996 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
1998 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
1999 "t1 >= 13 and t1 <= 16);"
2000 "[t1] : t1 <= 15 and t1 >= 12 }" },
2001 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2002 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2003 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2004 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2005 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2006 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2008 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2009 "(exists (e0 : 3e0 = -2 + c0)) }" },
2010 { 0, "[n, b0, t0] -> "
2011 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2012 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2013 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2014 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2015 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2016 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2017 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2018 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2019 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2020 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2021 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2022 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2023 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2024 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2025 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2026 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2027 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2028 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2029 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2030 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2031 { 0, "{ [i0, i1, i2] : "
2032 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2033 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2034 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2035 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2036 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2037 "32e0 <= 31 + i0)) or "
2039 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2040 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2041 "2*floor((c)/2) = c and 0 <= a <= 192;"
2042 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2044 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2045 "(0 <= a <= b <= n) }" },
2046 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2047 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2048 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2049 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2050 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2051 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2052 "b = 3 and 9e0 <= -19 + 2c)) }" },
2053 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2054 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2055 "(a = 4 and b = 3 and "
2056 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2057 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2058 "(b = -1 + a and 0 < a <= 3 and "
2059 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2060 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2061 "b = 3 and 9e0 <= -19 + 2c)) }" },
2062 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2064 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2066 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2067 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2068 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2069 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2070 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2071 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2072 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2073 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2074 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2075 { 1, "{ [a] : a <= 8 and "
2076 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2077 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2078 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2079 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2080 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2081 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2082 "(a < 0 and 3*floor((a)/3) < a) }" },
2083 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2084 "(a < -1 and 3*floor((a)/3) < a) }" },
2085 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2086 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2087 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2088 "or (2 <= a <= 15 and b < a)) }" },
2089 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2090 "32*floor((a)/32) < a) or a <= 15) }" },
2091 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2092 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2093 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2094 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2095 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2096 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2097 "S_0[n] : n <= m <= 2 + n }" },
2098 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2099 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2101 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2102 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2103 "2e0 < -a + 2b) }" },
2104 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2105 "[i, 0, i] : 0 <= i <= 7 }" },
2106 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2107 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2108 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2109 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2110 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2111 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2112 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2113 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2114 "a > 0 and a <= 5) }" },
2117 /* A specialized coalescing test case that would result
2118 * in a segmentation fault or a failed assertion in earlier versions of isl.
2120 static int test_coalesce_special(struct isl_ctx
*ctx
)
2123 isl_map
*map1
, *map2
;
2125 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2126 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2127 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2128 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2129 "o1 <= 239 and o1 >= 212)) or "
2130 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2131 "o1 <= 241 and o1 >= 240));"
2132 "[S_L220_OUT[] -> T7[]] -> "
2133 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2134 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2135 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2136 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2137 map1
= isl_map_read_from_str(ctx
, str
);
2138 map1
= isl_map_align_divs_internal(map1
);
2139 map1
= isl_map_coalesce(map1
);
2140 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2141 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2142 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2143 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2144 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2145 map2
= isl_map_read_from_str(ctx
, str
);
2146 map2
= isl_map_union(map2
, map1
);
2147 map2
= isl_map_align_divs_internal(map2
);
2148 map2
= isl_map_coalesce(map2
);
2156 /* A specialized coalescing test case that would result in an assertion
2157 * in an earlier version of isl.
2158 * The explicit call to isl_basic_set_union prevents the implicit
2159 * equality constraints in the first basic map from being detected prior
2160 * to the call to isl_set_coalesce, at least at the point
2161 * where this test case was introduced.
2163 static int test_coalesce_special2(struct isl_ctx
*ctx
)
2166 isl_basic_set
*bset1
, *bset2
;
2169 str
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2170 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2171 str
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2172 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2173 set
= isl_basic_set_union(bset1
, bset2
);
2174 set
= isl_set_coalesce(set
);
2182 /* Check that calling isl_set_coalesce does not leave other sets
2183 * that may share some information with the input to isl_set_coalesce
2184 * in an inconsistent state.
2185 * In particular, older versions of isl would modify all copies
2186 * of the basic sets in the isl_set_coalesce input in a way
2187 * that could leave them in an inconsistent state.
2188 * The result of printing any other set containing one of these
2189 * basic sets would then result in an invalid set description.
2191 static int test_coalesce_special3(isl_ctx
*ctx
)
2195 isl_set
*set1
, *set2
;
2198 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2199 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2200 set2
= isl_set_read_from_str(ctx
, str
);
2201 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2202 set1
= isl_set_coalesce(set1
);
2205 p
= isl_printer_to_str(ctx
);
2206 p
= isl_printer_print_set(p
, set2
);
2208 s
= isl_printer_get_str(p
);
2209 isl_printer_free(p
);
2210 set1
= isl_set_read_from_str(ctx
, s
);
2220 /* Test the functionality of isl_set_coalesce.
2221 * That is, check that the output is always equal to the input
2222 * and in some cases that the result consists of a single disjunct.
2224 static int test_coalesce(struct isl_ctx
*ctx
)
2228 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2229 const char *str
= coalesce_tests
[i
].str
;
2230 int check_one
= coalesce_tests
[i
].single_disjunct
;
2231 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2235 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2237 if (test_coalesce_special(ctx
) < 0)
2239 if (test_coalesce_special2(ctx
) < 0)
2241 if (test_coalesce_special3(ctx
) < 0)
2247 /* Construct a representation of the graph on the right of Figure 1
2248 * in "Computing the Transitive Closure of a Union of
2249 * Affine Integer Tuple Relations".
2251 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2254 isl_map
*up
, *right
;
2256 dom
= isl_set_read_from_str(ctx
,
2257 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2258 "2 x - 3 y + 3 >= 0 }");
2259 right
= isl_map_read_from_str(ctx
,
2260 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2261 up
= isl_map_read_from_str(ctx
,
2262 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2263 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2264 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2265 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2266 up
= isl_map_intersect_range(up
, dom
);
2267 return isl_map_union(up
, right
);
2270 /* Construct a representation of the power of the graph
2271 * on the right of Figure 1 in "Computing the Transitive Closure of
2272 * a Union of Affine Integer Tuple Relations".
2274 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2276 return isl_map_read_from_str(ctx
,
2277 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2278 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2279 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2282 /* Construct a representation of the transitive closure of the graph
2283 * on the right of Figure 1 in "Computing the Transitive Closure of
2284 * a Union of Affine Integer Tuple Relations".
2286 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2288 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2291 static int test_closure(isl_ctx
*ctx
)
2294 isl_map
*map
, *map2
;
2297 /* COCOA example 1 */
2298 map
= isl_map_read_from_str(ctx
,
2299 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2300 "1 <= i and i < n and 1 <= j and j < n or "
2301 "i2 = i + 1 and j2 = j - 1 and "
2302 "1 <= i and i < n and 2 <= j and j <= n }");
2303 map
= isl_map_power(map
, &exact
);
2307 /* COCOA example 1 */
2308 map
= isl_map_read_from_str(ctx
,
2309 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2310 "1 <= i and i < n and 1 <= j and j < n or "
2311 "i2 = i + 1 and j2 = j - 1 and "
2312 "1 <= i and i < n and 2 <= j and j <= n }");
2313 map
= isl_map_transitive_closure(map
, &exact
);
2315 map2
= isl_map_read_from_str(ctx
,
2316 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2317 "1 <= i and i < n and 1 <= j and j <= n and "
2318 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2319 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2320 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2321 assert(isl_map_is_equal(map
, map2
));
2325 map
= isl_map_read_from_str(ctx
,
2326 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2327 " 0 <= y and y <= n }");
2328 map
= isl_map_transitive_closure(map
, &exact
);
2329 map2
= isl_map_read_from_str(ctx
,
2330 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2331 " 0 <= y and y <= n }");
2332 assert(isl_map_is_equal(map
, map2
));
2336 /* COCOA example 2 */
2337 map
= isl_map_read_from_str(ctx
,
2338 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2339 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2340 "i2 = i + 2 and j2 = j - 2 and "
2341 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2342 map
= isl_map_transitive_closure(map
, &exact
);
2344 map2
= isl_map_read_from_str(ctx
,
2345 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2346 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2347 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2348 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2349 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2350 assert(isl_map_is_equal(map
, map2
));
2354 /* COCOA Fig.2 left */
2355 map
= isl_map_read_from_str(ctx
,
2356 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2357 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2359 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2360 "j <= 2 i - 3 and j <= n - 2 or "
2361 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2362 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2363 map
= isl_map_transitive_closure(map
, &exact
);
2367 /* COCOA Fig.2 right */
2368 map
= isl_map_read_from_str(ctx
,
2369 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2370 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2372 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2373 "j <= 2 i - 4 and j <= n - 3 or "
2374 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2375 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2376 map
= isl_map_power(map
, &exact
);
2380 /* COCOA Fig.2 right */
2381 map
= isl_map_read_from_str(ctx
,
2382 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2383 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2385 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2386 "j <= 2 i - 4 and j <= n - 3 or "
2387 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2388 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
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,k3,k : "
2393 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2394 "j <= n and 3 + i + 2 j <= 3 n and "
2395 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2396 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2397 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2398 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2399 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2400 assert(isl_map_is_equal(map
, map2
));
2404 map
= cocoa_fig_1_right_graph(ctx
);
2405 map
= isl_map_transitive_closure(map
, &exact
);
2407 map2
= cocoa_fig_1_right_tc(ctx
);
2408 assert(isl_map_is_equal(map
, map2
));
2412 map
= cocoa_fig_1_right_graph(ctx
);
2413 map
= isl_map_power(map
, &exact
);
2414 map2
= cocoa_fig_1_right_power(ctx
);
2415 equal
= isl_map_is_equal(map
, map2
);
2421 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2423 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2425 /* COCOA Theorem 1 counter example */
2426 map
= isl_map_read_from_str(ctx
,
2427 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2428 "i2 = 1 and j2 = j or "
2429 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2430 map
= isl_map_transitive_closure(map
, &exact
);
2434 map
= isl_map_read_from_str(ctx
,
2435 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2436 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2437 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2438 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2439 map
= isl_map_transitive_closure(map
, &exact
);
2443 /* Kelly et al 1996, fig 12 */
2444 map
= isl_map_read_from_str(ctx
,
2445 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2446 "1 <= i,j,j+1 <= n or "
2447 "j = n and j2 = 1 and i2 = i + 1 and "
2448 "1 <= i,i+1 <= n }");
2449 map
= isl_map_transitive_closure(map
, &exact
);
2451 map2
= isl_map_read_from_str(ctx
,
2452 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2453 "1 <= i <= n and i = i2 or "
2454 "1 <= i < i2 <= n and 1 <= j <= n and "
2456 assert(isl_map_is_equal(map
, map2
));
2460 /* Omega's closure4 */
2461 map
= isl_map_read_from_str(ctx
,
2462 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2463 "1 <= x,y <= 10 or "
2464 "x2 = x + 1 and y2 = y and "
2465 "1 <= x <= 20 && 5 <= y <= 15 }");
2466 map
= isl_map_transitive_closure(map
, &exact
);
2470 map
= isl_map_read_from_str(ctx
,
2471 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2472 map
= isl_map_transitive_closure(map
, &exact
);
2474 map2
= isl_map_read_from_str(ctx
,
2475 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2476 assert(isl_map_is_equal(map
, map2
));
2480 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2481 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2482 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2483 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2484 map
= isl_map_read_from_str(ctx
, str
);
2485 map
= isl_map_transitive_closure(map
, &exact
);
2487 map2
= isl_map_read_from_str(ctx
, str
);
2488 assert(isl_map_is_equal(map
, map2
));
2492 str
= "{[0] -> [1]; [2] -> [3]}";
2493 map
= isl_map_read_from_str(ctx
, str
);
2494 map
= isl_map_transitive_closure(map
, &exact
);
2496 map2
= isl_map_read_from_str(ctx
, str
);
2497 assert(isl_map_is_equal(map
, map2
));
2501 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2502 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2503 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2504 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2505 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2506 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2507 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2508 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2509 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2510 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2511 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2512 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2513 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2514 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2515 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2516 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2517 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2518 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2519 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2520 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2521 map
= isl_map_read_from_str(ctx
, str
);
2522 map
= isl_map_transitive_closure(map
, NULL
);
2529 static int test_lex(struct isl_ctx
*ctx
)
2535 dim
= isl_space_set_alloc(ctx
, 0, 0);
2536 map
= isl_map_lex_le(dim
);
2537 empty
= isl_map_is_empty(map
);
2543 isl_die(ctx
, isl_error_unknown
,
2544 "expecting non-empty result", return -1);
2549 /* Inputs for isl_map_lexmin tests.
2550 * "map" is the input and "lexmin" is the expected result.
2555 } lexmin_tests
[] = {
2556 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2557 "{ [x] -> [5] : 6 <= x <= 8; "
2558 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2559 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2560 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2561 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2562 "{ [x] -> [y] : (4y = x and x >= 0) or "
2563 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2564 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2565 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2566 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2567 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2568 /* Check that empty pieces are properly combined. */
2569 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2570 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2571 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2572 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2573 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2575 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2576 "a <= 255 and c <= 255 and d <= 255 - j and "
2577 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2578 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2579 "247d <= 247 + i and 248 - b <= 248d <= c and "
2580 "254d >= i - a + b and 254d >= -a + b and "
2581 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2583 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2584 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2585 "247j >= 62738 - i and 509j <= 129795 + i and "
2586 "742j >= 188724 - i; "
2587 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2588 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2589 "16*floor((8 + b)/16) <= 7 + b; "
2591 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2592 "[a] -> [b = 0] : 0 < a <= 509 }" },
2593 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2594 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2597 static int test_lexmin(struct isl_ctx
*ctx
)
2602 isl_basic_map
*bmap
;
2603 isl_map
*map
, *map2
;
2606 isl_pw_multi_aff
*pma
;
2608 str
= "[p0, p1] -> { [] -> [] : "
2609 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2610 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2611 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2612 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2613 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2614 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2615 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2616 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2617 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2618 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2619 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2620 map
= isl_map_read_from_str(ctx
, str
);
2621 map
= isl_map_lexmin(map
);
2624 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2625 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2626 set
= isl_set_read_from_str(ctx
, str
);
2627 set
= isl_set_lexmax(set
);
2628 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
2629 set2
= isl_set_read_from_str(ctx
, str
);
2630 set
= isl_set_intersect(set
, set2
);
2631 assert(!isl_set_is_empty(set
));
2634 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
2635 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
2636 map
= isl_map_lexmin(map
);
2637 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
2638 equal
= isl_map_is_equal(map
, map2
);
2645 isl_die(ctx
, isl_error_unknown
,
2646 "unexpected result", return -1);
2649 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2650 " 8i' <= i and 8i' >= -7 + i }";
2651 bmap
= isl_basic_map_read_from_str(ctx
, str
);
2652 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
2653 map2
= isl_map_from_pw_multi_aff(pma
);
2654 map
= isl_map_from_basic_map(bmap
);
2655 assert(isl_map_is_equal(map
, map2
));
2659 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2660 " 8i' <= i and 8i' >= -7 + i }";
2661 set
= isl_set_read_from_str(ctx
, str
);
2662 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
2663 set2
= isl_set_from_pw_multi_aff(pma
);
2664 equal
= isl_set_is_equal(set
, set2
);
2670 isl_die(ctx
, isl_error_unknown
,
2671 "unexpected difference between set and "
2672 "piecewise affine expression", return -1);
2677 /* A specialized isl_set_min_val test case that would return the wrong result
2678 * in earlier versions of isl.
2679 * The explicit call to isl_basic_set_union prevents the second basic set
2680 * from being determined to be empty prior to the call to isl_set_min_val,
2681 * at least at the point where this test case was introduced.
2683 static int test_min_special(isl_ctx
*ctx
)
2686 isl_basic_set
*bset1
, *bset2
;
2692 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
2693 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2694 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
2695 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2696 set
= isl_basic_set_union(bset1
, bset2
);
2697 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
2699 res
= isl_set_min_val(set
, obj
);
2700 ok
= isl_val_cmp_si(res
, 5) == 0;
2709 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
2715 /* A specialized isl_set_min_val test case that would return an error
2716 * in earlier versions of isl.
2718 static int test_min_special2(isl_ctx
*ctx
)
2721 isl_basic_set
*bset
;
2725 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
2726 bset
= isl_basic_set_read_from_str(ctx
, str
);
2728 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
2730 res
= isl_basic_set_max_val(bset
, obj
);
2732 isl_basic_set_free(bset
);
2745 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
2746 __isl_keep isl_aff
*obj
);
2749 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
2750 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
2751 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
2752 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
2753 &isl_set_max_val
, "30" },
2757 /* Perform basic isl_set_min_val and isl_set_max_val tests.
2758 * In particular, check the results on non-convex inputs.
2760 static int test_min(struct isl_ctx
*ctx
)
2768 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
2769 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
2770 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
2771 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
2772 val
= opt_tests
[i
].fn(set
, obj
);
2773 ok
= isl_val_eq(res
, val
);
2782 isl_die(ctx
, isl_error_unknown
,
2783 "unexpected optimum", return -1);
2786 if (test_min_special(ctx
) < 0)
2788 if (test_min_special2(ctx
) < 0)
2799 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
2800 void *dep_user
, void *user
)
2802 struct must_may
*mm
= (struct must_may
*)user
;
2805 mm
->must
= isl_map_union(mm
->must
, dep
);
2807 mm
->may
= isl_map_union(mm
->may
, dep
);
2812 static int common_space(void *first
, void *second
)
2814 int depth
= *(int *)first
;
2818 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
2826 map2
= isl_map_read_from_str(map
->ctx
, str
);
2827 equal
= isl_map_is_equal(map
, map2
);
2833 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
2837 equal
= map_is_equal(map
, str
);
2841 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
2842 "result not as expected", return -1);
2846 static int test_dep(struct isl_ctx
*ctx
)
2851 isl_access_info
*ai
;
2858 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2859 map
= isl_map_read_from_str(ctx
, str
);
2860 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2862 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2863 map
= isl_map_read_from_str(ctx
, str
);
2864 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2866 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2867 map
= isl_map_read_from_str(ctx
, str
);
2868 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2870 flow
= isl_access_info_compute_flow(ai
);
2871 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2872 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2873 mm
.may
= isl_map_empty(dim
);
2875 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2877 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
2878 " [1,10,0] -> [2,5,0] }";
2879 assert(map_is_equal(mm
.must
, str
));
2880 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2881 assert(map_is_equal(mm
.may
, str
));
2883 isl_map_free(mm
.must
);
2884 isl_map_free(mm
.may
);
2885 isl_flow_free(flow
);
2888 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2889 map
= isl_map_read_from_str(ctx
, str
);
2890 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2892 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2893 map
= isl_map_read_from_str(ctx
, str
);
2894 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2896 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2897 map
= isl_map_read_from_str(ctx
, str
);
2898 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2900 flow
= isl_access_info_compute_flow(ai
);
2901 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2902 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2903 mm
.may
= isl_map_empty(dim
);
2905 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2907 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2908 assert(map_is_equal(mm
.must
, str
));
2909 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2910 assert(map_is_equal(mm
.may
, str
));
2912 isl_map_free(mm
.must
);
2913 isl_map_free(mm
.may
);
2914 isl_flow_free(flow
);
2917 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2918 map
= isl_map_read_from_str(ctx
, str
);
2919 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2921 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2922 map
= isl_map_read_from_str(ctx
, str
);
2923 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2925 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2926 map
= isl_map_read_from_str(ctx
, str
);
2927 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2929 flow
= isl_access_info_compute_flow(ai
);
2930 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2931 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2932 mm
.may
= isl_map_empty(dim
);
2934 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2936 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
2937 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2938 assert(map_is_equal(mm
.may
, str
));
2939 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2940 assert(map_is_equal(mm
.must
, str
));
2942 isl_map_free(mm
.must
);
2943 isl_map_free(mm
.may
);
2944 isl_flow_free(flow
);
2947 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
2948 map
= isl_map_read_from_str(ctx
, str
);
2949 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2951 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2952 map
= isl_map_read_from_str(ctx
, str
);
2953 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2955 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
2956 map
= isl_map_read_from_str(ctx
, str
);
2957 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2959 flow
= isl_access_info_compute_flow(ai
);
2960 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2961 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2962 mm
.may
= isl_map_empty(dim
);
2964 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2966 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2967 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2968 assert(map_is_equal(mm
.may
, str
));
2969 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2970 assert(map_is_equal(mm
.must
, str
));
2972 isl_map_free(mm
.must
);
2973 isl_map_free(mm
.may
);
2974 isl_flow_free(flow
);
2977 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2978 map
= isl_map_read_from_str(ctx
, str
);
2979 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2981 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2982 map
= isl_map_read_from_str(ctx
, str
);
2983 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2985 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2986 map
= isl_map_read_from_str(ctx
, str
);
2987 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2989 flow
= isl_access_info_compute_flow(ai
);
2990 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2991 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2992 mm
.may
= isl_map_empty(dim
);
2994 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2996 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2997 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2998 assert(map_is_equal(mm
.may
, str
));
2999 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3000 assert(map_is_equal(mm
.must
, str
));
3002 isl_map_free(mm
.must
);
3003 isl_map_free(mm
.may
);
3004 isl_flow_free(flow
);
3009 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3010 map
= isl_map_read_from_str(ctx
, str
);
3011 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
3013 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3014 map
= isl_map_read_from_str(ctx
, str
);
3015 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3017 flow
= isl_access_info_compute_flow(ai
);
3018 dim
= isl_space_alloc(ctx
, 0, 5, 5);
3019 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3020 mm
.may
= isl_map_empty(dim
);
3022 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3024 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3025 assert(map_is_equal(mm
.must
, str
));
3026 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3027 assert(map_is_equal(mm
.may
, str
));
3029 isl_map_free(mm
.must
);
3030 isl_map_free(mm
.may
);
3031 isl_flow_free(flow
);
3036 /* Check that the dependence analysis proceeds without errors.
3037 * Earlier versions of isl would break down during the analysis
3038 * due to the use of the wrong spaces.
3040 static int test_flow(isl_ctx
*ctx
)
3043 isl_union_map
*access
, *schedule
;
3044 isl_union_map
*must_dep
, *may_dep
;
3047 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3048 access
= isl_union_map_read_from_str(ctx
, str
);
3049 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3050 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3051 "S2[] -> [1,0,0,0]; "
3052 "S3[] -> [-1,0,0,0] }";
3053 schedule
= isl_union_map_read_from_str(ctx
, str
);
3054 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
3055 isl_union_map_copy(access
), schedule
,
3056 &must_dep
, &may_dep
, NULL
, NULL
);
3057 isl_union_map_free(may_dep
);
3058 isl_union_map_free(must_dep
);
3067 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3068 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3069 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3070 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3071 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3072 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3073 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3074 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3075 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3078 int test_sv(isl_ctx
*ctx
)
3080 isl_union_map
*umap
;
3084 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
3085 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
3086 sv
= isl_union_map_is_single_valued(umap
);
3087 isl_union_map_free(umap
);
3090 if (sv_tests
[i
].sv
&& !sv
)
3091 isl_die(ctx
, isl_error_internal
,
3092 "map not detected as single valued", return -1);
3093 if (!sv_tests
[i
].sv
&& sv
)
3094 isl_die(ctx
, isl_error_internal
,
3095 "map detected as single valued", return -1);
3104 } bijective_tests
[] = {
3105 { "[N,M]->{[i,j] -> [i]}", 0 },
3106 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3107 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3108 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3109 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3110 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3111 { "[N,M]->{[i,j] -> []}", 0 },
3112 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3113 { "[N,M]->{[i,j] -> [2i]}", 0 },
3114 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3115 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3116 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3117 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3120 static int test_bijective(struct isl_ctx
*ctx
)
3126 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
3127 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
3128 bijective
= isl_map_is_bijective(map
);
3132 if (bijective_tests
[i
].bijective
&& !bijective
)
3133 isl_die(ctx
, isl_error_internal
,
3134 "map not detected as bijective", return -1);
3135 if (!bijective_tests
[i
].bijective
&& bijective
)
3136 isl_die(ctx
, isl_error_internal
,
3137 "map detected as bijective", return -1);
3143 /* Inputs for isl_pw_qpolynomial_gist tests.
3144 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3150 } pwqp_gist_tests
[] = {
3151 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3152 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3153 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3154 "{ [i] -> -1/2 + 1/2 * i }" },
3155 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3158 static int test_pwqp(struct isl_ctx
*ctx
)
3163 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3166 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3167 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3169 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3172 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3173 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3175 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3177 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3179 isl_pw_qpolynomial_free(pwqp1
);
3181 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3182 str
= pwqp_gist_tests
[i
].pwqp
;
3183 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3184 str
= pwqp_gist_tests
[i
].set
;
3185 set
= isl_set_read_from_str(ctx
, str
);
3186 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3187 str
= pwqp_gist_tests
[i
].gist
;
3188 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3189 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3190 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3191 isl_pw_qpolynomial_free(pwqp1
);
3196 isl_die(ctx
, isl_error_unknown
,
3197 "unexpected result", return -1);
3200 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3201 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3202 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3203 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3205 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3207 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3209 isl_pw_qpolynomial_free(pwqp1
);
3211 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3212 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3213 str
= "{ [x] -> x }";
3214 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3216 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3218 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3220 isl_pw_qpolynomial_free(pwqp1
);
3222 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3223 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3224 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3225 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3226 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3227 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3228 isl_pw_qpolynomial_free(pwqp1
);
3230 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3231 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3232 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3233 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3234 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3235 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3236 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3237 isl_pw_qpolynomial_free(pwqp1
);
3238 isl_pw_qpolynomial_free(pwqp2
);
3242 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3244 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3245 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3246 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3247 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3248 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3250 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3251 isl_pw_qpolynomial_free(pwqp1
);
3252 isl_pw_qpolynomial_free(pwqp2
);
3256 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3261 static int test_split_periods(isl_ctx
*ctx
)
3264 isl_pw_qpolynomial
*pwqp
;
3266 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3267 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3268 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3269 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3271 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3273 isl_pw_qpolynomial_free(pwqp
);
3281 static int test_union(isl_ctx
*ctx
)
3284 isl_union_set
*uset1
, *uset2
;
3285 isl_union_map
*umap1
, *umap2
;
3288 str
= "{ [i] : 0 <= i <= 1 }";
3289 uset1
= isl_union_set_read_from_str(ctx
, str
);
3290 str
= "{ [1] -> [0] }";
3291 umap1
= isl_union_map_read_from_str(ctx
, str
);
3293 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3294 equal
= isl_union_map_is_equal(umap1
, umap2
);
3296 isl_union_map_free(umap1
);
3297 isl_union_map_free(umap2
);
3302 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3305 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3306 umap1
= isl_union_map_read_from_str(ctx
, str
);
3307 str
= "{ A[i]; B[i] }";
3308 uset1
= isl_union_set_read_from_str(ctx
, str
);
3310 uset2
= isl_union_map_domain(umap1
);
3312 equal
= isl_union_set_is_equal(uset1
, uset2
);
3314 isl_union_set_free(uset1
);
3315 isl_union_set_free(uset2
);
3320 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3326 /* Check that computing a bound of a non-zero polynomial over an unbounded
3327 * domain does not produce a rational value.
3328 * In particular, check that the upper bound is infinity.
3330 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
3333 isl_pw_qpolynomial
*pwqp
;
3334 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
3337 str
= "{ [m,n] -> -m * n }";
3338 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3339 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3341 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3342 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3343 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
3344 isl_pw_qpolynomial_fold_free(pwf
);
3345 isl_pw_qpolynomial_fold_free(pwf2
);
3350 isl_die(ctx
, isl_error_unknown
,
3351 "expecting infinite polynomial bound", return -1);
3356 static int test_bound(isl_ctx
*ctx
)
3360 isl_pw_qpolynomial
*pwqp
;
3361 isl_pw_qpolynomial_fold
*pwf
;
3363 if (test_bound_unbounded_domain(ctx
) < 0)
3366 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
3367 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3368 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3369 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3370 isl_pw_qpolynomial_fold_free(pwf
);
3372 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3375 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3376 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3377 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3378 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3379 isl_pw_qpolynomial_fold_free(pwf
);
3381 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3387 /* Check that the conversion from 'set' to 'basic set list' works as expected.
3389 static isl_stat
test_get_list_bset_from_set(isl_ctx
*ctx
)
3393 isl_set
*set
, *set2
;
3394 isl_basic_set_list
*bset_list
;
3396 set
= isl_set_read_from_str(ctx
, "{ [0]; [2]; [3] }");
3397 bset_list
= isl_set_get_basic_set_list(set
);
3399 set2
= isl_set_empty(isl_set_get_space(set
));
3401 for (i
= 0; i
< isl_basic_set_list_n_basic_set(bset_list
); i
++) {
3402 isl_basic_set
*bset
;
3403 bset
= isl_basic_set_list_get_basic_set(bset_list
, i
);
3404 set2
= isl_set_union(set2
, isl_set_from_basic_set(bset
));
3407 equal
= isl_set_is_equal(set
, set2
);
3411 isl_basic_set_list_free(bset_list
);
3414 return isl_stat_error
;
3417 isl_die(ctx
, isl_error_unknown
, "sets are not equal",
3418 return isl_stat_error
);
3423 /* Check that the conversion from 'union set' to 'basic set list' works as
3426 static isl_stat
test_get_list_bset_from_uset(isl_ctx
*ctx
)
3430 isl_union_set
*uset
, *uset2
;
3431 isl_basic_set_list
*bset_list
;
3433 uset
= isl_union_set_read_from_str(ctx
, "{ A[0]; B[2]; B[3] }");
3434 bset_list
= isl_union_set_get_basic_set_list(uset
);
3436 uset2
= isl_union_set_empty(isl_union_set_get_space(uset
));
3438 for (i
= 0; i
< isl_basic_set_list_n_basic_set(bset_list
); i
++) {
3439 isl_basic_set
*bset
;
3440 bset
= isl_basic_set_list_get_basic_set(bset_list
, i
);
3441 uset2
= isl_union_set_union(uset2
,
3442 isl_union_set_from_basic_set(bset
));
3445 equal
= isl_union_set_is_equal(uset
, uset2
);
3447 isl_union_set_free(uset
);
3448 isl_union_set_free(uset2
);
3449 isl_basic_set_list_free(bset_list
);
3452 return isl_stat_error
;
3455 isl_die(ctx
, isl_error_unknown
, "sets are not equal",
3456 return isl_stat_error
);
3461 /* Check that the conversion from 'union set' to 'set list' works as expected.
3463 static isl_stat
test_get_list_set_from_uset(isl_ctx
*ctx
)
3467 isl_union_set
*uset
, *uset2
;
3468 isl_set_list
*set_list
;
3470 uset
= isl_union_set_read_from_str(ctx
, "{ A[0]; A[2]; B[3] }");
3471 set_list
= isl_union_set_get_set_list(uset
);
3473 uset2
= isl_union_set_empty(isl_union_set_get_space(uset
));
3475 for (i
= 0; i
< isl_set_list_n_set(set_list
); i
++) {
3477 set
= isl_set_list_get_set(set_list
, i
);
3478 uset2
= isl_union_set_union(uset2
, isl_union_set_from_set(set
));
3481 equal
= isl_union_set_is_equal(uset
, uset2
);
3483 isl_union_set_free(uset
);
3484 isl_union_set_free(uset2
);
3485 isl_set_list_free(set_list
);
3488 return isl_stat_error
;
3491 isl_die(ctx
, isl_error_unknown
, "union sets are not equal",
3492 return isl_stat_error
);
3497 /* Check that the conversion from 'map' to 'basic map list' works as expected.
3499 static isl_stat
test_get_list_bmap_from_map(isl_ctx
*ctx
)
3503 isl_map
*map
, *map2
;
3504 isl_basic_map_list
*bmap_list
;
3506 map
= isl_map_read_from_str(ctx
,
3507 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }");
3508 bmap_list
= isl_map_get_basic_map_list(map
);
3510 map2
= isl_map_empty(isl_map_get_space(map
));
3512 for (i
= 0; i
< isl_basic_map_list_n_basic_map(bmap_list
); i
++) {
3513 isl_basic_map
*bmap
;
3514 bmap
= isl_basic_map_list_get_basic_map(bmap_list
, i
);
3515 map2
= isl_map_union(map2
, isl_map_from_basic_map(bmap
));
3518 equal
= isl_map_is_equal(map
, map2
);
3522 isl_basic_map_list_free(bmap_list
);
3525 return isl_stat_error
;
3528 isl_die(ctx
, isl_error_unknown
, "maps are not equal",
3529 return isl_stat_error
);
3534 /* Check that the conversion from 'union map' to 'map list' works as expected.
3536 static isl_stat
test_get_list_map_from_umap(isl_ctx
*ctx
)
3540 isl_union_map
*umap
, *umap2
;
3541 isl_map_list
*map_list
;
3543 umap
= isl_union_map_read_from_str(ctx
,
3544 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }");
3545 map_list
= isl_union_map_get_map_list(umap
);
3547 umap2
= isl_union_map_empty(isl_union_map_get_space(umap
));
3549 for (i
= 0; i
< isl_map_list_n_map(map_list
); i
++) {
3551 map
= isl_map_list_get_map(map_list
, i
);
3552 umap2
= isl_union_map_union(umap2
, isl_union_map_from_map(map
));
3555 equal
= isl_union_map_is_equal(umap
, umap2
);
3557 isl_union_map_free(umap
);
3558 isl_union_map_free(umap2
);
3559 isl_map_list_free(map_list
);
3562 return isl_stat_error
;
3565 isl_die(ctx
, isl_error_unknown
, "union maps are not equal",
3566 return isl_stat_error
);
3571 /* Check that the conversion from isl objects to lists works as expected.
3573 static int test_get_list(isl_ctx
*ctx
)
3575 if (test_get_list_bset_from_set(ctx
))
3577 if (test_get_list_bset_from_uset(ctx
))
3579 if (test_get_list_set_from_uset(ctx
))
3581 if (test_get_list_bmap_from_map(ctx
))
3583 if (test_get_list_map_from_umap(ctx
))
3589 static int test_lift(isl_ctx
*ctx
)
3592 isl_basic_map
*bmap
;
3593 isl_basic_set
*bset
;
3595 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
3596 bset
= isl_basic_set_read_from_str(ctx
, str
);
3597 bset
= isl_basic_set_lift(bset
);
3598 bmap
= isl_basic_map_from_range(bset
);
3599 bset
= isl_basic_map_domain(bmap
);
3600 isl_basic_set_free(bset
);
3609 } subset_tests
[] = {
3611 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3612 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3613 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3615 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3616 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3617 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3618 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3619 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3620 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3621 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3622 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3623 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3624 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3625 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3626 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3627 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3628 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3629 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3630 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3631 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3632 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3633 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3634 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3635 "4e0 <= -57 + i0 + i1)) or "
3636 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3637 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3638 "4e0 >= -61 + i0 + i1)) or "
3639 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3640 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3643 static int test_subset(isl_ctx
*ctx
)
3646 isl_set
*set1
, *set2
;
3649 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
3650 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
3651 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
3652 subset
= isl_set_is_subset(set1
, set2
);
3657 if (subset
!= subset_tests
[i
].subset
)
3658 isl_die(ctx
, isl_error_unknown
,
3659 "incorrect subset result", return -1);
3666 const char *minuend
;
3667 const char *subtrahend
;
3668 const char *difference
;
3669 } subtract_domain_tests
[] = {
3670 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
3671 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
3672 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
3675 static int test_subtract(isl_ctx
*ctx
)
3678 isl_union_map
*umap1
, *umap2
;
3679 isl_union_pw_multi_aff
*upma1
, *upma2
;
3680 isl_union_set
*uset
;
3683 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3684 umap1
= isl_union_map_read_from_str(ctx
,
3685 subtract_domain_tests
[i
].minuend
);
3686 uset
= isl_union_set_read_from_str(ctx
,
3687 subtract_domain_tests
[i
].subtrahend
);
3688 umap2
= isl_union_map_read_from_str(ctx
,
3689 subtract_domain_tests
[i
].difference
);
3690 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
3691 equal
= isl_union_map_is_equal(umap1
, umap2
);
3692 isl_union_map_free(umap1
);
3693 isl_union_map_free(umap2
);
3697 isl_die(ctx
, isl_error_unknown
,
3698 "incorrect subtract domain result", return -1);
3701 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3702 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3703 subtract_domain_tests
[i
].minuend
);
3704 uset
= isl_union_set_read_from_str(ctx
,
3705 subtract_domain_tests
[i
].subtrahend
);
3706 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3707 subtract_domain_tests
[i
].difference
);
3708 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
3709 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
3710 isl_union_pw_multi_aff_free(upma1
);
3711 isl_union_pw_multi_aff_free(upma2
);
3715 isl_die(ctx
, isl_error_unknown
,
3716 "incorrect subtract domain result", return -1);
3722 /* Check that intersecting the empty basic set with another basic set
3723 * does not increase the number of constraints. In particular,
3724 * the empty basic set should maintain its canonical representation.
3726 static int test_intersect_1(isl_ctx
*ctx
)
3729 isl_basic_set
*bset1
, *bset2
;
3731 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
3732 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
3733 n1
= isl_basic_set_n_constraint(bset1
);
3734 bset1
= isl_basic_set_intersect(bset1
, bset2
);
3735 n2
= isl_basic_set_n_constraint(bset1
);
3736 isl_basic_set_free(bset1
);
3740 isl_die(ctx
, isl_error_unknown
,
3741 "number of constraints of empty set changed",
3747 /* Check that intersecting a set with itself does not cause
3748 * an explosion in the number of disjuncts.
3750 static isl_stat
test_intersect_2(isl_ctx
*ctx
)
3755 set
= isl_set_read_from_str(ctx
, "{ [x,y] : x >= 0 or y >= 0 }");
3756 for (i
= 0; i
< 100; ++i
)
3757 set
= isl_set_intersect(set
, isl_set_copy(set
));
3760 return isl_stat_error
;
3764 /* Perform some intersection tests.
3766 static int test_intersect(isl_ctx
*ctx
)
3768 if (test_intersect_1(ctx
) < 0)
3770 if (test_intersect_2(ctx
) < 0)
3776 int test_factorize(isl_ctx
*ctx
)
3779 isl_basic_set
*bset
;
3782 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
3783 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
3784 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
3785 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
3786 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
3787 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
3788 "3i5 >= -2i0 - i2 + 3i4 }";
3789 bset
= isl_basic_set_read_from_str(ctx
, str
);
3790 f
= isl_basic_set_factorizer(bset
);
3791 isl_basic_set_free(bset
);
3792 isl_factorizer_free(f
);
3794 isl_die(ctx
, isl_error_unknown
,
3795 "failed to construct factorizer", return -1);
3797 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
3798 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
3799 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
3800 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
3801 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
3802 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
3803 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
3804 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
3805 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
3806 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
3807 bset
= isl_basic_set_read_from_str(ctx
, str
);
3808 f
= isl_basic_set_factorizer(bset
);
3809 isl_basic_set_free(bset
);
3810 isl_factorizer_free(f
);
3812 isl_die(ctx
, isl_error_unknown
,
3813 "failed to construct factorizer", return -1);
3818 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
3820 int *injective
= user
;
3822 *injective
= isl_map_is_injective(map
);
3825 if (*injective
< 0 || !*injective
)
3826 return isl_stat_error
;
3831 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
3832 const char *r
, const char *s
, int tilable
, int parallel
)
3836 isl_union_map
*W
, *R
, *S
;
3837 isl_union_map
*empty
;
3838 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
3839 isl_union_map
*validity
, *proximity
, *coincidence
;
3840 isl_union_map
*schedule
;
3841 isl_union_map
*test
;
3842 isl_union_set
*delta
;
3843 isl_union_set
*domain
;
3847 isl_schedule_constraints
*sc
;
3848 isl_schedule
*sched
;
3849 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
3851 D
= isl_union_set_read_from_str(ctx
, d
);
3852 W
= isl_union_map_read_from_str(ctx
, w
);
3853 R
= isl_union_map_read_from_str(ctx
, r
);
3854 S
= isl_union_map_read_from_str(ctx
, s
);
3856 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
3857 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
3859 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
3860 isl_union_map_compute_flow(isl_union_map_copy(R
),
3861 isl_union_map_copy(W
), empty
,
3862 isl_union_map_copy(S
),
3863 &dep_raw
, NULL
, NULL
, NULL
);
3864 isl_union_map_compute_flow(isl_union_map_copy(W
),
3865 isl_union_map_copy(W
),
3866 isl_union_map_copy(R
),
3867 isl_union_map_copy(S
),
3868 &dep_waw
, &dep_war
, NULL
, NULL
);
3870 dep
= isl_union_map_union(dep_waw
, dep_war
);
3871 dep
= isl_union_map_union(dep
, dep_raw
);
3872 validity
= isl_union_map_copy(dep
);
3873 coincidence
= isl_union_map_copy(dep
);
3874 proximity
= isl_union_map_copy(dep
);
3876 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
3877 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3878 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
3879 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3880 sched
= isl_schedule_constraints_compute_schedule(sc
);
3881 schedule
= isl_schedule_get_map(sched
);
3882 isl_schedule_free(sched
);
3883 isl_union_map_free(W
);
3884 isl_union_map_free(R
);
3885 isl_union_map_free(S
);
3888 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
3890 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
3891 is_complete
= isl_union_set_is_subset(D
, domain
);
3892 isl_union_set_free(D
);
3893 isl_union_set_free(domain
);
3895 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
3896 test
= isl_union_map_apply_range(test
, dep
);
3897 test
= isl_union_map_apply_range(test
, schedule
);
3899 delta
= isl_union_map_deltas(test
);
3900 if (isl_union_set_n_set(delta
) == 0) {
3904 isl_union_set_free(delta
);
3906 delta_set
= isl_set_from_union_set(delta
);
3908 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3909 for (i
= 0; i
< tilable
; ++i
)
3910 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
3911 is_tilable
= isl_set_is_subset(delta_set
, slice
);
3912 isl_set_free(slice
);
3914 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3915 for (i
= 0; i
< parallel
; ++i
)
3916 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
3917 is_parallel
= isl_set_is_subset(delta_set
, slice
);
3918 isl_set_free(slice
);
3920 origin
= isl_set_universe(isl_set_get_space(delta_set
));
3921 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
3922 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
3924 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
3925 delta_set
= isl_set_lexmin(delta_set
);
3927 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
3929 isl_set_free(origin
);
3930 isl_set_free(delta_set
);
3933 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
3934 is_injection
< 0 || is_complete
< 0)
3937 isl_die(ctx
, isl_error_unknown
,
3938 "generated schedule incomplete", return -1);
3940 isl_die(ctx
, isl_error_unknown
,
3941 "generated schedule not injective on each statement",
3944 isl_die(ctx
, isl_error_unknown
,
3945 "negative dependences in generated schedule",
3948 isl_die(ctx
, isl_error_unknown
,
3949 "generated schedule not as tilable as expected",
3952 isl_die(ctx
, isl_error_unknown
,
3953 "generated schedule not as parallel as expected",
3959 /* Compute a schedule for the given instance set, validity constraints,
3960 * proximity constraints and context and return a corresponding union map
3963 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
3964 const char *domain
, const char *validity
, const char *proximity
,
3965 const char *context
)
3970 isl_union_map
*prox
;
3971 isl_schedule_constraints
*sc
;
3972 isl_schedule
*schedule
;
3973 isl_union_map
*sched
;
3975 con
= isl_set_read_from_str(ctx
, context
);
3976 dom
= isl_union_set_read_from_str(ctx
, domain
);
3977 dep
= isl_union_map_read_from_str(ctx
, validity
);
3978 prox
= isl_union_map_read_from_str(ctx
, proximity
);
3979 sc
= isl_schedule_constraints_on_domain(dom
);
3980 sc
= isl_schedule_constraints_set_context(sc
, con
);
3981 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
3982 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
3983 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3984 sched
= isl_schedule_get_map(schedule
);
3985 isl_schedule_free(schedule
);
3990 /* Compute a schedule for the given instance set, validity constraints and
3991 * proximity constraints and return a corresponding union map representation.
3993 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
3994 const char *domain
, const char *validity
, const char *proximity
)
3996 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
4000 /* Check that a schedule can be constructed on the given domain
4001 * with the given validity and proximity constraints.
4003 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
4004 const char *validity
, const char *proximity
)
4006 isl_union_map
*sched
;
4008 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
4012 isl_union_map_free(sched
);
4016 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
4017 const char *validity
, const char *proximity
, const char *expected_sched
)
4019 isl_union_map
*sched1
, *sched2
;
4022 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
4023 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
4025 equal
= isl_union_map_is_equal(sched1
, sched2
);
4026 isl_union_map_free(sched1
);
4027 isl_union_map_free(sched2
);
4032 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
4038 /* Check that the schedule map is properly padded, i.e., that the range
4039 * lives in a single space.
4041 static int test_padded_schedule(isl_ctx
*ctx
)
4045 isl_union_map
*validity
, *proximity
;
4046 isl_schedule_constraints
*sc
;
4047 isl_schedule
*sched
;
4048 isl_union_map
*umap
;
4049 isl_union_set
*range
;
4052 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4053 D
= isl_union_set_read_from_str(ctx
, str
);
4054 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
4055 proximity
= isl_union_map_copy(validity
);
4056 sc
= isl_schedule_constraints_on_domain(D
);
4057 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4058 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4059 sched
= isl_schedule_constraints_compute_schedule(sc
);
4060 umap
= isl_schedule_get_map(sched
);
4061 isl_schedule_free(sched
);
4062 range
= isl_union_map_range(umap
);
4063 set
= isl_set_from_union_set(range
);
4072 /* Check that conditional validity constraints are also taken into
4073 * account across bands.
4074 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4075 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4076 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4077 * is enforced by the rest of the schedule.
4079 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
4082 isl_union_set
*domain
;
4083 isl_union_map
*validity
, *proximity
, *condition
;
4084 isl_union_map
*sink
, *source
, *dep
;
4085 isl_schedule_constraints
*sc
;
4086 isl_schedule
*schedule
;
4087 isl_union_access_info
*access
;
4088 isl_union_flow
*flow
;
4091 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4092 "A[k] : k >= 1 and k <= -1 + n; "
4093 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4094 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4095 domain
= isl_union_set_read_from_str(ctx
, str
);
4096 sc
= isl_schedule_constraints_on_domain(domain
);
4097 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4098 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4099 "D[k, i] -> C[1 + k, i] : "
4100 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4101 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4102 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4103 validity
= isl_union_map_read_from_str(ctx
, str
);
4104 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4105 str
= "[n] -> { C[k, i] -> D[k, i] : "
4106 "0 <= i <= -1 + k and k <= -1 + n }";
4107 proximity
= isl_union_map_read_from_str(ctx
, str
);
4108 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4109 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4110 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4111 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4112 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4113 condition
= isl_union_map_read_from_str(ctx
, str
);
4114 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4115 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4116 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4117 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4118 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4119 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4120 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4121 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4122 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4123 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4124 validity
= isl_union_map_read_from_str(ctx
, str
);
4125 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4127 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4128 str
= "{ D[2,0] -> [] }";
4129 sink
= isl_union_map_read_from_str(ctx
, str
);
4130 access
= isl_union_access_info_from_sink(sink
);
4131 str
= "{ C[2,1] -> [] }";
4132 source
= isl_union_map_read_from_str(ctx
, str
);
4133 access
= isl_union_access_info_set_must_source(access
, source
);
4134 access
= isl_union_access_info_set_schedule(access
, schedule
);
4135 flow
= isl_union_access_info_compute_flow(access
);
4136 dep
= isl_union_flow_get_must_dependence(flow
);
4137 isl_union_flow_free(flow
);
4138 empty
= isl_union_map_is_empty(dep
);
4139 isl_union_map_free(dep
);
4144 isl_die(ctx
, isl_error_unknown
,
4145 "conditional validity not respected", return -1);
4150 /* Check that the test for violated conditional validity constraints
4151 * is not confused by domain compression.
4152 * In particular, earlier versions of isl would apply
4153 * a schedule on the compressed domains to the original domains,
4154 * resulting in a failure to detect that the default schedule
4155 * violates the conditional validity constraints.
4157 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
4161 isl_union_set
*domain
;
4162 isl_union_map
*validity
, *condition
;
4163 isl_schedule_constraints
*sc
;
4164 isl_schedule
*schedule
;
4165 isl_union_map
*umap
;
4168 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4169 domain
= isl_union_set_read_from_str(ctx
, str
);
4170 sc
= isl_schedule_constraints_on_domain(domain
);
4171 str
= "{ B[1, i] -> A[0, i + 1] }";
4172 condition
= isl_union_map_read_from_str(ctx
, str
);
4173 str
= "{ A[0, i] -> B[1, i - 1] }";
4174 validity
= isl_union_map_read_from_str(ctx
, str
);
4175 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4176 isl_union_map_copy(validity
));
4177 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4178 umap
= isl_schedule_get_map(schedule
);
4179 isl_schedule_free(schedule
);
4180 validity
= isl_union_map_apply_domain(validity
,
4181 isl_union_map_copy(umap
));
4182 validity
= isl_union_map_apply_range(validity
, umap
);
4183 map
= isl_map_from_union_map(validity
);
4184 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4185 map
= isl_map_intersect(map
, ge
);
4186 empty
= isl_map_is_empty(map
);
4192 isl_die(ctx
, isl_error_unknown
,
4193 "conditional validity constraints not satisfied",
4199 /* Input for testing of schedule construction based on
4200 * conditional constraints.
4202 * domain is the iteration domain
4203 * flow are the flow dependences, which determine the validity and
4204 * proximity constraints
4205 * condition are the conditions on the conditional validity constraints
4206 * conditional_validity are the conditional validity constraints
4207 * outer_band_n is the expected number of members in the outer band
4212 const char *condition
;
4213 const char *conditional_validity
;
4215 } live_range_tests
[] = {
4216 /* Contrived example that illustrates that we need to keep
4217 * track of tagged condition dependences and
4218 * tagged conditional validity dependences
4219 * in isl_sched_edge separately.
4220 * In particular, the conditional validity constraints on A
4221 * cannot be satisfied,
4222 * but they can be ignored because there are no corresponding
4223 * condition constraints. However, we do have an additional
4224 * conditional validity constraint that maps to the same
4225 * dependence relation
4226 * as the condition constraint on B. If we did not make a distinction
4227 * between tagged condition and tagged conditional validity
4228 * dependences, then we
4229 * could end up treating this shared dependence as an condition
4230 * constraint on A, forcing a localization of the conditions,
4231 * which is impossible.
4233 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4234 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4235 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4236 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4237 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4238 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4241 /* TACO 2013 Fig. 7 */
4242 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4243 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4244 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4245 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4246 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4247 "0 <= i < n and 0 <= j < n - 1 }",
4248 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4249 "0 <= i < n and 0 <= j < j' < n;"
4250 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4251 "0 <= i < i' < n and 0 <= j,j' < n;"
4252 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4253 "0 <= i,j,j' < n and j < j' }",
4256 /* TACO 2013 Fig. 7, without tags */
4257 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4258 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4259 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4260 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4261 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4262 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4263 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4264 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4267 /* TACO 2013 Fig. 12 */
4268 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4269 "S3[i,3] : 0 <= i <= 1 }",
4270 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4271 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4272 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4273 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4274 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4275 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4276 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4277 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4278 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4279 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4280 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4285 /* Test schedule construction based on conditional constraints.
4286 * In particular, check the number of members in the outer band node
4287 * as an indication of whether tiling is possible or not.
4289 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4292 isl_union_set
*domain
;
4293 isl_union_map
*condition
;
4294 isl_union_map
*flow
;
4295 isl_union_map
*validity
;
4296 isl_schedule_constraints
*sc
;
4297 isl_schedule
*schedule
;
4298 isl_schedule_node
*node
;
4301 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4303 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4306 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4307 domain
= isl_union_set_read_from_str(ctx
,
4308 live_range_tests
[i
].domain
);
4309 flow
= isl_union_map_read_from_str(ctx
,
4310 live_range_tests
[i
].flow
);
4311 condition
= isl_union_map_read_from_str(ctx
,
4312 live_range_tests
[i
].condition
);
4313 validity
= isl_union_map_read_from_str(ctx
,
4314 live_range_tests
[i
].conditional_validity
);
4315 sc
= isl_schedule_constraints_on_domain(domain
);
4316 sc
= isl_schedule_constraints_set_validity(sc
,
4317 isl_union_map_copy(flow
));
4318 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4319 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4320 condition
, validity
);
4321 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4322 node
= isl_schedule_get_root(schedule
);
4324 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4325 node
= isl_schedule_node_first_child(node
);
4326 n_member
= isl_schedule_node_band_n_member(node
);
4327 isl_schedule_node_free(node
);
4328 isl_schedule_free(schedule
);
4332 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4333 isl_die(ctx
, isl_error_unknown
,
4334 "unexpected number of members in outer band",
4340 /* Check that the schedule computed for the given instance set and
4341 * dependence relation strongly satisfies the dependences.
4342 * In particular, check that no instance is scheduled before
4343 * or together with an instance on which it depends.
4344 * Earlier versions of isl would produce a schedule that
4345 * only weakly satisfies the dependences.
4347 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4349 const char *domain
, *dep
;
4350 isl_union_map
*D
, *schedule
;
4354 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4355 "A[i0] : 0 <= i0 <= 1 }";
4356 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4357 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4358 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
4359 D
= isl_union_map_read_from_str(ctx
, dep
);
4360 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
4361 D
= isl_union_map_apply_range(D
, schedule
);
4362 map
= isl_map_from_union_map(D
);
4363 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4364 map
= isl_map_intersect(map
, ge
);
4365 empty
= isl_map_is_empty(map
);
4371 isl_die(ctx
, isl_error_unknown
,
4372 "dependences not strongly satisfied", return -1);
4377 /* Compute a schedule for input where the instance set constraints
4378 * conflict with the context constraints.
4379 * Earlier versions of isl did not properly handle this situation.
4381 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
4383 isl_union_map
*schedule
;
4384 const char *domain
, *context
;
4386 domain
= "[n] -> { A[] : n >= 0 }";
4387 context
= "[n] -> { : n < 0 }";
4388 schedule
= compute_schedule_with_context(ctx
,
4389 domain
, "{}", "{}", context
);
4390 isl_union_map_free(schedule
);
4398 /* Check that the dependence carrying step is not confused by
4399 * a bound on the coefficient size.
4400 * In particular, force the scheduler to move to a dependence carrying
4401 * step by demanding outer coincidence and bound the size of
4402 * the coefficients. Earlier versions of isl would take this
4403 * bound into account while carrying dependences, breaking
4404 * fundamental assumptions.
4405 * On the other hand, the dependence carrying step now tries
4406 * to prevent loop coalescing by default, so check that indeed
4407 * no loop coalescing occurs by comparing the computed schedule
4408 * to the expected non-coalescing schedule.
4410 static int test_bounded_coefficients_schedule(isl_ctx
*ctx
)
4412 const char *domain
, *dep
;
4415 isl_schedule_constraints
*sc
;
4416 isl_schedule
*schedule
;
4417 isl_union_map
*sched1
, *sched2
;
4420 domain
= "{ C[i0, i1] : 2 <= i0 <= 3999 and 0 <= i1 <= -1 + i0 }";
4421 dep
= "{ C[i0, i1] -> C[i0, 1 + i1] : i0 <= 3999 and i1 >= 0 and "
4423 "C[i0, -1 + i0] -> C[1 + i0, 0] : i0 <= 3998 and i0 >= 1 }";
4424 I
= isl_union_set_read_from_str(ctx
, domain
);
4425 D
= isl_union_map_read_from_str(ctx
, dep
);
4426 sc
= isl_schedule_constraints_on_domain(I
);
4427 sc
= isl_schedule_constraints_set_validity(sc
, isl_union_map_copy(D
));
4428 sc
= isl_schedule_constraints_set_coincidence(sc
, D
);
4429 isl_options_set_schedule_outer_coincidence(ctx
, 1);
4430 isl_options_set_schedule_max_coefficient(ctx
, 20);
4431 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4432 isl_options_set_schedule_max_coefficient(ctx
, -1);
4433 isl_options_set_schedule_outer_coincidence(ctx
, 0);
4434 sched1
= isl_schedule_get_map(schedule
);
4435 isl_schedule_free(schedule
);
4437 sched2
= isl_union_map_read_from_str(ctx
, "{ C[x,y] -> [x,y] }");
4438 equal
= isl_union_map_is_equal(sched1
, sched2
);
4439 isl_union_map_free(sched1
);
4440 isl_union_map_free(sched2
);
4445 isl_die(ctx
, isl_error_unknown
,
4446 "unexpected schedule", return -1);
4451 /* Check that the bounds on the coefficients are respected.
4452 * This function checks for a particular output schedule,
4453 * but the exact output is not important, only that it does
4454 * not contain any coefficients greater than 4.
4455 * It is, however, easier to check for a particular output.
4456 * This test is only run for the whole component scheduler
4457 * because the incremental scheduler produces a slightly different schedule.
4459 static int test_bounded_coefficients_schedule_whole(isl_ctx
*ctx
)
4461 const char *domain
, *dep
, *str
;
4464 isl_schedule_constraints
*sc
;
4465 isl_schedule
*schedule
;
4466 isl_union_map
*sched1
, *sched2
;
4469 domain
= "{ S_4[i, j, k] : 0 <= i < j <= 10 and 0 <= k <= 100; "
4470 "S_2[i, j] : 0 <= i < j <= 10; S_6[i, j] : 0 <= i < j <= 10 }";
4471 dep
= "{ S_2[0, j] -> S_4[0, j, 0] : 0 < j <= 10; "
4472 "S_4[0, j, 100] -> S_6[0, j] : 0 < j <= 10 }";
4473 I
= isl_union_set_read_from_str(ctx
, domain
);
4474 D
= isl_union_map_read_from_str(ctx
, dep
);
4475 sc
= isl_schedule_constraints_on_domain(I
);
4476 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4477 isl_options_set_schedule_max_constant_term(ctx
, 10);
4478 isl_options_set_schedule_max_coefficient(ctx
, 4);
4479 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4480 isl_options_set_schedule_max_coefficient(ctx
, -1);
4481 isl_options_set_schedule_max_constant_term(ctx
, -1);
4482 sched1
= isl_schedule_get_map(schedule
);
4483 isl_schedule_free(schedule
);
4485 str
= "{ S_4[i, j, k] -> [i, j, 10 - k]; "
4486 "S_2[i, j] -> [0, i, j]; S_6[i, j] -> [0, 10 + i, j] }";
4487 sched2
= isl_union_map_read_from_str(ctx
, str
);
4488 equal
= isl_union_map_is_equal(sched1
, sched2
);
4489 isl_union_map_free(sched1
);
4490 isl_union_map_free(sched2
);
4495 isl_die(ctx
, isl_error_unknown
,
4496 "unexpected schedule", return -1);
4501 /* Check that a set of schedule constraints that only allow for
4502 * a coalescing schedule still produces a schedule even if the user
4503 * request a non-coalescing schedule. Earlier versions of isl
4504 * would not handle this case correctly.
4506 static int test_coalescing_schedule(isl_ctx
*ctx
)
4508 const char *domain
, *dep
;
4511 isl_schedule_constraints
*sc
;
4512 isl_schedule
*schedule
;
4513 int treat_coalescing
;
4515 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4516 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
4517 I
= isl_union_set_read_from_str(ctx
, domain
);
4518 D
= isl_union_map_read_from_str(ctx
, dep
);
4519 sc
= isl_schedule_constraints_on_domain(I
);
4520 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4521 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4522 isl_options_set_schedule_treat_coalescing(ctx
, 1);
4523 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4524 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4525 isl_schedule_free(schedule
);
4531 /* Check that the scheduler does not perform any needless
4532 * compound skewing. Earlier versions of isl would compute
4533 * schedules in terms of transformed schedule coefficients and
4534 * would not accurately keep track of the sum of the original
4535 * schedule coefficients. It could then produce the schedule
4536 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4537 * for the input below instead of the schedule below.
4539 static int test_skewing_schedule(isl_ctx
*ctx
)
4541 const char *D
, *V
, *P
, *S
;
4543 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4544 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4545 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4546 "-1 <= a-i + b-j + c-k <= 1 }";
4548 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4550 return test_special_schedule(ctx
, D
, V
, P
, S
);
4553 int test_schedule(isl_ctx
*ctx
)
4555 const char *D
, *W
, *R
, *V
, *P
, *S
;
4556 int max_coincidence
;
4557 int treat_coalescing
;
4559 /* Handle resulting schedule with zero bands. */
4560 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4564 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4565 W
= "{ S1[t,i] -> a[t,i] }";
4566 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4567 "S1[t,i] -> a[t-1,i+1] }";
4568 S
= "{ S1[t,i] -> [t,i] }";
4569 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4572 /* Fig. 5 of CC2008 */
4573 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4575 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4576 "j >= 2 and j <= -1 + N }";
4577 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4578 "j >= 2 and j <= -1 + N; "
4579 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4580 "j >= 2 and j <= -1 + N }";
4581 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4582 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4585 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4586 W
= "{ S1[i] -> a[i] }";
4587 R
= "{ S2[i] -> a[i+1] }";
4588 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4589 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4592 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4593 W
= "{ S1[i] -> a[i] }";
4594 R
= "{ S2[i] -> a[9-i] }";
4595 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4596 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4599 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4600 W
= "{ S1[i] -> a[i] }";
4601 R
= "[N] -> { S2[i] -> a[N-1-i] }";
4602 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4603 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4606 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4607 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4608 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4609 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4610 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4613 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4614 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4615 R
= "{ S2[i,j] -> a[i-1,j] }";
4616 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4617 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4620 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4621 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4622 R
= "{ S2[i,j] -> a[i,j-1] }";
4623 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4624 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4627 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4628 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4629 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4630 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4631 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4632 "S_0[] -> [0, 0, 0] }";
4633 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
4635 ctx
->opt
->schedule_parametric
= 0;
4636 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4638 ctx
->opt
->schedule_parametric
= 1;
4640 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4641 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4642 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4643 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4644 "S4[i] -> a[i,N] }";
4645 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4646 "S4[i] -> [4,i,0] }";
4647 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
4648 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
4649 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4651 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
4653 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4654 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4656 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4658 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4660 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4661 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4664 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4665 " S_2[t] : t >= 0 and t <= -1 + N; "
4666 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4668 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4669 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4670 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4671 "i >= 0 and i <= -1 + N }";
4672 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4673 "i >= 0 and i <= -1 + N; "
4674 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4675 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4676 " S_0[t] -> [0, t, 0] }";
4678 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4680 ctx
->opt
->schedule_parametric
= 0;
4681 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4683 ctx
->opt
->schedule_parametric
= 1;
4685 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4686 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4687 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
4690 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4691 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4692 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4693 "j >= 0 and j <= -1 + N; "
4694 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4695 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4696 "j >= 0 and j <= -1 + N; "
4697 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4698 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4699 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4702 D
= "{ S_0[i] : i >= 0 }";
4703 W
= "{ S_0[i] -> a[i] : i >= 0 }";
4704 R
= "{ S_0[i] -> a[0] : i >= 0 }";
4705 S
= "{ S_0[i] -> [0, i, 0] }";
4706 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4709 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
4710 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
4711 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
4712 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
4713 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4716 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
4717 "k <= -1 + n and k >= 0 }";
4718 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
4719 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
4720 "k <= -1 + n and k >= 0; "
4721 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
4722 "k <= -1 + n and k >= 0; "
4723 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
4724 "k <= -1 + n and k >= 0 }";
4725 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
4726 ctx
->opt
->schedule_outer_coincidence
= 1;
4727 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4729 ctx
->opt
->schedule_outer_coincidence
= 0;
4731 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
4732 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
4733 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
4734 "Stmt_for_body24[i0, i1, 1, 0]:"
4735 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
4736 "Stmt_for_body7[i0, i1, i2]:"
4737 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
4740 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
4741 "Stmt_for_body24[1, i1, i2, i3]:"
4742 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
4744 "Stmt_for_body24[0, i1, i2, i3] -> "
4745 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
4746 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
4748 "Stmt_for_body24[0, i1, i2, i3] ->"
4749 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
4750 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
4751 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
4752 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
4753 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
4754 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
4755 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
4756 "i1 <= 6 and i1 >= 0;"
4757 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
4758 "Stmt_for_body7[i0, i1, i2] -> "
4759 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
4760 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
4761 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
4762 "Stmt_for_body7[i0, i1, i2] -> "
4763 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
4764 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
4765 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
4768 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4769 isl_options_set_schedule_treat_coalescing(ctx
, 0);
4770 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4772 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4774 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
4775 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
4776 "j >= 1 and j <= 7;"
4777 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
4778 "j >= 1 and j <= 8 }";
4780 S
= "{ S_0[i, j] -> [i + j, i] }";
4781 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4782 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4784 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4786 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
4787 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
4788 "j >= 0 and j <= -1 + i }";
4789 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
4790 "i <= -1 + N and j >= 0;"
4791 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
4794 S
= "{ S_0[i, j] -> [i, j] }";
4795 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4796 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4798 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4800 /* Test both algorithms on a case with only proximity dependences. */
4801 D
= "{ S[i,j] : 0 <= i <= 10 }";
4803 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
4804 S
= "{ S[i, j] -> [j, i] }";
4805 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4806 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4808 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4809 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4812 D
= "{ A[a]; B[] }";
4814 P
= "{ A[a] -> B[] }";
4815 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4818 if (test_padded_schedule(ctx
) < 0)
4821 /* Check that check for progress is not confused by rational
4824 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
4825 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
4827 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
4828 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
4830 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4831 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4833 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4835 /* Check that we allow schedule rows that are only non-trivial
4836 * on some full-dimensional domains.
4838 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
4839 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
4840 "S1[j] -> S2[1] : 0 <= j <= 1 }";
4842 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4843 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4845 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4847 if (test_conditional_schedule_constraints(ctx
) < 0)
4850 if (test_strongly_satisfying_schedule(ctx
) < 0)
4853 if (test_conflicting_context_schedule(ctx
) < 0)
4856 if (test_bounded_coefficients_schedule(ctx
) < 0)
4858 if (test_coalescing_schedule(ctx
) < 0)
4860 if (test_skewing_schedule(ctx
) < 0)
4866 /* Perform scheduling tests using the whole component scheduler.
4868 static int test_schedule_whole(isl_ctx
*ctx
)
4873 whole
= isl_options_get_schedule_whole_component(ctx
);
4874 isl_options_set_schedule_whole_component(ctx
, 1);
4875 r
= test_schedule(ctx
);
4877 r
= test_bounded_coefficients_schedule_whole(ctx
);
4878 isl_options_set_schedule_whole_component(ctx
, whole
);
4883 /* Perform scheduling tests using the incremental scheduler.
4885 static int test_schedule_incremental(isl_ctx
*ctx
)
4890 whole
= isl_options_get_schedule_whole_component(ctx
);
4891 isl_options_set_schedule_whole_component(ctx
, 0);
4892 r
= test_schedule(ctx
);
4893 isl_options_set_schedule_whole_component(ctx
, whole
);
4898 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
4900 isl_union_map
*umap
;
4903 umap
= isl_union_map_read_from_str(ctx
, str
);
4904 test
= isl_union_map_plain_is_injective(umap
);
4905 isl_union_map_free(umap
);
4908 if (test
== injective
)
4911 isl_die(ctx
, isl_error_unknown
,
4912 "map not detected as injective", return -1);
4914 isl_die(ctx
, isl_error_unknown
,
4915 "map detected as injective", return -1);
4918 int test_injective(isl_ctx
*ctx
)
4922 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
4924 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
4926 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
4928 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
4930 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
4932 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
4934 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
4936 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
4939 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
4940 if (test_plain_injective(ctx
, str
, 1))
4942 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
4943 if (test_plain_injective(ctx
, str
, 0))
4949 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
4957 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
4958 equal
= isl_aff_plain_is_equal(aff
, aff2
);
4964 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
4968 equal
= aff_plain_is_equal(aff
, str
);
4972 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
4973 "result not as expected", return -1);
4977 /* Is "upa" obviously equal to the isl_union_pw_aff represented by "str"?
4979 static isl_bool
union_pw_aff_plain_is_equal(__isl_keep isl_union_pw_aff
*upa
,
4983 isl_union_pw_aff
*upa2
;
4987 return isl_bool_error
;
4989 ctx
= isl_union_pw_aff_get_ctx(upa
);
4990 upa2
= isl_union_pw_aff_read_from_str(ctx
, str
);
4991 equal
= isl_union_pw_aff_plain_is_equal(upa
, upa2
);
4992 isl_union_pw_aff_free(upa2
);
4997 /* Check that "upa" is obviously equal to the isl_union_pw_aff
4998 * represented by "str".
5000 static isl_stat
union_pw_aff_check_plain_equal(__isl_keep isl_union_pw_aff
*upa
,
5005 equal
= union_pw_aff_plain_is_equal(upa
, str
);
5007 return isl_stat_error
;
5009 isl_die(isl_union_pw_aff_get_ctx(upa
), isl_error_unknown
,
5010 "result not as expected", return isl_stat_error
);
5014 /* Basic tests on isl_union_pw_aff.
5016 * In particular, check that isl_union_pw_aff_aff_on_domain
5017 * aligns the parameters of the input objects and
5018 * that isl_union_pw_aff_param_on_domain_id properly
5019 * introduces the parameter.
5021 static int test_upa(isl_ctx
*ctx
)
5026 isl_union_set
*domain
;
5027 isl_union_pw_aff
*upa
;
5030 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
5031 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5032 domain
= isl_union_set_read_from_str(ctx
, str
);
5033 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
5034 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5035 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5036 isl_union_pw_aff_free(upa
);
5040 id
= isl_id_alloc(ctx
, "N", NULL
);
5041 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5042 domain
= isl_union_set_read_from_str(ctx
, str
);
5043 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
5044 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5045 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5046 isl_union_pw_aff_free(upa
);
5054 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5055 __isl_take isl_aff
*aff2
);
5057 ['+'] = { &isl_aff_add
},
5058 ['-'] = { &isl_aff_sub
},
5059 ['*'] = { &isl_aff_mul
},
5060 ['/'] = { &isl_aff_div
},
5068 } aff_bin_tests
[] = {
5069 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5070 "{ [i] -> [2i] }" },
5071 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5073 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5074 "{ [i] -> [2i] }" },
5075 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5076 "{ [i] -> [2i] }" },
5077 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5078 "{ [i] -> [i/2] }" },
5079 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5081 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5082 "{ [i] -> [NaN] }" },
5083 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5084 "{ [i] -> [NaN] }" },
5085 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5086 "{ [i] -> [NaN] }" },
5087 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5088 "{ [i] -> [NaN] }" },
5089 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5090 "{ [i] -> [NaN] }" },
5091 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5092 "{ [i] -> [NaN] }" },
5093 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5094 "{ [i] -> [NaN] }" },
5095 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5096 "{ [i] -> [NaN] }" },
5097 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5098 "{ [i] -> [NaN] }" },
5099 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5100 "{ [i] -> [NaN] }" },
5101 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5102 "{ [i] -> [NaN] }" },
5103 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5104 "{ [i] -> [NaN] }" },
5107 /* Perform some basic tests of binary operations on isl_aff objects.
5109 static int test_bin_aff(isl_ctx
*ctx
)
5112 isl_aff
*aff1
, *aff2
, *res
;
5113 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5114 __isl_take isl_aff
*aff2
);
5117 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
5118 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
5119 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
5120 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
5121 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
5122 aff1
= fn(aff1
, aff2
);
5123 if (isl_aff_is_nan(res
))
5124 ok
= isl_aff_is_nan(aff1
);
5126 ok
= isl_aff_plain_is_equal(aff1
, res
);
5132 isl_die(ctx
, isl_error_unknown
,
5133 "unexpected result", return -1);
5140 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
5141 __isl_take isl_pw_aff
*pa2
);
5142 } pw_aff_bin_op
[] = {
5143 ['m'] = { &isl_pw_aff_min
},
5144 ['M'] = { &isl_pw_aff_max
},
5147 /* Inputs for binary isl_pw_aff operation tests.
5148 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5149 * defined by pw_aff_bin_op, and "res" is the expected result.
5156 } pw_aff_bin_tests
[] = {
5157 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5159 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5161 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5162 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5163 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5164 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5165 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5166 "{ [i] -> [NaN] }" },
5167 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5168 "{ [i] -> [NaN] }" },
5171 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5173 static int test_bin_pw_aff(isl_ctx
*ctx
)
5177 isl_pw_aff
*pa1
, *pa2
, *res
;
5179 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
5180 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
5181 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
5182 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
5183 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
5184 if (isl_pw_aff_involves_nan(res
))
5185 ok
= isl_pw_aff_involves_nan(pa1
);
5187 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
5188 isl_pw_aff_free(pa1
);
5189 isl_pw_aff_free(res
);
5193 isl_die(ctx
, isl_error_unknown
,
5194 "unexpected result", return -1);
5201 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5202 __isl_take isl_union_pw_multi_aff
*upma1
,
5203 __isl_take isl_union_pw_multi_aff
*upma2
);
5207 } upma_bin_tests
[] = {
5208 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
5209 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5210 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
5211 "{ B[x] -> [2] : x >= 0 }",
5212 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5213 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
5214 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5215 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5216 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5217 "D[i] -> B[2] : i >= 5 }" },
5218 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5219 "{ B[x] -> C[2] : x > 0 }",
5220 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5221 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5222 "{ B[x] -> A[2] : x >= 0 }",
5223 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5226 /* Perform some basic tests of binary operations on
5227 * isl_union_pw_multi_aff objects.
5229 static int test_bin_upma(isl_ctx
*ctx
)
5232 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
5235 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
5236 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5237 upma_bin_tests
[i
].arg1
);
5238 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5239 upma_bin_tests
[i
].arg2
);
5240 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5241 upma_bin_tests
[i
].res
);
5242 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
5243 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
5244 isl_union_pw_multi_aff_free(upma1
);
5245 isl_union_pw_multi_aff_free(res
);
5249 isl_die(ctx
, isl_error_unknown
,
5250 "unexpected result", return -1);
5257 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5258 __isl_take isl_union_pw_multi_aff
*upma1
,
5259 __isl_take isl_union_pw_multi_aff
*upma2
);
5262 } upma_bin_fail_tests
[] = {
5263 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5264 "{ B[x] -> C[2] : x >= 0 }" },
5267 /* Perform some basic tests of binary operations on
5268 * isl_union_pw_multi_aff objects that are expected to fail.
5270 static int test_bin_upma_fail(isl_ctx
*ctx
)
5273 isl_union_pw_multi_aff
*upma1
, *upma2
;
5276 on_error
= isl_options_get_on_error(ctx
);
5277 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5278 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5279 for (i
= 0; i
< n
; ++i
) {
5280 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5281 upma_bin_fail_tests
[i
].arg1
);
5282 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5283 upma_bin_fail_tests
[i
].arg2
);
5284 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5285 isl_union_pw_multi_aff_free(upma1
);
5289 isl_options_set_on_error(ctx
, on_error
);
5291 isl_die(ctx
, isl_error_unknown
,
5292 "operation not expected to succeed", return -1);
5297 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5298 * "fn" is the function that is tested.
5299 * "arg" is a string description of the input.
5300 * "res" is a string description of the expected result.
5303 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5306 } mpa_un_tests
[] = {
5307 { &isl_multi_pw_aff_range_factor_domain
,
5308 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5309 "{ A[x] -> B[(1 : x >= 5)] }" },
5310 { &isl_multi_pw_aff_range_factor_range
,
5311 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5312 "{ A[y] -> C[(2 : y <= 10)] }" },
5313 { &isl_multi_pw_aff_range_factor_domain
,
5314 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5315 "{ A[x] -> B[(1 : x >= 5)] }" },
5316 { &isl_multi_pw_aff_range_factor_range
,
5317 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5318 "{ A[y] -> C[] }" },
5319 { &isl_multi_pw_aff_range_factor_domain
,
5320 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5321 "{ A[x] -> B[] }" },
5322 { &isl_multi_pw_aff_range_factor_range
,
5323 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5324 "{ A[y] -> C[(2 : y <= 10)] }" },
5325 { &isl_multi_pw_aff_range_factor_domain
,
5326 "{ A[x] -> [B[] -> C[]] }",
5327 "{ A[x] -> B[] }" },
5328 { &isl_multi_pw_aff_range_factor_range
,
5329 "{ A[x] -> [B[] -> C[]] }",
5330 "{ A[y] -> C[] }" },
5331 { &isl_multi_pw_aff_factor_range
,
5334 { &isl_multi_pw_aff_range_factor_domain
,
5335 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5336 "{ A[x] -> B[] : x >= 0 }" },
5337 { &isl_multi_pw_aff_range_factor_range
,
5338 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5339 "{ A[y] -> C[] : y >= 0 }" },
5340 { &isl_multi_pw_aff_factor_range
,
5341 "[N] -> { [B[] -> C[]] : N >= 0 }",
5342 "[N] -> { C[] : N >= 0 }" },
5345 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5347 static int test_un_mpa(isl_ctx
*ctx
)
5351 isl_multi_pw_aff
*mpa
, *res
;
5353 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5354 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5355 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5356 mpa
= mpa_un_tests
[i
].fn(mpa
);
5357 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5358 isl_multi_pw_aff_free(mpa
);
5359 isl_multi_pw_aff_free(res
);
5363 isl_die(ctx
, isl_error_unknown
,
5364 "unexpected result", return -1);
5370 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5371 * "fn" is the function that is tested.
5372 * "arg1" and "arg2" are string descriptions of the inputs.
5373 * "res" is a string description of the expected result.
5376 __isl_give isl_multi_pw_aff
*(*fn
)(
5377 __isl_take isl_multi_pw_aff
*mpa1
,
5378 __isl_take isl_multi_pw_aff
*mpa2
);
5382 } mpa_bin_tests
[] = {
5383 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
5385 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
5386 "{ A[x] -> [(x : x <= 10)] }",
5387 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5388 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5389 "{ A[x] -> [] : x <= 10 }",
5390 "{ A[x] -> [] : 5 <= x <= 10 }" },
5391 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5392 "[N] -> { A[x] -> [] : x <= N }",
5393 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5394 { &isl_multi_pw_aff_add
,
5395 "[N] -> { A[x] -> [] : x <= N }",
5396 "{ A[x] -> [] : x >= 5 }",
5397 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5398 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5399 "{ A[y] -> C[(2 : y <= 10)] }",
5400 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5401 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5402 "{ A[y] -> C[2] : y <= 10 }",
5403 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5404 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5405 "[N] -> { A[y] -> C[2] : y <= N }",
5406 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5407 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
5408 "{ A[y] -> C[2] : y <= 10 }",
5409 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5410 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5411 "{ A[] -> [B[1] -> C[2]] }" },
5412 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5413 "{ A[] -> [B[] -> C[]] }" },
5414 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5415 "{ A[y] -> C[] : y <= 10 }",
5416 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5417 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
5418 "{ A[x] -> B[(1 : x >= 5)] }",
5419 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5420 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5421 "{ A[y] -> C[(2 : y <= 10)] }",
5422 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5423 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5424 "{ A[y] -> C[] : y <= 10 }",
5425 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5426 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
5427 "{ A[x] -> B[(1 : x >= 5)] }",
5428 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5429 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5430 "[N] -> { A[y] -> C[] : y <= N }",
5431 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5432 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
5433 "{ A[x] -> B[(1 : x >= 5)] }",
5434 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5435 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
5436 "{ A[y] -> C[] : y <= 10 }",
5437 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5438 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5439 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5440 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5441 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5442 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5443 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5444 "{ A[a,b] -> C[b + 2a] }" },
5445 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5446 "{ B[i,j] -> C[i + 2j] }",
5447 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5448 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5449 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5450 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5451 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5452 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5453 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5454 "{ B[i,j] -> C[] }",
5455 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5456 "{ A[a,b] -> C[] }" },
5457 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5458 "{ B[i,j] -> C[] : i > j }",
5459 "{ A[a,b] -> B[b,a] }",
5460 "{ A[a,b] -> C[] : b > a }" },
5461 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5462 "{ B[i,j] -> C[] : j > 5 }",
5463 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5464 "{ A[a,b] -> C[] : b > a > 5 }" },
5465 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5466 "[N] -> { B[i,j] -> C[] : j > N }",
5467 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5468 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5469 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5470 "[M,N] -> { B[] -> C[] : N > 5 }",
5471 "[M,N] -> { A[] -> B[] : M > N }",
5472 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5475 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5477 static int test_bin_mpa(isl_ctx
*ctx
)
5481 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
5483 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
5484 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
5485 mpa_bin_tests
[i
].arg1
);
5486 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
5487 mpa_bin_tests
[i
].arg2
);
5488 res
= isl_multi_pw_aff_read_from_str(ctx
,
5489 mpa_bin_tests
[i
].res
);
5490 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
5491 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
5492 isl_multi_pw_aff_free(mpa1
);
5493 isl_multi_pw_aff_free(res
);
5497 isl_die(ctx
, isl_error_unknown
,
5498 "unexpected result", return -1);
5504 /* Inputs for basic tests of unary operations on
5505 * isl_multi_union_pw_aff objects.
5506 * "fn" is the function that is tested.
5507 * "arg" is a string description of the input.
5508 * "res" is a string description of the expected result.
5511 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5512 __isl_take isl_multi_union_pw_aff
*mupa
);
5515 } mupa_un_tests
[] = {
5516 { &isl_multi_union_pw_aff_factor_range
,
5517 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5518 "C[{ A[] -> [2] }]" },
5519 { &isl_multi_union_pw_aff_factor_range
,
5520 "[B[] -> C[{ A[] -> [2] }]]",
5521 "C[{ A[] -> [2] }]" },
5522 { &isl_multi_union_pw_aff_factor_range
,
5523 "[B[{ A[] -> [1] }] -> C[]]",
5525 { &isl_multi_union_pw_aff_factor_range
,
5528 { &isl_multi_union_pw_aff_factor_range
,
5529 "([B[] -> C[]] : { A[x] : x >= 0 })",
5530 "(C[] : { A[x] : x >= 0 })" },
5531 { &isl_multi_union_pw_aff_factor_range
,
5532 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
5533 "[N] -> (C[] : { A[x] : x <= N })" },
5534 { &isl_multi_union_pw_aff_factor_range
,
5535 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
5536 "[N] -> (C[] : { : N >= 0 })" },
5539 /* Perform some basic tests of unary operations on
5540 * isl_multi_union_pw_aff objects.
5542 static int test_un_mupa(isl_ctx
*ctx
)
5546 isl_multi_union_pw_aff
*mupa
, *res
;
5548 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
5549 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5550 mupa_un_tests
[i
].arg
);
5551 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5552 mupa_un_tests
[i
].res
);
5553 mupa
= mupa_un_tests
[i
].fn(mupa
);
5554 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5555 isl_multi_union_pw_aff_free(mupa
);
5556 isl_multi_union_pw_aff_free(res
);
5560 isl_die(ctx
, isl_error_unknown
,
5561 "unexpected result", return -1);
5567 /* Inputs for basic tests of binary operations on
5568 * isl_multi_union_pw_aff objects.
5569 * "fn" is the function that is tested.
5570 * "arg1" and "arg2" are string descriptions of the inputs.
5571 * "res" is a string description of the expected result.
5574 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5575 __isl_take isl_multi_union_pw_aff
*mupa1
,
5576 __isl_take isl_multi_union_pw_aff
*mupa2
);
5580 } mupa_bin_tests
[] = {
5581 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5582 "[{ A[] -> [3] }]" },
5583 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5584 "[{ A[] -> [-1] }]" },
5585 { &isl_multi_union_pw_aff_add
,
5586 "[{ A[] -> [1]; B[] -> [4] }]",
5587 "[{ A[] -> [2]; C[] -> [5] }]",
5588 "[{ A[] -> [3] }]" },
5589 { &isl_multi_union_pw_aff_union_add
,
5590 "[{ A[] -> [1]; B[] -> [4] }]",
5591 "[{ A[] -> [2]; C[] -> [5] }]",
5592 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
5593 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5594 "[{ A[x] -> [(x)] : x <= 10 }]",
5595 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
5596 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5597 "([] : { A[x] : x <= 10 })",
5598 "([] : { A[x] : 5 <= x <= 10 })" },
5599 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5600 "[N] -> ([] : { A[x] : x <= N })",
5601 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
5602 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
5603 "([] : { A[x] : x <= 10 })",
5604 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
5605 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5606 "[{ A[x] -> [(x)] : x <= 10 }]",
5607 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
5608 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
5609 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
5610 "([] : { A[x] : x <= 10 })",
5611 "([] : { A[x] })" },
5612 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
5613 "[N] -> ([] : { A[x] : x >= N })",
5614 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
5615 { &isl_multi_union_pw_aff_union_add
,
5616 "[N] -> ([] : { A[] : N >= 0})",
5617 "[N] -> ([] : { A[] : N <= 0})",
5618 "[N] -> ([] : { A[] })" },
5619 { &isl_multi_union_pw_aff_union_add
,
5620 "[N] -> ([] : { A[] })",
5621 "[N] -> ([] : { : })",
5622 "[N] -> ([] : { : })" },
5623 { &isl_multi_union_pw_aff_union_add
,
5624 "[N] -> ([] : { : })",
5625 "[N] -> ([] : { A[] })",
5626 "[N] -> ([] : { : })" },
5627 { &isl_multi_union_pw_aff_union_add
,
5628 "[N] -> ([] : { : N >= 0})",
5629 "[N] -> ([] : { : N <= 0})",
5630 "[N] -> ([] : { : })" },
5631 { &isl_multi_union_pw_aff_range_product
,
5632 "B[{ A[] -> [1] }]",
5633 "C[{ A[] -> [2] }]",
5634 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
5635 { &isl_multi_union_pw_aff_range_product
,
5636 "(B[] : { A[x] : x >= 5 })",
5637 "(C[] : { A[x] : x <= 10 })",
5638 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
5639 { &isl_multi_union_pw_aff_range_product
,
5640 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5641 "(C[] : { A[x] : x <= 10 })",
5642 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
5643 { &isl_multi_union_pw_aff_range_product
,
5644 "(C[] : { A[x] : x <= 10 })",
5645 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5646 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
5647 { &isl_multi_union_pw_aff_range_product
,
5648 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5649 "[N] -> (C[] : { A[x] : x <= N })",
5650 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
5651 { &isl_multi_union_pw_aff_range_product
,
5652 "[N] -> (C[] : { A[x] : x <= N })",
5653 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5654 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
5655 { &isl_multi_union_pw_aff_range_product
,
5656 "B[{ A[] -> [1]; D[] -> [3] }]",
5657 "C[{ A[] -> [2] }]",
5658 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
5659 { &isl_multi_union_pw_aff_range_product
,
5662 "([B[] -> C[]] : { A[x] })" },
5663 { &isl_multi_union_pw_aff_range_product
,
5666 "([B[] -> C[]] : { A[x] })" },
5669 /* Perform some basic tests of binary operations on
5670 * isl_multi_union_pw_aff objects.
5672 static int test_bin_mupa(isl_ctx
*ctx
)
5676 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
5678 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
5679 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
5680 mupa_bin_tests
[i
].arg1
);
5681 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
5682 mupa_bin_tests
[i
].arg2
);
5683 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5684 mupa_bin_tests
[i
].res
);
5685 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
5686 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
5687 isl_multi_union_pw_aff_free(mupa1
);
5688 isl_multi_union_pw_aff_free(res
);
5692 isl_die(ctx
, isl_error_unknown
,
5693 "unexpected result", return -1);
5699 /* Inputs for basic tests of binary operations on
5700 * pairs of isl_multi_union_pw_aff and isl_set objects.
5701 * "fn" is the function that is tested.
5702 * "arg1" and "arg2" are string descriptions of the inputs.
5703 * "res" is a string description of the expected result.
5706 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5707 __isl_take isl_multi_union_pw_aff
*mupa
,
5708 __isl_take isl_set
*set
);
5712 } mupa_set_tests
[] = {
5713 { &isl_multi_union_pw_aff_intersect_range
,
5714 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
5715 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
5716 { &isl_multi_union_pw_aff_intersect_range
,
5717 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
5718 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
5719 { &isl_multi_union_pw_aff_intersect_range
,
5720 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
5721 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
5722 { &isl_multi_union_pw_aff_intersect_range
,
5723 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
5724 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
5725 { &isl_multi_union_pw_aff_intersect_range
,
5726 "C[]", "{ C[] }", "C[]" },
5727 { &isl_multi_union_pw_aff_intersect_range
,
5728 "[N] -> (C[] : { : N >= 0 })",
5730 "[N] -> (C[] : { : N >= 0 })" },
5731 { &isl_multi_union_pw_aff_intersect_range
,
5732 "(C[] : { A[a,b] })",
5734 "(C[] : { A[a,b] })" },
5735 { &isl_multi_union_pw_aff_intersect_range
,
5736 "[N] -> (C[] : { A[a,b] : a,b <= N })",
5738 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
5739 { &isl_multi_union_pw_aff_intersect_range
,
5741 "[N] -> { C[] : N >= 0 }",
5742 "[N] -> (C[] : { : N >= 0 })" },
5743 { &isl_multi_union_pw_aff_intersect_range
,
5744 "(C[] : { A[a,b] })",
5745 "[N] -> { C[] : N >= 0 }",
5746 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5747 { &isl_multi_union_pw_aff_intersect_range
,
5748 "[N] -> (C[] : { : N >= 0 })",
5749 "[N] -> { C[] : N < 1024 }",
5750 "[N] -> (C[] : { : 0 <= N < 1024 })" },
5751 { &isl_multi_union_pw_aff_intersect_params
,
5752 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
5753 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
5754 { &isl_multi_union_pw_aff_intersect_params
,
5755 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
5756 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
5757 { &isl_multi_union_pw_aff_intersect_params
,
5758 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
5759 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
5760 { &isl_multi_union_pw_aff_intersect_params
,
5761 "C[]", "[N] -> { : N >= 0 }",
5762 "[N] -> (C[] : { : N >= 0 })" },
5763 { &isl_multi_union_pw_aff_intersect_params
,
5764 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
5765 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5766 { &isl_multi_union_pw_aff_intersect_params
,
5767 "[N] -> (C[] : { A[a,N] })", "{ : }",
5768 "[N] -> (C[] : { A[a,N] })" },
5769 { &isl_multi_union_pw_aff_intersect_params
,
5770 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
5771 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
5774 /* Perform some basic tests of binary operations on
5775 * pairs of isl_multi_union_pw_aff and isl_set objects.
5777 static int test_mupa_set(isl_ctx
*ctx
)
5781 isl_multi_union_pw_aff
*mupa
, *res
;
5784 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
5785 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5786 mupa_set_tests
[i
].arg1
);
5787 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
5788 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5789 mupa_set_tests
[i
].res
);
5790 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
5791 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5792 isl_multi_union_pw_aff_free(mupa
);
5793 isl_multi_union_pw_aff_free(res
);
5797 isl_die(ctx
, isl_error_unknown
,
5798 "unexpected result", return -1);
5804 /* Inputs for basic tests of binary operations on
5805 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5806 * "fn" is the function that is tested.
5807 * "arg1" and "arg2" are string descriptions of the inputs.
5808 * "res" is a string description of the expected result.
5811 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5812 __isl_take isl_multi_union_pw_aff
*mupa
,
5813 __isl_take isl_union_set
*uset
);
5817 } mupa_uset_tests
[] = {
5818 { &isl_multi_union_pw_aff_intersect_domain
,
5819 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
5820 "C[{ B[i,i] -> [3i] }]" },
5821 { &isl_multi_union_pw_aff_intersect_domain
,
5822 "(C[] : { B[i,j] })", "{ B[i,i] }",
5823 "(C[] : { B[i,i] })" },
5824 { &isl_multi_union_pw_aff_intersect_domain
,
5825 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
5826 "[N] -> (C[] : { B[N,N] })" },
5827 { &isl_multi_union_pw_aff_intersect_domain
,
5828 "C[]", "{ B[i,i] }",
5829 "(C[] : { B[i,i] })" },
5830 { &isl_multi_union_pw_aff_intersect_domain
,
5831 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
5832 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
5835 /* Perform some basic tests of binary operations on
5836 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5838 static int test_mupa_uset(isl_ctx
*ctx
)
5842 isl_multi_union_pw_aff
*mupa
, *res
;
5843 isl_union_set
*uset
;
5845 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
5846 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5847 mupa_uset_tests
[i
].arg1
);
5848 uset
= isl_union_set_read_from_str(ctx
,
5849 mupa_uset_tests
[i
].arg2
);
5850 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5851 mupa_uset_tests
[i
].res
);
5852 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
5853 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5854 isl_multi_union_pw_aff_free(mupa
);
5855 isl_multi_union_pw_aff_free(res
);
5859 isl_die(ctx
, isl_error_unknown
,
5860 "unexpected result", return -1);
5866 /* Inputs for basic tests of binary operations on
5867 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5868 * "fn" is the function that is tested.
5869 * "arg1" and "arg2" are string descriptions of the inputs.
5870 * "res" is a string description of the expected result.
5873 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5874 __isl_take isl_multi_union_pw_aff
*mupa
,
5875 __isl_take isl_multi_aff
*ma
);
5879 } mupa_ma_tests
[] = {
5880 { &isl_multi_union_pw_aff_apply_multi_aff
,
5881 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5882 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5883 "{ C[a,b] -> D[b,a] }",
5884 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
5885 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
5886 { &isl_multi_union_pw_aff_apply_multi_aff
,
5887 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
5888 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5889 "{ C[a,b] -> D[b,a] }",
5890 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
5891 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
5892 { &isl_multi_union_pw_aff_apply_multi_aff
,
5893 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5894 "[N] -> { C[a] -> D[a + N] }",
5895 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
5896 { &isl_multi_union_pw_aff_apply_multi_aff
,
5900 { &isl_multi_union_pw_aff_apply_multi_aff
,
5901 "[N] -> (C[] : { : N >= 0 })",
5903 "[N] -> (D[] : { : N >= 0 })" },
5904 { &isl_multi_union_pw_aff_apply_multi_aff
,
5906 "[N] -> { C[] -> D[N] }",
5907 "[N] -> D[{ [N] }]" },
5908 { &isl_multi_union_pw_aff_apply_multi_aff
,
5909 "(C[] : { A[i,j] : i >= j })",
5911 "(D[] : { A[i,j] : i >= j })" },
5912 { &isl_multi_union_pw_aff_apply_multi_aff
,
5913 "[N] -> (C[] : { A[i,j] : N >= 0 })",
5915 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
5916 { &isl_multi_union_pw_aff_apply_multi_aff
,
5917 "(C[] : { A[i,j] : i >= j })",
5918 "[N] -> { C[] -> D[N] }",
5919 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
5922 /* Perform some basic tests of binary operations on
5923 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5925 static int test_mupa_ma(isl_ctx
*ctx
)
5929 isl_multi_union_pw_aff
*mupa
, *res
;
5932 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
5933 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5934 mupa_ma_tests
[i
].arg1
);
5935 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
5936 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5937 mupa_ma_tests
[i
].res
);
5938 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
5939 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5940 isl_multi_union_pw_aff_free(mupa
);
5941 isl_multi_union_pw_aff_free(res
);
5945 isl_die(ctx
, isl_error_unknown
,
5946 "unexpected result", return -1);
5952 /* Inputs for basic tests of binary operations on
5953 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
5954 * "fn" is the function that is tested.
5955 * "arg1" and "arg2" are string descriptions of the inputs.
5956 * "res" is a string description of the expected result.
5959 __isl_give isl_union_pw_aff
*(*fn
)(
5960 __isl_take isl_multi_union_pw_aff
*mupa
,
5961 __isl_take isl_pw_aff
*pa
);
5965 } mupa_pa_tests
[] = {
5966 { &isl_multi_union_pw_aff_apply_pw_aff
,
5967 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5968 "[N] -> { C[a] -> [a + N] }",
5969 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
5970 { &isl_multi_union_pw_aff_apply_pw_aff
,
5971 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5972 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
5973 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
5974 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
5975 { &isl_multi_union_pw_aff_apply_pw_aff
,
5977 "[N] -> { C[] -> [N] }",
5979 { &isl_multi_union_pw_aff_apply_pw_aff
,
5981 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5982 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
5983 { &isl_multi_union_pw_aff_apply_pw_aff
,
5984 "[N] -> (C[] : { : N >= 0 })",
5985 "[N] -> { C[] -> [N] }",
5986 "[N] -> { [N] : N >= 0 }" },
5987 { &isl_multi_union_pw_aff_apply_pw_aff
,
5988 "[N] -> (C[] : { : N >= 0 })",
5989 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5990 "[N] -> { [N] : N >= 0 }" },
5991 { &isl_multi_union_pw_aff_apply_pw_aff
,
5992 "[N] -> (C[] : { : N >= 0 })",
5994 "[N] -> { [0] : N >= 0 }" },
5995 { &isl_multi_union_pw_aff_apply_pw_aff
,
5996 "(C[] : { A[i,j] : i >= j })",
5997 "[N] -> { C[] -> [N] }",
5998 "[N] -> { A[i,j] -> [N] : i >= j }" },
5999 { &isl_multi_union_pw_aff_apply_pw_aff
,
6000 "(C[] : { A[i,j] : i >= j })",
6001 "[N] -> { C[] -> [N] : N >= 0 }",
6002 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6005 /* Perform some basic tests of binary operations on
6006 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6008 static int test_mupa_pa(isl_ctx
*ctx
)
6012 isl_multi_union_pw_aff
*mupa
;
6013 isl_union_pw_aff
*upa
, *res
;
6016 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
6017 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6018 mupa_pa_tests
[i
].arg1
);
6019 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
6020 res
= isl_union_pw_aff_read_from_str(ctx
,
6021 mupa_pa_tests
[i
].res
);
6022 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
6023 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
6024 isl_union_pw_aff_free(upa
);
6025 isl_union_pw_aff_free(res
);
6029 isl_die(ctx
, isl_error_unknown
,
6030 "unexpected result", return -1);
6036 /* Inputs for basic tests of binary operations on
6037 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6038 * "fn" is the function that is tested.
6039 * "arg1" and "arg2" are string descriptions of the inputs.
6040 * "res" is a string description of the expected result.
6043 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6044 __isl_take isl_multi_union_pw_aff
*mupa
,
6045 __isl_take isl_pw_multi_aff
*pma
);
6049 } mupa_pma_tests
[] = {
6050 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6051 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6052 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6053 "{ C[a,b] -> D[b,a] }",
6054 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6055 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6056 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6057 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6058 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6059 "{ C[a,b] -> D[b,a] }",
6060 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6061 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6062 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6063 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6064 "[N] -> { C[a] -> D[a + N] }",
6065 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6066 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6067 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6068 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6069 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6070 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6071 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6072 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6073 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6074 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6075 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6076 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6077 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6078 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6079 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6083 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6084 "[N] -> (C[] : { : N >= 0 })",
6086 "[N] -> (D[] : { : N >= 0 })" },
6087 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6089 "[N] -> { C[] -> D[N] }",
6090 "[N] -> D[{ [N] }]" },
6091 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6092 "(C[] : { A[i,j] : i >= j })",
6094 "(D[] : { A[i,j] : i >= j })" },
6095 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6096 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6098 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6099 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6100 "(C[] : { A[i,j] : i >= j })",
6101 "[N] -> { C[] -> D[N] }",
6102 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6103 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6105 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6106 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6107 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6108 "[N] -> (C[] : { : N >= 0 })",
6109 "[N] -> { C[] -> D[N] }",
6110 "[N] -> D[{ [N] : N >= 0 }]" },
6111 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6112 "[N] -> (C[] : { : N >= 0 })",
6113 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6114 "[N] -> D[{ [N] : N >= 0 }]" },
6115 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6116 "[N] -> (C[] : { : N >= 0 })",
6118 "[N] -> D[{ [0] : N >= 0 }]" },
6119 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6120 "(C[] : { A[i,j] : i >= j })",
6121 "[N] -> { C[] -> D[N] : N >= 0 }",
6122 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6125 /* Perform some basic tests of binary operations on
6126 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6128 static int test_mupa_pma(isl_ctx
*ctx
)
6132 isl_multi_union_pw_aff
*mupa
, *res
;
6133 isl_pw_multi_aff
*pma
;
6135 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
6136 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6137 mupa_pma_tests
[i
].arg1
);
6138 pma
= isl_pw_multi_aff_read_from_str(ctx
,
6139 mupa_pma_tests
[i
].arg2
);
6140 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6141 mupa_pma_tests
[i
].res
);
6142 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
6143 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6144 isl_multi_union_pw_aff_free(mupa
);
6145 isl_multi_union_pw_aff_free(res
);
6149 isl_die(ctx
, isl_error_unknown
,
6150 "unexpected result", return -1);
6156 /* Inputs for basic tests of binary operations on
6157 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6158 * "fn" is the function that is tested.
6159 * "arg1" and "arg2" are string descriptions of the inputs.
6160 * "res" is a string description of the expected result.
6163 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6164 __isl_take isl_multi_union_pw_aff
*mupa
,
6165 __isl_take isl_union_pw_multi_aff
*upma
);
6169 } mupa_upma_tests
[] = {
6170 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6171 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6172 "C[{ A[a,b] -> [b + 2a] }]" },
6173 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6174 "C[{ B[i,j] -> [i + 2j] }]",
6175 "{ A[a,b] -> B[b,a] : b > a }",
6176 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6177 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6178 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6179 "{ A[a,b] -> B[b,a] : b > a }",
6180 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6181 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6182 "C[{ B[i,j] -> [i + 2j] }]",
6183 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6184 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6185 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6186 "(C[] : { B[a,b] })",
6187 "{ A[a,b] -> B[b,a] }",
6188 "(C[] : { A[a,b] })" },
6189 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6190 "(C[] : { B[a,b] })",
6191 "{ B[a,b] -> A[b,a] }",
6193 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6194 "(C[] : { B[a,b] })",
6195 "{ A[a,b] -> B[b,a] : a > b }",
6196 "(C[] : { A[a,b] : a > b })" },
6197 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6198 "(C[] : { B[a,b] : a > b })",
6199 "{ A[a,b] -> B[b,a] }",
6200 "(C[] : { A[a,b] : b > a })" },
6201 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6202 "[N] -> (C[] : { B[a,b] : a > N })",
6203 "{ A[a,b] -> B[b,a] : a > b }",
6204 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6205 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6206 "(C[] : { B[a,b] : a > b })",
6207 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6208 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6209 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6211 "{ A[a,b] -> B[b,a] }",
6213 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6214 "[N] -> (C[] : { : N >= 0 })",
6215 "{ A[a,b] -> B[b,a] }",
6216 "[N] -> (C[] : { : N >= 0 })" },
6217 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6219 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6220 "[N] -> (C[] : { : N >= 0 })" },
6223 /* Perform some basic tests of binary operations on
6224 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6226 static int test_mupa_upma(isl_ctx
*ctx
)
6230 isl_multi_union_pw_aff
*mupa
, *res
;
6231 isl_union_pw_multi_aff
*upma
;
6233 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
6234 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6235 mupa_upma_tests
[i
].arg1
);
6236 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
6237 mupa_upma_tests
[i
].arg2
);
6238 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6239 mupa_upma_tests
[i
].res
);
6240 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
6241 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6242 isl_multi_union_pw_aff_free(mupa
);
6243 isl_multi_union_pw_aff_free(res
);
6247 isl_die(ctx
, isl_error_unknown
,
6248 "unexpected result", return -1);
6254 /* Check that the input tuple of an isl_aff can be set properly.
6256 static isl_stat
test_aff_set_tuple_id(isl_ctx
*ctx
)
6262 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x + 1] }");
6263 id
= isl_id_alloc(ctx
, "A", NULL
);
6264 aff
= isl_aff_set_tuple_id(aff
, isl_dim_in
, id
);
6265 equal
= aff_check_plain_equal(aff
, "{ A[x] -> [x + 1] }");
6268 return isl_stat_error
;
6273 int test_aff(isl_ctx
*ctx
)
6278 isl_local_space
*ls
;
6282 if (test_upa(ctx
) < 0)
6284 if (test_bin_aff(ctx
) < 0)
6286 if (test_bin_pw_aff(ctx
) < 0)
6288 if (test_bin_upma(ctx
) < 0)
6290 if (test_bin_upma_fail(ctx
) < 0)
6292 if (test_un_mpa(ctx
) < 0)
6294 if (test_bin_mpa(ctx
) < 0)
6296 if (test_un_mupa(ctx
) < 0)
6298 if (test_bin_mupa(ctx
) < 0)
6300 if (test_mupa_set(ctx
) < 0)
6302 if (test_mupa_uset(ctx
) < 0)
6304 if (test_mupa_ma(ctx
) < 0)
6306 if (test_mupa_pa(ctx
) < 0)
6308 if (test_mupa_pma(ctx
) < 0)
6310 if (test_mupa_upma(ctx
) < 0)
6313 space
= isl_space_set_alloc(ctx
, 0, 1);
6314 ls
= isl_local_space_from_space(space
);
6315 aff
= isl_aff_zero_on_domain(ls
);
6317 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6318 aff
= isl_aff_scale_down_ui(aff
, 3);
6319 aff
= isl_aff_floor(aff
);
6320 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6321 aff
= isl_aff_scale_down_ui(aff
, 2);
6322 aff
= isl_aff_floor(aff
);
6323 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6326 set
= isl_set_read_from_str(ctx
, str
);
6327 aff
= isl_aff_gist(aff
, set
);
6329 aff
= isl_aff_add_constant_si(aff
, -16);
6330 zero
= isl_aff_plain_is_zero(aff
);
6336 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6338 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6339 aff
= isl_aff_scale_down_ui(aff
, 64);
6340 aff
= isl_aff_floor(aff
);
6341 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6346 if (test_aff_set_tuple_id(ctx
) < 0)
6352 /* Check that "pa" consists of a single expression.
6354 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
6358 n
= isl_pw_aff_n_piece(pa
);
6359 isl_pw_aff_free(pa
);
6364 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
6370 /* Check that the computation below results in a single expression.
6371 * One or two expressions may result depending on which constraint
6372 * ends up being considered as redundant with respect to the other
6373 * constraints after the projection that is performed internally
6374 * by isl_set_dim_min.
6376 static int test_dim_max_1(isl_ctx
*ctx
)
6382 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
6383 "-4a <= b <= 3 and b < n - 4a }";
6384 set
= isl_set_read_from_str(ctx
, str
);
6385 pa
= isl_set_dim_min(set
, 0);
6386 return check_single_piece(ctx
, pa
);
6389 /* Check that the computation below results in a single expression.
6390 * The PIP problem corresponding to these constraints has a row
6391 * that causes a split of the solution domain. The solver should
6392 * first pick rows that split off empty parts such that the actual
6393 * solution domain does not get split.
6394 * Note that the description contains some redundant constraints.
6395 * If these constraints get removed first, then the row mentioned
6396 * above does not appear in the PIP problem.
6398 static int test_dim_max_2(isl_ctx
*ctx
)
6404 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
6405 "N > 0 and P >= 0 }";
6406 set
= isl_set_read_from_str(ctx
, str
);
6407 pa
= isl_set_dim_max(set
, 0);
6408 return check_single_piece(ctx
, pa
);
6411 int test_dim_max(isl_ctx
*ctx
)
6415 isl_set
*set1
, *set2
;
6420 if (test_dim_max_1(ctx
) < 0)
6422 if (test_dim_max_2(ctx
) < 0)
6425 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
6426 set
= isl_set_read_from_str(ctx
, str
);
6427 pwaff
= isl_set_dim_max(set
, 0);
6428 set1
= isl_set_from_pw_aff(pwaff
);
6429 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
6430 set2
= isl_set_read_from_str(ctx
, str
);
6431 equal
= isl_set_is_equal(set1
, set2
);
6437 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6439 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
6440 set
= isl_set_read_from_str(ctx
, str
);
6441 pwaff
= isl_set_dim_max(set
, 0);
6442 set1
= isl_set_from_pw_aff(pwaff
);
6443 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6444 set2
= isl_set_read_from_str(ctx
, str
);
6445 equal
= isl_set_is_equal(set1
, set2
);
6451 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6453 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
6454 set
= isl_set_read_from_str(ctx
, str
);
6455 pwaff
= isl_set_dim_max(set
, 0);
6456 set1
= isl_set_from_pw_aff(pwaff
);
6457 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6458 set2
= isl_set_read_from_str(ctx
, str
);
6459 equal
= isl_set_is_equal(set1
, set2
);
6465 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6467 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
6468 "0 <= i < N and 0 <= j < M }";
6469 map
= isl_map_read_from_str(ctx
, str
);
6470 set
= isl_map_range(map
);
6472 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
6473 set1
= isl_set_from_pw_aff(pwaff
);
6474 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
6475 set2
= isl_set_read_from_str(ctx
, str
);
6476 equal
= isl_set_is_equal(set1
, set2
);
6480 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
6481 set1
= isl_set_from_pw_aff(pwaff
);
6482 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
6483 set2
= isl_set_read_from_str(ctx
, str
);
6484 if (equal
>= 0 && equal
)
6485 equal
= isl_set_is_equal(set1
, set2
);
6494 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6496 /* Check that solutions are properly merged. */
6497 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
6498 "c <= -1 + n - 4a - 2b and c >= -2b and "
6499 "4a >= -4 + n and c >= 0 }";
6500 set
= isl_set_read_from_str(ctx
, str
);
6501 pwaff
= isl_set_dim_min(set
, 2);
6502 set1
= isl_set_from_pw_aff(pwaff
);
6503 str
= "[n] -> { [(0)] : n >= 1 }";
6504 set2
= isl_set_read_from_str(ctx
, str
);
6505 equal
= isl_set_is_equal(set1
, set2
);
6512 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6514 /* Check that empty solution lie in the right space. */
6515 str
= "[n] -> { [t,a] : 1 = 0 }";
6516 set
= isl_set_read_from_str(ctx
, str
);
6517 pwaff
= isl_set_dim_max(set
, 0);
6518 set1
= isl_set_from_pw_aff(pwaff
);
6519 str
= "[n] -> { [t] : 1 = 0 }";
6520 set2
= isl_set_read_from_str(ctx
, str
);
6521 equal
= isl_set_is_equal(set1
, set2
);
6528 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6533 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
6535 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
6539 isl_pw_multi_aff
*pma2
;
6545 ctx
= isl_pw_multi_aff_get_ctx(pma
);
6546 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6547 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
6548 isl_pw_multi_aff_free(pma2
);
6553 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
6554 * represented by "str".
6556 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
6561 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
6565 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
6566 "result not as expected", return -1);
6570 /* Basic test for isl_pw_multi_aff_product.
6572 * Check that multiple pieces are properly handled.
6574 static int test_product_pma(isl_ctx
*ctx
)
6578 isl_pw_multi_aff
*pma1
, *pma2
;
6580 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
6581 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6582 str
= "{ C[] -> D[] }";
6583 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6584 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
6585 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
6586 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
6587 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
6588 isl_pw_multi_aff_free(pma1
);
6595 int test_product(isl_ctx
*ctx
)
6599 isl_union_set
*uset1
, *uset2
;
6603 set
= isl_set_read_from_str(ctx
, str
);
6604 set
= isl_set_product(set
, isl_set_copy(set
));
6605 ok
= isl_set_is_wrapping(set
);
6610 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6613 uset1
= isl_union_set_read_from_str(ctx
, str
);
6614 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
6615 str
= "{ [[] -> []] }";
6616 uset2
= isl_union_set_read_from_str(ctx
, str
);
6617 ok
= isl_union_set_is_equal(uset1
, uset2
);
6618 isl_union_set_free(uset1
);
6619 isl_union_set_free(uset2
);
6623 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6625 if (test_product_pma(ctx
) < 0)
6631 /* Check that two sets are not considered disjoint just because
6632 * they have a different set of (named) parameters.
6634 static int test_disjoint(isl_ctx
*ctx
)
6637 isl_set
*set
, *set2
;
6640 str
= "[n] -> { [[]->[]] }";
6641 set
= isl_set_read_from_str(ctx
, str
);
6642 str
= "{ [[]->[]] }";
6643 set2
= isl_set_read_from_str(ctx
, str
);
6644 disjoint
= isl_set_is_disjoint(set
, set2
);
6650 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6655 /* Inputs for isl_pw_multi_aff_is_equal tests.
6656 * "f1" and "f2" are the two function that need to be compared.
6657 * "equal" is the expected result.
6663 } pma_equal_tests
[] = {
6664 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
6665 "[N] -> { [0] : 0 <= N <= 1 }" },
6666 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6667 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
6668 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6669 "[N] -> { [0] : 0 <= N <= 1 }" },
6670 { 0, "{ [NaN] }", "{ [NaN] }" },
6673 int test_equal(isl_ctx
*ctx
)
6677 isl_set
*set
, *set2
;
6681 set
= isl_set_read_from_str(ctx
, str
);
6683 set2
= isl_set_read_from_str(ctx
, str
);
6684 equal
= isl_set_is_equal(set
, set2
);
6690 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6692 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
6693 int expected
= pma_equal_tests
[i
].equal
;
6694 isl_pw_multi_aff
*f1
, *f2
;
6696 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
6697 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
6698 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
6699 isl_pw_multi_aff_free(f1
);
6700 isl_pw_multi_aff_free(f2
);
6703 if (equal
!= expected
)
6704 isl_die(ctx
, isl_error_unknown
,
6705 "unexpected equality result", return -1);
6711 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
6712 enum isl_dim_type type
, unsigned pos
, int fixed
)
6716 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
6723 isl_die(ctx
, isl_error_unknown
,
6724 "map not detected as fixed", return -1);
6726 isl_die(ctx
, isl_error_unknown
,
6727 "map detected as fixed", return -1);
6730 int test_fixed(isl_ctx
*ctx
)
6735 str
= "{ [i] -> [i] }";
6736 map
= isl_map_read_from_str(ctx
, str
);
6737 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
6739 str
= "{ [i] -> [1] }";
6740 map
= isl_map_read_from_str(ctx
, str
);
6741 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6743 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
6744 map
= isl_map_read_from_str(ctx
, str
);
6745 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6747 map
= isl_map_read_from_str(ctx
, str
);
6748 map
= isl_map_neg(map
);
6749 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
6755 struct isl_vertices_test_data
{
6758 const char *vertex
[6];
6759 } vertices_tests
[] = {
6760 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
6761 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
6762 { "{ A[t, i] : t = 14 and i = 1 }",
6763 1, { "{ A[14, 1] }" } },
6764 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
6765 "c <= m and m <= n and m > 0 }",
6767 "[n, m] -> { [n, m, m] : 0 < m <= n }",
6768 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
6769 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
6770 "[n, m] -> { [m, m, m] : 0 < m <= n }",
6771 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
6772 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
6776 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
6778 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
6780 struct isl_vertices_test_data
*data
= user
;
6783 isl_basic_set
*bset
;
6784 isl_pw_multi_aff
*pma
;
6788 ctx
= isl_vertex_get_ctx(vertex
);
6789 bset
= isl_vertex_get_domain(vertex
);
6790 ma
= isl_vertex_get_expr(vertex
);
6791 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
6793 for (i
= 0; i
< data
->n
; ++i
) {
6794 isl_pw_multi_aff
*pma_i
;
6796 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
6797 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
6798 isl_pw_multi_aff_free(pma_i
);
6800 if (equal
< 0 || equal
)
6804 isl_pw_multi_aff_free(pma
);
6805 isl_vertex_free(vertex
);
6808 return isl_stat_error
;
6810 return equal
? isl_stat_ok
: isl_stat_error
;
6813 int test_vertices(isl_ctx
*ctx
)
6817 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
6818 isl_basic_set
*bset
;
6819 isl_vertices
*vertices
;
6823 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
6824 vertices
= isl_basic_set_compute_vertices(bset
);
6825 n
= isl_vertices_get_n_vertices(vertices
);
6826 if (vertices_tests
[i
].n
!= n
)
6828 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
6829 &vertices_tests
[i
]) < 0)
6831 isl_vertices_free(vertices
);
6832 isl_basic_set_free(bset
);
6837 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
6844 int test_union_pw(isl_ctx
*ctx
)
6848 isl_union_set
*uset
;
6849 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
6851 str
= "{ [x] -> x^2 }";
6852 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
6853 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
6854 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
6855 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
6856 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
6857 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
6858 isl_union_pw_qpolynomial_free(upwqp1
);
6859 isl_union_pw_qpolynomial_free(upwqp2
);
6863 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6868 /* Inputs for basic tests of functions that select
6869 * subparts of the domain of an isl_multi_union_pw_aff.
6870 * "fn" is the function that is tested.
6871 * "arg" is a string description of the input.
6872 * "res" is a string description of the expected result.
6875 __isl_give isl_union_set
*(*fn
)(
6876 __isl_take isl_multi_union_pw_aff
*mupa
);
6879 } un_locus_tests
[] = {
6880 { &isl_multi_union_pw_aff_zero_union_set
,
6881 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6882 "{ A[0,j]; B[0,j] }" },
6883 { &isl_multi_union_pw_aff_zero_union_set
,
6884 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
6885 "{ A[i,i]; B[i,i] : i >= 0 }" },
6886 { &isl_multi_union_pw_aff_zero_union_set
,
6887 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
6888 "{ A[i,j]; B[i,i] : i >= 0 }" },
6891 /* Perform some basic tests of functions that select
6892 * subparts of the domain of an isl_multi_union_pw_aff.
6894 static int test_un_locus(isl_ctx
*ctx
)
6898 isl_union_set
*uset
, *res
;
6899 isl_multi_union_pw_aff
*mupa
;
6901 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
6902 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6903 un_locus_tests
[i
].arg
);
6904 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
6905 uset
= un_locus_tests
[i
].fn(mupa
);
6906 ok
= isl_union_set_is_equal(uset
, res
);
6907 isl_union_set_free(uset
);
6908 isl_union_set_free(res
);
6912 isl_die(ctx
, isl_error_unknown
,
6913 "unexpected result", return -1);
6919 /* Inputs for basic tests of functions that select
6920 * subparts of an isl_union_map based on a relation
6921 * specified by an isl_multi_union_pw_aff.
6922 * "fn" is the function that is tested.
6923 * "arg1" and "arg2" are string descriptions of the inputs.
6924 * "res" is a string description of the expected result.
6927 __isl_give isl_union_map
*(*fn
)(
6928 __isl_take isl_union_map
*umap
,
6929 __isl_take isl_multi_union_pw_aff
*mupa
);
6933 } bin_locus_tests
[] = {
6934 { &isl_union_map_eq_at_multi_union_pw_aff
,
6935 "{ A[i,j] -> B[i',j'] }",
6936 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6937 "{ A[i,j] -> B[i,j'] }" },
6938 { &isl_union_map_eq_at_multi_union_pw_aff
,
6939 "{ A[i,j] -> B[i',j'] }",
6940 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6941 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6942 "{ A[i,j] -> B[i,j] }" },
6943 { &isl_union_map_eq_at_multi_union_pw_aff
,
6944 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6945 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6946 "{ A[i,j] -> B[i,j'] }" },
6947 { &isl_union_map_eq_at_multi_union_pw_aff
,
6948 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6949 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
6950 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
6951 { &isl_union_map_eq_at_multi_union_pw_aff
,
6952 "{ A[i,j] -> B[i',j'] }",
6953 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
6954 "{ A[i,j] -> B[i,j'] : i > j }" },
6955 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
6956 "{ A[i,j] -> B[i',j'] }",
6957 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6958 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6959 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
6960 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
6961 "{ A[i,j] -> B[i',j'] }",
6962 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6963 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6964 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
6965 { &isl_union_map_eq_at_multi_union_pw_aff
,
6966 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6967 "(F[] : { A[i,j]; B[i,j] })",
6968 "{ A[i,j] -> B[i',j'] }" },
6969 { &isl_union_map_eq_at_multi_union_pw_aff
,
6970 "{ A[i,j] -> B[i',j'] }",
6971 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6972 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
6973 { &isl_union_map_eq_at_multi_union_pw_aff
,
6974 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
6975 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6976 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
6977 { &isl_union_map_eq_at_multi_union_pw_aff
,
6978 "{ A[i,j] -> B[i',j'] }",
6979 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
6980 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
6981 { &isl_union_map_eq_at_multi_union_pw_aff
,
6982 "{ A[i,j] -> B[i',j'] }",
6983 "[N] -> (F[] : { : N >= 0 })",
6984 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
6987 /* Perform some basic tests of functions that select
6988 * subparts of an isl_union_map based on a relation
6989 * specified by an isl_multi_union_pw_aff.
6991 static int test_bin_locus(isl_ctx
*ctx
)
6995 isl_union_map
*umap
, *res
;
6996 isl_multi_union_pw_aff
*mupa
;
6998 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
6999 umap
= isl_union_map_read_from_str(ctx
,
7000 bin_locus_tests
[i
].arg1
);
7001 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
7002 bin_locus_tests
[i
].arg2
);
7003 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
7004 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
7005 ok
= isl_union_map_is_equal(umap
, res
);
7006 isl_union_map_free(umap
);
7007 isl_union_map_free(res
);
7011 isl_die(ctx
, isl_error_unknown
,
7012 "unexpected result", return -1);
7018 /* Perform basic locus tests.
7020 static int test_locus(isl_ctx
*ctx
)
7022 if (test_un_locus(ctx
) < 0)
7024 if (test_bin_locus(ctx
) < 0)
7029 /* Test that isl_union_pw_qpolynomial_eval picks up the function
7030 * defined over the correct domain space.
7032 static int test_eval_1(isl_ctx
*ctx
)
7037 isl_union_pw_qpolynomial
*upwqp
;
7041 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
7042 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
7044 set
= isl_set_read_from_str(ctx
, str
);
7045 pnt
= isl_set_sample_point(set
);
7046 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
7047 cmp
= isl_val_cmp_si(v
, 36);
7053 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
7058 /* Check that isl_qpolynomial_eval handles getting called on a void point.
7060 static int test_eval_2(isl_ctx
*ctx
)
7065 isl_qpolynomial
*qp
;
7069 str
= "{ A[x] -> [x] }";
7070 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
7071 str
= "{ A[x] : false }";
7072 set
= isl_set_read_from_str(ctx
, str
);
7073 pnt
= isl_set_sample_point(set
);
7074 v
= isl_qpolynomial_eval(qp
, pnt
);
7075 ok
= isl_val_is_nan(v
);
7081 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
7086 /* Inputs for isl_pw_aff_eval test.
7087 * "f" is the affine function.
7088 * "p" is the point where the function should be evaluated.
7089 * "res" is the expected result.
7095 } aff_eval_tests
[] = {
7096 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
7097 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
7098 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
7099 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
7100 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
7101 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
7102 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
7103 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
7104 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
7105 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
7106 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
7107 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
7108 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
7109 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
7110 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
7111 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
7112 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
7113 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
7114 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
7115 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
7116 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
7117 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
7118 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
7121 /* Perform basic isl_pw_aff_eval tests.
7123 static int test_eval_aff(isl_ctx
*ctx
)
7127 for (i
= 0; i
< ARRAY_SIZE(aff_eval_tests
); ++i
) {
7134 pa
= isl_pw_aff_read_from_str(ctx
, aff_eval_tests
[i
].f
);
7135 set
= isl_set_read_from_str(ctx
, aff_eval_tests
[i
].p
);
7136 pnt
= isl_set_sample_point(set
);
7137 v
= isl_pw_aff_eval(pa
, pnt
);
7138 r
= val_check_equal(v
, aff_eval_tests
[i
].res
);
7146 /* Perform basic evaluation tests.
7148 static int test_eval(isl_ctx
*ctx
)
7150 if (test_eval_1(ctx
) < 0)
7152 if (test_eval_2(ctx
) < 0)
7154 if (test_eval_aff(ctx
) < 0)
7159 /* Descriptions of sets that are tested for reparsing after printing.
7161 const char *output_tests
[] = {
7162 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
7165 "{ [x] : x mod 2 = 0 }",
7166 "{ [x] : x mod 2 = 1 }",
7167 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
7168 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
7169 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
7170 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
7171 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
7172 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
7175 /* Check that printing a set and reparsing a set from the printed output
7176 * results in the same set.
7178 static int test_output_set(isl_ctx
*ctx
)
7182 isl_set
*set1
, *set2
;
7185 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
7186 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
7187 str
= isl_set_to_str(set1
);
7188 set2
= isl_set_read_from_str(ctx
, str
);
7190 equal
= isl_set_is_equal(set1
, set2
);
7196 isl_die(ctx
, isl_error_unknown
,
7197 "parsed output not the same", return -1);
7203 /* Check that an isl_multi_aff is printed using a consistent space.
7205 static isl_stat
test_output_ma(isl_ctx
*ctx
)
7210 isl_multi_aff
*ma
, *ma2
;
7212 ma
= isl_multi_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
7213 aff
= isl_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
7214 ma
= isl_multi_aff_set_aff(ma
, 0, aff
);
7215 str
= isl_multi_aff_to_str(ma
);
7216 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
7218 equal
= isl_multi_aff_plain_is_equal(ma
, ma2
);
7219 isl_multi_aff_free(ma2
);
7220 isl_multi_aff_free(ma
);
7223 return isl_stat_error
;
7225 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7226 return isl_stat_error
);
7231 /* Check that an isl_multi_pw_aff is printed using a consistent space.
7233 static isl_stat
test_output_mpa(isl_ctx
*ctx
)
7238 isl_multi_pw_aff
*mpa
, *mpa2
;
7240 mpa
= isl_multi_pw_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
7241 pa
= isl_pw_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
7242 mpa
= isl_multi_pw_aff_set_pw_aff(mpa
, 0, pa
);
7243 str
= isl_multi_pw_aff_to_str(mpa
);
7244 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
7246 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
7247 isl_multi_pw_aff_free(mpa2
);
7248 isl_multi_pw_aff_free(mpa
);
7251 return isl_stat_error
;
7253 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7254 return isl_stat_error
);
7259 int test_output(isl_ctx
*ctx
)
7267 if (test_output_set(ctx
) < 0)
7269 if (test_output_ma(ctx
) < 0)
7271 if (test_output_mpa(ctx
) < 0)
7274 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
7275 pa
= isl_pw_aff_read_from_str(ctx
, str
);
7277 p
= isl_printer_to_str(ctx
);
7278 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
7279 p
= isl_printer_print_pw_aff(p
, pa
);
7280 s
= isl_printer_get_str(p
);
7281 isl_printer_free(p
);
7282 isl_pw_aff_free(pa
);
7286 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
7291 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7296 int test_sample(isl_ctx
*ctx
)
7299 isl_basic_set
*bset1
, *bset2
;
7302 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
7303 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
7304 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
7305 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
7306 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
7307 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
7308 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
7309 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
7310 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
7311 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
7312 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
7313 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
7314 "d - 1073741821e and "
7315 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
7316 "3j >= 1 - a + b + 2e and "
7317 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
7318 "3i <= 4 - a + 4b - e and "
7319 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
7320 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
7321 "c <= -1 + a and 3i >= -2 - a + 3e and "
7322 "1073741822e <= 1073741823 - a + 1073741822b + c and "
7323 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
7324 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
7325 "1073741823e >= 1 + 1073741823b - d and "
7326 "3i >= 1073741823b + c - 1073741823e - f and "
7327 "3i >= 1 + 2b + e + 3g }";
7328 bset1
= isl_basic_set_read_from_str(ctx
, str
);
7329 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
7330 empty
= isl_basic_set_is_empty(bset2
);
7331 subset
= isl_basic_set_is_subset(bset2
, bset1
);
7332 isl_basic_set_free(bset1
);
7333 isl_basic_set_free(bset2
);
7334 if (empty
< 0 || subset
< 0)
7337 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
7339 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
7344 int test_fixed_power(isl_ctx
*ctx
)
7351 str
= "{ [i] -> [i + 1] }";
7352 map
= isl_map_read_from_str(ctx
, str
);
7353 exp
= isl_val_int_from_si(ctx
, 23);
7354 map
= isl_map_fixed_power_val(map
, exp
);
7355 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
7363 int test_slice(isl_ctx
*ctx
)
7369 str
= "{ [i] -> [j] }";
7370 map
= isl_map_read_from_str(ctx
, str
);
7371 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7372 equal
= map_check_equal(map
, "{ [i] -> [i] }");
7377 str
= "{ [i] -> [j] }";
7378 map
= isl_map_read_from_str(ctx
, str
);
7379 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7380 equal
= map_check_equal(map
, "{ [i] -> [j] }");
7385 str
= "{ [i] -> [j] }";
7386 map
= isl_map_read_from_str(ctx
, str
);
7387 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7388 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
7393 str
= "{ [i] -> [j] }";
7394 map
= isl_map_read_from_str(ctx
, str
);
7395 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7396 equal
= map_check_equal(map
, "{ [0] -> [j] }");
7401 str
= "{ [i] -> [j] }";
7402 map
= isl_map_read_from_str(ctx
, str
);
7403 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7404 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
7409 str
= "{ [i] -> [j] }";
7410 map
= isl_map_read_from_str(ctx
, str
);
7411 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7412 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
7420 int test_eliminate(isl_ctx
*ctx
)
7426 str
= "{ [i] -> [j] : i = 2j }";
7427 map
= isl_map_read_from_str(ctx
, str
);
7428 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
7429 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
7437 /* Check that isl_set_dim_residue_class detects that the values of j
7438 * in the set below are all odd and that it does not detect any spurious
7441 static int test_residue_class(isl_ctx
*ctx
)
7448 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
7449 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
7450 set
= isl_set_read_from_str(ctx
, str
);
7453 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
7455 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
7456 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
7457 res
= isl_stat_error
);
7465 static int test_align_parameters_1(isl_ctx
*ctx
)
7469 isl_multi_aff
*ma1
, *ma2
;
7472 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
7473 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
7475 space
= isl_space_params_alloc(ctx
, 1);
7476 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
7477 ma1
= isl_multi_aff_align_params(ma1
, space
);
7479 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
7480 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
7482 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
7484 isl_multi_aff_free(ma1
);
7485 isl_multi_aff_free(ma2
);
7490 isl_die(ctx
, isl_error_unknown
,
7491 "result not as expected", return -1);
7496 /* Check the isl_multi_*_from_*_list operation in case inputs
7497 * have unaligned parameters.
7498 * In particular, older versions of isl would simply fail
7499 * (without printing any error message).
7501 static isl_stat
test_align_parameters_2(isl_ctx
*ctx
)
7508 map
= isl_map_read_from_str(ctx
, "{ A[] -> M[x] }");
7509 space
= isl_map_get_space(map
);
7512 aff
= isl_aff_read_from_str(ctx
, "[N] -> { A[] -> [N] }");
7513 ma
= isl_multi_aff_from_aff_list(space
, isl_aff_list_from_aff(aff
));
7514 isl_multi_aff_free(ma
);
7517 return isl_stat_error
;
7521 /* Perform basic parameter alignment tests.
7523 static int test_align_parameters(isl_ctx
*ctx
)
7525 if (test_align_parameters_1(ctx
) < 0)
7527 if (test_align_parameters_2(ctx
) < 0)
7533 /* Check that isl_*_drop_unused_params actually drops the unused parameters
7534 * by comparing the result using isl_*_plain_is_equal.
7535 * Note that this assumes that isl_*_plain_is_equal does not consider
7536 * objects that only differ by unused parameters to be equal.
7538 int test_drop_unused_parameters(isl_ctx
*ctx
)
7540 const char *str_with
, *str_without
;
7541 isl_basic_set
*bset1
, *bset2
;
7542 isl_set
*set1
, *set2
;
7543 isl_pw_aff
*pwa1
, *pwa2
;
7546 str_with
= "[n, m, o] -> { [m] }";
7547 str_without
= "[m] -> { [m] }";
7549 bset1
= isl_basic_set_read_from_str(ctx
, str_with
);
7550 bset2
= isl_basic_set_read_from_str(ctx
, str_without
);
7551 bset1
= isl_basic_set_drop_unused_params(bset1
);
7552 equal
= isl_basic_set_plain_is_equal(bset1
, bset2
);
7553 isl_basic_set_free(bset1
);
7554 isl_basic_set_free(bset2
);
7559 isl_die(ctx
, isl_error_unknown
,
7560 "result not as expected", return -1);
7562 set1
= isl_set_read_from_str(ctx
, str_with
);
7563 set2
= isl_set_read_from_str(ctx
, str_without
);
7564 set1
= isl_set_drop_unused_params(set1
);
7565 equal
= isl_set_plain_is_equal(set1
, set2
);
7572 isl_die(ctx
, isl_error_unknown
,
7573 "result not as expected", return -1);
7575 pwa1
= isl_pw_aff_read_from_str(ctx
, str_with
);
7576 pwa2
= isl_pw_aff_read_from_str(ctx
, str_without
);
7577 pwa1
= isl_pw_aff_drop_unused_params(pwa1
);
7578 equal
= isl_pw_aff_plain_is_equal(pwa1
, pwa2
);
7579 isl_pw_aff_free(pwa1
);
7580 isl_pw_aff_free(pwa2
);
7585 isl_die(ctx
, isl_error_unknown
,
7586 "result not as expected", return -1);
7591 static int test_list(isl_ctx
*ctx
)
7593 isl_id
*a
, *b
, *c
, *d
, *id
;
7597 a
= isl_id_alloc(ctx
, "a", NULL
);
7598 b
= isl_id_alloc(ctx
, "b", NULL
);
7599 c
= isl_id_alloc(ctx
, "c", NULL
);
7600 d
= isl_id_alloc(ctx
, "d", NULL
);
7602 list
= isl_id_list_alloc(ctx
, 4);
7603 list
= isl_id_list_add(list
, b
);
7604 list
= isl_id_list_insert(list
, 0, a
);
7605 list
= isl_id_list_add(list
, c
);
7606 list
= isl_id_list_add(list
, d
);
7607 list
= isl_id_list_drop(list
, 1, 1);
7611 if (isl_id_list_n_id(list
) != 3) {
7612 isl_id_list_free(list
);
7613 isl_die(ctx
, isl_error_unknown
,
7614 "unexpected number of elements in list", return -1);
7617 id
= isl_id_list_get_id(list
, 0);
7620 id
= isl_id_list_get_id(list
, 1);
7623 id
= isl_id_list_get_id(list
, 2);
7627 isl_id_list_free(list
);
7630 isl_die(ctx
, isl_error_unknown
,
7631 "unexpected elements in list", return -1);
7636 const char *set_conversion_tests
[] = {
7637 "[N] -> { [i] : N - 1 <= 2 i <= N }",
7638 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
7639 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7640 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7641 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
7642 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
7643 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
7644 "-3 + c <= d <= 28 + c) }",
7647 /* Check that converting from isl_set to isl_pw_multi_aff and back
7648 * to isl_set produces the original isl_set.
7650 static int test_set_conversion(isl_ctx
*ctx
)
7654 isl_set
*set1
, *set2
;
7655 isl_pw_multi_aff
*pma
;
7658 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
7659 str
= set_conversion_tests
[i
];
7660 set1
= isl_set_read_from_str(ctx
, str
);
7661 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
7662 set2
= isl_set_from_pw_multi_aff(pma
);
7663 equal
= isl_set_is_equal(set1
, set2
);
7670 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7677 const char *conversion_tests
[] = {
7678 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7679 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7680 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7681 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7683 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7684 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7685 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7688 /* Check that converting from isl_map to isl_pw_multi_aff and back
7689 * to isl_map produces the original isl_map.
7691 static int test_map_conversion(isl_ctx
*ctx
)
7694 isl_map
*map1
, *map2
;
7695 isl_pw_multi_aff
*pma
;
7698 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
7699 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
7700 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
7701 map2
= isl_map_from_pw_multi_aff(pma
);
7702 equal
= isl_map_is_equal(map1
, map2
);
7709 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7716 /* Descriptions of isl_pw_multi_aff objects for testing conversion
7717 * to isl_multi_pw_aff and back.
7719 const char *mpa_conversion_tests
[] = {
7721 "{ [x] -> A[x] : x >= 0 }",
7722 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
7723 "{ [x] -> A[x, x + 1] }",
7725 "{ [x] -> A[] : x >= 0 }",
7728 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
7729 * back to isl_pw_multi_aff preserves the original meaning.
7731 static int test_mpa_conversion(isl_ctx
*ctx
)
7734 isl_pw_multi_aff
*pma1
, *pma2
;
7735 isl_multi_pw_aff
*mpa
;
7738 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
7740 str
= mpa_conversion_tests
[i
];
7741 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7742 pma2
= isl_pw_multi_aff_copy(pma1
);
7743 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
7744 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
7745 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
7746 isl_pw_multi_aff_free(pma1
);
7747 isl_pw_multi_aff_free(pma2
);
7752 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7759 /* Descriptions of union maps that should be convertible
7760 * to an isl_multi_union_pw_aff.
7762 const char *umap_mupa_conversion_tests
[] = {
7763 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7764 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7765 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7766 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7768 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7769 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7770 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7771 "{ A[] -> B[0]; C[] -> B[1] }",
7772 "{ A[] -> B[]; C[] -> B[] }",
7775 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
7776 * to isl_union_map produces the original isl_union_map.
7778 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
7781 isl_union_map
*umap1
, *umap2
;
7782 isl_multi_union_pw_aff
*mupa
;
7785 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
7787 str
= umap_mupa_conversion_tests
[i
];
7788 umap1
= isl_union_map_read_from_str(ctx
, str
);
7789 umap2
= isl_union_map_copy(umap1
);
7790 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
7791 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
7792 equal
= isl_union_map_is_equal(umap1
, umap2
);
7793 isl_union_map_free(umap1
);
7794 isl_union_map_free(umap2
);
7799 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7806 static int test_conversion(isl_ctx
*ctx
)
7808 if (test_set_conversion(ctx
) < 0)
7810 if (test_map_conversion(ctx
) < 0)
7812 if (test_mpa_conversion(ctx
) < 0)
7814 if (test_union_map_mupa_conversion(ctx
) < 0)
7819 /* Check that isl_basic_map_curry does not modify input.
7821 static int test_curry(isl_ctx
*ctx
)
7824 isl_basic_map
*bmap1
, *bmap2
;
7827 str
= "{ [A[] -> B[]] -> C[] }";
7828 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
7829 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
7830 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
7831 isl_basic_map_free(bmap1
);
7832 isl_basic_map_free(bmap2
);
7837 isl_die(ctx
, isl_error_unknown
,
7838 "curried map should not be equal to original",
7848 } preimage_tests
[] = {
7849 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
7850 "{ A[j,i] -> B[i,j] }",
7851 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
7852 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7853 "{ A[a,b] -> B[a/2,b/6] }",
7854 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
7855 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7856 "{ A[a,b] -> B[a/2,b/6] }",
7857 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
7858 "exists i,j : a = 2 i and b = 6 j }" },
7859 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
7860 "[n] -> { : 0 <= n <= 100 }" },
7861 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7862 "{ A[a] -> B[2a] }",
7863 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
7864 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7865 "{ A[a] -> B[([a/2])] }",
7866 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
7867 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
7868 "{ A[a] -> B[a,a,a/3] }",
7869 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
7870 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
7871 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
7874 static int test_preimage_basic_set(isl_ctx
*ctx
)
7877 isl_basic_set
*bset1
, *bset2
;
7881 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
7882 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
7883 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
7884 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
7885 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
7886 equal
= isl_basic_set_is_equal(bset1
, bset2
);
7887 isl_basic_set_free(bset1
);
7888 isl_basic_set_free(bset2
);
7892 isl_die(ctx
, isl_error_unknown
, "bad preimage",
7903 } preimage_domain_tests
[] = {
7904 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
7905 "{ A[j,i] -> B[i,j] }",
7906 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
7907 { "{ B[i] -> C[i]; D[i] -> E[i] }",
7908 "{ A[i] -> B[i + 1] }",
7909 "{ A[i] -> C[i + 1] }" },
7910 { "{ B[i] -> C[i]; B[i] -> E[i] }",
7911 "{ A[i] -> B[i + 1] }",
7912 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
7913 { "{ B[i] -> C[([i/2])] }",
7914 "{ A[i] -> B[2i] }",
7915 "{ A[i] -> C[i] }" },
7916 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
7917 "{ A[i] -> B[([i/5]), ([i/7])] }",
7918 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
7919 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
7920 "[N] -> { A[] -> B[([N/5])] }",
7921 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
7922 { "{ B[i] -> C[i] : exists a : i = 5 a }",
7923 "{ A[i] -> B[2i] }",
7924 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
7925 { "{ B[i] -> C[i] : exists a : i = 2 a; "
7926 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
7927 "{ A[i] -> B[2i] }",
7928 "{ A[i] -> C[2i] }" },
7929 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
7930 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
7933 static int test_preimage_union_map(isl_ctx
*ctx
)
7936 isl_union_map
*umap1
, *umap2
;
7940 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
7941 umap1
= isl_union_map_read_from_str(ctx
,
7942 preimage_domain_tests
[i
].map
);
7943 ma
= isl_multi_aff_read_from_str(ctx
,
7944 preimage_domain_tests
[i
].ma
);
7945 umap2
= isl_union_map_read_from_str(ctx
,
7946 preimage_domain_tests
[i
].res
);
7947 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
7948 equal
= isl_union_map_is_equal(umap1
, umap2
);
7949 isl_union_map_free(umap1
);
7950 isl_union_map_free(umap2
);
7954 isl_die(ctx
, isl_error_unknown
, "bad preimage",
7961 static int test_preimage(isl_ctx
*ctx
)
7963 if (test_preimage_basic_set(ctx
) < 0)
7965 if (test_preimage_union_map(ctx
) < 0)
7975 } pullback_tests
[] = {
7976 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
7977 "{ A[a,b] -> C[b + 2a] }" },
7978 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
7979 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
7980 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
7981 "{ A[a] -> C[(a)/6] }" },
7982 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
7983 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
7984 "{ A[a] -> C[(2a)/3] }" },
7985 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
7986 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
7987 "{ A[i,j] -> C[i + j, i + j] }"},
7988 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
7989 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
7990 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
7991 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
7992 "{ [i, j] -> [floor((i)/3), j] }",
7993 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
7996 static int test_pullback(isl_ctx
*ctx
)
7999 isl_multi_aff
*ma1
, *ma2
;
8003 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
8004 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
8005 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
8006 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
8007 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
8008 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
8009 isl_multi_aff_free(ma1
);
8010 isl_multi_aff_free(ma2
);
8014 isl_die(ctx
, isl_error_unknown
, "bad pullback",
8021 /* Check that negation is printed correctly and that equal expressions
8022 * are correctly identified.
8024 static int test_ast(isl_ctx
*ctx
)
8026 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
8030 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
8031 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
8032 expr
= isl_ast_expr_add(expr1
, expr2
);
8033 expr2
= isl_ast_expr_copy(expr
);
8034 expr
= isl_ast_expr_neg(expr
);
8035 expr2
= isl_ast_expr_neg(expr2
);
8036 equal
= isl_ast_expr_is_equal(expr
, expr2
);
8037 str
= isl_ast_expr_to_C_str(expr
);
8038 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
8040 isl_ast_expr_free(expr
);
8041 isl_ast_expr_free(expr2
);
8043 if (ok
< 0 || equal
< 0)
8046 isl_die(ctx
, isl_error_unknown
,
8047 "equal expressions not considered equal", return -1);
8049 isl_die(ctx
, isl_error_unknown
,
8050 "isl_ast_expr printed incorrectly", return -1);
8052 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
8053 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
8054 expr
= isl_ast_expr_add(expr1
, expr2
);
8055 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
8056 expr
= isl_ast_expr_sub(expr3
, expr
);
8057 str
= isl_ast_expr_to_C_str(expr
);
8058 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
8060 isl_ast_expr_free(expr
);
8065 isl_die(ctx
, isl_error_unknown
,
8066 "isl_ast_expr printed incorrectly", return -1);
8071 /* Check that isl_ast_build_expr_from_set returns a valid expression
8072 * for an empty set. Note that isl_ast_build_expr_from_set getting
8073 * called on an empty set probably indicates a bug in the caller.
8075 static int test_ast_build(isl_ctx
*ctx
)
8078 isl_ast_build
*build
;
8081 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8082 build
= isl_ast_build_from_context(set
);
8084 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
8085 expr
= isl_ast_build_expr_from_set(build
, set
);
8087 isl_ast_expr_free(expr
);
8088 isl_ast_build_free(build
);
8096 /* Internal data structure for before_for and after_for callbacks.
8098 * depth is the current depth
8099 * before is the number of times before_for has been called
8100 * after is the number of times after_for has been called
8102 struct isl_test_codegen_data
{
8108 /* This function is called before each for loop in the AST generated
8109 * from test_ast_gen1.
8111 * Increment the number of calls and the depth.
8112 * Check that the space returned by isl_ast_build_get_schedule_space
8113 * matches the target space of the schedule returned by
8114 * isl_ast_build_get_schedule.
8115 * Return an isl_id that is checked by the corresponding call
8118 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
8121 struct isl_test_codegen_data
*data
= user
;
8124 isl_union_map
*schedule
;
8125 isl_union_set
*uset
;
8130 ctx
= isl_ast_build_get_ctx(build
);
8132 if (data
->before
>= 3)
8133 isl_die(ctx
, isl_error_unknown
,
8134 "unexpected number of for nodes", return NULL
);
8135 if (data
->depth
>= 2)
8136 isl_die(ctx
, isl_error_unknown
,
8137 "unexpected depth", return NULL
);
8139 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
8143 schedule
= isl_ast_build_get_schedule(build
);
8144 uset
= isl_union_map_range(schedule
);
8147 if (isl_union_set_n_set(uset
) != 1) {
8148 isl_union_set_free(uset
);
8149 isl_die(ctx
, isl_error_unknown
,
8150 "expecting single range space", return NULL
);
8153 space
= isl_ast_build_get_schedule_space(build
);
8154 set
= isl_union_set_extract_set(uset
, space
);
8155 isl_union_set_free(uset
);
8156 empty
= isl_set_is_empty(set
);
8162 isl_die(ctx
, isl_error_unknown
,
8163 "spaces don't match", return NULL
);
8165 return isl_id_alloc(ctx
, name
, NULL
);
8168 /* This function is called after each for loop in the AST generated
8169 * from test_ast_gen1.
8171 * Increment the number of calls and decrement the depth.
8172 * Check that the annotation attached to the node matches
8173 * the isl_id returned by the corresponding call to before_for.
8175 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
8176 __isl_keep isl_ast_build
*build
, void *user
)
8178 struct isl_test_codegen_data
*data
= user
;
8186 if (data
->after
> data
->before
)
8187 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8188 "mismatch in number of for nodes",
8189 return isl_ast_node_free(node
));
8191 id
= isl_ast_node_get_annotation(node
);
8193 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8194 "missing annotation", return isl_ast_node_free(node
));
8196 name
= isl_id_get_name(id
);
8197 valid
= name
&& atoi(name
+ 1) == data
->depth
;
8201 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8202 "wrong annotation", return isl_ast_node_free(node
));
8207 /* Check that the before_each_for and after_each_for callbacks
8208 * are called for each for loop in the generated code,
8209 * that they are called in the right order and that the isl_id
8210 * returned from the before_each_for callback is attached to
8211 * the isl_ast_node passed to the corresponding after_each_for call.
8213 static int test_ast_gen1(isl_ctx
*ctx
)
8217 isl_union_map
*schedule
;
8218 isl_ast_build
*build
;
8220 struct isl_test_codegen_data data
;
8222 str
= "[N] -> { : N >= 10 }";
8223 set
= isl_set_read_from_str(ctx
, str
);
8224 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
8225 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
8226 schedule
= isl_union_map_read_from_str(ctx
, str
);
8231 build
= isl_ast_build_from_context(set
);
8232 build
= isl_ast_build_set_before_each_for(build
,
8233 &before_for
, &data
);
8234 build
= isl_ast_build_set_after_each_for(build
,
8236 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8237 isl_ast_build_free(build
);
8241 isl_ast_node_free(tree
);
8243 if (data
.before
!= 3 || data
.after
!= 3)
8244 isl_die(ctx
, isl_error_unknown
,
8245 "unexpected number of for nodes", return -1);
8250 /* Check that the AST generator handles domains that are integrally disjoint
8251 * but not rationally disjoint.
8253 static int test_ast_gen2(isl_ctx
*ctx
)
8257 isl_union_map
*schedule
;
8258 isl_union_map
*options
;
8259 isl_ast_build
*build
;
8262 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
8263 schedule
= isl_union_map_read_from_str(ctx
, str
);
8264 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8265 build
= isl_ast_build_from_context(set
);
8267 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
8268 options
= isl_union_map_read_from_str(ctx
, str
);
8269 build
= isl_ast_build_set_options(build
, options
);
8270 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8271 isl_ast_build_free(build
);
8274 isl_ast_node_free(tree
);
8279 /* Increment *user on each call.
8281 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
8282 __isl_keep isl_ast_build
*build
, void *user
)
8291 /* Test that unrolling tries to minimize the number of instances.
8292 * In particular, for the schedule given below, make sure it generates
8293 * 3 nodes (rather than 101).
8295 static int test_ast_gen3(isl_ctx
*ctx
)
8299 isl_union_map
*schedule
;
8300 isl_union_map
*options
;
8301 isl_ast_build
*build
;
8305 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
8306 schedule
= isl_union_map_read_from_str(ctx
, str
);
8307 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8309 str
= "{ [i] -> unroll[0] }";
8310 options
= isl_union_map_read_from_str(ctx
, str
);
8312 build
= isl_ast_build_from_context(set
);
8313 build
= isl_ast_build_set_options(build
, options
);
8314 build
= isl_ast_build_set_at_each_domain(build
,
8315 &count_domains
, &n_domain
);
8316 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8317 isl_ast_build_free(build
);
8321 isl_ast_node_free(tree
);
8324 isl_die(ctx
, isl_error_unknown
,
8325 "unexpected number of for nodes", return -1);
8330 /* Check that if the ast_build_exploit_nested_bounds options is set,
8331 * we do not get an outer if node in the generated AST,
8332 * while we do get such an outer if node if the options is not set.
8334 static int test_ast_gen4(isl_ctx
*ctx
)
8338 isl_union_map
*schedule
;
8339 isl_ast_build
*build
;
8341 enum isl_ast_node_type type
;
8344 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
8345 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
8347 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
8349 schedule
= isl_union_map_read_from_str(ctx
, str
);
8350 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8351 build
= isl_ast_build_from_context(set
);
8352 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8353 isl_ast_build_free(build
);
8357 type
= isl_ast_node_get_type(tree
);
8358 isl_ast_node_free(tree
);
8360 if (type
== isl_ast_node_if
)
8361 isl_die(ctx
, isl_error_unknown
,
8362 "not expecting if node", return -1);
8364 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
8366 schedule
= isl_union_map_read_from_str(ctx
, str
);
8367 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8368 build
= isl_ast_build_from_context(set
);
8369 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8370 isl_ast_build_free(build
);
8374 type
= isl_ast_node_get_type(tree
);
8375 isl_ast_node_free(tree
);
8377 if (type
!= isl_ast_node_if
)
8378 isl_die(ctx
, isl_error_unknown
,
8379 "expecting if node", return -1);
8381 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
8386 /* This function is called for each leaf in the AST generated
8387 * from test_ast_gen5.
8389 * We finalize the AST generation by extending the outer schedule
8390 * with a zero-dimensional schedule. If this results in any for loops,
8391 * then this means that we did not pass along enough information
8392 * about the outer schedule to the inner AST generation.
8394 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
8397 isl_union_map
*schedule
, *extra
;
8400 schedule
= isl_ast_build_get_schedule(build
);
8401 extra
= isl_union_map_copy(schedule
);
8402 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
8403 schedule
= isl_union_map_range_product(schedule
, extra
);
8404 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8405 isl_ast_build_free(build
);
8410 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
8411 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
8412 "code should not contain any for loop",
8413 return isl_ast_node_free(tree
));
8418 /* Check that we do not lose any information when going back and
8419 * forth between internal and external schedule.
8421 * In particular, we create an AST where we unroll the only
8422 * non-constant dimension in the schedule. We therefore do
8423 * not expect any for loops in the AST. However, older versions
8424 * of isl would not pass along enough information about the outer
8425 * schedule when performing an inner code generation from a create_leaf
8426 * callback, resulting in the inner code generation producing a for loop.
8428 static int test_ast_gen5(isl_ctx
*ctx
)
8432 isl_union_map
*schedule
, *options
;
8433 isl_ast_build
*build
;
8436 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
8437 schedule
= isl_union_map_read_from_str(ctx
, str
);
8439 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
8440 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
8441 options
= isl_union_map_read_from_str(ctx
, str
);
8443 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8444 build
= isl_ast_build_from_context(set
);
8445 build
= isl_ast_build_set_options(build
, options
);
8446 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
8447 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8448 isl_ast_build_free(build
);
8449 isl_ast_node_free(tree
);
8456 /* Check that the expression
8458 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
8460 * is not combined into
8464 * as this would result in n/2 being evaluated in parts of
8465 * the definition domain where n is not a multiple of 2.
8467 static int test_ast_expr(isl_ctx
*ctx
)
8471 isl_ast_build
*build
;
8476 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
8477 isl_options_set_ast_build_detect_min_max(ctx
, 1);
8479 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
8480 pa
= isl_pw_aff_read_from_str(ctx
, str
);
8481 build
= isl_ast_build_alloc(ctx
);
8482 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
8483 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
8484 isl_ast_expr_get_op_type(expr
) == isl_ast_op_min
;
8485 isl_ast_build_free(build
);
8486 isl_ast_expr_free(expr
);
8488 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
8493 isl_die(ctx
, isl_error_unknown
,
8494 "expressions should not be combined", return -1);
8499 static int test_ast_gen(isl_ctx
*ctx
)
8501 if (test_ast_gen1(ctx
) < 0)
8503 if (test_ast_gen2(ctx
) < 0)
8505 if (test_ast_gen3(ctx
) < 0)
8507 if (test_ast_gen4(ctx
) < 0)
8509 if (test_ast_gen5(ctx
) < 0)
8511 if (test_ast_expr(ctx
) < 0)
8516 /* Check if dropping output dimensions from an isl_pw_multi_aff
8519 static int test_pw_multi_aff(isl_ctx
*ctx
)
8522 isl_pw_multi_aff
*pma1
, *pma2
;
8525 str
= "{ [i,j] -> [i+j, 4i-j] }";
8526 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8527 str
= "{ [i,j] -> [4i-j] }";
8528 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8530 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
8532 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
8534 isl_pw_multi_aff_free(pma1
);
8535 isl_pw_multi_aff_free(pma2
);
8539 isl_die(ctx
, isl_error_unknown
,
8540 "expressions not equal", return -1);
8545 /* Check that we can properly parse multi piecewise affine expressions
8546 * where the piecewise affine expressions have different domains.
8548 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
8551 isl_set
*dom
, *dom2
;
8552 isl_multi_pw_aff
*mpa1
, *mpa2
;
8557 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
8558 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
8559 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
8560 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
8561 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
8562 str
= "{ [i] -> [(i : i > 0), 2i] }";
8563 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8565 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
8567 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
8568 dom
= isl_pw_aff_domain(pa
);
8569 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
8570 dom2
= isl_pw_aff_domain(pa
);
8571 equal_domain
= isl_set_is_equal(dom
, dom2
);
8575 isl_multi_pw_aff_free(mpa1
);
8576 isl_multi_pw_aff_free(mpa2
);
8581 isl_die(ctx
, isl_error_unknown
,
8582 "expressions not equal", return -1);
8584 if (equal_domain
< 0)
8587 isl_die(ctx
, isl_error_unknown
,
8588 "domains unexpectedly equal", return -1);
8593 /* Check that the dimensions in the explicit domain
8594 * of a multi piecewise affine expression are properly
8595 * taken into account.
8597 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
8600 isl_bool involves1
, involves2
, involves3
, equal
;
8601 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
8603 str
= "{ A[x,y] -> B[] : x >= y }";
8604 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8605 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
8606 mpa1
= isl_multi_pw_aff_copy(mpa
);
8608 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
8609 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
8610 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
8611 str
= "{ [a,x,y] -> B[] : x >= y }";
8612 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8613 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
8614 isl_multi_pw_aff_free(mpa2
);
8616 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
8617 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
8618 if (equal
>= 0 && equal
)
8619 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
8620 isl_multi_pw_aff_free(mpa1
);
8621 isl_multi_pw_aff_free(mpa
);
8623 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
8626 isl_die(ctx
, isl_error_unknown
,
8627 "incorrect result of dimension insertion/removal",
8628 return isl_stat_error
);
8629 if (!involves1
|| involves2
|| !involves3
)
8630 isl_die(ctx
, isl_error_unknown
,
8631 "incorrect characterization of involved dimensions",
8632 return isl_stat_error
);
8637 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
8638 * sets the explicit domain of a zero-dimensional result,
8639 * such that it can be converted to an isl_union_map.
8641 static isl_stat
test_multi_pw_aff_3(isl_ctx
*ctx
)
8646 isl_multi_union_pw_aff
*mupa
;
8647 isl_union_map
*umap
;
8649 dom
= isl_union_set_read_from_str(ctx
, "{ A[]; B[] }");
8650 space
= isl_union_set_get_space(dom
);
8651 mv
= isl_multi_val_zero(isl_space_set_from_params(space
));
8652 mupa
= isl_multi_union_pw_aff_multi_val_on_domain(dom
, mv
);
8653 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
8654 isl_union_map_free(umap
);
8656 return isl_stat_error
;
8661 /* Perform some tests on multi piecewise affine expressions.
8663 static int test_multi_pw_aff(isl_ctx
*ctx
)
8665 if (test_multi_pw_aff_1(ctx
) < 0)
8667 if (test_multi_pw_aff_2(ctx
) < 0)
8669 if (test_multi_pw_aff_3(ctx
) < 0)
8674 /* This is a regression test for a bug where isl_basic_map_simplify
8675 * would end up in an infinite loop. In particular, we construct
8676 * an empty basic set that is not obviously empty.
8677 * isl_basic_set_is_empty marks the basic set as empty.
8678 * After projecting out i3, the variable can be dropped completely,
8679 * but isl_basic_map_simplify refrains from doing so if the basic set
8680 * is empty and would end up in an infinite loop if it didn't test
8681 * explicitly for empty basic maps in the outer loop.
8683 static int test_simplify_1(isl_ctx
*ctx
)
8686 isl_basic_set
*bset
;
8689 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
8690 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
8691 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
8693 bset
= isl_basic_set_read_from_str(ctx
, str
);
8694 empty
= isl_basic_set_is_empty(bset
);
8695 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
8696 isl_basic_set_free(bset
);
8700 isl_die(ctx
, isl_error_unknown
,
8701 "basic set should be empty", return -1);
8706 /* Check that the equality in the set description below
8707 * is simplified away.
8709 static int test_simplify_2(isl_ctx
*ctx
)
8712 isl_basic_set
*bset
;
8715 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
8716 bset
= isl_basic_set_read_from_str(ctx
, str
);
8717 universe
= isl_basic_set_plain_is_universe(bset
);
8718 isl_basic_set_free(bset
);
8723 isl_die(ctx
, isl_error_unknown
,
8724 "equality not simplified away", return -1);
8728 /* Some simplification tests.
8730 static int test_simplify(isl_ctx
*ctx
)
8732 if (test_simplify_1(ctx
) < 0)
8734 if (test_simplify_2(ctx
) < 0)
8739 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
8740 * with gbr context would fail to disable the use of the shifted tableau
8741 * when transferring equalities for the input to the context, resulting
8742 * in invalid sample values.
8744 static int test_partial_lexmin(isl_ctx
*ctx
)
8747 isl_basic_set
*bset
;
8748 isl_basic_map
*bmap
;
8751 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
8752 bmap
= isl_basic_map_read_from_str(ctx
, str
);
8753 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
8754 bset
= isl_basic_set_read_from_str(ctx
, str
);
8755 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
8764 /* Check that the variable compression performed on the existentially
8765 * quantified variables inside isl_basic_set_compute_divs is not confused
8766 * by the implicit equalities among the parameters.
8768 static int test_compute_divs(isl_ctx
*ctx
)
8771 isl_basic_set
*bset
;
8774 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
8775 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
8776 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
8777 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
8778 bset
= isl_basic_set_read_from_str(ctx
, str
);
8779 set
= isl_basic_set_compute_divs(bset
);
8787 /* Check that isl_schedule_get_map is not confused by a schedule tree
8788 * with divergent filter node parameters, as can result from a call
8789 * to isl_schedule_intersect_domain.
8791 static int test_schedule_tree(isl_ctx
*ctx
)
8794 isl_union_set
*uset
;
8795 isl_schedule
*sched1
, *sched2
;
8796 isl_union_map
*umap
;
8798 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
8799 sched1
= isl_schedule_from_domain(uset
);
8800 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
8801 sched2
= isl_schedule_from_domain(uset
);
8803 sched1
= isl_schedule_sequence(sched1
, sched2
);
8804 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
8805 uset
= isl_union_set_read_from_str(ctx
, str
);
8806 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
8807 umap
= isl_schedule_get_map(sched1
);
8808 isl_schedule_free(sched1
);
8809 isl_union_map_free(umap
);
8816 /* Check that a zero-dimensional prefix schedule keeps track
8817 * of the domain and outer filters.
8819 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
8823 isl_union_set
*uset
;
8824 isl_union_set_list
*filters
;
8825 isl_multi_union_pw_aff
*mupa
, *mupa2
;
8826 isl_schedule_node
*node
;
8828 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8829 uset
= isl_union_set_read_from_str(ctx
, str
);
8830 node
= isl_schedule_node_from_domain(uset
);
8831 node
= isl_schedule_node_child(node
, 0);
8833 str
= "{ S1[i,j] : i > j }";
8834 uset
= isl_union_set_read_from_str(ctx
, str
);
8835 filters
= isl_union_set_list_from_union_set(uset
);
8836 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
8837 uset
= isl_union_set_read_from_str(ctx
, str
);
8838 filters
= isl_union_set_list_add(filters
, uset
);
8839 node
= isl_schedule_node_insert_sequence(node
, filters
);
8841 node
= isl_schedule_node_child(node
, 0);
8842 node
= isl_schedule_node_child(node
, 0);
8843 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
8844 str
= "([] : { S1[i,j] : i > j })";
8845 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8846 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
8847 isl_multi_union_pw_aff_free(mupa2
);
8848 isl_multi_union_pw_aff_free(mupa
);
8849 isl_schedule_node_free(node
);
8854 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
8860 /* Check that the reaching domain elements and the prefix schedule
8861 * at a leaf node are the same before and after grouping.
8863 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
8868 isl_union_set
*uset
;
8869 isl_multi_union_pw_aff
*mupa
;
8870 isl_union_pw_multi_aff
*upma1
, *upma2
;
8871 isl_union_set
*domain1
, *domain2
;
8872 isl_union_map
*umap1
, *umap2
;
8873 isl_schedule_node
*node
;
8875 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8876 uset
= isl_union_set_read_from_str(ctx
, str
);
8877 node
= isl_schedule_node_from_domain(uset
);
8878 node
= isl_schedule_node_child(node
, 0);
8879 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
8880 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8881 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8882 node
= isl_schedule_node_child(node
, 0);
8883 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
8884 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8885 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8886 node
= isl_schedule_node_child(node
, 0);
8887 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
8888 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
8889 domain1
= isl_schedule_node_get_domain(node
);
8890 id
= isl_id_alloc(ctx
, "group", NULL
);
8891 node
= isl_schedule_node_parent(node
);
8892 node
= isl_schedule_node_group(node
, id
);
8893 node
= isl_schedule_node_child(node
, 0);
8894 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
8895 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
8896 domain2
= isl_schedule_node_get_domain(node
);
8897 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
8898 if (equal
>= 0 && equal
)
8899 equal
= isl_union_set_is_equal(domain1
, domain2
);
8900 if (equal
>= 0 && equal
)
8901 equal
= isl_union_map_is_equal(umap1
, umap2
);
8902 isl_union_map_free(umap1
);
8903 isl_union_map_free(umap2
);
8904 isl_union_set_free(domain1
);
8905 isl_union_set_free(domain2
);
8906 isl_union_pw_multi_aff_free(upma1
);
8907 isl_union_pw_multi_aff_free(upma2
);
8908 isl_schedule_node_free(node
);
8913 isl_die(ctx
, isl_error_unknown
,
8914 "expressions not equal", return -1);
8919 /* Check that we can have nested groupings and that the union map
8920 * schedule representation is the same before and after the grouping.
8921 * Note that after the grouping, the union map representation contains
8922 * the domain constraints from the ranges of the expansion nodes,
8923 * while they are missing from the union map representation of
8924 * the tree without expansion nodes.
8926 * Also check that the global expansion is as expected.
8928 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
8930 int equal
, equal_expansion
;
8933 isl_union_set
*uset
;
8934 isl_union_map
*umap1
, *umap2
;
8935 isl_union_map
*expansion1
, *expansion2
;
8936 isl_union_set_list
*filters
;
8937 isl_multi_union_pw_aff
*mupa
;
8938 isl_schedule
*schedule
;
8939 isl_schedule_node
*node
;
8941 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
8942 "S3[i,j] : 0 <= i,j < 10 }";
8943 uset
= isl_union_set_read_from_str(ctx
, str
);
8944 node
= isl_schedule_node_from_domain(uset
);
8945 node
= isl_schedule_node_child(node
, 0);
8946 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
8947 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
8948 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
8949 node
= isl_schedule_node_child(node
, 0);
8950 str
= "{ S1[i,j] }";
8951 uset
= isl_union_set_read_from_str(ctx
, str
);
8952 filters
= isl_union_set_list_from_union_set(uset
);
8953 str
= "{ S2[i,j]; S3[i,j] }";
8954 uset
= isl_union_set_read_from_str(ctx
, str
);
8955 filters
= isl_union_set_list_add(filters
, uset
);
8956 node
= isl_schedule_node_insert_sequence(node
, filters
);
8957 node
= isl_schedule_node_child(node
, 1);
8958 node
= isl_schedule_node_child(node
, 0);
8959 str
= "{ S2[i,j] }";
8960 uset
= isl_union_set_read_from_str(ctx
, str
);
8961 filters
= isl_union_set_list_from_union_set(uset
);
8962 str
= "{ S3[i,j] }";
8963 uset
= isl_union_set_read_from_str(ctx
, str
);
8964 filters
= isl_union_set_list_add(filters
, uset
);
8965 node
= isl_schedule_node_insert_sequence(node
, filters
);
8967 schedule
= isl_schedule_node_get_schedule(node
);
8968 umap1
= isl_schedule_get_map(schedule
);
8969 uset
= isl_schedule_get_domain(schedule
);
8970 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
8971 isl_schedule_free(schedule
);
8973 node
= isl_schedule_node_parent(node
);
8974 node
= isl_schedule_node_parent(node
);
8975 id
= isl_id_alloc(ctx
, "group1", NULL
);
8976 node
= isl_schedule_node_group(node
, id
);
8977 node
= isl_schedule_node_child(node
, 1);
8978 node
= isl_schedule_node_child(node
, 0);
8979 id
= isl_id_alloc(ctx
, "group2", NULL
);
8980 node
= isl_schedule_node_group(node
, id
);
8982 schedule
= isl_schedule_node_get_schedule(node
);
8983 umap2
= isl_schedule_get_map(schedule
);
8984 isl_schedule_free(schedule
);
8986 node
= isl_schedule_node_root(node
);
8987 node
= isl_schedule_node_child(node
, 0);
8988 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
8989 isl_schedule_node_free(node
);
8991 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
8992 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
8993 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
8995 expansion2
= isl_union_map_read_from_str(ctx
, str
);
8997 equal
= isl_union_map_is_equal(umap1
, umap2
);
8998 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
9000 isl_union_map_free(umap1
);
9001 isl_union_map_free(umap2
);
9002 isl_union_map_free(expansion1
);
9003 isl_union_map_free(expansion2
);
9005 if (equal
< 0 || equal_expansion
< 0)
9008 isl_die(ctx
, isl_error_unknown
,
9009 "expressions not equal", return -1);
9010 if (!equal_expansion
)
9011 isl_die(ctx
, isl_error_unknown
,
9012 "unexpected expansion", return -1);
9017 /* Some tests for the isl_schedule_node_group function.
9019 static int test_schedule_tree_group(isl_ctx
*ctx
)
9021 if (test_schedule_tree_group_1(ctx
) < 0)
9023 if (test_schedule_tree_group_2(ctx
) < 0)
9032 { "{ rat: [i] : 0 <= i <= 10 }",
9033 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
9034 { "{ rat: [i] : FALSE }",
9035 "{ rat: coefficients[[cst] -> [a]] }" },
9037 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
9044 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
9045 "{ rat: [i] : 0 <= i <= 10 }" },
9046 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
9048 { "{ rat: coefficients[[cst] -> [a]] }",
9049 "{ rat: [i] : FALSE }" },
9052 /* Test the basic functionality of isl_basic_set_coefficients and
9053 * isl_basic_set_solutions.
9055 static int test_dual(isl_ctx
*ctx
)
9059 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
9061 isl_basic_set
*bset1
, *bset2
;
9063 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
9064 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
9065 bset1
= isl_basic_set_coefficients(bset1
);
9066 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9067 isl_basic_set_free(bset1
);
9068 isl_basic_set_free(bset2
);
9072 isl_die(ctx
, isl_error_unknown
,
9073 "incorrect dual", return -1);
9076 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
9078 isl_basic_set
*bset1
, *bset2
;
9080 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
9081 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
9082 bset1
= isl_basic_set_solutions(bset1
);
9083 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9084 isl_basic_set_free(bset1
);
9085 isl_basic_set_free(bset2
);
9089 isl_die(ctx
, isl_error_unknown
,
9090 "incorrect dual", return -1);
9100 const char *schedule
;
9105 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
9106 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9108 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
9109 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9111 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
9112 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9114 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
9115 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9117 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
9118 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9120 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
9121 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
9123 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
9124 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9126 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
9127 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
9131 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
9132 * tile the band and then check if the tile and point bands have the
9133 * expected partial schedule.
9135 static int test_tile(isl_ctx
*ctx
)
9141 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
9142 shift
= isl_options_get_tile_shift_point_loops(ctx
);
9144 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
9148 isl_union_set
*domain
;
9149 isl_multi_union_pw_aff
*mupa
, *mupa2
;
9150 isl_schedule_node
*node
;
9151 isl_multi_val
*sizes
;
9153 opt
= tile_tests
[i
].scale_tile
;
9154 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
9155 opt
= tile_tests
[i
].shift_point
;
9156 isl_options_set_tile_shift_point_loops(ctx
, opt
);
9158 str
= tile_tests
[i
].domain
;
9159 domain
= isl_union_set_read_from_str(ctx
, str
);
9160 node
= isl_schedule_node_from_domain(domain
);
9161 node
= isl_schedule_node_child(node
, 0);
9162 str
= tile_tests
[i
].schedule
;
9163 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9164 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
9165 str
= tile_tests
[i
].sizes
;
9166 sizes
= isl_multi_val_read_from_str(ctx
, str
);
9167 node
= isl_schedule_node_band_tile(node
, sizes
);
9169 str
= tile_tests
[i
].tile
;
9170 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9171 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
9172 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
9173 isl_multi_union_pw_aff_free(mupa
);
9174 isl_multi_union_pw_aff_free(mupa2
);
9176 node
= isl_schedule_node_child(node
, 0);
9178 str
= tile_tests
[i
].point
;
9179 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9180 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
9181 if (equal
>= 0 && equal
)
9182 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
9184 isl_multi_union_pw_aff_free(mupa
);
9185 isl_multi_union_pw_aff_free(mupa2
);
9187 isl_schedule_node_free(node
);
9192 isl_die(ctx
, isl_error_unknown
,
9193 "unexpected result", return -1);
9196 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
9197 isl_options_set_tile_shift_point_loops(ctx
, shift
);
9202 /* Check that the domain hash of a space is equal to the hash
9203 * of the domain of the space.
9205 static int test_domain_hash(isl_ctx
*ctx
)
9209 uint32_t hash1
, hash2
;
9211 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
9212 space
= isl_map_get_space(map
);
9214 hash1
= isl_space_get_domain_hash(space
);
9215 space
= isl_space_domain(space
);
9216 hash2
= isl_space_get_hash(space
);
9217 isl_space_free(space
);
9222 isl_die(ctx
, isl_error_unknown
,
9223 "domain hash not equal to hash of domain", return -1);
9228 /* Check that a universe basic set that is not obviously equal to the universe
9229 * is still recognized as being equal to the universe.
9231 static int test_universe(isl_ctx
*ctx
)
9234 isl_basic_set
*bset
;
9237 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
9238 bset
= isl_basic_set_read_from_str(ctx
, s
);
9239 is_univ
= isl_basic_set_is_universe(bset
);
9240 isl_basic_set_free(bset
);
9245 isl_die(ctx
, isl_error_unknown
,
9246 "not recognized as universe set", return -1);
9251 /* Sets for which chambers are computed and checked.
9253 const char *chambers_tests
[] = {
9254 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
9255 "z >= 0 and z <= C - y and z <= B - x - y }",
9258 /* Add the domain of "cell" to "cells".
9260 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
9262 isl_basic_set_list
**cells
= user
;
9265 dom
= isl_cell_get_domain(cell
);
9266 isl_cell_free(cell
);
9267 *cells
= isl_basic_set_list_add(*cells
, dom
);
9269 return *cells
? isl_stat_ok
: isl_stat_error
;
9272 /* Check that the elements of "list" are pairwise disjoint.
9274 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
9279 return isl_stat_error
;
9281 n
= isl_basic_set_list_n_basic_set(list
);
9282 for (i
= 0; i
< n
; ++i
) {
9283 isl_basic_set
*bset_i
;
9285 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
9286 for (j
= i
+ 1; j
< n
; ++j
) {
9287 isl_basic_set
*bset_j
;
9290 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
9291 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
9292 isl_basic_set_free(bset_j
);
9294 isl_die(isl_basic_set_list_get_ctx(list
),
9295 isl_error_unknown
, "not disjoint",
9297 if (disjoint
< 0 || !disjoint
)
9300 isl_basic_set_free(bset_i
);
9302 return isl_stat_error
;
9308 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
9309 * are pairwise disjoint.
9311 static int test_chambers(isl_ctx
*ctx
)
9315 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
9316 isl_basic_set
*bset
;
9317 isl_vertices
*vertices
;
9318 isl_basic_set_list
*cells
;
9321 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
9322 vertices
= isl_basic_set_compute_vertices(bset
);
9323 cells
= isl_basic_set_list_alloc(ctx
, 0);
9324 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
9326 cells
= isl_basic_set_list_free(cells
);
9327 ok
= check_pairwise_disjoint(cells
);
9328 isl_basic_set_list_free(cells
);
9329 isl_vertices_free(vertices
);
9330 isl_basic_set_free(bset
);
9341 int (*fn
)(isl_ctx
*ctx
);
9343 { "universe", &test_universe
},
9344 { "domain hash", &test_domain_hash
},
9345 { "dual", &test_dual
},
9346 { "dependence analysis", &test_flow
},
9347 { "val", &test_val
},
9348 { "compute divs", &test_compute_divs
},
9349 { "partial lexmin", &test_partial_lexmin
},
9350 { "simplify", &test_simplify
},
9351 { "curry", &test_curry
},
9352 { "piecewise multi affine expressions", &test_pw_multi_aff
},
9353 { "multi piecewise affine expressions", &test_multi_pw_aff
},
9354 { "conversion", &test_conversion
},
9355 { "list", &test_list
},
9356 { "align parameters", &test_align_parameters
},
9357 { "drop unused parameters", &test_drop_unused_parameters
},
9358 { "preimage", &test_preimage
},
9359 { "pullback", &test_pullback
},
9360 { "AST", &test_ast
},
9361 { "AST build", &test_ast_build
},
9362 { "AST generation", &test_ast_gen
},
9363 { "eliminate", &test_eliminate
},
9364 { "residue class", &test_residue_class
},
9365 { "div", &test_div
},
9366 { "slice", &test_slice
},
9367 { "fixed power", &test_fixed_power
},
9368 { "sample", &test_sample
},
9369 { "output", &test_output
},
9370 { "vertices", &test_vertices
},
9371 { "chambers", &test_chambers
},
9372 { "fixed", &test_fixed
},
9373 { "equal", &test_equal
},
9374 { "disjoint", &test_disjoint
},
9375 { "product", &test_product
},
9376 { "dim_max", &test_dim_max
},
9377 { "affine", &test_aff
},
9378 { "injective", &test_injective
},
9379 { "schedule (whole component)", &test_schedule_whole
},
9380 { "schedule (incremental)", &test_schedule_incremental
},
9381 { "schedule tree", &test_schedule_tree
},
9382 { "schedule tree prefix", &test_schedule_tree_prefix
},
9383 { "schedule tree grouping", &test_schedule_tree_group
},
9384 { "tile", &test_tile
},
9385 { "union_pw", &test_union_pw
},
9386 { "locus", &test_locus
},
9387 { "eval", &test_eval
},
9388 { "parse", &test_parse
},
9389 { "single-valued", &test_sv
},
9390 { "affine hull", &test_affine_hull
},
9391 { "simple_hull", &test_simple_hull
},
9392 { "coalesce", &test_coalesce
},
9393 { "factorize", &test_factorize
},
9394 { "subset", &test_subset
},
9395 { "subtract", &test_subtract
},
9396 { "intersect", &test_intersect
},
9397 { "lexmin", &test_lexmin
},
9398 { "min", &test_min
},
9399 { "gist", &test_gist
},
9400 { "piecewise quasi-polynomials", &test_pwqp
},
9401 { "lift", &test_lift
},
9402 { "bound", &test_bound
},
9403 { "get lists", &test_get_list
},
9404 { "union", &test_union
},
9405 { "split periods", &test_split_periods
},
9406 { "lexicographic order", &test_lex
},
9407 { "bijectivity", &test_bijective
},
9408 { "dataflow analysis", &test_dep
},
9409 { "reading", &test_read
},
9410 { "bounded", &test_bounded
},
9411 { "construction", &test_construction
},
9412 { "dimension manipulation", &test_dim
},
9413 { "map application", &test_application
},
9414 { "convex hull", &test_convex_hull
},
9415 { "transitive closure", &test_closure
},
9418 int main(int argc
, char **argv
)
9421 struct isl_ctx
*ctx
;
9422 struct isl_options
*options
;
9424 options
= isl_options_new_with_defaults();
9426 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
9428 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
9429 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
9430 printf("%s\n", tests
[i
].name
);
9431 if (tests
[i
].fn(ctx
) < 0)