2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
5 * Copyright 2014 INRIA Rocquencourt
7 * Use of this software is governed by the MIT license
9 * Written by Sven Verdoolaege, K.U.Leuven, Departement
10 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
11 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
12 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
14 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
15 * B.P. 105 - 78153 Le Chesnay, France
21 #include <isl_ctx_private.h>
22 #include <isl_map_private.h>
23 #include <isl_aff_private.h>
24 #include <isl_space_private.h>
28 #include <isl_constraint_private.h>
29 #include <isl/polynomial.h>
30 #include <isl/union_set.h>
31 #include <isl/union_map.h>
32 #include <isl_factorization.h>
33 #include <isl/schedule.h>
34 #include <isl/schedule_node.h>
35 #include <isl_options_private.h>
36 #include <isl_vertices_private.h>
37 #include <isl/ast_build.h>
40 #include <isl_ast_build_expr.h>
41 #include <isl/options.h>
43 #include "isl_srcdir.c"
45 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
47 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
50 char *pattern
= "%s/test_inputs/%s.%s";
52 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
54 filename
= isl_alloc_array(ctx
, char, length
);
59 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
64 void test_parse_map(isl_ctx
*ctx
, const char *str
)
68 map
= isl_map_read_from_str(ctx
, str
);
73 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
78 map
= isl_map_read_from_str(ctx
, str
);
79 map2
= isl_map_read_from_str(ctx
, str2
);
80 equal
= isl_map_is_equal(map
, map2
);
87 isl_die(ctx
, isl_error_unknown
, "maps not equal",
93 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
95 isl_pw_qpolynomial
*pwqp
;
97 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
99 isl_pw_qpolynomial_free(pwqp
);
102 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
106 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
108 isl_pw_aff_free(pwaff
);
111 /* Check that we can read an isl_multi_val from "str" without errors.
113 static int test_parse_multi_val(isl_ctx
*ctx
, const char *str
)
117 mv
= isl_multi_val_read_from_str(ctx
, str
);
118 isl_multi_val_free(mv
);
123 /* String descriptions of multi piecewise affine expressions
124 * that are used for testing printing and parsing.
126 static const char *reparse_multi_pw_aff_tests
[] = {
127 "{ A[x, y] -> [] : x + y >= 0 }",
128 "{ A[x, y] -> B[] : x + y >= 0 }",
129 "{ A[x, y] -> [x] : x + y >= 0 }",
130 "[N] -> { A[x, y] -> [x] : x + y <= N }",
131 "{ A[x, y] -> [x, y] : x + y >= 0 }",
132 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
133 "[N] -> { [] : N >= 0 }",
134 "[N] -> { [] : N >= 0 }",
135 "[N] -> { [N] : N >= 0 }",
136 "[N] -> { [N, N + 1] : N >= 0 }",
137 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
141 #define BASE multi_pw_aff
143 #include "check_reparse_templ.c"
144 #include "check_reparse_test_templ.c"
146 /* String descriptions of piecewise multi affine expressions
147 * that are used for testing printing and parsing.
149 static const char *reparse_pw_multi_aff_tests
[] = {
151 "{ [x] -> [x % 4] }",
152 "{ [x] -> [x % 4] : x mod 3 = 1 }",
153 "{ [x, x] -> [x % 4] }",
154 "{ [x, x + 1] -> [x % 4] : x mod 3 = 1 }",
155 "{ [x, x mod 2] -> [x % 4] }",
159 #define BASE pw_multi_aff
161 #include "check_reparse_templ.c"
162 #include "check_reparse_test_templ.c"
164 /* Test parsing of piecewise multi affine expressions by printing
165 * the expressions and checking that parsing the output results
166 * in the same expression.
167 * Do this for an expression converted from a map with an output
168 * dimension name that is equal to an automatically generated name, and
169 * a set of expressions parsed from strings.
171 static isl_stat
test_parse_pma(isl_ctx
*ctx
)
174 isl_pw_multi_aff
*pma
;
176 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
177 pma
= isl_pw_multi_aff_from_map(map
);
178 if (check_reparse_pw_multi_aff(ctx
, pma
) < 0)
179 return isl_stat_error
;
181 if (check_reparse_pw_multi_aff_tests(ctx
) < 0)
182 return isl_stat_error
;
187 /* Test parsing of multi piecewise affine expressions by printing
188 * the expressions and checking that parsing the output results
189 * in the same expression.
190 * Do this for a couple of manually constructed expressions,
191 * an expression converted from a map with an output dimension name
192 * that is equal to an automatically generated name, and
193 * a set of expressions parsed from strings.
195 static int test_parse_mpa(isl_ctx
*ctx
)
200 isl_pw_multi_aff
*pma
;
201 isl_multi_pw_aff
*mpa
;
204 space
= isl_space_set_alloc(ctx
, 0, 0);
205 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
206 mpa
= isl_multi_pw_aff_zero(space
);
207 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
211 space
= isl_space_set_alloc(ctx
, 1, 0);
212 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
213 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
214 dom
= isl_set_universe(isl_space_params(isl_space_copy(space
)));
215 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
216 mpa
= isl_multi_pw_aff_zero(space
);
217 mpa
= isl_multi_pw_aff_intersect_domain(mpa
, dom
);
218 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
222 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
223 pma
= isl_pw_multi_aff_from_map(map
);
224 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma
);
225 if (check_reparse_multi_pw_aff(ctx
, mpa
) < 0)
228 if (check_reparse_multi_pw_aff_tests(ctx
) < 0)
234 /* String descriptions of multi union piecewise affine expressions
235 * that are used for testing printing and parsing.
237 static const char *reparse_multi_union_pw_aff_tests
[] = {
241 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
243 "[N] -> (A[] : { })",
244 "[N] -> (A[] : { : N >= 0 })",
245 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
246 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
247 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
248 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
249 "{ S[x] : x > 0; T[y] : y >= 0 })",
253 #define BASE multi_union_pw_aff
255 #include "check_reparse_templ.c"
256 #include "check_reparse_test_templ.c"
258 /* Test parsing of multi union piecewise affine expressions by printing
259 * the expressions and checking that parsing the output results
260 * in the same expression.
261 * Do this for a couple of manually constructed expressions and
262 * a set of expressions parsed from strings.
264 static int test_parse_mupa(isl_ctx
*ctx
)
267 isl_multi_union_pw_aff
*mupa
;
272 space
= isl_space_set_alloc(ctx
, 0, 0);
273 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
274 mupa
= isl_multi_union_pw_aff_zero(space
);
275 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
279 space
= isl_space_set_alloc(ctx
, 1, 0);
280 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
281 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
282 dom
= isl_set_universe(space
);
283 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
284 uset
= isl_union_set_from_set(dom
);
285 space
= isl_space_set_alloc(ctx
, 1, 0);
286 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
287 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "B");
288 mupa
= isl_multi_union_pw_aff_zero(space
);
289 mupa
= isl_multi_union_pw_aff_intersect_domain(mupa
, uset
);
290 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
294 if (check_reparse_multi_union_pw_aff_tests(ctx
) < 0)
300 /* Test parsing of multi expressions.
302 static int test_parse_multi(isl_ctx
*ctx
)
304 if (test_parse_mpa(ctx
) < 0)
306 if (test_parse_mupa(ctx
) < 0)
312 /* Pairs of binary relation representations that should represent
313 * the same binary relations.
318 } parse_map_equal_tests
[] = {
319 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
320 "{ [x, y] : 2y >= 6 - x }" },
321 { "{ [x,y] : x <= min(y, 2*y+3) }",
322 "{ [x,y] : x <= y, 2*y + 3 }" },
323 { "{ [x,y] : x >= min(y, 2*y+3) }",
324 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
325 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
326 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
327 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
328 "{ [i,j] -> [min(i,j)] }" },
329 { "{ [i,j] : i != j }",
330 "{ [i,j] : i < j or i > j }" },
331 { "{ [i,j] : (i+1)*2 >= j }",
332 "{ [i, j] : j <= 2 + 2i }" },
333 { "{ [i] -> [i > 0 ? 4 : 5] }",
334 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
335 { "[N=2,M] -> { [i=[(M+N)/4]] }",
336 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
337 { "{ [x] : x >= 0 }",
338 "{ [x] : x-0 >= 0 }" },
339 { "{ [i] : ((i > 10)) }",
340 "{ [i] : i >= 11 }" },
342 "{ [i] -> [0 * i] }" },
343 { "{ [a] -> [b] : (not false) }",
344 "{ [a] -> [b] : true }" },
345 { "{ [i] : i/2 <= 5 }",
346 "{ [i] : i <= 10 }" },
347 { "{Sym=[n] [i] : i <= n }",
348 "[n] -> { [i] : i <= n }" },
351 { "{ [i] : 2*floor(i/2) = i }",
352 "{ [i] : exists a : i = 2 a }" },
353 { "{ [a] -> [b] : a = 5 implies b = 5 }",
354 "{ [a] -> [b] : a != 5 or b = 5 }" },
355 { "{ [a] -> [a - 1 : a > 0] }",
356 "{ [a] -> [a - 1] : a > 0 }" },
357 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
358 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : 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] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
366 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
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 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
374 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
375 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
376 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
377 "8c < n - 32a and i < n and c >= 0 and "
378 "c <= 3 and c >= -4a) }",
379 "{ [n] -> [i] : 0 <= i < n }" },
380 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
381 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
382 "{ [x] -> [] : 0 <= x <= 15 }" },
383 { "{ [x] -> [x] : }",
385 { "{ [x=4:5] -> [x + 1] }",
386 "{ [x] -> [x + 1] : 4 <= x <= 5 }" },
387 { "{ [x=4:5] -> [x + 1 : x + 1] }",
388 "{ [x=4:5] -> [x + 1] }" },
389 { "{ [x] -> [x - 1 : x + 1] }",
390 "{ [x] -> [y] : x - 1 <= y <= x + 1 }" },
391 { "{ [x=4:] -> [x + 1] }",
392 "{ [x] -> [x + 1] : 4 <= x }" },
393 { "{ [x=:5] -> [x + 1] }",
394 "{ [x] -> [x + 1] : x <= 5 }" },
395 { "{ [x=:] -> [x + 1] }",
396 "{ [x] -> [x + 1] }" },
400 "{ [x, floor(x/4)] }" },
405 int test_parse(struct isl_ctx
*ctx
)
409 const char *str
, *str2
;
411 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
413 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
415 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
417 if (test_parse_multi(ctx
) < 0)
419 if (test_parse_pma(ctx
) < 0)
422 str
= "{ [i] -> [-i] }";
423 map
= isl_map_read_from_str(ctx
, str
);
427 str
= "{ A[i] -> L[([i/3])] }";
428 map
= isl_map_read_from_str(ctx
, str
);
432 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
433 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
434 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
436 for (i
= 0; i
< ARRAY_SIZE(parse_map_equal_tests
); ++i
) {
437 str
= parse_map_equal_tests
[i
].map1
;
438 str2
= parse_map_equal_tests
[i
].map2
;
439 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
443 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
444 map
= isl_map_read_from_str(ctx
, str
);
445 str
= "{ [new, old] -> [o0, o1] : "
446 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
447 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
448 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
449 map2
= isl_map_read_from_str(ctx
, str
);
450 assert(isl_map_is_equal(map
, map2
));
454 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
455 map
= isl_map_read_from_str(ctx
, str
);
456 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
457 map2
= isl_map_read_from_str(ctx
, str
);
458 assert(isl_map_is_equal(map
, map2
));
462 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
463 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
464 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
465 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
466 test_parse_pwaff(ctx
, "{ [] -> [(100)] }");
471 static int test_read(isl_ctx
*ctx
)
475 isl_basic_set
*bset1
, *bset2
;
476 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
479 filename
= get_filename(ctx
, "set", "omega");
481 input
= fopen(filename
, "r");
484 bset1
= isl_basic_set_read_from_file(ctx
, input
);
485 bset2
= isl_basic_set_read_from_str(ctx
, str
);
487 equal
= isl_basic_set_is_equal(bset1
, bset2
);
489 isl_basic_set_free(bset1
);
490 isl_basic_set_free(bset2
);
498 isl_die(ctx
, isl_error_unknown
,
499 "read sets not equal", return -1);
504 static int test_bounded(isl_ctx
*ctx
)
509 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
510 bounded
= isl_set_is_bounded(set
);
516 isl_die(ctx
, isl_error_unknown
,
517 "set not considered bounded", return -1);
519 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
520 bounded
= isl_set_is_bounded(set
);
527 isl_die(ctx
, isl_error_unknown
,
528 "set considered bounded", return -1);
530 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
531 bounded
= isl_set_is_bounded(set
);
537 isl_die(ctx
, isl_error_unknown
,
538 "set considered bounded", return -1);
543 /* Construct the basic set { [i] : 5 <= i <= N } */
544 static int test_construction_1(isl_ctx
*ctx
)
551 space
= isl_space_set_alloc(ctx
, 1, 1);
552 bset
= isl_basic_set_universe(isl_space_copy(space
));
553 ls
= isl_local_space_from_space(space
);
555 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
556 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
557 c
= isl_constraint_set_coefficient_si(c
, isl_dim_param
, 0, 1);
558 bset
= isl_basic_set_add_constraint(bset
, c
);
560 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
561 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
562 c
= isl_constraint_set_constant_si(c
, -5);
563 bset
= isl_basic_set_add_constraint(bset
, c
);
565 isl_local_space_free(ls
);
566 isl_basic_set_free(bset
);
571 /* Construct the basic set { [x] : -100 <= x <= 100 }
572 * using isl_basic_set_{lower,upper}_bound_val and
573 * check that it is equal the same basic set parsed from a string.
575 static int test_construction_2(isl_ctx
*ctx
)
580 isl_basic_set
*bset1
, *bset2
;
582 v
= isl_val_int_from_si(ctx
, 100);
583 space
= isl_space_set_alloc(ctx
, 0, 1);
584 bset1
= isl_basic_set_universe(space
);
585 bset1
= isl_basic_set_upper_bound_val(bset1
, isl_dim_set
, 0,
587 bset1
= isl_basic_set_lower_bound_val(bset1
, isl_dim_set
, 0,
589 bset2
= isl_basic_set_read_from_str(ctx
, "{ [x] : -100 <= x <= 100 }");
590 equal
= isl_basic_set_is_equal(bset1
, bset2
);
591 isl_basic_set_free(bset1
);
592 isl_basic_set_free(bset2
);
597 isl_die(ctx
, isl_error_unknown
,
598 "failed construction", return -1);
603 /* Basic tests for constructing basic sets.
605 static int test_construction(isl_ctx
*ctx
)
607 if (test_construction_1(ctx
) < 0)
609 if (test_construction_2(ctx
) < 0)
614 static int test_dim(isl_ctx
*ctx
)
617 isl_map
*map1
, *map2
;
620 map1
= isl_map_read_from_str(ctx
,
621 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
622 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
623 map2
= isl_map_read_from_str(ctx
,
624 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
625 equal
= isl_map_is_equal(map1
, map2
);
628 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
629 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
630 if (equal
>= 0 && equal
)
631 equal
= isl_map_is_equal(map1
, map2
);
639 isl_die(ctx
, isl_error_unknown
,
640 "unexpected result", return -1);
642 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
643 map1
= isl_map_read_from_str(ctx
, str
);
644 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
645 map2
= isl_map_read_from_str(ctx
, str
);
646 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
647 equal
= isl_map_is_equal(map1
, map2
);
654 isl_die(ctx
, isl_error_unknown
,
655 "unexpected result", return -1);
661 #define BASE multi_val
662 #include "isl_test_plain_equal_templ.c"
665 #define BASE multi_aff
666 #include "isl_test_plain_equal_templ.c"
668 /* Check that "val" is equal to the value described by "str".
669 * If "str" is "NaN", then check for a NaN value explicitly.
671 static isl_stat
val_check_equal(__isl_keep isl_val
*val
, const char *str
)
678 return isl_stat_error
;
680 ctx
= isl_val_get_ctx(val
);
681 res
= isl_val_read_from_str(ctx
, str
);
682 is_nan
= isl_val_is_nan(res
);
686 ok
= isl_val_is_nan(val
);
688 ok
= isl_val_eq(val
, res
);
691 return isl_stat_error
;
693 isl_die(ctx
, isl_error_unknown
,
694 "unexpected result", return isl_stat_error
);
699 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
703 { &isl_val_neg
, "0", "0" },
704 { &isl_val_abs
, "0", "0" },
705 { &isl_val_pow2
, "0", "1" },
706 { &isl_val_floor
, "0", "0" },
707 { &isl_val_ceil
, "0", "0" },
708 { &isl_val_neg
, "1", "-1" },
709 { &isl_val_neg
, "-1", "1" },
710 { &isl_val_neg
, "1/2", "-1/2" },
711 { &isl_val_neg
, "-1/2", "1/2" },
712 { &isl_val_neg
, "infty", "-infty" },
713 { &isl_val_neg
, "-infty", "infty" },
714 { &isl_val_neg
, "NaN", "NaN" },
715 { &isl_val_abs
, "1", "1" },
716 { &isl_val_abs
, "-1", "1" },
717 { &isl_val_abs
, "1/2", "1/2" },
718 { &isl_val_abs
, "-1/2", "1/2" },
719 { &isl_val_abs
, "infty", "infty" },
720 { &isl_val_abs
, "-infty", "infty" },
721 { &isl_val_abs
, "NaN", "NaN" },
722 { &isl_val_floor
, "1", "1" },
723 { &isl_val_floor
, "-1", "-1" },
724 { &isl_val_floor
, "1/2", "0" },
725 { &isl_val_floor
, "-1/2", "-1" },
726 { &isl_val_floor
, "infty", "infty" },
727 { &isl_val_floor
, "-infty", "-infty" },
728 { &isl_val_floor
, "NaN", "NaN" },
729 { &isl_val_ceil
, "1", "1" },
730 { &isl_val_ceil
, "-1", "-1" },
731 { &isl_val_ceil
, "1/2", "1" },
732 { &isl_val_ceil
, "-1/2", "0" },
733 { &isl_val_ceil
, "infty", "infty" },
734 { &isl_val_ceil
, "-infty", "-infty" },
735 { &isl_val_ceil
, "NaN", "NaN" },
736 { &isl_val_pow2
, "-3", "1/8" },
737 { &isl_val_pow2
, "-1", "1/2" },
738 { &isl_val_pow2
, "1", "2" },
739 { &isl_val_pow2
, "2", "4" },
740 { &isl_val_pow2
, "3", "8" },
741 { &isl_val_inv
, "1", "1" },
742 { &isl_val_inv
, "2", "1/2" },
743 { &isl_val_inv
, "1/2", "2" },
744 { &isl_val_inv
, "-2", "-1/2" },
745 { &isl_val_inv
, "-1/2", "-2" },
746 { &isl_val_inv
, "0", "NaN" },
747 { &isl_val_inv
, "NaN", "NaN" },
748 { &isl_val_inv
, "infty", "0" },
749 { &isl_val_inv
, "-infty", "0" },
752 /* Perform some basic tests of unary operations on isl_val objects.
754 static int test_un_val(isl_ctx
*ctx
)
758 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
760 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
763 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
764 fn
= val_un_tests
[i
].op
;
766 r
= val_check_equal(v
, val_un_tests
[i
].res
);
776 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
777 __isl_take isl_val
*v2
);
779 ['+'] = { &isl_val_add
},
780 ['-'] = { &isl_val_sub
},
781 ['*'] = { &isl_val_mul
},
782 ['/'] = { &isl_val_div
},
783 ['g'] = { &isl_val_gcd
},
784 ['m'] = { &isl_val_min
},
785 ['M'] = { &isl_val_max
},
793 } val_bin_tests
[] = {
794 { "0", '+', "0", "0" },
795 { "1", '+', "0", "1" },
796 { "1", '+', "1", "2" },
797 { "1", '-', "1", "0" },
798 { "1", '*', "1", "1" },
799 { "1", '/', "1", "1" },
800 { "2", '*', "3", "6" },
801 { "2", '*', "1/2", "1" },
802 { "2", '*', "1/3", "2/3" },
803 { "2/3", '*', "3/5", "2/5" },
804 { "2/3", '*', "7/5", "14/15" },
805 { "2", '/', "1/2", "4" },
806 { "-2", '/', "-1/2", "4" },
807 { "-2", '/', "1/2", "-4" },
808 { "2", '/', "-1/2", "-4" },
809 { "2", '/', "2", "1" },
810 { "2", '/', "3", "2/3" },
811 { "2/3", '/', "5/3", "2/5" },
812 { "2/3", '/', "5/7", "14/15" },
813 { "0", '/', "0", "NaN" },
814 { "42", '/', "0", "NaN" },
815 { "-42", '/', "0", "NaN" },
816 { "infty", '/', "0", "NaN" },
817 { "-infty", '/', "0", "NaN" },
818 { "NaN", '/', "0", "NaN" },
819 { "0", '/', "NaN", "NaN" },
820 { "42", '/', "NaN", "NaN" },
821 { "-42", '/', "NaN", "NaN" },
822 { "infty", '/', "NaN", "NaN" },
823 { "-infty", '/', "NaN", "NaN" },
824 { "NaN", '/', "NaN", "NaN" },
825 { "0", '/', "infty", "0" },
826 { "42", '/', "infty", "0" },
827 { "-42", '/', "infty", "0" },
828 { "infty", '/', "infty", "NaN" },
829 { "-infty", '/', "infty", "NaN" },
830 { "NaN", '/', "infty", "NaN" },
831 { "0", '/', "-infty", "0" },
832 { "42", '/', "-infty", "0" },
833 { "-42", '/', "-infty", "0" },
834 { "infty", '/', "-infty", "NaN" },
835 { "-infty", '/', "-infty", "NaN" },
836 { "NaN", '/', "-infty", "NaN" },
837 { "1", '-', "1/3", "2/3" },
838 { "1/3", '+', "1/2", "5/6" },
839 { "1/2", '+', "1/2", "1" },
840 { "3/4", '-', "1/4", "1/2" },
841 { "1/2", '-', "1/3", "1/6" },
842 { "infty", '+', "42", "infty" },
843 { "infty", '+', "infty", "infty" },
844 { "42", '+', "infty", "infty" },
845 { "infty", '-', "infty", "NaN" },
846 { "infty", '*', "infty", "infty" },
847 { "infty", '*', "-infty", "-infty" },
848 { "-infty", '*', "infty", "-infty" },
849 { "-infty", '*', "-infty", "infty" },
850 { "0", '*', "infty", "NaN" },
851 { "1", '*', "infty", "infty" },
852 { "infty", '*', "0", "NaN" },
853 { "infty", '*', "42", "infty" },
854 { "42", '-', "infty", "-infty" },
855 { "infty", '+', "-infty", "NaN" },
856 { "4", 'g', "6", "2" },
857 { "5", 'g', "6", "1" },
858 { "42", 'm', "3", "3" },
859 { "42", 'M', "3", "42" },
860 { "3", 'm', "42", "3" },
861 { "3", 'M', "42", "42" },
862 { "42", 'm', "infty", "42" },
863 { "42", 'M', "infty", "infty" },
864 { "42", 'm', "-infty", "-infty" },
865 { "42", 'M', "-infty", "42" },
866 { "42", 'm', "NaN", "NaN" },
867 { "42", 'M', "NaN", "NaN" },
868 { "infty", 'm', "-infty", "-infty" },
869 { "infty", 'M', "-infty", "infty" },
872 /* Perform some basic tests of binary operations on isl_val objects.
874 static int test_bin_val(isl_ctx
*ctx
)
877 isl_val
*v1
, *v2
, *res
;
878 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
879 __isl_take isl_val
*v2
);
882 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
883 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
884 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
885 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
886 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
888 if (isl_val_is_nan(res
))
889 ok
= isl_val_is_nan(v1
);
891 ok
= isl_val_eq(v1
, res
);
897 isl_die(ctx
, isl_error_unknown
,
898 "unexpected result", return -1);
904 /* Perform some basic tests on isl_val objects.
906 static int test_val(isl_ctx
*ctx
)
908 if (test_un_val(ctx
) < 0)
910 if (test_bin_val(ctx
) < 0)
915 /* Sets described using existentially quantified variables that
916 * can also be described without.
918 static const char *elimination_tests
[] = {
919 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
920 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
921 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
924 /* Check that redundant existentially quantified variables are
927 static int test_elimination(isl_ctx
*ctx
)
933 for (i
= 0; i
< ARRAY_SIZE(elimination_tests
); ++i
) {
934 bset
= isl_basic_set_read_from_str(ctx
, elimination_tests
[i
]);
935 n
= isl_basic_set_dim(bset
, isl_dim_div
);
936 isl_basic_set_free(bset
);
940 isl_die(ctx
, isl_error_unknown
,
941 "expecting no existentials", return -1);
947 static int test_div(isl_ctx
*ctx
)
954 struct isl_basic_set
*bset
;
955 struct isl_constraint
*c
;
958 space
= isl_space_set_alloc(ctx
, 0, 3);
959 bset
= isl_basic_set_universe(isl_space_copy(space
));
960 ls
= isl_local_space_from_space(space
);
962 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
963 c
= isl_constraint_set_constant_si(c
, -1);
964 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
965 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
966 bset
= isl_basic_set_add_constraint(bset
, c
);
968 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
969 c
= isl_constraint_set_constant_si(c
, 1);
970 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
971 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
972 bset
= isl_basic_set_add_constraint(bset
, c
);
974 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
976 assert(bset
&& bset
->n_div
== 1);
977 isl_local_space_free(ls
);
978 isl_basic_set_free(bset
);
981 space
= isl_space_set_alloc(ctx
, 0, 3);
982 bset
= isl_basic_set_universe(isl_space_copy(space
));
983 ls
= isl_local_space_from_space(space
);
985 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
986 c
= isl_constraint_set_constant_si(c
, 1);
987 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
988 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
989 bset
= isl_basic_set_add_constraint(bset
, c
);
991 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
992 c
= isl_constraint_set_constant_si(c
, -1);
993 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
994 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
995 bset
= isl_basic_set_add_constraint(bset
, c
);
997 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
999 assert(bset
&& bset
->n_div
== 1);
1000 isl_local_space_free(ls
);
1001 isl_basic_set_free(bset
);
1004 space
= isl_space_set_alloc(ctx
, 0, 3);
1005 bset
= isl_basic_set_universe(isl_space_copy(space
));
1006 ls
= isl_local_space_from_space(space
);
1008 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1009 c
= isl_constraint_set_constant_si(c
, 1);
1010 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1011 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1012 bset
= isl_basic_set_add_constraint(bset
, c
);
1014 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1015 c
= isl_constraint_set_constant_si(c
, -3);
1016 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1017 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 4);
1018 bset
= isl_basic_set_add_constraint(bset
, c
);
1020 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1022 assert(bset
&& bset
->n_div
== 1);
1023 isl_local_space_free(ls
);
1024 isl_basic_set_free(bset
);
1027 space
= isl_space_set_alloc(ctx
, 0, 3);
1028 bset
= isl_basic_set_universe(isl_space_copy(space
));
1029 ls
= isl_local_space_from_space(space
);
1031 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1032 c
= isl_constraint_set_constant_si(c
, 2);
1033 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1034 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 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_constant_si(c
, -1);
1039 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1040 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1041 bset
= isl_basic_set_add_constraint(bset
, c
);
1043 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1045 assert(isl_basic_set_is_empty(bset
));
1046 isl_local_space_free(ls
);
1047 isl_basic_set_free(bset
);
1050 space
= isl_space_set_alloc(ctx
, 0, 3);
1051 bset
= isl_basic_set_universe(isl_space_copy(space
));
1052 ls
= isl_local_space_from_space(space
);
1054 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1055 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1056 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1057 bset
= isl_basic_set_add_constraint(bset
, c
);
1059 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1060 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1061 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1062 bset
= isl_basic_set_add_constraint(bset
, c
);
1064 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1066 assert(bset
&& bset
->n_div
== 0);
1067 isl_basic_set_free(bset
);
1068 isl_local_space_free(ls
);
1071 space
= isl_space_set_alloc(ctx
, 0, 3);
1072 bset
= isl_basic_set_universe(isl_space_copy(space
));
1073 ls
= isl_local_space_from_space(space
);
1075 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1076 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1077 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1078 bset
= isl_basic_set_add_constraint(bset
, c
);
1080 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1081 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1082 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1083 bset
= isl_basic_set_add_constraint(bset
, c
);
1085 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1087 assert(bset
&& bset
->n_div
== 1);
1088 isl_basic_set_free(bset
);
1089 isl_local_space_free(ls
);
1092 /* This test is a bit tricky. We set up an equality
1093 * a + 3b + 3c = 6 e0
1094 * Normalization of divs creates _two_ divs
1097 * Afterwards e0 is removed again because it has coefficient -1
1098 * and we end up with the original equality and div again.
1099 * Perhaps we can avoid the introduction of this temporary div.
1101 space
= isl_space_set_alloc(ctx
, 0, 4);
1102 bset
= isl_basic_set_universe(isl_space_copy(space
));
1103 ls
= isl_local_space_from_space(space
);
1105 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1106 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1107 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1108 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -3);
1109 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 6);
1110 bset
= isl_basic_set_add_constraint(bset
, c
);
1112 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
1114 /* Test disabled for now */
1116 assert(bset && bset->n_div == 1);
1118 isl_local_space_free(ls
);
1119 isl_basic_set_free(bset
);
1122 space
= isl_space_set_alloc(ctx
, 0, 5);
1123 bset
= isl_basic_set_universe(isl_space_copy(space
));
1124 ls
= isl_local_space_from_space(space
);
1126 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1127 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1128 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1129 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, -3);
1130 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 4, 6);
1131 bset
= isl_basic_set_add_constraint(bset
, c
);
1133 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1134 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1135 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 1);
1136 c
= isl_constraint_set_constant_si(c
, 1);
1137 bset
= isl_basic_set_add_constraint(bset
, c
);
1139 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
1141 /* Test disabled for now */
1143 assert(bset && bset->n_div == 1);
1145 isl_local_space_free(ls
);
1146 isl_basic_set_free(bset
);
1149 space
= isl_space_set_alloc(ctx
, 0, 4);
1150 bset
= isl_basic_set_universe(isl_space_copy(space
));
1151 ls
= isl_local_space_from_space(space
);
1153 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1154 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1155 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -1);
1156 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1157 bset
= isl_basic_set_add_constraint(bset
, c
);
1159 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1160 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1161 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 3);
1162 c
= isl_constraint_set_constant_si(c
, 2);
1163 bset
= isl_basic_set_add_constraint(bset
, c
);
1165 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
1167 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1169 assert(!isl_basic_set_is_empty(bset
));
1171 isl_local_space_free(ls
);
1172 isl_basic_set_free(bset
);
1175 space
= isl_space_set_alloc(ctx
, 0, 3);
1176 bset
= isl_basic_set_universe(isl_space_copy(space
));
1177 ls
= isl_local_space_from_space(space
);
1179 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1180 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1181 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1182 bset
= isl_basic_set_add_constraint(bset
, c
);
1184 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1186 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1188 isl_local_space_free(ls
);
1189 isl_basic_set_free(bset
);
1191 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1192 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1193 set
= isl_set_read_from_str(ctx
, str
);
1194 set
= isl_set_compute_divs(set
);
1199 if (test_elimination(ctx
) < 0)
1202 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1203 set
= isl_set_read_from_str(ctx
, str
);
1204 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
1205 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
1206 empty
= isl_set_is_empty(set
);
1211 isl_die(ctx
, isl_error_unknown
,
1212 "result not as accurate as expected", return -1);
1217 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
1221 struct isl_basic_set
*bset1
, *bset2
;
1222 struct isl_basic_map
*bmap
;
1224 filename
= get_filename(ctx
, name
, "omega");
1226 input
= fopen(filename
, "r");
1229 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1230 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1232 bset1
= isl_basic_set_apply(bset1
, bmap
);
1234 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1236 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1238 isl_basic_set_free(bset1
);
1239 isl_basic_set_free(bset2
);
1245 static int test_application(isl_ctx
*ctx
)
1247 test_application_case(ctx
, "application");
1248 test_application_case(ctx
, "application2");
1253 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1257 struct isl_basic_set
*bset1
, *bset2
;
1259 filename
= get_filename(ctx
, name
, "polylib");
1261 input
= fopen(filename
, "r");
1264 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1265 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1267 bset1
= isl_basic_set_affine_hull(bset1
);
1269 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1271 isl_basic_set_free(bset1
);
1272 isl_basic_set_free(bset2
);
1278 /* Pairs of sets and the corresponding expected results of
1279 * isl_basic_set_recession_cone.
1284 } recession_cone_tests
[] = {
1285 { "{ [i] : 0 <= i <= 10 }", "{ [0] }" },
1286 { "{ [i] : 0 <= i }", "{ [i] : 0 <= i }" },
1287 { "{ [i] : i <= 10 }", "{ [i] : i <= 0 }" },
1288 { "{ [i] : false }", "{ [i] : false }" },
1291 /* Perform some basic isl_basic_set_recession_cone tests.
1293 static int test_recession_cone(struct isl_ctx
*ctx
)
1297 for (i
= 0; i
< ARRAY_SIZE(recession_cone_tests
); ++i
) {
1299 isl_basic_set
*bset
;
1300 isl_basic_set
*cone
, *expected
;
1303 str
= recession_cone_tests
[i
].set
;
1304 bset
= isl_basic_set_read_from_str(ctx
, str
);
1305 str
= recession_cone_tests
[i
].cone
;
1306 expected
= isl_basic_set_read_from_str(ctx
, str
);
1307 cone
= isl_basic_set_recession_cone(bset
);
1308 equal
= isl_basic_set_is_equal(cone
, expected
);
1309 isl_basic_set_free(cone
);
1310 isl_basic_set_free(expected
);
1314 isl_die(ctx
, isl_error_unknown
, "unexpected cone",
1321 int test_affine_hull(struct isl_ctx
*ctx
)
1325 isl_basic_set
*bset
, *bset2
;
1329 test_affine_hull_case(ctx
, "affine2");
1330 test_affine_hull_case(ctx
, "affine");
1331 test_affine_hull_case(ctx
, "affine3");
1333 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1334 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1335 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1336 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1337 set
= isl_set_read_from_str(ctx
, str
);
1338 bset
= isl_set_affine_hull(set
);
1339 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1340 isl_basic_set_free(bset
);
1344 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1347 /* Check that isl_map_affine_hull is not confused by
1348 * the reordering of divs in isl_map_align_divs.
1350 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1351 "32e0 = b and 32e1 = c); "
1352 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1353 set
= isl_set_read_from_str(ctx
, str
);
1354 bset
= isl_set_affine_hull(set
);
1355 isl_basic_set_free(bset
);
1359 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1360 "32e2 = 31 + 31e0 }";
1361 set
= isl_set_read_from_str(ctx
, str
);
1362 bset
= isl_set_affine_hull(set
);
1363 str
= "{ [a] : exists e : a = 32 e }";
1364 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1365 subset
= isl_basic_set_is_subset(bset
, bset2
);
1366 isl_basic_set_free(bset
);
1367 isl_basic_set_free(bset2
);
1371 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1377 /* Test a special case of isl_set_plain_unshifted_simple_hull
1378 * where older versions of isl would include a redundant constraint
1380 * Check that the result does not have any constraints.
1382 static isl_stat
test_plain_unshifted_simple_hull_special(isl_ctx
*ctx
)
1385 isl_bool is_universe
;
1387 isl_basic_set
*bset
;
1389 str
= "{[x, y] : x = 0 or 2*((x+y)//2) <= y + 2 }";
1390 set
= isl_set_read_from_str(ctx
, str
);
1391 bset
= isl_set_plain_unshifted_simple_hull(set
);
1392 is_universe
= isl_basic_set_plain_is_universe(bset
);
1393 isl_basic_set_free(bset
);
1395 if (is_universe
< 0)
1396 return isl_stat_error
;
1398 isl_die(ctx
, isl_error_unknown
,
1399 "hull should not have any constraints",
1400 return isl_stat_error
);
1405 /* Pairs of maps and the corresponding expected results of
1406 * isl_map_plain_unshifted_simple_hull.
1411 } plain_unshifted_simple_hull_tests
[] = {
1412 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1413 "{ [i] -> [j] : i >= 1 }" },
1414 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1415 "(j mod 4 = 2 and k mod 6 = n) }",
1416 "{ [n] -> [i,j,k] : j mod 4 = 2 }" },
1419 /* Basic tests for isl_map_plain_unshifted_simple_hull.
1421 static int test_plain_unshifted_simple_hull(isl_ctx
*ctx
)
1425 isl_basic_map
*hull
, *expected
;
1428 for (i
= 0; i
< ARRAY_SIZE(plain_unshifted_simple_hull_tests
); ++i
) {
1430 str
= plain_unshifted_simple_hull_tests
[i
].map
;
1431 map
= isl_map_read_from_str(ctx
, str
);
1432 str
= plain_unshifted_simple_hull_tests
[i
].hull
;
1433 expected
= isl_basic_map_read_from_str(ctx
, str
);
1434 hull
= isl_map_plain_unshifted_simple_hull(map
);
1435 equal
= isl_basic_map_is_equal(hull
, expected
);
1436 isl_basic_map_free(hull
);
1437 isl_basic_map_free(expected
);
1441 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1448 /* Pairs of sets and the corresponding expected results of
1449 * isl_set_unshifted_simple_hull.
1454 } unshifted_simple_hull_tests
[] = {
1455 { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1456 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1459 /* Basic tests for isl_set_unshifted_simple_hull.
1461 static int test_unshifted_simple_hull(isl_ctx
*ctx
)
1465 isl_basic_set
*hull
, *expected
;
1468 for (i
= 0; i
< ARRAY_SIZE(unshifted_simple_hull_tests
); ++i
) {
1470 str
= unshifted_simple_hull_tests
[i
].set
;
1471 set
= isl_set_read_from_str(ctx
, str
);
1472 str
= unshifted_simple_hull_tests
[i
].hull
;
1473 expected
= isl_basic_set_read_from_str(ctx
, str
);
1474 hull
= isl_set_unshifted_simple_hull(set
);
1475 equal
= isl_basic_set_is_equal(hull
, expected
);
1476 isl_basic_set_free(hull
);
1477 isl_basic_set_free(expected
);
1481 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1488 static int test_simple_hull(struct isl_ctx
*ctx
)
1492 isl_basic_set
*bset
;
1495 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1496 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1497 set
= isl_set_read_from_str(ctx
, str
);
1498 bset
= isl_set_simple_hull(set
);
1499 is_empty
= isl_basic_set_is_empty(bset
);
1500 isl_basic_set_free(bset
);
1502 if (is_empty
== isl_bool_error
)
1505 if (is_empty
== isl_bool_false
)
1506 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1509 if (test_plain_unshifted_simple_hull_special(ctx
) < 0)
1511 if (test_plain_unshifted_simple_hull(ctx
) < 0)
1513 if (test_unshifted_simple_hull(ctx
) < 0)
1519 /* Inputs for isl_set_get_simple_fixed_box_hull tests.
1520 * "set" is the input set.
1521 * "offset" is the expected box offset.
1522 * "size" is the expected box size.
1528 } box_hull_tests
[] = {
1529 { "{ S[x, y] : 0 <= x, y < 10 }", "{ S[0, 0] }", "{ S[10, 10] }" },
1530 { "[N] -> { S[x, y] : N <= x, y < N + 10 }",
1531 "[N] -> { S[N, N] }", "{ S[10, 10] }" },
1532 { "{ S[x, y] : 0 <= x + y, x - y < 10 }",
1533 "{ S[0, -4] }", "{ S[10, 9] }" },
1534 { "{ [i=0:10] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1535 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1536 "{ [3] }", "{ [8] }" },
1537 { "[N] -> { [w = 0:17] : exists (e0: w < 2N and "
1538 "-1 + w <= e0 <= w and 2e0 >= N + w and w <= 2e0 <= 15 + w) }",
1539 "[N] -> { [N] }", "{ [9] }" },
1542 /* Perform basic isl_set_get_simple_fixed_box_hull tests.
1544 static int test_box_hull(struct isl_ctx
*ctx
)
1548 for (i
= 0; i
< ARRAY_SIZE(box_hull_tests
); ++i
) {
1552 isl_multi_aff
*offset
;
1553 isl_multi_val
*size
;
1556 set
= isl_set_read_from_str(ctx
, box_hull_tests
[i
].set
);
1557 box
= isl_set_get_simple_fixed_box_hull(set
);
1558 offset
= isl_fixed_box_get_offset(box
);
1559 size
= isl_fixed_box_get_size(box
);
1560 str
= box_hull_tests
[i
].offset
;
1561 r
= multi_aff_check_plain_equal(offset
, str
);
1562 str
= box_hull_tests
[i
].size
;
1564 r
= multi_val_check_plain_equal(size
, str
);
1565 isl_multi_aff_free(offset
);
1566 isl_multi_val_free(size
);
1567 isl_fixed_box_free(box
);
1576 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1580 struct isl_basic_set
*bset1
, *bset2
;
1581 struct isl_set
*set
;
1583 filename
= get_filename(ctx
, name
, "polylib");
1585 input
= fopen(filename
, "r");
1588 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1589 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1591 set
= isl_basic_set_union(bset1
, bset2
);
1592 bset1
= isl_set_convex_hull(set
);
1594 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1596 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1598 isl_basic_set_free(bset1
);
1599 isl_basic_set_free(bset2
);
1608 } convex_hull_tests
[] = {
1609 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1610 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1611 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1612 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1613 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1614 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1615 "i2 <= 5 and i2 >= 4; "
1616 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1617 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1618 "i2 <= 5 + i0 and i2 >= i0 }" },
1619 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1620 "{ [x, y] : 1 = 0 }" },
1621 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1622 "[x, y, 0] : x >= 0 and y < 0 }",
1623 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1624 { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and "
1626 "[0, 2, 0]; [3, 1, 0] }",
1627 "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and "
1628 "5c <= 6 - a - 3b }" },
1631 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1634 int orig_convex
= ctx
->opt
->convex
;
1635 ctx
->opt
->convex
= convex
;
1637 test_convex_hull_case(ctx
, "convex0");
1638 test_convex_hull_case(ctx
, "convex1");
1639 test_convex_hull_case(ctx
, "convex2");
1640 test_convex_hull_case(ctx
, "convex3");
1641 test_convex_hull_case(ctx
, "convex4");
1642 test_convex_hull_case(ctx
, "convex5");
1643 test_convex_hull_case(ctx
, "convex6");
1644 test_convex_hull_case(ctx
, "convex7");
1645 test_convex_hull_case(ctx
, "convex8");
1646 test_convex_hull_case(ctx
, "convex9");
1647 test_convex_hull_case(ctx
, "convex10");
1648 test_convex_hull_case(ctx
, "convex11");
1649 test_convex_hull_case(ctx
, "convex12");
1650 test_convex_hull_case(ctx
, "convex13");
1651 test_convex_hull_case(ctx
, "convex14");
1652 test_convex_hull_case(ctx
, "convex15");
1654 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1655 isl_set
*set1
, *set2
;
1658 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1659 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1660 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1661 equal
= isl_set_is_equal(set1
, set2
);
1668 isl_die(ctx
, isl_error_unknown
,
1669 "unexpected convex hull", return -1);
1672 ctx
->opt
->convex
= orig_convex
;
1677 static int test_convex_hull(isl_ctx
*ctx
)
1679 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1681 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1686 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1690 struct isl_basic_set
*bset1
, *bset2
;
1692 filename
= get_filename(ctx
, name
, "polylib");
1694 input
= fopen(filename
, "r");
1697 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1698 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1700 bset1
= isl_basic_set_gist(bset1
, bset2
);
1702 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1704 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1706 isl_basic_set_free(bset1
);
1707 isl_basic_set_free(bset2
);
1713 /* Check that computing the gist of "map" with respect to "context"
1714 * does not make any copy of "map" get marked empty.
1715 * Earlier versions of isl would end up doing that.
1717 static isl_stat
test_gist_empty_pair(isl_ctx
*ctx
, const char *map
,
1718 const char *context
)
1720 isl_map
*m1
, *m2
, *m3
;
1721 isl_bool empty_before
, empty_after
;
1723 m1
= isl_map_read_from_str(ctx
, map
);
1724 m2
= isl_map_read_from_str(ctx
, context
);
1725 m3
= isl_map_copy(m1
);
1726 empty_before
= isl_map_is_empty(m3
);
1727 m1
= isl_map_gist(m1
, m2
);
1728 empty_after
= isl_map_is_empty(m3
);
1732 if (empty_before
< 0 || empty_after
< 0)
1733 return isl_stat_error
;
1735 isl_die(ctx
, isl_error_unknown
, "map should not be empty",
1736 return isl_stat_error
);
1738 isl_die(ctx
, isl_error_unknown
, "map should still not be empty",
1739 return isl_stat_error
);
1744 /* Check that computing a gist does not make any copy of the input
1746 * Earlier versions of isl would end up doing that on some pairs of inputs.
1748 static isl_stat
test_gist_empty(isl_ctx
*ctx
)
1750 const char *map
, *context
;
1752 map
= "{ [] -> [a, b, c] : 2b = 1 + a }";
1753 context
= "{ [] -> [a, b, c] : 2c = 2 + a }";
1754 if (test_gist_empty_pair(ctx
, map
, context
) < 0)
1755 return isl_stat_error
;
1756 map
= "{ [] -> [0, 0] }";
1757 context
= "{ [] -> [a, b] : a > b }";
1758 if (test_gist_empty_pair(ctx
, map
, context
) < 0)
1759 return isl_stat_error
;
1764 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1768 const char *context
;
1770 } plain_gist_tests
[] = {
1771 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1772 "{ [i] -> [j] : i >= 1 }",
1773 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1774 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1775 "(j mod 4 = 2 and k mod 6 = n) }",
1776 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1777 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1778 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1779 "{ [i] -> [j] : i > j }",
1780 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1783 /* Basic tests for isl_map_plain_gist_basic_map.
1785 static int test_plain_gist(isl_ctx
*ctx
)
1789 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1792 isl_map
*map
, *gist
;
1793 isl_basic_map
*context
;
1795 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1796 str
= plain_gist_tests
[i
].context
;
1797 context
= isl_basic_map_read_from_str(ctx
, str
);
1798 map
= isl_map_plain_gist_basic_map(map
, context
);
1799 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1800 equal
= isl_map_is_equal(map
, gist
);
1806 isl_die(ctx
, isl_error_unknown
,
1807 "incorrect gist result", return -1);
1813 /* Inputs for isl_basic_set_gist tests that are expected to fail.
1817 const char *context
;
1818 } gist_fail_tests
[] = {
1819 { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1820 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1821 "{ [i] : i >= 0 }" },
1824 /* Check that isl_basic_set_gist fails (gracefully) when expected.
1825 * In particular, the user should be able to recover from the failure.
1827 static isl_stat
test_gist_fail(struct isl_ctx
*ctx
)
1832 on_error
= isl_options_get_on_error(ctx
);
1833 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
1834 n
= ARRAY_SIZE(gist_fail_tests
);
1835 for (i
= 0; i
< n
; ++i
) {
1837 isl_basic_set
*bset
, *context
;
1839 bset
= isl_basic_set_read_from_str(ctx
, gist_fail_tests
[i
].set
);
1840 str
= gist_fail_tests
[i
].context
;
1841 context
= isl_basic_set_read_from_str(ctx
, str
);
1842 bset
= isl_basic_set_gist(bset
, context
);
1843 isl_basic_set_free(bset
);
1847 isl_options_set_on_error(ctx
, on_error
);
1849 isl_die(ctx
, isl_error_unknown
,
1850 "operation not expected to succeed",
1851 return isl_stat_error
);
1858 const char *context
;
1861 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1862 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1863 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1864 "{ [a, b, c] : a <= 15 }" },
1865 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1866 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1867 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1868 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1869 { "{ [m, n, a, b] : a <= 2147 + n }",
1870 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1871 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1872 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1874 "{ [m, n, ku, kl] }" },
1875 { "{ [a, a, b] : a >= 10 }",
1876 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1877 "{ [a, a, b] : a >= 10 }" },
1878 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1879 "{ [0, j] : j >= 0 }" },
1880 /* Check that no constraints on i6 are introduced in the gist */
1881 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1882 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1883 "5e0 <= 381 - t1 and i4 <= 1) }",
1884 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1885 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1886 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1887 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1888 "20e0 >= 1511 - 4t1 - 5i4) }" },
1889 /* Check that no constraints on i6 are introduced in the gist */
1890 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1891 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1892 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1893 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1894 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1895 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1896 "20e1 <= 1530 - 4t1 - 5i4 and "
1897 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1898 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1899 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1900 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1901 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1902 "10e0 <= -91 + 5i4 + 4i6 and "
1903 "10e0 >= -105 + 5i4 + 4i6) }",
1904 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1905 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1906 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1907 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1908 "{ [a, b, q, p] : b >= 1 + a }",
1909 "{ [a, b, q, p] : false }" },
1910 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1911 "[n] -> { [x] : x mod 32 = 0 }",
1912 "[n] -> { [x = n] }" },
1913 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1914 "{ [x] : x mod 2 = 0 }" },
1915 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1916 "{ [x] : x mod 128 = 0 }" },
1917 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1918 "{ [x] : x mod 3200 = 0 }" },
1919 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1920 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1921 "{ [a, b, c = a] }" },
1922 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1923 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1924 "{ [a, b, c = a] : a mod 3 = 0 }" },
1925 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1926 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1928 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1929 "{ [x,y] : 1 <= y <= 3 }",
1933 /* Check that isl_set_gist behaves as expected.
1935 * For the test cases in gist_tests, besides checking that the result
1936 * is as expected, also check that applying the gist operation does
1937 * not modify the input set (an earlier version of isl would do that) and
1938 * that the test case is consistent, i.e., that the gist has the same
1939 * intersection with the context as the input set.
1941 static int test_gist(struct isl_ctx
*ctx
)
1945 isl_basic_set
*bset1
, *bset2
;
1946 isl_map
*map1
, *map2
;
1950 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1951 isl_bool equal_input
, equal_intersection
;
1952 isl_set
*set1
, *set2
, *copy
, *context
;
1954 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1955 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1956 copy
= isl_set_copy(set1
);
1957 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1958 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1959 equal
= isl_set_is_equal(set1
, set2
);
1961 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1962 equal_input
= isl_set_is_equal(set1
, copy
);
1964 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1965 set2
= isl_set_intersect(set2
, context
);
1966 equal_intersection
= isl_set_is_equal(set1
, set2
);
1969 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1972 isl_die(ctx
, isl_error_unknown
,
1973 "incorrect gist result", return -1);
1975 isl_die(ctx
, isl_error_unknown
,
1976 "gist modified input", return -1);
1978 isl_die(ctx
, isl_error_unknown
,
1979 "inconsistent gist test case", return -1);
1982 if (test_gist_fail(ctx
) < 0)
1985 test_gist_case(ctx
, "gist1");
1987 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1988 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1989 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1990 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1991 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1992 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1993 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1994 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1995 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1996 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1997 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1998 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1999 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
2000 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
2001 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
2002 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
2003 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
2004 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
2005 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2006 bset1
= isl_basic_set_gist(bset1
, bset2
);
2007 assert(bset1
&& bset1
->n_div
== 0);
2008 isl_basic_set_free(bset1
);
2010 /* Check that the integer divisions of the second disjunct
2011 * do not spread to the first disjunct.
2013 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
2014 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
2015 "(exists (e0 = [(-1 + t1)/16], "
2016 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
2017 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
2018 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
2019 "o0 <= 4294967295 and t1 <= -1)) }";
2020 map1
= isl_map_read_from_str(ctx
, str
);
2021 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
2022 map2
= isl_map_read_from_str(ctx
, str
);
2023 map1
= isl_map_gist(map1
, map2
);
2027 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
2028 isl_map_free(map1
); return -1);
2029 n_div
= isl_basic_map_dim(map1
->p
[0], isl_dim_div
);
2034 isl_die(ctx
, isl_error_unknown
, "expecting single div",
2037 if (test_gist_empty(ctx
) < 0)
2039 if (test_plain_gist(ctx
) < 0)
2045 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
2047 isl_set
*set
, *set2
;
2051 set
= isl_set_read_from_str(ctx
, str
);
2052 set
= isl_set_coalesce(set
);
2053 set2
= isl_set_read_from_str(ctx
, str
);
2054 equal
= isl_set_is_equal(set
, set2
);
2055 one
= set
&& set
->n
== 1;
2062 isl_die(ctx
, isl_error_unknown
,
2063 "coalesced set not equal to input", return -1);
2064 if (check_one
&& !one
)
2065 isl_die(ctx
, isl_error_unknown
,
2066 "coalesced set should not be a union", return -1);
2071 /* Inputs for coalescing tests with unbounded wrapping.
2072 * "str" is a string representation of the input set.
2073 * "single_disjunct" is set if we expect the result to consist of
2074 * a single disjunct.
2077 int single_disjunct
;
2079 } coalesce_unbounded_tests
[] = {
2080 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
2081 "-x - y + 1 >= 0 and -3 <= z <= 3;"
2082 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
2083 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
2085 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
2086 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
2087 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
2088 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
2089 { 0, "{ [x, y, z] : 0 <= x,y,z <= 100 and 0 < z <= 2 + 2x + 2y; "
2090 "[x, y, 0] : x,y <= 100 and y <= 9 + 11x and x <= 9 + 11y }" },
2093 /* Test the functionality of isl_set_coalesce with the bounded wrapping
2094 * option turned off.
2096 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
2102 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
2103 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
2105 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
2106 const char *str
= coalesce_unbounded_tests
[i
].str
;
2107 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
2108 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
2114 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
2119 /* Inputs for coalescing tests.
2120 * "str" is a string representation of the input set.
2121 * "single_disjunct" is set if we expect the result to consist of
2122 * a single disjunct.
2125 int single_disjunct
;
2127 } coalesce_tests
[] = {
2128 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
2129 "y >= x & x >= 2 & 5 >= y }" },
2130 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2131 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
2132 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2133 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
2134 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2135 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
2136 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2137 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
2138 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2139 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
2140 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
2141 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
2142 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
2143 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
2144 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
2145 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
2146 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
2147 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2148 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2149 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2150 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
2151 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
2152 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
2153 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
2154 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
2155 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2156 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2157 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2158 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
2159 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
2160 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
2161 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
2162 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
2163 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
2164 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
2165 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
2166 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
2167 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
2168 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
2169 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
2170 "[o0, o1, o2, o3, o4, o5, o6]] : "
2171 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
2172 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
2173 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
2174 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
2175 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
2176 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
2177 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
2178 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
2179 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
2180 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
2181 "o6 >= i3 + i6 - o3 and M >= 0 and "
2182 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
2183 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
2184 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
2185 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
2186 "(o0 = 0 and M >= 2 and N >= 3) or "
2187 "(M = 0 and o0 = 0 and N >= 3) }" },
2188 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
2189 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
2190 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
2191 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
2192 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
2193 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
2194 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
2195 "(y = 3 and x = 1) }" },
2196 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
2197 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
2198 "i1 <= M and i3 <= M and i4 <= M) or "
2199 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
2200 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
2201 "i4 <= -1 + M) }" },
2202 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
2203 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
2204 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
2205 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
2206 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
2207 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
2208 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
2209 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
2210 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
2211 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
2212 { 0, "{ [a, b] : exists e : 2e = a and "
2213 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
2214 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
2215 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
2216 "j >= 1 and j' <= i + j - i' and i >= 1; "
2218 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
2219 "[i,j] : exists a : j = 3a }" },
2220 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
2221 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
2223 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
2224 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
2225 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
2226 "c <= 6 + 8a and a >= 3; "
2227 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
2228 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
2229 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2230 "[x,0] : 3 <= x <= 4 }" },
2231 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
2232 "[x,0] : 4 <= x <= 5 }" },
2233 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2234 "[x,0] : 3 <= x <= 5 }" },
2235 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
2236 "[x,0] : 3 <= x <= 4 }" },
2237 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
2239 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
2240 { 1, "{ [0,0]; [1,1] }" },
2241 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
2242 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
2244 "[k, 0, k] : k <= 6 and k >= 1 }" },
2245 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
2246 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
2247 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
2248 { 1, "[n] -> { [1] : n >= 0;"
2249 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
2250 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
2251 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
2252 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
2253 "2e0 <= x and 2e0 <= n);"
2254 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
2256 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
2257 "128e0 >= -134 + 127t1 and t1 >= 2 and "
2258 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
2260 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
2261 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
2263 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
2264 "t1 >= 13 and t1 <= 16);"
2265 "[t1] : t1 <= 15 and t1 >= 12 }" },
2266 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2267 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2268 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2269 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2270 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2271 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2273 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2274 "(exists (e0 : 3e0 = -2 + c0)) }" },
2275 { 0, "[n, b0, t0] -> "
2276 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2277 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2278 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2279 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2280 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2281 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2282 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2283 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2284 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2285 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2286 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2287 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2288 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2289 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2290 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2291 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2292 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2293 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2294 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2295 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2296 { 0, "{ [i0, i1, i2] : "
2297 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2298 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2299 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2300 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2301 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2302 "32e0 <= 31 + i0)) or "
2304 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2305 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2306 "2*floor((c)/2) = c and 0 <= a <= 192;"
2307 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2309 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2310 "(0 <= a <= b <= n) }" },
2311 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2312 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2313 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2314 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2315 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2316 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2317 "b = 3 and 9e0 <= -19 + 2c)) }" },
2318 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2319 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2320 "(a = 4 and b = 3 and "
2321 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2322 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2323 "(b = -1 + a and 0 < a <= 3 and "
2324 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2325 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2326 "b = 3 and 9e0 <= -19 + 2c)) }" },
2327 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2329 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2331 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2332 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2333 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2334 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2335 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2336 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2337 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2338 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2339 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2340 { 1, "{ [a] : a <= 8 and "
2341 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2342 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2343 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2344 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2345 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2346 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2347 "(a < 0 and 3*floor((a)/3) < a) }" },
2348 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2349 "(a < -1 and 3*floor((a)/3) < a) }" },
2350 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2351 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2352 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2353 "or (2 <= a <= 15 and b < a)) }" },
2354 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2355 "32*floor((a)/32) < a) or a <= 15) }" },
2356 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2357 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2358 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2359 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2360 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2361 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2362 "S_0[n] : n <= m <= 2 + n }" },
2363 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2364 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2366 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2367 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2368 "2e0 < -a + 2b) }" },
2369 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2370 "[i, 0, i] : 0 <= i <= 7 }" },
2371 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2372 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2373 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2374 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2375 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2376 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2377 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2378 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2379 "a > 0 and a <= 5) }" },
2380 { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" },
2381 { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and "
2382 "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; "
2383 "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" },
2384 { 1, "{ [a] : (a = 0 or ((1 + a) mod 2 = 0 and 0 < a <= 15) or "
2385 "((a) mod 2 = 0 and 0 < a <= 15)) }" },
2388 /* A specialized coalescing test case that would result
2389 * in a segmentation fault or a failed assertion in earlier versions of isl.
2391 static int test_coalesce_special(struct isl_ctx
*ctx
)
2394 isl_map
*map1
, *map2
;
2396 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2397 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2398 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2399 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2400 "o1 <= 239 and o1 >= 212)) or "
2401 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2402 "o1 <= 241 and o1 >= 240));"
2403 "[S_L220_OUT[] -> T7[]] -> "
2404 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2405 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2406 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2407 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2408 map1
= isl_map_read_from_str(ctx
, str
);
2409 map1
= isl_map_align_divs_internal(map1
);
2410 map1
= isl_map_coalesce(map1
);
2411 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2412 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2413 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2414 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2415 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2416 map2
= isl_map_read_from_str(ctx
, str
);
2417 map2
= isl_map_union(map2
, map1
);
2418 map2
= isl_map_align_divs_internal(map2
);
2419 map2
= isl_map_coalesce(map2
);
2427 /* A specialized coalescing test case that would result in an assertion
2428 * in an earlier version of isl.
2429 * The explicit call to isl_basic_set_union prevents the implicit
2430 * equality constraints in the first basic map from being detected prior
2431 * to the call to isl_set_coalesce, at least at the point
2432 * where this test case was introduced.
2434 static int test_coalesce_special2(struct isl_ctx
*ctx
)
2437 isl_basic_set
*bset1
, *bset2
;
2440 str
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2441 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2442 str
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2443 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2444 set
= isl_basic_set_union(bset1
, bset2
);
2445 set
= isl_set_coalesce(set
);
2453 /* Check that calling isl_set_coalesce does not leave other sets
2454 * that may share some information with the input to isl_set_coalesce
2455 * in an inconsistent state.
2456 * In particular, older versions of isl would modify all copies
2457 * of the basic sets in the isl_set_coalesce input in a way
2458 * that could leave them in an inconsistent state.
2459 * The result of printing any other set containing one of these
2460 * basic sets would then result in an invalid set description.
2462 static int test_coalesce_special3(isl_ctx
*ctx
)
2466 isl_set
*set1
, *set2
;
2469 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2470 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2471 set2
= isl_set_read_from_str(ctx
, str
);
2472 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2473 set1
= isl_set_coalesce(set1
);
2476 p
= isl_printer_to_str(ctx
);
2477 p
= isl_printer_print_set(p
, set2
);
2479 s
= isl_printer_get_str(p
);
2480 isl_printer_free(p
);
2481 set1
= isl_set_read_from_str(ctx
, s
);
2491 /* Check that calling isl_set_coalesce on the intersection of
2492 * the sets described by "s1" and "s2" does not leave other sets
2493 * that may share some information with the input to isl_set_coalesce
2494 * in an inconsistent state.
2495 * In particular, when isl_set_coalesce detects equality constraints,
2496 * it does not immediately perform Gaussian elimination on them,
2497 * but then it needs to ensure that it is performed at some point.
2498 * The input set has implicit equality constraints in the first disjunct.
2499 * It is constructed as an intersection, because otherwise
2500 * those equality constraints would already be detected during parsing.
2502 static isl_stat
test_coalesce_intersection(isl_ctx
*ctx
,
2503 const char *s1
, const char *s2
)
2505 isl_set
*set1
, *set2
;
2507 set1
= isl_set_read_from_str(ctx
, s1
);
2508 set2
= isl_set_read_from_str(ctx
, s2
);
2509 set1
= isl_set_intersect(set1
, set2
);
2510 isl_set_free(isl_set_coalesce(isl_set_copy(set1
)));
2511 set1
= isl_set_coalesce(set1
);
2515 return isl_stat_error
;
2520 /* Check that calling isl_set_coalesce does not leave other sets
2521 * that may share some information with the input to isl_set_coalesce
2522 * in an inconsistent state, for the case where one disjunct
2523 * is a subset of the other.
2525 static isl_stat
test_coalesce_special4(isl_ctx
*ctx
)
2527 const char *s1
, *s2
;
2529 s1
= "{ [a, b] : b <= 0 or a <= 1 }";
2530 s2
= "{ [a, b] : -1 <= -a < b }";
2531 return test_coalesce_intersection(ctx
, s1
, s2
);
2534 /* Check that calling isl_set_coalesce does not leave other sets
2535 * that may share some information with the input to isl_set_coalesce
2536 * in an inconsistent state, for the case where two disjuncts
2539 static isl_stat
test_coalesce_special5(isl_ctx
*ctx
)
2541 const char *s1
, *s2
;
2543 s1
= "{ [a, b, c] : b <= 0 }";
2544 s2
= "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }";
2545 return test_coalesce_intersection(ctx
, s1
, s2
);
2548 /* Check that calling isl_set_coalesce does not leave other sets
2549 * that may share some information with the input to isl_set_coalesce
2550 * in an inconsistent state, for the case where two disjuncts
2551 * can be fused and where both disjuncts have implicit equality constraints.
2553 static isl_stat
test_coalesce_special6(isl_ctx
*ctx
)
2555 const char *s1
, *s2
;
2557 s1
= "{ [a, b, c] : c <= 0 }";
2558 s2
= "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }";
2559 return test_coalesce_intersection(ctx
, s1
, s2
);
2562 /* Test the functionality of isl_set_coalesce.
2563 * That is, check that the output is always equal to the input
2564 * and in some cases that the result consists of a single disjunct.
2566 static int test_coalesce(struct isl_ctx
*ctx
)
2570 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2571 const char *str
= coalesce_tests
[i
].str
;
2572 int check_one
= coalesce_tests
[i
].single_disjunct
;
2573 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2577 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2579 if (test_coalesce_special(ctx
) < 0)
2581 if (test_coalesce_special2(ctx
) < 0)
2583 if (test_coalesce_special3(ctx
) < 0)
2585 if (test_coalesce_special4(ctx
) < 0)
2587 if (test_coalesce_special5(ctx
) < 0)
2589 if (test_coalesce_special6(ctx
) < 0)
2596 /* Construct a representation of the graph on the right of Figure 1
2597 * in "Computing the Transitive Closure of a Union of
2598 * Affine Integer Tuple Relations".
2600 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2603 isl_map
*up
, *right
;
2605 dom
= isl_set_read_from_str(ctx
,
2606 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2607 "2 x - 3 y + 3 >= 0 }");
2608 right
= isl_map_read_from_str(ctx
,
2609 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2610 up
= isl_map_read_from_str(ctx
,
2611 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2612 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2613 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2614 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2615 up
= isl_map_intersect_range(up
, dom
);
2616 return isl_map_union(up
, right
);
2619 /* Construct a representation of the power of the graph
2620 * on the right of Figure 1 in "Computing the Transitive Closure of
2621 * a Union of Affine Integer Tuple Relations".
2623 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2625 return isl_map_read_from_str(ctx
,
2626 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2627 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2628 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2631 /* Construct a representation of the transitive closure of the graph
2632 * on the right of Figure 1 in "Computing the Transitive Closure of
2633 * a Union of Affine Integer Tuple Relations".
2635 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2637 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2640 static int test_closure(isl_ctx
*ctx
)
2643 isl_map
*map
, *map2
;
2644 isl_bool exact
, equal
;
2646 /* COCOA example 1 */
2647 map
= isl_map_read_from_str(ctx
,
2648 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2649 "1 <= i and i < n and 1 <= j and j < n or "
2650 "i2 = i + 1 and j2 = j - 1 and "
2651 "1 <= i and i < n and 2 <= j and j <= n }");
2652 map
= isl_map_power(map
, &exact
);
2656 /* COCOA example 1 */
2657 map
= isl_map_read_from_str(ctx
,
2658 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2659 "1 <= i and i < n and 1 <= j and j < n or "
2660 "i2 = i + 1 and j2 = j - 1 and "
2661 "1 <= i and i < n and 2 <= j and j <= n }");
2662 map
= isl_map_transitive_closure(map
, &exact
);
2664 map2
= isl_map_read_from_str(ctx
,
2665 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2666 "1 <= i and i < n and 1 <= j and j <= n and "
2667 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2668 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2669 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2670 assert(isl_map_is_equal(map
, map2
));
2674 map
= isl_map_read_from_str(ctx
,
2675 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2676 " 0 <= y and y <= n }");
2677 map
= isl_map_transitive_closure(map
, &exact
);
2678 map2
= isl_map_read_from_str(ctx
,
2679 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2680 " 0 <= y and y <= n }");
2681 assert(isl_map_is_equal(map
, map2
));
2685 /* COCOA example 2 */
2686 map
= isl_map_read_from_str(ctx
,
2687 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2688 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2689 "i2 = i + 2 and j2 = j - 2 and "
2690 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2691 map
= isl_map_transitive_closure(map
, &exact
);
2693 map2
= isl_map_read_from_str(ctx
,
2694 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2695 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2696 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2697 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2698 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2699 assert(isl_map_is_equal(map
, map2
));
2703 /* COCOA Fig.2 left */
2704 map
= isl_map_read_from_str(ctx
,
2705 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2706 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2708 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2709 "j <= 2 i - 3 and j <= n - 2 or "
2710 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2711 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2712 map
= isl_map_transitive_closure(map
, &exact
);
2716 /* COCOA Fig.2 right */
2717 map
= isl_map_read_from_str(ctx
,
2718 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2719 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2721 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2722 "j <= 2 i - 4 and j <= n - 3 or "
2723 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2724 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2725 map
= isl_map_power(map
, &exact
);
2729 /* COCOA Fig.2 right */
2730 map
= isl_map_read_from_str(ctx
,
2731 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2732 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2734 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2735 "j <= 2 i - 4 and j <= n - 3 or "
2736 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2737 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2738 map
= isl_map_transitive_closure(map
, &exact
);
2740 map2
= isl_map_read_from_str(ctx
,
2741 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2742 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2743 "j <= n and 3 + i + 2 j <= 3 n and "
2744 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2745 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2746 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2747 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2748 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2749 assert(isl_map_is_equal(map
, map2
));
2753 map
= cocoa_fig_1_right_graph(ctx
);
2754 map
= isl_map_transitive_closure(map
, &exact
);
2756 map2
= cocoa_fig_1_right_tc(ctx
);
2757 assert(isl_map_is_equal(map
, map2
));
2761 map
= cocoa_fig_1_right_graph(ctx
);
2762 map
= isl_map_power(map
, &exact
);
2763 map2
= cocoa_fig_1_right_power(ctx
);
2764 equal
= isl_map_is_equal(map
, map2
);
2770 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2772 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2774 /* COCOA Theorem 1 counter example */
2775 map
= isl_map_read_from_str(ctx
,
2776 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2777 "i2 = 1 and j2 = j or "
2778 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2779 map
= isl_map_transitive_closure(map
, &exact
);
2783 map
= isl_map_read_from_str(ctx
,
2784 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2785 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2786 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2787 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2788 map
= isl_map_transitive_closure(map
, &exact
);
2792 /* Kelly et al 1996, fig 12 */
2793 map
= isl_map_read_from_str(ctx
,
2794 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2795 "1 <= i,j,j+1 <= n or "
2796 "j = n and j2 = 1 and i2 = i + 1 and "
2797 "1 <= i,i+1 <= n }");
2798 map
= isl_map_transitive_closure(map
, &exact
);
2800 map2
= isl_map_read_from_str(ctx
,
2801 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2802 "1 <= i <= n and i = i2 or "
2803 "1 <= i < i2 <= n and 1 <= j <= n and "
2805 assert(isl_map_is_equal(map
, map2
));
2809 /* Omega's closure4 */
2810 map
= isl_map_read_from_str(ctx
,
2811 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2812 "1 <= x,y <= 10 or "
2813 "x2 = x + 1 and y2 = y and "
2814 "1 <= x <= 20 && 5 <= y <= 15 }");
2815 map
= isl_map_transitive_closure(map
, &exact
);
2819 map
= isl_map_read_from_str(ctx
,
2820 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2821 map
= isl_map_transitive_closure(map
, &exact
);
2823 map2
= isl_map_read_from_str(ctx
,
2824 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2825 assert(isl_map_is_equal(map
, map2
));
2829 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2830 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2831 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2832 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2833 map
= isl_map_read_from_str(ctx
, str
);
2834 map
= isl_map_transitive_closure(map
, &exact
);
2836 map2
= isl_map_read_from_str(ctx
, str
);
2837 assert(isl_map_is_equal(map
, map2
));
2841 str
= "{[0] -> [1]; [2] -> [3]}";
2842 map
= isl_map_read_from_str(ctx
, str
);
2843 map
= isl_map_transitive_closure(map
, &exact
);
2845 map2
= isl_map_read_from_str(ctx
, str
);
2846 assert(isl_map_is_equal(map
, map2
));
2850 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2851 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2852 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2853 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2854 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2855 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2856 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2857 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2858 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2859 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2860 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2861 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2862 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2863 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2864 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2865 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2866 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2867 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2868 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2869 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2870 map
= isl_map_read_from_str(ctx
, str
);
2871 map
= isl_map_transitive_closure(map
, NULL
);
2878 /* Check that the actual result of a boolean operation is equal
2879 * to the expected result.
2881 static isl_stat
check_bool(isl_ctx
*ctx
, isl_bool actual
, isl_bool expected
)
2883 if (actual
!= expected
)
2884 isl_die(ctx
, isl_error_unknown
,
2885 "incorrect boolean operation", return isl_stat_error
);
2889 /* Test operations on isl_bool values.
2896 static int test_isl_bool(isl_ctx
*ctx
)
2898 if (check_bool(ctx
, isl_bool_not(isl_bool_true
), isl_bool_false
) < 0)
2900 if (check_bool(ctx
, isl_bool_not(isl_bool_false
), isl_bool_true
) < 0)
2902 if (check_bool(ctx
, isl_bool_not(isl_bool_error
), isl_bool_error
) < 0)
2904 if (check_bool(ctx
, isl_bool_ok(0), isl_bool_false
) < 0)
2906 if (check_bool(ctx
, isl_bool_ok(1), isl_bool_true
) < 0)
2908 if (check_bool(ctx
, isl_bool_ok(-1), isl_bool_true
) < 0)
2910 if (check_bool(ctx
, isl_bool_ok(2), isl_bool_true
) < 0)
2912 if (check_bool(ctx
, isl_bool_ok(-2), isl_bool_true
) < 0)
2918 static int test_lex(struct isl_ctx
*ctx
)
2924 space
= isl_space_set_alloc(ctx
, 0, 0);
2925 map
= isl_map_lex_le(space
);
2926 empty
= isl_map_is_empty(map
);
2932 isl_die(ctx
, isl_error_unknown
,
2933 "expecting non-empty result", return -1);
2938 /* Inputs for isl_map_lexmin tests.
2939 * "map" is the input and "lexmin" is the expected result.
2944 } lexmin_tests
[] = {
2945 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2946 "{ [x] -> [5] : 6 <= x <= 8; "
2947 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2948 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2949 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2950 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2951 "{ [x] -> [y] : (4y = x and x >= 0) or "
2952 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2953 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2954 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2955 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2956 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2957 /* Check that empty pieces are properly combined. */
2958 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2959 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2960 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2961 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2962 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2964 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2965 "a <= 255 and c <= 255 and d <= 255 - j and "
2966 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2967 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2968 "247d <= 247 + i and 248 - b <= 248d <= c and "
2969 "254d >= i - a + b and 254d >= -a + b and "
2970 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2972 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2973 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2974 "247j >= 62738 - i and 509j <= 129795 + i and "
2975 "742j >= 188724 - i; "
2976 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2977 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2978 "16*floor((8 + b)/16) <= 7 + b; "
2980 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2981 "[a] -> [b = 0] : 0 < a <= 509 }" },
2982 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2983 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2984 { "{ rat: [i] : 21 <= 2i <= 29 or i = 5 }", "{ rat: [5] }" },
2987 static int test_lexmin(struct isl_ctx
*ctx
)
2992 isl_basic_map
*bmap
;
2993 isl_map
*map
, *map2
;
2996 isl_pw_multi_aff
*pma
;
2998 str
= "[p0, p1] -> { [] -> [] : "
2999 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
3000 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
3001 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
3002 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
3003 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
3004 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
3005 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
3006 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
3007 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
3008 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
3009 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
3010 map
= isl_map_read_from_str(ctx
, str
);
3011 map
= isl_map_lexmin(map
);
3016 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
3017 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
3018 set
= isl_set_read_from_str(ctx
, str
);
3019 set
= isl_set_lexmax(set
);
3020 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
3021 set2
= isl_set_read_from_str(ctx
, str
);
3022 set
= isl_set_intersect(set
, set2
);
3023 assert(!isl_set_is_empty(set
));
3026 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
3027 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
3028 map
= isl_map_lexmin(map
);
3029 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
3030 equal
= isl_map_is_equal(map
, map2
);
3037 isl_die(ctx
, isl_error_unknown
,
3038 "unexpected result", return -1);
3041 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3042 " 8i' <= i and 8i' >= -7 + i }";
3043 bmap
= isl_basic_map_read_from_str(ctx
, str
);
3044 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
3045 map2
= isl_map_from_pw_multi_aff(pma
);
3046 map
= isl_map_from_basic_map(bmap
);
3047 assert(isl_map_is_equal(map
, map2
));
3051 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3052 " 8i' <= i and 8i' >= -7 + i }";
3053 set
= isl_set_read_from_str(ctx
, str
);
3054 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
3055 set2
= isl_set_from_pw_multi_aff(pma
);
3056 equal
= isl_set_is_equal(set
, set2
);
3062 isl_die(ctx
, isl_error_unknown
,
3063 "unexpected difference between set and "
3064 "piecewise affine expression", return -1);
3069 /* Inputs for isl_pw_multi_aff_max_multi_val tests.
3070 * "pma" is the input.
3071 * "res" is the expected result.
3076 } opt_pw_tests
[] = {
3077 { "{ [-1] -> [-1]; [1] -> [1] }", "{ [1] }" },
3078 { "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] : "
3079 "0 <= a, b <= 100 and b mod 2 = 0}", "{ [30] }" },
3080 { "[N] -> { [i,j] -> A[i, -i, i + j] : 0 <= i,j <= N <= 10 }",
3081 "{ A[10, 0, 20] }" },
3082 { "[N] -> {A[N, -N, 2N] : 0 <= N }", "{ A[infty, 0, infty] }" },
3085 /* Perform basic isl_pw_multi_aff_max_multi_val tests.
3087 static isl_stat
test_pw_max(struct isl_ctx
*ctx
)
3090 isl_pw_multi_aff
*pma
;
3094 for (i
= 0; i
< ARRAY_SIZE(opt_pw_tests
); ++i
) {
3095 pma
= isl_pw_multi_aff_read_from_str(ctx
, opt_pw_tests
[i
].pma
);
3096 mv
= isl_pw_multi_aff_max_multi_val(pma
);
3097 r
= multi_val_check_plain_equal(mv
, opt_pw_tests
[i
].res
);
3098 isl_multi_val_free(mv
);
3101 return isl_stat_error
;
3107 /* A specialized isl_set_min_val test case that would return the wrong result
3108 * in earlier versions of isl.
3109 * The explicit call to isl_basic_set_union prevents the second basic set
3110 * from being determined to be empty prior to the call to isl_set_min_val,
3111 * at least at the point where this test case was introduced.
3113 static int test_min_special(isl_ctx
*ctx
)
3116 isl_basic_set
*bset1
, *bset2
;
3122 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
3123 bset1
= isl_basic_set_read_from_str(ctx
, str
);
3124 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
3125 bset2
= isl_basic_set_read_from_str(ctx
, str
);
3126 set
= isl_basic_set_union(bset1
, bset2
);
3127 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
3129 res
= isl_set_min_val(set
, obj
);
3130 ok
= isl_val_cmp_si(res
, 5) == 0;
3139 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
3145 /* A specialized isl_set_min_val test case that would return an error
3146 * in earlier versions of isl.
3148 static int test_min_special2(isl_ctx
*ctx
)
3151 isl_basic_set
*bset
;
3155 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
3156 bset
= isl_basic_set_read_from_str(ctx
, str
);
3158 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
3160 res
= isl_basic_set_max_val(bset
, obj
);
3162 isl_basic_set_free(bset
);
3175 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
3176 __isl_keep isl_aff
*obj
);
3179 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
3180 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
3181 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
3182 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
3183 &isl_set_max_val
, "30" },
3187 /* Perform basic isl_set_min_val and isl_set_max_val tests.
3188 * In particular, check the results on non-convex inputs.
3190 static int test_min(struct isl_ctx
*ctx
)
3198 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
3199 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
3200 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
3201 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
3202 val
= opt_tests
[i
].fn(set
, obj
);
3203 ok
= isl_val_eq(res
, val
);
3212 isl_die(ctx
, isl_error_unknown
,
3213 "unexpected optimum", return -1);
3216 if (test_pw_max(ctx
) < 0)
3218 if (test_min_special(ctx
) < 0)
3220 if (test_min_special2(ctx
) < 0)
3231 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
3232 void *dep_user
, void *user
)
3234 struct must_may
*mm
= (struct must_may
*)user
;
3237 mm
->must
= isl_map_union(mm
->must
, dep
);
3239 mm
->may
= isl_map_union(mm
->may
, dep
);
3244 static int common_space(void *first
, void *second
)
3246 int depth
= *(int *)first
;
3250 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
3258 map2
= isl_map_read_from_str(map
->ctx
, str
);
3259 equal
= isl_map_is_equal(map
, map2
);
3265 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
3269 equal
= map_is_equal(map
, str
);
3273 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
3274 "result not as expected", return -1);
3278 /* Is "set" equal to the set described by "str"?
3280 static isl_bool
set_is_equal(__isl_keep isl_set
*set
, const char *str
)
3286 return isl_bool_error
;
3288 set2
= isl_set_read_from_str(isl_set_get_ctx(set
), str
);
3289 equal
= isl_set_is_equal(set
, set2
);
3295 /* Check that "set" is equal to the set described by "str".
3297 static isl_stat
set_check_equal(__isl_keep isl_set
*set
, const char *str
)
3301 equal
= set_is_equal(set
, str
);
3303 return isl_stat_error
;
3305 isl_die(isl_set_get_ctx(set
), isl_error_unknown
,
3306 "result not as expected", return isl_stat_error
);
3310 /* Is "uset" equal to the union set described by "str"?
3312 static isl_bool
uset_is_equal(__isl_keep isl_union_set
*uset
, const char *str
)
3314 isl_union_set
*uset2
;
3318 return isl_bool_error
;
3320 uset2
= isl_union_set_read_from_str(isl_union_set_get_ctx(uset
), str
);
3321 equal
= isl_union_set_is_equal(uset
, uset2
);
3322 isl_union_set_free(uset2
);
3327 /* Check that "uset" is equal to the union set described by "str".
3329 static isl_stat
uset_check_equal(__isl_keep isl_union_set
*uset
,
3334 equal
= uset_is_equal(uset
, str
);
3336 return isl_stat_error
;
3338 isl_die(isl_union_set_get_ctx(uset
), isl_error_unknown
,
3339 "result not as expected", return isl_stat_error
);
3343 static int test_dep(struct isl_ctx
*ctx
)
3348 isl_access_info
*ai
;
3355 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3356 map
= isl_map_read_from_str(ctx
, str
);
3357 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3359 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3360 map
= isl_map_read_from_str(ctx
, str
);
3361 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3363 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3364 map
= isl_map_read_from_str(ctx
, str
);
3365 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3367 flow
= isl_access_info_compute_flow(ai
);
3368 space
= isl_space_alloc(ctx
, 0, 3, 3);
3369 mm
.must
= isl_map_empty(isl_space_copy(space
));
3370 mm
.may
= isl_map_empty(space
);
3372 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3374 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
3375 " [1,10,0] -> [2,5,0] }";
3376 assert(map_is_equal(mm
.must
, str
));
3377 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3378 assert(map_is_equal(mm
.may
, str
));
3380 isl_map_free(mm
.must
);
3381 isl_map_free(mm
.may
);
3382 isl_flow_free(flow
);
3385 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3386 map
= isl_map_read_from_str(ctx
, str
);
3387 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3389 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3390 map
= isl_map_read_from_str(ctx
, str
);
3391 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3393 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3394 map
= isl_map_read_from_str(ctx
, str
);
3395 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3397 flow
= isl_access_info_compute_flow(ai
);
3398 space
= isl_space_alloc(ctx
, 0, 3, 3);
3399 mm
.must
= isl_map_empty(isl_space_copy(space
));
3400 mm
.may
= isl_map_empty(space
);
3402 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3404 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
3405 assert(map_is_equal(mm
.must
, str
));
3406 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3407 assert(map_is_equal(mm
.may
, str
));
3409 isl_map_free(mm
.must
);
3410 isl_map_free(mm
.may
);
3411 isl_flow_free(flow
);
3414 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3415 map
= isl_map_read_from_str(ctx
, str
);
3416 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3418 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3419 map
= isl_map_read_from_str(ctx
, str
);
3420 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3422 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3423 map
= isl_map_read_from_str(ctx
, str
);
3424 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3426 flow
= isl_access_info_compute_flow(ai
);
3427 space
= isl_space_alloc(ctx
, 0, 3, 3);
3428 mm
.must
= isl_map_empty(isl_space_copy(space
));
3429 mm
.may
= isl_map_empty(space
);
3431 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3433 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
3434 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3435 assert(map_is_equal(mm
.may
, str
));
3436 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3437 assert(map_is_equal(mm
.must
, str
));
3439 isl_map_free(mm
.must
);
3440 isl_map_free(mm
.may
);
3441 isl_flow_free(flow
);
3444 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
3445 map
= isl_map_read_from_str(ctx
, str
);
3446 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3448 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3449 map
= isl_map_read_from_str(ctx
, str
);
3450 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3452 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3453 map
= isl_map_read_from_str(ctx
, str
);
3454 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3456 flow
= isl_access_info_compute_flow(ai
);
3457 space
= isl_space_alloc(ctx
, 0, 3, 3);
3458 mm
.must
= isl_map_empty(isl_space_copy(space
));
3459 mm
.may
= isl_map_empty(space
);
3461 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3463 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3464 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3465 assert(map_is_equal(mm
.may
, str
));
3466 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3467 assert(map_is_equal(mm
.must
, str
));
3469 isl_map_free(mm
.must
);
3470 isl_map_free(mm
.may
);
3471 isl_flow_free(flow
);
3474 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3475 map
= isl_map_read_from_str(ctx
, str
);
3476 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3478 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3479 map
= isl_map_read_from_str(ctx
, str
);
3480 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3482 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3483 map
= isl_map_read_from_str(ctx
, str
);
3484 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3486 flow
= isl_access_info_compute_flow(ai
);
3487 space
= isl_space_alloc(ctx
, 0, 3, 3);
3488 mm
.must
= isl_map_empty(isl_space_copy(space
));
3489 mm
.may
= isl_map_empty(space
);
3491 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3493 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3494 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3495 assert(map_is_equal(mm
.may
, str
));
3496 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3497 assert(map_is_equal(mm
.must
, str
));
3499 isl_map_free(mm
.must
);
3500 isl_map_free(mm
.may
);
3501 isl_flow_free(flow
);
3506 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3507 map
= isl_map_read_from_str(ctx
, str
);
3508 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
3510 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3511 map
= isl_map_read_from_str(ctx
, str
);
3512 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3514 flow
= isl_access_info_compute_flow(ai
);
3515 space
= isl_space_alloc(ctx
, 0, 5, 5);
3516 mm
.must
= isl_map_empty(isl_space_copy(space
));
3517 mm
.may
= isl_map_empty(space
);
3519 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3521 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3522 assert(map_is_equal(mm
.must
, str
));
3523 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3524 assert(map_is_equal(mm
.may
, str
));
3526 isl_map_free(mm
.must
);
3527 isl_map_free(mm
.may
);
3528 isl_flow_free(flow
);
3533 /* Check that the dependence analysis proceeds without errors.
3534 * Earlier versions of isl would break down during the analysis
3535 * due to the use of the wrong spaces.
3537 static int test_flow(isl_ctx
*ctx
)
3540 isl_union_map
*access
, *schedule
;
3541 isl_union_map
*must_dep
, *may_dep
;
3544 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3545 access
= isl_union_map_read_from_str(ctx
, str
);
3546 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3547 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3548 "S2[] -> [1,0,0,0]; "
3549 "S3[] -> [-1,0,0,0] }";
3550 schedule
= isl_union_map_read_from_str(ctx
, str
);
3551 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
3552 isl_union_map_copy(access
), schedule
,
3553 &must_dep
, &may_dep
, NULL
, NULL
);
3554 isl_union_map_free(may_dep
);
3555 isl_union_map_free(must_dep
);
3564 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3565 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3566 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3567 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3568 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3569 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3570 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3571 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3572 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3575 int test_sv(isl_ctx
*ctx
)
3577 isl_union_map
*umap
;
3581 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
3582 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
3583 sv
= isl_union_map_is_single_valued(umap
);
3584 isl_union_map_free(umap
);
3587 if (sv_tests
[i
].sv
&& !sv
)
3588 isl_die(ctx
, isl_error_internal
,
3589 "map not detected as single valued", return -1);
3590 if (!sv_tests
[i
].sv
&& sv
)
3591 isl_die(ctx
, isl_error_internal
,
3592 "map detected as single valued", return -1);
3601 } bijective_tests
[] = {
3602 { "[N,M]->{[i,j] -> [i]}", 0 },
3603 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3604 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3605 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3606 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3607 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3608 { "[N,M]->{[i,j] -> []}", 0 },
3609 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3610 { "[N,M]->{[i,j] -> [2i]}", 0 },
3611 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3612 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3613 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3614 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3617 static int test_bijective(struct isl_ctx
*ctx
)
3623 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
3624 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
3625 bijective
= isl_map_is_bijective(map
);
3629 if (bijective_tests
[i
].bijective
&& !bijective
)
3630 isl_die(ctx
, isl_error_internal
,
3631 "map not detected as bijective", return -1);
3632 if (!bijective_tests
[i
].bijective
&& bijective
)
3633 isl_die(ctx
, isl_error_internal
,
3634 "map detected as bijective", return -1);
3640 /* Inputs for isl_pw_qpolynomial_gist tests.
3641 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3647 } pwqp_gist_tests
[] = {
3648 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3649 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3650 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3651 "{ [i] -> -1/2 + 1/2 * i }" },
3652 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3655 /* Perform some basic isl_pw_qpolynomial_gist tests.
3657 static isl_stat
test_pwqp_gist(isl_ctx
*ctx
)
3662 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3665 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3666 str
= pwqp_gist_tests
[i
].pwqp
;
3667 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3668 str
= pwqp_gist_tests
[i
].set
;
3669 set
= isl_set_read_from_str(ctx
, str
);
3670 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3671 str
= pwqp_gist_tests
[i
].gist
;
3672 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3673 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3674 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3675 isl_pw_qpolynomial_free(pwqp1
);
3678 return isl_stat_error
;
3680 isl_die(ctx
, isl_error_unknown
,
3681 "unexpected result", return isl_stat_error
);
3687 /* Perform a basic isl_pw_qpolynomial_max test.
3689 static isl_stat
test_pwqp_max(isl_ctx
*ctx
)
3692 isl_pw_qpolynomial
*pwqp
;
3696 str
= "{ [x=2:9, y] -> floor((x + 1)/4)^3 - floor((2x)/3)^2 }";
3697 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3698 v
= isl_pw_qpolynomial_max(pwqp
);
3699 ok
= isl_val_cmp_si(v
, -1) == 0;
3703 return isl_stat_error
;
3705 isl_die(ctx
, isl_error_unknown
, "unexpected maximum",
3706 return isl_stat_error
);
3711 static int test_pwqp(struct isl_ctx
*ctx
)
3715 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3718 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3719 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3721 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3724 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3725 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3727 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3729 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3731 isl_pw_qpolynomial_free(pwqp1
);
3733 if (test_pwqp_gist(ctx
) < 0)
3736 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3737 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3738 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3739 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3741 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3743 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3745 isl_pw_qpolynomial_free(pwqp1
);
3747 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3748 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3749 str
= "{ [x] -> x }";
3750 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3752 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3754 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3756 isl_pw_qpolynomial_free(pwqp1
);
3758 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3759 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3760 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3761 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3762 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3763 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3764 isl_pw_qpolynomial_free(pwqp1
);
3766 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3767 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3768 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3769 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3770 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3771 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3772 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3773 isl_pw_qpolynomial_free(pwqp1
);
3774 isl_pw_qpolynomial_free(pwqp2
);
3778 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3780 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3781 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3782 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3783 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3784 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3786 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3787 isl_pw_qpolynomial_free(pwqp1
);
3788 isl_pw_qpolynomial_free(pwqp2
);
3792 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3794 if (test_pwqp_max(ctx
) < 0)
3800 static int test_split_periods(isl_ctx
*ctx
)
3803 isl_pw_qpolynomial
*pwqp
;
3805 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3806 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3807 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3808 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3810 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3812 isl_pw_qpolynomial_free(pwqp
);
3820 static int test_union(isl_ctx
*ctx
)
3823 isl_union_set
*uset1
, *uset2
;
3824 isl_union_map
*umap1
, *umap2
;
3827 str
= "{ [i] : 0 <= i <= 1 }";
3828 uset1
= isl_union_set_read_from_str(ctx
, str
);
3829 str
= "{ [1] -> [0] }";
3830 umap1
= isl_union_map_read_from_str(ctx
, str
);
3832 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3833 equal
= isl_union_map_is_equal(umap1
, umap2
);
3835 isl_union_map_free(umap1
);
3836 isl_union_map_free(umap2
);
3841 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3844 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3845 umap1
= isl_union_map_read_from_str(ctx
, str
);
3846 str
= "{ A[i]; B[i] }";
3847 uset1
= isl_union_set_read_from_str(ctx
, str
);
3849 uset2
= isl_union_map_domain(umap1
);
3851 equal
= isl_union_set_is_equal(uset1
, uset2
);
3853 isl_union_set_free(uset1
);
3854 isl_union_set_free(uset2
);
3859 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3865 /* Check that computing a bound of a non-zero polynomial over an unbounded
3866 * domain does not produce a rational value.
3867 * In particular, check that the upper bound is infinity.
3869 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
3872 isl_pw_qpolynomial
*pwqp
;
3873 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
3876 str
= "{ [m,n] -> -m * n }";
3877 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3878 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3880 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3881 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3882 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
3883 isl_pw_qpolynomial_fold_free(pwf
);
3884 isl_pw_qpolynomial_fold_free(pwf2
);
3889 isl_die(ctx
, isl_error_unknown
,
3890 "expecting infinite polynomial bound", return -1);
3895 static int test_bound(isl_ctx
*ctx
)
3899 isl_pw_qpolynomial
*pwqp
;
3900 isl_pw_qpolynomial_fold
*pwf
;
3902 if (test_bound_unbounded_domain(ctx
) < 0)
3905 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
3906 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3907 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3908 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3909 isl_pw_qpolynomial_fold_free(pwf
);
3913 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3916 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3917 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3918 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3919 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3920 isl_pw_qpolynomial_fold_free(pwf
);
3924 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3930 /* isl_set is defined to isl_map internally, so the corresponding elements
3931 * are isl_basic_map objects.
3935 #define EL_BASE basic_map
3936 #define SET_BASE set
3937 #include "isl_test_list_templ.c"
3941 #define EL_BASE basic_set
3942 #define SET_BASE union_set
3943 #include "isl_test_list_templ.c"
3948 #define SET_BASE union_set
3949 #include "isl_test_list_templ.c"
3953 #define EL_BASE basic_map
3954 #define SET_BASE map
3955 #include "isl_test_list_templ.c"
3960 #define SET_BASE union_map
3961 #include "isl_test_list_templ.c"
3963 /* Check that the conversion from isl objects to lists works as expected.
3965 static int test_get_list(isl_ctx
*ctx
)
3967 if (test_get_list_basic_map_from_set(ctx
, "{ [0]; [2]; [3] }"))
3969 if (test_get_list_basic_set_from_union_set(ctx
, "{ A[0]; B[2]; B[3] }"))
3971 if (test_get_list_set_from_union_set(ctx
, "{ A[0]; A[2]; B[3] }"))
3973 if (test_get_list_basic_map_from_map(ctx
,
3974 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"))
3976 if (test_get_list_map_from_union_map(ctx
,
3977 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"))
3983 static int test_lift(isl_ctx
*ctx
)
3986 isl_basic_map
*bmap
;
3987 isl_basic_set
*bset
;
3989 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
3990 bset
= isl_basic_set_read_from_str(ctx
, str
);
3991 bset
= isl_basic_set_lift(bset
);
3992 bmap
= isl_basic_map_from_range(bset
);
3993 bset
= isl_basic_map_domain(bmap
);
3994 isl_basic_set_free(bset
);
3999 /* Check that isl_set_is_subset is not confused by identical
4000 * integer divisions.
4001 * The call to isl_set_normalize ensures that the equality constraints
4002 * a = b = 0 are discovered, turning e0 and e1 into identical
4003 * integer divisions. Any further simplification would remove
4004 * the duplicate integer divisions.
4006 static isl_stat
test_subset_duplicate_integer_divisions(isl_ctx
*ctx
)
4010 isl_set
*set1
, *set2
;
4012 str
= "{ [a, b, c, d] : "
4013 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
4014 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
4015 "e3 = floor((-d + 4*floor((d)/4))/10): "
4016 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
4017 "b >= 0 and a <= 0 and b <= a) }";
4018 set1
= isl_set_read_from_str(ctx
, str
);
4019 set2
= isl_set_read_from_str(ctx
, str
);
4020 set2
= isl_set_normalize(set2
);
4022 is_subset
= isl_set_is_subset(set1
, set2
);
4028 return isl_stat_error
;
4030 isl_die(ctx
, isl_error_unknown
,
4031 "set is not considered to be a subset of itself",
4032 return isl_stat_error
);
4041 } subset_tests
[] = {
4043 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
4044 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
4045 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
4047 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
4048 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
4049 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
4050 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
4051 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
4052 "256e0 <= 255i and 256e0 >= -255 + 255i and "
4053 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
4054 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
4055 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
4056 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
4057 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
4058 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
4059 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
4060 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
4061 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
4062 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
4063 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
4064 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
4065 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
4066 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
4067 "4e0 <= -57 + i0 + i1)) or "
4068 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
4069 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
4070 "4e0 >= -61 + i0 + i1)) or "
4071 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
4072 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
4075 static int test_subset(isl_ctx
*ctx
)
4078 isl_set
*set1
, *set2
;
4081 if (test_subset_duplicate_integer_divisions(ctx
) < 0)
4084 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
4085 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
4086 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
4087 subset
= isl_set_is_subset(set1
, set2
);
4092 if (subset
!= subset_tests
[i
].subset
)
4093 isl_die(ctx
, isl_error_unknown
,
4094 "incorrect subset result", return -1);
4100 /* Perform a set subtraction with a set that has a non-obviously empty disjunct.
4101 * Older versions of isl would fail on such cases.
4103 static isl_stat
test_subtract_empty(isl_ctx
*ctx
)
4108 s1
= isl_set_read_from_str(ctx
, "{ [0] }");
4109 str
= "{ [a] : (exists (e0, e1, e2: 1056e1 <= 32 + a - 33e0 and "
4110 "1089e1 >= a - 33e0 and 1089e1 <= 1 + a - 33e0 and "
4111 "33e2 >= -a + 33e0 + 1056e1 and "
4112 "33e2 < -2a + 66e0 + 2112e1)) or a = 0 }";
4113 s2
= isl_set_read_from_str(ctx
, str
);
4114 s1
= isl_set_subtract(s1
, s2
);
4117 return isl_stat_non_null(s1
);
4121 const char *minuend
;
4122 const char *subtrahend
;
4123 const char *difference
;
4124 } subtract_domain_tests
[] = {
4125 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
4126 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
4127 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
4130 static int test_subtract(isl_ctx
*ctx
)
4133 isl_union_map
*umap1
, *umap2
;
4134 isl_union_pw_multi_aff
*upma1
, *upma2
;
4135 isl_union_set
*uset
;
4138 if (test_subtract_empty(ctx
) < 0)
4141 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4142 umap1
= isl_union_map_read_from_str(ctx
,
4143 subtract_domain_tests
[i
].minuend
);
4144 uset
= isl_union_set_read_from_str(ctx
,
4145 subtract_domain_tests
[i
].subtrahend
);
4146 umap2
= isl_union_map_read_from_str(ctx
,
4147 subtract_domain_tests
[i
].difference
);
4148 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
4149 equal
= isl_union_map_is_equal(umap1
, umap2
);
4150 isl_union_map_free(umap1
);
4151 isl_union_map_free(umap2
);
4155 isl_die(ctx
, isl_error_unknown
,
4156 "incorrect subtract domain result", return -1);
4159 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4160 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4161 subtract_domain_tests
[i
].minuend
);
4162 uset
= isl_union_set_read_from_str(ctx
,
4163 subtract_domain_tests
[i
].subtrahend
);
4164 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4165 subtract_domain_tests
[i
].difference
);
4166 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
4167 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
4168 isl_union_pw_multi_aff_free(upma1
);
4169 isl_union_pw_multi_aff_free(upma2
);
4173 isl_die(ctx
, isl_error_unknown
,
4174 "incorrect subtract domain result", return -1);
4180 /* Check that intersecting the empty basic set with another basic set
4181 * does not increase the number of constraints. In particular,
4182 * the empty basic set should maintain its canonical representation.
4184 static int test_intersect_1(isl_ctx
*ctx
)
4187 isl_basic_set
*bset1
, *bset2
;
4189 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
4190 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
4191 n1
= isl_basic_set_n_constraint(bset1
);
4192 bset1
= isl_basic_set_intersect(bset1
, bset2
);
4193 n2
= isl_basic_set_n_constraint(bset1
);
4194 isl_basic_set_free(bset1
);
4195 if (n1
< 0 || n2
< 0)
4198 isl_die(ctx
, isl_error_unknown
,
4199 "number of constraints of empty set changed",
4205 /* Check that intersecting a set with itself does not cause
4206 * an explosion in the number of disjuncts.
4208 static isl_stat
test_intersect_2(isl_ctx
*ctx
)
4213 set
= isl_set_read_from_str(ctx
, "{ [x,y] : x >= 0 or y >= 0 }");
4214 for (i
= 0; i
< 100; ++i
)
4215 set
= isl_set_intersect(set
, isl_set_copy(set
));
4218 return isl_stat_error
;
4222 /* Perform some intersection tests.
4224 static int test_intersect(isl_ctx
*ctx
)
4226 if (test_intersect_1(ctx
) < 0)
4228 if (test_intersect_2(ctx
) < 0)
4234 int test_factorize(isl_ctx
*ctx
)
4237 isl_basic_set
*bset
;
4240 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
4241 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
4242 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
4243 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
4244 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
4245 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
4246 "3i5 >= -2i0 - i2 + 3i4 }";
4247 bset
= isl_basic_set_read_from_str(ctx
, str
);
4248 f
= isl_basic_set_factorizer(bset
);
4249 isl_basic_set_free(bset
);
4250 isl_factorizer_free(f
);
4252 isl_die(ctx
, isl_error_unknown
,
4253 "failed to construct factorizer", return -1);
4255 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
4256 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
4257 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
4258 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
4259 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
4260 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
4261 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
4262 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
4263 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
4264 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
4265 bset
= isl_basic_set_read_from_str(ctx
, str
);
4266 f
= isl_basic_set_factorizer(bset
);
4267 isl_basic_set_free(bset
);
4268 isl_factorizer_free(f
);
4270 isl_die(ctx
, isl_error_unknown
,
4271 "failed to construct factorizer", return -1);
4276 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
4278 int *injective
= user
;
4280 *injective
= isl_map_is_injective(map
);
4283 if (*injective
< 0 || !*injective
)
4284 return isl_stat_error
;
4289 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
4290 const char *r
, const char *s
, int tilable
, int parallel
)
4294 isl_union_map
*W
, *R
, *S
;
4295 isl_union_map
*empty
;
4296 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
4297 isl_union_map
*validity
, *proximity
, *coincidence
;
4298 isl_union_map
*schedule
;
4299 isl_union_map
*test
;
4300 isl_union_set
*delta
;
4301 isl_union_set
*domain
;
4305 isl_schedule_constraints
*sc
;
4306 isl_schedule
*sched
;
4307 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
4310 D
= isl_union_set_read_from_str(ctx
, d
);
4311 W
= isl_union_map_read_from_str(ctx
, w
);
4312 R
= isl_union_map_read_from_str(ctx
, r
);
4313 S
= isl_union_map_read_from_str(ctx
, s
);
4315 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
4316 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
4318 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
4319 isl_union_map_compute_flow(isl_union_map_copy(R
),
4320 isl_union_map_copy(W
), empty
,
4321 isl_union_map_copy(S
),
4322 &dep_raw
, NULL
, NULL
, NULL
);
4323 isl_union_map_compute_flow(isl_union_map_copy(W
),
4324 isl_union_map_copy(W
),
4325 isl_union_map_copy(R
),
4326 isl_union_map_copy(S
),
4327 &dep_waw
, &dep_war
, NULL
, NULL
);
4329 dep
= isl_union_map_union(dep_waw
, dep_war
);
4330 dep
= isl_union_map_union(dep
, dep_raw
);
4331 validity
= isl_union_map_copy(dep
);
4332 coincidence
= isl_union_map_copy(dep
);
4333 proximity
= isl_union_map_copy(dep
);
4335 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
4336 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4337 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
4338 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4339 sched
= isl_schedule_constraints_compute_schedule(sc
);
4340 schedule
= isl_schedule_get_map(sched
);
4341 isl_schedule_free(sched
);
4342 isl_union_map_free(W
);
4343 isl_union_map_free(R
);
4344 isl_union_map_free(S
);
4347 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
4349 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
4350 is_complete
= isl_union_set_is_subset(D
, domain
);
4351 isl_union_set_free(D
);
4352 isl_union_set_free(domain
);
4354 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
4355 test
= isl_union_map_apply_range(test
, dep
);
4356 test
= isl_union_map_apply_range(test
, schedule
);
4358 delta
= isl_union_map_deltas(test
);
4359 n
= isl_union_set_n_set(delta
);
4361 isl_union_set_free(delta
);
4368 isl_union_set_free(delta
);
4372 delta_set
= isl_set_from_union_set(delta
);
4374 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4375 for (i
= 0; i
< tilable
; ++i
)
4376 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
4377 is_tilable
= isl_set_is_subset(delta_set
, slice
);
4378 isl_set_free(slice
);
4380 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4381 for (i
= 0; i
< parallel
; ++i
)
4382 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
4383 is_parallel
= isl_set_is_subset(delta_set
, slice
);
4384 isl_set_free(slice
);
4386 origin
= isl_set_universe(isl_set_get_space(delta_set
));
4387 dim
= isl_set_dim(origin
, isl_dim_set
);
4389 origin
= isl_set_free(origin
);
4390 for (i
= 0; i
< dim
; ++i
)
4391 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
4393 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
4394 delta_set
= isl_set_lexmin(delta_set
);
4396 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
4398 isl_set_free(origin
);
4399 isl_set_free(delta_set
);
4402 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
4403 is_injection
< 0 || is_complete
< 0)
4406 isl_die(ctx
, isl_error_unknown
,
4407 "generated schedule incomplete", return -1);
4409 isl_die(ctx
, isl_error_unknown
,
4410 "generated schedule not injective on each statement",
4413 isl_die(ctx
, isl_error_unknown
,
4414 "negative dependences in generated schedule",
4417 isl_die(ctx
, isl_error_unknown
,
4418 "generated schedule not as tilable as expected",
4421 isl_die(ctx
, isl_error_unknown
,
4422 "generated schedule not as parallel as expected",
4428 /* Compute a schedule for the given instance set, validity constraints,
4429 * proximity constraints and context and return a corresponding union map
4432 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
4433 const char *domain
, const char *validity
, const char *proximity
,
4434 const char *context
)
4439 isl_union_map
*prox
;
4440 isl_schedule_constraints
*sc
;
4441 isl_schedule
*schedule
;
4442 isl_union_map
*sched
;
4444 con
= isl_set_read_from_str(ctx
, context
);
4445 dom
= isl_union_set_read_from_str(ctx
, domain
);
4446 dep
= isl_union_map_read_from_str(ctx
, validity
);
4447 prox
= isl_union_map_read_from_str(ctx
, proximity
);
4448 sc
= isl_schedule_constraints_on_domain(dom
);
4449 sc
= isl_schedule_constraints_set_context(sc
, con
);
4450 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
4451 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
4452 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4453 sched
= isl_schedule_get_map(schedule
);
4454 isl_schedule_free(schedule
);
4459 /* Compute a schedule for the given instance set, validity constraints and
4460 * proximity constraints and return a corresponding union map representation.
4462 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
4463 const char *domain
, const char *validity
, const char *proximity
)
4465 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
4469 /* Check that a schedule can be constructed on the given domain
4470 * with the given validity and proximity constraints.
4472 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
4473 const char *validity
, const char *proximity
)
4475 isl_union_map
*sched
;
4477 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
4481 isl_union_map_free(sched
);
4485 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
4486 const char *validity
, const char *proximity
, const char *expected_sched
)
4488 isl_union_map
*sched1
, *sched2
;
4491 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
4492 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
4494 equal
= isl_union_map_is_equal(sched1
, sched2
);
4495 isl_union_map_free(sched1
);
4496 isl_union_map_free(sched2
);
4501 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
4507 /* Check that the schedule map is properly padded, i.e., that the range
4508 * lives in a single space.
4510 static int test_padded_schedule(isl_ctx
*ctx
)
4514 isl_union_map
*validity
, *proximity
;
4515 isl_schedule_constraints
*sc
;
4516 isl_schedule
*sched
;
4517 isl_union_map
*umap
;
4518 isl_union_set
*range
;
4521 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4522 D
= isl_union_set_read_from_str(ctx
, str
);
4523 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
4524 proximity
= isl_union_map_copy(validity
);
4525 sc
= isl_schedule_constraints_on_domain(D
);
4526 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4527 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4528 sched
= isl_schedule_constraints_compute_schedule(sc
);
4529 umap
= isl_schedule_get_map(sched
);
4530 isl_schedule_free(sched
);
4531 range
= isl_union_map_range(umap
);
4532 set
= isl_set_from_union_set(range
);
4541 /* Check that conditional validity constraints are also taken into
4542 * account across bands.
4543 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4544 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4545 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4546 * is enforced by the rest of the schedule.
4548 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
4551 isl_union_set
*domain
;
4552 isl_union_map
*validity
, *proximity
, *condition
;
4553 isl_union_map
*sink
, *source
, *dep
;
4554 isl_schedule_constraints
*sc
;
4555 isl_schedule
*schedule
;
4556 isl_union_access_info
*access
;
4557 isl_union_flow
*flow
;
4560 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4561 "A[k] : k >= 1 and k <= -1 + n; "
4562 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4563 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4564 domain
= isl_union_set_read_from_str(ctx
, str
);
4565 sc
= isl_schedule_constraints_on_domain(domain
);
4566 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4567 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4568 "D[k, i] -> C[1 + k, i] : "
4569 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4570 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4571 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4572 validity
= isl_union_map_read_from_str(ctx
, str
);
4573 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4574 str
= "[n] -> { C[k, i] -> D[k, i] : "
4575 "0 <= i <= -1 + k and k <= -1 + n }";
4576 proximity
= isl_union_map_read_from_str(ctx
, str
);
4577 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4578 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4579 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4580 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4581 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4582 condition
= isl_union_map_read_from_str(ctx
, str
);
4583 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4584 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4585 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4586 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4587 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4588 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4589 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4590 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4591 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4592 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4593 validity
= isl_union_map_read_from_str(ctx
, str
);
4594 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4596 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4597 str
= "{ D[2,0] -> [] }";
4598 sink
= isl_union_map_read_from_str(ctx
, str
);
4599 access
= isl_union_access_info_from_sink(sink
);
4600 str
= "{ C[2,1] -> [] }";
4601 source
= isl_union_map_read_from_str(ctx
, str
);
4602 access
= isl_union_access_info_set_must_source(access
, source
);
4603 access
= isl_union_access_info_set_schedule(access
, schedule
);
4604 flow
= isl_union_access_info_compute_flow(access
);
4605 dep
= isl_union_flow_get_must_dependence(flow
);
4606 isl_union_flow_free(flow
);
4607 empty
= isl_union_map_is_empty(dep
);
4608 isl_union_map_free(dep
);
4613 isl_die(ctx
, isl_error_unknown
,
4614 "conditional validity not respected", return -1);
4619 /* Check that the test for violated conditional validity constraints
4620 * is not confused by domain compression.
4621 * In particular, earlier versions of isl would apply
4622 * a schedule on the compressed domains to the original domains,
4623 * resulting in a failure to detect that the default schedule
4624 * violates the conditional validity constraints.
4626 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
4630 isl_union_set
*domain
;
4631 isl_union_map
*validity
, *condition
;
4632 isl_schedule_constraints
*sc
;
4633 isl_schedule
*schedule
;
4634 isl_union_map
*umap
;
4637 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4638 domain
= isl_union_set_read_from_str(ctx
, str
);
4639 sc
= isl_schedule_constraints_on_domain(domain
);
4640 str
= "{ B[1, i] -> A[0, i + 1] }";
4641 condition
= isl_union_map_read_from_str(ctx
, str
);
4642 str
= "{ A[0, i] -> B[1, i - 1] }";
4643 validity
= isl_union_map_read_from_str(ctx
, str
);
4644 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4645 isl_union_map_copy(validity
));
4646 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4647 umap
= isl_schedule_get_map(schedule
);
4648 isl_schedule_free(schedule
);
4649 validity
= isl_union_map_apply_domain(validity
,
4650 isl_union_map_copy(umap
));
4651 validity
= isl_union_map_apply_range(validity
, umap
);
4652 map
= isl_map_from_union_map(validity
);
4653 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4654 map
= isl_map_intersect(map
, ge
);
4655 empty
= isl_map_is_empty(map
);
4661 isl_die(ctx
, isl_error_unknown
,
4662 "conditional validity constraints not satisfied",
4668 /* Input for testing of schedule construction based on
4669 * conditional constraints.
4671 * domain is the iteration domain
4672 * flow are the flow dependences, which determine the validity and
4673 * proximity constraints
4674 * condition are the conditions on the conditional validity constraints
4675 * conditional_validity are the conditional validity constraints
4676 * outer_band_n is the expected number of members in the outer band
4681 const char *condition
;
4682 const char *conditional_validity
;
4684 } live_range_tests
[] = {
4685 /* Contrived example that illustrates that we need to keep
4686 * track of tagged condition dependences and
4687 * tagged conditional validity dependences
4688 * in isl_sched_edge separately.
4689 * In particular, the conditional validity constraints on A
4690 * cannot be satisfied,
4691 * but they can be ignored because there are no corresponding
4692 * condition constraints. However, we do have an additional
4693 * conditional validity constraint that maps to the same
4694 * dependence relation
4695 * as the condition constraint on B. If we did not make a distinction
4696 * between tagged condition and tagged conditional validity
4697 * dependences, then we
4698 * could end up treating this shared dependence as an condition
4699 * constraint on A, forcing a localization of the conditions,
4700 * which is impossible.
4702 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4703 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4704 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4705 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4706 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4707 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4710 /* TACO 2013 Fig. 7 */
4711 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4712 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4713 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4714 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4715 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4716 "0 <= i < n and 0 <= j < n - 1 }",
4717 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4718 "0 <= i < n and 0 <= j < j' < n;"
4719 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4720 "0 <= i < i' < n and 0 <= j,j' < n;"
4721 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4722 "0 <= i,j,j' < n and j < j' }",
4725 /* TACO 2013 Fig. 7, without tags */
4726 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4727 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4728 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4729 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4730 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4731 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4732 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4733 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4736 /* TACO 2013 Fig. 12 */
4737 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4738 "S3[i,3] : 0 <= i <= 1 }",
4739 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4740 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4741 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4742 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4743 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4744 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4745 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4746 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4747 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4748 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4749 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4754 /* Test schedule construction based on conditional constraints.
4755 * In particular, check the number of members in the outer band node
4756 * as an indication of whether tiling is possible or not.
4758 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4761 isl_union_set
*domain
;
4762 isl_union_map
*condition
;
4763 isl_union_map
*flow
;
4764 isl_union_map
*validity
;
4765 isl_schedule_constraints
*sc
;
4766 isl_schedule
*schedule
;
4767 isl_schedule_node
*node
;
4770 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4772 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4775 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4776 domain
= isl_union_set_read_from_str(ctx
,
4777 live_range_tests
[i
].domain
);
4778 flow
= isl_union_map_read_from_str(ctx
,
4779 live_range_tests
[i
].flow
);
4780 condition
= isl_union_map_read_from_str(ctx
,
4781 live_range_tests
[i
].condition
);
4782 validity
= isl_union_map_read_from_str(ctx
,
4783 live_range_tests
[i
].conditional_validity
);
4784 sc
= isl_schedule_constraints_on_domain(domain
);
4785 sc
= isl_schedule_constraints_set_validity(sc
,
4786 isl_union_map_copy(flow
));
4787 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4788 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4789 condition
, validity
);
4790 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4791 node
= isl_schedule_get_root(schedule
);
4793 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4794 node
= isl_schedule_node_first_child(node
);
4795 n_member
= isl_schedule_node_band_n_member(node
);
4796 isl_schedule_node_free(node
);
4797 isl_schedule_free(schedule
);
4799 if (!schedule
|| n_member
< 0)
4801 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4802 isl_die(ctx
, isl_error_unknown
,
4803 "unexpected number of members in outer band",
4809 /* Check that the schedule computed for the given instance set and
4810 * dependence relation strongly satisfies the dependences.
4811 * In particular, check that no instance is scheduled before
4812 * or together with an instance on which it depends.
4813 * Earlier versions of isl would produce a schedule that
4814 * only weakly satisfies the dependences.
4816 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4818 const char *domain
, *dep
;
4819 isl_union_map
*D
, *schedule
;
4823 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4824 "A[i0] : 0 <= i0 <= 1 }";
4825 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4826 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4827 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
4828 D
= isl_union_map_read_from_str(ctx
, dep
);
4829 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
4830 D
= isl_union_map_apply_range(D
, schedule
);
4831 map
= isl_map_from_union_map(D
);
4832 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4833 map
= isl_map_intersect(map
, ge
);
4834 empty
= isl_map_is_empty(map
);
4840 isl_die(ctx
, isl_error_unknown
,
4841 "dependences not strongly satisfied", return -1);
4846 /* Compute a schedule for input where the instance set constraints
4847 * conflict with the context constraints.
4848 * Earlier versions of isl did not properly handle this situation.
4850 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
4852 isl_union_map
*schedule
;
4853 const char *domain
, *context
;
4855 domain
= "[n] -> { A[] : n >= 0 }";
4856 context
= "[n] -> { : n < 0 }";
4857 schedule
= compute_schedule_with_context(ctx
,
4858 domain
, "{}", "{}", context
);
4859 isl_union_map_free(schedule
);
4867 /* Check that a set of schedule constraints that only allow for
4868 * a coalescing schedule still produces a schedule even if the user
4869 * request a non-coalescing schedule. Earlier versions of isl
4870 * would not handle this case correctly.
4872 static int test_coalescing_schedule(isl_ctx
*ctx
)
4874 const char *domain
, *dep
;
4877 isl_schedule_constraints
*sc
;
4878 isl_schedule
*schedule
;
4879 int treat_coalescing
;
4881 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4882 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
4883 I
= isl_union_set_read_from_str(ctx
, domain
);
4884 D
= isl_union_map_read_from_str(ctx
, dep
);
4885 sc
= isl_schedule_constraints_on_domain(I
);
4886 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4887 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4888 isl_options_set_schedule_treat_coalescing(ctx
, 1);
4889 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4890 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4891 isl_schedule_free(schedule
);
4897 /* Check that the scheduler does not perform any needless
4898 * compound skewing. Earlier versions of isl would compute
4899 * schedules in terms of transformed schedule coefficients and
4900 * would not accurately keep track of the sum of the original
4901 * schedule coefficients. It could then produce the schedule
4902 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4903 * for the input below instead of the schedule below.
4905 static int test_skewing_schedule(isl_ctx
*ctx
)
4907 const char *D
, *V
, *P
, *S
;
4909 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4910 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4911 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4912 "-1 <= a-i + b-j + c-k <= 1 }";
4914 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4916 return test_special_schedule(ctx
, D
, V
, P
, S
);
4919 int test_schedule(isl_ctx
*ctx
)
4921 const char *D
, *W
, *R
, *V
, *P
, *S
;
4922 int max_coincidence
;
4923 int treat_coalescing
;
4925 /* Handle resulting schedule with zero bands. */
4926 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4930 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4931 W
= "{ S1[t,i] -> a[t,i] }";
4932 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4933 "S1[t,i] -> a[t-1,i+1] }";
4934 S
= "{ S1[t,i] -> [t,i] }";
4935 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4938 /* Fig. 5 of CC2008 */
4939 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4941 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4942 "j >= 2 and j <= -1 + N }";
4943 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4944 "j >= 2 and j <= -1 + N; "
4945 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4946 "j >= 2 and j <= -1 + N }";
4947 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4948 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4951 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4952 W
= "{ S1[i] -> a[i] }";
4953 R
= "{ S2[i] -> a[i+1] }";
4954 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4955 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4958 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4959 W
= "{ S1[i] -> a[i] }";
4960 R
= "{ S2[i] -> a[9-i] }";
4961 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4962 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4965 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4966 W
= "{ S1[i] -> a[i] }";
4967 R
= "[N] -> { S2[i] -> a[N-1-i] }";
4968 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4969 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4972 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4973 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4974 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4975 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4976 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4979 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4980 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4981 R
= "{ S2[i,j] -> a[i-1,j] }";
4982 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4983 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4986 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4987 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4988 R
= "{ S2[i,j] -> a[i,j-1] }";
4989 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4990 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4993 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4994 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4995 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4996 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4997 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4998 "S_0[] -> [0, 0, 0] }";
4999 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
5001 ctx
->opt
->schedule_parametric
= 0;
5002 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5004 ctx
->opt
->schedule_parametric
= 1;
5006 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
5007 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
5008 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
5009 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
5010 "S4[i] -> a[i,N] }";
5011 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
5012 "S4[i] -> [4,i,0] }";
5013 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
5014 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
5015 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5017 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
5019 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
5020 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5022 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5024 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
5026 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
5027 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5030 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
5031 " S_2[t] : t >= 0 and t <= -1 + N; "
5032 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
5034 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
5035 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
5036 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
5037 "i >= 0 and i <= -1 + N }";
5038 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
5039 "i >= 0 and i <= -1 + N; "
5040 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
5041 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
5042 " S_0[t] -> [0, t, 0] }";
5044 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5046 ctx
->opt
->schedule_parametric
= 0;
5047 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5049 ctx
->opt
->schedule_parametric
= 1;
5051 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
5052 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
5053 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
5056 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
5057 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
5058 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
5059 "j >= 0 and j <= -1 + N; "
5060 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5061 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
5062 "j >= 0 and j <= -1 + N; "
5063 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5064 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
5065 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5068 D
= "{ S_0[i] : i >= 0 }";
5069 W
= "{ S_0[i] -> a[i] : i >= 0 }";
5070 R
= "{ S_0[i] -> a[0] : i >= 0 }";
5071 S
= "{ S_0[i] -> [0, i, 0] }";
5072 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5075 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
5076 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
5077 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
5078 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
5079 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5082 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
5083 "k <= -1 + n and k >= 0 }";
5084 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
5085 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
5086 "k <= -1 + n and k >= 0; "
5087 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
5088 "k <= -1 + n and k >= 0; "
5089 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
5090 "k <= -1 + n and k >= 0 }";
5091 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
5092 ctx
->opt
->schedule_outer_coincidence
= 1;
5093 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5095 ctx
->opt
->schedule_outer_coincidence
= 0;
5097 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
5098 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
5099 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
5100 "Stmt_for_body24[i0, i1, 1, 0]:"
5101 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
5102 "Stmt_for_body7[i0, i1, i2]:"
5103 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
5106 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
5107 "Stmt_for_body24[1, i1, i2, i3]:"
5108 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
5110 "Stmt_for_body24[0, i1, i2, i3] -> "
5111 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
5112 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
5114 "Stmt_for_body24[0, i1, i2, i3] ->"
5115 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
5116 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
5117 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
5118 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
5119 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
5120 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
5121 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
5122 "i1 <= 6 and i1 >= 0;"
5123 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
5124 "Stmt_for_body7[i0, i1, i2] -> "
5125 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
5126 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
5127 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
5128 "Stmt_for_body7[i0, i1, i2] -> "
5129 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
5130 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
5131 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
5134 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
5135 isl_options_set_schedule_treat_coalescing(ctx
, 0);
5136 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5138 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
5140 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
5141 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
5142 "j >= 1 and j <= 7;"
5143 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
5144 "j >= 1 and j <= 8 }";
5146 S
= "{ S_0[i, j] -> [i + j, i] }";
5147 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5148 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5150 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5152 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
5153 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
5154 "j >= 0 and j <= -1 + i }";
5155 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
5156 "i <= -1 + N and j >= 0;"
5157 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
5160 S
= "{ S_0[i, j] -> [i, j] }";
5161 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5162 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5164 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5166 /* Test both algorithms on a case with only proximity dependences. */
5167 D
= "{ S[i,j] : 0 <= i <= 10 }";
5169 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
5170 S
= "{ S[i, j] -> [j, i] }";
5171 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5172 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5174 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5175 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5178 D
= "{ A[a]; B[] }";
5180 P
= "{ A[a] -> B[] }";
5181 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5184 if (test_padded_schedule(ctx
) < 0)
5187 /* Check that check for progress is not confused by rational
5190 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
5191 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
5193 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
5194 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
5196 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5197 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5199 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5201 /* Check that we allow schedule rows that are only non-trivial
5202 * on some full-dimensional domains.
5204 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
5205 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
5206 "S1[j] -> S2[1] : 0 <= j <= 1 }";
5208 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5209 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5211 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5213 if (test_conditional_schedule_constraints(ctx
) < 0)
5216 if (test_strongly_satisfying_schedule(ctx
) < 0)
5219 if (test_conflicting_context_schedule(ctx
) < 0)
5222 if (test_coalescing_schedule(ctx
) < 0)
5224 if (test_skewing_schedule(ctx
) < 0)
5230 /* Perform scheduling tests using the whole component scheduler.
5232 static int test_schedule_whole(isl_ctx
*ctx
)
5237 whole
= isl_options_get_schedule_whole_component(ctx
);
5238 isl_options_set_schedule_whole_component(ctx
, 1);
5239 r
= test_schedule(ctx
);
5240 isl_options_set_schedule_whole_component(ctx
, whole
);
5245 /* Perform scheduling tests using the incremental scheduler.
5247 static int test_schedule_incremental(isl_ctx
*ctx
)
5252 whole
= isl_options_get_schedule_whole_component(ctx
);
5253 isl_options_set_schedule_whole_component(ctx
, 0);
5254 r
= test_schedule(ctx
);
5255 isl_options_set_schedule_whole_component(ctx
, whole
);
5260 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
5262 isl_union_map
*umap
;
5265 umap
= isl_union_map_read_from_str(ctx
, str
);
5266 test
= isl_union_map_plain_is_injective(umap
);
5267 isl_union_map_free(umap
);
5270 if (test
== injective
)
5273 isl_die(ctx
, isl_error_unknown
,
5274 "map not detected as injective", return -1);
5276 isl_die(ctx
, isl_error_unknown
,
5277 "map detected as injective", return -1);
5280 int test_injective(isl_ctx
*ctx
)
5284 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
5286 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
5288 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
5290 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
5292 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
5294 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
5296 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
5298 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
5301 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
5302 if (test_plain_injective(ctx
, str
, 1))
5304 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
5305 if (test_plain_injective(ctx
, str
, 0))
5313 #include "isl_test_plain_equal_templ.c"
5316 #define BASE pw_multi_aff
5317 #include "isl_test_plain_equal_templ.c"
5320 #define BASE union_pw_aff
5321 #include "isl_test_plain_equal_templ.c"
5323 /* Basic tests on isl_union_pw_aff.
5325 * In particular, check that isl_union_pw_aff_aff_on_domain
5326 * aligns the parameters of the input objects and
5327 * that isl_union_pw_aff_param_on_domain_id properly
5328 * introduces the parameter.
5330 static int test_upa(isl_ctx
*ctx
)
5335 isl_union_set
*domain
;
5336 isl_union_pw_aff
*upa
;
5339 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
5340 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5341 domain
= isl_union_set_read_from_str(ctx
, str
);
5342 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
5343 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5344 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5345 isl_union_pw_aff_free(upa
);
5349 id
= isl_id_alloc(ctx
, "N", NULL
);
5350 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5351 domain
= isl_union_set_read_from_str(ctx
, str
);
5352 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
5353 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5354 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5355 isl_union_pw_aff_free(upa
);
5363 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5364 __isl_take isl_aff
*aff2
);
5366 ['+'] = { &isl_aff_add
},
5367 ['-'] = { &isl_aff_sub
},
5368 ['*'] = { &isl_aff_mul
},
5369 ['/'] = { &isl_aff_div
},
5377 } aff_bin_tests
[] = {
5378 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5379 "{ [i] -> [2i] }" },
5380 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5382 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5383 "{ [i] -> [2i] }" },
5384 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5385 "{ [i] -> [2i] }" },
5386 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5387 "{ [i] -> [i/2] }" },
5388 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5390 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5391 "{ [i] -> [NaN] }" },
5392 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5393 "{ [i] -> [NaN] }" },
5394 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5395 "{ [i] -> [NaN] }" },
5396 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5397 "{ [i] -> [NaN] }" },
5398 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5399 "{ [i] -> [NaN] }" },
5400 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5401 "{ [i] -> [NaN] }" },
5402 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5403 "{ [i] -> [NaN] }" },
5404 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5405 "{ [i] -> [NaN] }" },
5406 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5407 "{ [i] -> [NaN] }" },
5408 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5409 "{ [i] -> [NaN] }" },
5410 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5411 "{ [i] -> [NaN] }" },
5412 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5413 "{ [i] -> [NaN] }" },
5416 /* Perform some basic tests of binary operations on isl_aff objects.
5418 static int test_bin_aff(isl_ctx
*ctx
)
5421 isl_aff
*aff1
, *aff2
, *res
;
5422 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5423 __isl_take isl_aff
*aff2
);
5426 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
5427 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
5428 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
5429 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
5430 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
5431 aff1
= fn(aff1
, aff2
);
5432 if (isl_aff_is_nan(res
))
5433 ok
= isl_aff_is_nan(aff1
);
5435 ok
= isl_aff_plain_is_equal(aff1
, res
);
5441 isl_die(ctx
, isl_error_unknown
,
5442 "unexpected result", return -1);
5449 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
5450 __isl_take isl_pw_aff
*pa2
);
5451 } pw_aff_bin_op
[] = {
5452 ['m'] = { &isl_pw_aff_min
},
5453 ['M'] = { &isl_pw_aff_max
},
5456 /* Inputs for binary isl_pw_aff operation tests.
5457 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5458 * defined by pw_aff_bin_op, and "res" is the expected result.
5465 } pw_aff_bin_tests
[] = {
5466 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5468 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5470 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5471 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5472 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5473 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5474 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5475 "{ [i] -> [NaN] }" },
5476 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5477 "{ [i] -> [NaN] }" },
5480 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5482 static int test_bin_pw_aff(isl_ctx
*ctx
)
5486 isl_pw_aff
*pa1
, *pa2
, *res
;
5488 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
5489 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
5490 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
5491 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
5492 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
5493 if (isl_pw_aff_involves_nan(res
))
5494 ok
= isl_pw_aff_involves_nan(pa1
);
5496 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
5497 isl_pw_aff_free(pa1
);
5498 isl_pw_aff_free(res
);
5502 isl_die(ctx
, isl_error_unknown
,
5503 "unexpected result", return -1);
5509 /* Inputs for basic tests of test operations on
5510 * isl_union_pw_multi_aff objects.
5511 * "fn" is the function that is being tested.
5512 * "arg" is a string description of the input.
5513 * "res" is the expected result.
5516 isl_bool (*fn
)(__isl_keep isl_union_pw_multi_aff
*upma1
);
5519 } upma_test_tests
[] = {
5520 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [1] }",
5522 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [NaN]; B[0] -> [1] }",
5524 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [NaN] }",
5526 { &isl_union_pw_multi_aff_involves_nan
,
5527 "{ A[] -> [0]; B[0] -> [1, NaN, 5] }",
5529 { &isl_union_pw_multi_aff_involves_locals
,
5530 "{ A[] -> [0]; B[0] -> [1] }",
5532 { &isl_union_pw_multi_aff_involves_locals
,
5533 "{ A[] -> [0]; B[x] -> [1] : x mod 2 = 0 }",
5535 { &isl_union_pw_multi_aff_involves_locals
,
5536 "{ A[] -> [0]; B[x] -> [x // 2] }",
5538 { &isl_union_pw_multi_aff_involves_locals
,
5539 "{ A[i] -> [i // 2]; B[0] -> [1] }",
5543 /* Perform some basic tests of test operations on
5544 * isl_union_pw_multi_aff objects.
5546 static isl_stat
test_upma_test(isl_ctx
*ctx
)
5549 isl_union_pw_multi_aff
*upma
;
5552 for (i
= 0; i
< ARRAY_SIZE(upma_test_tests
); ++i
) {
5555 str
= upma_test_tests
[i
].arg
;
5556 upma
= isl_union_pw_multi_aff_read_from_str(ctx
, str
);
5557 res
= upma_test_tests
[i
].fn(upma
);
5558 isl_union_pw_multi_aff_free(upma
);
5560 return isl_stat_error
;
5561 if (res
!= upma_test_tests
[i
].res
)
5562 isl_die(ctx
, isl_error_unknown
,
5563 "unexpected result", return isl_stat_error
);
5570 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5571 __isl_take isl_union_pw_multi_aff
*upma1
,
5572 __isl_take isl_union_pw_multi_aff
*upma2
);
5576 } upma_bin_tests
[] = {
5577 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
5578 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5579 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
5580 "{ B[x] -> [2] : x >= 0 }",
5581 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5582 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
5583 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5584 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5585 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5586 "D[i] -> B[2] : i >= 5 }" },
5587 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5588 "{ B[x] -> C[2] : x > 0 }",
5589 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5590 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5591 "{ B[x] -> A[2] : x >= 0 }",
5592 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5595 /* Perform some basic tests of binary operations on
5596 * isl_union_pw_multi_aff objects.
5598 static int test_bin_upma(isl_ctx
*ctx
)
5601 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
5604 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
5605 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5606 upma_bin_tests
[i
].arg1
);
5607 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5608 upma_bin_tests
[i
].arg2
);
5609 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5610 upma_bin_tests
[i
].res
);
5611 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
5612 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
5613 isl_union_pw_multi_aff_free(upma1
);
5614 isl_union_pw_multi_aff_free(res
);
5618 isl_die(ctx
, isl_error_unknown
,
5619 "unexpected result", return -1);
5626 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5627 __isl_take isl_union_pw_multi_aff
*upma1
,
5628 __isl_take isl_union_pw_multi_aff
*upma2
);
5631 } upma_bin_fail_tests
[] = {
5632 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5633 "{ B[x] -> C[2] : x >= 0 }" },
5636 /* Perform some basic tests of binary operations on
5637 * isl_union_pw_multi_aff objects that are expected to fail.
5639 static int test_bin_upma_fail(isl_ctx
*ctx
)
5642 isl_union_pw_multi_aff
*upma1
, *upma2
;
5645 on_error
= isl_options_get_on_error(ctx
);
5646 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5647 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5648 for (i
= 0; i
< n
; ++i
) {
5649 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5650 upma_bin_fail_tests
[i
].arg1
);
5651 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5652 upma_bin_fail_tests
[i
].arg2
);
5653 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5654 isl_union_pw_multi_aff_free(upma1
);
5658 isl_options_set_on_error(ctx
, on_error
);
5660 isl_die(ctx
, isl_error_unknown
,
5661 "operation not expected to succeed", return -1);
5666 /* Inputs for basic tests of binary operations on
5667 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5668 * "fn" is the function that is being tested.
5669 * "arg1" and "arg2" are string descriptions of the inputs.
5670 * "res" is a string description of the expected result.
5673 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5674 __isl_take isl_union_pw_multi_aff
*upma
,
5675 __isl_take isl_union_set
*uset
);
5679 } upma_uset_tests
[] = {
5680 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5681 "{ A[i] -> B[i] }", "{ B[0] }",
5683 { &isl_union_pw_multi_aff_intersect_domain_wrapped_domain
,
5684 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5685 "{ [A[1] -> B[1]] -> C[2] }" },
5686 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5687 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5688 "{ [A[0] -> B[0]] -> C[1] }" },
5689 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5690 "{ [A[i] -> B[i]] -> C[i + 1] }", "[N] -> { B[N] }",
5691 "[N] -> { [A[N] -> B[N]] -> C[N + 1] }" },
5692 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5693 "[M] -> { [A[M] -> B[M]] -> C[M + 1] }", "[N] -> { B[N] }",
5694 "[N, M] -> { [A[N] -> B[N]] -> C[N + 1] : N = M }" },
5695 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5696 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[]; [B[] -> A[]] -> E[] }",
5698 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[] }" },
5701 /* Perform some basic tests of binary operations on
5702 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5704 static isl_stat
test_upma_uset(isl_ctx
*ctx
)
5708 isl_union_pw_multi_aff
*upma
, *res
;
5709 isl_union_set
*uset
;
5711 for (i
= 0; i
< ARRAY_SIZE(upma_uset_tests
); ++i
) {
5712 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
5713 upma_uset_tests
[i
].arg1
);
5714 uset
= isl_union_set_read_from_str(ctx
,
5715 upma_uset_tests
[i
].arg2
);
5716 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5717 upma_uset_tests
[i
].res
);
5718 upma
= upma_uset_tests
[i
].fn(upma
, uset
);
5719 ok
= isl_union_pw_multi_aff_plain_is_equal(upma
, res
);
5720 isl_union_pw_multi_aff_free(upma
);
5721 isl_union_pw_multi_aff_free(res
);
5723 return isl_stat_error
;
5725 isl_die(ctx
, isl_error_unknown
,
5726 "unexpected result", return isl_stat_error
);
5732 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5733 * "fn" is the function that is tested.
5734 * "arg" is a string description of the input.
5735 * "res" is a string description of the expected result.
5738 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5741 } mpa_un_tests
[] = {
5742 { &isl_multi_pw_aff_range_factor_domain
,
5743 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5744 "{ A[x] -> B[(1 : x >= 5)] }" },
5745 { &isl_multi_pw_aff_range_factor_range
,
5746 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5747 "{ A[y] -> C[(2 : y <= 10)] }" },
5748 { &isl_multi_pw_aff_range_factor_domain
,
5749 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5750 "{ A[x] -> B[(1 : x >= 5)] }" },
5751 { &isl_multi_pw_aff_range_factor_range
,
5752 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5753 "{ A[y] -> C[] }" },
5754 { &isl_multi_pw_aff_range_factor_domain
,
5755 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5756 "{ A[x] -> B[] }" },
5757 { &isl_multi_pw_aff_range_factor_range
,
5758 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5759 "{ A[y] -> C[(2 : y <= 10)] }" },
5760 { &isl_multi_pw_aff_range_factor_domain
,
5761 "{ A[x] -> [B[] -> C[]] }",
5762 "{ A[x] -> B[] }" },
5763 { &isl_multi_pw_aff_range_factor_range
,
5764 "{ A[x] -> [B[] -> C[]] }",
5765 "{ A[y] -> C[] }" },
5766 { &isl_multi_pw_aff_factor_range
,
5769 { &isl_multi_pw_aff_range_factor_domain
,
5770 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5771 "{ A[x] -> B[] : x >= 0 }" },
5772 { &isl_multi_pw_aff_range_factor_range
,
5773 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5774 "{ A[y] -> C[] : y >= 0 }" },
5775 { &isl_multi_pw_aff_factor_range
,
5776 "[N] -> { [B[] -> C[]] : N >= 0 }",
5777 "[N] -> { C[] : N >= 0 }" },
5780 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5782 static int test_un_mpa(isl_ctx
*ctx
)
5786 isl_multi_pw_aff
*mpa
, *res
;
5788 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5789 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5790 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5791 mpa
= mpa_un_tests
[i
].fn(mpa
);
5792 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5793 isl_multi_pw_aff_free(mpa
);
5794 isl_multi_pw_aff_free(res
);
5798 isl_die(ctx
, isl_error_unknown
,
5799 "unexpected result", return -1);
5805 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5806 * "fn" is the function that is tested.
5807 * "arg1" and "arg2" are string descriptions of the inputs.
5808 * "res" is a string description of the expected result.
5811 __isl_give isl_multi_pw_aff
*(*fn
)(
5812 __isl_take isl_multi_pw_aff
*mpa1
,
5813 __isl_take isl_multi_pw_aff
*mpa2
);
5817 } mpa_bin_tests
[] = {
5818 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
5820 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
5821 "{ A[x] -> [(x : x <= 10)] }",
5822 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5823 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5824 "{ A[x] -> [] : x <= 10 }",
5825 "{ A[x] -> [] : 5 <= x <= 10 }" },
5826 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5827 "[N] -> { A[x] -> [] : x <= N }",
5828 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5829 { &isl_multi_pw_aff_add
,
5830 "[N] -> { A[x] -> [] : x <= N }",
5831 "{ A[x] -> [] : x >= 5 }",
5832 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5833 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5834 "{ A[y] -> C[(2 : y <= 10)] }",
5835 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5836 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5837 "{ A[y] -> C[2] : y <= 10 }",
5838 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5839 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5840 "[N] -> { A[y] -> C[2] : y <= N }",
5841 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5842 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
5843 "{ A[y] -> C[2] : y <= 10 }",
5844 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5845 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5846 "{ A[] -> [B[1] -> C[2]] }" },
5847 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5848 "{ A[] -> [B[] -> C[]] }" },
5849 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5850 "{ A[y] -> C[] : y <= 10 }",
5851 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5852 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
5853 "{ A[x] -> B[(1 : x >= 5)] }",
5854 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5855 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5856 "{ A[y] -> C[(2 : y <= 10)] }",
5857 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5858 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5859 "{ A[y] -> C[] : y <= 10 }",
5860 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5861 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
5862 "{ A[x] -> B[(1 : x >= 5)] }",
5863 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5864 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5865 "[N] -> { A[y] -> C[] : y <= N }",
5866 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5867 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
5868 "{ A[x] -> B[(1 : x >= 5)] }",
5869 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5870 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
5871 "{ A[y] -> C[] : y <= 10 }",
5872 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5873 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5874 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5875 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5876 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5877 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5878 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5879 "{ A[a,b] -> C[b + 2a] }" },
5880 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5881 "{ B[i,j] -> C[i + 2j] }",
5882 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5883 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5884 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5885 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5886 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5887 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5888 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5889 "{ B[i,j] -> C[] }",
5890 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5891 "{ A[a,b] -> C[] }" },
5892 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5893 "{ B[i,j] -> C[] : i > j }",
5894 "{ A[a,b] -> B[b,a] }",
5895 "{ A[a,b] -> C[] : b > a }" },
5896 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5897 "{ B[i,j] -> C[] : j > 5 }",
5898 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5899 "{ A[a,b] -> C[] : b > a > 5 }" },
5900 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5901 "[N] -> { B[i,j] -> C[] : j > N }",
5902 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5903 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5904 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5905 "[M,N] -> { B[] -> C[] : N > 5 }",
5906 "[M,N] -> { A[] -> B[] : M > N }",
5907 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5910 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5912 static int test_bin_mpa(isl_ctx
*ctx
)
5916 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
5918 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
5919 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
5920 mpa_bin_tests
[i
].arg1
);
5921 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
5922 mpa_bin_tests
[i
].arg2
);
5923 res
= isl_multi_pw_aff_read_from_str(ctx
,
5924 mpa_bin_tests
[i
].res
);
5925 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
5926 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
5927 isl_multi_pw_aff_free(mpa1
);
5928 isl_multi_pw_aff_free(res
);
5932 isl_die(ctx
, isl_error_unknown
,
5933 "unexpected result", return -1);
5939 /* Inputs for basic tests of unary operations on
5940 * isl_multi_union_pw_aff objects.
5941 * "fn" is the function that is tested.
5942 * "arg" is a string description of the input.
5943 * "res" is a string description of the expected result.
5946 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5947 __isl_take isl_multi_union_pw_aff
*mupa
);
5950 } mupa_un_tests
[] = {
5951 { &isl_multi_union_pw_aff_factor_range
,
5952 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5953 "C[{ A[] -> [2] }]" },
5954 { &isl_multi_union_pw_aff_factor_range
,
5955 "[B[] -> C[{ A[] -> [2] }]]",
5956 "C[{ A[] -> [2] }]" },
5957 { &isl_multi_union_pw_aff_factor_range
,
5958 "[B[{ A[] -> [1] }] -> C[]]",
5960 { &isl_multi_union_pw_aff_factor_range
,
5963 { &isl_multi_union_pw_aff_factor_range
,
5964 "([B[] -> C[]] : { A[x] : x >= 0 })",
5965 "(C[] : { A[x] : x >= 0 })" },
5966 { &isl_multi_union_pw_aff_factor_range
,
5967 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
5968 "[N] -> (C[] : { A[x] : x <= N })" },
5969 { &isl_multi_union_pw_aff_factor_range
,
5970 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
5971 "[N] -> (C[] : { : N >= 0 })" },
5974 /* Perform some basic tests of unary operations on
5975 * isl_multi_union_pw_aff objects.
5977 static int test_un_mupa(isl_ctx
*ctx
)
5981 isl_multi_union_pw_aff
*mupa
, *res
;
5983 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
5984 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5985 mupa_un_tests
[i
].arg
);
5986 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5987 mupa_un_tests
[i
].res
);
5988 mupa
= mupa_un_tests
[i
].fn(mupa
);
5989 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5990 isl_multi_union_pw_aff_free(mupa
);
5991 isl_multi_union_pw_aff_free(res
);
5995 isl_die(ctx
, isl_error_unknown
,
5996 "unexpected result", return -1);
6002 /* Inputs for basic tests of binary operations on
6003 * isl_multi_union_pw_aff objects.
6004 * "fn" is the function that is tested.
6005 * "arg1" and "arg2" are string descriptions of the inputs.
6006 * "res" is a string description of the expected result.
6009 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6010 __isl_take isl_multi_union_pw_aff
*mupa1
,
6011 __isl_take isl_multi_union_pw_aff
*mupa2
);
6015 } mupa_bin_tests
[] = {
6016 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6017 "[{ A[] -> [3] }]" },
6018 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6019 "[{ A[] -> [-1] }]" },
6020 { &isl_multi_union_pw_aff_add
,
6021 "[{ A[] -> [1]; B[] -> [4] }]",
6022 "[{ A[] -> [2]; C[] -> [5] }]",
6023 "[{ A[] -> [3] }]" },
6024 { &isl_multi_union_pw_aff_union_add
,
6025 "[{ A[] -> [1]; B[] -> [4] }]",
6026 "[{ A[] -> [2]; C[] -> [5] }]",
6027 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
6028 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
6029 "[{ A[x] -> [(x)] : x <= 10 }]",
6030 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
6031 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
6032 "([] : { A[x] : x <= 10 })",
6033 "([] : { A[x] : 5 <= x <= 10 })" },
6034 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
6035 "[N] -> ([] : { A[x] : x <= N })",
6036 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
6037 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
6038 "([] : { A[x] : x <= 10 })",
6039 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
6040 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
6041 "[{ A[x] -> [(x)] : x <= 10 }]",
6042 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
6043 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
6044 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
6045 "([] : { A[x] : x <= 10 })",
6046 "([] : { A[x] })" },
6047 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
6048 "[N] -> ([] : { A[x] : x >= N })",
6049 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
6050 { &isl_multi_union_pw_aff_union_add
,
6051 "[N] -> ([] : { A[] : N >= 0})",
6052 "[N] -> ([] : { A[] : N <= 0})",
6053 "[N] -> ([] : { A[] })" },
6054 { &isl_multi_union_pw_aff_union_add
,
6055 "[N] -> ([] : { A[] })",
6056 "[N] -> ([] : { : })",
6057 "[N] -> ([] : { : })" },
6058 { &isl_multi_union_pw_aff_union_add
,
6059 "[N] -> ([] : { : })",
6060 "[N] -> ([] : { A[] })",
6061 "[N] -> ([] : { : })" },
6062 { &isl_multi_union_pw_aff_union_add
,
6063 "[N] -> ([] : { : N >= 0})",
6064 "[N] -> ([] : { : N <= 0})",
6065 "[N] -> ([] : { : })" },
6066 { &isl_multi_union_pw_aff_range_product
,
6067 "B[{ A[] -> [1] }]",
6068 "C[{ A[] -> [2] }]",
6069 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
6070 { &isl_multi_union_pw_aff_range_product
,
6071 "(B[] : { A[x] : x >= 5 })",
6072 "(C[] : { A[x] : x <= 10 })",
6073 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
6074 { &isl_multi_union_pw_aff_range_product
,
6075 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6076 "(C[] : { A[x] : x <= 10 })",
6077 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
6078 { &isl_multi_union_pw_aff_range_product
,
6079 "(C[] : { A[x] : x <= 10 })",
6080 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6081 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
6082 { &isl_multi_union_pw_aff_range_product
,
6083 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6084 "[N] -> (C[] : { A[x] : x <= N })",
6085 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
6086 { &isl_multi_union_pw_aff_range_product
,
6087 "[N] -> (C[] : { A[x] : x <= N })",
6088 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6089 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
6090 { &isl_multi_union_pw_aff_range_product
,
6091 "B[{ A[] -> [1]; D[] -> [3] }]",
6092 "C[{ A[] -> [2] }]",
6093 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
6094 { &isl_multi_union_pw_aff_range_product
,
6097 "([B[] -> C[]] : { A[x] })" },
6098 { &isl_multi_union_pw_aff_range_product
,
6101 "([B[] -> C[]] : { A[x] })" },
6104 /* Perform some basic tests of binary operations on
6105 * isl_multi_union_pw_aff objects.
6107 static int test_bin_mupa(isl_ctx
*ctx
)
6111 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
6113 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
6114 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
6115 mupa_bin_tests
[i
].arg1
);
6116 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
6117 mupa_bin_tests
[i
].arg2
);
6118 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6119 mupa_bin_tests
[i
].res
);
6120 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
6121 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
6122 isl_multi_union_pw_aff_free(mupa1
);
6123 isl_multi_union_pw_aff_free(res
);
6127 isl_die(ctx
, isl_error_unknown
,
6128 "unexpected result", return -1);
6134 /* Inputs for basic tests of binary operations on
6135 * pairs of isl_multi_union_pw_aff and isl_set objects.
6136 * "fn" is the function that is tested.
6137 * "arg1" and "arg2" are string descriptions of the inputs.
6138 * "res" is a string description of the expected result.
6141 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6142 __isl_take isl_multi_union_pw_aff
*mupa
,
6143 __isl_take isl_set
*set
);
6147 } mupa_set_tests
[] = {
6148 { &isl_multi_union_pw_aff_intersect_range
,
6149 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
6150 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
6151 { &isl_multi_union_pw_aff_intersect_range
,
6152 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
6153 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
6154 { &isl_multi_union_pw_aff_intersect_range
,
6155 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
6156 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
6157 { &isl_multi_union_pw_aff_intersect_range
,
6158 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
6159 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
6160 { &isl_multi_union_pw_aff_intersect_range
,
6161 "C[]", "{ C[] }", "C[]" },
6162 { &isl_multi_union_pw_aff_intersect_range
,
6163 "[N] -> (C[] : { : N >= 0 })",
6165 "[N] -> (C[] : { : N >= 0 })" },
6166 { &isl_multi_union_pw_aff_intersect_range
,
6167 "(C[] : { A[a,b] })",
6169 "(C[] : { A[a,b] })" },
6170 { &isl_multi_union_pw_aff_intersect_range
,
6171 "[N] -> (C[] : { A[a,b] : a,b <= N })",
6173 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
6174 { &isl_multi_union_pw_aff_intersect_range
,
6176 "[N] -> { C[] : N >= 0 }",
6177 "[N] -> (C[] : { : N >= 0 })" },
6178 { &isl_multi_union_pw_aff_intersect_range
,
6179 "(C[] : { A[a,b] })",
6180 "[N] -> { C[] : N >= 0 }",
6181 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6182 { &isl_multi_union_pw_aff_intersect_range
,
6183 "[N] -> (C[] : { : N >= 0 })",
6184 "[N] -> { C[] : N < 1024 }",
6185 "[N] -> (C[] : { : 0 <= N < 1024 })" },
6186 { &isl_multi_union_pw_aff_intersect_params
,
6187 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
6188 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
6189 { &isl_multi_union_pw_aff_intersect_params
,
6190 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
6191 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
6192 { &isl_multi_union_pw_aff_intersect_params
,
6193 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
6194 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
6195 { &isl_multi_union_pw_aff_intersect_params
,
6196 "C[]", "[N] -> { : N >= 0 }",
6197 "[N] -> (C[] : { : N >= 0 })" },
6198 { &isl_multi_union_pw_aff_intersect_params
,
6199 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
6200 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6201 { &isl_multi_union_pw_aff_intersect_params
,
6202 "[N] -> (C[] : { A[a,N] })", "{ : }",
6203 "[N] -> (C[] : { A[a,N] })" },
6204 { &isl_multi_union_pw_aff_intersect_params
,
6205 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
6206 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
6209 /* Perform some basic tests of binary operations on
6210 * pairs of isl_multi_union_pw_aff and isl_set objects.
6212 static int test_mupa_set(isl_ctx
*ctx
)
6216 isl_multi_union_pw_aff
*mupa
, *res
;
6219 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
6220 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6221 mupa_set_tests
[i
].arg1
);
6222 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
6223 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6224 mupa_set_tests
[i
].res
);
6225 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
6226 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6227 isl_multi_union_pw_aff_free(mupa
);
6228 isl_multi_union_pw_aff_free(res
);
6232 isl_die(ctx
, isl_error_unknown
,
6233 "unexpected result", return -1);
6239 /* Inputs for basic tests of binary operations on
6240 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6241 * "fn" is the function that is tested.
6242 * "arg1" and "arg2" are string descriptions of the inputs.
6243 * "res" is a string description of the expected result.
6246 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6247 __isl_take isl_multi_union_pw_aff
*mupa
,
6248 __isl_take isl_union_set
*uset
);
6252 } mupa_uset_tests
[] = {
6253 { &isl_multi_union_pw_aff_intersect_domain
,
6254 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
6255 "C[{ B[i,i] -> [3i] }]" },
6256 { &isl_multi_union_pw_aff_intersect_domain
,
6257 "(C[] : { B[i,j] })", "{ B[i,i] }",
6258 "(C[] : { B[i,i] })" },
6259 { &isl_multi_union_pw_aff_intersect_domain
,
6260 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
6261 "[N] -> (C[] : { B[N,N] })" },
6262 { &isl_multi_union_pw_aff_intersect_domain
,
6263 "C[]", "{ B[i,i] }",
6264 "(C[] : { B[i,i] })" },
6265 { &isl_multi_union_pw_aff_intersect_domain
,
6266 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
6267 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
6270 /* Perform some basic tests of binary operations on
6271 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6273 static int test_mupa_uset(isl_ctx
*ctx
)
6277 isl_multi_union_pw_aff
*mupa
, *res
;
6278 isl_union_set
*uset
;
6280 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
6281 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6282 mupa_uset_tests
[i
].arg1
);
6283 uset
= isl_union_set_read_from_str(ctx
,
6284 mupa_uset_tests
[i
].arg2
);
6285 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6286 mupa_uset_tests
[i
].res
);
6287 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
6288 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6289 isl_multi_union_pw_aff_free(mupa
);
6290 isl_multi_union_pw_aff_free(res
);
6294 isl_die(ctx
, isl_error_unknown
,
6295 "unexpected result", return -1);
6301 /* Inputs for basic tests of binary operations on
6302 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6303 * "fn" is the function that is tested.
6304 * "arg1" and "arg2" are string descriptions of the inputs.
6305 * "res" is a string description of the expected result.
6308 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6309 __isl_take isl_multi_union_pw_aff
*mupa
,
6310 __isl_take isl_multi_aff
*ma
);
6314 } mupa_ma_tests
[] = {
6315 { &isl_multi_union_pw_aff_apply_multi_aff
,
6316 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6317 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6318 "{ C[a,b] -> D[b,a] }",
6319 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6320 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6321 { &isl_multi_union_pw_aff_apply_multi_aff
,
6322 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6323 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6324 "{ C[a,b] -> D[b,a] }",
6325 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6326 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6327 { &isl_multi_union_pw_aff_apply_multi_aff
,
6328 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6329 "[N] -> { C[a] -> D[a + N] }",
6330 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
6331 { &isl_multi_union_pw_aff_apply_multi_aff
,
6335 { &isl_multi_union_pw_aff_apply_multi_aff
,
6336 "[N] -> (C[] : { : N >= 0 })",
6338 "[N] -> (D[] : { : N >= 0 })" },
6339 { &isl_multi_union_pw_aff_apply_multi_aff
,
6341 "[N] -> { C[] -> D[N] }",
6342 "[N] -> D[{ [N] }]" },
6343 { &isl_multi_union_pw_aff_apply_multi_aff
,
6344 "(C[] : { A[i,j] : i >= j })",
6346 "(D[] : { A[i,j] : i >= j })" },
6347 { &isl_multi_union_pw_aff_apply_multi_aff
,
6348 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6350 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6351 { &isl_multi_union_pw_aff_apply_multi_aff
,
6352 "(C[] : { A[i,j] : i >= j })",
6353 "[N] -> { C[] -> D[N] }",
6354 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6357 /* Perform some basic tests of binary operations on
6358 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6360 static int test_mupa_ma(isl_ctx
*ctx
)
6364 isl_multi_union_pw_aff
*mupa
, *res
;
6367 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
6368 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6369 mupa_ma_tests
[i
].arg1
);
6370 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
6371 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6372 mupa_ma_tests
[i
].res
);
6373 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
6374 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6375 isl_multi_union_pw_aff_free(mupa
);
6376 isl_multi_union_pw_aff_free(res
);
6380 isl_die(ctx
, isl_error_unknown
,
6381 "unexpected result", return -1);
6387 /* Inputs for basic tests of binary operations on
6388 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6389 * "fn" is the function that is tested.
6390 * "arg1" and "arg2" are string descriptions of the inputs.
6391 * "res" is a string description of the expected result.
6394 __isl_give isl_union_pw_aff
*(*fn
)(
6395 __isl_take isl_multi_union_pw_aff
*mupa
,
6396 __isl_take isl_pw_aff
*pa
);
6400 } mupa_pa_tests
[] = {
6401 { &isl_multi_union_pw_aff_apply_pw_aff
,
6402 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6403 "[N] -> { C[a] -> [a + N] }",
6404 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
6405 { &isl_multi_union_pw_aff_apply_pw_aff
,
6406 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6407 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
6408 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6409 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
6410 { &isl_multi_union_pw_aff_apply_pw_aff
,
6412 "[N] -> { C[] -> [N] }",
6414 { &isl_multi_union_pw_aff_apply_pw_aff
,
6416 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6417 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
6418 { &isl_multi_union_pw_aff_apply_pw_aff
,
6419 "[N] -> (C[] : { : N >= 0 })",
6420 "[N] -> { C[] -> [N] }",
6421 "[N] -> { [N] : N >= 0 }" },
6422 { &isl_multi_union_pw_aff_apply_pw_aff
,
6423 "[N] -> (C[] : { : N >= 0 })",
6424 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6425 "[N] -> { [N] : N >= 0 }" },
6426 { &isl_multi_union_pw_aff_apply_pw_aff
,
6427 "[N] -> (C[] : { : N >= 0 })",
6429 "[N] -> { [0] : N >= 0 }" },
6430 { &isl_multi_union_pw_aff_apply_pw_aff
,
6431 "(C[] : { A[i,j] : i >= j })",
6432 "[N] -> { C[] -> [N] }",
6433 "[N] -> { A[i,j] -> [N] : i >= j }" },
6434 { &isl_multi_union_pw_aff_apply_pw_aff
,
6435 "(C[] : { A[i,j] : i >= j })",
6436 "[N] -> { C[] -> [N] : N >= 0 }",
6437 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6440 /* Perform some basic tests of binary operations on
6441 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6443 static int test_mupa_pa(isl_ctx
*ctx
)
6447 isl_multi_union_pw_aff
*mupa
;
6448 isl_union_pw_aff
*upa
, *res
;
6451 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
6452 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6453 mupa_pa_tests
[i
].arg1
);
6454 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
6455 res
= isl_union_pw_aff_read_from_str(ctx
,
6456 mupa_pa_tests
[i
].res
);
6457 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
6458 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
6459 isl_union_pw_aff_free(upa
);
6460 isl_union_pw_aff_free(res
);
6464 isl_die(ctx
, isl_error_unknown
,
6465 "unexpected result", return -1);
6471 /* Inputs for basic tests of binary operations on
6472 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6473 * "fn" is the function that is tested.
6474 * "arg1" and "arg2" are string descriptions of the inputs.
6475 * "res" is a string description of the expected result.
6478 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6479 __isl_take isl_multi_union_pw_aff
*mupa
,
6480 __isl_take isl_pw_multi_aff
*pma
);
6484 } mupa_pma_tests
[] = {
6485 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6486 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6487 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6488 "{ C[a,b] -> D[b,a] }",
6489 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6490 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6491 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6492 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6493 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6494 "{ C[a,b] -> D[b,a] }",
6495 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6496 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6497 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6498 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6499 "[N] -> { C[a] -> D[a + N] }",
6500 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6501 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6502 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6503 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6504 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6505 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6506 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6507 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6508 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6509 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6510 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6511 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6512 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6513 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6514 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6518 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6519 "[N] -> (C[] : { : N >= 0 })",
6521 "[N] -> (D[] : { : N >= 0 })" },
6522 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6524 "[N] -> { C[] -> D[N] }",
6525 "[N] -> D[{ [N] }]" },
6526 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6527 "(C[] : { A[i,j] : i >= j })",
6529 "(D[] : { A[i,j] : i >= j })" },
6530 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6531 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6533 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6534 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6535 "(C[] : { A[i,j] : i >= j })",
6536 "[N] -> { C[] -> D[N] }",
6537 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6538 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6540 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6541 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6542 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6543 "[N] -> (C[] : { : N >= 0 })",
6544 "[N] -> { C[] -> D[N] }",
6545 "[N] -> D[{ [N] : N >= 0 }]" },
6546 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6547 "[N] -> (C[] : { : N >= 0 })",
6548 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6549 "[N] -> D[{ [N] : N >= 0 }]" },
6550 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6551 "[N] -> (C[] : { : N >= 0 })",
6553 "[N] -> D[{ [0] : N >= 0 }]" },
6554 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6555 "(C[] : { A[i,j] : i >= j })",
6556 "[N] -> { C[] -> D[N] : N >= 0 }",
6557 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6560 /* Perform some basic tests of binary operations on
6561 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6563 static int test_mupa_pma(isl_ctx
*ctx
)
6567 isl_multi_union_pw_aff
*mupa
, *res
;
6568 isl_pw_multi_aff
*pma
;
6570 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
6571 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6572 mupa_pma_tests
[i
].arg1
);
6573 pma
= isl_pw_multi_aff_read_from_str(ctx
,
6574 mupa_pma_tests
[i
].arg2
);
6575 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6576 mupa_pma_tests
[i
].res
);
6577 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
6578 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6579 isl_multi_union_pw_aff_free(mupa
);
6580 isl_multi_union_pw_aff_free(res
);
6584 isl_die(ctx
, isl_error_unknown
,
6585 "unexpected result", return -1);
6591 /* Inputs for basic tests of binary operations on
6592 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6593 * "fn" is the function that is tested.
6594 * "arg1" and "arg2" are string descriptions of the inputs.
6595 * "res" is a string description of the expected result.
6598 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6599 __isl_take isl_multi_union_pw_aff
*mupa
,
6600 __isl_take isl_union_pw_multi_aff
*upma
);
6604 } mupa_upma_tests
[] = {
6605 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6606 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6607 "C[{ A[a,b] -> [b + 2a] }]" },
6608 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6609 "C[{ B[i,j] -> [i + 2j] }]",
6610 "{ A[a,b] -> B[b,a] : b > a }",
6611 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6612 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6613 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6614 "{ A[a,b] -> B[b,a] : b > a }",
6615 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6616 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6617 "C[{ B[i,j] -> [i + 2j] }]",
6618 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6619 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6620 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6621 "(C[] : { B[a,b] })",
6622 "{ A[a,b] -> B[b,a] }",
6623 "(C[] : { A[a,b] })" },
6624 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6625 "(C[] : { B[a,b] })",
6626 "{ B[a,b] -> A[b,a] }",
6628 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6629 "(C[] : { B[a,b] })",
6630 "{ A[a,b] -> B[b,a] : a > b }",
6631 "(C[] : { A[a,b] : a > b })" },
6632 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6633 "(C[] : { B[a,b] : a > b })",
6634 "{ A[a,b] -> B[b,a] }",
6635 "(C[] : { A[a,b] : b > a })" },
6636 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6637 "[N] -> (C[] : { B[a,b] : a > N })",
6638 "{ A[a,b] -> B[b,a] : a > b }",
6639 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6640 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6641 "(C[] : { B[a,b] : a > b })",
6642 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6643 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6644 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6646 "{ A[a,b] -> B[b,a] }",
6648 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6649 "[N] -> (C[] : { : N >= 0 })",
6650 "{ A[a,b] -> B[b,a] }",
6651 "[N] -> (C[] : { : N >= 0 })" },
6652 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6654 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6655 "[N] -> (C[] : { : N >= 0 })" },
6658 /* Perform some basic tests of binary operations on
6659 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6661 static int test_mupa_upma(isl_ctx
*ctx
)
6665 isl_multi_union_pw_aff
*mupa
, *res
;
6666 isl_union_pw_multi_aff
*upma
;
6668 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
6669 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6670 mupa_upma_tests
[i
].arg1
);
6671 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
6672 mupa_upma_tests
[i
].arg2
);
6673 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6674 mupa_upma_tests
[i
].res
);
6675 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
6676 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6677 isl_multi_union_pw_aff_free(mupa
);
6678 isl_multi_union_pw_aff_free(res
);
6682 isl_die(ctx
, isl_error_unknown
,
6683 "unexpected result", return -1);
6689 /* Check that the input tuple of an isl_aff can be set properly.
6691 static isl_stat
test_aff_set_tuple_id(isl_ctx
*ctx
)
6697 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x + 1] }");
6698 id
= isl_id_alloc(ctx
, "A", NULL
);
6699 aff
= isl_aff_set_tuple_id(aff
, isl_dim_in
, id
);
6700 equal
= aff_check_plain_equal(aff
, "{ A[x] -> [x + 1] }");
6703 return isl_stat_error
;
6708 /* Check that affine expressions get normalized on addition/subtraction.
6709 * In particular, check that (final) unused integer divisions get removed
6710 * such that an expression derived from expressions with integer divisions
6711 * is found to be obviously equal to one that is created directly.
6713 static isl_stat
test_aff_normalize(isl_ctx
*ctx
)
6715 isl_aff
*aff
, *aff2
;
6718 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x//2] }");
6719 aff2
= isl_aff_read_from_str(ctx
, "{ [x] -> [1 + x//2] }");
6720 aff
= isl_aff_sub(aff2
, aff
);
6721 ok
= aff_check_plain_equal(aff
, "{ [x] -> [1] }");
6727 int test_aff(isl_ctx
*ctx
)
6732 isl_local_space
*ls
;
6737 if (test_upa(ctx
) < 0)
6739 if (test_bin_aff(ctx
) < 0)
6741 if (test_bin_pw_aff(ctx
) < 0)
6743 if (test_upma_test(ctx
) < 0)
6745 if (test_bin_upma(ctx
) < 0)
6747 if (test_bin_upma_fail(ctx
) < 0)
6749 if (test_upma_uset(ctx
) < 0)
6751 if (test_un_mpa(ctx
) < 0)
6753 if (test_bin_mpa(ctx
) < 0)
6755 if (test_un_mupa(ctx
) < 0)
6757 if (test_bin_mupa(ctx
) < 0)
6759 if (test_mupa_set(ctx
) < 0)
6761 if (test_mupa_uset(ctx
) < 0)
6763 if (test_mupa_ma(ctx
) < 0)
6765 if (test_mupa_pa(ctx
) < 0)
6767 if (test_mupa_pma(ctx
) < 0)
6769 if (test_mupa_upma(ctx
) < 0)
6772 space
= isl_space_set_alloc(ctx
, 0, 1);
6773 ls
= isl_local_space_from_space(space
);
6774 aff
= isl_aff_zero_on_domain(ls
);
6776 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6777 aff
= isl_aff_scale_down_ui(aff
, 3);
6778 aff
= isl_aff_floor(aff
);
6779 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6780 aff
= isl_aff_scale_down_ui(aff
, 2);
6781 aff
= isl_aff_floor(aff
);
6782 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6785 set
= isl_set_read_from_str(ctx
, str
);
6786 aff
= isl_aff_gist(aff
, set
);
6788 aff
= isl_aff_add_constant_si(aff
, -16);
6789 zero
= isl_aff_plain_is_zero(aff
);
6795 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6797 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6798 aff
= isl_aff_scale_down_ui(aff
, 64);
6799 aff
= isl_aff_floor(aff
);
6800 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6805 if (test_aff_set_tuple_id(ctx
) < 0)
6807 if (test_aff_normalize(ctx
) < 0)
6813 /* Inputs for isl_set_bind tests.
6814 * "set" is the input set.
6815 * "tuple" is the binding tuple.
6816 * "res" is the expected result.
6823 } bind_set_tests
[] = {
6824 { "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6826 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6827 { "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }",
6829 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6830 { "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }",
6832 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6833 { "[M] -> { D[x, N] : x mod 2 = 0 and N mod 8 = 3 and M >= 0 }",
6835 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 and M >= 0 }" },
6838 /* Perform basic isl_set_bind tests.
6840 static isl_stat
test_bind_set(isl_ctx
*ctx
)
6844 for (i
= 0; i
< ARRAY_SIZE(bind_set_tests
); ++i
) {
6847 isl_multi_id
*tuple
;
6850 set
= isl_set_read_from_str(ctx
, bind_set_tests
[i
].set
);
6851 str
= bind_set_tests
[i
].tuple
;
6852 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6853 set
= isl_set_bind(set
, tuple
);
6854 r
= set_check_equal(set
, bind_set_tests
[i
].res
);
6857 return isl_stat_error
;
6863 /* Inputs for isl_map_bind_domain tests.
6864 * "map" is the input map.
6865 * "tuple" is the binding tuple.
6866 * "res" is the expected result.
6872 } bind_map_domain_tests
[] = {
6873 { "{ A[M, N] -> [M + floor(N/2)] }",
6875 "[M, N] -> { [M + floor(N/2)] }" },
6876 { "{ B[N, M] -> [M + floor(N/2)] }",
6878 "[N, M] -> { [M + floor(N/2)] }" },
6879 { "[M] -> { C[N] -> [M + floor(N/2)] }",
6881 "[M, N] -> { [M + floor(N/2)] }" },
6882 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
6884 "[M, N] -> { [M + floor(N/2)] }" },
6885 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
6887 "[M, N] -> { [M + floor(N/2)] }" },
6888 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
6890 "[A, N, M] -> { [M + floor(N/2)] }" },
6893 /* Perform basic isl_map_bind_domain tests.
6895 static isl_stat
test_bind_map_domain(isl_ctx
*ctx
)
6899 for (i
= 0; i
< ARRAY_SIZE(bind_map_domain_tests
); ++i
) {
6903 isl_multi_id
*tuple
;
6906 str
= bind_map_domain_tests
[i
].map
;
6907 map
= isl_map_read_from_str(ctx
, str
);
6908 str
= bind_map_domain_tests
[i
].tuple
;
6909 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6910 set
= isl_map_bind_domain(map
, tuple
);
6911 str
= bind_map_domain_tests
[i
].res
;
6912 r
= set_check_equal(set
, str
);
6915 return isl_stat_error
;
6921 /* Inputs for isl_union_map_bind_range tests.
6922 * "map" is the input union map.
6923 * "tuple" is the binding tuple.
6924 * "res" is the expected result.
6930 } bind_umap_range_tests
[] = {
6931 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6933 "[M, N] -> { B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
6934 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6937 { "{ A[] -> B[]; C[] -> D[]; E[] -> B[] }",
6942 /* Perform basic isl_union_map_bind_range tests.
6944 static isl_stat
test_bind_umap_range(isl_ctx
*ctx
)
6948 for (i
= 0; i
< ARRAY_SIZE(bind_umap_range_tests
); ++i
) {
6950 isl_union_map
*umap
;
6951 isl_union_set
*uset
;
6952 isl_multi_id
*tuple
;
6955 str
= bind_umap_range_tests
[i
].map
;
6956 umap
= isl_union_map_read_from_str(ctx
, str
);
6957 str
= bind_umap_range_tests
[i
].tuple
;
6958 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6959 uset
= isl_union_map_bind_range(umap
, tuple
);
6960 str
= bind_umap_range_tests
[i
].res
;
6961 r
= uset_check_equal(uset
, str
);
6962 isl_union_set_free(uset
);
6964 return isl_stat_error
;
6970 /* Inputs for isl_pw_multi_aff_bind_domain tests.
6971 * "pma" is the input expression.
6972 * "tuple" is the binding tuple.
6973 * "res" is the expected result.
6979 } bind_pma_domain_tests
[] = {
6980 { "{ A[M, N] -> [M + floor(N/2)] }",
6982 "[M, N] -> { [M + floor(N/2)] }" },
6983 { "{ B[N, M] -> [M + floor(N/2)] }",
6985 "[N, M] -> { [M + floor(N/2)] }" },
6986 { "[M] -> { C[N] -> [M + floor(N/2)] }",
6988 "[M, N] -> { [M + floor(N/2)] }" },
6989 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
6991 "[M, N] -> { [M + floor(N/2)] }" },
6992 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
6994 "[M, N] -> { [M + floor(N/2)] }" },
6995 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
6997 "[A, N, M] -> { [M + floor(N/2)] }" },
7000 /* Perform basic isl_pw_multi_aff_bind_domain tests.
7002 static isl_stat
test_bind_pma_domain(isl_ctx
*ctx
)
7006 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_tests
); ++i
) {
7008 isl_pw_multi_aff
*pma
;
7009 isl_multi_id
*tuple
;
7012 str
= bind_pma_domain_tests
[i
].pma
;
7013 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7014 str
= bind_pma_domain_tests
[i
].tuple
;
7015 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7016 pma
= isl_pw_multi_aff_bind_domain(pma
, tuple
);
7017 str
= bind_pma_domain_tests
[i
].res
;
7018 r
= pw_multi_aff_check_plain_equal(pma
, str
);
7019 isl_pw_multi_aff_free(pma
);
7021 return isl_stat_error
;
7027 /* Inputs for isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7028 * "pma" is the input expression.
7029 * "tuple" is the binding tuple.
7030 * "res" is the expected result.
7036 } bind_pma_domain_wrapped_tests
[] = {
7037 { "{ [A[M, N] -> B[]] -> [M + floor(N/2)] }",
7039 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7040 { "{ [B[N, M] -> D[]] -> [M + floor(N/2)] }",
7042 "[N, M] -> { D[] -> [M + floor(N/2)] }" },
7043 { "[M] -> { [C[N] -> B[x]] -> [x + M + floor(N/2)] }",
7045 "[M, N] -> { B[x] -> [x + M + floor(N/2)] }" },
7046 { "[M] -> { [C[x, N] -> B[]] -> [x + floor(N/2)] }",
7048 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7049 { "[M] -> { [C[x, N] -> B[]] -> [M + floor(N/2)] }",
7051 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7052 { "[A, M] -> { [C[N, x] -> B[]] -> [x + floor(N/2)] }",
7054 "[A, N, M] -> { B[] -> [M + floor(N/2)] }" },
7057 /* Perform basic isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7059 static isl_stat
test_bind_pma_domain_wrapped(isl_ctx
*ctx
)
7063 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_wrapped_tests
); ++i
) {
7065 isl_pw_multi_aff
*pma
;
7066 isl_multi_id
*tuple
;
7069 str
= bind_pma_domain_wrapped_tests
[i
].pma
;
7070 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7071 str
= bind_pma_domain_wrapped_tests
[i
].tuple
;
7072 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7073 pma
= isl_pw_multi_aff_bind_domain_wrapped_domain(pma
, tuple
);
7074 str
= bind_pma_domain_wrapped_tests
[i
].res
;
7075 r
= pw_multi_aff_check_plain_equal(pma
, str
);
7076 isl_pw_multi_aff_free(pma
);
7078 return isl_stat_error
;
7084 /* Inputs for isl_aff_bind_id tests.
7085 * "aff" is the input expression.
7086 * "id" is the binding id.
7087 * "res" is the expected result.
7094 } bind_aff_tests
[] = {
7095 { "{ [4] }", "M", "[M = 4] -> { : }" },
7096 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7097 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7098 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7099 { "{ [NaN] }", "M", "{ : false }" },
7100 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7103 /* Perform basic isl_aff_bind_id tests.
7105 static isl_stat
test_bind_aff(isl_ctx
*ctx
)
7109 for (i
= 0; i
< ARRAY_SIZE(bind_aff_tests
); ++i
) {
7115 aff
= isl_aff_read_from_str(ctx
, bind_aff_tests
[i
].aff
);
7116 id
= isl_id_read_from_str(ctx
, bind_aff_tests
[i
].id
);
7117 res
= isl_set_from_basic_set(isl_aff_bind_id(aff
, id
));
7118 r
= set_check_equal(res
, bind_aff_tests
[i
].res
);
7121 return isl_stat_error
;
7127 /* Inputs for isl_pw_aff_bind_id tests.
7128 * "pa" is the input expression.
7129 * "id" is the binding id.
7130 * "res" is the expected result.
7137 } bind_pa_tests
[] = {
7138 { "{ [4] }", "M", "[M = 4] -> { : }" },
7139 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7140 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7141 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7142 { "[M] -> { [M] : M >= 0; [-M] : M < 0 }", "M", "[M] -> { : M >= 0 }" },
7143 { "{ [NaN] }", "M", "{ : false }" },
7144 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7147 /* Perform basic isl_pw_aff_bind_id tests.
7149 static isl_stat
test_bind_pa(isl_ctx
*ctx
)
7153 for (i
= 0; i
< ARRAY_SIZE(bind_pa_tests
); ++i
) {
7159 pa
= isl_pw_aff_read_from_str(ctx
, bind_pa_tests
[i
].pa
);
7160 id
= isl_id_read_from_str(ctx
, bind_pa_tests
[i
].id
);
7161 res
= isl_pw_aff_bind_id(pa
, id
);
7162 r
= set_check_equal(res
, bind_pa_tests
[i
].res
);
7165 return isl_stat_error
;
7171 /* Inputs for isl_multi_union_pw_aff_bind tests.
7172 * "mupa" is the input expression.
7173 * "tuple" is the binding tuple.
7174 * "res" is the expected result.
7181 } bind_mupa_tests
[] = {
7182 { "A[{ [4] }, { [5] }]",
7184 "[M = 4, N = 5] -> { : }" },
7185 { "A[{ B[x] -> [floor(x/2)] }, { B[y] -> [y + 5] }]",
7187 "[M, N] -> { B[x] : M = floor(x/2) and N = x + 5 }" },
7188 { "[M] -> A[{ [4] }, { [M + 1] }]",
7190 "[M = 4, N = 5] -> { : }" },
7193 /* Perform basic isl_multi_union_pw_aff_bind tests.
7195 static isl_stat
test_bind_mupa(isl_ctx
*ctx
)
7199 for (i
= 0; i
< ARRAY_SIZE(bind_mupa_tests
); ++i
) {
7201 isl_multi_union_pw_aff
*mupa
;
7203 isl_multi_id
*tuple
;
7206 str
= bind_mupa_tests
[i
].mupa
;
7207 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
7208 str
= bind_mupa_tests
[i
].tuple
;
7209 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7210 res
= isl_multi_union_pw_aff_bind(mupa
, tuple
);
7211 r
= uset_check_equal(res
, bind_mupa_tests
[i
].res
);
7212 isl_union_set_free(res
);
7214 return isl_stat_error
;
7220 /* Perform tests that reinterpret dimensions as parameters.
7222 static int test_bind(isl_ctx
*ctx
)
7224 if (test_bind_set(ctx
) < 0)
7226 if (test_bind_map_domain(ctx
) < 0)
7228 if (test_bind_umap_range(ctx
) < 0)
7230 if (test_bind_pma_domain(ctx
) < 0)
7232 if (test_bind_pma_domain_wrapped(ctx
) < 0)
7234 if (test_bind_aff(ctx
) < 0)
7236 if (test_bind_pa(ctx
) < 0)
7238 if (test_bind_mupa(ctx
) < 0)
7244 /* Inputs for isl_set_unbind_params tests.
7245 * "set" is the input parameter domain.
7246 * "tuple" is the tuple of the constructed set.
7247 * "res" is the expected result.
7253 } unbind_set_tests
[] = {
7254 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7256 "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7257 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7259 "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7260 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7262 "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }" },
7263 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7265 "[M] -> { D[x, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7268 /* Perform basic isl_set_unbind_params tests.
7270 static isl_stat
test_unbind_set(isl_ctx
*ctx
)
7274 for (i
= 0; i
< ARRAY_SIZE(unbind_set_tests
); ++i
) {
7277 isl_multi_id
*tuple
;
7280 set
= isl_set_read_from_str(ctx
, unbind_set_tests
[i
].set
);
7281 str
= unbind_set_tests
[i
].tuple
;
7282 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7283 set
= isl_set_unbind_params(set
, tuple
);
7284 r
= set_check_equal(set
, unbind_set_tests
[i
].res
);
7287 return isl_stat_error
;
7293 /* Inputs for isl_aff_unbind_params_insert_domain tests.
7294 * "aff" is the input affine expression defined over a parameter domain.
7295 * "tuple" is the tuple of the domain that gets introduced.
7296 * "res" is the expected result.
7302 } unbind_aff_tests
[] = {
7303 { "[M, N] -> { [M + floor(N/2)] }",
7305 "{ A[M, N] -> [M + floor(N/2)] }" },
7306 { "[M, N] -> { [M + floor(N/2)] }",
7308 "{ B[N, M] -> [M + floor(N/2)] }" },
7309 { "[M, N] -> { [M + floor(N/2)] }",
7311 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7312 { "[M, N] -> { [M + floor(N/2)] }",
7313 "{ D[A, B, C, N, Z] }",
7314 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7317 /* Perform basic isl_aff_unbind_params_insert_domain tests.
7319 static isl_stat
test_unbind_aff(isl_ctx
*ctx
)
7323 for (i
= 0; i
< ARRAY_SIZE(unbind_aff_tests
); ++i
) {
7326 isl_multi_id
*tuple
;
7329 aff
= isl_aff_read_from_str(ctx
, unbind_aff_tests
[i
].aff
);
7330 str
= unbind_aff_tests
[i
].tuple
;
7331 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7332 aff
= isl_aff_unbind_params_insert_domain(aff
, tuple
);
7333 r
= aff_check_plain_equal(aff
, unbind_aff_tests
[i
].res
);
7336 return isl_stat_error
;
7342 /* Inputs for isl_multi_aff_unbind_params_insert_domain tests.
7343 * "ma" is the input multi affine expression defined over a parameter domain.
7344 * "tuple" is the tuple of the domain that gets introduced.
7345 * "res" is the expected result.
7351 } unbind_multi_aff_tests
[] = {
7352 { "[M, N] -> { T[M + floor(N/2)] }",
7354 "{ A[M, N] -> T[M + floor(N/2)] }" },
7355 { "[M, N] -> { [M + floor(N/2)] }",
7357 "{ B[N, M] -> [M + floor(N/2)] }" },
7358 { "[M, N] -> { [M + floor(N/2)] }",
7360 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7361 { "[M, N] -> { [M + floor(N/2)] }",
7362 "{ D[A, B, C, N, Z] }",
7363 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7364 { "[M, N] -> { T[M + floor(N/2), N + floor(M/3)] }",
7366 "{ A[M, N] -> T[M + floor(N/2), N + floor(M/3)] }" },
7369 /* Perform basic isl_multi_aff_unbind_params_insert_domain tests.
7371 static isl_stat
test_unbind_multi_aff(isl_ctx
*ctx
)
7375 for (i
= 0; i
< ARRAY_SIZE(unbind_multi_aff_tests
); ++i
) {
7378 isl_multi_id
*tuple
;
7381 str
= unbind_multi_aff_tests
[i
].ma
;
7382 ma
= isl_multi_aff_read_from_str(ctx
, str
);
7383 str
= unbind_multi_aff_tests
[i
].tuple
;
7384 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7385 ma
= isl_multi_aff_unbind_params_insert_domain(ma
, tuple
);
7386 str
= unbind_multi_aff_tests
[i
].res
;
7387 r
= multi_aff_check_plain_equal(ma
, str
);
7388 isl_multi_aff_free(ma
);
7390 return isl_stat_error
;
7396 /* Perform tests that reinterpret parameters.
7398 static int test_unbind(isl_ctx
*ctx
)
7400 if (test_unbind_set(ctx
) < 0)
7402 if (test_unbind_aff(ctx
) < 0)
7404 if (test_unbind_multi_aff(ctx
) < 0)
7410 /* Check that "pa" consists of a single expression.
7412 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
7416 n
= isl_pw_aff_n_piece(pa
);
7417 isl_pw_aff_free(pa
);
7422 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
7428 /* Check that the computation below results in a single expression.
7429 * One or two expressions may result depending on which constraint
7430 * ends up being considered as redundant with respect to the other
7431 * constraints after the projection that is performed internally
7432 * by isl_set_dim_min.
7434 static int test_dim_max_1(isl_ctx
*ctx
)
7440 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
7441 "-4a <= b <= 3 and b < n - 4a }";
7442 set
= isl_set_read_from_str(ctx
, str
);
7443 pa
= isl_set_dim_min(set
, 0);
7444 return check_single_piece(ctx
, pa
);
7447 /* Check that the computation below results in a single expression.
7448 * The PIP problem corresponding to these constraints has a row
7449 * that causes a split of the solution domain. The solver should
7450 * first pick rows that split off empty parts such that the actual
7451 * solution domain does not get split.
7452 * Note that the description contains some redundant constraints.
7453 * If these constraints get removed first, then the row mentioned
7454 * above does not appear in the PIP problem.
7456 static int test_dim_max_2(isl_ctx
*ctx
)
7462 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
7463 "N > 0 and P >= 0 }";
7464 set
= isl_set_read_from_str(ctx
, str
);
7465 pa
= isl_set_dim_max(set
, 0);
7466 return check_single_piece(ctx
, pa
);
7469 int test_dim_max(isl_ctx
*ctx
)
7473 isl_set
*set1
, *set2
;
7478 if (test_dim_max_1(ctx
) < 0)
7480 if (test_dim_max_2(ctx
) < 0)
7483 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
7484 set
= isl_set_read_from_str(ctx
, str
);
7485 pwaff
= isl_set_dim_max(set
, 0);
7486 set1
= isl_set_from_pw_aff(pwaff
);
7487 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
7488 set2
= isl_set_read_from_str(ctx
, str
);
7489 equal
= isl_set_is_equal(set1
, set2
);
7495 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7497 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
7498 set
= isl_set_read_from_str(ctx
, str
);
7499 pwaff
= isl_set_dim_max(set
, 0);
7500 set1
= isl_set_from_pw_aff(pwaff
);
7501 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7502 set2
= isl_set_read_from_str(ctx
, str
);
7503 equal
= isl_set_is_equal(set1
, set2
);
7509 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7511 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
7512 set
= isl_set_read_from_str(ctx
, str
);
7513 pwaff
= isl_set_dim_max(set
, 0);
7514 set1
= isl_set_from_pw_aff(pwaff
);
7515 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7516 set2
= isl_set_read_from_str(ctx
, str
);
7517 equal
= isl_set_is_equal(set1
, set2
);
7523 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7525 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
7526 "0 <= i < N and 0 <= j < M }";
7527 map
= isl_map_read_from_str(ctx
, str
);
7528 set
= isl_map_range(map
);
7530 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
7531 set1
= isl_set_from_pw_aff(pwaff
);
7532 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
7533 set2
= isl_set_read_from_str(ctx
, str
);
7534 equal
= isl_set_is_equal(set1
, set2
);
7538 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
7539 set1
= isl_set_from_pw_aff(pwaff
);
7540 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
7541 set2
= isl_set_read_from_str(ctx
, str
);
7542 if (equal
>= 0 && equal
)
7543 equal
= isl_set_is_equal(set1
, set2
);
7552 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7554 /* Check that solutions are properly merged. */
7555 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
7556 "c <= -1 + n - 4a - 2b and c >= -2b and "
7557 "4a >= -4 + n and c >= 0 }";
7558 set
= isl_set_read_from_str(ctx
, str
);
7559 pwaff
= isl_set_dim_min(set
, 2);
7560 set1
= isl_set_from_pw_aff(pwaff
);
7561 str
= "[n] -> { [(0)] : n >= 1 }";
7562 set2
= isl_set_read_from_str(ctx
, str
);
7563 equal
= isl_set_is_equal(set1
, set2
);
7570 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7572 /* Check that empty solution lie in the right space. */
7573 str
= "[n] -> { [t,a] : 1 = 0 }";
7574 set
= isl_set_read_from_str(ctx
, str
);
7575 pwaff
= isl_set_dim_max(set
, 0);
7576 set1
= isl_set_from_pw_aff(pwaff
);
7577 str
= "[n] -> { [t] : 1 = 0 }";
7578 set2
= isl_set_read_from_str(ctx
, str
);
7579 equal
= isl_set_is_equal(set1
, set2
);
7586 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7591 /* Basic test for isl_pw_multi_aff_product.
7593 * Check that multiple pieces are properly handled.
7595 static int test_product_pma(isl_ctx
*ctx
)
7599 isl_pw_multi_aff
*pma1
, *pma2
;
7601 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
7602 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7603 str
= "{ C[] -> D[] }";
7604 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7605 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
7606 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
7607 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
7608 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
7609 isl_pw_multi_aff_free(pma1
);
7616 int test_product(isl_ctx
*ctx
)
7620 isl_union_set
*uset1
, *uset2
;
7624 set
= isl_set_read_from_str(ctx
, str
);
7625 set
= isl_set_product(set
, isl_set_copy(set
));
7626 ok
= isl_set_is_wrapping(set
);
7631 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7634 uset1
= isl_union_set_read_from_str(ctx
, str
);
7635 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
7636 str
= "{ [[] -> []] }";
7637 uset2
= isl_union_set_read_from_str(ctx
, str
);
7638 ok
= isl_union_set_is_equal(uset1
, uset2
);
7639 isl_union_set_free(uset1
);
7640 isl_union_set_free(uset2
);
7644 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7646 if (test_product_pma(ctx
) < 0)
7652 /* Check that two sets are not considered disjoint just because
7653 * they have a different set of (named) parameters.
7655 static int test_disjoint(isl_ctx
*ctx
)
7658 isl_set
*set
, *set2
;
7661 str
= "[n] -> { [[]->[]] }";
7662 set
= isl_set_read_from_str(ctx
, str
);
7663 str
= "{ [[]->[]] }";
7664 set2
= isl_set_read_from_str(ctx
, str
);
7665 disjoint
= isl_set_is_disjoint(set
, set2
);
7671 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7676 /* Inputs for isl_pw_multi_aff_is_equal tests.
7677 * "f1" and "f2" are the two function that need to be compared.
7678 * "equal" is the expected result.
7684 } pma_equal_tests
[] = {
7685 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
7686 "[N] -> { [0] : 0 <= N <= 1 }" },
7687 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7688 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
7689 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7690 "[N] -> { [0] : 0 <= N <= 1 }" },
7691 { 0, "{ [NaN] }", "{ [NaN] }" },
7694 int test_equal(isl_ctx
*ctx
)
7698 isl_set
*set
, *set2
;
7702 set
= isl_set_read_from_str(ctx
, str
);
7704 set2
= isl_set_read_from_str(ctx
, str
);
7705 equal
= isl_set_is_equal(set
, set2
);
7711 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7713 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
7714 int expected
= pma_equal_tests
[i
].equal
;
7715 isl_pw_multi_aff
*f1
, *f2
;
7717 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
7718 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
7719 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
7720 isl_pw_multi_aff_free(f1
);
7721 isl_pw_multi_aff_free(f2
);
7724 if (equal
!= expected
)
7725 isl_die(ctx
, isl_error_unknown
,
7726 "unexpected equality result", return -1);
7732 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
7733 enum isl_dim_type type
, unsigned pos
, int fixed
)
7737 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
7744 isl_die(ctx
, isl_error_unknown
,
7745 "map not detected as fixed", return -1);
7747 isl_die(ctx
, isl_error_unknown
,
7748 "map detected as fixed", return -1);
7751 int test_fixed(isl_ctx
*ctx
)
7756 str
= "{ [i] -> [i] }";
7757 map
= isl_map_read_from_str(ctx
, str
);
7758 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
7760 str
= "{ [i] -> [1] }";
7761 map
= isl_map_read_from_str(ctx
, str
);
7762 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7764 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
7765 map
= isl_map_read_from_str(ctx
, str
);
7766 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7768 map
= isl_map_read_from_str(ctx
, str
);
7769 map
= isl_map_neg(map
);
7770 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7776 struct isl_vertices_test_data
{
7779 const char *vertex
[6];
7780 } vertices_tests
[] = {
7781 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
7782 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
7783 { "{ A[t, i] : t = 14 and i = 1 }",
7784 1, { "{ A[14, 1] }" } },
7785 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
7786 "c <= m and m <= n and m > 0 }",
7788 "[n, m] -> { [n, m, m] : 0 < m <= n }",
7789 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
7790 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
7791 "[n, m] -> { [m, m, m] : 0 < m <= n }",
7792 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
7793 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
7797 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
7799 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
7801 struct isl_vertices_test_data
*data
= user
;
7804 isl_basic_set
*bset
;
7805 isl_pw_multi_aff
*pma
;
7809 ctx
= isl_vertex_get_ctx(vertex
);
7810 bset
= isl_vertex_get_domain(vertex
);
7811 ma
= isl_vertex_get_expr(vertex
);
7812 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
7814 for (i
= 0; i
< data
->n
; ++i
) {
7815 isl_pw_multi_aff
*pma_i
;
7817 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
7818 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
7819 isl_pw_multi_aff_free(pma_i
);
7821 if (equal
< 0 || equal
)
7825 isl_pw_multi_aff_free(pma
);
7826 isl_vertex_free(vertex
);
7829 return isl_stat_error
;
7831 return equal
? isl_stat_ok
: isl_stat_error
;
7834 int test_vertices(isl_ctx
*ctx
)
7838 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
7839 isl_basic_set
*bset
;
7840 isl_vertices
*vertices
;
7844 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
7845 vertices
= isl_basic_set_compute_vertices(bset
);
7846 n
= isl_vertices_get_n_vertices(vertices
);
7847 if (vertices_tests
[i
].n
!= n
)
7849 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
7850 &vertices_tests
[i
]) < 0)
7852 isl_vertices_free(vertices
);
7853 isl_basic_set_free(bset
);
7858 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
7865 /* Inputs for basic tests of unary operations on isl_union_map.
7866 * "fn" is the function that is being tested.
7867 * "arg" is a string description of the input.
7868 * "res" is a string description of the expected result.
7871 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap
);
7874 } umap_un_tests
[] = {
7875 { &isl_union_map_range_reverse
,
7876 "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
7877 "{ A[] -> [C[] -> B[]]; A[0] -> N[B[2] -> B[1]] }" },
7878 { &isl_union_map_range_reverse
,
7879 "{ A[] -> N[B[] -> C[]] }",
7880 "{ A[] -> [C[] -> B[]] }" },
7881 { &isl_union_map_range_reverse
,
7882 "{ A[] -> N[B[x] -> B[y]] }",
7883 "{ A[] -> N[B[*] -> B[*]] }" },
7886 /* Perform basic tests of unary operations on isl_union_map.
7888 static isl_stat
test_un_union_map(isl_ctx
*ctx
)
7892 for (i
= 0; i
< ARRAY_SIZE(umap_un_tests
); ++i
) {
7894 isl_union_map
*umap
, *res
;
7897 str
= umap_un_tests
[i
].arg
;
7898 umap
= isl_union_map_read_from_str(ctx
, str
);
7899 str
= umap_un_tests
[i
].res
;
7900 res
= isl_union_map_read_from_str(ctx
, str
);
7901 umap
= umap_un_tests
[i
].fn(umap
);
7902 equal
= isl_union_map_is_equal(umap
, res
);
7903 isl_union_map_free(umap
);
7904 isl_union_map_free(res
);
7906 return isl_stat_error
;
7908 isl_die(ctx
, isl_error_unknown
,
7909 "unexpected result", return isl_stat_error
);
7915 /* Inputs for basic tests of binary operations on isl_union_map.
7916 * "fn" is the function that is being tested.
7917 * "arg1" and "arg2" are string descriptions of the inputs.
7918 * "res" is a string description of the expected result.
7921 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap1
,
7922 __isl_take isl_union_map
*umap2
);
7926 } umap_bin_tests
[] = {
7927 { &isl_union_map_intersect
,
7928 "[n] -> { A[i] -> [] : 0 <= i <= n; B[] -> [] }",
7929 "[m] -> { A[i] -> [] : 0 <= i <= m; C[] -> [] }",
7930 "[m, n] -> { A[i] -> [] : 0 <= i <= n and i <= m }" },
7931 { &isl_union_map_intersect_domain_factor_range
,
7932 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7933 "[N] -> { B[i] -> C[N] }",
7934 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
7935 { &isl_union_map_intersect_domain_factor_range
,
7936 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
7937 "[N] -> { B[i] -> C[N] }",
7938 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
7939 { &isl_union_map_intersect_domain_factor_range
,
7940 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7941 "[N] -> { A[i] -> C[N] }",
7943 { &isl_union_map_intersect_range_factor_domain
,
7944 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7945 "[N] -> { A[i] -> B[N] }",
7946 "[N] -> { A[N - 1] -> [B[N] -> C[N + 1]] }" },
7947 { &isl_union_map_intersect_range_factor_domain
,
7948 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
7949 "[N] -> { A[i] -> B[N] }",
7950 "[N] -> { A[N - 1] -> T[B[N] -> C[N + 1]] }" },
7951 { &isl_union_map_intersect_range_factor_domain
,
7952 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7953 "[N] -> { A[i] -> C[N] }",
7955 { &isl_union_map_intersect_range_factor_range
,
7956 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7957 "[N] -> { A[i] -> C[N] }",
7958 "[N] -> { A[N - 2] -> [B[N - 1] -> C[N]] }" },
7959 { &isl_union_map_intersect_range_factor_range
,
7960 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
7961 "[N] -> { A[i] -> C[N] }",
7962 "[N] -> { A[N - 2] -> T[B[N - 1] -> C[N]] }" },
7963 { &isl_union_map_intersect_range_factor_range
,
7964 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7965 "[N] -> { A[i] -> B[N] }",
7969 /* Perform basic tests of binary operations on isl_union_map.
7971 static isl_stat
test_bin_union_map(isl_ctx
*ctx
)
7975 for (i
= 0; i
< ARRAY_SIZE(umap_bin_tests
); ++i
) {
7977 isl_union_map
*umap1
, *umap2
, *res
;
7980 str
= umap_bin_tests
[i
].arg1
;
7981 umap1
= isl_union_map_read_from_str(ctx
, str
);
7982 str
= umap_bin_tests
[i
].arg2
;
7983 umap2
= isl_union_map_read_from_str(ctx
, str
);
7984 str
= umap_bin_tests
[i
].res
;
7985 res
= isl_union_map_read_from_str(ctx
, str
);
7986 umap1
= umap_bin_tests
[i
].fn(umap1
, umap2
);
7987 equal
= isl_union_map_is_equal(umap1
, res
);
7988 isl_union_map_free(umap1
);
7989 isl_union_map_free(res
);
7991 return isl_stat_error
;
7993 isl_die(ctx
, isl_error_unknown
,
7994 "unexpected result", return isl_stat_error
);
8000 /* Perform basic tests of operations on isl_union_map.
8002 static int test_union_map(isl_ctx
*ctx
)
8004 if (test_un_union_map(ctx
) < 0)
8006 if (test_bin_union_map(ctx
) < 0)
8011 int test_union_pw(isl_ctx
*ctx
)
8015 isl_union_set
*uset
;
8016 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
8018 str
= "{ [x] -> x^2 }";
8019 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8020 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
8021 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
8022 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
8023 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
8024 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
8025 isl_union_pw_qpolynomial_free(upwqp1
);
8026 isl_union_pw_qpolynomial_free(upwqp2
);
8030 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
8035 /* Inputs for basic tests of functions that select
8036 * subparts of the domain of an isl_multi_union_pw_aff.
8037 * "fn" is the function that is tested.
8038 * "arg" is a string description of the input.
8039 * "res" is a string description of the expected result.
8042 __isl_give isl_union_set
*(*fn
)(
8043 __isl_take isl_multi_union_pw_aff
*mupa
);
8046 } un_locus_tests
[] = {
8047 { &isl_multi_union_pw_aff_zero_union_set
,
8048 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8049 "{ A[0,j]; B[0,j] }" },
8050 { &isl_multi_union_pw_aff_zero_union_set
,
8051 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
8052 "{ A[i,i]; B[i,i] : i >= 0 }" },
8053 { &isl_multi_union_pw_aff_zero_union_set
,
8054 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
8055 "{ A[i,j]; B[i,i] : i >= 0 }" },
8058 /* Perform some basic tests of functions that select
8059 * subparts of the domain of an isl_multi_union_pw_aff.
8061 static int test_un_locus(isl_ctx
*ctx
)
8065 isl_union_set
*uset
, *res
;
8066 isl_multi_union_pw_aff
*mupa
;
8068 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
8069 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
8070 un_locus_tests
[i
].arg
);
8071 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
8072 uset
= un_locus_tests
[i
].fn(mupa
);
8073 ok
= isl_union_set_is_equal(uset
, res
);
8074 isl_union_set_free(uset
);
8075 isl_union_set_free(res
);
8079 isl_die(ctx
, isl_error_unknown
,
8080 "unexpected result", return -1);
8086 /* Inputs for basic tests of functions that select
8087 * subparts of an isl_union_map based on a relation
8088 * specified by an isl_multi_union_pw_aff.
8089 * "fn" is the function that is tested.
8090 * "arg1" and "arg2" are string descriptions of the inputs.
8091 * "res" is a string description of the expected result.
8094 __isl_give isl_union_map
*(*fn
)(
8095 __isl_take isl_union_map
*umap
,
8096 __isl_take isl_multi_union_pw_aff
*mupa
);
8100 } bin_locus_tests
[] = {
8101 { &isl_union_map_eq_at_multi_union_pw_aff
,
8102 "{ A[i,j] -> B[i',j'] }",
8103 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8104 "{ A[i,j] -> B[i,j'] }" },
8105 { &isl_union_map_eq_at_multi_union_pw_aff
,
8106 "{ A[i,j] -> B[i',j'] }",
8107 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8108 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8109 "{ A[i,j] -> B[i,j] }" },
8110 { &isl_union_map_eq_at_multi_union_pw_aff
,
8111 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8112 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8113 "{ A[i,j] -> B[i,j'] }" },
8114 { &isl_union_map_eq_at_multi_union_pw_aff
,
8115 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8116 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
8117 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
8118 { &isl_union_map_eq_at_multi_union_pw_aff
,
8119 "{ A[i,j] -> B[i',j'] }",
8120 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
8121 "{ A[i,j] -> B[i,j'] : i > j }" },
8122 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
8123 "{ A[i,j] -> B[i',j'] }",
8124 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8125 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8126 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
8127 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
8128 "{ A[i,j] -> B[i',j'] }",
8129 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8130 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8131 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
8132 { &isl_union_map_eq_at_multi_union_pw_aff
,
8133 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8134 "(F[] : { A[i,j]; B[i,j] })",
8135 "{ A[i,j] -> B[i',j'] }" },
8136 { &isl_union_map_eq_at_multi_union_pw_aff
,
8137 "{ A[i,j] -> B[i',j'] }",
8138 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8139 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
8140 { &isl_union_map_eq_at_multi_union_pw_aff
,
8141 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
8142 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8143 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
8144 { &isl_union_map_eq_at_multi_union_pw_aff
,
8145 "{ A[i,j] -> B[i',j'] }",
8146 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
8147 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
8148 { &isl_union_map_eq_at_multi_union_pw_aff
,
8149 "{ A[i,j] -> B[i',j'] }",
8150 "[N] -> (F[] : { : N >= 0 })",
8151 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
8154 /* Perform some basic tests of functions that select
8155 * subparts of an isl_union_map based on a relation
8156 * specified by an isl_multi_union_pw_aff.
8158 static int test_bin_locus(isl_ctx
*ctx
)
8162 isl_union_map
*umap
, *res
;
8163 isl_multi_union_pw_aff
*mupa
;
8165 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
8166 umap
= isl_union_map_read_from_str(ctx
,
8167 bin_locus_tests
[i
].arg1
);
8168 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
8169 bin_locus_tests
[i
].arg2
);
8170 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
8171 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
8172 ok
= isl_union_map_is_equal(umap
, res
);
8173 isl_union_map_free(umap
);
8174 isl_union_map_free(res
);
8178 isl_die(ctx
, isl_error_unknown
,
8179 "unexpected result", return -1);
8185 /* Inputs for basic tests of functions that determine
8186 * the part of the domain where two isl_multi_aff objects
8187 * related to each other in a specific way.
8188 * "fn" is the function that is being tested.
8189 * "arg1" and "arg2" are string descriptions of the inputs.
8190 * "res" is a string description of the expected result.
8193 __isl_give isl_set
*(*fn
)(__isl_take isl_multi_aff
*ma1
,
8194 __isl_take isl_multi_aff
*ma2
);
8198 } bin_locus_ma_tests
[] = {
8199 { &isl_multi_aff_lex_le_set
, "{ [] }", "{ [] }", "{ : }" },
8200 { &isl_multi_aff_lex_lt_set
, "{ [] }", "{ [] }", "{ : false }" },
8201 { &isl_multi_aff_lex_le_set
,
8202 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8203 "{ A[i] : i <= 0 }" },
8204 { &isl_multi_aff_lex_lt_set
,
8205 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8206 "{ A[i] : i < 0 }" },
8207 { &isl_multi_aff_lex_le_set
,
8208 "{ A[i] -> [i, i] }", "{ A[i] -> [0, 0] }",
8209 "{ A[i] : i <= 0 }" },
8210 { &isl_multi_aff_lex_le_set
,
8211 "{ A[i] -> [i, 0] }", "{ A[i] -> [0, 0] }",
8212 "{ A[i] : i <= 0 }" },
8213 { &isl_multi_aff_lex_le_set
,
8214 "{ A[i] -> [i, 1] }", "{ A[i] -> [0, 0] }",
8215 "{ A[i] : i < 0 }" },
8218 /* Perform some basic tests of functions that determine
8219 * the part of the domain where two isl_multi_aff objects
8220 * related to each other in a specific way.
8222 static isl_stat
test_bin_locus_ma(isl_ctx
*ctx
)
8226 for (i
= 0; i
< ARRAY_SIZE(bin_locus_ma_tests
); ++i
) {
8229 isl_multi_aff
*ma1
, *ma2
;
8232 str
= bin_locus_ma_tests
[i
].arg1
;
8233 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
8234 str
= bin_locus_ma_tests
[i
].arg2
;
8235 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8236 res
= isl_set_read_from_str(ctx
, bin_locus_ma_tests
[i
].res
);
8237 set
= bin_locus_ma_tests
[i
].fn(ma1
, ma2
);
8238 ok
= isl_set_is_equal(set
, res
);
8242 return isl_stat_error
;
8244 isl_die(ctx
, isl_error_unknown
,
8245 "unexpected result", return isl_stat_error
);
8251 /* Perform basic locus tests.
8253 static int test_locus(isl_ctx
*ctx
)
8255 if (test_un_locus(ctx
) < 0)
8257 if (test_bin_locus(ctx
) < 0)
8259 if (test_bin_locus_ma(ctx
) < 0)
8264 /* Test that isl_union_pw_qpolynomial_eval picks up the function
8265 * defined over the correct domain space.
8267 static int test_eval_1(isl_ctx
*ctx
)
8272 isl_union_pw_qpolynomial
*upwqp
;
8276 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
8277 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8279 set
= isl_set_read_from_str(ctx
, str
);
8280 pnt
= isl_set_sample_point(set
);
8281 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
8282 cmp
= isl_val_cmp_si(v
, 36);
8288 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
8293 /* Check that isl_qpolynomial_eval handles getting called on a void point.
8295 static int test_eval_2(isl_ctx
*ctx
)
8300 isl_qpolynomial
*qp
;
8304 str
= "{ A[x] -> [x] }";
8305 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
8306 str
= "{ A[x] : false }";
8307 set
= isl_set_read_from_str(ctx
, str
);
8308 pnt
= isl_set_sample_point(set
);
8309 v
= isl_qpolynomial_eval(qp
, pnt
);
8310 ok
= isl_val_is_nan(v
);
8316 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
8321 /* Check that a polynomial (without local variables) can be evaluated
8322 * in a rational point.
8324 static isl_stat
test_eval_3(isl_ctx
*ctx
)
8326 isl_pw_qpolynomial
*pwqp
;
8331 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, "{ [x] -> x^2 }");
8332 pnt
= isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp
));
8333 v
= isl_val_read_from_str(ctx
, "1/2");
8334 pnt
= isl_point_set_coordinate_val(pnt
, isl_dim_set
, 0, v
);
8335 v
= isl_pw_qpolynomial_eval(pwqp
, pnt
);
8336 r
= val_check_equal(v
, "1/4");
8342 /* Inputs for isl_pw_aff_eval test.
8343 * "f" is the affine function.
8344 * "p" is the point where the function should be evaluated.
8345 * "res" is the expected result.
8351 } aff_eval_tests
[] = {
8352 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
8353 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
8354 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
8355 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
8356 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
8357 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
8358 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
8359 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
8360 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
8361 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
8362 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
8363 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
8364 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
8365 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
8366 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
8367 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
8368 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
8369 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
8370 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
8371 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
8372 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
8373 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
8374 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
8377 /* Perform basic isl_pw_aff_eval tests.
8379 static int test_eval_aff(isl_ctx
*ctx
)
8383 for (i
= 0; i
< ARRAY_SIZE(aff_eval_tests
); ++i
) {
8390 pa
= isl_pw_aff_read_from_str(ctx
, aff_eval_tests
[i
].f
);
8391 set
= isl_set_read_from_str(ctx
, aff_eval_tests
[i
].p
);
8392 pnt
= isl_set_sample_point(set
);
8393 v
= isl_pw_aff_eval(pa
, pnt
);
8394 r
= val_check_equal(v
, aff_eval_tests
[i
].res
);
8402 /* Perform basic evaluation tests.
8404 static int test_eval(isl_ctx
*ctx
)
8406 if (test_eval_1(ctx
) < 0)
8408 if (test_eval_2(ctx
) < 0)
8410 if (test_eval_3(ctx
) < 0)
8412 if (test_eval_aff(ctx
) < 0)
8417 /* Descriptions of sets that are tested for reparsing after printing.
8419 const char *output_tests
[] = {
8420 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
8423 "{ [x] : x mod 2 = 0 }",
8424 "{ [x] : x mod 2 = 1 }",
8425 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
8426 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
8427 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8428 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8429 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
8430 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
8433 /* Check that printing a set and reparsing a set from the printed output
8434 * results in the same set.
8436 static int test_output_set(isl_ctx
*ctx
)
8440 isl_set
*set1
, *set2
;
8443 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
8444 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
8445 str
= isl_set_to_str(set1
);
8446 set2
= isl_set_read_from_str(ctx
, str
);
8448 equal
= isl_set_is_equal(set1
, set2
);
8454 isl_die(ctx
, isl_error_unknown
,
8455 "parsed output not the same", return -1);
8461 /* Check that an isl_multi_aff is printed using a consistent space.
8463 static isl_stat
test_output_ma(isl_ctx
*ctx
)
8468 isl_multi_aff
*ma
, *ma2
;
8470 ma
= isl_multi_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8471 aff
= isl_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8472 ma
= isl_multi_aff_set_aff(ma
, 0, aff
);
8473 str
= isl_multi_aff_to_str(ma
);
8474 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8476 equal
= isl_multi_aff_plain_is_equal(ma
, ma2
);
8477 isl_multi_aff_free(ma2
);
8478 isl_multi_aff_free(ma
);
8481 return isl_stat_error
;
8483 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8484 return isl_stat_error
);
8489 /* Check that an isl_multi_pw_aff is printed using a consistent space.
8491 static isl_stat
test_output_mpa(isl_ctx
*ctx
)
8496 isl_multi_pw_aff
*mpa
, *mpa2
;
8498 mpa
= isl_multi_pw_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8499 pa
= isl_pw_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8500 mpa
= isl_multi_pw_aff_set_pw_aff(mpa
, 0, pa
);
8501 str
= isl_multi_pw_aff_to_str(mpa
);
8502 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8504 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
8505 isl_multi_pw_aff_free(mpa2
);
8506 isl_multi_pw_aff_free(mpa
);
8509 return isl_stat_error
;
8511 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8512 return isl_stat_error
);
8517 int test_output(isl_ctx
*ctx
)
8525 if (test_output_set(ctx
) < 0)
8527 if (test_output_ma(ctx
) < 0)
8529 if (test_output_mpa(ctx
) < 0)
8532 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
8533 pa
= isl_pw_aff_read_from_str(ctx
, str
);
8535 p
= isl_printer_to_str(ctx
);
8536 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
8537 p
= isl_printer_print_pw_aff(p
, pa
);
8538 s
= isl_printer_get_str(p
);
8539 isl_printer_free(p
);
8540 isl_pw_aff_free(pa
);
8544 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
8549 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
8554 int test_sample(isl_ctx
*ctx
)
8557 isl_basic_set
*bset1
, *bset2
;
8560 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
8561 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
8562 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
8563 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
8564 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
8565 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
8566 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
8567 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
8568 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
8569 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
8570 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
8571 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
8572 "d - 1073741821e and "
8573 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
8574 "3j >= 1 - a + b + 2e and "
8575 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
8576 "3i <= 4 - a + 4b - e and "
8577 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
8578 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
8579 "c <= -1 + a and 3i >= -2 - a + 3e and "
8580 "1073741822e <= 1073741823 - a + 1073741822b + c and "
8581 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
8582 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
8583 "1073741823e >= 1 + 1073741823b - d and "
8584 "3i >= 1073741823b + c - 1073741823e - f and "
8585 "3i >= 1 + 2b + e + 3g }";
8586 bset1
= isl_basic_set_read_from_str(ctx
, str
);
8587 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
8588 empty
= isl_basic_set_is_empty(bset2
);
8589 subset
= isl_basic_set_is_subset(bset2
, bset1
);
8590 isl_basic_set_free(bset1
);
8591 isl_basic_set_free(bset2
);
8592 if (empty
< 0 || subset
< 0)
8595 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
8597 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
8602 int test_fixed_power(isl_ctx
*ctx
)
8609 str
= "{ [i] -> [i + 1] }";
8610 map
= isl_map_read_from_str(ctx
, str
);
8611 exp
= isl_val_int_from_si(ctx
, 23);
8612 map
= isl_map_fixed_power_val(map
, exp
);
8613 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
8621 int test_slice(isl_ctx
*ctx
)
8627 str
= "{ [i] -> [j] }";
8628 map
= isl_map_read_from_str(ctx
, str
);
8629 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8630 equal
= map_check_equal(map
, "{ [i] -> [i] }");
8635 str
= "{ [i] -> [j] }";
8636 map
= isl_map_read_from_str(ctx
, str
);
8637 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8638 equal
= map_check_equal(map
, "{ [i] -> [j] }");
8643 str
= "{ [i] -> [j] }";
8644 map
= isl_map_read_from_str(ctx
, str
);
8645 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8646 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
8651 str
= "{ [i] -> [j] }";
8652 map
= isl_map_read_from_str(ctx
, str
);
8653 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8654 equal
= map_check_equal(map
, "{ [0] -> [j] }");
8659 str
= "{ [i] -> [j] }";
8660 map
= isl_map_read_from_str(ctx
, str
);
8661 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8662 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
8667 str
= "{ [i] -> [j] }";
8668 map
= isl_map_read_from_str(ctx
, str
);
8669 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8670 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
8678 int test_eliminate(isl_ctx
*ctx
)
8684 str
= "{ [i] -> [j] : i = 2j }";
8685 map
= isl_map_read_from_str(ctx
, str
);
8686 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
8687 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
8695 /* Check basic functionality of isl_map_deltas_map.
8697 static int test_deltas_map(isl_ctx
*ctx
)
8703 str
= "{ A[i] -> A[i + 1] }";
8704 map
= isl_map_read_from_str(ctx
, str
);
8705 map
= isl_map_deltas_map(map
);
8706 equal
= map_check_equal(map
, "{ [A[i] -> A[i + 1]] -> A[1] }");
8714 /* Check that isl_set_dim_residue_class detects that the values of j
8715 * in the set below are all odd and that it does not detect any spurious
8718 static int test_residue_class(isl_ctx
*ctx
)
8725 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
8726 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
8727 set
= isl_set_read_from_str(ctx
, str
);
8730 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
8732 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
8733 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
8734 res
= isl_stat_error
);
8742 static int test_align_parameters_1(isl_ctx
*ctx
)
8746 isl_multi_aff
*ma1
, *ma2
;
8749 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
8750 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
8752 space
= isl_space_params_alloc(ctx
, 1);
8753 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
8754 ma1
= isl_multi_aff_align_params(ma1
, space
);
8756 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
8757 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8759 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
8761 isl_multi_aff_free(ma1
);
8762 isl_multi_aff_free(ma2
);
8767 isl_die(ctx
, isl_error_unknown
,
8768 "result not as expected", return -1);
8773 /* Check the isl_multi_*_from_*_list operation in case inputs
8774 * have unaligned parameters.
8775 * In particular, older versions of isl would simply fail
8776 * (without printing any error message).
8778 static isl_stat
test_align_parameters_2(isl_ctx
*ctx
)
8785 map
= isl_map_read_from_str(ctx
, "{ A[] -> M[x] }");
8786 space
= isl_map_get_space(map
);
8789 aff
= isl_aff_read_from_str(ctx
, "[N] -> { A[] -> [N] }");
8790 ma
= isl_multi_aff_from_aff_list(space
, isl_aff_list_from_aff(aff
));
8791 isl_multi_aff_free(ma
);
8794 return isl_stat_error
;
8798 /* Perform basic parameter alignment tests.
8800 static int test_align_parameters(isl_ctx
*ctx
)
8802 if (test_align_parameters_1(ctx
) < 0)
8804 if (test_align_parameters_2(ctx
) < 0)
8810 /* Check that isl_*_drop_unused_params actually drops the unused parameters
8811 * by comparing the result using isl_*_plain_is_equal.
8812 * Note that this assumes that isl_*_plain_is_equal does not consider
8813 * objects that only differ by unused parameters to be equal.
8815 int test_drop_unused_parameters(isl_ctx
*ctx
)
8817 const char *str_with
, *str_without
;
8818 isl_basic_set
*bset1
, *bset2
;
8819 isl_set
*set1
, *set2
;
8820 isl_pw_aff
*pwa1
, *pwa2
;
8823 str_with
= "[n, m, o] -> { [m] }";
8824 str_without
= "[m] -> { [m] }";
8826 bset1
= isl_basic_set_read_from_str(ctx
, str_with
);
8827 bset2
= isl_basic_set_read_from_str(ctx
, str_without
);
8828 bset1
= isl_basic_set_drop_unused_params(bset1
);
8829 equal
= isl_basic_set_plain_is_equal(bset1
, bset2
);
8830 isl_basic_set_free(bset1
);
8831 isl_basic_set_free(bset2
);
8836 isl_die(ctx
, isl_error_unknown
,
8837 "result not as expected", return -1);
8839 set1
= isl_set_read_from_str(ctx
, str_with
);
8840 set2
= isl_set_read_from_str(ctx
, str_without
);
8841 set1
= isl_set_drop_unused_params(set1
);
8842 equal
= isl_set_plain_is_equal(set1
, set2
);
8849 isl_die(ctx
, isl_error_unknown
,
8850 "result not as expected", return -1);
8852 pwa1
= isl_pw_aff_read_from_str(ctx
, str_with
);
8853 pwa2
= isl_pw_aff_read_from_str(ctx
, str_without
);
8854 pwa1
= isl_pw_aff_drop_unused_params(pwa1
);
8855 equal
= isl_pw_aff_plain_is_equal(pwa1
, pwa2
);
8856 isl_pw_aff_free(pwa1
);
8857 isl_pw_aff_free(pwa2
);
8862 isl_die(ctx
, isl_error_unknown
,
8863 "result not as expected", return -1);
8868 static int test_list(isl_ctx
*ctx
)
8870 isl_id
*a
, *b
, *c
, *d
, *id
;
8875 a
= isl_id_alloc(ctx
, "a", NULL
);
8876 b
= isl_id_alloc(ctx
, "b", NULL
);
8877 c
= isl_id_alloc(ctx
, "c", NULL
);
8878 d
= isl_id_alloc(ctx
, "d", NULL
);
8880 list
= isl_id_list_alloc(ctx
, 4);
8881 list
= isl_id_list_add(list
, b
);
8882 list
= isl_id_list_insert(list
, 0, a
);
8883 list
= isl_id_list_add(list
, c
);
8884 list
= isl_id_list_add(list
, d
);
8885 list
= isl_id_list_drop(list
, 1, 1);
8887 n
= isl_id_list_n_id(list
);
8891 isl_id_list_free(list
);
8892 isl_die(ctx
, isl_error_unknown
,
8893 "unexpected number of elements in list", return -1);
8896 id
= isl_id_list_get_id(list
, 0);
8899 id
= isl_id_list_get_id(list
, 1);
8902 id
= isl_id_list_get_id(list
, 2);
8906 isl_id_list_free(list
);
8909 isl_die(ctx
, isl_error_unknown
,
8910 "unexpected elements in list", return -1);
8915 /* Check the conversion from an isl_multi_aff to an isl_basic_set.
8917 static isl_stat
test_ma_conversion(isl_ctx
*ctx
)
8922 isl_basic_set
*bset1
, *bset2
;
8924 str
= "[N] -> { A[0, N + 1] }";
8925 ma
= isl_multi_aff_read_from_str(ctx
, str
);
8926 bset1
= isl_basic_set_read_from_str(ctx
, str
);
8927 bset2
= isl_basic_set_from_multi_aff(ma
);
8928 equal
= isl_basic_set_is_equal(bset1
, bset2
);
8929 isl_basic_set_free(bset1
);
8930 isl_basic_set_free(bset2
);
8932 return isl_stat_error
;
8934 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8935 return isl_stat_error
);
8939 const char *set_conversion_tests
[] = {
8940 "[N] -> { [i] : N - 1 <= 2 i <= N }",
8941 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
8942 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
8943 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
8944 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
8945 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
8946 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
8947 "-3 + c <= d <= 28 + c) }",
8950 /* Check that converting from isl_set to isl_pw_multi_aff and back
8951 * to isl_set produces the original isl_set.
8953 static int test_set_conversion(isl_ctx
*ctx
)
8957 isl_set
*set1
, *set2
;
8958 isl_pw_multi_aff
*pma
;
8961 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
8962 str
= set_conversion_tests
[i
];
8963 set1
= isl_set_read_from_str(ctx
, str
);
8964 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
8965 set2
= isl_set_from_pw_multi_aff(pma
);
8966 equal
= isl_set_is_equal(set1
, set2
);
8973 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8980 const char *conversion_tests
[] = {
8981 "{ [a, b, c, d] -> s0[a, b, e, f] : "
8982 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
8983 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
8984 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
8986 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
8987 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
8988 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
8991 /* Check that converting from isl_map to isl_pw_multi_aff and back
8992 * to isl_map produces the original isl_map.
8994 static int test_map_conversion(isl_ctx
*ctx
)
8997 isl_map
*map1
, *map2
;
8998 isl_pw_multi_aff
*pma
;
9001 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
9002 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
9003 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
9004 map2
= isl_map_from_pw_multi_aff(pma
);
9005 equal
= isl_map_is_equal(map1
, map2
);
9012 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9019 /* Descriptions of isl_pw_multi_aff objects for testing conversion
9020 * to isl_multi_pw_aff and back.
9022 const char *mpa_conversion_tests
[] = {
9024 "{ [x] -> A[x] : x >= 0 }",
9025 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
9026 "{ [x] -> A[x, x + 1] }",
9028 "{ [x] -> A[] : x >= 0 }",
9031 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
9032 * back to isl_pw_multi_aff preserves the original meaning.
9034 static int test_mpa_conversion(isl_ctx
*ctx
)
9037 isl_pw_multi_aff
*pma1
, *pma2
;
9038 isl_multi_pw_aff
*mpa
;
9041 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
9043 str
= mpa_conversion_tests
[i
];
9044 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9045 pma2
= isl_pw_multi_aff_copy(pma1
);
9046 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
9047 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
9048 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
9049 isl_pw_multi_aff_free(pma1
);
9050 isl_pw_multi_aff_free(pma2
);
9055 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9062 /* Descriptions of union maps that should be convertible
9063 * to an isl_multi_union_pw_aff.
9065 const char *umap_mupa_conversion_tests
[] = {
9066 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9067 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9068 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9069 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9071 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9072 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9073 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9074 "{ A[] -> B[0]; C[] -> B[1] }",
9075 "{ A[] -> B[]; C[] -> B[] }",
9078 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
9079 * to isl_union_map produces the original isl_union_map.
9081 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
9084 isl_union_map
*umap1
, *umap2
;
9085 isl_multi_union_pw_aff
*mupa
;
9088 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
9090 str
= umap_mupa_conversion_tests
[i
];
9091 umap1
= isl_union_map_read_from_str(ctx
, str
);
9092 umap2
= isl_union_map_copy(umap1
);
9093 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
9094 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
9095 equal
= isl_union_map_is_equal(umap1
, umap2
);
9096 isl_union_map_free(umap1
);
9097 isl_union_map_free(umap2
);
9102 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9109 static int test_conversion(isl_ctx
*ctx
)
9111 if (test_ma_conversion(ctx
) < 0)
9113 if (test_set_conversion(ctx
) < 0)
9115 if (test_map_conversion(ctx
) < 0)
9117 if (test_mpa_conversion(ctx
) < 0)
9119 if (test_union_map_mupa_conversion(ctx
) < 0)
9124 /* Check that isl_basic_map_curry does not modify input.
9126 static int test_curry(isl_ctx
*ctx
)
9129 isl_basic_map
*bmap1
, *bmap2
;
9132 str
= "{ [A[] -> B[]] -> C[] }";
9133 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
9134 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
9135 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
9136 isl_basic_map_free(bmap1
);
9137 isl_basic_map_free(bmap2
);
9142 isl_die(ctx
, isl_error_unknown
,
9143 "curried map should not be equal to original",
9153 } preimage_tests
[] = {
9154 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
9155 "{ A[j,i] -> B[i,j] }",
9156 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
9157 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
9158 "{ A[a,b] -> B[a/2,b/6] }",
9159 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
9160 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
9161 "{ A[a,b] -> B[a/2,b/6] }",
9162 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
9163 "exists i,j : a = 2 i and b = 6 j }" },
9164 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
9165 "[n] -> { : 0 <= n <= 100 }" },
9166 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
9167 "{ A[a] -> B[2a] }",
9168 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
9169 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
9170 "{ A[a] -> B[([a/2])] }",
9171 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
9172 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
9173 "{ A[a] -> B[a,a,a/3] }",
9174 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
9175 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
9176 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
9179 static int test_preimage_basic_set(isl_ctx
*ctx
)
9182 isl_basic_set
*bset1
, *bset2
;
9186 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
9187 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
9188 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
9189 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
9190 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
9191 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9192 isl_basic_set_free(bset1
);
9193 isl_basic_set_free(bset2
);
9197 isl_die(ctx
, isl_error_unknown
, "bad preimage",
9208 } preimage_domain_tests
[] = {
9209 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
9210 "{ A[j,i] -> B[i,j] }",
9211 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
9212 { "{ B[i] -> C[i]; D[i] -> E[i] }",
9213 "{ A[i] -> B[i + 1] }",
9214 "{ A[i] -> C[i + 1] }" },
9215 { "{ B[i] -> C[i]; B[i] -> E[i] }",
9216 "{ A[i] -> B[i + 1] }",
9217 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
9218 { "{ B[i] -> C[([i/2])] }",
9219 "{ A[i] -> B[2i] }",
9220 "{ A[i] -> C[i] }" },
9221 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
9222 "{ A[i] -> B[([i/5]), ([i/7])] }",
9223 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
9224 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
9225 "[N] -> { A[] -> B[([N/5])] }",
9226 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
9227 { "{ B[i] -> C[i] : exists a : i = 5 a }",
9228 "{ A[i] -> B[2i] }",
9229 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
9230 { "{ B[i] -> C[i] : exists a : i = 2 a; "
9231 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
9232 "{ A[i] -> B[2i] }",
9233 "{ A[i] -> C[2i] }" },
9234 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
9235 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
9238 static int test_preimage_union_map(isl_ctx
*ctx
)
9241 isl_union_map
*umap1
, *umap2
;
9245 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
9246 umap1
= isl_union_map_read_from_str(ctx
,
9247 preimage_domain_tests
[i
].map
);
9248 ma
= isl_multi_aff_read_from_str(ctx
,
9249 preimage_domain_tests
[i
].ma
);
9250 umap2
= isl_union_map_read_from_str(ctx
,
9251 preimage_domain_tests
[i
].res
);
9252 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
9253 equal
= isl_union_map_is_equal(umap1
, umap2
);
9254 isl_union_map_free(umap1
);
9255 isl_union_map_free(umap2
);
9259 isl_die(ctx
, isl_error_unknown
, "bad preimage",
9266 static int test_preimage(isl_ctx
*ctx
)
9268 if (test_preimage_basic_set(ctx
) < 0)
9270 if (test_preimage_union_map(ctx
) < 0)
9280 } pullback_tests
[] = {
9281 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
9282 "{ A[a,b] -> C[b + 2a] }" },
9283 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
9284 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
9285 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
9286 "{ A[a] -> C[(a)/6] }" },
9287 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
9288 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
9289 "{ A[a] -> C[(2a)/3] }" },
9290 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
9291 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
9292 "{ A[i,j] -> C[i + j, i + j] }"},
9293 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
9294 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
9295 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
9296 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
9297 "{ [i, j] -> [floor((i)/3), j] }",
9298 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
9301 static int test_pullback(isl_ctx
*ctx
)
9304 isl_multi_aff
*ma1
, *ma2
;
9308 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
9309 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
9310 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
9311 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
9312 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
9313 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
9314 isl_multi_aff_free(ma1
);
9315 isl_multi_aff_free(ma2
);
9319 isl_die(ctx
, isl_error_unknown
, "bad pullback",
9326 /* Check that negation is printed correctly and that equal expressions
9327 * are correctly identified.
9329 static int test_ast(isl_ctx
*ctx
)
9331 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
9335 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
9336 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
9337 expr
= isl_ast_expr_add(expr1
, expr2
);
9338 expr2
= isl_ast_expr_copy(expr
);
9339 expr
= isl_ast_expr_neg(expr
);
9340 expr2
= isl_ast_expr_neg(expr2
);
9341 equal
= isl_ast_expr_is_equal(expr
, expr2
);
9342 str
= isl_ast_expr_to_C_str(expr
);
9343 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
9345 isl_ast_expr_free(expr
);
9346 isl_ast_expr_free(expr2
);
9348 if (ok
< 0 || equal
< 0)
9351 isl_die(ctx
, isl_error_unknown
,
9352 "equal expressions not considered equal", return -1);
9354 isl_die(ctx
, isl_error_unknown
,
9355 "isl_ast_expr printed incorrectly", return -1);
9357 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
9358 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
9359 expr
= isl_ast_expr_add(expr1
, expr2
);
9360 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
9361 expr
= isl_ast_expr_sub(expr3
, expr
);
9362 str
= isl_ast_expr_to_C_str(expr
);
9363 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
9365 isl_ast_expr_free(expr
);
9370 isl_die(ctx
, isl_error_unknown
,
9371 "isl_ast_expr printed incorrectly", return -1);
9376 /* Check that isl_ast_build_expr_from_set returns a valid expression
9377 * for an empty set. Note that isl_ast_build_expr_from_set getting
9378 * called on an empty set probably indicates a bug in the caller.
9380 static int test_ast_build(isl_ctx
*ctx
)
9383 isl_ast_build
*build
;
9386 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9387 build
= isl_ast_build_from_context(set
);
9389 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
9390 expr
= isl_ast_build_expr_from_set(build
, set
);
9392 isl_ast_expr_free(expr
);
9393 isl_ast_build_free(build
);
9401 /* Internal data structure for before_for and after_for callbacks.
9403 * depth is the current depth
9404 * before is the number of times before_for has been called
9405 * after is the number of times after_for has been called
9407 struct isl_test_codegen_data
{
9413 /* This function is called before each for loop in the AST generated
9414 * from test_ast_gen1.
9416 * Increment the number of calls and the depth.
9417 * Check that the space returned by isl_ast_build_get_schedule_space
9418 * matches the target space of the schedule returned by
9419 * isl_ast_build_get_schedule.
9420 * Return an isl_id that is checked by the corresponding call
9423 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
9426 struct isl_test_codegen_data
*data
= user
;
9429 isl_union_map
*schedule
;
9430 isl_union_set
*uset
;
9436 ctx
= isl_ast_build_get_ctx(build
);
9438 if (data
->before
>= 3)
9439 isl_die(ctx
, isl_error_unknown
,
9440 "unexpected number of for nodes", return NULL
);
9441 if (data
->depth
>= 2)
9442 isl_die(ctx
, isl_error_unknown
,
9443 "unexpected depth", return NULL
);
9445 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
9449 schedule
= isl_ast_build_get_schedule(build
);
9450 uset
= isl_union_map_range(schedule
);
9451 n
= isl_union_set_n_set(uset
);
9453 isl_union_set_free(uset
);
9456 isl_die(ctx
, isl_error_unknown
,
9457 "expecting single range space", return NULL
);
9460 space
= isl_ast_build_get_schedule_space(build
);
9461 set
= isl_union_set_extract_set(uset
, space
);
9462 isl_union_set_free(uset
);
9463 empty
= isl_set_is_empty(set
);
9469 isl_die(ctx
, isl_error_unknown
,
9470 "spaces don't match", return NULL
);
9472 return isl_id_alloc(ctx
, name
, NULL
);
9475 /* This function is called after each for loop in the AST generated
9476 * from test_ast_gen1.
9478 * Increment the number of calls and decrement the depth.
9479 * Check that the annotation attached to the node matches
9480 * the isl_id returned by the corresponding call to before_for.
9482 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
9483 __isl_keep isl_ast_build
*build
, void *user
)
9485 struct isl_test_codegen_data
*data
= user
;
9493 if (data
->after
> data
->before
)
9494 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9495 "mismatch in number of for nodes",
9496 return isl_ast_node_free(node
));
9498 id
= isl_ast_node_get_annotation(node
);
9500 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9501 "missing annotation", return isl_ast_node_free(node
));
9503 name
= isl_id_get_name(id
);
9504 valid
= name
&& atoi(name
+ 1) == data
->depth
;
9508 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9509 "wrong annotation", return isl_ast_node_free(node
));
9514 /* Check that the before_each_for and after_each_for callbacks
9515 * are called for each for loop in the generated code,
9516 * that they are called in the right order and that the isl_id
9517 * returned from the before_each_for callback is attached to
9518 * the isl_ast_node passed to the corresponding after_each_for call.
9520 static int test_ast_gen1(isl_ctx
*ctx
)
9524 isl_union_map
*schedule
;
9525 isl_ast_build
*build
;
9527 struct isl_test_codegen_data data
;
9529 str
= "[N] -> { : N >= 10 }";
9530 set
= isl_set_read_from_str(ctx
, str
);
9531 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
9532 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
9533 schedule
= isl_union_map_read_from_str(ctx
, str
);
9538 build
= isl_ast_build_from_context(set
);
9539 build
= isl_ast_build_set_before_each_for(build
,
9540 &before_for
, &data
);
9541 build
= isl_ast_build_set_after_each_for(build
,
9543 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9544 isl_ast_build_free(build
);
9548 isl_ast_node_free(tree
);
9550 if (data
.before
!= 3 || data
.after
!= 3)
9551 isl_die(ctx
, isl_error_unknown
,
9552 "unexpected number of for nodes", return -1);
9557 /* Check that the AST generator handles domains that are integrally disjoint
9558 * but not rationally disjoint.
9560 static int test_ast_gen2(isl_ctx
*ctx
)
9564 isl_union_map
*schedule
;
9565 isl_union_map
*options
;
9566 isl_ast_build
*build
;
9569 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
9570 schedule
= isl_union_map_read_from_str(ctx
, str
);
9571 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9572 build
= isl_ast_build_from_context(set
);
9574 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
9575 options
= isl_union_map_read_from_str(ctx
, str
);
9576 build
= isl_ast_build_set_options(build
, options
);
9577 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9578 isl_ast_build_free(build
);
9581 isl_ast_node_free(tree
);
9586 /* Increment *user on each call.
9588 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
9589 __isl_keep isl_ast_build
*build
, void *user
)
9598 /* Test that unrolling tries to minimize the number of instances.
9599 * In particular, for the schedule given below, make sure it generates
9600 * 3 nodes (rather than 101).
9602 static int test_ast_gen3(isl_ctx
*ctx
)
9606 isl_union_map
*schedule
;
9607 isl_union_map
*options
;
9608 isl_ast_build
*build
;
9612 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
9613 schedule
= isl_union_map_read_from_str(ctx
, str
);
9614 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9616 str
= "{ [i] -> unroll[0] }";
9617 options
= isl_union_map_read_from_str(ctx
, str
);
9619 build
= isl_ast_build_from_context(set
);
9620 build
= isl_ast_build_set_options(build
, options
);
9621 build
= isl_ast_build_set_at_each_domain(build
,
9622 &count_domains
, &n_domain
);
9623 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9624 isl_ast_build_free(build
);
9628 isl_ast_node_free(tree
);
9631 isl_die(ctx
, isl_error_unknown
,
9632 "unexpected number of for nodes", return -1);
9637 /* Check that if the ast_build_exploit_nested_bounds options is set,
9638 * we do not get an outer if node in the generated AST,
9639 * while we do get such an outer if node if the options is not set.
9641 static int test_ast_gen4(isl_ctx
*ctx
)
9645 isl_union_map
*schedule
;
9646 isl_ast_build
*build
;
9648 enum isl_ast_node_type type
;
9651 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
9652 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
9654 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
9656 schedule
= isl_union_map_read_from_str(ctx
, str
);
9657 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9658 build
= isl_ast_build_from_context(set
);
9659 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9660 isl_ast_build_free(build
);
9664 type
= isl_ast_node_get_type(tree
);
9665 isl_ast_node_free(tree
);
9667 if (type
== isl_ast_node_if
)
9668 isl_die(ctx
, isl_error_unknown
,
9669 "not expecting if node", return -1);
9671 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
9673 schedule
= isl_union_map_read_from_str(ctx
, str
);
9674 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9675 build
= isl_ast_build_from_context(set
);
9676 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9677 isl_ast_build_free(build
);
9681 type
= isl_ast_node_get_type(tree
);
9682 isl_ast_node_free(tree
);
9684 if (type
!= isl_ast_node_if
)
9685 isl_die(ctx
, isl_error_unknown
,
9686 "expecting if node", return -1);
9688 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
9693 /* This function is called for each leaf in the AST generated
9694 * from test_ast_gen5.
9696 * We finalize the AST generation by extending the outer schedule
9697 * with a zero-dimensional schedule. If this results in any for loops,
9698 * then this means that we did not pass along enough information
9699 * about the outer schedule to the inner AST generation.
9701 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
9704 isl_union_map
*schedule
, *extra
;
9707 schedule
= isl_ast_build_get_schedule(build
);
9708 extra
= isl_union_map_copy(schedule
);
9709 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
9710 schedule
= isl_union_map_range_product(schedule
, extra
);
9711 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9712 isl_ast_build_free(build
);
9717 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
9718 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
9719 "code should not contain any for loop",
9720 return isl_ast_node_free(tree
));
9725 /* Check that we do not lose any information when going back and
9726 * forth between internal and external schedule.
9728 * In particular, we create an AST where we unroll the only
9729 * non-constant dimension in the schedule. We therefore do
9730 * not expect any for loops in the AST. However, older versions
9731 * of isl would not pass along enough information about the outer
9732 * schedule when performing an inner code generation from a create_leaf
9733 * callback, resulting in the inner code generation producing a for loop.
9735 static int test_ast_gen5(isl_ctx
*ctx
)
9739 isl_union_map
*schedule
, *options
;
9740 isl_ast_build
*build
;
9743 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
9744 schedule
= isl_union_map_read_from_str(ctx
, str
);
9746 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
9747 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
9748 options
= isl_union_map_read_from_str(ctx
, str
);
9750 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9751 build
= isl_ast_build_from_context(set
);
9752 build
= isl_ast_build_set_options(build
, options
);
9753 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
9754 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9755 isl_ast_build_free(build
);
9756 isl_ast_node_free(tree
);
9763 /* Check that the expression
9765 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
9767 * is not combined into
9771 * as this would result in n/2 being evaluated in parts of
9772 * the definition domain where n is not a multiple of 2.
9774 static int test_ast_expr(isl_ctx
*ctx
)
9778 isl_ast_build
*build
;
9783 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
9784 isl_options_set_ast_build_detect_min_max(ctx
, 1);
9786 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
9787 pa
= isl_pw_aff_read_from_str(ctx
, str
);
9788 build
= isl_ast_build_alloc(ctx
);
9789 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
9790 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
9791 isl_ast_expr_get_op_type(expr
) == isl_ast_expr_op_min
;
9792 isl_ast_build_free(build
);
9793 isl_ast_expr_free(expr
);
9795 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
9800 isl_die(ctx
, isl_error_unknown
,
9801 "expressions should not be combined", return -1);
9806 static int test_ast_gen(isl_ctx
*ctx
)
9808 if (test_ast_gen1(ctx
) < 0)
9810 if (test_ast_gen2(ctx
) < 0)
9812 if (test_ast_gen3(ctx
) < 0)
9814 if (test_ast_gen4(ctx
) < 0)
9816 if (test_ast_gen5(ctx
) < 0)
9818 if (test_ast_expr(ctx
) < 0)
9823 /* Check if dropping output dimensions from an isl_pw_multi_aff
9826 static int test_pw_multi_aff(isl_ctx
*ctx
)
9829 isl_pw_multi_aff
*pma1
, *pma2
;
9832 str
= "{ [i,j] -> [i+j, 4i-j] }";
9833 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9834 str
= "{ [i,j] -> [4i-j] }";
9835 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9837 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
9839 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
9841 isl_pw_multi_aff_free(pma1
);
9842 isl_pw_multi_aff_free(pma2
);
9846 isl_die(ctx
, isl_error_unknown
,
9847 "expressions not equal", return -1);
9852 /* Check that we can properly parse multi piecewise affine expressions
9853 * where the piecewise affine expressions have different domains.
9855 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
9858 isl_set
*dom
, *dom2
;
9859 isl_multi_pw_aff
*mpa1
, *mpa2
;
9864 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
9865 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
9866 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
9867 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
9868 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
9869 str
= "{ [i] -> [(i : i > 0), 2i] }";
9870 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
9872 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
9874 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
9875 dom
= isl_pw_aff_domain(pa
);
9876 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
9877 dom2
= isl_pw_aff_domain(pa
);
9878 equal_domain
= isl_set_is_equal(dom
, dom2
);
9882 isl_multi_pw_aff_free(mpa1
);
9883 isl_multi_pw_aff_free(mpa2
);
9888 isl_die(ctx
, isl_error_unknown
,
9889 "expressions not equal", return -1);
9891 if (equal_domain
< 0)
9894 isl_die(ctx
, isl_error_unknown
,
9895 "domains unexpectedly equal", return -1);
9900 /* Check that the dimensions in the explicit domain
9901 * of a multi piecewise affine expression are properly
9902 * taken into account.
9904 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
9907 isl_bool involves1
, involves2
, involves3
, equal
;
9908 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
9910 str
= "{ A[x,y] -> B[] : x >= y }";
9911 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
9912 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
9913 mpa1
= isl_multi_pw_aff_copy(mpa
);
9915 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
9916 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
9917 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
9918 str
= "{ [a,x,y] -> B[] : x >= y }";
9919 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
9920 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
9921 isl_multi_pw_aff_free(mpa2
);
9923 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
9924 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
9925 if (equal
>= 0 && equal
)
9926 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
9927 isl_multi_pw_aff_free(mpa1
);
9928 isl_multi_pw_aff_free(mpa
);
9930 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
9933 isl_die(ctx
, isl_error_unknown
,
9934 "incorrect result of dimension insertion/removal",
9935 return isl_stat_error
);
9936 if (!involves1
|| involves2
|| !involves3
)
9937 isl_die(ctx
, isl_error_unknown
,
9938 "incorrect characterization of involved dimensions",
9939 return isl_stat_error
);
9944 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
9945 * sets the explicit domain of a zero-dimensional result,
9946 * such that it can be converted to an isl_union_map.
9948 static isl_stat
test_multi_pw_aff_3(isl_ctx
*ctx
)
9953 isl_multi_union_pw_aff
*mupa
;
9954 isl_union_map
*umap
;
9956 dom
= isl_union_set_read_from_str(ctx
, "{ A[]; B[] }");
9957 space
= isl_union_set_get_space(dom
);
9958 mv
= isl_multi_val_zero(isl_space_set_from_params(space
));
9959 mupa
= isl_multi_union_pw_aff_multi_val_on_domain(dom
, mv
);
9960 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
9961 isl_union_map_free(umap
);
9963 return isl_stat_error
;
9968 /* Perform some tests on multi piecewise affine expressions.
9970 static int test_multi_pw_aff(isl_ctx
*ctx
)
9972 if (test_multi_pw_aff_1(ctx
) < 0)
9974 if (test_multi_pw_aff_2(ctx
) < 0)
9976 if (test_multi_pw_aff_3(ctx
) < 0)
9981 /* This is a regression test for a bug where isl_basic_map_simplify
9982 * would end up in an infinite loop. In particular, we construct
9983 * an empty basic set that is not obviously empty.
9984 * isl_basic_set_is_empty marks the basic set as empty.
9985 * After projecting out i3, the variable can be dropped completely,
9986 * but isl_basic_map_simplify refrains from doing so if the basic set
9987 * is empty and would end up in an infinite loop if it didn't test
9988 * explicitly for empty basic maps in the outer loop.
9990 static int test_simplify_1(isl_ctx
*ctx
)
9993 isl_basic_set
*bset
;
9996 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
9997 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
9998 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
10000 bset
= isl_basic_set_read_from_str(ctx
, str
);
10001 empty
= isl_basic_set_is_empty(bset
);
10002 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
10003 isl_basic_set_free(bset
);
10007 isl_die(ctx
, isl_error_unknown
,
10008 "basic set should be empty", return -1);
10013 /* Check that the equality in the set description below
10014 * is simplified away.
10016 static int test_simplify_2(isl_ctx
*ctx
)
10019 isl_basic_set
*bset
;
10022 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
10023 bset
= isl_basic_set_read_from_str(ctx
, str
);
10024 universe
= isl_basic_set_plain_is_universe(bset
);
10025 isl_basic_set_free(bset
);
10030 isl_die(ctx
, isl_error_unknown
,
10031 "equality not simplified away", return -1);
10035 /* Some simplification tests.
10037 static int test_simplify(isl_ctx
*ctx
)
10039 if (test_simplify_1(ctx
) < 0)
10041 if (test_simplify_2(ctx
) < 0)
10046 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
10047 * with gbr context would fail to disable the use of the shifted tableau
10048 * when transferring equalities for the input to the context, resulting
10049 * in invalid sample values.
10051 static int test_partial_lexmin(isl_ctx
*ctx
)
10054 isl_basic_set
*bset
;
10055 isl_basic_map
*bmap
;
10058 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
10059 bmap
= isl_basic_map_read_from_str(ctx
, str
);
10060 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
10061 bset
= isl_basic_set_read_from_str(ctx
, str
);
10062 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
10071 /* Check that the variable compression performed on the existentially
10072 * quantified variables inside isl_basic_set_compute_divs is not confused
10073 * by the implicit equalities among the parameters.
10075 static int test_compute_divs(isl_ctx
*ctx
)
10078 isl_basic_set
*bset
;
10081 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
10082 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
10083 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
10084 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
10085 bset
= isl_basic_set_read_from_str(ctx
, str
);
10086 set
= isl_basic_set_compute_divs(bset
);
10094 /* Check that isl_schedule_get_map is not confused by a schedule tree
10095 * with divergent filter node parameters, as can result from a call
10096 * to isl_schedule_intersect_domain.
10098 static int test_schedule_tree(isl_ctx
*ctx
)
10101 isl_union_set
*uset
;
10102 isl_schedule
*sched1
, *sched2
;
10103 isl_union_map
*umap
;
10105 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
10106 sched1
= isl_schedule_from_domain(uset
);
10107 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
10108 sched2
= isl_schedule_from_domain(uset
);
10110 sched1
= isl_schedule_sequence(sched1
, sched2
);
10111 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
10112 uset
= isl_union_set_read_from_str(ctx
, str
);
10113 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
10114 umap
= isl_schedule_get_map(sched1
);
10115 isl_schedule_free(sched1
);
10116 isl_union_map_free(umap
);
10123 /* Check that a zero-dimensional prefix schedule keeps track
10124 * of the domain and outer filters.
10126 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
10130 isl_union_set
*uset
;
10131 isl_union_set_list
*filters
;
10132 isl_multi_union_pw_aff
*mupa
, *mupa2
;
10133 isl_schedule_node
*node
;
10135 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10136 uset
= isl_union_set_read_from_str(ctx
, str
);
10137 node
= isl_schedule_node_from_domain(uset
);
10138 node
= isl_schedule_node_child(node
, 0);
10140 str
= "{ S1[i,j] : i > j }";
10141 uset
= isl_union_set_read_from_str(ctx
, str
);
10142 filters
= isl_union_set_list_from_union_set(uset
);
10143 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
10144 uset
= isl_union_set_read_from_str(ctx
, str
);
10145 filters
= isl_union_set_list_add(filters
, uset
);
10146 node
= isl_schedule_node_insert_sequence(node
, filters
);
10148 node
= isl_schedule_node_child(node
, 0);
10149 node
= isl_schedule_node_child(node
, 0);
10150 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
10151 str
= "([] : { S1[i,j] : i > j })";
10152 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10153 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
10154 isl_multi_union_pw_aff_free(mupa2
);
10155 isl_multi_union_pw_aff_free(mupa
);
10156 isl_schedule_node_free(node
);
10161 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
10167 /* Check that the reaching domain elements and the prefix schedule
10168 * at a leaf node are the same before and after grouping.
10170 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
10175 isl_union_set
*uset
;
10176 isl_multi_union_pw_aff
*mupa
;
10177 isl_union_pw_multi_aff
*upma1
, *upma2
;
10178 isl_union_set
*domain1
, *domain2
;
10179 isl_union_map
*umap1
, *umap2
;
10180 isl_schedule_node
*node
;
10182 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10183 uset
= isl_union_set_read_from_str(ctx
, str
);
10184 node
= isl_schedule_node_from_domain(uset
);
10185 node
= isl_schedule_node_child(node
, 0);
10186 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
10187 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10188 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10189 node
= isl_schedule_node_child(node
, 0);
10190 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
10191 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10192 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10193 node
= isl_schedule_node_child(node
, 0);
10194 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
10195 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
10196 domain1
= isl_schedule_node_get_domain(node
);
10197 id
= isl_id_alloc(ctx
, "group", NULL
);
10198 node
= isl_schedule_node_parent(node
);
10199 node
= isl_schedule_node_group(node
, id
);
10200 node
= isl_schedule_node_child(node
, 0);
10201 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
10202 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
10203 domain2
= isl_schedule_node_get_domain(node
);
10204 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
10205 if (equal
>= 0 && equal
)
10206 equal
= isl_union_set_is_equal(domain1
, domain2
);
10207 if (equal
>= 0 && equal
)
10208 equal
= isl_union_map_is_equal(umap1
, umap2
);
10209 isl_union_map_free(umap1
);
10210 isl_union_map_free(umap2
);
10211 isl_union_set_free(domain1
);
10212 isl_union_set_free(domain2
);
10213 isl_union_pw_multi_aff_free(upma1
);
10214 isl_union_pw_multi_aff_free(upma2
);
10215 isl_schedule_node_free(node
);
10220 isl_die(ctx
, isl_error_unknown
,
10221 "expressions not equal", return -1);
10226 /* Check that we can have nested groupings and that the union map
10227 * schedule representation is the same before and after the grouping.
10228 * Note that after the grouping, the union map representation contains
10229 * the domain constraints from the ranges of the expansion nodes,
10230 * while they are missing from the union map representation of
10231 * the tree without expansion nodes.
10233 * Also check that the global expansion is as expected.
10235 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
10237 int equal
, equal_expansion
;
10240 isl_union_set
*uset
;
10241 isl_union_map
*umap1
, *umap2
;
10242 isl_union_map
*expansion1
, *expansion2
;
10243 isl_union_set_list
*filters
;
10244 isl_multi_union_pw_aff
*mupa
;
10245 isl_schedule
*schedule
;
10246 isl_schedule_node
*node
;
10248 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
10249 "S3[i,j] : 0 <= i,j < 10 }";
10250 uset
= isl_union_set_read_from_str(ctx
, str
);
10251 node
= isl_schedule_node_from_domain(uset
);
10252 node
= isl_schedule_node_child(node
, 0);
10253 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
10254 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10255 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10256 node
= isl_schedule_node_child(node
, 0);
10257 str
= "{ S1[i,j] }";
10258 uset
= isl_union_set_read_from_str(ctx
, str
);
10259 filters
= isl_union_set_list_from_union_set(uset
);
10260 str
= "{ S2[i,j]; S3[i,j] }";
10261 uset
= isl_union_set_read_from_str(ctx
, str
);
10262 filters
= isl_union_set_list_add(filters
, uset
);
10263 node
= isl_schedule_node_insert_sequence(node
, filters
);
10264 node
= isl_schedule_node_child(node
, 1);
10265 node
= isl_schedule_node_child(node
, 0);
10266 str
= "{ S2[i,j] }";
10267 uset
= isl_union_set_read_from_str(ctx
, str
);
10268 filters
= isl_union_set_list_from_union_set(uset
);
10269 str
= "{ S3[i,j] }";
10270 uset
= isl_union_set_read_from_str(ctx
, str
);
10271 filters
= isl_union_set_list_add(filters
, uset
);
10272 node
= isl_schedule_node_insert_sequence(node
, filters
);
10274 schedule
= isl_schedule_node_get_schedule(node
);
10275 umap1
= isl_schedule_get_map(schedule
);
10276 uset
= isl_schedule_get_domain(schedule
);
10277 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
10278 isl_schedule_free(schedule
);
10280 node
= isl_schedule_node_parent(node
);
10281 node
= isl_schedule_node_parent(node
);
10282 id
= isl_id_alloc(ctx
, "group1", NULL
);
10283 node
= isl_schedule_node_group(node
, id
);
10284 node
= isl_schedule_node_child(node
, 1);
10285 node
= isl_schedule_node_child(node
, 0);
10286 id
= isl_id_alloc(ctx
, "group2", NULL
);
10287 node
= isl_schedule_node_group(node
, id
);
10289 schedule
= isl_schedule_node_get_schedule(node
);
10290 umap2
= isl_schedule_get_map(schedule
);
10291 isl_schedule_free(schedule
);
10293 node
= isl_schedule_node_root(node
);
10294 node
= isl_schedule_node_child(node
, 0);
10295 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
10296 isl_schedule_node_free(node
);
10298 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
10299 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
10300 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
10302 expansion2
= isl_union_map_read_from_str(ctx
, str
);
10304 equal
= isl_union_map_is_equal(umap1
, umap2
);
10305 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
10307 isl_union_map_free(umap1
);
10308 isl_union_map_free(umap2
);
10309 isl_union_map_free(expansion1
);
10310 isl_union_map_free(expansion2
);
10312 if (equal
< 0 || equal_expansion
< 0)
10315 isl_die(ctx
, isl_error_unknown
,
10316 "expressions not equal", return -1);
10317 if (!equal_expansion
)
10318 isl_die(ctx
, isl_error_unknown
,
10319 "unexpected expansion", return -1);
10324 /* Some tests for the isl_schedule_node_group function.
10326 static int test_schedule_tree_group(isl_ctx
*ctx
)
10328 if (test_schedule_tree_group_1(ctx
) < 0)
10330 if (test_schedule_tree_group_2(ctx
) < 0)
10339 { "{ rat: [i] : 0 <= i <= 10 }",
10340 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
10341 { "{ rat: [i] : FALSE }",
10342 "{ rat: coefficients[[cst] -> [a]] }" },
10343 { "{ rat: [i] : }",
10344 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
10345 { "{ [0:,1,2:3] }",
10346 "{ rat: coefficients[[c_cst] -> [a, b, c]] : "
10347 "a >= 0 and 2c >= -c_cst - b and 3c >= -c_cst - b }" },
10348 { "[M, N] -> { [x = (1 - N):-1, -4x:(M - 4x)] }",
10349 "{ rat: coefficients[[c_cst, c_M = 0:, c_N = 0:] -> [a, b = -c_M:]] :"
10350 "4b >= -c_N + a and 4b >= -c_cst - 2c_N + a }" },
10351 { "{ rat : [x, y] : 1 <= 2x <= 9 and 2 <= 3y <= 16 }",
10352 "{ rat: coefficients[[c_cst] -> [c_x, c_y]] : "
10353 "4c_y >= -6c_cst - 3c_x and 4c_y >= -6c_cst - 27c_x and "
10354 "32c_y >= -6c_cst - 3c_x and 32c_y >= -6c_cst - 27c_x }" },
10355 { "{ [x, y, z] : 3y <= 2x - 2 and y >= -2 + 2x and 2y >= 2 - x }",
10356 "{ rat: coefficients[[cst] -> [a, b, c]] }" },
10363 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
10364 "{ rat: [i] : 0 <= i <= 10 }" },
10365 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
10367 { "{ rat: coefficients[[cst] -> [a]] }",
10368 "{ rat: [i] : FALSE }" },
10371 /* Test the basic functionality of isl_basic_set_coefficients and
10372 * isl_basic_set_solutions.
10374 static int test_dual(isl_ctx
*ctx
)
10378 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
10380 isl_basic_set
*bset1
, *bset2
;
10382 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
10383 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
10384 bset1
= isl_basic_set_coefficients(bset1
);
10385 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10386 isl_basic_set_free(bset1
);
10387 isl_basic_set_free(bset2
);
10391 isl_die(ctx
, isl_error_unknown
,
10392 "incorrect dual", return -1);
10395 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
10397 isl_basic_set
*bset1
, *bset2
;
10399 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
10400 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
10401 bset1
= isl_basic_set_solutions(bset1
);
10402 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10403 isl_basic_set_free(bset1
);
10404 isl_basic_set_free(bset2
);
10408 isl_die(ctx
, isl_error_unknown
,
10409 "incorrect dual", return -1);
10418 const char *domain
;
10419 const char *schedule
;
10424 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10425 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10427 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10428 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10430 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10431 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10433 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10434 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10436 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10437 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10439 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10440 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10442 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10443 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10445 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10446 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10450 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
10451 * tile the band and then check if the tile and point bands have the
10452 * expected partial schedule.
10454 static int test_tile(isl_ctx
*ctx
)
10460 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
10461 shift
= isl_options_get_tile_shift_point_loops(ctx
);
10463 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
10467 isl_union_set
*domain
;
10468 isl_multi_union_pw_aff
*mupa
, *mupa2
;
10469 isl_schedule_node
*node
;
10470 isl_multi_val
*sizes
;
10472 opt
= tile_tests
[i
].scale_tile
;
10473 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
10474 opt
= tile_tests
[i
].shift_point
;
10475 isl_options_set_tile_shift_point_loops(ctx
, opt
);
10477 str
= tile_tests
[i
].domain
;
10478 domain
= isl_union_set_read_from_str(ctx
, str
);
10479 node
= isl_schedule_node_from_domain(domain
);
10480 node
= isl_schedule_node_child(node
, 0);
10481 str
= tile_tests
[i
].schedule
;
10482 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10483 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10484 str
= tile_tests
[i
].sizes
;
10485 sizes
= isl_multi_val_read_from_str(ctx
, str
);
10486 node
= isl_schedule_node_band_tile(node
, sizes
);
10488 str
= tile_tests
[i
].tile
;
10489 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10490 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10491 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
10492 isl_multi_union_pw_aff_free(mupa
);
10493 isl_multi_union_pw_aff_free(mupa2
);
10495 node
= isl_schedule_node_child(node
, 0);
10497 str
= tile_tests
[i
].point
;
10498 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10499 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10500 if (equal
>= 0 && equal
)
10501 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
10503 isl_multi_union_pw_aff_free(mupa
);
10504 isl_multi_union_pw_aff_free(mupa2
);
10506 isl_schedule_node_free(node
);
10511 isl_die(ctx
, isl_error_unknown
,
10512 "unexpected result", return -1);
10515 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
10516 isl_options_set_tile_shift_point_loops(ctx
, shift
);
10521 /* Check that the domain hash of a space is equal to the hash
10522 * of the domain of the space.
10524 static int test_domain_hash(isl_ctx
*ctx
)
10528 uint32_t hash1
, hash2
;
10530 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
10531 space
= isl_map_get_space(map
);
10533 hash1
= isl_space_get_domain_hash(space
);
10534 space
= isl_space_domain(space
);
10535 hash2
= isl_space_get_hash(space
);
10536 isl_space_free(space
);
10540 if (hash1
!= hash2
)
10541 isl_die(ctx
, isl_error_unknown
,
10542 "domain hash not equal to hash of domain", return -1);
10547 /* Check that a universe basic set that is not obviously equal to the universe
10548 * is still recognized as being equal to the universe.
10550 static int test_universe(isl_ctx
*ctx
)
10553 isl_basic_set
*bset
;
10556 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
10557 bset
= isl_basic_set_read_from_str(ctx
, s
);
10558 is_univ
= isl_basic_set_is_universe(bset
);
10559 isl_basic_set_free(bset
);
10564 isl_die(ctx
, isl_error_unknown
,
10565 "not recognized as universe set", return -1);
10570 /* Sets for which chambers are computed and checked.
10572 const char *chambers_tests
[] = {
10573 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
10574 "z >= 0 and z <= C - y and z <= B - x - y }",
10577 /* Add the domain of "cell" to "cells".
10579 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
10581 isl_basic_set_list
**cells
= user
;
10582 isl_basic_set
*dom
;
10584 dom
= isl_cell_get_domain(cell
);
10585 isl_cell_free(cell
);
10586 *cells
= isl_basic_set_list_add(*cells
, dom
);
10588 return *cells
? isl_stat_ok
: isl_stat_error
;
10591 /* Check that the elements of "list" are pairwise disjoint.
10593 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
10598 n
= isl_basic_set_list_n_basic_set(list
);
10600 return isl_stat_error
;
10602 for (i
= 0; i
< n
; ++i
) {
10603 isl_basic_set
*bset_i
;
10605 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
10606 for (j
= i
+ 1; j
< n
; ++j
) {
10607 isl_basic_set
*bset_j
;
10610 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
10611 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
10612 isl_basic_set_free(bset_j
);
10614 isl_die(isl_basic_set_list_get_ctx(list
),
10615 isl_error_unknown
, "not disjoint",
10617 if (disjoint
< 0 || !disjoint
)
10620 isl_basic_set_free(bset_i
);
10622 return isl_stat_error
;
10625 return isl_stat_ok
;
10628 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
10629 * are pairwise disjoint.
10631 static int test_chambers(isl_ctx
*ctx
)
10635 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
10636 isl_basic_set
*bset
;
10637 isl_vertices
*vertices
;
10638 isl_basic_set_list
*cells
;
10641 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
10642 vertices
= isl_basic_set_compute_vertices(bset
);
10643 cells
= isl_basic_set_list_alloc(ctx
, 0);
10644 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
10646 cells
= isl_basic_set_list_free(cells
);
10647 ok
= check_pairwise_disjoint(cells
);
10648 isl_basic_set_list_free(cells
);
10649 isl_vertices_free(vertices
);
10650 isl_basic_set_free(bset
);
10661 int (*fn
)(isl_ctx
*ctx
);
10663 { "universe", &test_universe
},
10664 { "domain hash", &test_domain_hash
},
10665 { "dual", &test_dual
},
10666 { "dependence analysis", &test_flow
},
10667 { "val", &test_val
},
10668 { "compute divs", &test_compute_divs
},
10669 { "partial lexmin", &test_partial_lexmin
},
10670 { "simplify", &test_simplify
},
10671 { "curry", &test_curry
},
10672 { "piecewise multi affine expressions", &test_pw_multi_aff
},
10673 { "multi piecewise affine expressions", &test_multi_pw_aff
},
10674 { "conversion", &test_conversion
},
10675 { "list", &test_list
},
10676 { "align parameters", &test_align_parameters
},
10677 { "drop unused parameters", &test_drop_unused_parameters
},
10678 { "preimage", &test_preimage
},
10679 { "pullback", &test_pullback
},
10680 { "AST", &test_ast
},
10681 { "AST build", &test_ast_build
},
10682 { "AST generation", &test_ast_gen
},
10683 { "eliminate", &test_eliminate
},
10684 { "deltas_map", &test_deltas_map
},
10685 { "residue class", &test_residue_class
},
10686 { "div", &test_div
},
10687 { "slice", &test_slice
},
10688 { "fixed power", &test_fixed_power
},
10689 { "sample", &test_sample
},
10690 { "output", &test_output
},
10691 { "vertices", &test_vertices
},
10692 { "chambers", &test_chambers
},
10693 { "fixed", &test_fixed
},
10694 { "equal", &test_equal
},
10695 { "disjoint", &test_disjoint
},
10696 { "product", &test_product
},
10697 { "dim_max", &test_dim_max
},
10698 { "affine", &test_aff
},
10699 { "injective", &test_injective
},
10700 { "schedule (whole component)", &test_schedule_whole
},
10701 { "schedule (incremental)", &test_schedule_incremental
},
10702 { "schedule tree", &test_schedule_tree
},
10703 { "schedule tree prefix", &test_schedule_tree_prefix
},
10704 { "schedule tree grouping", &test_schedule_tree_group
},
10705 { "tile", &test_tile
},
10706 { "union map", &test_union_map
},
10707 { "union_pw", &test_union_pw
},
10708 { "locus", &test_locus
},
10709 { "eval", &test_eval
},
10710 { "parse", &test_parse
},
10711 { "single-valued", &test_sv
},
10712 { "recession cone", &test_recession_cone
},
10713 { "affine hull", &test_affine_hull
},
10714 { "simple_hull", &test_simple_hull
},
10715 { "box hull", &test_box_hull
},
10716 { "coalesce", &test_coalesce
},
10717 { "factorize", &test_factorize
},
10718 { "subset", &test_subset
},
10719 { "subtract", &test_subtract
},
10720 { "intersect", &test_intersect
},
10721 { "lexmin", &test_lexmin
},
10722 { "min", &test_min
},
10723 { "gist", &test_gist
},
10724 { "piecewise quasi-polynomials", &test_pwqp
},
10725 { "lift", &test_lift
},
10726 { "bind parameters", &test_bind
},
10727 { "unbind parameters", &test_unbind
},
10728 { "bound", &test_bound
},
10729 { "get lists", &test_get_list
},
10730 { "union", &test_union
},
10731 { "split periods", &test_split_periods
},
10732 { "lexicographic order", &test_lex
},
10733 { "bijectivity", &test_bijective
},
10734 { "dataflow analysis", &test_dep
},
10735 { "reading", &test_read
},
10736 { "bounded", &test_bounded
},
10737 { "construction", &test_construction
},
10738 { "dimension manipulation", &test_dim
},
10739 { "map application", &test_application
},
10740 { "convex hull", &test_convex_hull
},
10741 { "transitive closure", &test_closure
},
10742 { "isl_bool", &test_isl_bool
},
10745 int main(int argc
, char **argv
)
10748 struct isl_ctx
*ctx
;
10749 struct isl_options
*options
;
10751 options
= isl_options_new_with_defaults();
10753 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
10755 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
10756 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
10757 printf("%s\n", tests
[i
].name
);
10758 if (tests
[i
].fn(ctx
) < 0)