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
);
124 #define BASE multi_pw_aff
126 #include "check_reparse_templ.c"
129 #define BASE pw_multi_aff
131 #include "check_reparse_templ.c"
133 /* Test parsing of piecewise multi affine expressions by printing
134 * the expressions and checking that parsing the output results
135 * in the same expression.
136 * Do this for an expression converted from a map with an output
137 * dimension name that is equal to an automatically generated name.
139 static isl_stat
test_parse_pma(isl_ctx
*ctx
)
142 isl_pw_multi_aff
*pma
;
144 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
145 pma
= isl_pw_multi_aff_from_map(map
);
146 if (check_reparse_pw_multi_aff(ctx
, pma
) < 0)
147 return isl_stat_error
;
152 /* String descriptions of multi piecewise affine expressions
153 * that are used for testing printing and parsing.
155 const char *parse_multi_mpa_tests
[] = {
156 "{ A[x, y] -> [] : x + y >= 0 }",
157 "{ A[x, y] -> B[] : x + y >= 0 }",
158 "{ A[x, y] -> [x] : x + y >= 0 }",
159 "[N] -> { A[x, y] -> [x] : x + y <= N }",
160 "{ A[x, y] -> [x, y] : x + y >= 0 }",
161 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
162 "[N] -> { [] : N >= 0 }",
163 "[N] -> { [] : N >= 0 }",
164 "[N] -> { [N] : N >= 0 }",
165 "[N] -> { [N, N + 1] : N >= 0 }",
166 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
169 /* Test parsing of multi piecewise affine expressions by printing
170 * the expressions and checking that parsing the output results
171 * in the same expression.
172 * Do this for a couple of manually constructed expressions,
173 * an expression converted from a map with an output dimension name
174 * that is equal to an automatically generated name, and
175 * a set of expressions parsed from strings.
177 static int test_parse_mpa(isl_ctx
*ctx
)
183 isl_pw_multi_aff
*pma
;
184 isl_multi_pw_aff
*mpa
;
187 space
= isl_space_set_alloc(ctx
, 0, 0);
188 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
189 mpa
= isl_multi_pw_aff_zero(space
);
190 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
194 space
= isl_space_set_alloc(ctx
, 1, 0);
195 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
196 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
197 dom
= isl_set_universe(isl_space_params(isl_space_copy(space
)));
198 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
199 mpa
= isl_multi_pw_aff_zero(space
);
200 mpa
= isl_multi_pw_aff_intersect_domain(mpa
, dom
);
201 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
205 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
206 pma
= isl_pw_multi_aff_from_map(map
);
207 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma
);
208 if (check_reparse_multi_pw_aff(ctx
, mpa
) < 0)
211 for (i
= 0; i
< ARRAY_SIZE(parse_multi_mpa_tests
); ++i
) {
214 str
= parse_multi_mpa_tests
[i
];
215 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
216 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
226 #define BASE multi_union_pw_aff
228 #include "check_reparse_templ.c"
230 /* String descriptions of multi union piecewise affine expressions
231 * that are used for testing printing and parsing.
233 const char *parse_multi_mupa_tests
[] = {
237 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
239 "[N] -> (A[] : { })",
240 "[N] -> (A[] : { : N >= 0 })",
241 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
242 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
243 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
244 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
245 "{ S[x] : x > 0; T[y] : y >= 0 })",
248 /* Test parsing of multi union piecewise affine expressions by printing
249 * the expressions and checking that parsing the output results
250 * in the same expression.
251 * Do this for a couple of manually constructed expressions and
252 * a set of expressions parsed from strings.
254 static int test_parse_mupa(isl_ctx
*ctx
)
258 isl_multi_union_pw_aff
*mupa
;
263 space
= isl_space_set_alloc(ctx
, 0, 0);
264 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
265 mupa
= isl_multi_union_pw_aff_zero(space
);
266 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
270 space
= isl_space_set_alloc(ctx
, 1, 0);
271 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
272 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
273 dom
= isl_set_universe(space
);
274 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
275 uset
= isl_union_set_from_set(dom
);
276 space
= isl_space_set_alloc(ctx
, 1, 0);
277 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
278 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "B");
279 mupa
= isl_multi_union_pw_aff_zero(space
);
280 mupa
= isl_multi_union_pw_aff_intersect_domain(mupa
, uset
);
281 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
285 for (i
= 0; i
< ARRAY_SIZE(parse_multi_mupa_tests
); ++i
) {
288 str
= parse_multi_mupa_tests
[i
];
289 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
290 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
298 /* Test parsing of multi expressions.
300 static int test_parse_multi(isl_ctx
*ctx
)
302 if (test_parse_mpa(ctx
) < 0)
304 if (test_parse_mupa(ctx
) < 0)
310 /* Pairs of binary relation representations that should represent
311 * the same binary relations.
316 } parse_map_equal_tests
[] = {
317 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
318 "{ [x, y] : 2y >= 6 - x }" },
319 { "{ [x,y] : x <= min(y, 2*y+3) }",
320 "{ [x,y] : x <= y, 2*y + 3 }" },
321 { "{ [x,y] : x >= min(y, 2*y+3) }",
322 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
323 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
324 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
325 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
326 "{ [i,j] -> [min(i,j)] }" },
327 { "{ [i,j] : i != j }",
328 "{ [i,j] : i < j or i > j }" },
329 { "{ [i,j] : (i+1)*2 >= j }",
330 "{ [i, j] : j <= 2 + 2i }" },
331 { "{ [i] -> [i > 0 ? 4 : 5] }",
332 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
333 { "[N=2,M] -> { [i=[(M+N)/4]] }",
334 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
335 { "{ [x] : x >= 0 }",
336 "{ [x] : x-0 >= 0 }" },
337 { "{ [i] : ((i > 10)) }",
338 "{ [i] : i >= 11 }" },
340 "{ [i] -> [0 * i] }" },
341 { "{ [a] -> [b] : (not false) }",
342 "{ [a] -> [b] : true }" },
343 { "{ [i] : i/2 <= 5 }",
344 "{ [i] : i <= 10 }" },
345 { "{Sym=[n] [i] : i <= n }",
346 "[n] -> { [i] : i <= n }" },
349 { "{ [i] : 2*floor(i/2) = i }",
350 "{ [i] : exists a : i = 2 a }" },
351 { "{ [a] -> [b] : a = 5 implies b = 5 }",
352 "{ [a] -> [b] : a != 5 or b = 5 }" },
353 { "{ [a] -> [a - 1 : a > 0] }",
354 "{ [a] -> [a - 1] : a > 0 }" },
355 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
356 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
357 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
358 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
359 { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
360 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
361 { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
362 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
363 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
364 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
365 { "{ [a,b] -> [i,j] : a,b << i,j }",
366 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
367 { "{ [a,b] -> [i,j] : a,b <<= i,j }",
368 "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" },
369 { "{ [a,b] -> [i,j] : a,b >> i,j }",
370 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
371 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
372 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
373 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
374 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
375 "8c < n - 32a and i < n and c >= 0 and "
376 "c <= 3 and c >= -4a) }",
377 "{ [n] -> [i] : 0 <= i < n }" },
378 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
379 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
380 "{ [x] -> [] : 0 <= x <= 15 }" },
381 { "{ [x] -> [x] : }",
383 { "{ [x=4:5] -> [x + 1] }",
384 "{ [x] -> [x + 1] : 4 <= x <= 5 }" },
385 { "{ [x=4:5] -> [x + 1 : x + 1] }",
386 "{ [x=4:5] -> [x + 1] }" },
387 { "{ [x] -> [x - 1 : x + 1] }",
388 "{ [x] -> [y] : x - 1 <= y <= x + 1 }" },
391 int test_parse(struct isl_ctx
*ctx
)
395 const char *str
, *str2
;
397 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
399 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
401 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
403 if (test_parse_multi(ctx
) < 0)
405 if (test_parse_pma(ctx
) < 0)
408 str
= "{ [i] -> [-i] }";
409 map
= isl_map_read_from_str(ctx
, str
);
413 str
= "{ A[i] -> L[([i/3])] }";
414 map
= isl_map_read_from_str(ctx
, str
);
418 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
419 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
420 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
422 for (i
= 0; i
< ARRAY_SIZE(parse_map_equal_tests
); ++i
) {
423 str
= parse_map_equal_tests
[i
].map1
;
424 str2
= parse_map_equal_tests
[i
].map2
;
425 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
429 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
430 map
= isl_map_read_from_str(ctx
, str
);
431 str
= "{ [new, old] -> [o0, o1] : "
432 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
433 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
434 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
435 map2
= isl_map_read_from_str(ctx
, str
);
436 assert(isl_map_is_equal(map
, map2
));
440 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
441 map
= isl_map_read_from_str(ctx
, str
);
442 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
443 map2
= isl_map_read_from_str(ctx
, str
);
444 assert(isl_map_is_equal(map
, map2
));
448 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
449 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
450 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
451 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
452 test_parse_pwaff(ctx
, "{ [] -> [(100)] }");
457 static int test_read(isl_ctx
*ctx
)
461 isl_basic_set
*bset1
, *bset2
;
462 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
465 filename
= get_filename(ctx
, "set", "omega");
467 input
= fopen(filename
, "r");
470 bset1
= isl_basic_set_read_from_file(ctx
, input
);
471 bset2
= isl_basic_set_read_from_str(ctx
, str
);
473 equal
= isl_basic_set_is_equal(bset1
, bset2
);
475 isl_basic_set_free(bset1
);
476 isl_basic_set_free(bset2
);
484 isl_die(ctx
, isl_error_unknown
,
485 "read sets not equal", return -1);
490 static int test_bounded(isl_ctx
*ctx
)
495 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
496 bounded
= isl_set_is_bounded(set
);
502 isl_die(ctx
, isl_error_unknown
,
503 "set not considered bounded", return -1);
505 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
506 bounded
= isl_set_is_bounded(set
);
513 isl_die(ctx
, isl_error_unknown
,
514 "set considered bounded", return -1);
516 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
517 bounded
= isl_set_is_bounded(set
);
523 isl_die(ctx
, isl_error_unknown
,
524 "set considered bounded", return -1);
529 /* Construct the basic set { [i] : 5 <= i <= N } */
530 static int test_construction_1(isl_ctx
*ctx
)
537 dim
= isl_space_set_alloc(ctx
, 1, 1);
538 bset
= isl_basic_set_universe(isl_space_copy(dim
));
539 ls
= isl_local_space_from_space(dim
);
541 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
542 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
543 c
= isl_constraint_set_coefficient_si(c
, isl_dim_param
, 0, 1);
544 bset
= isl_basic_set_add_constraint(bset
, c
);
546 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
547 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
548 c
= isl_constraint_set_constant_si(c
, -5);
549 bset
= isl_basic_set_add_constraint(bset
, c
);
551 isl_local_space_free(ls
);
552 isl_basic_set_free(bset
);
557 /* Construct the basic set { [x] : -100 <= x <= 100 }
558 * using isl_basic_set_{lower,upper}_bound_val and
559 * check that it is equal the same basic set parsed from a string.
561 static int test_construction_2(isl_ctx
*ctx
)
566 isl_basic_set
*bset1
, *bset2
;
568 v
= isl_val_int_from_si(ctx
, 100);
569 space
= isl_space_set_alloc(ctx
, 0, 1);
570 bset1
= isl_basic_set_universe(space
);
571 bset1
= isl_basic_set_upper_bound_val(bset1
, isl_dim_set
, 0,
573 bset1
= isl_basic_set_lower_bound_val(bset1
, isl_dim_set
, 0,
575 bset2
= isl_basic_set_read_from_str(ctx
, "{ [x] : -100 <= x <= 100 }");
576 equal
= isl_basic_set_is_equal(bset1
, bset2
);
577 isl_basic_set_free(bset1
);
578 isl_basic_set_free(bset2
);
583 isl_die(ctx
, isl_error_unknown
,
584 "failed construction", return -1);
589 /* Basic tests for constructing basic sets.
591 static int test_construction(isl_ctx
*ctx
)
593 if (test_construction_1(ctx
) < 0)
595 if (test_construction_2(ctx
) < 0)
600 static int test_dim(isl_ctx
*ctx
)
603 isl_map
*map1
, *map2
;
606 map1
= isl_map_read_from_str(ctx
,
607 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
608 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
609 map2
= isl_map_read_from_str(ctx
,
610 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
611 equal
= isl_map_is_equal(map1
, map2
);
614 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
615 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
616 if (equal
>= 0 && equal
)
617 equal
= isl_map_is_equal(map1
, map2
);
625 isl_die(ctx
, isl_error_unknown
,
626 "unexpected result", return -1);
628 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
629 map1
= isl_map_read_from_str(ctx
, str
);
630 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
631 map2
= isl_map_read_from_str(ctx
, str
);
632 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
633 equal
= isl_map_is_equal(map1
, map2
);
640 isl_die(ctx
, isl_error_unknown
,
641 "unexpected result", return -1);
646 /* Check that "val" is equal to the value described by "str".
647 * If "str" is "NaN", then check for a NaN value explicitly.
649 static isl_stat
val_check_equal(__isl_keep isl_val
*val
, const char *str
)
656 return isl_stat_error
;
658 ctx
= isl_val_get_ctx(val
);
659 res
= isl_val_read_from_str(ctx
, str
);
660 is_nan
= isl_val_is_nan(res
);
664 ok
= isl_val_is_nan(val
);
666 ok
= isl_val_eq(val
, res
);
669 return isl_stat_error
;
671 isl_die(ctx
, isl_error_unknown
,
672 "unexpected result", return isl_stat_error
);
677 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
681 { &isl_val_neg
, "0", "0" },
682 { &isl_val_abs
, "0", "0" },
683 { &isl_val_pow2
, "0", "1" },
684 { &isl_val_floor
, "0", "0" },
685 { &isl_val_ceil
, "0", "0" },
686 { &isl_val_neg
, "1", "-1" },
687 { &isl_val_neg
, "-1", "1" },
688 { &isl_val_neg
, "1/2", "-1/2" },
689 { &isl_val_neg
, "-1/2", "1/2" },
690 { &isl_val_neg
, "infty", "-infty" },
691 { &isl_val_neg
, "-infty", "infty" },
692 { &isl_val_neg
, "NaN", "NaN" },
693 { &isl_val_abs
, "1", "1" },
694 { &isl_val_abs
, "-1", "1" },
695 { &isl_val_abs
, "1/2", "1/2" },
696 { &isl_val_abs
, "-1/2", "1/2" },
697 { &isl_val_abs
, "infty", "infty" },
698 { &isl_val_abs
, "-infty", "infty" },
699 { &isl_val_abs
, "NaN", "NaN" },
700 { &isl_val_floor
, "1", "1" },
701 { &isl_val_floor
, "-1", "-1" },
702 { &isl_val_floor
, "1/2", "0" },
703 { &isl_val_floor
, "-1/2", "-1" },
704 { &isl_val_floor
, "infty", "infty" },
705 { &isl_val_floor
, "-infty", "-infty" },
706 { &isl_val_floor
, "NaN", "NaN" },
707 { &isl_val_ceil
, "1", "1" },
708 { &isl_val_ceil
, "-1", "-1" },
709 { &isl_val_ceil
, "1/2", "1" },
710 { &isl_val_ceil
, "-1/2", "0" },
711 { &isl_val_ceil
, "infty", "infty" },
712 { &isl_val_ceil
, "-infty", "-infty" },
713 { &isl_val_ceil
, "NaN", "NaN" },
714 { &isl_val_pow2
, "-3", "1/8" },
715 { &isl_val_pow2
, "-1", "1/2" },
716 { &isl_val_pow2
, "1", "2" },
717 { &isl_val_pow2
, "2", "4" },
718 { &isl_val_pow2
, "3", "8" },
719 { &isl_val_inv
, "1", "1" },
720 { &isl_val_inv
, "2", "1/2" },
721 { &isl_val_inv
, "1/2", "2" },
722 { &isl_val_inv
, "-2", "-1/2" },
723 { &isl_val_inv
, "-1/2", "-2" },
724 { &isl_val_inv
, "0", "NaN" },
725 { &isl_val_inv
, "NaN", "NaN" },
726 { &isl_val_inv
, "infty", "0" },
727 { &isl_val_inv
, "-infty", "0" },
730 /* Perform some basic tests of unary operations on isl_val objects.
732 static int test_un_val(isl_ctx
*ctx
)
736 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
738 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
741 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
742 fn
= val_un_tests
[i
].op
;
744 r
= val_check_equal(v
, val_un_tests
[i
].res
);
754 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
755 __isl_take isl_val
*v2
);
757 ['+'] = { &isl_val_add
},
758 ['-'] = { &isl_val_sub
},
759 ['*'] = { &isl_val_mul
},
760 ['/'] = { &isl_val_div
},
761 ['g'] = { &isl_val_gcd
},
762 ['m'] = { &isl_val_min
},
763 ['M'] = { &isl_val_max
},
771 } val_bin_tests
[] = {
772 { "0", '+', "0", "0" },
773 { "1", '+', "0", "1" },
774 { "1", '+', "1", "2" },
775 { "1", '-', "1", "0" },
776 { "1", '*', "1", "1" },
777 { "1", '/', "1", "1" },
778 { "2", '*', "3", "6" },
779 { "2", '*', "1/2", "1" },
780 { "2", '*', "1/3", "2/3" },
781 { "2/3", '*', "3/5", "2/5" },
782 { "2/3", '*', "7/5", "14/15" },
783 { "2", '/', "1/2", "4" },
784 { "-2", '/', "-1/2", "4" },
785 { "-2", '/', "1/2", "-4" },
786 { "2", '/', "-1/2", "-4" },
787 { "2", '/', "2", "1" },
788 { "2", '/', "3", "2/3" },
789 { "2/3", '/', "5/3", "2/5" },
790 { "2/3", '/', "5/7", "14/15" },
791 { "0", '/', "0", "NaN" },
792 { "42", '/', "0", "NaN" },
793 { "-42", '/', "0", "NaN" },
794 { "infty", '/', "0", "NaN" },
795 { "-infty", '/', "0", "NaN" },
796 { "NaN", '/', "0", "NaN" },
797 { "0", '/', "NaN", "NaN" },
798 { "42", '/', "NaN", "NaN" },
799 { "-42", '/', "NaN", "NaN" },
800 { "infty", '/', "NaN", "NaN" },
801 { "-infty", '/', "NaN", "NaN" },
802 { "NaN", '/', "NaN", "NaN" },
803 { "0", '/', "infty", "0" },
804 { "42", '/', "infty", "0" },
805 { "-42", '/', "infty", "0" },
806 { "infty", '/', "infty", "NaN" },
807 { "-infty", '/', "infty", "NaN" },
808 { "NaN", '/', "infty", "NaN" },
809 { "0", '/', "-infty", "0" },
810 { "42", '/', "-infty", "0" },
811 { "-42", '/', "-infty", "0" },
812 { "infty", '/', "-infty", "NaN" },
813 { "-infty", '/', "-infty", "NaN" },
814 { "NaN", '/', "-infty", "NaN" },
815 { "1", '-', "1/3", "2/3" },
816 { "1/3", '+', "1/2", "5/6" },
817 { "1/2", '+', "1/2", "1" },
818 { "3/4", '-', "1/4", "1/2" },
819 { "1/2", '-', "1/3", "1/6" },
820 { "infty", '+', "42", "infty" },
821 { "infty", '+', "infty", "infty" },
822 { "42", '+', "infty", "infty" },
823 { "infty", '-', "infty", "NaN" },
824 { "infty", '*', "infty", "infty" },
825 { "infty", '*', "-infty", "-infty" },
826 { "-infty", '*', "infty", "-infty" },
827 { "-infty", '*', "-infty", "infty" },
828 { "0", '*', "infty", "NaN" },
829 { "1", '*', "infty", "infty" },
830 { "infty", '*', "0", "NaN" },
831 { "infty", '*', "42", "infty" },
832 { "42", '-', "infty", "-infty" },
833 { "infty", '+', "-infty", "NaN" },
834 { "4", 'g', "6", "2" },
835 { "5", 'g', "6", "1" },
836 { "42", 'm', "3", "3" },
837 { "42", 'M', "3", "42" },
838 { "3", 'm', "42", "3" },
839 { "3", 'M', "42", "42" },
840 { "42", 'm', "infty", "42" },
841 { "42", 'M', "infty", "infty" },
842 { "42", 'm', "-infty", "-infty" },
843 { "42", 'M', "-infty", "42" },
844 { "42", 'm', "NaN", "NaN" },
845 { "42", 'M', "NaN", "NaN" },
846 { "infty", 'm', "-infty", "-infty" },
847 { "infty", 'M', "-infty", "infty" },
850 /* Perform some basic tests of binary operations on isl_val objects.
852 static int test_bin_val(isl_ctx
*ctx
)
855 isl_val
*v1
, *v2
, *res
;
856 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
857 __isl_take isl_val
*v2
);
860 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
861 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
862 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
863 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
864 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
866 if (isl_val_is_nan(res
))
867 ok
= isl_val_is_nan(v1
);
869 ok
= isl_val_eq(v1
, res
);
875 isl_die(ctx
, isl_error_unknown
,
876 "unexpected result", return -1);
882 /* Perform some basic tests on isl_val objects.
884 static int test_val(isl_ctx
*ctx
)
886 if (test_un_val(ctx
) < 0)
888 if (test_bin_val(ctx
) < 0)
893 /* Sets described using existentially quantified variables that
894 * can also be described without.
896 static const char *elimination_tests
[] = {
897 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
898 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
899 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
902 /* Check that redundant existentially quantified variables are
905 static int test_elimination(isl_ctx
*ctx
)
911 for (i
= 0; i
< ARRAY_SIZE(elimination_tests
); ++i
) {
912 bset
= isl_basic_set_read_from_str(ctx
, elimination_tests
[i
]);
913 n
= isl_basic_set_dim(bset
, isl_dim_div
);
914 isl_basic_set_free(bset
);
918 isl_die(ctx
, isl_error_unknown
,
919 "expecting no existentials", return -1);
925 static int test_div(isl_ctx
*ctx
)
932 struct isl_basic_set
*bset
;
933 struct isl_constraint
*c
;
936 dim
= isl_space_set_alloc(ctx
, 0, 3);
937 bset
= isl_basic_set_universe(isl_space_copy(dim
));
938 ls
= isl_local_space_from_space(dim
);
940 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
941 c
= isl_constraint_set_constant_si(c
, -1);
942 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
943 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
944 bset
= isl_basic_set_add_constraint(bset
, c
);
946 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
947 c
= isl_constraint_set_constant_si(c
, 1);
948 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
949 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
950 bset
= isl_basic_set_add_constraint(bset
, c
);
952 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
954 assert(bset
&& bset
->n_div
== 1);
955 isl_local_space_free(ls
);
956 isl_basic_set_free(bset
);
959 dim
= isl_space_set_alloc(ctx
, 0, 3);
960 bset
= isl_basic_set_universe(isl_space_copy(dim
));
961 ls
= isl_local_space_from_space(dim
);
963 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
964 c
= isl_constraint_set_constant_si(c
, 1);
965 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
966 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
967 bset
= isl_basic_set_add_constraint(bset
, c
);
969 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
970 c
= isl_constraint_set_constant_si(c
, -1);
971 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
972 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
973 bset
= isl_basic_set_add_constraint(bset
, c
);
975 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
977 assert(bset
&& bset
->n_div
== 1);
978 isl_local_space_free(ls
);
979 isl_basic_set_free(bset
);
982 dim
= isl_space_set_alloc(ctx
, 0, 3);
983 bset
= isl_basic_set_universe(isl_space_copy(dim
));
984 ls
= isl_local_space_from_space(dim
);
986 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
987 c
= isl_constraint_set_constant_si(c
, 1);
988 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
989 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
990 bset
= isl_basic_set_add_constraint(bset
, c
);
992 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
993 c
= isl_constraint_set_constant_si(c
, -3);
994 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
995 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 4);
996 bset
= isl_basic_set_add_constraint(bset
, c
);
998 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1000 assert(bset
&& bset
->n_div
== 1);
1001 isl_local_space_free(ls
);
1002 isl_basic_set_free(bset
);
1005 dim
= isl_space_set_alloc(ctx
, 0, 3);
1006 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1007 ls
= isl_local_space_from_space(dim
);
1009 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1010 c
= isl_constraint_set_constant_si(c
, 2);
1011 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1012 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1013 bset
= isl_basic_set_add_constraint(bset
, c
);
1015 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1016 c
= isl_constraint_set_constant_si(c
, -1);
1017 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1018 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1019 bset
= isl_basic_set_add_constraint(bset
, c
);
1021 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1023 assert(isl_basic_set_is_empty(bset
));
1024 isl_local_space_free(ls
);
1025 isl_basic_set_free(bset
);
1028 dim
= isl_space_set_alloc(ctx
, 0, 3);
1029 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1030 ls
= isl_local_space_from_space(dim
);
1032 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1033 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1034 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1035 bset
= isl_basic_set_add_constraint(bset
, c
);
1037 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1038 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1039 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1040 bset
= isl_basic_set_add_constraint(bset
, c
);
1042 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1044 assert(bset
&& bset
->n_div
== 0);
1045 isl_basic_set_free(bset
);
1046 isl_local_space_free(ls
);
1049 dim
= isl_space_set_alloc(ctx
, 0, 3);
1050 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1051 ls
= isl_local_space_from_space(dim
);
1053 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1054 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1055 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1056 bset
= isl_basic_set_add_constraint(bset
, c
);
1058 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1059 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1060 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1061 bset
= isl_basic_set_add_constraint(bset
, c
);
1063 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1065 assert(bset
&& bset
->n_div
== 1);
1066 isl_basic_set_free(bset
);
1067 isl_local_space_free(ls
);
1070 /* This test is a bit tricky. We set up an equality
1071 * a + 3b + 3c = 6 e0
1072 * Normalization of divs creates _two_ divs
1075 * Afterwards e0 is removed again because it has coefficient -1
1076 * and we end up with the original equality and div again.
1077 * Perhaps we can avoid the introduction of this temporary div.
1079 dim
= isl_space_set_alloc(ctx
, 0, 4);
1080 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1081 ls
= isl_local_space_from_space(dim
);
1083 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1084 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1085 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1086 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -3);
1087 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 6);
1088 bset
= isl_basic_set_add_constraint(bset
, c
);
1090 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
1092 /* Test disabled for now */
1094 assert(bset && bset->n_div == 1);
1096 isl_local_space_free(ls
);
1097 isl_basic_set_free(bset
);
1100 dim
= isl_space_set_alloc(ctx
, 0, 5);
1101 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1102 ls
= isl_local_space_from_space(dim
);
1104 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1105 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1106 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1107 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, -3);
1108 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 4, 6);
1109 bset
= isl_basic_set_add_constraint(bset
, c
);
1111 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1112 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1113 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 1);
1114 c
= isl_constraint_set_constant_si(c
, 1);
1115 bset
= isl_basic_set_add_constraint(bset
, c
);
1117 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
1119 /* Test disabled for now */
1121 assert(bset && bset->n_div == 1);
1123 isl_local_space_free(ls
);
1124 isl_basic_set_free(bset
);
1127 dim
= isl_space_set_alloc(ctx
, 0, 4);
1128 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1129 ls
= isl_local_space_from_space(dim
);
1131 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1132 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1133 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -1);
1134 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1135 bset
= isl_basic_set_add_constraint(bset
, c
);
1137 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1138 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1139 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 3);
1140 c
= isl_constraint_set_constant_si(c
, 2);
1141 bset
= isl_basic_set_add_constraint(bset
, c
);
1143 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
1145 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1147 assert(!isl_basic_set_is_empty(bset
));
1149 isl_local_space_free(ls
);
1150 isl_basic_set_free(bset
);
1153 dim
= isl_space_set_alloc(ctx
, 0, 3);
1154 bset
= isl_basic_set_universe(isl_space_copy(dim
));
1155 ls
= isl_local_space_from_space(dim
);
1157 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1158 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1159 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1160 bset
= isl_basic_set_add_constraint(bset
, c
);
1162 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1164 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1166 isl_local_space_free(ls
);
1167 isl_basic_set_free(bset
);
1169 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1170 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1171 set
= isl_set_read_from_str(ctx
, str
);
1172 set
= isl_set_compute_divs(set
);
1177 if (test_elimination(ctx
) < 0)
1180 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1181 set
= isl_set_read_from_str(ctx
, str
);
1182 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
1183 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
1184 empty
= isl_set_is_empty(set
);
1189 isl_die(ctx
, isl_error_unknown
,
1190 "result not as accurate as expected", return -1);
1195 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
1199 struct isl_basic_set
*bset1
, *bset2
;
1200 struct isl_basic_map
*bmap
;
1202 filename
= get_filename(ctx
, name
, "omega");
1204 input
= fopen(filename
, "r");
1207 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1208 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1210 bset1
= isl_basic_set_apply(bset1
, bmap
);
1212 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1214 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1216 isl_basic_set_free(bset1
);
1217 isl_basic_set_free(bset2
);
1223 static int test_application(isl_ctx
*ctx
)
1225 test_application_case(ctx
, "application");
1226 test_application_case(ctx
, "application2");
1231 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1235 struct isl_basic_set
*bset1
, *bset2
;
1237 filename
= get_filename(ctx
, name
, "polylib");
1239 input
= fopen(filename
, "r");
1242 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1243 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1245 bset1
= isl_basic_set_affine_hull(bset1
);
1247 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1249 isl_basic_set_free(bset1
);
1250 isl_basic_set_free(bset2
);
1256 int test_affine_hull(struct isl_ctx
*ctx
)
1260 isl_basic_set
*bset
, *bset2
;
1264 test_affine_hull_case(ctx
, "affine2");
1265 test_affine_hull_case(ctx
, "affine");
1266 test_affine_hull_case(ctx
, "affine3");
1268 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1269 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1270 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1271 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1272 set
= isl_set_read_from_str(ctx
, str
);
1273 bset
= isl_set_affine_hull(set
);
1274 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1275 isl_basic_set_free(bset
);
1279 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1282 /* Check that isl_map_affine_hull is not confused by
1283 * the reordering of divs in isl_map_align_divs.
1285 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1286 "32e0 = b and 32e1 = c); "
1287 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1288 set
= isl_set_read_from_str(ctx
, str
);
1289 bset
= isl_set_affine_hull(set
);
1290 isl_basic_set_free(bset
);
1294 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1295 "32e2 = 31 + 31e0 }";
1296 set
= isl_set_read_from_str(ctx
, str
);
1297 bset
= isl_set_affine_hull(set
);
1298 str
= "{ [a] : exists e : a = 32 e }";
1299 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1300 subset
= isl_basic_set_is_subset(bset
, bset2
);
1301 isl_basic_set_free(bset
);
1302 isl_basic_set_free(bset2
);
1306 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1312 /* Pairs of maps and the corresponding expected results of
1313 * isl_map_plain_unshifted_simple_hull.
1318 } plain_unshifted_simple_hull_tests
[] = {
1319 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1320 "{ [i] -> [j] : i >= 1 }" },
1321 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1322 "(j mod 4 = 2 and k mod 6 = n) }",
1323 "{ [n] -> [i,j,k] : j mod 4 = 2 }" },
1326 /* Basic tests for isl_map_plain_unshifted_simple_hull.
1328 static int test_plain_unshifted_simple_hull(isl_ctx
*ctx
)
1332 isl_basic_map
*hull
, *expected
;
1335 for (i
= 0; i
< ARRAY_SIZE(plain_unshifted_simple_hull_tests
); ++i
) {
1337 str
= plain_unshifted_simple_hull_tests
[i
].map
;
1338 map
= isl_map_read_from_str(ctx
, str
);
1339 str
= plain_unshifted_simple_hull_tests
[i
].hull
;
1340 expected
= isl_basic_map_read_from_str(ctx
, str
);
1341 hull
= isl_map_plain_unshifted_simple_hull(map
);
1342 equal
= isl_basic_map_is_equal(hull
, expected
);
1343 isl_basic_map_free(hull
);
1344 isl_basic_map_free(expected
);
1348 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1355 /* Pairs of sets and the corresponding expected results of
1356 * isl_set_unshifted_simple_hull.
1361 } unshifted_simple_hull_tests
[] = {
1362 { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1363 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1366 /* Basic tests for isl_set_unshifted_simple_hull.
1368 static int test_unshifted_simple_hull(isl_ctx
*ctx
)
1372 isl_basic_set
*hull
, *expected
;
1375 for (i
= 0; i
< ARRAY_SIZE(unshifted_simple_hull_tests
); ++i
) {
1377 str
= unshifted_simple_hull_tests
[i
].set
;
1378 set
= isl_set_read_from_str(ctx
, str
);
1379 str
= unshifted_simple_hull_tests
[i
].hull
;
1380 expected
= isl_basic_set_read_from_str(ctx
, str
);
1381 hull
= isl_set_unshifted_simple_hull(set
);
1382 equal
= isl_basic_set_is_equal(hull
, expected
);
1383 isl_basic_set_free(hull
);
1384 isl_basic_set_free(expected
);
1388 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1395 static int test_simple_hull(struct isl_ctx
*ctx
)
1399 isl_basic_set
*bset
;
1402 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1403 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1404 set
= isl_set_read_from_str(ctx
, str
);
1405 bset
= isl_set_simple_hull(set
);
1406 is_empty
= isl_basic_set_is_empty(bset
);
1407 isl_basic_set_free(bset
);
1409 if (is_empty
== isl_bool_error
)
1412 if (is_empty
== isl_bool_false
)
1413 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1416 if (test_plain_unshifted_simple_hull(ctx
) < 0)
1418 if (test_unshifted_simple_hull(ctx
) < 0)
1424 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1428 struct isl_basic_set
*bset1
, *bset2
;
1429 struct isl_set
*set
;
1431 filename
= get_filename(ctx
, name
, "polylib");
1433 input
= fopen(filename
, "r");
1436 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1437 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1439 set
= isl_basic_set_union(bset1
, bset2
);
1440 bset1
= isl_set_convex_hull(set
);
1442 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1444 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1446 isl_basic_set_free(bset1
);
1447 isl_basic_set_free(bset2
);
1456 } convex_hull_tests
[] = {
1457 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1458 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1459 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1460 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1461 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1462 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1463 "i2 <= 5 and i2 >= 4; "
1464 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1465 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1466 "i2 <= 5 + i0 and i2 >= i0 }" },
1467 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1468 "{ [x, y] : 1 = 0 }" },
1469 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1470 "[x, y, 0] : x >= 0 and y < 0 }",
1471 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1472 { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and "
1474 "[0, 2, 0]; [3, 1, 0] }",
1475 "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and "
1476 "5c <= 6 - a - 3b }" },
1479 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1482 int orig_convex
= ctx
->opt
->convex
;
1483 ctx
->opt
->convex
= convex
;
1485 test_convex_hull_case(ctx
, "convex0");
1486 test_convex_hull_case(ctx
, "convex1");
1487 test_convex_hull_case(ctx
, "convex2");
1488 test_convex_hull_case(ctx
, "convex3");
1489 test_convex_hull_case(ctx
, "convex4");
1490 test_convex_hull_case(ctx
, "convex5");
1491 test_convex_hull_case(ctx
, "convex6");
1492 test_convex_hull_case(ctx
, "convex7");
1493 test_convex_hull_case(ctx
, "convex8");
1494 test_convex_hull_case(ctx
, "convex9");
1495 test_convex_hull_case(ctx
, "convex10");
1496 test_convex_hull_case(ctx
, "convex11");
1497 test_convex_hull_case(ctx
, "convex12");
1498 test_convex_hull_case(ctx
, "convex13");
1499 test_convex_hull_case(ctx
, "convex14");
1500 test_convex_hull_case(ctx
, "convex15");
1502 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1503 isl_set
*set1
, *set2
;
1506 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1507 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1508 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1509 equal
= isl_set_is_equal(set1
, set2
);
1516 isl_die(ctx
, isl_error_unknown
,
1517 "unexpected convex hull", return -1);
1520 ctx
->opt
->convex
= orig_convex
;
1525 static int test_convex_hull(isl_ctx
*ctx
)
1527 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1529 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1534 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1538 struct isl_basic_set
*bset1
, *bset2
;
1540 filename
= get_filename(ctx
, name
, "polylib");
1542 input
= fopen(filename
, "r");
1545 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1546 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1548 bset1
= isl_basic_set_gist(bset1
, bset2
);
1550 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1552 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1554 isl_basic_set_free(bset1
);
1555 isl_basic_set_free(bset2
);
1561 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1565 const char *context
;
1567 } plain_gist_tests
[] = {
1568 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1569 "{ [i] -> [j] : i >= 1 }",
1570 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1571 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1572 "(j mod 4 = 2 and k mod 6 = n) }",
1573 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1574 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1575 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1576 "{ [i] -> [j] : i > j }",
1577 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1580 /* Basic tests for isl_map_plain_gist_basic_map.
1582 static int test_plain_gist(isl_ctx
*ctx
)
1586 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1589 isl_map
*map
, *gist
;
1590 isl_basic_map
*context
;
1592 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1593 str
= plain_gist_tests
[i
].context
;
1594 context
= isl_basic_map_read_from_str(ctx
, str
);
1595 map
= isl_map_plain_gist_basic_map(map
, context
);
1596 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1597 equal
= isl_map_is_equal(map
, gist
);
1603 isl_die(ctx
, isl_error_unknown
,
1604 "incorrect gist result", return -1);
1610 /* Inputs for isl_basic_set_gist tests that are expected to fail.
1614 const char *context
;
1615 } gist_fail_tests
[] = {
1616 { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1617 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1618 "{ [i] : i >= 0 }" },
1621 /* Check that isl_basic_set_gist fails (gracefully) when expected.
1622 * In particular, the user should be able to recover from the failure.
1624 static isl_stat
test_gist_fail(struct isl_ctx
*ctx
)
1629 on_error
= isl_options_get_on_error(ctx
);
1630 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
1631 n
= ARRAY_SIZE(gist_fail_tests
);
1632 for (i
= 0; i
< n
; ++i
) {
1634 isl_basic_set
*bset
, *context
;
1636 bset
= isl_basic_set_read_from_str(ctx
, gist_fail_tests
[i
].set
);
1637 str
= gist_fail_tests
[i
].context
;
1638 context
= isl_basic_set_read_from_str(ctx
, str
);
1639 bset
= isl_basic_set_gist(bset
, context
);
1640 isl_basic_set_free(bset
);
1644 isl_options_set_on_error(ctx
, on_error
);
1646 isl_die(ctx
, isl_error_unknown
,
1647 "operation not expected to succeed",
1648 return isl_stat_error
);
1655 const char *context
;
1658 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1659 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1660 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1661 "{ [a, b, c] : a <= 15 }" },
1662 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1663 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1664 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1665 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1666 { "{ [m, n, a, b] : a <= 2147 + n }",
1667 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1668 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1669 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1671 "{ [m, n, ku, kl] }" },
1672 { "{ [a, a, b] : a >= 10 }",
1673 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1674 "{ [a, a, b] : a >= 10 }" },
1675 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1676 "{ [0, j] : j >= 0 }" },
1677 /* Check that no constraints on i6 are introduced in the gist */
1678 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1679 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1680 "5e0 <= 381 - t1 and i4 <= 1) }",
1681 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1682 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1683 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1684 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1685 "20e0 >= 1511 - 4t1 - 5i4) }" },
1686 /* Check that no constraints on i6 are introduced in the gist */
1687 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1688 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1689 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1690 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1691 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1692 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1693 "20e1 <= 1530 - 4t1 - 5i4 and "
1694 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1695 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1696 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1697 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1698 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1699 "10e0 <= -91 + 5i4 + 4i6 and "
1700 "10e0 >= -105 + 5i4 + 4i6) }",
1701 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1702 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1703 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1704 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1705 "{ [a, b, q, p] : b >= 1 + a }",
1706 "{ [a, b, q, p] : false }" },
1707 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1708 "[n] -> { [x] : x mod 32 = 0 }",
1709 "[n] -> { [x = n] }" },
1710 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1711 "{ [x] : x mod 2 = 0 }" },
1712 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1713 "{ [x] : x mod 128 = 0 }" },
1714 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1715 "{ [x] : x mod 3200 = 0 }" },
1716 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1717 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1718 "{ [a, b, c = a] }" },
1719 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1720 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1721 "{ [a, b, c = a] : a mod 3 = 0 }" },
1722 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1723 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1725 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1726 "{ [x,y] : 1 <= y <= 3 }",
1730 /* Check that isl_set_gist behaves as expected.
1732 * For the test cases in gist_tests, besides checking that the result
1733 * is as expected, also check that applying the gist operation does
1734 * not modify the input set (an earlier version of isl would do that) and
1735 * that the test case is consistent, i.e., that the gist has the same
1736 * intersection with the context as the input set.
1738 static int test_gist(struct isl_ctx
*ctx
)
1742 isl_basic_set
*bset1
, *bset2
;
1743 isl_map
*map1
, *map2
;
1747 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1748 isl_bool equal_input
, equal_intersection
;
1749 isl_set
*set1
, *set2
, *copy
, *context
;
1751 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1752 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1753 copy
= isl_set_copy(set1
);
1754 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1755 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1756 equal
= isl_set_is_equal(set1
, set2
);
1758 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1759 equal_input
= isl_set_is_equal(set1
, copy
);
1761 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1762 set2
= isl_set_intersect(set2
, context
);
1763 equal_intersection
= isl_set_is_equal(set1
, set2
);
1766 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1769 isl_die(ctx
, isl_error_unknown
,
1770 "incorrect gist result", return -1);
1772 isl_die(ctx
, isl_error_unknown
,
1773 "gist modified input", return -1);
1775 isl_die(ctx
, isl_error_unknown
,
1776 "inconsistent gist test case", return -1);
1779 if (test_gist_fail(ctx
) < 0)
1782 test_gist_case(ctx
, "gist1");
1784 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1785 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1786 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1787 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1788 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1789 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1790 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1791 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1792 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1793 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1794 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1795 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1796 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1797 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1798 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1799 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1800 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1801 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1802 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1803 bset1
= isl_basic_set_gist(bset1
, bset2
);
1804 assert(bset1
&& bset1
->n_div
== 0);
1805 isl_basic_set_free(bset1
);
1807 /* Check that the integer divisions of the second disjunct
1808 * do not spread to the first disjunct.
1810 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1811 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1812 "(exists (e0 = [(-1 + t1)/16], "
1813 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1814 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1815 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1816 "o0 <= 4294967295 and t1 <= -1)) }";
1817 map1
= isl_map_read_from_str(ctx
, str
);
1818 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1819 map2
= isl_map_read_from_str(ctx
, str
);
1820 map1
= isl_map_gist(map1
, map2
);
1824 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1825 isl_map_free(map1
); return -1);
1826 n_div
= isl_basic_map_dim(map1
->p
[0], isl_dim_div
);
1831 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1834 if (test_plain_gist(ctx
) < 0)
1840 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1842 isl_set
*set
, *set2
;
1846 set
= isl_set_read_from_str(ctx
, str
);
1847 set
= isl_set_coalesce(set
);
1848 set2
= isl_set_read_from_str(ctx
, str
);
1849 equal
= isl_set_is_equal(set
, set2
);
1850 one
= set
&& set
->n
== 1;
1857 isl_die(ctx
, isl_error_unknown
,
1858 "coalesced set not equal to input", return -1);
1859 if (check_one
&& !one
)
1860 isl_die(ctx
, isl_error_unknown
,
1861 "coalesced set should not be a union", return -1);
1866 /* Inputs for coalescing tests with unbounded wrapping.
1867 * "str" is a string representation of the input set.
1868 * "single_disjunct" is set if we expect the result to consist of
1869 * a single disjunct.
1872 int single_disjunct
;
1874 } coalesce_unbounded_tests
[] = {
1875 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1876 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1877 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1878 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1880 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1881 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1882 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1883 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1884 { 0, "{ [x, y, z] : 0 <= x,y,z <= 100 and 0 < z <= 2 + 2x + 2y; "
1885 "[x, y, 0] : x,y <= 100 and y <= 9 + 11x and x <= 9 + 11y }" },
1888 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1889 * option turned off.
1891 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1897 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1898 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1900 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
1901 const char *str
= coalesce_unbounded_tests
[i
].str
;
1902 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
1903 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
1909 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1914 /* Inputs for coalescing tests.
1915 * "str" is a string representation of the input set.
1916 * "single_disjunct" is set if we expect the result to consist of
1917 * a single disjunct.
1920 int single_disjunct
;
1922 } coalesce_tests
[] = {
1923 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1924 "y >= x & x >= 2 & 5 >= y }" },
1925 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1926 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1927 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1928 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1929 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1930 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1931 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1932 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1933 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1934 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1935 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1936 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1937 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1938 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1939 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1940 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1941 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1942 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1943 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1944 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1945 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1946 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1947 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1948 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1949 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1950 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1951 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1952 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1953 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1954 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1955 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1956 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1957 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1958 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1959 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1960 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1961 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1962 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1963 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1964 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1965 "[o0, o1, o2, o3, o4, o5, o6]] : "
1966 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1967 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1968 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1969 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1970 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1971 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1972 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1973 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1974 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1975 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1976 "o6 >= i3 + i6 - o3 and M >= 0 and "
1977 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1978 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1979 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1980 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1981 "(o0 = 0 and M >= 2 and N >= 3) or "
1982 "(M = 0 and o0 = 0 and N >= 3) }" },
1983 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1984 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1985 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1986 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1987 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1988 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1989 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1990 "(y = 3 and x = 1) }" },
1991 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1992 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1993 "i1 <= M and i3 <= M and i4 <= M) or "
1994 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1995 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1996 "i4 <= -1 + M) }" },
1997 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1998 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1999 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
2000 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
2001 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
2002 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
2003 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
2004 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
2005 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
2006 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
2007 { 0, "{ [a, b] : exists e : 2e = a and "
2008 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
2009 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
2010 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
2011 "j >= 1 and j' <= i + j - i' and i >= 1; "
2013 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
2014 "[i,j] : exists a : j = 3a }" },
2015 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
2016 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
2018 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
2019 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
2020 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
2021 "c <= 6 + 8a and a >= 3; "
2022 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
2023 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
2024 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2025 "[x,0] : 3 <= x <= 4 }" },
2026 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
2027 "[x,0] : 4 <= x <= 5 }" },
2028 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2029 "[x,0] : 3 <= x <= 5 }" },
2030 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
2031 "[x,0] : 3 <= x <= 4 }" },
2032 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
2034 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
2035 { 1, "{ [0,0]; [1,1] }" },
2036 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
2037 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
2039 "[k, 0, k] : k <= 6 and k >= 1 }" },
2040 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
2041 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
2042 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
2043 { 1, "[n] -> { [1] : n >= 0;"
2044 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
2045 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
2046 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
2047 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
2048 "2e0 <= x and 2e0 <= n);"
2049 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
2051 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
2052 "128e0 >= -134 + 127t1 and t1 >= 2 and "
2053 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
2055 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
2056 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
2058 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
2059 "t1 >= 13 and t1 <= 16);"
2060 "[t1] : t1 <= 15 and t1 >= 12 }" },
2061 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2062 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2063 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2064 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2065 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2066 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2068 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2069 "(exists (e0 : 3e0 = -2 + c0)) }" },
2070 { 0, "[n, b0, t0] -> "
2071 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2072 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2073 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2074 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2075 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2076 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2077 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2078 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2079 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2080 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2081 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2082 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2083 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2084 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2085 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2086 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2087 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2088 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2089 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2090 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2091 { 0, "{ [i0, i1, i2] : "
2092 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2093 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2094 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2095 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2096 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2097 "32e0 <= 31 + i0)) or "
2099 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2100 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2101 "2*floor((c)/2) = c and 0 <= a <= 192;"
2102 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2104 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2105 "(0 <= a <= b <= n) }" },
2106 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2107 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2108 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2109 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2110 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2111 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2112 "b = 3 and 9e0 <= -19 + 2c)) }" },
2113 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2114 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2115 "(a = 4 and b = 3 and "
2116 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2117 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2118 "(b = -1 + a and 0 < a <= 3 and "
2119 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2120 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2121 "b = 3 and 9e0 <= -19 + 2c)) }" },
2122 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2124 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2126 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2127 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2128 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2129 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2130 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2131 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2132 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2133 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2134 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2135 { 1, "{ [a] : a <= 8 and "
2136 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2137 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2138 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2139 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2140 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2141 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2142 "(a < 0 and 3*floor((a)/3) < a) }" },
2143 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2144 "(a < -1 and 3*floor((a)/3) < a) }" },
2145 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2146 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2147 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2148 "or (2 <= a <= 15 and b < a)) }" },
2149 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2150 "32*floor((a)/32) < a) or a <= 15) }" },
2151 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2152 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2153 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2154 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2155 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2156 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2157 "S_0[n] : n <= m <= 2 + n }" },
2158 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2159 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2161 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2162 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2163 "2e0 < -a + 2b) }" },
2164 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2165 "[i, 0, i] : 0 <= i <= 7 }" },
2166 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2167 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2168 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2169 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2170 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2171 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2172 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2173 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2174 "a > 0 and a <= 5) }" },
2175 { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" },
2176 { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and "
2177 "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; "
2178 "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" },
2181 /* A specialized coalescing test case that would result
2182 * in a segmentation fault or a failed assertion in earlier versions of isl.
2184 static int test_coalesce_special(struct isl_ctx
*ctx
)
2187 isl_map
*map1
, *map2
;
2189 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2190 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2191 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2192 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2193 "o1 <= 239 and o1 >= 212)) or "
2194 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2195 "o1 <= 241 and o1 >= 240));"
2196 "[S_L220_OUT[] -> T7[]] -> "
2197 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2198 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2199 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2200 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2201 map1
= isl_map_read_from_str(ctx
, str
);
2202 map1
= isl_map_align_divs_internal(map1
);
2203 map1
= isl_map_coalesce(map1
);
2204 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2205 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2206 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2207 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2208 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2209 map2
= isl_map_read_from_str(ctx
, str
);
2210 map2
= isl_map_union(map2
, map1
);
2211 map2
= isl_map_align_divs_internal(map2
);
2212 map2
= isl_map_coalesce(map2
);
2220 /* A specialized coalescing test case that would result in an assertion
2221 * in an earlier version of isl.
2222 * The explicit call to isl_basic_set_union prevents the implicit
2223 * equality constraints in the first basic map from being detected prior
2224 * to the call to isl_set_coalesce, at least at the point
2225 * where this test case was introduced.
2227 static int test_coalesce_special2(struct isl_ctx
*ctx
)
2230 isl_basic_set
*bset1
, *bset2
;
2233 str
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2234 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2235 str
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2236 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2237 set
= isl_basic_set_union(bset1
, bset2
);
2238 set
= isl_set_coalesce(set
);
2246 /* Check that calling isl_set_coalesce does not leave other sets
2247 * that may share some information with the input to isl_set_coalesce
2248 * in an inconsistent state.
2249 * In particular, older versions of isl would modify all copies
2250 * of the basic sets in the isl_set_coalesce input in a way
2251 * that could leave them in an inconsistent state.
2252 * The result of printing any other set containing one of these
2253 * basic sets would then result in an invalid set description.
2255 static int test_coalesce_special3(isl_ctx
*ctx
)
2259 isl_set
*set1
, *set2
;
2262 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2263 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2264 set2
= isl_set_read_from_str(ctx
, str
);
2265 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2266 set1
= isl_set_coalesce(set1
);
2269 p
= isl_printer_to_str(ctx
);
2270 p
= isl_printer_print_set(p
, set2
);
2272 s
= isl_printer_get_str(p
);
2273 isl_printer_free(p
);
2274 set1
= isl_set_read_from_str(ctx
, s
);
2284 /* Check that calling isl_set_coalesce on the intersection of
2285 * the sets described by "s1" and "s2" does not leave other sets
2286 * that may share some information with the input to isl_set_coalesce
2287 * in an inconsistent state.
2288 * In particular, when isl_set_coalesce detects equality constraints,
2289 * it does not immediately perform Gaussian elimination on them,
2290 * but then it needs to ensure that it is performed at some point.
2291 * The input set has implicit equality constraints in the first disjunct.
2292 * It is constructed as an intersection, because otherwise
2293 * those equality constraints would already be detected during parsing.
2295 static isl_stat
test_coalesce_intersection(isl_ctx
*ctx
,
2296 const char *s1
, const char *s2
)
2298 isl_set
*set1
, *set2
;
2300 set1
= isl_set_read_from_str(ctx
, s1
);
2301 set2
= isl_set_read_from_str(ctx
, s2
);
2302 set1
= isl_set_intersect(set1
, set2
);
2303 isl_set_free(isl_set_coalesce(isl_set_copy(set1
)));
2304 set1
= isl_set_coalesce(set1
);
2308 return isl_stat_error
;
2313 /* Check that calling isl_set_coalesce does not leave other sets
2314 * that may share some information with the input to isl_set_coalesce
2315 * in an inconsistent state, for the case where one disjunct
2316 * is a subset of the other.
2318 static isl_stat
test_coalesce_special4(isl_ctx
*ctx
)
2320 const char *s1
, *s2
;
2322 s1
= "{ [a, b] : b <= 0 or a <= 1 }";
2323 s2
= "{ [a, b] : -1 <= -a < b }";
2324 return test_coalesce_intersection(ctx
, s1
, s2
);
2327 /* Check that calling isl_set_coalesce does not leave other sets
2328 * that may share some information with the input to isl_set_coalesce
2329 * in an inconsistent state, for the case where two disjuncts
2332 static isl_stat
test_coalesce_special5(isl_ctx
*ctx
)
2334 const char *s1
, *s2
;
2336 s1
= "{ [a, b, c] : b <= 0 }";
2337 s2
= "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }";
2338 return test_coalesce_intersection(ctx
, s1
, s2
);
2341 /* Check that calling isl_set_coalesce does not leave other sets
2342 * that may share some information with the input to isl_set_coalesce
2343 * in an inconsistent state, for the case where two disjuncts
2344 * can be fused and where both disjuncts have implicit equality constraints.
2346 static isl_stat
test_coalesce_special6(isl_ctx
*ctx
)
2348 const char *s1
, *s2
;
2350 s1
= "{ [a, b, c] : c <= 0 }";
2351 s2
= "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }";
2352 return test_coalesce_intersection(ctx
, s1
, s2
);
2355 /* Test the functionality of isl_set_coalesce.
2356 * That is, check that the output is always equal to the input
2357 * and in some cases that the result consists of a single disjunct.
2359 static int test_coalesce(struct isl_ctx
*ctx
)
2363 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2364 const char *str
= coalesce_tests
[i
].str
;
2365 int check_one
= coalesce_tests
[i
].single_disjunct
;
2366 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2370 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2372 if (test_coalesce_special(ctx
) < 0)
2374 if (test_coalesce_special2(ctx
) < 0)
2376 if (test_coalesce_special3(ctx
) < 0)
2378 if (test_coalesce_special4(ctx
) < 0)
2380 if (test_coalesce_special5(ctx
) < 0)
2382 if (test_coalesce_special6(ctx
) < 0)
2389 /* Construct a representation of the graph on the right of Figure 1
2390 * in "Computing the Transitive Closure of a Union of
2391 * Affine Integer Tuple Relations".
2393 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2396 isl_map
*up
, *right
;
2398 dom
= isl_set_read_from_str(ctx
,
2399 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2400 "2 x - 3 y + 3 >= 0 }");
2401 right
= isl_map_read_from_str(ctx
,
2402 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2403 up
= isl_map_read_from_str(ctx
,
2404 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2405 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2406 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2407 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2408 up
= isl_map_intersect_range(up
, dom
);
2409 return isl_map_union(up
, right
);
2412 /* Construct a representation of the power of the graph
2413 * on the right of Figure 1 in "Computing the Transitive Closure of
2414 * a Union of Affine Integer Tuple Relations".
2416 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2418 return isl_map_read_from_str(ctx
,
2419 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2420 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2421 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2424 /* Construct a representation of the transitive closure of the graph
2425 * on the right of Figure 1 in "Computing the Transitive Closure of
2426 * a Union of Affine Integer Tuple Relations".
2428 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2430 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2433 static int test_closure(isl_ctx
*ctx
)
2436 isl_map
*map
, *map2
;
2437 isl_bool exact
, equal
;
2439 /* COCOA example 1 */
2440 map
= isl_map_read_from_str(ctx
,
2441 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2442 "1 <= i and i < n and 1 <= j and j < n or "
2443 "i2 = i + 1 and j2 = j - 1 and "
2444 "1 <= i and i < n and 2 <= j and j <= n }");
2445 map
= isl_map_power(map
, &exact
);
2449 /* COCOA example 1 */
2450 map
= isl_map_read_from_str(ctx
,
2451 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2452 "1 <= i and i < n and 1 <= j and j < n or "
2453 "i2 = i + 1 and j2 = j - 1 and "
2454 "1 <= i and i < n and 2 <= j and j <= n }");
2455 map
= isl_map_transitive_closure(map
, &exact
);
2457 map2
= isl_map_read_from_str(ctx
,
2458 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2459 "1 <= i and i < n and 1 <= j and j <= n and "
2460 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2461 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2462 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2463 assert(isl_map_is_equal(map
, map2
));
2467 map
= isl_map_read_from_str(ctx
,
2468 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2469 " 0 <= y and y <= n }");
2470 map
= isl_map_transitive_closure(map
, &exact
);
2471 map2
= isl_map_read_from_str(ctx
,
2472 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2473 " 0 <= y and y <= n }");
2474 assert(isl_map_is_equal(map
, map2
));
2478 /* COCOA example 2 */
2479 map
= isl_map_read_from_str(ctx
,
2480 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2481 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2482 "i2 = i + 2 and j2 = j - 2 and "
2483 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2484 map
= isl_map_transitive_closure(map
, &exact
);
2486 map2
= isl_map_read_from_str(ctx
,
2487 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2488 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2489 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2490 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2491 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2492 assert(isl_map_is_equal(map
, map2
));
2496 /* COCOA Fig.2 left */
2497 map
= isl_map_read_from_str(ctx
,
2498 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2499 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2501 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2502 "j <= 2 i - 3 and j <= n - 2 or "
2503 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2504 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2505 map
= isl_map_transitive_closure(map
, &exact
);
2509 /* COCOA Fig.2 right */
2510 map
= isl_map_read_from_str(ctx
,
2511 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2512 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2514 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2515 "j <= 2 i - 4 and j <= n - 3 or "
2516 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2517 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2518 map
= isl_map_power(map
, &exact
);
2522 /* COCOA Fig.2 right */
2523 map
= isl_map_read_from_str(ctx
,
2524 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2525 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2527 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2528 "j <= 2 i - 4 and j <= n - 3 or "
2529 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2530 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2531 map
= isl_map_transitive_closure(map
, &exact
);
2533 map2
= isl_map_read_from_str(ctx
,
2534 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2535 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2536 "j <= n and 3 + i + 2 j <= 3 n and "
2537 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2538 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2539 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2540 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2541 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2542 assert(isl_map_is_equal(map
, map2
));
2546 map
= cocoa_fig_1_right_graph(ctx
);
2547 map
= isl_map_transitive_closure(map
, &exact
);
2549 map2
= cocoa_fig_1_right_tc(ctx
);
2550 assert(isl_map_is_equal(map
, map2
));
2554 map
= cocoa_fig_1_right_graph(ctx
);
2555 map
= isl_map_power(map
, &exact
);
2556 map2
= cocoa_fig_1_right_power(ctx
);
2557 equal
= isl_map_is_equal(map
, map2
);
2563 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2565 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2567 /* COCOA Theorem 1 counter example */
2568 map
= isl_map_read_from_str(ctx
,
2569 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2570 "i2 = 1 and j2 = j or "
2571 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2572 map
= isl_map_transitive_closure(map
, &exact
);
2576 map
= isl_map_read_from_str(ctx
,
2577 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2578 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2579 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2580 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2581 map
= isl_map_transitive_closure(map
, &exact
);
2585 /* Kelly et al 1996, fig 12 */
2586 map
= isl_map_read_from_str(ctx
,
2587 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2588 "1 <= i,j,j+1 <= n or "
2589 "j = n and j2 = 1 and i2 = i + 1 and "
2590 "1 <= i,i+1 <= n }");
2591 map
= isl_map_transitive_closure(map
, &exact
);
2593 map2
= isl_map_read_from_str(ctx
,
2594 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2595 "1 <= i <= n and i = i2 or "
2596 "1 <= i < i2 <= n and 1 <= j <= n and "
2598 assert(isl_map_is_equal(map
, map2
));
2602 /* Omega's closure4 */
2603 map
= isl_map_read_from_str(ctx
,
2604 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2605 "1 <= x,y <= 10 or "
2606 "x2 = x + 1 and y2 = y and "
2607 "1 <= x <= 20 && 5 <= y <= 15 }");
2608 map
= isl_map_transitive_closure(map
, &exact
);
2612 map
= isl_map_read_from_str(ctx
,
2613 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2614 map
= isl_map_transitive_closure(map
, &exact
);
2616 map2
= isl_map_read_from_str(ctx
,
2617 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2618 assert(isl_map_is_equal(map
, map2
));
2622 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2623 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2624 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2625 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2626 map
= isl_map_read_from_str(ctx
, str
);
2627 map
= isl_map_transitive_closure(map
, &exact
);
2629 map2
= isl_map_read_from_str(ctx
, str
);
2630 assert(isl_map_is_equal(map
, map2
));
2634 str
= "{[0] -> [1]; [2] -> [3]}";
2635 map
= isl_map_read_from_str(ctx
, str
);
2636 map
= isl_map_transitive_closure(map
, &exact
);
2638 map2
= isl_map_read_from_str(ctx
, str
);
2639 assert(isl_map_is_equal(map
, map2
));
2643 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2644 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2645 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2646 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2647 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2648 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2649 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2650 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2651 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2652 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2653 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2654 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2655 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2656 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2657 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2658 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2659 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2660 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2661 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2662 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2663 map
= isl_map_read_from_str(ctx
, str
);
2664 map
= isl_map_transitive_closure(map
, NULL
);
2671 /* Check that the actual result of a boolean operation is equal
2672 * to the expected result.
2674 static isl_stat
check_bool(isl_ctx
*ctx
, isl_bool actual
, isl_bool expected
)
2676 if (actual
!= expected
)
2677 isl_die(ctx
, isl_error_unknown
,
2678 "incorrect boolean operation", return isl_stat_error
);
2682 /* Test operations on isl_bool values.
2689 static int test_isl_bool(isl_ctx
*ctx
)
2691 if (check_bool(ctx
, isl_bool_not(isl_bool_true
), isl_bool_false
) < 0)
2693 if (check_bool(ctx
, isl_bool_not(isl_bool_false
), isl_bool_true
) < 0)
2695 if (check_bool(ctx
, isl_bool_not(isl_bool_error
), isl_bool_error
) < 0)
2697 if (check_bool(ctx
, isl_bool_ok(0), isl_bool_false
) < 0)
2699 if (check_bool(ctx
, isl_bool_ok(1), isl_bool_true
) < 0)
2701 if (check_bool(ctx
, isl_bool_ok(-1), isl_bool_true
) < 0)
2703 if (check_bool(ctx
, isl_bool_ok(2), isl_bool_true
) < 0)
2705 if (check_bool(ctx
, isl_bool_ok(-2), isl_bool_true
) < 0)
2711 static int test_lex(struct isl_ctx
*ctx
)
2717 dim
= isl_space_set_alloc(ctx
, 0, 0);
2718 map
= isl_map_lex_le(dim
);
2719 empty
= isl_map_is_empty(map
);
2725 isl_die(ctx
, isl_error_unknown
,
2726 "expecting non-empty result", return -1);
2731 /* Inputs for isl_map_lexmin tests.
2732 * "map" is the input and "lexmin" is the expected result.
2737 } lexmin_tests
[] = {
2738 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2739 "{ [x] -> [5] : 6 <= x <= 8; "
2740 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2741 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2742 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2743 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2744 "{ [x] -> [y] : (4y = x and x >= 0) or "
2745 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2746 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2747 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2748 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2749 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2750 /* Check that empty pieces are properly combined. */
2751 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2752 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2753 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2754 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2755 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2757 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2758 "a <= 255 and c <= 255 and d <= 255 - j and "
2759 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2760 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2761 "247d <= 247 + i and 248 - b <= 248d <= c and "
2762 "254d >= i - a + b and 254d >= -a + b and "
2763 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2765 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2766 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2767 "247j >= 62738 - i and 509j <= 129795 + i and "
2768 "742j >= 188724 - i; "
2769 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2770 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2771 "16*floor((8 + b)/16) <= 7 + b; "
2773 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2774 "[a] -> [b = 0] : 0 < a <= 509 }" },
2775 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2776 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2779 static int test_lexmin(struct isl_ctx
*ctx
)
2784 isl_basic_map
*bmap
;
2785 isl_map
*map
, *map2
;
2788 isl_pw_multi_aff
*pma
;
2790 str
= "[p0, p1] -> { [] -> [] : "
2791 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2792 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2793 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2794 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2795 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2796 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2797 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2798 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2799 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2800 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2801 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2802 map
= isl_map_read_from_str(ctx
, str
);
2803 map
= isl_map_lexmin(map
);
2806 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2807 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2808 set
= isl_set_read_from_str(ctx
, str
);
2809 set
= isl_set_lexmax(set
);
2810 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
2811 set2
= isl_set_read_from_str(ctx
, str
);
2812 set
= isl_set_intersect(set
, set2
);
2813 assert(!isl_set_is_empty(set
));
2816 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
2817 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
2818 map
= isl_map_lexmin(map
);
2819 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
2820 equal
= isl_map_is_equal(map
, map2
);
2827 isl_die(ctx
, isl_error_unknown
,
2828 "unexpected result", return -1);
2831 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2832 " 8i' <= i and 8i' >= -7 + i }";
2833 bmap
= isl_basic_map_read_from_str(ctx
, str
);
2834 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
2835 map2
= isl_map_from_pw_multi_aff(pma
);
2836 map
= isl_map_from_basic_map(bmap
);
2837 assert(isl_map_is_equal(map
, map2
));
2841 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2842 " 8i' <= i and 8i' >= -7 + i }";
2843 set
= isl_set_read_from_str(ctx
, str
);
2844 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
2845 set2
= isl_set_from_pw_multi_aff(pma
);
2846 equal
= isl_set_is_equal(set
, set2
);
2852 isl_die(ctx
, isl_error_unknown
,
2853 "unexpected difference between set and "
2854 "piecewise affine expression", return -1);
2859 /* A specialized isl_set_min_val test case that would return the wrong result
2860 * in earlier versions of isl.
2861 * The explicit call to isl_basic_set_union prevents the second basic set
2862 * from being determined to be empty prior to the call to isl_set_min_val,
2863 * at least at the point where this test case was introduced.
2865 static int test_min_special(isl_ctx
*ctx
)
2868 isl_basic_set
*bset1
, *bset2
;
2874 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
2875 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2876 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
2877 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2878 set
= isl_basic_set_union(bset1
, bset2
);
2879 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
2881 res
= isl_set_min_val(set
, obj
);
2882 ok
= isl_val_cmp_si(res
, 5) == 0;
2891 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
2897 /* A specialized isl_set_min_val test case that would return an error
2898 * in earlier versions of isl.
2900 static int test_min_special2(isl_ctx
*ctx
)
2903 isl_basic_set
*bset
;
2907 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
2908 bset
= isl_basic_set_read_from_str(ctx
, str
);
2910 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
2912 res
= isl_basic_set_max_val(bset
, obj
);
2914 isl_basic_set_free(bset
);
2927 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
2928 __isl_keep isl_aff
*obj
);
2931 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
2932 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
2933 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
2934 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
2935 &isl_set_max_val
, "30" },
2939 /* Perform basic isl_set_min_val and isl_set_max_val tests.
2940 * In particular, check the results on non-convex inputs.
2942 static int test_min(struct isl_ctx
*ctx
)
2950 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
2951 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
2952 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
2953 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
2954 val
= opt_tests
[i
].fn(set
, obj
);
2955 ok
= isl_val_eq(res
, val
);
2964 isl_die(ctx
, isl_error_unknown
,
2965 "unexpected optimum", return -1);
2968 if (test_min_special(ctx
) < 0)
2970 if (test_min_special2(ctx
) < 0)
2981 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
2982 void *dep_user
, void *user
)
2984 struct must_may
*mm
= (struct must_may
*)user
;
2987 mm
->must
= isl_map_union(mm
->must
, dep
);
2989 mm
->may
= isl_map_union(mm
->may
, dep
);
2994 static int common_space(void *first
, void *second
)
2996 int depth
= *(int *)first
;
3000 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
3008 map2
= isl_map_read_from_str(map
->ctx
, str
);
3009 equal
= isl_map_is_equal(map
, map2
);
3015 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
3019 equal
= map_is_equal(map
, str
);
3023 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
3024 "result not as expected", return -1);
3028 /* Is "set" equal to the set described by "str"?
3030 static isl_bool
set_is_equal(__isl_keep isl_set
*set
, const char *str
)
3036 return isl_bool_error
;
3038 set2
= isl_set_read_from_str(isl_set_get_ctx(set
), str
);
3039 equal
= isl_set_is_equal(set
, set2
);
3045 /* Check that "set" is equal to the set described by "str".
3047 static isl_stat
set_check_equal(__isl_keep isl_set
*set
, const char *str
)
3051 equal
= set_is_equal(set
, str
);
3053 return isl_stat_error
;
3055 isl_die(isl_set_get_ctx(set
), isl_error_unknown
,
3056 "result not as expected", return isl_stat_error
);
3060 /* Is "uset" equal to the union set described by "str"?
3062 static isl_bool
uset_is_equal(__isl_keep isl_union_set
*uset
, const char *str
)
3064 isl_union_set
*uset2
;
3068 return isl_bool_error
;
3070 uset2
= isl_union_set_read_from_str(isl_union_set_get_ctx(uset
), str
);
3071 equal
= isl_union_set_is_equal(uset
, uset2
);
3072 isl_union_set_free(uset2
);
3077 /* Check that "uset" is equal to the union set described by "str".
3079 static isl_stat
uset_check_equal(__isl_keep isl_union_set
*uset
,
3084 equal
= uset_is_equal(uset
, str
);
3086 return isl_stat_error
;
3088 isl_die(isl_union_set_get_ctx(uset
), isl_error_unknown
,
3089 "result not as expected", return isl_stat_error
);
3093 static int test_dep(struct isl_ctx
*ctx
)
3098 isl_access_info
*ai
;
3105 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3106 map
= isl_map_read_from_str(ctx
, str
);
3107 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3109 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3110 map
= isl_map_read_from_str(ctx
, str
);
3111 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3113 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3114 map
= isl_map_read_from_str(ctx
, str
);
3115 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3117 flow
= isl_access_info_compute_flow(ai
);
3118 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3119 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3120 mm
.may
= isl_map_empty(dim
);
3122 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3124 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
3125 " [1,10,0] -> [2,5,0] }";
3126 assert(map_is_equal(mm
.must
, str
));
3127 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3128 assert(map_is_equal(mm
.may
, str
));
3130 isl_map_free(mm
.must
);
3131 isl_map_free(mm
.may
);
3132 isl_flow_free(flow
);
3135 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3136 map
= isl_map_read_from_str(ctx
, str
);
3137 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3139 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3140 map
= isl_map_read_from_str(ctx
, str
);
3141 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3143 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3144 map
= isl_map_read_from_str(ctx
, str
);
3145 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3147 flow
= isl_access_info_compute_flow(ai
);
3148 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3149 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3150 mm
.may
= isl_map_empty(dim
);
3152 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3154 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
3155 assert(map_is_equal(mm
.must
, str
));
3156 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3157 assert(map_is_equal(mm
.may
, str
));
3159 isl_map_free(mm
.must
);
3160 isl_map_free(mm
.may
);
3161 isl_flow_free(flow
);
3164 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3165 map
= isl_map_read_from_str(ctx
, str
);
3166 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3168 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3169 map
= isl_map_read_from_str(ctx
, str
);
3170 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3172 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3173 map
= isl_map_read_from_str(ctx
, str
);
3174 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3176 flow
= isl_access_info_compute_flow(ai
);
3177 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3178 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3179 mm
.may
= isl_map_empty(dim
);
3181 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3183 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
3184 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3185 assert(map_is_equal(mm
.may
, str
));
3186 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3187 assert(map_is_equal(mm
.must
, str
));
3189 isl_map_free(mm
.must
);
3190 isl_map_free(mm
.may
);
3191 isl_flow_free(flow
);
3194 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
3195 map
= isl_map_read_from_str(ctx
, str
);
3196 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3198 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3199 map
= isl_map_read_from_str(ctx
, str
);
3200 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3202 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3203 map
= isl_map_read_from_str(ctx
, str
);
3204 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3206 flow
= isl_access_info_compute_flow(ai
);
3207 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3208 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3209 mm
.may
= isl_map_empty(dim
);
3211 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3213 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3214 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3215 assert(map_is_equal(mm
.may
, str
));
3216 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3217 assert(map_is_equal(mm
.must
, str
));
3219 isl_map_free(mm
.must
);
3220 isl_map_free(mm
.may
);
3221 isl_flow_free(flow
);
3224 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3225 map
= isl_map_read_from_str(ctx
, str
);
3226 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3228 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3229 map
= isl_map_read_from_str(ctx
, str
);
3230 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3232 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3233 map
= isl_map_read_from_str(ctx
, str
);
3234 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3236 flow
= isl_access_info_compute_flow(ai
);
3237 dim
= isl_space_alloc(ctx
, 0, 3, 3);
3238 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3239 mm
.may
= isl_map_empty(dim
);
3241 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3243 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3244 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3245 assert(map_is_equal(mm
.may
, str
));
3246 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3247 assert(map_is_equal(mm
.must
, str
));
3249 isl_map_free(mm
.must
);
3250 isl_map_free(mm
.may
);
3251 isl_flow_free(flow
);
3256 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3257 map
= isl_map_read_from_str(ctx
, str
);
3258 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
3260 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3261 map
= isl_map_read_from_str(ctx
, str
);
3262 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3264 flow
= isl_access_info_compute_flow(ai
);
3265 dim
= isl_space_alloc(ctx
, 0, 5, 5);
3266 mm
.must
= isl_map_empty(isl_space_copy(dim
));
3267 mm
.may
= isl_map_empty(dim
);
3269 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3271 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3272 assert(map_is_equal(mm
.must
, str
));
3273 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3274 assert(map_is_equal(mm
.may
, str
));
3276 isl_map_free(mm
.must
);
3277 isl_map_free(mm
.may
);
3278 isl_flow_free(flow
);
3283 /* Check that the dependence analysis proceeds without errors.
3284 * Earlier versions of isl would break down during the analysis
3285 * due to the use of the wrong spaces.
3287 static int test_flow(isl_ctx
*ctx
)
3290 isl_union_map
*access
, *schedule
;
3291 isl_union_map
*must_dep
, *may_dep
;
3294 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3295 access
= isl_union_map_read_from_str(ctx
, str
);
3296 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3297 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3298 "S2[] -> [1,0,0,0]; "
3299 "S3[] -> [-1,0,0,0] }";
3300 schedule
= isl_union_map_read_from_str(ctx
, str
);
3301 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
3302 isl_union_map_copy(access
), schedule
,
3303 &must_dep
, &may_dep
, NULL
, NULL
);
3304 isl_union_map_free(may_dep
);
3305 isl_union_map_free(must_dep
);
3314 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3315 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3316 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3317 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3318 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3319 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3320 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3321 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3322 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3325 int test_sv(isl_ctx
*ctx
)
3327 isl_union_map
*umap
;
3331 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
3332 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
3333 sv
= isl_union_map_is_single_valued(umap
);
3334 isl_union_map_free(umap
);
3337 if (sv_tests
[i
].sv
&& !sv
)
3338 isl_die(ctx
, isl_error_internal
,
3339 "map not detected as single valued", return -1);
3340 if (!sv_tests
[i
].sv
&& sv
)
3341 isl_die(ctx
, isl_error_internal
,
3342 "map detected as single valued", return -1);
3351 } bijective_tests
[] = {
3352 { "[N,M]->{[i,j] -> [i]}", 0 },
3353 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3354 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3355 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3356 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3357 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3358 { "[N,M]->{[i,j] -> []}", 0 },
3359 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3360 { "[N,M]->{[i,j] -> [2i]}", 0 },
3361 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3362 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3363 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3364 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3367 static int test_bijective(struct isl_ctx
*ctx
)
3373 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
3374 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
3375 bijective
= isl_map_is_bijective(map
);
3379 if (bijective_tests
[i
].bijective
&& !bijective
)
3380 isl_die(ctx
, isl_error_internal
,
3381 "map not detected as bijective", return -1);
3382 if (!bijective_tests
[i
].bijective
&& bijective
)
3383 isl_die(ctx
, isl_error_internal
,
3384 "map detected as bijective", return -1);
3390 /* Inputs for isl_pw_qpolynomial_gist tests.
3391 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3397 } pwqp_gist_tests
[] = {
3398 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3399 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3400 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3401 "{ [i] -> -1/2 + 1/2 * i }" },
3402 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3405 static int test_pwqp(struct isl_ctx
*ctx
)
3410 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3413 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3414 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3416 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3419 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3420 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3422 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3424 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3426 isl_pw_qpolynomial_free(pwqp1
);
3428 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3429 str
= pwqp_gist_tests
[i
].pwqp
;
3430 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3431 str
= pwqp_gist_tests
[i
].set
;
3432 set
= isl_set_read_from_str(ctx
, str
);
3433 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3434 str
= pwqp_gist_tests
[i
].gist
;
3435 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3436 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3437 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3438 isl_pw_qpolynomial_free(pwqp1
);
3443 isl_die(ctx
, isl_error_unknown
,
3444 "unexpected result", return -1);
3447 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3448 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3449 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3450 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3452 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3454 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3456 isl_pw_qpolynomial_free(pwqp1
);
3458 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3459 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3460 str
= "{ [x] -> x }";
3461 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3463 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3465 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3467 isl_pw_qpolynomial_free(pwqp1
);
3469 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3470 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3471 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3472 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3473 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3474 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3475 isl_pw_qpolynomial_free(pwqp1
);
3477 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3478 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3479 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3480 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3481 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3482 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3483 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3484 isl_pw_qpolynomial_free(pwqp1
);
3485 isl_pw_qpolynomial_free(pwqp2
);
3489 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3491 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3492 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3493 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3494 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3495 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3497 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3498 isl_pw_qpolynomial_free(pwqp1
);
3499 isl_pw_qpolynomial_free(pwqp2
);
3503 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3508 static int test_split_periods(isl_ctx
*ctx
)
3511 isl_pw_qpolynomial
*pwqp
;
3513 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3514 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3515 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3516 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3518 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3520 isl_pw_qpolynomial_free(pwqp
);
3528 static int test_union(isl_ctx
*ctx
)
3531 isl_union_set
*uset1
, *uset2
;
3532 isl_union_map
*umap1
, *umap2
;
3535 str
= "{ [i] : 0 <= i <= 1 }";
3536 uset1
= isl_union_set_read_from_str(ctx
, str
);
3537 str
= "{ [1] -> [0] }";
3538 umap1
= isl_union_map_read_from_str(ctx
, str
);
3540 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3541 equal
= isl_union_map_is_equal(umap1
, umap2
);
3543 isl_union_map_free(umap1
);
3544 isl_union_map_free(umap2
);
3549 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3552 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3553 umap1
= isl_union_map_read_from_str(ctx
, str
);
3554 str
= "{ A[i]; B[i] }";
3555 uset1
= isl_union_set_read_from_str(ctx
, str
);
3557 uset2
= isl_union_map_domain(umap1
);
3559 equal
= isl_union_set_is_equal(uset1
, uset2
);
3561 isl_union_set_free(uset1
);
3562 isl_union_set_free(uset2
);
3567 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3573 /* Check that computing a bound of a non-zero polynomial over an unbounded
3574 * domain does not produce a rational value.
3575 * In particular, check that the upper bound is infinity.
3577 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
3580 isl_pw_qpolynomial
*pwqp
;
3581 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
3584 str
= "{ [m,n] -> -m * n }";
3585 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3586 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3588 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3589 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3590 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
3591 isl_pw_qpolynomial_fold_free(pwf
);
3592 isl_pw_qpolynomial_fold_free(pwf2
);
3597 isl_die(ctx
, isl_error_unknown
,
3598 "expecting infinite polynomial bound", return -1);
3603 static int test_bound(isl_ctx
*ctx
)
3607 isl_pw_qpolynomial
*pwqp
;
3608 isl_pw_qpolynomial_fold
*pwf
;
3610 if (test_bound_unbounded_domain(ctx
) < 0)
3613 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
3614 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3615 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3616 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3617 isl_pw_qpolynomial_fold_free(pwf
);
3621 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3624 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3625 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3626 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3627 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3628 isl_pw_qpolynomial_fold_free(pwf
);
3632 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3638 /* isl_set is defined to isl_map internally, so the corresponding elements
3639 * are isl_basic_map objects.
3643 #define EL_BASE basic_map
3644 #define SET_BASE set
3645 #include "isl_test_list_templ.c"
3649 #define EL_BASE basic_set
3650 #define SET_BASE union_set
3651 #include "isl_test_list_templ.c"
3656 #define SET_BASE union_set
3657 #include "isl_test_list_templ.c"
3661 #define EL_BASE basic_map
3662 #define SET_BASE map
3663 #include "isl_test_list_templ.c"
3668 #define SET_BASE union_map
3669 #include "isl_test_list_templ.c"
3671 /* Check that the conversion from isl objects to lists works as expected.
3673 static int test_get_list(isl_ctx
*ctx
)
3675 if (test_get_list_basic_map_from_set(ctx
, "{ [0]; [2]; [3] }"))
3677 if (test_get_list_basic_set_from_union_set(ctx
, "{ A[0]; B[2]; B[3] }"))
3679 if (test_get_list_set_from_union_set(ctx
, "{ A[0]; A[2]; B[3] }"))
3681 if (test_get_list_basic_map_from_map(ctx
,
3682 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"))
3684 if (test_get_list_map_from_union_map(ctx
,
3685 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"))
3691 static int test_lift(isl_ctx
*ctx
)
3694 isl_basic_map
*bmap
;
3695 isl_basic_set
*bset
;
3697 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
3698 bset
= isl_basic_set_read_from_str(ctx
, str
);
3699 bset
= isl_basic_set_lift(bset
);
3700 bmap
= isl_basic_map_from_range(bset
);
3701 bset
= isl_basic_map_domain(bmap
);
3702 isl_basic_set_free(bset
);
3707 /* Check that isl_set_is_subset is not confused by identical
3708 * integer divisions.
3709 * The call to isl_set_normalize ensures that the equality constraints
3710 * a = b = 0 are discovered, turning e0 and e1 into identical
3711 * integer divisions. Any further simplification would remove
3712 * the duplicate integer divisions.
3714 static isl_stat
test_subset_duplicate_integer_divisions(isl_ctx
*ctx
)
3718 isl_set
*set1
, *set2
;
3720 str
= "{ [a, b, c, d] : "
3721 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
3722 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
3723 "e3 = floor((-d + 4*floor((d)/4))/10): "
3724 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
3725 "b >= 0 and a <= 0 and b <= a) }";
3726 set1
= isl_set_read_from_str(ctx
, str
);
3727 set2
= isl_set_read_from_str(ctx
, str
);
3728 set2
= isl_set_normalize(set2
);
3730 is_subset
= isl_set_is_subset(set1
, set2
);
3736 return isl_stat_error
;
3738 isl_die(ctx
, isl_error_unknown
,
3739 "set is not considered to be a subset of itself",
3740 return isl_stat_error
);
3749 } subset_tests
[] = {
3751 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3752 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3753 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3755 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3756 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3757 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3758 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3759 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3760 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3761 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3762 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3763 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3764 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3765 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3766 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3767 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3768 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3769 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3770 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3771 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3772 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3773 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3774 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3775 "4e0 <= -57 + i0 + i1)) or "
3776 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3777 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3778 "4e0 >= -61 + i0 + i1)) or "
3779 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3780 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3783 static int test_subset(isl_ctx
*ctx
)
3786 isl_set
*set1
, *set2
;
3789 if (test_subset_duplicate_integer_divisions(ctx
) < 0)
3792 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
3793 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
3794 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
3795 subset
= isl_set_is_subset(set1
, set2
);
3800 if (subset
!= subset_tests
[i
].subset
)
3801 isl_die(ctx
, isl_error_unknown
,
3802 "incorrect subset result", return -1);
3809 const char *minuend
;
3810 const char *subtrahend
;
3811 const char *difference
;
3812 } subtract_domain_tests
[] = {
3813 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
3814 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
3815 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
3818 static int test_subtract(isl_ctx
*ctx
)
3821 isl_union_map
*umap1
, *umap2
;
3822 isl_union_pw_multi_aff
*upma1
, *upma2
;
3823 isl_union_set
*uset
;
3826 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3827 umap1
= isl_union_map_read_from_str(ctx
,
3828 subtract_domain_tests
[i
].minuend
);
3829 uset
= isl_union_set_read_from_str(ctx
,
3830 subtract_domain_tests
[i
].subtrahend
);
3831 umap2
= isl_union_map_read_from_str(ctx
,
3832 subtract_domain_tests
[i
].difference
);
3833 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
3834 equal
= isl_union_map_is_equal(umap1
, umap2
);
3835 isl_union_map_free(umap1
);
3836 isl_union_map_free(umap2
);
3840 isl_die(ctx
, isl_error_unknown
,
3841 "incorrect subtract domain result", return -1);
3844 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3845 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3846 subtract_domain_tests
[i
].minuend
);
3847 uset
= isl_union_set_read_from_str(ctx
,
3848 subtract_domain_tests
[i
].subtrahend
);
3849 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3850 subtract_domain_tests
[i
].difference
);
3851 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
3852 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
3853 isl_union_pw_multi_aff_free(upma1
);
3854 isl_union_pw_multi_aff_free(upma2
);
3858 isl_die(ctx
, isl_error_unknown
,
3859 "incorrect subtract domain result", return -1);
3865 /* Check that intersecting the empty basic set with another basic set
3866 * does not increase the number of constraints. In particular,
3867 * the empty basic set should maintain its canonical representation.
3869 static int test_intersect_1(isl_ctx
*ctx
)
3872 isl_basic_set
*bset1
, *bset2
;
3874 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
3875 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
3876 n1
= isl_basic_set_n_constraint(bset1
);
3877 bset1
= isl_basic_set_intersect(bset1
, bset2
);
3878 n2
= isl_basic_set_n_constraint(bset1
);
3879 isl_basic_set_free(bset1
);
3880 if (n1
< 0 || n2
< 0)
3883 isl_die(ctx
, isl_error_unknown
,
3884 "number of constraints of empty set changed",
3890 /* Check that intersecting a set with itself does not cause
3891 * an explosion in the number of disjuncts.
3893 static isl_stat
test_intersect_2(isl_ctx
*ctx
)
3898 set
= isl_set_read_from_str(ctx
, "{ [x,y] : x >= 0 or y >= 0 }");
3899 for (i
= 0; i
< 100; ++i
)
3900 set
= isl_set_intersect(set
, isl_set_copy(set
));
3903 return isl_stat_error
;
3907 /* Perform some intersection tests.
3909 static int test_intersect(isl_ctx
*ctx
)
3911 if (test_intersect_1(ctx
) < 0)
3913 if (test_intersect_2(ctx
) < 0)
3919 int test_factorize(isl_ctx
*ctx
)
3922 isl_basic_set
*bset
;
3925 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
3926 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
3927 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
3928 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
3929 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
3930 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
3931 "3i5 >= -2i0 - i2 + 3i4 }";
3932 bset
= isl_basic_set_read_from_str(ctx
, str
);
3933 f
= isl_basic_set_factorizer(bset
);
3934 isl_basic_set_free(bset
);
3935 isl_factorizer_free(f
);
3937 isl_die(ctx
, isl_error_unknown
,
3938 "failed to construct factorizer", return -1);
3940 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
3941 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
3942 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
3943 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
3944 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
3945 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
3946 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
3947 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
3948 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
3949 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
3950 bset
= isl_basic_set_read_from_str(ctx
, str
);
3951 f
= isl_basic_set_factorizer(bset
);
3952 isl_basic_set_free(bset
);
3953 isl_factorizer_free(f
);
3955 isl_die(ctx
, isl_error_unknown
,
3956 "failed to construct factorizer", return -1);
3961 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
3963 int *injective
= user
;
3965 *injective
= isl_map_is_injective(map
);
3968 if (*injective
< 0 || !*injective
)
3969 return isl_stat_error
;
3974 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
3975 const char *r
, const char *s
, int tilable
, int parallel
)
3979 isl_union_map
*W
, *R
, *S
;
3980 isl_union_map
*empty
;
3981 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
3982 isl_union_map
*validity
, *proximity
, *coincidence
;
3983 isl_union_map
*schedule
;
3984 isl_union_map
*test
;
3985 isl_union_set
*delta
;
3986 isl_union_set
*domain
;
3990 isl_schedule_constraints
*sc
;
3991 isl_schedule
*sched
;
3992 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
3995 D
= isl_union_set_read_from_str(ctx
, d
);
3996 W
= isl_union_map_read_from_str(ctx
, w
);
3997 R
= isl_union_map_read_from_str(ctx
, r
);
3998 S
= isl_union_map_read_from_str(ctx
, s
);
4000 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
4001 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
4003 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
4004 isl_union_map_compute_flow(isl_union_map_copy(R
),
4005 isl_union_map_copy(W
), empty
,
4006 isl_union_map_copy(S
),
4007 &dep_raw
, NULL
, NULL
, NULL
);
4008 isl_union_map_compute_flow(isl_union_map_copy(W
),
4009 isl_union_map_copy(W
),
4010 isl_union_map_copy(R
),
4011 isl_union_map_copy(S
),
4012 &dep_waw
, &dep_war
, NULL
, NULL
);
4014 dep
= isl_union_map_union(dep_waw
, dep_war
);
4015 dep
= isl_union_map_union(dep
, dep_raw
);
4016 validity
= isl_union_map_copy(dep
);
4017 coincidence
= isl_union_map_copy(dep
);
4018 proximity
= isl_union_map_copy(dep
);
4020 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
4021 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4022 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
4023 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4024 sched
= isl_schedule_constraints_compute_schedule(sc
);
4025 schedule
= isl_schedule_get_map(sched
);
4026 isl_schedule_free(sched
);
4027 isl_union_map_free(W
);
4028 isl_union_map_free(R
);
4029 isl_union_map_free(S
);
4032 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
4034 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
4035 is_complete
= isl_union_set_is_subset(D
, domain
);
4036 isl_union_set_free(D
);
4037 isl_union_set_free(domain
);
4039 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
4040 test
= isl_union_map_apply_range(test
, dep
);
4041 test
= isl_union_map_apply_range(test
, schedule
);
4043 delta
= isl_union_map_deltas(test
);
4044 n
= isl_union_set_n_set(delta
);
4046 isl_union_set_free(delta
);
4053 isl_union_set_free(delta
);
4057 delta_set
= isl_set_from_union_set(delta
);
4059 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4060 for (i
= 0; i
< tilable
; ++i
)
4061 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
4062 is_tilable
= isl_set_is_subset(delta_set
, slice
);
4063 isl_set_free(slice
);
4065 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4066 for (i
= 0; i
< parallel
; ++i
)
4067 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
4068 is_parallel
= isl_set_is_subset(delta_set
, slice
);
4069 isl_set_free(slice
);
4071 origin
= isl_set_universe(isl_set_get_space(delta_set
));
4072 dim
= isl_set_dim(origin
, isl_dim_set
);
4074 origin
= isl_set_free(origin
);
4075 for (i
= 0; i
< dim
; ++i
)
4076 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
4078 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
4079 delta_set
= isl_set_lexmin(delta_set
);
4081 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
4083 isl_set_free(origin
);
4084 isl_set_free(delta_set
);
4087 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
4088 is_injection
< 0 || is_complete
< 0)
4091 isl_die(ctx
, isl_error_unknown
,
4092 "generated schedule incomplete", return -1);
4094 isl_die(ctx
, isl_error_unknown
,
4095 "generated schedule not injective on each statement",
4098 isl_die(ctx
, isl_error_unknown
,
4099 "negative dependences in generated schedule",
4102 isl_die(ctx
, isl_error_unknown
,
4103 "generated schedule not as tilable as expected",
4106 isl_die(ctx
, isl_error_unknown
,
4107 "generated schedule not as parallel as expected",
4113 /* Compute a schedule for the given instance set, validity constraints,
4114 * proximity constraints and context and return a corresponding union map
4117 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
4118 const char *domain
, const char *validity
, const char *proximity
,
4119 const char *context
)
4124 isl_union_map
*prox
;
4125 isl_schedule_constraints
*sc
;
4126 isl_schedule
*schedule
;
4127 isl_union_map
*sched
;
4129 con
= isl_set_read_from_str(ctx
, context
);
4130 dom
= isl_union_set_read_from_str(ctx
, domain
);
4131 dep
= isl_union_map_read_from_str(ctx
, validity
);
4132 prox
= isl_union_map_read_from_str(ctx
, proximity
);
4133 sc
= isl_schedule_constraints_on_domain(dom
);
4134 sc
= isl_schedule_constraints_set_context(sc
, con
);
4135 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
4136 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
4137 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4138 sched
= isl_schedule_get_map(schedule
);
4139 isl_schedule_free(schedule
);
4144 /* Compute a schedule for the given instance set, validity constraints and
4145 * proximity constraints and return a corresponding union map representation.
4147 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
4148 const char *domain
, const char *validity
, const char *proximity
)
4150 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
4154 /* Check that a schedule can be constructed on the given domain
4155 * with the given validity and proximity constraints.
4157 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
4158 const char *validity
, const char *proximity
)
4160 isl_union_map
*sched
;
4162 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
4166 isl_union_map_free(sched
);
4170 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
4171 const char *validity
, const char *proximity
, const char *expected_sched
)
4173 isl_union_map
*sched1
, *sched2
;
4176 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
4177 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
4179 equal
= isl_union_map_is_equal(sched1
, sched2
);
4180 isl_union_map_free(sched1
);
4181 isl_union_map_free(sched2
);
4186 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
4192 /* Check that the schedule map is properly padded, i.e., that the range
4193 * lives in a single space.
4195 static int test_padded_schedule(isl_ctx
*ctx
)
4199 isl_union_map
*validity
, *proximity
;
4200 isl_schedule_constraints
*sc
;
4201 isl_schedule
*sched
;
4202 isl_union_map
*umap
;
4203 isl_union_set
*range
;
4206 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4207 D
= isl_union_set_read_from_str(ctx
, str
);
4208 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
4209 proximity
= isl_union_map_copy(validity
);
4210 sc
= isl_schedule_constraints_on_domain(D
);
4211 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4212 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4213 sched
= isl_schedule_constraints_compute_schedule(sc
);
4214 umap
= isl_schedule_get_map(sched
);
4215 isl_schedule_free(sched
);
4216 range
= isl_union_map_range(umap
);
4217 set
= isl_set_from_union_set(range
);
4226 /* Check that conditional validity constraints are also taken into
4227 * account across bands.
4228 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4229 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4230 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4231 * is enforced by the rest of the schedule.
4233 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
4236 isl_union_set
*domain
;
4237 isl_union_map
*validity
, *proximity
, *condition
;
4238 isl_union_map
*sink
, *source
, *dep
;
4239 isl_schedule_constraints
*sc
;
4240 isl_schedule
*schedule
;
4241 isl_union_access_info
*access
;
4242 isl_union_flow
*flow
;
4245 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4246 "A[k] : k >= 1 and k <= -1 + n; "
4247 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4248 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4249 domain
= isl_union_set_read_from_str(ctx
, str
);
4250 sc
= isl_schedule_constraints_on_domain(domain
);
4251 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4252 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4253 "D[k, i] -> C[1 + k, i] : "
4254 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4255 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4256 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4257 validity
= isl_union_map_read_from_str(ctx
, str
);
4258 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4259 str
= "[n] -> { C[k, i] -> D[k, i] : "
4260 "0 <= i <= -1 + k and k <= -1 + n }";
4261 proximity
= isl_union_map_read_from_str(ctx
, str
);
4262 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4263 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4264 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4265 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4266 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4267 condition
= isl_union_map_read_from_str(ctx
, str
);
4268 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4269 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4270 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4271 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4272 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4273 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4274 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4275 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4276 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4277 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4278 validity
= isl_union_map_read_from_str(ctx
, str
);
4279 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4281 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4282 str
= "{ D[2,0] -> [] }";
4283 sink
= isl_union_map_read_from_str(ctx
, str
);
4284 access
= isl_union_access_info_from_sink(sink
);
4285 str
= "{ C[2,1] -> [] }";
4286 source
= isl_union_map_read_from_str(ctx
, str
);
4287 access
= isl_union_access_info_set_must_source(access
, source
);
4288 access
= isl_union_access_info_set_schedule(access
, schedule
);
4289 flow
= isl_union_access_info_compute_flow(access
);
4290 dep
= isl_union_flow_get_must_dependence(flow
);
4291 isl_union_flow_free(flow
);
4292 empty
= isl_union_map_is_empty(dep
);
4293 isl_union_map_free(dep
);
4298 isl_die(ctx
, isl_error_unknown
,
4299 "conditional validity not respected", return -1);
4304 /* Check that the test for violated conditional validity constraints
4305 * is not confused by domain compression.
4306 * In particular, earlier versions of isl would apply
4307 * a schedule on the compressed domains to the original domains,
4308 * resulting in a failure to detect that the default schedule
4309 * violates the conditional validity constraints.
4311 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
4315 isl_union_set
*domain
;
4316 isl_union_map
*validity
, *condition
;
4317 isl_schedule_constraints
*sc
;
4318 isl_schedule
*schedule
;
4319 isl_union_map
*umap
;
4322 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4323 domain
= isl_union_set_read_from_str(ctx
, str
);
4324 sc
= isl_schedule_constraints_on_domain(domain
);
4325 str
= "{ B[1, i] -> A[0, i + 1] }";
4326 condition
= isl_union_map_read_from_str(ctx
, str
);
4327 str
= "{ A[0, i] -> B[1, i - 1] }";
4328 validity
= isl_union_map_read_from_str(ctx
, str
);
4329 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4330 isl_union_map_copy(validity
));
4331 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4332 umap
= isl_schedule_get_map(schedule
);
4333 isl_schedule_free(schedule
);
4334 validity
= isl_union_map_apply_domain(validity
,
4335 isl_union_map_copy(umap
));
4336 validity
= isl_union_map_apply_range(validity
, umap
);
4337 map
= isl_map_from_union_map(validity
);
4338 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4339 map
= isl_map_intersect(map
, ge
);
4340 empty
= isl_map_is_empty(map
);
4346 isl_die(ctx
, isl_error_unknown
,
4347 "conditional validity constraints not satisfied",
4353 /* Input for testing of schedule construction based on
4354 * conditional constraints.
4356 * domain is the iteration domain
4357 * flow are the flow dependences, which determine the validity and
4358 * proximity constraints
4359 * condition are the conditions on the conditional validity constraints
4360 * conditional_validity are the conditional validity constraints
4361 * outer_band_n is the expected number of members in the outer band
4366 const char *condition
;
4367 const char *conditional_validity
;
4369 } live_range_tests
[] = {
4370 /* Contrived example that illustrates that we need to keep
4371 * track of tagged condition dependences and
4372 * tagged conditional validity dependences
4373 * in isl_sched_edge separately.
4374 * In particular, the conditional validity constraints on A
4375 * cannot be satisfied,
4376 * but they can be ignored because there are no corresponding
4377 * condition constraints. However, we do have an additional
4378 * conditional validity constraint that maps to the same
4379 * dependence relation
4380 * as the condition constraint on B. If we did not make a distinction
4381 * between tagged condition and tagged conditional validity
4382 * dependences, then we
4383 * could end up treating this shared dependence as an condition
4384 * constraint on A, forcing a localization of the conditions,
4385 * which is impossible.
4387 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4388 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4389 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4390 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4391 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4392 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4395 /* TACO 2013 Fig. 7 */
4396 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4397 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4398 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4399 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4400 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4401 "0 <= i < n and 0 <= j < n - 1 }",
4402 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4403 "0 <= i < n and 0 <= j < j' < n;"
4404 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4405 "0 <= i < i' < n and 0 <= j,j' < n;"
4406 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4407 "0 <= i,j,j' < n and j < j' }",
4410 /* TACO 2013 Fig. 7, without tags */
4411 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4412 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4413 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4414 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4415 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4416 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4417 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4418 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4421 /* TACO 2013 Fig. 12 */
4422 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4423 "S3[i,3] : 0 <= i <= 1 }",
4424 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4425 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4426 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4427 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4428 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4429 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4430 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4431 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4432 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4433 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4434 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4439 /* Test schedule construction based on conditional constraints.
4440 * In particular, check the number of members in the outer band node
4441 * as an indication of whether tiling is possible or not.
4443 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4446 isl_union_set
*domain
;
4447 isl_union_map
*condition
;
4448 isl_union_map
*flow
;
4449 isl_union_map
*validity
;
4450 isl_schedule_constraints
*sc
;
4451 isl_schedule
*schedule
;
4452 isl_schedule_node
*node
;
4455 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4457 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4460 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4461 domain
= isl_union_set_read_from_str(ctx
,
4462 live_range_tests
[i
].domain
);
4463 flow
= isl_union_map_read_from_str(ctx
,
4464 live_range_tests
[i
].flow
);
4465 condition
= isl_union_map_read_from_str(ctx
,
4466 live_range_tests
[i
].condition
);
4467 validity
= isl_union_map_read_from_str(ctx
,
4468 live_range_tests
[i
].conditional_validity
);
4469 sc
= isl_schedule_constraints_on_domain(domain
);
4470 sc
= isl_schedule_constraints_set_validity(sc
,
4471 isl_union_map_copy(flow
));
4472 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4473 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4474 condition
, validity
);
4475 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4476 node
= isl_schedule_get_root(schedule
);
4478 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4479 node
= isl_schedule_node_first_child(node
);
4480 n_member
= isl_schedule_node_band_n_member(node
);
4481 isl_schedule_node_free(node
);
4482 isl_schedule_free(schedule
);
4484 if (!schedule
|| n_member
< 0)
4486 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4487 isl_die(ctx
, isl_error_unknown
,
4488 "unexpected number of members in outer band",
4494 /* Check that the schedule computed for the given instance set and
4495 * dependence relation strongly satisfies the dependences.
4496 * In particular, check that no instance is scheduled before
4497 * or together with an instance on which it depends.
4498 * Earlier versions of isl would produce a schedule that
4499 * only weakly satisfies the dependences.
4501 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4503 const char *domain
, *dep
;
4504 isl_union_map
*D
, *schedule
;
4508 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4509 "A[i0] : 0 <= i0 <= 1 }";
4510 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4511 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4512 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
4513 D
= isl_union_map_read_from_str(ctx
, dep
);
4514 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
4515 D
= isl_union_map_apply_range(D
, schedule
);
4516 map
= isl_map_from_union_map(D
);
4517 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4518 map
= isl_map_intersect(map
, ge
);
4519 empty
= isl_map_is_empty(map
);
4525 isl_die(ctx
, isl_error_unknown
,
4526 "dependences not strongly satisfied", return -1);
4531 /* Compute a schedule for input where the instance set constraints
4532 * conflict with the context constraints.
4533 * Earlier versions of isl did not properly handle this situation.
4535 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
4537 isl_union_map
*schedule
;
4538 const char *domain
, *context
;
4540 domain
= "[n] -> { A[] : n >= 0 }";
4541 context
= "[n] -> { : n < 0 }";
4542 schedule
= compute_schedule_with_context(ctx
,
4543 domain
, "{}", "{}", context
);
4544 isl_union_map_free(schedule
);
4552 /* Check that a set of schedule constraints that only allow for
4553 * a coalescing schedule still produces a schedule even if the user
4554 * request a non-coalescing schedule. Earlier versions of isl
4555 * would not handle this case correctly.
4557 static int test_coalescing_schedule(isl_ctx
*ctx
)
4559 const char *domain
, *dep
;
4562 isl_schedule_constraints
*sc
;
4563 isl_schedule
*schedule
;
4564 int treat_coalescing
;
4566 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4567 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
4568 I
= isl_union_set_read_from_str(ctx
, domain
);
4569 D
= isl_union_map_read_from_str(ctx
, dep
);
4570 sc
= isl_schedule_constraints_on_domain(I
);
4571 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4572 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4573 isl_options_set_schedule_treat_coalescing(ctx
, 1);
4574 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4575 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4576 isl_schedule_free(schedule
);
4582 /* Check that the scheduler does not perform any needless
4583 * compound skewing. Earlier versions of isl would compute
4584 * schedules in terms of transformed schedule coefficients and
4585 * would not accurately keep track of the sum of the original
4586 * schedule coefficients. It could then produce the schedule
4587 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4588 * for the input below instead of the schedule below.
4590 static int test_skewing_schedule(isl_ctx
*ctx
)
4592 const char *D
, *V
, *P
, *S
;
4594 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4595 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4596 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4597 "-1 <= a-i + b-j + c-k <= 1 }";
4599 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4601 return test_special_schedule(ctx
, D
, V
, P
, S
);
4604 int test_schedule(isl_ctx
*ctx
)
4606 const char *D
, *W
, *R
, *V
, *P
, *S
;
4607 int max_coincidence
;
4608 int treat_coalescing
;
4610 /* Handle resulting schedule with zero bands. */
4611 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4615 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4616 W
= "{ S1[t,i] -> a[t,i] }";
4617 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4618 "S1[t,i] -> a[t-1,i+1] }";
4619 S
= "{ S1[t,i] -> [t,i] }";
4620 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4623 /* Fig. 5 of CC2008 */
4624 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4626 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4627 "j >= 2 and j <= -1 + N }";
4628 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4629 "j >= 2 and j <= -1 + N; "
4630 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4631 "j >= 2 and j <= -1 + N }";
4632 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4633 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4636 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4637 W
= "{ S1[i] -> a[i] }";
4638 R
= "{ S2[i] -> a[i+1] }";
4639 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4640 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4643 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4644 W
= "{ S1[i] -> a[i] }";
4645 R
= "{ S2[i] -> a[9-i] }";
4646 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4647 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4650 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4651 W
= "{ S1[i] -> a[i] }";
4652 R
= "[N] -> { S2[i] -> a[N-1-i] }";
4653 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4654 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4657 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4658 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4659 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4660 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4661 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4664 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4665 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4666 R
= "{ S2[i,j] -> a[i-1,j] }";
4667 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4668 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4671 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4672 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4673 R
= "{ S2[i,j] -> a[i,j-1] }";
4674 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4675 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4678 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4679 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4680 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4681 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4682 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4683 "S_0[] -> [0, 0, 0] }";
4684 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
4686 ctx
->opt
->schedule_parametric
= 0;
4687 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4689 ctx
->opt
->schedule_parametric
= 1;
4691 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4692 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4693 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4694 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4695 "S4[i] -> a[i,N] }";
4696 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4697 "S4[i] -> [4,i,0] }";
4698 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
4699 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
4700 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4702 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
4704 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4705 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4707 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4709 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4711 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4712 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4715 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4716 " S_2[t] : t >= 0 and t <= -1 + N; "
4717 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4719 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4720 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4721 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4722 "i >= 0 and i <= -1 + N }";
4723 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4724 "i >= 0 and i <= -1 + N; "
4725 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4726 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4727 " S_0[t] -> [0, t, 0] }";
4729 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4731 ctx
->opt
->schedule_parametric
= 0;
4732 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4734 ctx
->opt
->schedule_parametric
= 1;
4736 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4737 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4738 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
4741 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4742 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4743 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4744 "j >= 0 and j <= -1 + N; "
4745 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4746 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4747 "j >= 0 and j <= -1 + N; "
4748 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4749 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4750 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4753 D
= "{ S_0[i] : i >= 0 }";
4754 W
= "{ S_0[i] -> a[i] : i >= 0 }";
4755 R
= "{ S_0[i] -> a[0] : i >= 0 }";
4756 S
= "{ S_0[i] -> [0, i, 0] }";
4757 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4760 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
4761 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
4762 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
4763 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
4764 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4767 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
4768 "k <= -1 + n and k >= 0 }";
4769 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
4770 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
4771 "k <= -1 + n and k >= 0; "
4772 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
4773 "k <= -1 + n and k >= 0; "
4774 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
4775 "k <= -1 + n and k >= 0 }";
4776 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
4777 ctx
->opt
->schedule_outer_coincidence
= 1;
4778 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4780 ctx
->opt
->schedule_outer_coincidence
= 0;
4782 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
4783 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
4784 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
4785 "Stmt_for_body24[i0, i1, 1, 0]:"
4786 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
4787 "Stmt_for_body7[i0, i1, i2]:"
4788 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
4791 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
4792 "Stmt_for_body24[1, i1, i2, i3]:"
4793 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
4795 "Stmt_for_body24[0, i1, i2, i3] -> "
4796 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
4797 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
4799 "Stmt_for_body24[0, i1, i2, i3] ->"
4800 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
4801 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
4802 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
4803 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
4804 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
4805 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
4806 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
4807 "i1 <= 6 and i1 >= 0;"
4808 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
4809 "Stmt_for_body7[i0, i1, i2] -> "
4810 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
4811 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
4812 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
4813 "Stmt_for_body7[i0, i1, i2] -> "
4814 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
4815 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
4816 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
4819 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4820 isl_options_set_schedule_treat_coalescing(ctx
, 0);
4821 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4823 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4825 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
4826 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
4827 "j >= 1 and j <= 7;"
4828 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
4829 "j >= 1 and j <= 8 }";
4831 S
= "{ S_0[i, j] -> [i + j, i] }";
4832 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4833 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4835 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4837 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
4838 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
4839 "j >= 0 and j <= -1 + i }";
4840 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
4841 "i <= -1 + N and j >= 0;"
4842 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
4845 S
= "{ S_0[i, j] -> [i, j] }";
4846 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4847 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4849 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4851 /* Test both algorithms on a case with only proximity dependences. */
4852 D
= "{ S[i,j] : 0 <= i <= 10 }";
4854 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
4855 S
= "{ S[i, j] -> [j, i] }";
4856 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4857 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4859 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4860 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4863 D
= "{ A[a]; B[] }";
4865 P
= "{ A[a] -> B[] }";
4866 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4869 if (test_padded_schedule(ctx
) < 0)
4872 /* Check that check for progress is not confused by rational
4875 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
4876 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
4878 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
4879 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
4881 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4882 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4884 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4886 /* Check that we allow schedule rows that are only non-trivial
4887 * on some full-dimensional domains.
4889 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
4890 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
4891 "S1[j] -> S2[1] : 0 <= j <= 1 }";
4893 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4894 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4896 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4898 if (test_conditional_schedule_constraints(ctx
) < 0)
4901 if (test_strongly_satisfying_schedule(ctx
) < 0)
4904 if (test_conflicting_context_schedule(ctx
) < 0)
4907 if (test_coalescing_schedule(ctx
) < 0)
4909 if (test_skewing_schedule(ctx
) < 0)
4915 /* Perform scheduling tests using the whole component scheduler.
4917 static int test_schedule_whole(isl_ctx
*ctx
)
4922 whole
= isl_options_get_schedule_whole_component(ctx
);
4923 isl_options_set_schedule_whole_component(ctx
, 1);
4924 r
= test_schedule(ctx
);
4925 isl_options_set_schedule_whole_component(ctx
, whole
);
4930 /* Perform scheduling tests using the incremental scheduler.
4932 static int test_schedule_incremental(isl_ctx
*ctx
)
4937 whole
= isl_options_get_schedule_whole_component(ctx
);
4938 isl_options_set_schedule_whole_component(ctx
, 0);
4939 r
= test_schedule(ctx
);
4940 isl_options_set_schedule_whole_component(ctx
, whole
);
4945 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
4947 isl_union_map
*umap
;
4950 umap
= isl_union_map_read_from_str(ctx
, str
);
4951 test
= isl_union_map_plain_is_injective(umap
);
4952 isl_union_map_free(umap
);
4955 if (test
== injective
)
4958 isl_die(ctx
, isl_error_unknown
,
4959 "map not detected as injective", return -1);
4961 isl_die(ctx
, isl_error_unknown
,
4962 "map detected as injective", return -1);
4965 int test_injective(isl_ctx
*ctx
)
4969 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
4971 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
4973 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
4975 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
4977 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
4979 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
4981 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
4983 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
4986 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
4987 if (test_plain_injective(ctx
, str
, 1))
4989 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
4990 if (test_plain_injective(ctx
, str
, 0))
4996 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
5004 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
5005 equal
= isl_aff_plain_is_equal(aff
, aff2
);
5011 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
5015 equal
= aff_plain_is_equal(aff
, str
);
5019 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
5020 "result not as expected", return -1);
5024 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
5026 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
5030 isl_pw_multi_aff
*pma2
;
5036 ctx
= isl_pw_multi_aff_get_ctx(pma
);
5037 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
5038 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
5039 isl_pw_multi_aff_free(pma2
);
5044 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
5045 * represented by "str".
5047 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
5052 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
5056 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
5057 "result not as expected", return -1);
5061 /* Is "upa" obviously equal to the isl_union_pw_aff represented by "str"?
5063 static isl_bool
union_pw_aff_plain_is_equal(__isl_keep isl_union_pw_aff
*upa
,
5067 isl_union_pw_aff
*upa2
;
5071 return isl_bool_error
;
5073 ctx
= isl_union_pw_aff_get_ctx(upa
);
5074 upa2
= isl_union_pw_aff_read_from_str(ctx
, str
);
5075 equal
= isl_union_pw_aff_plain_is_equal(upa
, upa2
);
5076 isl_union_pw_aff_free(upa2
);
5081 /* Check that "upa" is obviously equal to the isl_union_pw_aff
5082 * represented by "str".
5084 static isl_stat
union_pw_aff_check_plain_equal(__isl_keep isl_union_pw_aff
*upa
,
5089 equal
= union_pw_aff_plain_is_equal(upa
, str
);
5091 return isl_stat_error
;
5093 isl_die(isl_union_pw_aff_get_ctx(upa
), isl_error_unknown
,
5094 "result not as expected", return isl_stat_error
);
5098 /* Basic tests on isl_union_pw_aff.
5100 * In particular, check that isl_union_pw_aff_aff_on_domain
5101 * aligns the parameters of the input objects and
5102 * that isl_union_pw_aff_param_on_domain_id properly
5103 * introduces the parameter.
5105 static int test_upa(isl_ctx
*ctx
)
5110 isl_union_set
*domain
;
5111 isl_union_pw_aff
*upa
;
5114 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
5115 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5116 domain
= isl_union_set_read_from_str(ctx
, str
);
5117 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
5118 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5119 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5120 isl_union_pw_aff_free(upa
);
5124 id
= isl_id_alloc(ctx
, "N", NULL
);
5125 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5126 domain
= isl_union_set_read_from_str(ctx
, str
);
5127 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
5128 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5129 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5130 isl_union_pw_aff_free(upa
);
5138 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5139 __isl_take isl_aff
*aff2
);
5141 ['+'] = { &isl_aff_add
},
5142 ['-'] = { &isl_aff_sub
},
5143 ['*'] = { &isl_aff_mul
},
5144 ['/'] = { &isl_aff_div
},
5152 } aff_bin_tests
[] = {
5153 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5154 "{ [i] -> [2i] }" },
5155 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5157 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5158 "{ [i] -> [2i] }" },
5159 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5160 "{ [i] -> [2i] }" },
5161 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5162 "{ [i] -> [i/2] }" },
5163 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5165 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5166 "{ [i] -> [NaN] }" },
5167 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5168 "{ [i] -> [NaN] }" },
5169 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5170 "{ [i] -> [NaN] }" },
5171 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5172 "{ [i] -> [NaN] }" },
5173 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5174 "{ [i] -> [NaN] }" },
5175 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5176 "{ [i] -> [NaN] }" },
5177 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5178 "{ [i] -> [NaN] }" },
5179 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5180 "{ [i] -> [NaN] }" },
5181 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5182 "{ [i] -> [NaN] }" },
5183 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5184 "{ [i] -> [NaN] }" },
5185 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5186 "{ [i] -> [NaN] }" },
5187 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5188 "{ [i] -> [NaN] }" },
5191 /* Perform some basic tests of binary operations on isl_aff objects.
5193 static int test_bin_aff(isl_ctx
*ctx
)
5196 isl_aff
*aff1
, *aff2
, *res
;
5197 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5198 __isl_take isl_aff
*aff2
);
5201 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
5202 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
5203 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
5204 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
5205 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
5206 aff1
= fn(aff1
, aff2
);
5207 if (isl_aff_is_nan(res
))
5208 ok
= isl_aff_is_nan(aff1
);
5210 ok
= isl_aff_plain_is_equal(aff1
, res
);
5216 isl_die(ctx
, isl_error_unknown
,
5217 "unexpected result", return -1);
5224 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
5225 __isl_take isl_pw_aff
*pa2
);
5226 } pw_aff_bin_op
[] = {
5227 ['m'] = { &isl_pw_aff_min
},
5228 ['M'] = { &isl_pw_aff_max
},
5231 /* Inputs for binary isl_pw_aff operation tests.
5232 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5233 * defined by pw_aff_bin_op, and "res" is the expected result.
5240 } pw_aff_bin_tests
[] = {
5241 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5243 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5245 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5246 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5247 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5248 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5249 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5250 "{ [i] -> [NaN] }" },
5251 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5252 "{ [i] -> [NaN] }" },
5255 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5257 static int test_bin_pw_aff(isl_ctx
*ctx
)
5261 isl_pw_aff
*pa1
, *pa2
, *res
;
5263 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
5264 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
5265 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
5266 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
5267 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
5268 if (isl_pw_aff_involves_nan(res
))
5269 ok
= isl_pw_aff_involves_nan(pa1
);
5271 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
5272 isl_pw_aff_free(pa1
);
5273 isl_pw_aff_free(res
);
5277 isl_die(ctx
, isl_error_unknown
,
5278 "unexpected result", return -1);
5285 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5286 __isl_take isl_union_pw_multi_aff
*upma1
,
5287 __isl_take isl_union_pw_multi_aff
*upma2
);
5291 } upma_bin_tests
[] = {
5292 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
5293 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5294 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
5295 "{ B[x] -> [2] : x >= 0 }",
5296 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5297 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
5298 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5299 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5300 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5301 "D[i] -> B[2] : i >= 5 }" },
5302 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5303 "{ B[x] -> C[2] : x > 0 }",
5304 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5305 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5306 "{ B[x] -> A[2] : x >= 0 }",
5307 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5310 /* Perform some basic tests of binary operations on
5311 * isl_union_pw_multi_aff objects.
5313 static int test_bin_upma(isl_ctx
*ctx
)
5316 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
5319 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
5320 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5321 upma_bin_tests
[i
].arg1
);
5322 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5323 upma_bin_tests
[i
].arg2
);
5324 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5325 upma_bin_tests
[i
].res
);
5326 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
5327 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
5328 isl_union_pw_multi_aff_free(upma1
);
5329 isl_union_pw_multi_aff_free(res
);
5333 isl_die(ctx
, isl_error_unknown
,
5334 "unexpected result", return -1);
5341 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5342 __isl_take isl_union_pw_multi_aff
*upma1
,
5343 __isl_take isl_union_pw_multi_aff
*upma2
);
5346 } upma_bin_fail_tests
[] = {
5347 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5348 "{ B[x] -> C[2] : x >= 0 }" },
5351 /* Perform some basic tests of binary operations on
5352 * isl_union_pw_multi_aff objects that are expected to fail.
5354 static int test_bin_upma_fail(isl_ctx
*ctx
)
5357 isl_union_pw_multi_aff
*upma1
, *upma2
;
5360 on_error
= isl_options_get_on_error(ctx
);
5361 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5362 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5363 for (i
= 0; i
< n
; ++i
) {
5364 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5365 upma_bin_fail_tests
[i
].arg1
);
5366 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5367 upma_bin_fail_tests
[i
].arg2
);
5368 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5369 isl_union_pw_multi_aff_free(upma1
);
5373 isl_options_set_on_error(ctx
, on_error
);
5375 isl_die(ctx
, isl_error_unknown
,
5376 "operation not expected to succeed", return -1);
5381 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5382 * "fn" is the function that is tested.
5383 * "arg" is a string description of the input.
5384 * "res" is a string description of the expected result.
5387 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5390 } mpa_un_tests
[] = {
5391 { &isl_multi_pw_aff_range_factor_domain
,
5392 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5393 "{ A[x] -> B[(1 : x >= 5)] }" },
5394 { &isl_multi_pw_aff_range_factor_range
,
5395 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5396 "{ A[y] -> C[(2 : y <= 10)] }" },
5397 { &isl_multi_pw_aff_range_factor_domain
,
5398 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5399 "{ A[x] -> B[(1 : x >= 5)] }" },
5400 { &isl_multi_pw_aff_range_factor_range
,
5401 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5402 "{ A[y] -> C[] }" },
5403 { &isl_multi_pw_aff_range_factor_domain
,
5404 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5405 "{ A[x] -> B[] }" },
5406 { &isl_multi_pw_aff_range_factor_range
,
5407 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5408 "{ A[y] -> C[(2 : y <= 10)] }" },
5409 { &isl_multi_pw_aff_range_factor_domain
,
5410 "{ A[x] -> [B[] -> C[]] }",
5411 "{ A[x] -> B[] }" },
5412 { &isl_multi_pw_aff_range_factor_range
,
5413 "{ A[x] -> [B[] -> C[]] }",
5414 "{ A[y] -> C[] }" },
5415 { &isl_multi_pw_aff_factor_range
,
5418 { &isl_multi_pw_aff_range_factor_domain
,
5419 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5420 "{ A[x] -> B[] : x >= 0 }" },
5421 { &isl_multi_pw_aff_range_factor_range
,
5422 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5423 "{ A[y] -> C[] : y >= 0 }" },
5424 { &isl_multi_pw_aff_factor_range
,
5425 "[N] -> { [B[] -> C[]] : N >= 0 }",
5426 "[N] -> { C[] : N >= 0 }" },
5429 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5431 static int test_un_mpa(isl_ctx
*ctx
)
5435 isl_multi_pw_aff
*mpa
, *res
;
5437 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5438 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5439 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5440 mpa
= mpa_un_tests
[i
].fn(mpa
);
5441 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5442 isl_multi_pw_aff_free(mpa
);
5443 isl_multi_pw_aff_free(res
);
5447 isl_die(ctx
, isl_error_unknown
,
5448 "unexpected result", return -1);
5454 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5455 * "fn" is the function that is tested.
5456 * "arg1" and "arg2" are string descriptions of the inputs.
5457 * "res" is a string description of the expected result.
5460 __isl_give isl_multi_pw_aff
*(*fn
)(
5461 __isl_take isl_multi_pw_aff
*mpa1
,
5462 __isl_take isl_multi_pw_aff
*mpa2
);
5466 } mpa_bin_tests
[] = {
5467 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
5469 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
5470 "{ A[x] -> [(x : x <= 10)] }",
5471 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5472 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5473 "{ A[x] -> [] : x <= 10 }",
5474 "{ A[x] -> [] : 5 <= x <= 10 }" },
5475 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5476 "[N] -> { A[x] -> [] : x <= N }",
5477 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5478 { &isl_multi_pw_aff_add
,
5479 "[N] -> { A[x] -> [] : x <= N }",
5480 "{ A[x] -> [] : x >= 5 }",
5481 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5482 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5483 "{ A[y] -> C[(2 : y <= 10)] }",
5484 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5485 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5486 "{ A[y] -> C[2] : y <= 10 }",
5487 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5488 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5489 "[N] -> { A[y] -> C[2] : y <= N }",
5490 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5491 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
5492 "{ A[y] -> C[2] : y <= 10 }",
5493 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5494 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5495 "{ A[] -> [B[1] -> C[2]] }" },
5496 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5497 "{ A[] -> [B[] -> C[]] }" },
5498 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5499 "{ A[y] -> C[] : y <= 10 }",
5500 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5501 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
5502 "{ A[x] -> B[(1 : x >= 5)] }",
5503 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5504 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5505 "{ A[y] -> C[(2 : y <= 10)] }",
5506 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5507 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5508 "{ A[y] -> C[] : y <= 10 }",
5509 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5510 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
5511 "{ A[x] -> B[(1 : x >= 5)] }",
5512 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5513 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5514 "[N] -> { A[y] -> C[] : y <= N }",
5515 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5516 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
5517 "{ A[x] -> B[(1 : x >= 5)] }",
5518 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5519 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
5520 "{ A[y] -> C[] : y <= 10 }",
5521 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5522 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5523 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5524 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5525 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5526 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5527 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5528 "{ A[a,b] -> C[b + 2a] }" },
5529 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5530 "{ B[i,j] -> C[i + 2j] }",
5531 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5532 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5533 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5534 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5535 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5536 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5537 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5538 "{ B[i,j] -> C[] }",
5539 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5540 "{ A[a,b] -> C[] }" },
5541 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5542 "{ B[i,j] -> C[] : i > j }",
5543 "{ A[a,b] -> B[b,a] }",
5544 "{ A[a,b] -> C[] : b > a }" },
5545 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5546 "{ B[i,j] -> C[] : j > 5 }",
5547 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5548 "{ A[a,b] -> C[] : b > a > 5 }" },
5549 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5550 "[N] -> { B[i,j] -> C[] : j > N }",
5551 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5552 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5553 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5554 "[M,N] -> { B[] -> C[] : N > 5 }",
5555 "[M,N] -> { A[] -> B[] : M > N }",
5556 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5559 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5561 static int test_bin_mpa(isl_ctx
*ctx
)
5565 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
5567 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
5568 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
5569 mpa_bin_tests
[i
].arg1
);
5570 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
5571 mpa_bin_tests
[i
].arg2
);
5572 res
= isl_multi_pw_aff_read_from_str(ctx
,
5573 mpa_bin_tests
[i
].res
);
5574 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
5575 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
5576 isl_multi_pw_aff_free(mpa1
);
5577 isl_multi_pw_aff_free(res
);
5581 isl_die(ctx
, isl_error_unknown
,
5582 "unexpected result", return -1);
5588 /* Inputs for basic tests of unary operations on
5589 * isl_multi_union_pw_aff objects.
5590 * "fn" is the function that is tested.
5591 * "arg" is a string description of the input.
5592 * "res" is a string description of the expected result.
5595 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5596 __isl_take isl_multi_union_pw_aff
*mupa
);
5599 } mupa_un_tests
[] = {
5600 { &isl_multi_union_pw_aff_factor_range
,
5601 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5602 "C[{ A[] -> [2] }]" },
5603 { &isl_multi_union_pw_aff_factor_range
,
5604 "[B[] -> C[{ A[] -> [2] }]]",
5605 "C[{ A[] -> [2] }]" },
5606 { &isl_multi_union_pw_aff_factor_range
,
5607 "[B[{ A[] -> [1] }] -> C[]]",
5609 { &isl_multi_union_pw_aff_factor_range
,
5612 { &isl_multi_union_pw_aff_factor_range
,
5613 "([B[] -> C[]] : { A[x] : x >= 0 })",
5614 "(C[] : { A[x] : x >= 0 })" },
5615 { &isl_multi_union_pw_aff_factor_range
,
5616 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
5617 "[N] -> (C[] : { A[x] : x <= N })" },
5618 { &isl_multi_union_pw_aff_factor_range
,
5619 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
5620 "[N] -> (C[] : { : N >= 0 })" },
5623 /* Perform some basic tests of unary operations on
5624 * isl_multi_union_pw_aff objects.
5626 static int test_un_mupa(isl_ctx
*ctx
)
5630 isl_multi_union_pw_aff
*mupa
, *res
;
5632 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
5633 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5634 mupa_un_tests
[i
].arg
);
5635 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5636 mupa_un_tests
[i
].res
);
5637 mupa
= mupa_un_tests
[i
].fn(mupa
);
5638 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5639 isl_multi_union_pw_aff_free(mupa
);
5640 isl_multi_union_pw_aff_free(res
);
5644 isl_die(ctx
, isl_error_unknown
,
5645 "unexpected result", return -1);
5651 /* Inputs for basic tests of binary operations on
5652 * isl_multi_union_pw_aff objects.
5653 * "fn" is the function that is tested.
5654 * "arg1" and "arg2" are string descriptions of the inputs.
5655 * "res" is a string description of the expected result.
5658 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5659 __isl_take isl_multi_union_pw_aff
*mupa1
,
5660 __isl_take isl_multi_union_pw_aff
*mupa2
);
5664 } mupa_bin_tests
[] = {
5665 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5666 "[{ A[] -> [3] }]" },
5667 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5668 "[{ A[] -> [-1] }]" },
5669 { &isl_multi_union_pw_aff_add
,
5670 "[{ A[] -> [1]; B[] -> [4] }]",
5671 "[{ A[] -> [2]; C[] -> [5] }]",
5672 "[{ A[] -> [3] }]" },
5673 { &isl_multi_union_pw_aff_union_add
,
5674 "[{ A[] -> [1]; B[] -> [4] }]",
5675 "[{ A[] -> [2]; C[] -> [5] }]",
5676 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
5677 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5678 "[{ A[x] -> [(x)] : x <= 10 }]",
5679 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
5680 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5681 "([] : { A[x] : x <= 10 })",
5682 "([] : { A[x] : 5 <= x <= 10 })" },
5683 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5684 "[N] -> ([] : { A[x] : x <= N })",
5685 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
5686 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
5687 "([] : { A[x] : x <= 10 })",
5688 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
5689 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5690 "[{ A[x] -> [(x)] : x <= 10 }]",
5691 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
5692 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
5693 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
5694 "([] : { A[x] : x <= 10 })",
5695 "([] : { A[x] })" },
5696 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
5697 "[N] -> ([] : { A[x] : x >= N })",
5698 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
5699 { &isl_multi_union_pw_aff_union_add
,
5700 "[N] -> ([] : { A[] : N >= 0})",
5701 "[N] -> ([] : { A[] : N <= 0})",
5702 "[N] -> ([] : { A[] })" },
5703 { &isl_multi_union_pw_aff_union_add
,
5704 "[N] -> ([] : { A[] })",
5705 "[N] -> ([] : { : })",
5706 "[N] -> ([] : { : })" },
5707 { &isl_multi_union_pw_aff_union_add
,
5708 "[N] -> ([] : { : })",
5709 "[N] -> ([] : { A[] })",
5710 "[N] -> ([] : { : })" },
5711 { &isl_multi_union_pw_aff_union_add
,
5712 "[N] -> ([] : { : N >= 0})",
5713 "[N] -> ([] : { : N <= 0})",
5714 "[N] -> ([] : { : })" },
5715 { &isl_multi_union_pw_aff_range_product
,
5716 "B[{ A[] -> [1] }]",
5717 "C[{ A[] -> [2] }]",
5718 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
5719 { &isl_multi_union_pw_aff_range_product
,
5720 "(B[] : { A[x] : x >= 5 })",
5721 "(C[] : { A[x] : x <= 10 })",
5722 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
5723 { &isl_multi_union_pw_aff_range_product
,
5724 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5725 "(C[] : { A[x] : x <= 10 })",
5726 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
5727 { &isl_multi_union_pw_aff_range_product
,
5728 "(C[] : { A[x] : x <= 10 })",
5729 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5730 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
5731 { &isl_multi_union_pw_aff_range_product
,
5732 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5733 "[N] -> (C[] : { A[x] : x <= N })",
5734 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
5735 { &isl_multi_union_pw_aff_range_product
,
5736 "[N] -> (C[] : { A[x] : x <= N })",
5737 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5738 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
5739 { &isl_multi_union_pw_aff_range_product
,
5740 "B[{ A[] -> [1]; D[] -> [3] }]",
5741 "C[{ A[] -> [2] }]",
5742 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
5743 { &isl_multi_union_pw_aff_range_product
,
5746 "([B[] -> C[]] : { A[x] })" },
5747 { &isl_multi_union_pw_aff_range_product
,
5750 "([B[] -> C[]] : { A[x] })" },
5753 /* Perform some basic tests of binary operations on
5754 * isl_multi_union_pw_aff objects.
5756 static int test_bin_mupa(isl_ctx
*ctx
)
5760 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
5762 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
5763 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
5764 mupa_bin_tests
[i
].arg1
);
5765 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
5766 mupa_bin_tests
[i
].arg2
);
5767 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5768 mupa_bin_tests
[i
].res
);
5769 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
5770 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
5771 isl_multi_union_pw_aff_free(mupa1
);
5772 isl_multi_union_pw_aff_free(res
);
5776 isl_die(ctx
, isl_error_unknown
,
5777 "unexpected result", return -1);
5783 /* Inputs for basic tests of binary operations on
5784 * pairs of isl_multi_union_pw_aff and isl_set objects.
5785 * "fn" is the function that is tested.
5786 * "arg1" and "arg2" are string descriptions of the inputs.
5787 * "res" is a string description of the expected result.
5790 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5791 __isl_take isl_multi_union_pw_aff
*mupa
,
5792 __isl_take isl_set
*set
);
5796 } mupa_set_tests
[] = {
5797 { &isl_multi_union_pw_aff_intersect_range
,
5798 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
5799 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
5800 { &isl_multi_union_pw_aff_intersect_range
,
5801 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
5802 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
5803 { &isl_multi_union_pw_aff_intersect_range
,
5804 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
5805 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
5806 { &isl_multi_union_pw_aff_intersect_range
,
5807 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
5808 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
5809 { &isl_multi_union_pw_aff_intersect_range
,
5810 "C[]", "{ C[] }", "C[]" },
5811 { &isl_multi_union_pw_aff_intersect_range
,
5812 "[N] -> (C[] : { : N >= 0 })",
5814 "[N] -> (C[] : { : N >= 0 })" },
5815 { &isl_multi_union_pw_aff_intersect_range
,
5816 "(C[] : { A[a,b] })",
5818 "(C[] : { A[a,b] })" },
5819 { &isl_multi_union_pw_aff_intersect_range
,
5820 "[N] -> (C[] : { A[a,b] : a,b <= N })",
5822 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
5823 { &isl_multi_union_pw_aff_intersect_range
,
5825 "[N] -> { C[] : N >= 0 }",
5826 "[N] -> (C[] : { : N >= 0 })" },
5827 { &isl_multi_union_pw_aff_intersect_range
,
5828 "(C[] : { A[a,b] })",
5829 "[N] -> { C[] : N >= 0 }",
5830 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5831 { &isl_multi_union_pw_aff_intersect_range
,
5832 "[N] -> (C[] : { : N >= 0 })",
5833 "[N] -> { C[] : N < 1024 }",
5834 "[N] -> (C[] : { : 0 <= N < 1024 })" },
5835 { &isl_multi_union_pw_aff_intersect_params
,
5836 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
5837 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
5838 { &isl_multi_union_pw_aff_intersect_params
,
5839 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
5840 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
5841 { &isl_multi_union_pw_aff_intersect_params
,
5842 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
5843 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
5844 { &isl_multi_union_pw_aff_intersect_params
,
5845 "C[]", "[N] -> { : N >= 0 }",
5846 "[N] -> (C[] : { : N >= 0 })" },
5847 { &isl_multi_union_pw_aff_intersect_params
,
5848 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
5849 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5850 { &isl_multi_union_pw_aff_intersect_params
,
5851 "[N] -> (C[] : { A[a,N] })", "{ : }",
5852 "[N] -> (C[] : { A[a,N] })" },
5853 { &isl_multi_union_pw_aff_intersect_params
,
5854 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
5855 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
5858 /* Perform some basic tests of binary operations on
5859 * pairs of isl_multi_union_pw_aff and isl_set objects.
5861 static int test_mupa_set(isl_ctx
*ctx
)
5865 isl_multi_union_pw_aff
*mupa
, *res
;
5868 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
5869 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5870 mupa_set_tests
[i
].arg1
);
5871 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
5872 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5873 mupa_set_tests
[i
].res
);
5874 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
5875 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5876 isl_multi_union_pw_aff_free(mupa
);
5877 isl_multi_union_pw_aff_free(res
);
5881 isl_die(ctx
, isl_error_unknown
,
5882 "unexpected result", return -1);
5888 /* Inputs for basic tests of binary operations on
5889 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5890 * "fn" is the function that is tested.
5891 * "arg1" and "arg2" are string descriptions of the inputs.
5892 * "res" is a string description of the expected result.
5895 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5896 __isl_take isl_multi_union_pw_aff
*mupa
,
5897 __isl_take isl_union_set
*uset
);
5901 } mupa_uset_tests
[] = {
5902 { &isl_multi_union_pw_aff_intersect_domain
,
5903 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
5904 "C[{ B[i,i] -> [3i] }]" },
5905 { &isl_multi_union_pw_aff_intersect_domain
,
5906 "(C[] : { B[i,j] })", "{ B[i,i] }",
5907 "(C[] : { B[i,i] })" },
5908 { &isl_multi_union_pw_aff_intersect_domain
,
5909 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
5910 "[N] -> (C[] : { B[N,N] })" },
5911 { &isl_multi_union_pw_aff_intersect_domain
,
5912 "C[]", "{ B[i,i] }",
5913 "(C[] : { B[i,i] })" },
5914 { &isl_multi_union_pw_aff_intersect_domain
,
5915 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
5916 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
5919 /* Perform some basic tests of binary operations on
5920 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5922 static int test_mupa_uset(isl_ctx
*ctx
)
5926 isl_multi_union_pw_aff
*mupa
, *res
;
5927 isl_union_set
*uset
;
5929 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
5930 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5931 mupa_uset_tests
[i
].arg1
);
5932 uset
= isl_union_set_read_from_str(ctx
,
5933 mupa_uset_tests
[i
].arg2
);
5934 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5935 mupa_uset_tests
[i
].res
);
5936 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
5937 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5938 isl_multi_union_pw_aff_free(mupa
);
5939 isl_multi_union_pw_aff_free(res
);
5943 isl_die(ctx
, isl_error_unknown
,
5944 "unexpected result", return -1);
5950 /* Inputs for basic tests of binary operations on
5951 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5952 * "fn" is the function that is tested.
5953 * "arg1" and "arg2" are string descriptions of the inputs.
5954 * "res" is a string description of the expected result.
5957 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5958 __isl_take isl_multi_union_pw_aff
*mupa
,
5959 __isl_take isl_multi_aff
*ma
);
5963 } mupa_ma_tests
[] = {
5964 { &isl_multi_union_pw_aff_apply_multi_aff
,
5965 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5966 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5967 "{ C[a,b] -> D[b,a] }",
5968 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
5969 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
5970 { &isl_multi_union_pw_aff_apply_multi_aff
,
5971 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
5972 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5973 "{ C[a,b] -> D[b,a] }",
5974 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
5975 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
5976 { &isl_multi_union_pw_aff_apply_multi_aff
,
5977 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5978 "[N] -> { C[a] -> D[a + N] }",
5979 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
5980 { &isl_multi_union_pw_aff_apply_multi_aff
,
5984 { &isl_multi_union_pw_aff_apply_multi_aff
,
5985 "[N] -> (C[] : { : N >= 0 })",
5987 "[N] -> (D[] : { : N >= 0 })" },
5988 { &isl_multi_union_pw_aff_apply_multi_aff
,
5990 "[N] -> { C[] -> D[N] }",
5991 "[N] -> D[{ [N] }]" },
5992 { &isl_multi_union_pw_aff_apply_multi_aff
,
5993 "(C[] : { A[i,j] : i >= j })",
5995 "(D[] : { A[i,j] : i >= j })" },
5996 { &isl_multi_union_pw_aff_apply_multi_aff
,
5997 "[N] -> (C[] : { A[i,j] : N >= 0 })",
5999 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6000 { &isl_multi_union_pw_aff_apply_multi_aff
,
6001 "(C[] : { A[i,j] : i >= j })",
6002 "[N] -> { C[] -> D[N] }",
6003 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6006 /* Perform some basic tests of binary operations on
6007 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6009 static int test_mupa_ma(isl_ctx
*ctx
)
6013 isl_multi_union_pw_aff
*mupa
, *res
;
6016 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
6017 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6018 mupa_ma_tests
[i
].arg1
);
6019 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
6020 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6021 mupa_ma_tests
[i
].res
);
6022 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
6023 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6024 isl_multi_union_pw_aff_free(mupa
);
6025 isl_multi_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_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_union_pw_aff
*(*fn
)(
6044 __isl_take isl_multi_union_pw_aff
*mupa
,
6045 __isl_take isl_pw_aff
*pa
);
6049 } mupa_pa_tests
[] = {
6050 { &isl_multi_union_pw_aff_apply_pw_aff
,
6051 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6052 "[N] -> { C[a] -> [a + N] }",
6053 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
6054 { &isl_multi_union_pw_aff_apply_pw_aff
,
6055 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6056 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
6057 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6058 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
6059 { &isl_multi_union_pw_aff_apply_pw_aff
,
6061 "[N] -> { C[] -> [N] }",
6063 { &isl_multi_union_pw_aff_apply_pw_aff
,
6065 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6066 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
6067 { &isl_multi_union_pw_aff_apply_pw_aff
,
6068 "[N] -> (C[] : { : N >= 0 })",
6069 "[N] -> { C[] -> [N] }",
6070 "[N] -> { [N] : N >= 0 }" },
6071 { &isl_multi_union_pw_aff_apply_pw_aff
,
6072 "[N] -> (C[] : { : N >= 0 })",
6073 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6074 "[N] -> { [N] : N >= 0 }" },
6075 { &isl_multi_union_pw_aff_apply_pw_aff
,
6076 "[N] -> (C[] : { : N >= 0 })",
6078 "[N] -> { [0] : N >= 0 }" },
6079 { &isl_multi_union_pw_aff_apply_pw_aff
,
6080 "(C[] : { A[i,j] : i >= j })",
6081 "[N] -> { C[] -> [N] }",
6082 "[N] -> { A[i,j] -> [N] : i >= j }" },
6083 { &isl_multi_union_pw_aff_apply_pw_aff
,
6084 "(C[] : { A[i,j] : i >= j })",
6085 "[N] -> { C[] -> [N] : N >= 0 }",
6086 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6089 /* Perform some basic tests of binary operations on
6090 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6092 static int test_mupa_pa(isl_ctx
*ctx
)
6096 isl_multi_union_pw_aff
*mupa
;
6097 isl_union_pw_aff
*upa
, *res
;
6100 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
6101 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6102 mupa_pa_tests
[i
].arg1
);
6103 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
6104 res
= isl_union_pw_aff_read_from_str(ctx
,
6105 mupa_pa_tests
[i
].res
);
6106 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
6107 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
6108 isl_union_pw_aff_free(upa
);
6109 isl_union_pw_aff_free(res
);
6113 isl_die(ctx
, isl_error_unknown
,
6114 "unexpected result", return -1);
6120 /* Inputs for basic tests of binary operations on
6121 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6122 * "fn" is the function that is tested.
6123 * "arg1" and "arg2" are string descriptions of the inputs.
6124 * "res" is a string description of the expected result.
6127 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6128 __isl_take isl_multi_union_pw_aff
*mupa
,
6129 __isl_take isl_pw_multi_aff
*pma
);
6133 } mupa_pma_tests
[] = {
6134 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6135 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6136 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6137 "{ C[a,b] -> D[b,a] }",
6138 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6139 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6140 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6141 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6142 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6143 "{ C[a,b] -> D[b,a] }",
6144 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6145 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6146 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6147 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6148 "[N] -> { C[a] -> D[a + N] }",
6149 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6150 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6151 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6152 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6153 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6154 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6155 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6156 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6157 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6158 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6159 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6160 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6161 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6162 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6163 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6167 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6168 "[N] -> (C[] : { : N >= 0 })",
6170 "[N] -> (D[] : { : N >= 0 })" },
6171 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6173 "[N] -> { C[] -> D[N] }",
6174 "[N] -> D[{ [N] }]" },
6175 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6176 "(C[] : { A[i,j] : i >= j })",
6178 "(D[] : { A[i,j] : i >= j })" },
6179 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6180 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6182 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6183 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6184 "(C[] : { A[i,j] : i >= j })",
6185 "[N] -> { C[] -> D[N] }",
6186 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6187 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6189 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6190 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6191 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6192 "[N] -> (C[] : { : N >= 0 })",
6193 "[N] -> { C[] -> D[N] }",
6194 "[N] -> D[{ [N] : N >= 0 }]" },
6195 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6196 "[N] -> (C[] : { : N >= 0 })",
6197 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6198 "[N] -> D[{ [N] : N >= 0 }]" },
6199 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6200 "[N] -> (C[] : { : N >= 0 })",
6202 "[N] -> D[{ [0] : N >= 0 }]" },
6203 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6204 "(C[] : { A[i,j] : i >= j })",
6205 "[N] -> { C[] -> D[N] : N >= 0 }",
6206 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6209 /* Perform some basic tests of binary operations on
6210 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6212 static int test_mupa_pma(isl_ctx
*ctx
)
6216 isl_multi_union_pw_aff
*mupa
, *res
;
6217 isl_pw_multi_aff
*pma
;
6219 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
6220 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6221 mupa_pma_tests
[i
].arg1
);
6222 pma
= isl_pw_multi_aff_read_from_str(ctx
,
6223 mupa_pma_tests
[i
].arg2
);
6224 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6225 mupa_pma_tests
[i
].res
);
6226 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
6227 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6228 isl_multi_union_pw_aff_free(mupa
);
6229 isl_multi_union_pw_aff_free(res
);
6233 isl_die(ctx
, isl_error_unknown
,
6234 "unexpected result", return -1);
6240 /* Inputs for basic tests of binary operations on
6241 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6242 * "fn" is the function that is tested.
6243 * "arg1" and "arg2" are string descriptions of the inputs.
6244 * "res" is a string description of the expected result.
6247 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6248 __isl_take isl_multi_union_pw_aff
*mupa
,
6249 __isl_take isl_union_pw_multi_aff
*upma
);
6253 } mupa_upma_tests
[] = {
6254 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6255 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6256 "C[{ A[a,b] -> [b + 2a] }]" },
6257 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6258 "C[{ B[i,j] -> [i + 2j] }]",
6259 "{ A[a,b] -> B[b,a] : b > a }",
6260 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6261 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6262 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6263 "{ A[a,b] -> B[b,a] : b > a }",
6264 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6265 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6266 "C[{ B[i,j] -> [i + 2j] }]",
6267 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6268 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6269 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6270 "(C[] : { B[a,b] })",
6271 "{ A[a,b] -> B[b,a] }",
6272 "(C[] : { A[a,b] })" },
6273 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6274 "(C[] : { B[a,b] })",
6275 "{ B[a,b] -> A[b,a] }",
6277 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6278 "(C[] : { B[a,b] })",
6279 "{ A[a,b] -> B[b,a] : a > b }",
6280 "(C[] : { A[a,b] : a > b })" },
6281 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6282 "(C[] : { B[a,b] : a > b })",
6283 "{ A[a,b] -> B[b,a] }",
6284 "(C[] : { A[a,b] : b > a })" },
6285 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6286 "[N] -> (C[] : { B[a,b] : a > N })",
6287 "{ A[a,b] -> B[b,a] : a > b }",
6288 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6289 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6290 "(C[] : { B[a,b] : a > b })",
6291 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6292 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6293 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6295 "{ A[a,b] -> B[b,a] }",
6297 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6298 "[N] -> (C[] : { : N >= 0 })",
6299 "{ A[a,b] -> B[b,a] }",
6300 "[N] -> (C[] : { : N >= 0 })" },
6301 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6303 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6304 "[N] -> (C[] : { : N >= 0 })" },
6307 /* Perform some basic tests of binary operations on
6308 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6310 static int test_mupa_upma(isl_ctx
*ctx
)
6314 isl_multi_union_pw_aff
*mupa
, *res
;
6315 isl_union_pw_multi_aff
*upma
;
6317 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
6318 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6319 mupa_upma_tests
[i
].arg1
);
6320 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
6321 mupa_upma_tests
[i
].arg2
);
6322 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6323 mupa_upma_tests
[i
].res
);
6324 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
6325 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6326 isl_multi_union_pw_aff_free(mupa
);
6327 isl_multi_union_pw_aff_free(res
);
6331 isl_die(ctx
, isl_error_unknown
,
6332 "unexpected result", return -1);
6338 /* Check that the input tuple of an isl_aff can be set properly.
6340 static isl_stat
test_aff_set_tuple_id(isl_ctx
*ctx
)
6346 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x + 1] }");
6347 id
= isl_id_alloc(ctx
, "A", NULL
);
6348 aff
= isl_aff_set_tuple_id(aff
, isl_dim_in
, id
);
6349 equal
= aff_check_plain_equal(aff
, "{ A[x] -> [x + 1] }");
6352 return isl_stat_error
;
6357 int test_aff(isl_ctx
*ctx
)
6362 isl_local_space
*ls
;
6366 if (test_upa(ctx
) < 0)
6368 if (test_bin_aff(ctx
) < 0)
6370 if (test_bin_pw_aff(ctx
) < 0)
6372 if (test_bin_upma(ctx
) < 0)
6374 if (test_bin_upma_fail(ctx
) < 0)
6376 if (test_un_mpa(ctx
) < 0)
6378 if (test_bin_mpa(ctx
) < 0)
6380 if (test_un_mupa(ctx
) < 0)
6382 if (test_bin_mupa(ctx
) < 0)
6384 if (test_mupa_set(ctx
) < 0)
6386 if (test_mupa_uset(ctx
) < 0)
6388 if (test_mupa_ma(ctx
) < 0)
6390 if (test_mupa_pa(ctx
) < 0)
6392 if (test_mupa_pma(ctx
) < 0)
6394 if (test_mupa_upma(ctx
) < 0)
6397 space
= isl_space_set_alloc(ctx
, 0, 1);
6398 ls
= isl_local_space_from_space(space
);
6399 aff
= isl_aff_zero_on_domain(ls
);
6401 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6402 aff
= isl_aff_scale_down_ui(aff
, 3);
6403 aff
= isl_aff_floor(aff
);
6404 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6405 aff
= isl_aff_scale_down_ui(aff
, 2);
6406 aff
= isl_aff_floor(aff
);
6407 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6410 set
= isl_set_read_from_str(ctx
, str
);
6411 aff
= isl_aff_gist(aff
, set
);
6413 aff
= isl_aff_add_constant_si(aff
, -16);
6414 zero
= isl_aff_plain_is_zero(aff
);
6420 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6422 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6423 aff
= isl_aff_scale_down_ui(aff
, 64);
6424 aff
= isl_aff_floor(aff
);
6425 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6430 if (test_aff_set_tuple_id(ctx
) < 0)
6436 /* Inputs for isl_set_bind tests.
6437 * "set" is the input set.
6438 * "tuple" is the binding tuple.
6439 * "res" is the expected result.
6446 } bind_set_tests
[] = {
6447 { "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6449 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6450 { "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }",
6452 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6453 { "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }",
6455 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6456 { "[M] -> { D[x, N] : x mod 2 = 0 and N mod 8 = 3 and M >= 0 }",
6458 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 and M >= 0 }" },
6461 /* Perform basic isl_set_bind tests.
6463 static isl_stat
test_bind_set(isl_ctx
*ctx
)
6467 for (i
= 0; i
< ARRAY_SIZE(bind_set_tests
); ++i
) {
6470 isl_multi_id
*tuple
;
6473 set
= isl_set_read_from_str(ctx
, bind_set_tests
[i
].set
);
6474 str
= bind_set_tests
[i
].tuple
;
6475 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6476 set
= isl_set_bind(set
, tuple
);
6477 r
= set_check_equal(set
, bind_set_tests
[i
].res
);
6480 return isl_stat_error
;
6486 /* Inputs for isl_map_bind_domain tests.
6487 * "map" is the input map.
6488 * "tuple" is the binding tuple.
6489 * "res" is the expected result.
6495 } bind_map_domain_tests
[] = {
6496 { "{ A[M, N] -> [M + floor(N/2)] }",
6498 "[M, N] -> { [M + floor(N/2)] }" },
6499 { "{ B[N, M] -> [M + floor(N/2)] }",
6501 "[N, M] -> { [M + floor(N/2)] }" },
6502 { "[M] -> { C[N] -> [M + floor(N/2)] }",
6504 "[M, N] -> { [M + floor(N/2)] }" },
6505 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
6507 "[M, N] -> { [M + floor(N/2)] }" },
6508 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
6510 "[M, N] -> { [M + floor(N/2)] }" },
6511 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
6513 "[A, N, M] -> { [M + floor(N/2)] }" },
6516 /* Perform basic isl_map_bind_domain tests.
6518 static isl_stat
test_bind_map_domain(isl_ctx
*ctx
)
6522 for (i
= 0; i
< ARRAY_SIZE(bind_map_domain_tests
); ++i
) {
6526 isl_multi_id
*tuple
;
6529 str
= bind_map_domain_tests
[i
].map
;
6530 map
= isl_map_read_from_str(ctx
, str
);
6531 str
= bind_map_domain_tests
[i
].tuple
;
6532 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6533 set
= isl_map_bind_domain(map
, tuple
);
6534 str
= bind_map_domain_tests
[i
].res
;
6535 r
= set_check_equal(set
, str
);
6538 return isl_stat_error
;
6544 /* Inputs for isl_union_map_bind_range tests.
6545 * "map" is the input union map.
6546 * "tuple" is the binding tuple.
6547 * "res" is the expected result.
6553 } bind_umap_range_tests
[] = {
6554 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6556 "[M, N] -> { B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
6557 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6560 { "{ A[] -> B[]; C[] -> D[]; E[] -> B[] }",
6565 /* Perform basic isl_union_map_bind_range tests.
6567 static isl_stat
test_bind_umap_range(isl_ctx
*ctx
)
6571 for (i
= 0; i
< ARRAY_SIZE(bind_umap_range_tests
); ++i
) {
6573 isl_union_map
*umap
;
6574 isl_union_set
*uset
;
6575 isl_multi_id
*tuple
;
6578 str
= bind_umap_range_tests
[i
].map
;
6579 umap
= isl_union_map_read_from_str(ctx
, str
);
6580 str
= bind_umap_range_tests
[i
].tuple
;
6581 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6582 uset
= isl_union_map_bind_range(umap
, tuple
);
6583 str
= bind_umap_range_tests
[i
].res
;
6584 r
= uset_check_equal(uset
, str
);
6585 isl_union_set_free(uset
);
6587 return isl_stat_error
;
6593 /* Inputs for isl_pw_multi_aff_bind_domain tests.
6594 * "pma" is the input expression.
6595 * "tuple" is the binding tuple.
6596 * "res" is the expected result.
6602 } bind_pma_domain_tests
[] = {
6603 { "{ A[M, N] -> [M + floor(N/2)] }",
6605 "[M, N] -> { [M + floor(N/2)] }" },
6606 { "{ B[N, M] -> [M + floor(N/2)] }",
6608 "[N, M] -> { [M + floor(N/2)] }" },
6609 { "[M] -> { C[N] -> [M + floor(N/2)] }",
6611 "[M, N] -> { [M + floor(N/2)] }" },
6612 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
6614 "[M, N] -> { [M + floor(N/2)] }" },
6615 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
6617 "[M, N] -> { [M + floor(N/2)] }" },
6618 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
6620 "[A, N, M] -> { [M + floor(N/2)] }" },
6623 /* Perform basic isl_pw_multi_aff_bind_domain tests.
6625 static isl_stat
test_bind_pma_domain(isl_ctx
*ctx
)
6629 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_tests
); ++i
) {
6631 isl_pw_multi_aff
*pma
;
6632 isl_multi_id
*tuple
;
6635 str
= bind_pma_domain_tests
[i
].pma
;
6636 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6637 str
= bind_pma_domain_tests
[i
].tuple
;
6638 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6639 pma
= isl_pw_multi_aff_bind_domain(pma
, tuple
);
6640 str
= bind_pma_domain_tests
[i
].res
;
6641 r
= pw_multi_aff_check_plain_equal(pma
, str
);
6642 isl_pw_multi_aff_free(pma
);
6644 return isl_stat_error
;
6650 /* Inputs for isl_pw_multi_aff_bind_domain_wrapped_domain tests.
6651 * "pma" is the input expression.
6652 * "tuple" is the binding tuple.
6653 * "res" is the expected result.
6659 } bind_pma_domain_wrapped_tests
[] = {
6660 { "{ [A[M, N] -> B[]] -> [M + floor(N/2)] }",
6662 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
6663 { "{ [B[N, M] -> D[]] -> [M + floor(N/2)] }",
6665 "[N, M] -> { D[] -> [M + floor(N/2)] }" },
6666 { "[M] -> { [C[N] -> B[x]] -> [x + M + floor(N/2)] }",
6668 "[M, N] -> { B[x] -> [x + M + floor(N/2)] }" },
6669 { "[M] -> { [C[x, N] -> B[]] -> [x + floor(N/2)] }",
6671 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
6672 { "[M] -> { [C[x, N] -> B[]] -> [M + floor(N/2)] }",
6674 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
6675 { "[A, M] -> { [C[N, x] -> B[]] -> [x + floor(N/2)] }",
6677 "[A, N, M] -> { B[] -> [M + floor(N/2)] }" },
6680 /* Perform basic isl_pw_multi_aff_bind_domain_wrapped_domain tests.
6682 static isl_stat
test_bind_pma_domain_wrapped(isl_ctx
*ctx
)
6686 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_wrapped_tests
); ++i
) {
6688 isl_pw_multi_aff
*pma
;
6689 isl_multi_id
*tuple
;
6692 str
= bind_pma_domain_wrapped_tests
[i
].pma
;
6693 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6694 str
= bind_pma_domain_wrapped_tests
[i
].tuple
;
6695 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6696 pma
= isl_pw_multi_aff_bind_domain_wrapped_domain(pma
, tuple
);
6697 str
= bind_pma_domain_wrapped_tests
[i
].res
;
6698 r
= pw_multi_aff_check_plain_equal(pma
, str
);
6699 isl_pw_multi_aff_free(pma
);
6701 return isl_stat_error
;
6707 /* Inputs for isl_aff_bind_id tests.
6708 * "aff" is the input expression.
6709 * "id" is the binding id.
6710 * "res" is the expected result.
6717 } bind_aff_tests
[] = {
6718 { "{ [4] }", "M", "[M = 4] -> { : }" },
6719 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
6720 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
6721 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
6722 { "{ [NaN] }", "M", "{ : false }" },
6723 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
6726 /* Perform basic isl_aff_bind_id tests.
6728 static isl_stat
test_bind_aff(isl_ctx
*ctx
)
6732 for (i
= 0; i
< ARRAY_SIZE(bind_aff_tests
); ++i
) {
6738 aff
= isl_aff_read_from_str(ctx
, bind_aff_tests
[i
].aff
);
6739 id
= isl_id_read_from_str(ctx
, bind_aff_tests
[i
].id
);
6740 res
= isl_set_from_basic_set(isl_aff_bind_id(aff
, id
));
6741 r
= set_check_equal(res
, bind_aff_tests
[i
].res
);
6744 return isl_stat_error
;
6750 /* Inputs for isl_pw_aff_bind_id tests.
6751 * "pa" is the input expression.
6752 * "id" is the binding id.
6753 * "res" is the expected result.
6760 } bind_pa_tests
[] = {
6761 { "{ [4] }", "M", "[M = 4] -> { : }" },
6762 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
6763 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
6764 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
6765 { "[M] -> { [M] : M >= 0; [-M] : M < 0 }", "M", "[M] -> { : M >= 0 }" },
6766 { "{ [NaN] }", "M", "{ : false }" },
6767 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
6770 /* Perform basic isl_pw_aff_bind_id tests.
6772 static isl_stat
test_bind_pa(isl_ctx
*ctx
)
6776 for (i
= 0; i
< ARRAY_SIZE(bind_pa_tests
); ++i
) {
6782 pa
= isl_pw_aff_read_from_str(ctx
, bind_pa_tests
[i
].pa
);
6783 id
= isl_id_read_from_str(ctx
, bind_pa_tests
[i
].id
);
6784 res
= isl_pw_aff_bind_id(pa
, id
);
6785 r
= set_check_equal(res
, bind_pa_tests
[i
].res
);
6788 return isl_stat_error
;
6794 /* Inputs for isl_multi_union_pw_aff_bind tests.
6795 * "mupa" is the input expression.
6796 * "tuple" is the binding tuple.
6797 * "res" is the expected result.
6804 } bind_mupa_tests
[] = {
6805 { "A[{ [4] }, { [5] }]",
6807 "[M = 4, N = 5] -> { : }" },
6808 { "A[{ B[x] -> [floor(x/2)] }, { B[y] -> [y + 5] }]",
6810 "[M, N] -> { B[x] : M = floor(x/2) and N = x + 5 }" },
6811 { "[M] -> A[{ [4] }, { [M + 1] }]",
6813 "[M = 4, N = 5] -> { : }" },
6816 /* Perform basic isl_multi_union_pw_aff_bind tests.
6818 static isl_stat
test_bind_mupa(isl_ctx
*ctx
)
6822 for (i
= 0; i
< ARRAY_SIZE(bind_mupa_tests
); ++i
) {
6824 isl_multi_union_pw_aff
*mupa
;
6826 isl_multi_id
*tuple
;
6829 str
= bind_mupa_tests
[i
].mupa
;
6830 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6831 str
= bind_mupa_tests
[i
].tuple
;
6832 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6833 res
= isl_multi_union_pw_aff_bind(mupa
, tuple
);
6834 r
= uset_check_equal(res
, bind_mupa_tests
[i
].res
);
6835 isl_union_set_free(res
);
6837 return isl_stat_error
;
6843 /* Perform tests that reinterpret dimensions as parameters.
6845 static int test_bind(isl_ctx
*ctx
)
6847 if (test_bind_set(ctx
) < 0)
6849 if (test_bind_map_domain(ctx
) < 0)
6851 if (test_bind_umap_range(ctx
) < 0)
6853 if (test_bind_pma_domain(ctx
) < 0)
6855 if (test_bind_pma_domain_wrapped(ctx
) < 0)
6857 if (test_bind_aff(ctx
) < 0)
6859 if (test_bind_pa(ctx
) < 0)
6861 if (test_bind_mupa(ctx
) < 0)
6867 /* Inputs for isl_set_unbind_params tests.
6868 * "set" is the input parameter domain.
6869 * "tuple" is the tuple of the constructed set.
6870 * "res" is the expected result.
6876 } unbind_set_tests
[] = {
6877 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
6879 "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }" },
6880 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
6882 "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
6883 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
6885 "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }" },
6886 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
6888 "[M] -> { D[x, N] : M mod 2 = 0 and N mod 8 = 3 }" },
6891 /* Perform basic isl_set_unbind_params tests.
6893 static isl_stat
test_unbind_set(isl_ctx
*ctx
)
6897 for (i
= 0; i
< ARRAY_SIZE(unbind_set_tests
); ++i
) {
6900 isl_multi_id
*tuple
;
6903 set
= isl_set_read_from_str(ctx
, unbind_set_tests
[i
].set
);
6904 str
= unbind_set_tests
[i
].tuple
;
6905 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6906 set
= isl_set_unbind_params(set
, tuple
);
6907 r
= set_check_equal(set
, unbind_set_tests
[i
].res
);
6910 return isl_stat_error
;
6916 /* Inputs for isl_aff_unbind_params_insert_domain tests.
6917 * "aff" is the input affine expression defined over a parameter domain.
6918 * "tuple" is the tuple of the domain that gets introduced.
6919 * "res" is the expected result.
6925 } unbind_aff_tests
[] = {
6926 { "[M, N] -> { [M + floor(N/2)] }",
6928 "{ A[M, N] -> [M + floor(N/2)] }" },
6929 { "[M, N] -> { [M + floor(N/2)] }",
6931 "{ B[N, M] -> [M + floor(N/2)] }" },
6932 { "[M, N] -> { [M + floor(N/2)] }",
6934 "[M] -> { C[N] -> [M + floor(N/2)] }" },
6935 { "[M, N] -> { [M + floor(N/2)] }",
6936 "{ D[A, B, C, N, Z] }",
6937 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
6940 /* Perform basic isl_aff_unbind_params_insert_domain tests.
6942 static isl_stat
test_unbind_aff(isl_ctx
*ctx
)
6946 for (i
= 0; i
< ARRAY_SIZE(unbind_aff_tests
); ++i
) {
6949 isl_multi_id
*tuple
;
6952 aff
= isl_aff_read_from_str(ctx
, unbind_aff_tests
[i
].aff
);
6953 str
= unbind_aff_tests
[i
].tuple
;
6954 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6955 aff
= isl_aff_unbind_params_insert_domain(aff
, tuple
);
6956 r
= aff_check_plain_equal(aff
, unbind_aff_tests
[i
].res
);
6959 return isl_stat_error
;
6965 /* Perform tests that reinterpret parameters.
6967 static int test_unbind(isl_ctx
*ctx
)
6969 if (test_unbind_set(ctx
) < 0)
6971 if (test_unbind_aff(ctx
) < 0)
6977 /* Check that "pa" consists of a single expression.
6979 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
6983 n
= isl_pw_aff_n_piece(pa
);
6984 isl_pw_aff_free(pa
);
6989 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
6995 /* Check that the computation below results in a single expression.
6996 * One or two expressions may result depending on which constraint
6997 * ends up being considered as redundant with respect to the other
6998 * constraints after the projection that is performed internally
6999 * by isl_set_dim_min.
7001 static int test_dim_max_1(isl_ctx
*ctx
)
7007 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
7008 "-4a <= b <= 3 and b < n - 4a }";
7009 set
= isl_set_read_from_str(ctx
, str
);
7010 pa
= isl_set_dim_min(set
, 0);
7011 return check_single_piece(ctx
, pa
);
7014 /* Check that the computation below results in a single expression.
7015 * The PIP problem corresponding to these constraints has a row
7016 * that causes a split of the solution domain. The solver should
7017 * first pick rows that split off empty parts such that the actual
7018 * solution domain does not get split.
7019 * Note that the description contains some redundant constraints.
7020 * If these constraints get removed first, then the row mentioned
7021 * above does not appear in the PIP problem.
7023 static int test_dim_max_2(isl_ctx
*ctx
)
7029 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
7030 "N > 0 and P >= 0 }";
7031 set
= isl_set_read_from_str(ctx
, str
);
7032 pa
= isl_set_dim_max(set
, 0);
7033 return check_single_piece(ctx
, pa
);
7036 int test_dim_max(isl_ctx
*ctx
)
7040 isl_set
*set1
, *set2
;
7045 if (test_dim_max_1(ctx
) < 0)
7047 if (test_dim_max_2(ctx
) < 0)
7050 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
7051 set
= isl_set_read_from_str(ctx
, str
);
7052 pwaff
= isl_set_dim_max(set
, 0);
7053 set1
= isl_set_from_pw_aff(pwaff
);
7054 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
7055 set2
= isl_set_read_from_str(ctx
, str
);
7056 equal
= isl_set_is_equal(set1
, set2
);
7062 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7064 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
7065 set
= isl_set_read_from_str(ctx
, str
);
7066 pwaff
= isl_set_dim_max(set
, 0);
7067 set1
= isl_set_from_pw_aff(pwaff
);
7068 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7069 set2
= isl_set_read_from_str(ctx
, str
);
7070 equal
= isl_set_is_equal(set1
, set2
);
7076 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7078 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
7079 set
= isl_set_read_from_str(ctx
, str
);
7080 pwaff
= isl_set_dim_max(set
, 0);
7081 set1
= isl_set_from_pw_aff(pwaff
);
7082 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7083 set2
= isl_set_read_from_str(ctx
, str
);
7084 equal
= isl_set_is_equal(set1
, set2
);
7090 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7092 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
7093 "0 <= i < N and 0 <= j < M }";
7094 map
= isl_map_read_from_str(ctx
, str
);
7095 set
= isl_map_range(map
);
7097 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
7098 set1
= isl_set_from_pw_aff(pwaff
);
7099 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
7100 set2
= isl_set_read_from_str(ctx
, str
);
7101 equal
= isl_set_is_equal(set1
, set2
);
7105 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
7106 set1
= isl_set_from_pw_aff(pwaff
);
7107 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
7108 set2
= isl_set_read_from_str(ctx
, str
);
7109 if (equal
>= 0 && equal
)
7110 equal
= isl_set_is_equal(set1
, set2
);
7119 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7121 /* Check that solutions are properly merged. */
7122 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
7123 "c <= -1 + n - 4a - 2b and c >= -2b and "
7124 "4a >= -4 + n and c >= 0 }";
7125 set
= isl_set_read_from_str(ctx
, str
);
7126 pwaff
= isl_set_dim_min(set
, 2);
7127 set1
= isl_set_from_pw_aff(pwaff
);
7128 str
= "[n] -> { [(0)] : n >= 1 }";
7129 set2
= isl_set_read_from_str(ctx
, str
);
7130 equal
= isl_set_is_equal(set1
, set2
);
7137 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7139 /* Check that empty solution lie in the right space. */
7140 str
= "[n] -> { [t,a] : 1 = 0 }";
7141 set
= isl_set_read_from_str(ctx
, str
);
7142 pwaff
= isl_set_dim_max(set
, 0);
7143 set1
= isl_set_from_pw_aff(pwaff
);
7144 str
= "[n] -> { [t] : 1 = 0 }";
7145 set2
= isl_set_read_from_str(ctx
, str
);
7146 equal
= isl_set_is_equal(set1
, set2
);
7153 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7158 /* Basic test for isl_pw_multi_aff_product.
7160 * Check that multiple pieces are properly handled.
7162 static int test_product_pma(isl_ctx
*ctx
)
7166 isl_pw_multi_aff
*pma1
, *pma2
;
7168 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
7169 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7170 str
= "{ C[] -> D[] }";
7171 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7172 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
7173 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
7174 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
7175 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
7176 isl_pw_multi_aff_free(pma1
);
7183 int test_product(isl_ctx
*ctx
)
7187 isl_union_set
*uset1
, *uset2
;
7191 set
= isl_set_read_from_str(ctx
, str
);
7192 set
= isl_set_product(set
, isl_set_copy(set
));
7193 ok
= isl_set_is_wrapping(set
);
7198 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7201 uset1
= isl_union_set_read_from_str(ctx
, str
);
7202 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
7203 str
= "{ [[] -> []] }";
7204 uset2
= isl_union_set_read_from_str(ctx
, str
);
7205 ok
= isl_union_set_is_equal(uset1
, uset2
);
7206 isl_union_set_free(uset1
);
7207 isl_union_set_free(uset2
);
7211 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7213 if (test_product_pma(ctx
) < 0)
7219 /* Check that two sets are not considered disjoint just because
7220 * they have a different set of (named) parameters.
7222 static int test_disjoint(isl_ctx
*ctx
)
7225 isl_set
*set
, *set2
;
7228 str
= "[n] -> { [[]->[]] }";
7229 set
= isl_set_read_from_str(ctx
, str
);
7230 str
= "{ [[]->[]] }";
7231 set2
= isl_set_read_from_str(ctx
, str
);
7232 disjoint
= isl_set_is_disjoint(set
, set2
);
7238 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7243 /* Inputs for isl_pw_multi_aff_is_equal tests.
7244 * "f1" and "f2" are the two function that need to be compared.
7245 * "equal" is the expected result.
7251 } pma_equal_tests
[] = {
7252 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
7253 "[N] -> { [0] : 0 <= N <= 1 }" },
7254 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7255 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
7256 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7257 "[N] -> { [0] : 0 <= N <= 1 }" },
7258 { 0, "{ [NaN] }", "{ [NaN] }" },
7261 int test_equal(isl_ctx
*ctx
)
7265 isl_set
*set
, *set2
;
7269 set
= isl_set_read_from_str(ctx
, str
);
7271 set2
= isl_set_read_from_str(ctx
, str
);
7272 equal
= isl_set_is_equal(set
, set2
);
7278 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7280 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
7281 int expected
= pma_equal_tests
[i
].equal
;
7282 isl_pw_multi_aff
*f1
, *f2
;
7284 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
7285 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
7286 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
7287 isl_pw_multi_aff_free(f1
);
7288 isl_pw_multi_aff_free(f2
);
7291 if (equal
!= expected
)
7292 isl_die(ctx
, isl_error_unknown
,
7293 "unexpected equality result", return -1);
7299 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
7300 enum isl_dim_type type
, unsigned pos
, int fixed
)
7304 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
7311 isl_die(ctx
, isl_error_unknown
,
7312 "map not detected as fixed", return -1);
7314 isl_die(ctx
, isl_error_unknown
,
7315 "map detected as fixed", return -1);
7318 int test_fixed(isl_ctx
*ctx
)
7323 str
= "{ [i] -> [i] }";
7324 map
= isl_map_read_from_str(ctx
, str
);
7325 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
7327 str
= "{ [i] -> [1] }";
7328 map
= isl_map_read_from_str(ctx
, str
);
7329 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7331 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
7332 map
= isl_map_read_from_str(ctx
, str
);
7333 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7335 map
= isl_map_read_from_str(ctx
, str
);
7336 map
= isl_map_neg(map
);
7337 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7343 struct isl_vertices_test_data
{
7346 const char *vertex
[6];
7347 } vertices_tests
[] = {
7348 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
7349 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
7350 { "{ A[t, i] : t = 14 and i = 1 }",
7351 1, { "{ A[14, 1] }" } },
7352 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
7353 "c <= m and m <= n and m > 0 }",
7355 "[n, m] -> { [n, m, m] : 0 < m <= n }",
7356 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
7357 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
7358 "[n, m] -> { [m, m, m] : 0 < m <= n }",
7359 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
7360 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
7364 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
7366 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
7368 struct isl_vertices_test_data
*data
= user
;
7371 isl_basic_set
*bset
;
7372 isl_pw_multi_aff
*pma
;
7376 ctx
= isl_vertex_get_ctx(vertex
);
7377 bset
= isl_vertex_get_domain(vertex
);
7378 ma
= isl_vertex_get_expr(vertex
);
7379 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
7381 for (i
= 0; i
< data
->n
; ++i
) {
7382 isl_pw_multi_aff
*pma_i
;
7384 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
7385 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
7386 isl_pw_multi_aff_free(pma_i
);
7388 if (equal
< 0 || equal
)
7392 isl_pw_multi_aff_free(pma
);
7393 isl_vertex_free(vertex
);
7396 return isl_stat_error
;
7398 return equal
? isl_stat_ok
: isl_stat_error
;
7401 int test_vertices(isl_ctx
*ctx
)
7405 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
7406 isl_basic_set
*bset
;
7407 isl_vertices
*vertices
;
7411 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
7412 vertices
= isl_basic_set_compute_vertices(bset
);
7413 n
= isl_vertices_get_n_vertices(vertices
);
7414 if (vertices_tests
[i
].n
!= n
)
7416 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
7417 &vertices_tests
[i
]) < 0)
7419 isl_vertices_free(vertices
);
7420 isl_basic_set_free(bset
);
7425 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
7432 int test_union_pw(isl_ctx
*ctx
)
7436 isl_union_set
*uset
;
7437 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
7439 str
= "{ [x] -> x^2 }";
7440 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
7441 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
7442 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
7443 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
7444 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
7445 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
7446 isl_union_pw_qpolynomial_free(upwqp1
);
7447 isl_union_pw_qpolynomial_free(upwqp2
);
7451 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7456 /* Inputs for basic tests of functions that select
7457 * subparts of the domain of an isl_multi_union_pw_aff.
7458 * "fn" is the function that is tested.
7459 * "arg" is a string description of the input.
7460 * "res" is a string description of the expected result.
7463 __isl_give isl_union_set
*(*fn
)(
7464 __isl_take isl_multi_union_pw_aff
*mupa
);
7467 } un_locus_tests
[] = {
7468 { &isl_multi_union_pw_aff_zero_union_set
,
7469 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
7470 "{ A[0,j]; B[0,j] }" },
7471 { &isl_multi_union_pw_aff_zero_union_set
,
7472 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
7473 "{ A[i,i]; B[i,i] : i >= 0 }" },
7474 { &isl_multi_union_pw_aff_zero_union_set
,
7475 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
7476 "{ A[i,j]; B[i,i] : i >= 0 }" },
7479 /* Perform some basic tests of functions that select
7480 * subparts of the domain of an isl_multi_union_pw_aff.
7482 static int test_un_locus(isl_ctx
*ctx
)
7486 isl_union_set
*uset
, *res
;
7487 isl_multi_union_pw_aff
*mupa
;
7489 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
7490 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
7491 un_locus_tests
[i
].arg
);
7492 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
7493 uset
= un_locus_tests
[i
].fn(mupa
);
7494 ok
= isl_union_set_is_equal(uset
, res
);
7495 isl_union_set_free(uset
);
7496 isl_union_set_free(res
);
7500 isl_die(ctx
, isl_error_unknown
,
7501 "unexpected result", return -1);
7507 /* Inputs for basic tests of functions that select
7508 * subparts of an isl_union_map based on a relation
7509 * specified by an isl_multi_union_pw_aff.
7510 * "fn" is the function that is tested.
7511 * "arg1" and "arg2" are string descriptions of the inputs.
7512 * "res" is a string description of the expected result.
7515 __isl_give isl_union_map
*(*fn
)(
7516 __isl_take isl_union_map
*umap
,
7517 __isl_take isl_multi_union_pw_aff
*mupa
);
7521 } bin_locus_tests
[] = {
7522 { &isl_union_map_eq_at_multi_union_pw_aff
,
7523 "{ A[i,j] -> B[i',j'] }",
7524 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
7525 "{ A[i,j] -> B[i,j'] }" },
7526 { &isl_union_map_eq_at_multi_union_pw_aff
,
7527 "{ A[i,j] -> B[i',j'] }",
7528 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
7529 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
7530 "{ A[i,j] -> B[i,j] }" },
7531 { &isl_union_map_eq_at_multi_union_pw_aff
,
7532 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
7533 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
7534 "{ A[i,j] -> B[i,j'] }" },
7535 { &isl_union_map_eq_at_multi_union_pw_aff
,
7536 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
7537 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
7538 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
7539 { &isl_union_map_eq_at_multi_union_pw_aff
,
7540 "{ A[i,j] -> B[i',j'] }",
7541 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
7542 "{ A[i,j] -> B[i,j'] : i > j }" },
7543 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
7544 "{ A[i,j] -> B[i',j'] }",
7545 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
7546 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
7547 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
7548 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
7549 "{ A[i,j] -> B[i',j'] }",
7550 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
7551 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
7552 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
7553 { &isl_union_map_eq_at_multi_union_pw_aff
,
7554 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
7555 "(F[] : { A[i,j]; B[i,j] })",
7556 "{ A[i,j] -> B[i',j'] }" },
7557 { &isl_union_map_eq_at_multi_union_pw_aff
,
7558 "{ A[i,j] -> B[i',j'] }",
7559 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
7560 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
7561 { &isl_union_map_eq_at_multi_union_pw_aff
,
7562 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
7563 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
7564 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
7565 { &isl_union_map_eq_at_multi_union_pw_aff
,
7566 "{ A[i,j] -> B[i',j'] }",
7567 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
7568 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
7569 { &isl_union_map_eq_at_multi_union_pw_aff
,
7570 "{ A[i,j] -> B[i',j'] }",
7571 "[N] -> (F[] : { : N >= 0 })",
7572 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
7575 /* Perform some basic tests of functions that select
7576 * subparts of an isl_union_map based on a relation
7577 * specified by an isl_multi_union_pw_aff.
7579 static int test_bin_locus(isl_ctx
*ctx
)
7583 isl_union_map
*umap
, *res
;
7584 isl_multi_union_pw_aff
*mupa
;
7586 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
7587 umap
= isl_union_map_read_from_str(ctx
,
7588 bin_locus_tests
[i
].arg1
);
7589 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
7590 bin_locus_tests
[i
].arg2
);
7591 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
7592 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
7593 ok
= isl_union_map_is_equal(umap
, res
);
7594 isl_union_map_free(umap
);
7595 isl_union_map_free(res
);
7599 isl_die(ctx
, isl_error_unknown
,
7600 "unexpected result", return -1);
7606 /* Perform basic locus tests.
7608 static int test_locus(isl_ctx
*ctx
)
7610 if (test_un_locus(ctx
) < 0)
7612 if (test_bin_locus(ctx
) < 0)
7617 /* Test that isl_union_pw_qpolynomial_eval picks up the function
7618 * defined over the correct domain space.
7620 static int test_eval_1(isl_ctx
*ctx
)
7625 isl_union_pw_qpolynomial
*upwqp
;
7629 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
7630 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
7632 set
= isl_set_read_from_str(ctx
, str
);
7633 pnt
= isl_set_sample_point(set
);
7634 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
7635 cmp
= isl_val_cmp_si(v
, 36);
7641 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
7646 /* Check that isl_qpolynomial_eval handles getting called on a void point.
7648 static int test_eval_2(isl_ctx
*ctx
)
7653 isl_qpolynomial
*qp
;
7657 str
= "{ A[x] -> [x] }";
7658 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
7659 str
= "{ A[x] : false }";
7660 set
= isl_set_read_from_str(ctx
, str
);
7661 pnt
= isl_set_sample_point(set
);
7662 v
= isl_qpolynomial_eval(qp
, pnt
);
7663 ok
= isl_val_is_nan(v
);
7669 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
7674 /* Check that a polynomial (without local variables) can be evaluated
7675 * in a rational point.
7677 static isl_stat
test_eval_3(isl_ctx
*ctx
)
7679 isl_pw_qpolynomial
*pwqp
;
7684 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, "{ [x] -> x^2 }");
7685 pnt
= isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp
));
7686 v
= isl_val_read_from_str(ctx
, "1/2");
7687 pnt
= isl_point_set_coordinate_val(pnt
, isl_dim_set
, 0, v
);
7688 v
= isl_pw_qpolynomial_eval(pwqp
, pnt
);
7689 r
= val_check_equal(v
, "1/4");
7695 /* Inputs for isl_pw_aff_eval test.
7696 * "f" is the affine function.
7697 * "p" is the point where the function should be evaluated.
7698 * "res" is the expected result.
7704 } aff_eval_tests
[] = {
7705 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
7706 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
7707 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
7708 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
7709 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
7710 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
7711 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
7712 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
7713 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
7714 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
7715 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
7716 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
7717 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
7718 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
7719 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
7720 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
7721 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
7722 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
7723 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
7724 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
7725 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
7726 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
7727 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
7730 /* Perform basic isl_pw_aff_eval tests.
7732 static int test_eval_aff(isl_ctx
*ctx
)
7736 for (i
= 0; i
< ARRAY_SIZE(aff_eval_tests
); ++i
) {
7743 pa
= isl_pw_aff_read_from_str(ctx
, aff_eval_tests
[i
].f
);
7744 set
= isl_set_read_from_str(ctx
, aff_eval_tests
[i
].p
);
7745 pnt
= isl_set_sample_point(set
);
7746 v
= isl_pw_aff_eval(pa
, pnt
);
7747 r
= val_check_equal(v
, aff_eval_tests
[i
].res
);
7755 /* Perform basic evaluation tests.
7757 static int test_eval(isl_ctx
*ctx
)
7759 if (test_eval_1(ctx
) < 0)
7761 if (test_eval_2(ctx
) < 0)
7763 if (test_eval_3(ctx
) < 0)
7765 if (test_eval_aff(ctx
) < 0)
7770 /* Descriptions of sets that are tested for reparsing after printing.
7772 const char *output_tests
[] = {
7773 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
7776 "{ [x] : x mod 2 = 0 }",
7777 "{ [x] : x mod 2 = 1 }",
7778 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
7779 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
7780 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
7781 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
7782 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
7783 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
7786 /* Check that printing a set and reparsing a set from the printed output
7787 * results in the same set.
7789 static int test_output_set(isl_ctx
*ctx
)
7793 isl_set
*set1
, *set2
;
7796 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
7797 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
7798 str
= isl_set_to_str(set1
);
7799 set2
= isl_set_read_from_str(ctx
, str
);
7801 equal
= isl_set_is_equal(set1
, set2
);
7807 isl_die(ctx
, isl_error_unknown
,
7808 "parsed output not the same", return -1);
7814 /* Check that an isl_multi_aff is printed using a consistent space.
7816 static isl_stat
test_output_ma(isl_ctx
*ctx
)
7821 isl_multi_aff
*ma
, *ma2
;
7823 ma
= isl_multi_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
7824 aff
= isl_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
7825 ma
= isl_multi_aff_set_aff(ma
, 0, aff
);
7826 str
= isl_multi_aff_to_str(ma
);
7827 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
7829 equal
= isl_multi_aff_plain_is_equal(ma
, ma2
);
7830 isl_multi_aff_free(ma2
);
7831 isl_multi_aff_free(ma
);
7834 return isl_stat_error
;
7836 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7837 return isl_stat_error
);
7842 /* Check that an isl_multi_pw_aff is printed using a consistent space.
7844 static isl_stat
test_output_mpa(isl_ctx
*ctx
)
7849 isl_multi_pw_aff
*mpa
, *mpa2
;
7851 mpa
= isl_multi_pw_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
7852 pa
= isl_pw_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
7853 mpa
= isl_multi_pw_aff_set_pw_aff(mpa
, 0, pa
);
7854 str
= isl_multi_pw_aff_to_str(mpa
);
7855 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
7857 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
7858 isl_multi_pw_aff_free(mpa2
);
7859 isl_multi_pw_aff_free(mpa
);
7862 return isl_stat_error
;
7864 isl_die(ctx
, isl_error_unknown
, "bad conversion",
7865 return isl_stat_error
);
7870 int test_output(isl_ctx
*ctx
)
7878 if (test_output_set(ctx
) < 0)
7880 if (test_output_ma(ctx
) < 0)
7882 if (test_output_mpa(ctx
) < 0)
7885 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
7886 pa
= isl_pw_aff_read_from_str(ctx
, str
);
7888 p
= isl_printer_to_str(ctx
);
7889 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
7890 p
= isl_printer_print_pw_aff(p
, pa
);
7891 s
= isl_printer_get_str(p
);
7892 isl_printer_free(p
);
7893 isl_pw_aff_free(pa
);
7897 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
7902 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7907 int test_sample(isl_ctx
*ctx
)
7910 isl_basic_set
*bset1
, *bset2
;
7913 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
7914 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
7915 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
7916 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
7917 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
7918 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
7919 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
7920 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
7921 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
7922 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
7923 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
7924 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
7925 "d - 1073741821e and "
7926 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
7927 "3j >= 1 - a + b + 2e and "
7928 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
7929 "3i <= 4 - a + 4b - e and "
7930 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
7931 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
7932 "c <= -1 + a and 3i >= -2 - a + 3e and "
7933 "1073741822e <= 1073741823 - a + 1073741822b + c and "
7934 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
7935 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
7936 "1073741823e >= 1 + 1073741823b - d and "
7937 "3i >= 1073741823b + c - 1073741823e - f and "
7938 "3i >= 1 + 2b + e + 3g }";
7939 bset1
= isl_basic_set_read_from_str(ctx
, str
);
7940 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
7941 empty
= isl_basic_set_is_empty(bset2
);
7942 subset
= isl_basic_set_is_subset(bset2
, bset1
);
7943 isl_basic_set_free(bset1
);
7944 isl_basic_set_free(bset2
);
7945 if (empty
< 0 || subset
< 0)
7948 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
7950 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
7955 int test_fixed_power(isl_ctx
*ctx
)
7962 str
= "{ [i] -> [i + 1] }";
7963 map
= isl_map_read_from_str(ctx
, str
);
7964 exp
= isl_val_int_from_si(ctx
, 23);
7965 map
= isl_map_fixed_power_val(map
, exp
);
7966 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
7974 int test_slice(isl_ctx
*ctx
)
7980 str
= "{ [i] -> [j] }";
7981 map
= isl_map_read_from_str(ctx
, str
);
7982 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7983 equal
= map_check_equal(map
, "{ [i] -> [i] }");
7988 str
= "{ [i] -> [j] }";
7989 map
= isl_map_read_from_str(ctx
, str
);
7990 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
7991 equal
= map_check_equal(map
, "{ [i] -> [j] }");
7996 str
= "{ [i] -> [j] }";
7997 map
= isl_map_read_from_str(ctx
, str
);
7998 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
7999 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
8004 str
= "{ [i] -> [j] }";
8005 map
= isl_map_read_from_str(ctx
, str
);
8006 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8007 equal
= map_check_equal(map
, "{ [0] -> [j] }");
8012 str
= "{ [i] -> [j] }";
8013 map
= isl_map_read_from_str(ctx
, str
);
8014 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8015 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
8020 str
= "{ [i] -> [j] }";
8021 map
= isl_map_read_from_str(ctx
, str
);
8022 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8023 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
8031 int test_eliminate(isl_ctx
*ctx
)
8037 str
= "{ [i] -> [j] : i = 2j }";
8038 map
= isl_map_read_from_str(ctx
, str
);
8039 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
8040 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
8048 /* Check basic functionality of isl_map_deltas_map.
8050 static int test_deltas_map(isl_ctx
*ctx
)
8056 str
= "{ A[i] -> A[i + 1] }";
8057 map
= isl_map_read_from_str(ctx
, str
);
8058 map
= isl_map_deltas_map(map
);
8059 equal
= map_check_equal(map
, "{ [A[i] -> A[i + 1]] -> A[1] }");
8067 /* Check that isl_set_dim_residue_class detects that the values of j
8068 * in the set below are all odd and that it does not detect any spurious
8071 static int test_residue_class(isl_ctx
*ctx
)
8078 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
8079 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
8080 set
= isl_set_read_from_str(ctx
, str
);
8083 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
8085 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
8086 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
8087 res
= isl_stat_error
);
8095 static int test_align_parameters_1(isl_ctx
*ctx
)
8099 isl_multi_aff
*ma1
, *ma2
;
8102 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
8103 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
8105 space
= isl_space_params_alloc(ctx
, 1);
8106 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
8107 ma1
= isl_multi_aff_align_params(ma1
, space
);
8109 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
8110 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8112 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
8114 isl_multi_aff_free(ma1
);
8115 isl_multi_aff_free(ma2
);
8120 isl_die(ctx
, isl_error_unknown
,
8121 "result not as expected", return -1);
8126 /* Check the isl_multi_*_from_*_list operation in case inputs
8127 * have unaligned parameters.
8128 * In particular, older versions of isl would simply fail
8129 * (without printing any error message).
8131 static isl_stat
test_align_parameters_2(isl_ctx
*ctx
)
8138 map
= isl_map_read_from_str(ctx
, "{ A[] -> M[x] }");
8139 space
= isl_map_get_space(map
);
8142 aff
= isl_aff_read_from_str(ctx
, "[N] -> { A[] -> [N] }");
8143 ma
= isl_multi_aff_from_aff_list(space
, isl_aff_list_from_aff(aff
));
8144 isl_multi_aff_free(ma
);
8147 return isl_stat_error
;
8151 /* Perform basic parameter alignment tests.
8153 static int test_align_parameters(isl_ctx
*ctx
)
8155 if (test_align_parameters_1(ctx
) < 0)
8157 if (test_align_parameters_2(ctx
) < 0)
8163 /* Check that isl_*_drop_unused_params actually drops the unused parameters
8164 * by comparing the result using isl_*_plain_is_equal.
8165 * Note that this assumes that isl_*_plain_is_equal does not consider
8166 * objects that only differ by unused parameters to be equal.
8168 int test_drop_unused_parameters(isl_ctx
*ctx
)
8170 const char *str_with
, *str_without
;
8171 isl_basic_set
*bset1
, *bset2
;
8172 isl_set
*set1
, *set2
;
8173 isl_pw_aff
*pwa1
, *pwa2
;
8176 str_with
= "[n, m, o] -> { [m] }";
8177 str_without
= "[m] -> { [m] }";
8179 bset1
= isl_basic_set_read_from_str(ctx
, str_with
);
8180 bset2
= isl_basic_set_read_from_str(ctx
, str_without
);
8181 bset1
= isl_basic_set_drop_unused_params(bset1
);
8182 equal
= isl_basic_set_plain_is_equal(bset1
, bset2
);
8183 isl_basic_set_free(bset1
);
8184 isl_basic_set_free(bset2
);
8189 isl_die(ctx
, isl_error_unknown
,
8190 "result not as expected", return -1);
8192 set1
= isl_set_read_from_str(ctx
, str_with
);
8193 set2
= isl_set_read_from_str(ctx
, str_without
);
8194 set1
= isl_set_drop_unused_params(set1
);
8195 equal
= isl_set_plain_is_equal(set1
, set2
);
8202 isl_die(ctx
, isl_error_unknown
,
8203 "result not as expected", return -1);
8205 pwa1
= isl_pw_aff_read_from_str(ctx
, str_with
);
8206 pwa2
= isl_pw_aff_read_from_str(ctx
, str_without
);
8207 pwa1
= isl_pw_aff_drop_unused_params(pwa1
);
8208 equal
= isl_pw_aff_plain_is_equal(pwa1
, pwa2
);
8209 isl_pw_aff_free(pwa1
);
8210 isl_pw_aff_free(pwa2
);
8215 isl_die(ctx
, isl_error_unknown
,
8216 "result not as expected", return -1);
8221 static int test_list(isl_ctx
*ctx
)
8223 isl_id
*a
, *b
, *c
, *d
, *id
;
8228 a
= isl_id_alloc(ctx
, "a", NULL
);
8229 b
= isl_id_alloc(ctx
, "b", NULL
);
8230 c
= isl_id_alloc(ctx
, "c", NULL
);
8231 d
= isl_id_alloc(ctx
, "d", NULL
);
8233 list
= isl_id_list_alloc(ctx
, 4);
8234 list
= isl_id_list_add(list
, b
);
8235 list
= isl_id_list_insert(list
, 0, a
);
8236 list
= isl_id_list_add(list
, c
);
8237 list
= isl_id_list_add(list
, d
);
8238 list
= isl_id_list_drop(list
, 1, 1);
8240 n
= isl_id_list_n_id(list
);
8244 isl_id_list_free(list
);
8245 isl_die(ctx
, isl_error_unknown
,
8246 "unexpected number of elements in list", return -1);
8249 id
= isl_id_list_get_id(list
, 0);
8252 id
= isl_id_list_get_id(list
, 1);
8255 id
= isl_id_list_get_id(list
, 2);
8259 isl_id_list_free(list
);
8262 isl_die(ctx
, isl_error_unknown
,
8263 "unexpected elements in list", return -1);
8268 /* Check the conversion from an isl_multi_aff to an isl_basic_set.
8270 static isl_stat
test_ma_conversion(isl_ctx
*ctx
)
8275 isl_basic_set
*bset1
, *bset2
;
8277 str
= "[N] -> { A[0, N + 1] }";
8278 ma
= isl_multi_aff_read_from_str(ctx
, str
);
8279 bset1
= isl_basic_set_read_from_str(ctx
, str
);
8280 bset2
= isl_basic_set_from_multi_aff(ma
);
8281 equal
= isl_basic_set_is_equal(bset1
, bset2
);
8282 isl_basic_set_free(bset1
);
8283 isl_basic_set_free(bset2
);
8285 return isl_stat_error
;
8287 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8288 return isl_stat_error
);
8292 const char *set_conversion_tests
[] = {
8293 "[N] -> { [i] : N - 1 <= 2 i <= N }",
8294 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
8295 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
8296 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
8297 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
8298 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
8299 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
8300 "-3 + c <= d <= 28 + c) }",
8303 /* Check that converting from isl_set to isl_pw_multi_aff and back
8304 * to isl_set produces the original isl_set.
8306 static int test_set_conversion(isl_ctx
*ctx
)
8310 isl_set
*set1
, *set2
;
8311 isl_pw_multi_aff
*pma
;
8314 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
8315 str
= set_conversion_tests
[i
];
8316 set1
= isl_set_read_from_str(ctx
, str
);
8317 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
8318 set2
= isl_set_from_pw_multi_aff(pma
);
8319 equal
= isl_set_is_equal(set1
, set2
);
8326 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8333 const char *conversion_tests
[] = {
8334 "{ [a, b, c, d] -> s0[a, b, e, f] : "
8335 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
8336 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
8337 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
8339 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
8340 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
8341 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
8344 /* Check that converting from isl_map to isl_pw_multi_aff and back
8345 * to isl_map produces the original isl_map.
8347 static int test_map_conversion(isl_ctx
*ctx
)
8350 isl_map
*map1
, *map2
;
8351 isl_pw_multi_aff
*pma
;
8354 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
8355 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
8356 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
8357 map2
= isl_map_from_pw_multi_aff(pma
);
8358 equal
= isl_map_is_equal(map1
, map2
);
8365 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8372 /* Descriptions of isl_pw_multi_aff objects for testing conversion
8373 * to isl_multi_pw_aff and back.
8375 const char *mpa_conversion_tests
[] = {
8377 "{ [x] -> A[x] : x >= 0 }",
8378 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
8379 "{ [x] -> A[x, x + 1] }",
8381 "{ [x] -> A[] : x >= 0 }",
8384 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
8385 * back to isl_pw_multi_aff preserves the original meaning.
8387 static int test_mpa_conversion(isl_ctx
*ctx
)
8390 isl_pw_multi_aff
*pma1
, *pma2
;
8391 isl_multi_pw_aff
*mpa
;
8394 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
8396 str
= mpa_conversion_tests
[i
];
8397 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8398 pma2
= isl_pw_multi_aff_copy(pma1
);
8399 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
8400 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
8401 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
8402 isl_pw_multi_aff_free(pma1
);
8403 isl_pw_multi_aff_free(pma2
);
8408 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8415 /* Descriptions of union maps that should be convertible
8416 * to an isl_multi_union_pw_aff.
8418 const char *umap_mupa_conversion_tests
[] = {
8419 "{ [a, b, c, d] -> s0[a, b, e, f] : "
8420 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
8421 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
8422 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
8424 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
8425 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
8426 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
8427 "{ A[] -> B[0]; C[] -> B[1] }",
8428 "{ A[] -> B[]; C[] -> B[] }",
8431 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
8432 * to isl_union_map produces the original isl_union_map.
8434 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
8437 isl_union_map
*umap1
, *umap2
;
8438 isl_multi_union_pw_aff
*mupa
;
8441 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
8443 str
= umap_mupa_conversion_tests
[i
];
8444 umap1
= isl_union_map_read_from_str(ctx
, str
);
8445 umap2
= isl_union_map_copy(umap1
);
8446 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
8447 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
8448 equal
= isl_union_map_is_equal(umap1
, umap2
);
8449 isl_union_map_free(umap1
);
8450 isl_union_map_free(umap2
);
8455 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8462 static int test_conversion(isl_ctx
*ctx
)
8464 if (test_ma_conversion(ctx
) < 0)
8466 if (test_set_conversion(ctx
) < 0)
8468 if (test_map_conversion(ctx
) < 0)
8470 if (test_mpa_conversion(ctx
) < 0)
8472 if (test_union_map_mupa_conversion(ctx
) < 0)
8477 /* Check that isl_basic_map_curry does not modify input.
8479 static int test_curry(isl_ctx
*ctx
)
8482 isl_basic_map
*bmap1
, *bmap2
;
8485 str
= "{ [A[] -> B[]] -> C[] }";
8486 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
8487 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
8488 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
8489 isl_basic_map_free(bmap1
);
8490 isl_basic_map_free(bmap2
);
8495 isl_die(ctx
, isl_error_unknown
,
8496 "curried map should not be equal to original",
8506 } preimage_tests
[] = {
8507 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
8508 "{ A[j,i] -> B[i,j] }",
8509 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
8510 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
8511 "{ A[a,b] -> B[a/2,b/6] }",
8512 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
8513 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
8514 "{ A[a,b] -> B[a/2,b/6] }",
8515 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
8516 "exists i,j : a = 2 i and b = 6 j }" },
8517 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
8518 "[n] -> { : 0 <= n <= 100 }" },
8519 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
8520 "{ A[a] -> B[2a] }",
8521 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
8522 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
8523 "{ A[a] -> B[([a/2])] }",
8524 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
8525 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
8526 "{ A[a] -> B[a,a,a/3] }",
8527 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
8528 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
8529 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
8532 static int test_preimage_basic_set(isl_ctx
*ctx
)
8535 isl_basic_set
*bset1
, *bset2
;
8539 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
8540 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
8541 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
8542 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
8543 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
8544 equal
= isl_basic_set_is_equal(bset1
, bset2
);
8545 isl_basic_set_free(bset1
);
8546 isl_basic_set_free(bset2
);
8550 isl_die(ctx
, isl_error_unknown
, "bad preimage",
8561 } preimage_domain_tests
[] = {
8562 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
8563 "{ A[j,i] -> B[i,j] }",
8564 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
8565 { "{ B[i] -> C[i]; D[i] -> E[i] }",
8566 "{ A[i] -> B[i + 1] }",
8567 "{ A[i] -> C[i + 1] }" },
8568 { "{ B[i] -> C[i]; B[i] -> E[i] }",
8569 "{ A[i] -> B[i + 1] }",
8570 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
8571 { "{ B[i] -> C[([i/2])] }",
8572 "{ A[i] -> B[2i] }",
8573 "{ A[i] -> C[i] }" },
8574 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
8575 "{ A[i] -> B[([i/5]), ([i/7])] }",
8576 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
8577 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
8578 "[N] -> { A[] -> B[([N/5])] }",
8579 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
8580 { "{ B[i] -> C[i] : exists a : i = 5 a }",
8581 "{ A[i] -> B[2i] }",
8582 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
8583 { "{ B[i] -> C[i] : exists a : i = 2 a; "
8584 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
8585 "{ A[i] -> B[2i] }",
8586 "{ A[i] -> C[2i] }" },
8587 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
8588 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
8591 static int test_preimage_union_map(isl_ctx
*ctx
)
8594 isl_union_map
*umap1
, *umap2
;
8598 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
8599 umap1
= isl_union_map_read_from_str(ctx
,
8600 preimage_domain_tests
[i
].map
);
8601 ma
= isl_multi_aff_read_from_str(ctx
,
8602 preimage_domain_tests
[i
].ma
);
8603 umap2
= isl_union_map_read_from_str(ctx
,
8604 preimage_domain_tests
[i
].res
);
8605 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
8606 equal
= isl_union_map_is_equal(umap1
, umap2
);
8607 isl_union_map_free(umap1
);
8608 isl_union_map_free(umap2
);
8612 isl_die(ctx
, isl_error_unknown
, "bad preimage",
8619 static int test_preimage(isl_ctx
*ctx
)
8621 if (test_preimage_basic_set(ctx
) < 0)
8623 if (test_preimage_union_map(ctx
) < 0)
8633 } pullback_tests
[] = {
8634 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
8635 "{ A[a,b] -> C[b + 2a] }" },
8636 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
8637 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
8638 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
8639 "{ A[a] -> C[(a)/6] }" },
8640 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
8641 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
8642 "{ A[a] -> C[(2a)/3] }" },
8643 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
8644 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
8645 "{ A[i,j] -> C[i + j, i + j] }"},
8646 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
8647 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
8648 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
8649 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
8650 "{ [i, j] -> [floor((i)/3), j] }",
8651 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
8654 static int test_pullback(isl_ctx
*ctx
)
8657 isl_multi_aff
*ma1
, *ma2
;
8661 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
8662 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
8663 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
8664 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
8665 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
8666 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
8667 isl_multi_aff_free(ma1
);
8668 isl_multi_aff_free(ma2
);
8672 isl_die(ctx
, isl_error_unknown
, "bad pullback",
8679 /* Check that negation is printed correctly and that equal expressions
8680 * are correctly identified.
8682 static int test_ast(isl_ctx
*ctx
)
8684 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
8688 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
8689 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
8690 expr
= isl_ast_expr_add(expr1
, expr2
);
8691 expr2
= isl_ast_expr_copy(expr
);
8692 expr
= isl_ast_expr_neg(expr
);
8693 expr2
= isl_ast_expr_neg(expr2
);
8694 equal
= isl_ast_expr_is_equal(expr
, expr2
);
8695 str
= isl_ast_expr_to_C_str(expr
);
8696 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
8698 isl_ast_expr_free(expr
);
8699 isl_ast_expr_free(expr2
);
8701 if (ok
< 0 || equal
< 0)
8704 isl_die(ctx
, isl_error_unknown
,
8705 "equal expressions not considered equal", return -1);
8707 isl_die(ctx
, isl_error_unknown
,
8708 "isl_ast_expr printed incorrectly", return -1);
8710 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
8711 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
8712 expr
= isl_ast_expr_add(expr1
, expr2
);
8713 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
8714 expr
= isl_ast_expr_sub(expr3
, expr
);
8715 str
= isl_ast_expr_to_C_str(expr
);
8716 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
8718 isl_ast_expr_free(expr
);
8723 isl_die(ctx
, isl_error_unknown
,
8724 "isl_ast_expr printed incorrectly", return -1);
8729 /* Check that isl_ast_build_expr_from_set returns a valid expression
8730 * for an empty set. Note that isl_ast_build_expr_from_set getting
8731 * called on an empty set probably indicates a bug in the caller.
8733 static int test_ast_build(isl_ctx
*ctx
)
8736 isl_ast_build
*build
;
8739 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8740 build
= isl_ast_build_from_context(set
);
8742 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
8743 expr
= isl_ast_build_expr_from_set(build
, set
);
8745 isl_ast_expr_free(expr
);
8746 isl_ast_build_free(build
);
8754 /* Internal data structure for before_for and after_for callbacks.
8756 * depth is the current depth
8757 * before is the number of times before_for has been called
8758 * after is the number of times after_for has been called
8760 struct isl_test_codegen_data
{
8766 /* This function is called before each for loop in the AST generated
8767 * from test_ast_gen1.
8769 * Increment the number of calls and the depth.
8770 * Check that the space returned by isl_ast_build_get_schedule_space
8771 * matches the target space of the schedule returned by
8772 * isl_ast_build_get_schedule.
8773 * Return an isl_id that is checked by the corresponding call
8776 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
8779 struct isl_test_codegen_data
*data
= user
;
8782 isl_union_map
*schedule
;
8783 isl_union_set
*uset
;
8789 ctx
= isl_ast_build_get_ctx(build
);
8791 if (data
->before
>= 3)
8792 isl_die(ctx
, isl_error_unknown
,
8793 "unexpected number of for nodes", return NULL
);
8794 if (data
->depth
>= 2)
8795 isl_die(ctx
, isl_error_unknown
,
8796 "unexpected depth", return NULL
);
8798 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
8802 schedule
= isl_ast_build_get_schedule(build
);
8803 uset
= isl_union_map_range(schedule
);
8804 n
= isl_union_set_n_set(uset
);
8806 isl_union_set_free(uset
);
8809 isl_die(ctx
, isl_error_unknown
,
8810 "expecting single range space", return NULL
);
8813 space
= isl_ast_build_get_schedule_space(build
);
8814 set
= isl_union_set_extract_set(uset
, space
);
8815 isl_union_set_free(uset
);
8816 empty
= isl_set_is_empty(set
);
8822 isl_die(ctx
, isl_error_unknown
,
8823 "spaces don't match", return NULL
);
8825 return isl_id_alloc(ctx
, name
, NULL
);
8828 /* This function is called after each for loop in the AST generated
8829 * from test_ast_gen1.
8831 * Increment the number of calls and decrement the depth.
8832 * Check that the annotation attached to the node matches
8833 * the isl_id returned by the corresponding call to before_for.
8835 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
8836 __isl_keep isl_ast_build
*build
, void *user
)
8838 struct isl_test_codegen_data
*data
= user
;
8846 if (data
->after
> data
->before
)
8847 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8848 "mismatch in number of for nodes",
8849 return isl_ast_node_free(node
));
8851 id
= isl_ast_node_get_annotation(node
);
8853 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8854 "missing annotation", return isl_ast_node_free(node
));
8856 name
= isl_id_get_name(id
);
8857 valid
= name
&& atoi(name
+ 1) == data
->depth
;
8861 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
8862 "wrong annotation", return isl_ast_node_free(node
));
8867 /* Check that the before_each_for and after_each_for callbacks
8868 * are called for each for loop in the generated code,
8869 * that they are called in the right order and that the isl_id
8870 * returned from the before_each_for callback is attached to
8871 * the isl_ast_node passed to the corresponding after_each_for call.
8873 static int test_ast_gen1(isl_ctx
*ctx
)
8877 isl_union_map
*schedule
;
8878 isl_ast_build
*build
;
8880 struct isl_test_codegen_data data
;
8882 str
= "[N] -> { : N >= 10 }";
8883 set
= isl_set_read_from_str(ctx
, str
);
8884 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
8885 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
8886 schedule
= isl_union_map_read_from_str(ctx
, str
);
8891 build
= isl_ast_build_from_context(set
);
8892 build
= isl_ast_build_set_before_each_for(build
,
8893 &before_for
, &data
);
8894 build
= isl_ast_build_set_after_each_for(build
,
8896 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8897 isl_ast_build_free(build
);
8901 isl_ast_node_free(tree
);
8903 if (data
.before
!= 3 || data
.after
!= 3)
8904 isl_die(ctx
, isl_error_unknown
,
8905 "unexpected number of for nodes", return -1);
8910 /* Check that the AST generator handles domains that are integrally disjoint
8911 * but not rationally disjoint.
8913 static int test_ast_gen2(isl_ctx
*ctx
)
8917 isl_union_map
*schedule
;
8918 isl_union_map
*options
;
8919 isl_ast_build
*build
;
8922 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
8923 schedule
= isl_union_map_read_from_str(ctx
, str
);
8924 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8925 build
= isl_ast_build_from_context(set
);
8927 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
8928 options
= isl_union_map_read_from_str(ctx
, str
);
8929 build
= isl_ast_build_set_options(build
, options
);
8930 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8931 isl_ast_build_free(build
);
8934 isl_ast_node_free(tree
);
8939 /* Increment *user on each call.
8941 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
8942 __isl_keep isl_ast_build
*build
, void *user
)
8951 /* Test that unrolling tries to minimize the number of instances.
8952 * In particular, for the schedule given below, make sure it generates
8953 * 3 nodes (rather than 101).
8955 static int test_ast_gen3(isl_ctx
*ctx
)
8959 isl_union_map
*schedule
;
8960 isl_union_map
*options
;
8961 isl_ast_build
*build
;
8965 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
8966 schedule
= isl_union_map_read_from_str(ctx
, str
);
8967 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
8969 str
= "{ [i] -> unroll[0] }";
8970 options
= isl_union_map_read_from_str(ctx
, str
);
8972 build
= isl_ast_build_from_context(set
);
8973 build
= isl_ast_build_set_options(build
, options
);
8974 build
= isl_ast_build_set_at_each_domain(build
,
8975 &count_domains
, &n_domain
);
8976 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
8977 isl_ast_build_free(build
);
8981 isl_ast_node_free(tree
);
8984 isl_die(ctx
, isl_error_unknown
,
8985 "unexpected number of for nodes", return -1);
8990 /* Check that if the ast_build_exploit_nested_bounds options is set,
8991 * we do not get an outer if node in the generated AST,
8992 * while we do get such an outer if node if the options is not set.
8994 static int test_ast_gen4(isl_ctx
*ctx
)
8998 isl_union_map
*schedule
;
8999 isl_ast_build
*build
;
9001 enum isl_ast_node_type type
;
9004 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
9005 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
9007 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
9009 schedule
= isl_union_map_read_from_str(ctx
, str
);
9010 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9011 build
= isl_ast_build_from_context(set
);
9012 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9013 isl_ast_build_free(build
);
9017 type
= isl_ast_node_get_type(tree
);
9018 isl_ast_node_free(tree
);
9020 if (type
== isl_ast_node_if
)
9021 isl_die(ctx
, isl_error_unknown
,
9022 "not expecting if node", return -1);
9024 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
9026 schedule
= isl_union_map_read_from_str(ctx
, str
);
9027 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9028 build
= isl_ast_build_from_context(set
);
9029 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9030 isl_ast_build_free(build
);
9034 type
= isl_ast_node_get_type(tree
);
9035 isl_ast_node_free(tree
);
9037 if (type
!= isl_ast_node_if
)
9038 isl_die(ctx
, isl_error_unknown
,
9039 "expecting if node", return -1);
9041 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
9046 /* This function is called for each leaf in the AST generated
9047 * from test_ast_gen5.
9049 * We finalize the AST generation by extending the outer schedule
9050 * with a zero-dimensional schedule. If this results in any for loops,
9051 * then this means that we did not pass along enough information
9052 * about the outer schedule to the inner AST generation.
9054 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
9057 isl_union_map
*schedule
, *extra
;
9060 schedule
= isl_ast_build_get_schedule(build
);
9061 extra
= isl_union_map_copy(schedule
);
9062 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
9063 schedule
= isl_union_map_range_product(schedule
, extra
);
9064 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9065 isl_ast_build_free(build
);
9070 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
9071 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
9072 "code should not contain any for loop",
9073 return isl_ast_node_free(tree
));
9078 /* Check that we do not lose any information when going back and
9079 * forth between internal and external schedule.
9081 * In particular, we create an AST where we unroll the only
9082 * non-constant dimension in the schedule. We therefore do
9083 * not expect any for loops in the AST. However, older versions
9084 * of isl would not pass along enough information about the outer
9085 * schedule when performing an inner code generation from a create_leaf
9086 * callback, resulting in the inner code generation producing a for loop.
9088 static int test_ast_gen5(isl_ctx
*ctx
)
9092 isl_union_map
*schedule
, *options
;
9093 isl_ast_build
*build
;
9096 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
9097 schedule
= isl_union_map_read_from_str(ctx
, str
);
9099 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
9100 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
9101 options
= isl_union_map_read_from_str(ctx
, str
);
9103 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9104 build
= isl_ast_build_from_context(set
);
9105 build
= isl_ast_build_set_options(build
, options
);
9106 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
9107 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9108 isl_ast_build_free(build
);
9109 isl_ast_node_free(tree
);
9116 /* Check that the expression
9118 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
9120 * is not combined into
9124 * as this would result in n/2 being evaluated in parts of
9125 * the definition domain where n is not a multiple of 2.
9127 static int test_ast_expr(isl_ctx
*ctx
)
9131 isl_ast_build
*build
;
9136 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
9137 isl_options_set_ast_build_detect_min_max(ctx
, 1);
9139 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
9140 pa
= isl_pw_aff_read_from_str(ctx
, str
);
9141 build
= isl_ast_build_alloc(ctx
);
9142 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
9143 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
9144 isl_ast_expr_get_op_type(expr
) == isl_ast_expr_op_min
;
9145 isl_ast_build_free(build
);
9146 isl_ast_expr_free(expr
);
9148 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
9153 isl_die(ctx
, isl_error_unknown
,
9154 "expressions should not be combined", return -1);
9159 static int test_ast_gen(isl_ctx
*ctx
)
9161 if (test_ast_gen1(ctx
) < 0)
9163 if (test_ast_gen2(ctx
) < 0)
9165 if (test_ast_gen3(ctx
) < 0)
9167 if (test_ast_gen4(ctx
) < 0)
9169 if (test_ast_gen5(ctx
) < 0)
9171 if (test_ast_expr(ctx
) < 0)
9176 /* Check if dropping output dimensions from an isl_pw_multi_aff
9179 static int test_pw_multi_aff(isl_ctx
*ctx
)
9182 isl_pw_multi_aff
*pma1
, *pma2
;
9185 str
= "{ [i,j] -> [i+j, 4i-j] }";
9186 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9187 str
= "{ [i,j] -> [4i-j] }";
9188 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9190 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
9192 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
9194 isl_pw_multi_aff_free(pma1
);
9195 isl_pw_multi_aff_free(pma2
);
9199 isl_die(ctx
, isl_error_unknown
,
9200 "expressions not equal", return -1);
9205 /* Check that we can properly parse multi piecewise affine expressions
9206 * where the piecewise affine expressions have different domains.
9208 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
9211 isl_set
*dom
, *dom2
;
9212 isl_multi_pw_aff
*mpa1
, *mpa2
;
9217 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
9218 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
9219 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
9220 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
9221 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
9222 str
= "{ [i] -> [(i : i > 0), 2i] }";
9223 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
9225 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
9227 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
9228 dom
= isl_pw_aff_domain(pa
);
9229 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
9230 dom2
= isl_pw_aff_domain(pa
);
9231 equal_domain
= isl_set_is_equal(dom
, dom2
);
9235 isl_multi_pw_aff_free(mpa1
);
9236 isl_multi_pw_aff_free(mpa2
);
9241 isl_die(ctx
, isl_error_unknown
,
9242 "expressions not equal", return -1);
9244 if (equal_domain
< 0)
9247 isl_die(ctx
, isl_error_unknown
,
9248 "domains unexpectedly equal", return -1);
9253 /* Check that the dimensions in the explicit domain
9254 * of a multi piecewise affine expression are properly
9255 * taken into account.
9257 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
9260 isl_bool involves1
, involves2
, involves3
, equal
;
9261 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
9263 str
= "{ A[x,y] -> B[] : x >= y }";
9264 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
9265 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
9266 mpa1
= isl_multi_pw_aff_copy(mpa
);
9268 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
9269 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
9270 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
9271 str
= "{ [a,x,y] -> B[] : x >= y }";
9272 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
9273 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
9274 isl_multi_pw_aff_free(mpa2
);
9276 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
9277 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
9278 if (equal
>= 0 && equal
)
9279 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
9280 isl_multi_pw_aff_free(mpa1
);
9281 isl_multi_pw_aff_free(mpa
);
9283 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
9286 isl_die(ctx
, isl_error_unknown
,
9287 "incorrect result of dimension insertion/removal",
9288 return isl_stat_error
);
9289 if (!involves1
|| involves2
|| !involves3
)
9290 isl_die(ctx
, isl_error_unknown
,
9291 "incorrect characterization of involved dimensions",
9292 return isl_stat_error
);
9297 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
9298 * sets the explicit domain of a zero-dimensional result,
9299 * such that it can be converted to an isl_union_map.
9301 static isl_stat
test_multi_pw_aff_3(isl_ctx
*ctx
)
9306 isl_multi_union_pw_aff
*mupa
;
9307 isl_union_map
*umap
;
9309 dom
= isl_union_set_read_from_str(ctx
, "{ A[]; B[] }");
9310 space
= isl_union_set_get_space(dom
);
9311 mv
= isl_multi_val_zero(isl_space_set_from_params(space
));
9312 mupa
= isl_multi_union_pw_aff_multi_val_on_domain(dom
, mv
);
9313 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
9314 isl_union_map_free(umap
);
9316 return isl_stat_error
;
9321 /* Perform some tests on multi piecewise affine expressions.
9323 static int test_multi_pw_aff(isl_ctx
*ctx
)
9325 if (test_multi_pw_aff_1(ctx
) < 0)
9327 if (test_multi_pw_aff_2(ctx
) < 0)
9329 if (test_multi_pw_aff_3(ctx
) < 0)
9334 /* This is a regression test for a bug where isl_basic_map_simplify
9335 * would end up in an infinite loop. In particular, we construct
9336 * an empty basic set that is not obviously empty.
9337 * isl_basic_set_is_empty marks the basic set as empty.
9338 * After projecting out i3, the variable can be dropped completely,
9339 * but isl_basic_map_simplify refrains from doing so if the basic set
9340 * is empty and would end up in an infinite loop if it didn't test
9341 * explicitly for empty basic maps in the outer loop.
9343 static int test_simplify_1(isl_ctx
*ctx
)
9346 isl_basic_set
*bset
;
9349 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
9350 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
9351 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
9353 bset
= isl_basic_set_read_from_str(ctx
, str
);
9354 empty
= isl_basic_set_is_empty(bset
);
9355 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
9356 isl_basic_set_free(bset
);
9360 isl_die(ctx
, isl_error_unknown
,
9361 "basic set should be empty", return -1);
9366 /* Check that the equality in the set description below
9367 * is simplified away.
9369 static int test_simplify_2(isl_ctx
*ctx
)
9372 isl_basic_set
*bset
;
9375 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
9376 bset
= isl_basic_set_read_from_str(ctx
, str
);
9377 universe
= isl_basic_set_plain_is_universe(bset
);
9378 isl_basic_set_free(bset
);
9383 isl_die(ctx
, isl_error_unknown
,
9384 "equality not simplified away", return -1);
9388 /* Some simplification tests.
9390 static int test_simplify(isl_ctx
*ctx
)
9392 if (test_simplify_1(ctx
) < 0)
9394 if (test_simplify_2(ctx
) < 0)
9399 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
9400 * with gbr context would fail to disable the use of the shifted tableau
9401 * when transferring equalities for the input to the context, resulting
9402 * in invalid sample values.
9404 static int test_partial_lexmin(isl_ctx
*ctx
)
9407 isl_basic_set
*bset
;
9408 isl_basic_map
*bmap
;
9411 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
9412 bmap
= isl_basic_map_read_from_str(ctx
, str
);
9413 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
9414 bset
= isl_basic_set_read_from_str(ctx
, str
);
9415 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
9424 /* Check that the variable compression performed on the existentially
9425 * quantified variables inside isl_basic_set_compute_divs is not confused
9426 * by the implicit equalities among the parameters.
9428 static int test_compute_divs(isl_ctx
*ctx
)
9431 isl_basic_set
*bset
;
9434 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
9435 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
9436 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
9437 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
9438 bset
= isl_basic_set_read_from_str(ctx
, str
);
9439 set
= isl_basic_set_compute_divs(bset
);
9447 /* Check that isl_schedule_get_map is not confused by a schedule tree
9448 * with divergent filter node parameters, as can result from a call
9449 * to isl_schedule_intersect_domain.
9451 static int test_schedule_tree(isl_ctx
*ctx
)
9454 isl_union_set
*uset
;
9455 isl_schedule
*sched1
, *sched2
;
9456 isl_union_map
*umap
;
9458 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
9459 sched1
= isl_schedule_from_domain(uset
);
9460 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
9461 sched2
= isl_schedule_from_domain(uset
);
9463 sched1
= isl_schedule_sequence(sched1
, sched2
);
9464 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
9465 uset
= isl_union_set_read_from_str(ctx
, str
);
9466 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
9467 umap
= isl_schedule_get_map(sched1
);
9468 isl_schedule_free(sched1
);
9469 isl_union_map_free(umap
);
9476 /* Check that a zero-dimensional prefix schedule keeps track
9477 * of the domain and outer filters.
9479 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
9483 isl_union_set
*uset
;
9484 isl_union_set_list
*filters
;
9485 isl_multi_union_pw_aff
*mupa
, *mupa2
;
9486 isl_schedule_node
*node
;
9488 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
9489 uset
= isl_union_set_read_from_str(ctx
, str
);
9490 node
= isl_schedule_node_from_domain(uset
);
9491 node
= isl_schedule_node_child(node
, 0);
9493 str
= "{ S1[i,j] : i > j }";
9494 uset
= isl_union_set_read_from_str(ctx
, str
);
9495 filters
= isl_union_set_list_from_union_set(uset
);
9496 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
9497 uset
= isl_union_set_read_from_str(ctx
, str
);
9498 filters
= isl_union_set_list_add(filters
, uset
);
9499 node
= isl_schedule_node_insert_sequence(node
, filters
);
9501 node
= isl_schedule_node_child(node
, 0);
9502 node
= isl_schedule_node_child(node
, 0);
9503 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
9504 str
= "([] : { S1[i,j] : i > j })";
9505 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9506 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
9507 isl_multi_union_pw_aff_free(mupa2
);
9508 isl_multi_union_pw_aff_free(mupa
);
9509 isl_schedule_node_free(node
);
9514 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
9520 /* Check that the reaching domain elements and the prefix schedule
9521 * at a leaf node are the same before and after grouping.
9523 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
9528 isl_union_set
*uset
;
9529 isl_multi_union_pw_aff
*mupa
;
9530 isl_union_pw_multi_aff
*upma1
, *upma2
;
9531 isl_union_set
*domain1
, *domain2
;
9532 isl_union_map
*umap1
, *umap2
;
9533 isl_schedule_node
*node
;
9535 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
9536 uset
= isl_union_set_read_from_str(ctx
, str
);
9537 node
= isl_schedule_node_from_domain(uset
);
9538 node
= isl_schedule_node_child(node
, 0);
9539 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
9540 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9541 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
9542 node
= isl_schedule_node_child(node
, 0);
9543 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
9544 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9545 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
9546 node
= isl_schedule_node_child(node
, 0);
9547 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
9548 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
9549 domain1
= isl_schedule_node_get_domain(node
);
9550 id
= isl_id_alloc(ctx
, "group", NULL
);
9551 node
= isl_schedule_node_parent(node
);
9552 node
= isl_schedule_node_group(node
, id
);
9553 node
= isl_schedule_node_child(node
, 0);
9554 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
9555 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
9556 domain2
= isl_schedule_node_get_domain(node
);
9557 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
9558 if (equal
>= 0 && equal
)
9559 equal
= isl_union_set_is_equal(domain1
, domain2
);
9560 if (equal
>= 0 && equal
)
9561 equal
= isl_union_map_is_equal(umap1
, umap2
);
9562 isl_union_map_free(umap1
);
9563 isl_union_map_free(umap2
);
9564 isl_union_set_free(domain1
);
9565 isl_union_set_free(domain2
);
9566 isl_union_pw_multi_aff_free(upma1
);
9567 isl_union_pw_multi_aff_free(upma2
);
9568 isl_schedule_node_free(node
);
9573 isl_die(ctx
, isl_error_unknown
,
9574 "expressions not equal", return -1);
9579 /* Check that we can have nested groupings and that the union map
9580 * schedule representation is the same before and after the grouping.
9581 * Note that after the grouping, the union map representation contains
9582 * the domain constraints from the ranges of the expansion nodes,
9583 * while they are missing from the union map representation of
9584 * the tree without expansion nodes.
9586 * Also check that the global expansion is as expected.
9588 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
9590 int equal
, equal_expansion
;
9593 isl_union_set
*uset
;
9594 isl_union_map
*umap1
, *umap2
;
9595 isl_union_map
*expansion1
, *expansion2
;
9596 isl_union_set_list
*filters
;
9597 isl_multi_union_pw_aff
*mupa
;
9598 isl_schedule
*schedule
;
9599 isl_schedule_node
*node
;
9601 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
9602 "S3[i,j] : 0 <= i,j < 10 }";
9603 uset
= isl_union_set_read_from_str(ctx
, str
);
9604 node
= isl_schedule_node_from_domain(uset
);
9605 node
= isl_schedule_node_child(node
, 0);
9606 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
9607 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9608 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
9609 node
= isl_schedule_node_child(node
, 0);
9610 str
= "{ S1[i,j] }";
9611 uset
= isl_union_set_read_from_str(ctx
, str
);
9612 filters
= isl_union_set_list_from_union_set(uset
);
9613 str
= "{ S2[i,j]; S3[i,j] }";
9614 uset
= isl_union_set_read_from_str(ctx
, str
);
9615 filters
= isl_union_set_list_add(filters
, uset
);
9616 node
= isl_schedule_node_insert_sequence(node
, filters
);
9617 node
= isl_schedule_node_child(node
, 1);
9618 node
= isl_schedule_node_child(node
, 0);
9619 str
= "{ S2[i,j] }";
9620 uset
= isl_union_set_read_from_str(ctx
, str
);
9621 filters
= isl_union_set_list_from_union_set(uset
);
9622 str
= "{ S3[i,j] }";
9623 uset
= isl_union_set_read_from_str(ctx
, str
);
9624 filters
= isl_union_set_list_add(filters
, uset
);
9625 node
= isl_schedule_node_insert_sequence(node
, filters
);
9627 schedule
= isl_schedule_node_get_schedule(node
);
9628 umap1
= isl_schedule_get_map(schedule
);
9629 uset
= isl_schedule_get_domain(schedule
);
9630 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
9631 isl_schedule_free(schedule
);
9633 node
= isl_schedule_node_parent(node
);
9634 node
= isl_schedule_node_parent(node
);
9635 id
= isl_id_alloc(ctx
, "group1", NULL
);
9636 node
= isl_schedule_node_group(node
, id
);
9637 node
= isl_schedule_node_child(node
, 1);
9638 node
= isl_schedule_node_child(node
, 0);
9639 id
= isl_id_alloc(ctx
, "group2", NULL
);
9640 node
= isl_schedule_node_group(node
, id
);
9642 schedule
= isl_schedule_node_get_schedule(node
);
9643 umap2
= isl_schedule_get_map(schedule
);
9644 isl_schedule_free(schedule
);
9646 node
= isl_schedule_node_root(node
);
9647 node
= isl_schedule_node_child(node
, 0);
9648 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
9649 isl_schedule_node_free(node
);
9651 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
9652 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
9653 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
9655 expansion2
= isl_union_map_read_from_str(ctx
, str
);
9657 equal
= isl_union_map_is_equal(umap1
, umap2
);
9658 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
9660 isl_union_map_free(umap1
);
9661 isl_union_map_free(umap2
);
9662 isl_union_map_free(expansion1
);
9663 isl_union_map_free(expansion2
);
9665 if (equal
< 0 || equal_expansion
< 0)
9668 isl_die(ctx
, isl_error_unknown
,
9669 "expressions not equal", return -1);
9670 if (!equal_expansion
)
9671 isl_die(ctx
, isl_error_unknown
,
9672 "unexpected expansion", return -1);
9677 /* Some tests for the isl_schedule_node_group function.
9679 static int test_schedule_tree_group(isl_ctx
*ctx
)
9681 if (test_schedule_tree_group_1(ctx
) < 0)
9683 if (test_schedule_tree_group_2(ctx
) < 0)
9692 { "{ rat: [i] : 0 <= i <= 10 }",
9693 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
9694 { "{ rat: [i] : FALSE }",
9695 "{ rat: coefficients[[cst] -> [a]] }" },
9697 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
9704 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
9705 "{ rat: [i] : 0 <= i <= 10 }" },
9706 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
9708 { "{ rat: coefficients[[cst] -> [a]] }",
9709 "{ rat: [i] : FALSE }" },
9712 /* Test the basic functionality of isl_basic_set_coefficients and
9713 * isl_basic_set_solutions.
9715 static int test_dual(isl_ctx
*ctx
)
9719 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
9721 isl_basic_set
*bset1
, *bset2
;
9723 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
9724 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
9725 bset1
= isl_basic_set_coefficients(bset1
);
9726 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9727 isl_basic_set_free(bset1
);
9728 isl_basic_set_free(bset2
);
9732 isl_die(ctx
, isl_error_unknown
,
9733 "incorrect dual", return -1);
9736 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
9738 isl_basic_set
*bset1
, *bset2
;
9740 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
9741 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
9742 bset1
= isl_basic_set_solutions(bset1
);
9743 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9744 isl_basic_set_free(bset1
);
9745 isl_basic_set_free(bset2
);
9749 isl_die(ctx
, isl_error_unknown
,
9750 "incorrect dual", return -1);
9760 const char *schedule
;
9765 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
9766 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9768 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
9769 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9771 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
9772 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9774 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
9775 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9777 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
9778 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9780 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
9781 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
9783 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
9784 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9786 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
9787 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
9791 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
9792 * tile the band and then check if the tile and point bands have the
9793 * expected partial schedule.
9795 static int test_tile(isl_ctx
*ctx
)
9801 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
9802 shift
= isl_options_get_tile_shift_point_loops(ctx
);
9804 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
9808 isl_union_set
*domain
;
9809 isl_multi_union_pw_aff
*mupa
, *mupa2
;
9810 isl_schedule_node
*node
;
9811 isl_multi_val
*sizes
;
9813 opt
= tile_tests
[i
].scale_tile
;
9814 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
9815 opt
= tile_tests
[i
].shift_point
;
9816 isl_options_set_tile_shift_point_loops(ctx
, opt
);
9818 str
= tile_tests
[i
].domain
;
9819 domain
= isl_union_set_read_from_str(ctx
, str
);
9820 node
= isl_schedule_node_from_domain(domain
);
9821 node
= isl_schedule_node_child(node
, 0);
9822 str
= tile_tests
[i
].schedule
;
9823 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9824 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
9825 str
= tile_tests
[i
].sizes
;
9826 sizes
= isl_multi_val_read_from_str(ctx
, str
);
9827 node
= isl_schedule_node_band_tile(node
, sizes
);
9829 str
= tile_tests
[i
].tile
;
9830 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9831 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
9832 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
9833 isl_multi_union_pw_aff_free(mupa
);
9834 isl_multi_union_pw_aff_free(mupa2
);
9836 node
= isl_schedule_node_child(node
, 0);
9838 str
= tile_tests
[i
].point
;
9839 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9840 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
9841 if (equal
>= 0 && equal
)
9842 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
9844 isl_multi_union_pw_aff_free(mupa
);
9845 isl_multi_union_pw_aff_free(mupa2
);
9847 isl_schedule_node_free(node
);
9852 isl_die(ctx
, isl_error_unknown
,
9853 "unexpected result", return -1);
9856 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
9857 isl_options_set_tile_shift_point_loops(ctx
, shift
);
9862 /* Check that the domain hash of a space is equal to the hash
9863 * of the domain of the space.
9865 static int test_domain_hash(isl_ctx
*ctx
)
9869 uint32_t hash1
, hash2
;
9871 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
9872 space
= isl_map_get_space(map
);
9874 hash1
= isl_space_get_domain_hash(space
);
9875 space
= isl_space_domain(space
);
9876 hash2
= isl_space_get_hash(space
);
9877 isl_space_free(space
);
9882 isl_die(ctx
, isl_error_unknown
,
9883 "domain hash not equal to hash of domain", return -1);
9888 /* Check that a universe basic set that is not obviously equal to the universe
9889 * is still recognized as being equal to the universe.
9891 static int test_universe(isl_ctx
*ctx
)
9894 isl_basic_set
*bset
;
9897 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
9898 bset
= isl_basic_set_read_from_str(ctx
, s
);
9899 is_univ
= isl_basic_set_is_universe(bset
);
9900 isl_basic_set_free(bset
);
9905 isl_die(ctx
, isl_error_unknown
,
9906 "not recognized as universe set", return -1);
9911 /* Sets for which chambers are computed and checked.
9913 const char *chambers_tests
[] = {
9914 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
9915 "z >= 0 and z <= C - y and z <= B - x - y }",
9918 /* Add the domain of "cell" to "cells".
9920 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
9922 isl_basic_set_list
**cells
= user
;
9925 dom
= isl_cell_get_domain(cell
);
9926 isl_cell_free(cell
);
9927 *cells
= isl_basic_set_list_add(*cells
, dom
);
9929 return *cells
? isl_stat_ok
: isl_stat_error
;
9932 /* Check that the elements of "list" are pairwise disjoint.
9934 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
9939 n
= isl_basic_set_list_n_basic_set(list
);
9941 return isl_stat_error
;
9943 for (i
= 0; i
< n
; ++i
) {
9944 isl_basic_set
*bset_i
;
9946 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
9947 for (j
= i
+ 1; j
< n
; ++j
) {
9948 isl_basic_set
*bset_j
;
9951 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
9952 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
9953 isl_basic_set_free(bset_j
);
9955 isl_die(isl_basic_set_list_get_ctx(list
),
9956 isl_error_unknown
, "not disjoint",
9958 if (disjoint
< 0 || !disjoint
)
9961 isl_basic_set_free(bset_i
);
9963 return isl_stat_error
;
9969 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
9970 * are pairwise disjoint.
9972 static int test_chambers(isl_ctx
*ctx
)
9976 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
9977 isl_basic_set
*bset
;
9978 isl_vertices
*vertices
;
9979 isl_basic_set_list
*cells
;
9982 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
9983 vertices
= isl_basic_set_compute_vertices(bset
);
9984 cells
= isl_basic_set_list_alloc(ctx
, 0);
9985 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
9987 cells
= isl_basic_set_list_free(cells
);
9988 ok
= check_pairwise_disjoint(cells
);
9989 isl_basic_set_list_free(cells
);
9990 isl_vertices_free(vertices
);
9991 isl_basic_set_free(bset
);
10002 int (*fn
)(isl_ctx
*ctx
);
10004 { "universe", &test_universe
},
10005 { "domain hash", &test_domain_hash
},
10006 { "dual", &test_dual
},
10007 { "dependence analysis", &test_flow
},
10008 { "val", &test_val
},
10009 { "compute divs", &test_compute_divs
},
10010 { "partial lexmin", &test_partial_lexmin
},
10011 { "simplify", &test_simplify
},
10012 { "curry", &test_curry
},
10013 { "piecewise multi affine expressions", &test_pw_multi_aff
},
10014 { "multi piecewise affine expressions", &test_multi_pw_aff
},
10015 { "conversion", &test_conversion
},
10016 { "list", &test_list
},
10017 { "align parameters", &test_align_parameters
},
10018 { "drop unused parameters", &test_drop_unused_parameters
},
10019 { "preimage", &test_preimage
},
10020 { "pullback", &test_pullback
},
10021 { "AST", &test_ast
},
10022 { "AST build", &test_ast_build
},
10023 { "AST generation", &test_ast_gen
},
10024 { "eliminate", &test_eliminate
},
10025 { "deltas_map", &test_deltas_map
},
10026 { "residue class", &test_residue_class
},
10027 { "div", &test_div
},
10028 { "slice", &test_slice
},
10029 { "fixed power", &test_fixed_power
},
10030 { "sample", &test_sample
},
10031 { "output", &test_output
},
10032 { "vertices", &test_vertices
},
10033 { "chambers", &test_chambers
},
10034 { "fixed", &test_fixed
},
10035 { "equal", &test_equal
},
10036 { "disjoint", &test_disjoint
},
10037 { "product", &test_product
},
10038 { "dim_max", &test_dim_max
},
10039 { "affine", &test_aff
},
10040 { "injective", &test_injective
},
10041 { "schedule (whole component)", &test_schedule_whole
},
10042 { "schedule (incremental)", &test_schedule_incremental
},
10043 { "schedule tree", &test_schedule_tree
},
10044 { "schedule tree prefix", &test_schedule_tree_prefix
},
10045 { "schedule tree grouping", &test_schedule_tree_group
},
10046 { "tile", &test_tile
},
10047 { "union_pw", &test_union_pw
},
10048 { "locus", &test_locus
},
10049 { "eval", &test_eval
},
10050 { "parse", &test_parse
},
10051 { "single-valued", &test_sv
},
10052 { "affine hull", &test_affine_hull
},
10053 { "simple_hull", &test_simple_hull
},
10054 { "coalesce", &test_coalesce
},
10055 { "factorize", &test_factorize
},
10056 { "subset", &test_subset
},
10057 { "subtract", &test_subtract
},
10058 { "intersect", &test_intersect
},
10059 { "lexmin", &test_lexmin
},
10060 { "min", &test_min
},
10061 { "gist", &test_gist
},
10062 { "piecewise quasi-polynomials", &test_pwqp
},
10063 { "lift", &test_lift
},
10064 { "bind parameters", &test_bind
},
10065 { "unbind parameters", &test_unbind
},
10066 { "bound", &test_bound
},
10067 { "get lists", &test_get_list
},
10068 { "union", &test_union
},
10069 { "split periods", &test_split_periods
},
10070 { "lexicographic order", &test_lex
},
10071 { "bijectivity", &test_bijective
},
10072 { "dataflow analysis", &test_dep
},
10073 { "reading", &test_read
},
10074 { "bounded", &test_bounded
},
10075 { "construction", &test_construction
},
10076 { "dimension manipulation", &test_dim
},
10077 { "map application", &test_application
},
10078 { "convex hull", &test_convex_hull
},
10079 { "transitive closure", &test_closure
},
10080 { "isl_bool", &test_isl_bool
},
10083 int main(int argc
, char **argv
)
10086 struct isl_ctx
*ctx
;
10087 struct isl_options
*options
;
10089 options
= isl_options_new_with_defaults();
10091 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
10093 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
10094 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
10095 printf("%s\n", tests
[i
].name
);
10096 if (tests
[i
].fn(ctx
) < 0)