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 /* Pairs of maps and the corresponding expected results of
1378 * isl_map_plain_unshifted_simple_hull.
1383 } plain_unshifted_simple_hull_tests
[] = {
1384 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1385 "{ [i] -> [j] : i >= 1 }" },
1386 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1387 "(j mod 4 = 2 and k mod 6 = n) }",
1388 "{ [n] -> [i,j,k] : j mod 4 = 2 }" },
1391 /* Basic tests for isl_map_plain_unshifted_simple_hull.
1393 static int test_plain_unshifted_simple_hull(isl_ctx
*ctx
)
1397 isl_basic_map
*hull
, *expected
;
1400 for (i
= 0; i
< ARRAY_SIZE(plain_unshifted_simple_hull_tests
); ++i
) {
1402 str
= plain_unshifted_simple_hull_tests
[i
].map
;
1403 map
= isl_map_read_from_str(ctx
, str
);
1404 str
= plain_unshifted_simple_hull_tests
[i
].hull
;
1405 expected
= isl_basic_map_read_from_str(ctx
, str
);
1406 hull
= isl_map_plain_unshifted_simple_hull(map
);
1407 equal
= isl_basic_map_is_equal(hull
, expected
);
1408 isl_basic_map_free(hull
);
1409 isl_basic_map_free(expected
);
1413 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1420 /* Pairs of sets and the corresponding expected results of
1421 * isl_set_unshifted_simple_hull.
1426 } unshifted_simple_hull_tests
[] = {
1427 { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1428 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1431 /* Basic tests for isl_set_unshifted_simple_hull.
1433 static int test_unshifted_simple_hull(isl_ctx
*ctx
)
1437 isl_basic_set
*hull
, *expected
;
1440 for (i
= 0; i
< ARRAY_SIZE(unshifted_simple_hull_tests
); ++i
) {
1442 str
= unshifted_simple_hull_tests
[i
].set
;
1443 set
= isl_set_read_from_str(ctx
, str
);
1444 str
= unshifted_simple_hull_tests
[i
].hull
;
1445 expected
= isl_basic_set_read_from_str(ctx
, str
);
1446 hull
= isl_set_unshifted_simple_hull(set
);
1447 equal
= isl_basic_set_is_equal(hull
, expected
);
1448 isl_basic_set_free(hull
);
1449 isl_basic_set_free(expected
);
1453 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1460 static int test_simple_hull(struct isl_ctx
*ctx
)
1464 isl_basic_set
*bset
;
1467 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1468 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1469 set
= isl_set_read_from_str(ctx
, str
);
1470 bset
= isl_set_simple_hull(set
);
1471 is_empty
= isl_basic_set_is_empty(bset
);
1472 isl_basic_set_free(bset
);
1474 if (is_empty
== isl_bool_error
)
1477 if (is_empty
== isl_bool_false
)
1478 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1481 if (test_plain_unshifted_simple_hull(ctx
) < 0)
1483 if (test_unshifted_simple_hull(ctx
) < 0)
1489 /* Inputs for isl_set_get_simple_fixed_box_hull tests.
1490 * "set" is the input set.
1491 * "offset" is the expected box offset.
1492 * "size" is the expected box size.
1498 } box_hull_tests
[] = {
1499 { "{ S[x, y] : 0 <= x, y < 10 }", "{ S[0, 0] }", "{ S[10, 10] }" },
1500 { "[N] -> { S[x, y] : N <= x, y < N + 10 }",
1501 "[N] -> { S[N, N] }", "{ S[10, 10] }" },
1502 { "{ S[x, y] : 0 <= x + y, x - y < 10 }",
1503 "{ S[0, -4] }", "{ S[10, 9] }" },
1504 { "{ [i=0:10] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1505 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1506 "{ [0] }", "{ [11] }" },
1509 /* Perform basic isl_set_get_simple_fixed_box_hull tests.
1511 static int test_box_hull(struct isl_ctx
*ctx
)
1515 for (i
= 0; i
< ARRAY_SIZE(box_hull_tests
); ++i
) {
1519 isl_multi_aff
*offset
;
1520 isl_multi_val
*size
;
1523 set
= isl_set_read_from_str(ctx
, box_hull_tests
[i
].set
);
1524 box
= isl_set_get_simple_fixed_box_hull(set
);
1525 offset
= isl_fixed_box_get_offset(box
);
1526 size
= isl_fixed_box_get_size(box
);
1527 str
= box_hull_tests
[i
].offset
;
1528 r
= multi_aff_check_plain_equal(offset
, str
);
1529 str
= box_hull_tests
[i
].size
;
1531 r
= multi_val_check_plain_equal(size
, str
);
1532 isl_multi_aff_free(offset
);
1533 isl_multi_val_free(size
);
1534 isl_fixed_box_free(box
);
1543 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1547 struct isl_basic_set
*bset1
, *bset2
;
1548 struct isl_set
*set
;
1550 filename
= get_filename(ctx
, name
, "polylib");
1552 input
= fopen(filename
, "r");
1555 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1556 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1558 set
= isl_basic_set_union(bset1
, bset2
);
1559 bset1
= isl_set_convex_hull(set
);
1561 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1563 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1565 isl_basic_set_free(bset1
);
1566 isl_basic_set_free(bset2
);
1575 } convex_hull_tests
[] = {
1576 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1577 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1578 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1579 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1580 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1581 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1582 "i2 <= 5 and i2 >= 4; "
1583 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1584 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1585 "i2 <= 5 + i0 and i2 >= i0 }" },
1586 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1587 "{ [x, y] : 1 = 0 }" },
1588 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1589 "[x, y, 0] : x >= 0 and y < 0 }",
1590 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1591 { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and "
1593 "[0, 2, 0]; [3, 1, 0] }",
1594 "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and "
1595 "5c <= 6 - a - 3b }" },
1598 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1601 int orig_convex
= ctx
->opt
->convex
;
1602 ctx
->opt
->convex
= convex
;
1604 test_convex_hull_case(ctx
, "convex0");
1605 test_convex_hull_case(ctx
, "convex1");
1606 test_convex_hull_case(ctx
, "convex2");
1607 test_convex_hull_case(ctx
, "convex3");
1608 test_convex_hull_case(ctx
, "convex4");
1609 test_convex_hull_case(ctx
, "convex5");
1610 test_convex_hull_case(ctx
, "convex6");
1611 test_convex_hull_case(ctx
, "convex7");
1612 test_convex_hull_case(ctx
, "convex8");
1613 test_convex_hull_case(ctx
, "convex9");
1614 test_convex_hull_case(ctx
, "convex10");
1615 test_convex_hull_case(ctx
, "convex11");
1616 test_convex_hull_case(ctx
, "convex12");
1617 test_convex_hull_case(ctx
, "convex13");
1618 test_convex_hull_case(ctx
, "convex14");
1619 test_convex_hull_case(ctx
, "convex15");
1621 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1622 isl_set
*set1
, *set2
;
1625 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1626 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1627 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1628 equal
= isl_set_is_equal(set1
, set2
);
1635 isl_die(ctx
, isl_error_unknown
,
1636 "unexpected convex hull", return -1);
1639 ctx
->opt
->convex
= orig_convex
;
1644 static int test_convex_hull(isl_ctx
*ctx
)
1646 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1648 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1653 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1657 struct isl_basic_set
*bset1
, *bset2
;
1659 filename
= get_filename(ctx
, name
, "polylib");
1661 input
= fopen(filename
, "r");
1664 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1665 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1667 bset1
= isl_basic_set_gist(bset1
, bset2
);
1669 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1671 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1673 isl_basic_set_free(bset1
);
1674 isl_basic_set_free(bset2
);
1680 /* Check that computing the gist of "map" with respect to "context"
1681 * does not make any copy of "map" get marked empty.
1682 * Earlier versions of isl would end up doing that.
1684 static isl_stat
test_gist_empty_pair(isl_ctx
*ctx
, const char *map
,
1685 const char *context
)
1687 isl_map
*m1
, *m2
, *m3
;
1688 isl_bool empty_before
, empty_after
;
1690 m1
= isl_map_read_from_str(ctx
, map
);
1691 m2
= isl_map_read_from_str(ctx
, context
);
1692 m3
= isl_map_copy(m1
);
1693 empty_before
= isl_map_is_empty(m3
);
1694 m1
= isl_map_gist(m1
, m2
);
1695 empty_after
= isl_map_is_empty(m3
);
1699 if (empty_before
< 0 || empty_after
< 0)
1700 return isl_stat_error
;
1702 isl_die(ctx
, isl_error_unknown
, "map should not be empty",
1703 return isl_stat_error
);
1705 isl_die(ctx
, isl_error_unknown
, "map should still not be empty",
1706 return isl_stat_error
);
1711 /* Check that computing a gist does not make any copy of the input
1713 * Earlier versions of isl would end up doing that on some pairs of inputs.
1715 static isl_stat
test_gist_empty(isl_ctx
*ctx
)
1717 const char *map
, *context
;
1719 map
= "{ [] -> [a, b, c] : 2b = 1 + a }";
1720 context
= "{ [] -> [a, b, c] : 2c = 2 + a }";
1721 if (test_gist_empty_pair(ctx
, map
, context
) < 0)
1722 return isl_stat_error
;
1723 map
= "{ [] -> [0, 0] }";
1724 context
= "{ [] -> [a, b] : a > b }";
1725 if (test_gist_empty_pair(ctx
, map
, context
) < 0)
1726 return isl_stat_error
;
1731 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1735 const char *context
;
1737 } plain_gist_tests
[] = {
1738 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1739 "{ [i] -> [j] : i >= 1 }",
1740 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1741 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1742 "(j mod 4 = 2 and k mod 6 = n) }",
1743 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1744 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1745 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1746 "{ [i] -> [j] : i > j }",
1747 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1750 /* Basic tests for isl_map_plain_gist_basic_map.
1752 static int test_plain_gist(isl_ctx
*ctx
)
1756 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1759 isl_map
*map
, *gist
;
1760 isl_basic_map
*context
;
1762 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1763 str
= plain_gist_tests
[i
].context
;
1764 context
= isl_basic_map_read_from_str(ctx
, str
);
1765 map
= isl_map_plain_gist_basic_map(map
, context
);
1766 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1767 equal
= isl_map_is_equal(map
, gist
);
1773 isl_die(ctx
, isl_error_unknown
,
1774 "incorrect gist result", return -1);
1780 /* Inputs for isl_basic_set_gist tests that are expected to fail.
1784 const char *context
;
1785 } gist_fail_tests
[] = {
1786 { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1787 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1788 "{ [i] : i >= 0 }" },
1791 /* Check that isl_basic_set_gist fails (gracefully) when expected.
1792 * In particular, the user should be able to recover from the failure.
1794 static isl_stat
test_gist_fail(struct isl_ctx
*ctx
)
1799 on_error
= isl_options_get_on_error(ctx
);
1800 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
1801 n
= ARRAY_SIZE(gist_fail_tests
);
1802 for (i
= 0; i
< n
; ++i
) {
1804 isl_basic_set
*bset
, *context
;
1806 bset
= isl_basic_set_read_from_str(ctx
, gist_fail_tests
[i
].set
);
1807 str
= gist_fail_tests
[i
].context
;
1808 context
= isl_basic_set_read_from_str(ctx
, str
);
1809 bset
= isl_basic_set_gist(bset
, context
);
1810 isl_basic_set_free(bset
);
1814 isl_options_set_on_error(ctx
, on_error
);
1816 isl_die(ctx
, isl_error_unknown
,
1817 "operation not expected to succeed",
1818 return isl_stat_error
);
1825 const char *context
;
1828 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1829 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1830 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1831 "{ [a, b, c] : a <= 15 }" },
1832 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1833 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1834 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1835 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1836 { "{ [m, n, a, b] : a <= 2147 + n }",
1837 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1838 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1839 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1841 "{ [m, n, ku, kl] }" },
1842 { "{ [a, a, b] : a >= 10 }",
1843 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1844 "{ [a, a, b] : a >= 10 }" },
1845 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1846 "{ [0, j] : j >= 0 }" },
1847 /* Check that no constraints on i6 are introduced in the gist */
1848 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1849 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1850 "5e0 <= 381 - t1 and i4 <= 1) }",
1851 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1852 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1853 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1854 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1855 "20e0 >= 1511 - 4t1 - 5i4) }" },
1856 /* Check that no constraints on i6 are introduced in the gist */
1857 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1858 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1859 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1860 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1861 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1862 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1863 "20e1 <= 1530 - 4t1 - 5i4 and "
1864 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1865 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1866 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1867 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1868 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1869 "10e0 <= -91 + 5i4 + 4i6 and "
1870 "10e0 >= -105 + 5i4 + 4i6) }",
1871 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1872 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1873 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1874 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1875 "{ [a, b, q, p] : b >= 1 + a }",
1876 "{ [a, b, q, p] : false }" },
1877 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1878 "[n] -> { [x] : x mod 32 = 0 }",
1879 "[n] -> { [x = n] }" },
1880 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1881 "{ [x] : x mod 2 = 0 }" },
1882 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1883 "{ [x] : x mod 128 = 0 }" },
1884 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1885 "{ [x] : x mod 3200 = 0 }" },
1886 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1887 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1888 "{ [a, b, c = a] }" },
1889 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1890 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1891 "{ [a, b, c = a] : a mod 3 = 0 }" },
1892 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1893 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1895 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1896 "{ [x,y] : 1 <= y <= 3 }",
1900 /* Check that isl_set_gist behaves as expected.
1902 * For the test cases in gist_tests, besides checking that the result
1903 * is as expected, also check that applying the gist operation does
1904 * not modify the input set (an earlier version of isl would do that) and
1905 * that the test case is consistent, i.e., that the gist has the same
1906 * intersection with the context as the input set.
1908 static int test_gist(struct isl_ctx
*ctx
)
1912 isl_basic_set
*bset1
, *bset2
;
1913 isl_map
*map1
, *map2
;
1917 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1918 isl_bool equal_input
, equal_intersection
;
1919 isl_set
*set1
, *set2
, *copy
, *context
;
1921 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1922 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1923 copy
= isl_set_copy(set1
);
1924 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1925 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1926 equal
= isl_set_is_equal(set1
, set2
);
1928 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1929 equal_input
= isl_set_is_equal(set1
, copy
);
1931 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1932 set2
= isl_set_intersect(set2
, context
);
1933 equal_intersection
= isl_set_is_equal(set1
, set2
);
1936 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1939 isl_die(ctx
, isl_error_unknown
,
1940 "incorrect gist result", return -1);
1942 isl_die(ctx
, isl_error_unknown
,
1943 "gist modified input", return -1);
1945 isl_die(ctx
, isl_error_unknown
,
1946 "inconsistent gist test case", return -1);
1949 if (test_gist_fail(ctx
) < 0)
1952 test_gist_case(ctx
, "gist1");
1954 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1955 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1956 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1957 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1958 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1959 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1960 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1961 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1962 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1963 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1964 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1965 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1966 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1967 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1968 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1969 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1970 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1971 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1972 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1973 bset1
= isl_basic_set_gist(bset1
, bset2
);
1974 assert(bset1
&& bset1
->n_div
== 0);
1975 isl_basic_set_free(bset1
);
1977 /* Check that the integer divisions of the second disjunct
1978 * do not spread to the first disjunct.
1980 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1981 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1982 "(exists (e0 = [(-1 + t1)/16], "
1983 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1984 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1985 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1986 "o0 <= 4294967295 and t1 <= -1)) }";
1987 map1
= isl_map_read_from_str(ctx
, str
);
1988 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1989 map2
= isl_map_read_from_str(ctx
, str
);
1990 map1
= isl_map_gist(map1
, map2
);
1994 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1995 isl_map_free(map1
); return -1);
1996 n_div
= isl_basic_map_dim(map1
->p
[0], isl_dim_div
);
2001 isl_die(ctx
, isl_error_unknown
, "expecting single div",
2004 if (test_gist_empty(ctx
) < 0)
2006 if (test_plain_gist(ctx
) < 0)
2012 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
2014 isl_set
*set
, *set2
;
2018 set
= isl_set_read_from_str(ctx
, str
);
2019 set
= isl_set_coalesce(set
);
2020 set2
= isl_set_read_from_str(ctx
, str
);
2021 equal
= isl_set_is_equal(set
, set2
);
2022 one
= set
&& set
->n
== 1;
2029 isl_die(ctx
, isl_error_unknown
,
2030 "coalesced set not equal to input", return -1);
2031 if (check_one
&& !one
)
2032 isl_die(ctx
, isl_error_unknown
,
2033 "coalesced set should not be a union", return -1);
2038 /* Inputs for coalescing tests with unbounded wrapping.
2039 * "str" is a string representation of the input set.
2040 * "single_disjunct" is set if we expect the result to consist of
2041 * a single disjunct.
2044 int single_disjunct
;
2046 } coalesce_unbounded_tests
[] = {
2047 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
2048 "-x - y + 1 >= 0 and -3 <= z <= 3;"
2049 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
2050 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
2052 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
2053 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
2054 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
2055 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
2056 { 0, "{ [x, y, z] : 0 <= x,y,z <= 100 and 0 < z <= 2 + 2x + 2y; "
2057 "[x, y, 0] : x,y <= 100 and y <= 9 + 11x and x <= 9 + 11y }" },
2060 /* Test the functionality of isl_set_coalesce with the bounded wrapping
2061 * option turned off.
2063 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
2069 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
2070 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
2072 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
2073 const char *str
= coalesce_unbounded_tests
[i
].str
;
2074 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
2075 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
2081 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
2086 /* Inputs for coalescing tests.
2087 * "str" is a string representation of the input set.
2088 * "single_disjunct" is set if we expect the result to consist of
2089 * a single disjunct.
2092 int single_disjunct
;
2094 } coalesce_tests
[] = {
2095 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
2096 "y >= x & x >= 2 & 5 >= y }" },
2097 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2098 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
2099 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2100 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
2101 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2102 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
2103 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2104 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
2105 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2106 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
2107 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
2108 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
2109 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
2110 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
2111 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
2112 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
2113 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
2114 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2115 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2116 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2117 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
2118 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
2119 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
2120 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
2121 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
2122 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2123 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2124 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2125 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
2126 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
2127 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
2128 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
2129 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
2130 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
2131 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
2132 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
2133 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
2134 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
2135 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
2136 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
2137 "[o0, o1, o2, o3, o4, o5, o6]] : "
2138 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
2139 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
2140 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
2141 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
2142 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
2143 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
2144 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
2145 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
2146 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
2147 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
2148 "o6 >= i3 + i6 - o3 and M >= 0 and "
2149 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
2150 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
2151 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
2152 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
2153 "(o0 = 0 and M >= 2 and N >= 3) or "
2154 "(M = 0 and o0 = 0 and N >= 3) }" },
2155 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
2156 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
2157 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
2158 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
2159 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
2160 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
2161 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
2162 "(y = 3 and x = 1) }" },
2163 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
2164 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
2165 "i1 <= M and i3 <= M and i4 <= M) or "
2166 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
2167 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
2168 "i4 <= -1 + M) }" },
2169 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
2170 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
2171 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
2172 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
2173 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
2174 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
2175 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
2176 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
2177 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
2178 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
2179 { 0, "{ [a, b] : exists e : 2e = a and "
2180 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
2181 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
2182 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
2183 "j >= 1 and j' <= i + j - i' and i >= 1; "
2185 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
2186 "[i,j] : exists a : j = 3a }" },
2187 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
2188 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
2190 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
2191 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
2192 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
2193 "c <= 6 + 8a and a >= 3; "
2194 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
2195 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
2196 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2197 "[x,0] : 3 <= x <= 4 }" },
2198 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
2199 "[x,0] : 4 <= x <= 5 }" },
2200 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2201 "[x,0] : 3 <= x <= 5 }" },
2202 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
2203 "[x,0] : 3 <= x <= 4 }" },
2204 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
2206 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
2207 { 1, "{ [0,0]; [1,1] }" },
2208 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
2209 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
2211 "[k, 0, k] : k <= 6 and k >= 1 }" },
2212 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
2213 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
2214 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
2215 { 1, "[n] -> { [1] : n >= 0;"
2216 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
2217 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
2218 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
2219 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
2220 "2e0 <= x and 2e0 <= n);"
2221 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
2223 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
2224 "128e0 >= -134 + 127t1 and t1 >= 2 and "
2225 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
2227 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
2228 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
2230 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
2231 "t1 >= 13 and t1 <= 16);"
2232 "[t1] : t1 <= 15 and t1 >= 12 }" },
2233 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2234 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2235 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2236 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2237 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2238 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2240 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2241 "(exists (e0 : 3e0 = -2 + c0)) }" },
2242 { 0, "[n, b0, t0] -> "
2243 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2244 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2245 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2246 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2247 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2248 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2249 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2250 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2251 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2252 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2253 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2254 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2255 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2256 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2257 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2258 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2259 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2260 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2261 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2262 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2263 { 0, "{ [i0, i1, i2] : "
2264 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2265 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2266 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2267 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2268 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2269 "32e0 <= 31 + i0)) or "
2271 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2272 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2273 "2*floor((c)/2) = c and 0 <= a <= 192;"
2274 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2276 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2277 "(0 <= a <= b <= n) }" },
2278 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2279 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2280 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2281 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2282 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2283 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2284 "b = 3 and 9e0 <= -19 + 2c)) }" },
2285 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2286 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2287 "(a = 4 and b = 3 and "
2288 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2289 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2290 "(b = -1 + a and 0 < a <= 3 and "
2291 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2292 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2293 "b = 3 and 9e0 <= -19 + 2c)) }" },
2294 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2296 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2298 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2299 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2300 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2301 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2302 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2303 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2304 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2305 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2306 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2307 { 1, "{ [a] : a <= 8 and "
2308 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2309 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2310 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2311 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2312 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2313 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2314 "(a < 0 and 3*floor((a)/3) < a) }" },
2315 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2316 "(a < -1 and 3*floor((a)/3) < a) }" },
2317 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2318 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2319 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2320 "or (2 <= a <= 15 and b < a)) }" },
2321 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2322 "32*floor((a)/32) < a) or a <= 15) }" },
2323 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2324 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2325 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2326 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2327 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2328 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2329 "S_0[n] : n <= m <= 2 + n }" },
2330 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2331 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2333 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2334 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2335 "2e0 < -a + 2b) }" },
2336 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2337 "[i, 0, i] : 0 <= i <= 7 }" },
2338 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2339 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2340 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2341 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2342 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2343 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2344 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2345 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2346 "a > 0 and a <= 5) }" },
2347 { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" },
2348 { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and "
2349 "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; "
2350 "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" },
2353 /* A specialized coalescing test case that would result
2354 * in a segmentation fault or a failed assertion in earlier versions of isl.
2356 static int test_coalesce_special(struct isl_ctx
*ctx
)
2359 isl_map
*map1
, *map2
;
2361 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2362 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2363 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2364 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2365 "o1 <= 239 and o1 >= 212)) or "
2366 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2367 "o1 <= 241 and o1 >= 240));"
2368 "[S_L220_OUT[] -> T7[]] -> "
2369 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2370 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2371 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2372 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2373 map1
= isl_map_read_from_str(ctx
, str
);
2374 map1
= isl_map_align_divs_internal(map1
);
2375 map1
= isl_map_coalesce(map1
);
2376 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2377 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2378 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2379 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2380 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2381 map2
= isl_map_read_from_str(ctx
, str
);
2382 map2
= isl_map_union(map2
, map1
);
2383 map2
= isl_map_align_divs_internal(map2
);
2384 map2
= isl_map_coalesce(map2
);
2392 /* A specialized coalescing test case that would result in an assertion
2393 * in an earlier version of isl.
2394 * The explicit call to isl_basic_set_union prevents the implicit
2395 * equality constraints in the first basic map from being detected prior
2396 * to the call to isl_set_coalesce, at least at the point
2397 * where this test case was introduced.
2399 static int test_coalesce_special2(struct isl_ctx
*ctx
)
2402 isl_basic_set
*bset1
, *bset2
;
2405 str
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2406 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2407 str
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2408 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2409 set
= isl_basic_set_union(bset1
, bset2
);
2410 set
= isl_set_coalesce(set
);
2418 /* Check that calling isl_set_coalesce does not leave other sets
2419 * that may share some information with the input to isl_set_coalesce
2420 * in an inconsistent state.
2421 * In particular, older versions of isl would modify all copies
2422 * of the basic sets in the isl_set_coalesce input in a way
2423 * that could leave them in an inconsistent state.
2424 * The result of printing any other set containing one of these
2425 * basic sets would then result in an invalid set description.
2427 static int test_coalesce_special3(isl_ctx
*ctx
)
2431 isl_set
*set1
, *set2
;
2434 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2435 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2436 set2
= isl_set_read_from_str(ctx
, str
);
2437 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2438 set1
= isl_set_coalesce(set1
);
2441 p
= isl_printer_to_str(ctx
);
2442 p
= isl_printer_print_set(p
, set2
);
2444 s
= isl_printer_get_str(p
);
2445 isl_printer_free(p
);
2446 set1
= isl_set_read_from_str(ctx
, s
);
2456 /* Check that calling isl_set_coalesce on the intersection of
2457 * the sets described by "s1" and "s2" does not leave other sets
2458 * that may share some information with the input to isl_set_coalesce
2459 * in an inconsistent state.
2460 * In particular, when isl_set_coalesce detects equality constraints,
2461 * it does not immediately perform Gaussian elimination on them,
2462 * but then it needs to ensure that it is performed at some point.
2463 * The input set has implicit equality constraints in the first disjunct.
2464 * It is constructed as an intersection, because otherwise
2465 * those equality constraints would already be detected during parsing.
2467 static isl_stat
test_coalesce_intersection(isl_ctx
*ctx
,
2468 const char *s1
, const char *s2
)
2470 isl_set
*set1
, *set2
;
2472 set1
= isl_set_read_from_str(ctx
, s1
);
2473 set2
= isl_set_read_from_str(ctx
, s2
);
2474 set1
= isl_set_intersect(set1
, set2
);
2475 isl_set_free(isl_set_coalesce(isl_set_copy(set1
)));
2476 set1
= isl_set_coalesce(set1
);
2480 return isl_stat_error
;
2485 /* Check that calling isl_set_coalesce does not leave other sets
2486 * that may share some information with the input to isl_set_coalesce
2487 * in an inconsistent state, for the case where one disjunct
2488 * is a subset of the other.
2490 static isl_stat
test_coalesce_special4(isl_ctx
*ctx
)
2492 const char *s1
, *s2
;
2494 s1
= "{ [a, b] : b <= 0 or a <= 1 }";
2495 s2
= "{ [a, b] : -1 <= -a < b }";
2496 return test_coalesce_intersection(ctx
, s1
, s2
);
2499 /* Check that calling isl_set_coalesce does not leave other sets
2500 * that may share some information with the input to isl_set_coalesce
2501 * in an inconsistent state, for the case where two disjuncts
2504 static isl_stat
test_coalesce_special5(isl_ctx
*ctx
)
2506 const char *s1
, *s2
;
2508 s1
= "{ [a, b, c] : b <= 0 }";
2509 s2
= "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }";
2510 return test_coalesce_intersection(ctx
, s1
, s2
);
2513 /* Check that calling isl_set_coalesce does not leave other sets
2514 * that may share some information with the input to isl_set_coalesce
2515 * in an inconsistent state, for the case where two disjuncts
2516 * can be fused and where both disjuncts have implicit equality constraints.
2518 static isl_stat
test_coalesce_special6(isl_ctx
*ctx
)
2520 const char *s1
, *s2
;
2522 s1
= "{ [a, b, c] : c <= 0 }";
2523 s2
= "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }";
2524 return test_coalesce_intersection(ctx
, s1
, s2
);
2527 /* Test the functionality of isl_set_coalesce.
2528 * That is, check that the output is always equal to the input
2529 * and in some cases that the result consists of a single disjunct.
2531 static int test_coalesce(struct isl_ctx
*ctx
)
2535 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2536 const char *str
= coalesce_tests
[i
].str
;
2537 int check_one
= coalesce_tests
[i
].single_disjunct
;
2538 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2542 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2544 if (test_coalesce_special(ctx
) < 0)
2546 if (test_coalesce_special2(ctx
) < 0)
2548 if (test_coalesce_special3(ctx
) < 0)
2550 if (test_coalesce_special4(ctx
) < 0)
2552 if (test_coalesce_special5(ctx
) < 0)
2554 if (test_coalesce_special6(ctx
) < 0)
2561 /* Construct a representation of the graph on the right of Figure 1
2562 * in "Computing the Transitive Closure of a Union of
2563 * Affine Integer Tuple Relations".
2565 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2568 isl_map
*up
, *right
;
2570 dom
= isl_set_read_from_str(ctx
,
2571 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2572 "2 x - 3 y + 3 >= 0 }");
2573 right
= isl_map_read_from_str(ctx
,
2574 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2575 up
= isl_map_read_from_str(ctx
,
2576 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2577 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2578 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2579 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2580 up
= isl_map_intersect_range(up
, dom
);
2581 return isl_map_union(up
, right
);
2584 /* Construct a representation of the power of the graph
2585 * on the right of Figure 1 in "Computing the Transitive Closure of
2586 * a Union of Affine Integer Tuple Relations".
2588 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2590 return isl_map_read_from_str(ctx
,
2591 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2592 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2593 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2596 /* Construct a representation of the transitive closure of the graph
2597 * on the right of Figure 1 in "Computing the Transitive Closure of
2598 * a Union of Affine Integer Tuple Relations".
2600 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2602 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2605 static int test_closure(isl_ctx
*ctx
)
2608 isl_map
*map
, *map2
;
2609 isl_bool exact
, equal
;
2611 /* COCOA example 1 */
2612 map
= isl_map_read_from_str(ctx
,
2613 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2614 "1 <= i and i < n and 1 <= j and j < n or "
2615 "i2 = i + 1 and j2 = j - 1 and "
2616 "1 <= i and i < n and 2 <= j and j <= n }");
2617 map
= isl_map_power(map
, &exact
);
2621 /* COCOA example 1 */
2622 map
= isl_map_read_from_str(ctx
,
2623 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2624 "1 <= i and i < n and 1 <= j and j < n or "
2625 "i2 = i + 1 and j2 = j - 1 and "
2626 "1 <= i and i < n and 2 <= j and j <= n }");
2627 map
= isl_map_transitive_closure(map
, &exact
);
2629 map2
= isl_map_read_from_str(ctx
,
2630 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2631 "1 <= i and i < n and 1 <= j and j <= n and "
2632 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2633 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2634 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2635 assert(isl_map_is_equal(map
, map2
));
2639 map
= isl_map_read_from_str(ctx
,
2640 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2641 " 0 <= y and y <= n }");
2642 map
= isl_map_transitive_closure(map
, &exact
);
2643 map2
= isl_map_read_from_str(ctx
,
2644 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2645 " 0 <= y and y <= n }");
2646 assert(isl_map_is_equal(map
, map2
));
2650 /* COCOA example 2 */
2651 map
= isl_map_read_from_str(ctx
,
2652 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2653 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2654 "i2 = i + 2 and j2 = j - 2 and "
2655 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2656 map
= isl_map_transitive_closure(map
, &exact
);
2658 map2
= isl_map_read_from_str(ctx
,
2659 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2660 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2661 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2662 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2663 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2664 assert(isl_map_is_equal(map
, map2
));
2668 /* COCOA Fig.2 left */
2669 map
= isl_map_read_from_str(ctx
,
2670 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2671 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2673 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2674 "j <= 2 i - 3 and j <= n - 2 or "
2675 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2676 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2677 map
= isl_map_transitive_closure(map
, &exact
);
2681 /* COCOA Fig.2 right */
2682 map
= isl_map_read_from_str(ctx
,
2683 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2684 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2686 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2687 "j <= 2 i - 4 and j <= n - 3 or "
2688 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2689 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2690 map
= isl_map_power(map
, &exact
);
2694 /* COCOA Fig.2 right */
2695 map
= isl_map_read_from_str(ctx
,
2696 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2697 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2699 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2700 "j <= 2 i - 4 and j <= n - 3 or "
2701 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2702 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2703 map
= isl_map_transitive_closure(map
, &exact
);
2705 map2
= isl_map_read_from_str(ctx
,
2706 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2707 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2708 "j <= n and 3 + i + 2 j <= 3 n and "
2709 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2710 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2711 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2712 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2713 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2714 assert(isl_map_is_equal(map
, map2
));
2718 map
= cocoa_fig_1_right_graph(ctx
);
2719 map
= isl_map_transitive_closure(map
, &exact
);
2721 map2
= cocoa_fig_1_right_tc(ctx
);
2722 assert(isl_map_is_equal(map
, map2
));
2726 map
= cocoa_fig_1_right_graph(ctx
);
2727 map
= isl_map_power(map
, &exact
);
2728 map2
= cocoa_fig_1_right_power(ctx
);
2729 equal
= isl_map_is_equal(map
, map2
);
2735 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2737 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2739 /* COCOA Theorem 1 counter example */
2740 map
= isl_map_read_from_str(ctx
,
2741 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2742 "i2 = 1 and j2 = j or "
2743 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2744 map
= isl_map_transitive_closure(map
, &exact
);
2748 map
= isl_map_read_from_str(ctx
,
2749 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2750 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2751 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2752 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2753 map
= isl_map_transitive_closure(map
, &exact
);
2757 /* Kelly et al 1996, fig 12 */
2758 map
= isl_map_read_from_str(ctx
,
2759 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2760 "1 <= i,j,j+1 <= n or "
2761 "j = n and j2 = 1 and i2 = i + 1 and "
2762 "1 <= i,i+1 <= n }");
2763 map
= isl_map_transitive_closure(map
, &exact
);
2765 map2
= isl_map_read_from_str(ctx
,
2766 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2767 "1 <= i <= n and i = i2 or "
2768 "1 <= i < i2 <= n and 1 <= j <= n and "
2770 assert(isl_map_is_equal(map
, map2
));
2774 /* Omega's closure4 */
2775 map
= isl_map_read_from_str(ctx
,
2776 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2777 "1 <= x,y <= 10 or "
2778 "x2 = x + 1 and y2 = y and "
2779 "1 <= x <= 20 && 5 <= y <= 15 }");
2780 map
= isl_map_transitive_closure(map
, &exact
);
2784 map
= isl_map_read_from_str(ctx
,
2785 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2786 map
= isl_map_transitive_closure(map
, &exact
);
2788 map2
= isl_map_read_from_str(ctx
,
2789 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2790 assert(isl_map_is_equal(map
, map2
));
2794 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2795 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2796 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2797 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2798 map
= isl_map_read_from_str(ctx
, str
);
2799 map
= isl_map_transitive_closure(map
, &exact
);
2801 map2
= isl_map_read_from_str(ctx
, str
);
2802 assert(isl_map_is_equal(map
, map2
));
2806 str
= "{[0] -> [1]; [2] -> [3]}";
2807 map
= isl_map_read_from_str(ctx
, str
);
2808 map
= isl_map_transitive_closure(map
, &exact
);
2810 map2
= isl_map_read_from_str(ctx
, str
);
2811 assert(isl_map_is_equal(map
, map2
));
2815 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2816 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2817 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2818 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2819 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2820 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2821 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2822 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2823 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2824 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2825 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2826 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2827 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2828 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2829 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2830 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2831 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2832 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2833 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2834 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2835 map
= isl_map_read_from_str(ctx
, str
);
2836 map
= isl_map_transitive_closure(map
, NULL
);
2843 /* Check that the actual result of a boolean operation is equal
2844 * to the expected result.
2846 static isl_stat
check_bool(isl_ctx
*ctx
, isl_bool actual
, isl_bool expected
)
2848 if (actual
!= expected
)
2849 isl_die(ctx
, isl_error_unknown
,
2850 "incorrect boolean operation", return isl_stat_error
);
2854 /* Test operations on isl_bool values.
2861 static int test_isl_bool(isl_ctx
*ctx
)
2863 if (check_bool(ctx
, isl_bool_not(isl_bool_true
), isl_bool_false
) < 0)
2865 if (check_bool(ctx
, isl_bool_not(isl_bool_false
), isl_bool_true
) < 0)
2867 if (check_bool(ctx
, isl_bool_not(isl_bool_error
), isl_bool_error
) < 0)
2869 if (check_bool(ctx
, isl_bool_ok(0), isl_bool_false
) < 0)
2871 if (check_bool(ctx
, isl_bool_ok(1), isl_bool_true
) < 0)
2873 if (check_bool(ctx
, isl_bool_ok(-1), isl_bool_true
) < 0)
2875 if (check_bool(ctx
, isl_bool_ok(2), isl_bool_true
) < 0)
2877 if (check_bool(ctx
, isl_bool_ok(-2), isl_bool_true
) < 0)
2883 static int test_lex(struct isl_ctx
*ctx
)
2889 space
= isl_space_set_alloc(ctx
, 0, 0);
2890 map
= isl_map_lex_le(space
);
2891 empty
= isl_map_is_empty(map
);
2897 isl_die(ctx
, isl_error_unknown
,
2898 "expecting non-empty result", return -1);
2903 /* Inputs for isl_map_lexmin tests.
2904 * "map" is the input and "lexmin" is the expected result.
2909 } lexmin_tests
[] = {
2910 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2911 "{ [x] -> [5] : 6 <= x <= 8; "
2912 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2913 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2914 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2915 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2916 "{ [x] -> [y] : (4y = x and x >= 0) or "
2917 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2918 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2919 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2920 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2921 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2922 /* Check that empty pieces are properly combined. */
2923 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2924 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2925 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2926 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2927 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2929 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2930 "a <= 255 and c <= 255 and d <= 255 - j and "
2931 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2932 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2933 "247d <= 247 + i and 248 - b <= 248d <= c and "
2934 "254d >= i - a + b and 254d >= -a + b and "
2935 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2937 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2938 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2939 "247j >= 62738 - i and 509j <= 129795 + i and "
2940 "742j >= 188724 - i; "
2941 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2942 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2943 "16*floor((8 + b)/16) <= 7 + b; "
2945 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2946 "[a] -> [b = 0] : 0 < a <= 509 }" },
2947 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2948 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2951 static int test_lexmin(struct isl_ctx
*ctx
)
2956 isl_basic_map
*bmap
;
2957 isl_map
*map
, *map2
;
2960 isl_pw_multi_aff
*pma
;
2962 str
= "[p0, p1] -> { [] -> [] : "
2963 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2964 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2965 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2966 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2967 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2968 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2969 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2970 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2971 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2972 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2973 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2974 map
= isl_map_read_from_str(ctx
, str
);
2975 map
= isl_map_lexmin(map
);
2980 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2981 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2982 set
= isl_set_read_from_str(ctx
, str
);
2983 set
= isl_set_lexmax(set
);
2984 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
2985 set2
= isl_set_read_from_str(ctx
, str
);
2986 set
= isl_set_intersect(set
, set2
);
2987 assert(!isl_set_is_empty(set
));
2990 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
2991 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
2992 map
= isl_map_lexmin(map
);
2993 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
2994 equal
= isl_map_is_equal(map
, map2
);
3001 isl_die(ctx
, isl_error_unknown
,
3002 "unexpected result", return -1);
3005 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3006 " 8i' <= i and 8i' >= -7 + i }";
3007 bmap
= isl_basic_map_read_from_str(ctx
, str
);
3008 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
3009 map2
= isl_map_from_pw_multi_aff(pma
);
3010 map
= isl_map_from_basic_map(bmap
);
3011 assert(isl_map_is_equal(map
, map2
));
3015 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3016 " 8i' <= i and 8i' >= -7 + i }";
3017 set
= isl_set_read_from_str(ctx
, str
);
3018 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
3019 set2
= isl_set_from_pw_multi_aff(pma
);
3020 equal
= isl_set_is_equal(set
, set2
);
3026 isl_die(ctx
, isl_error_unknown
,
3027 "unexpected difference between set and "
3028 "piecewise affine expression", return -1);
3033 /* A specialized isl_set_min_val test case that would return the wrong result
3034 * in earlier versions of isl.
3035 * The explicit call to isl_basic_set_union prevents the second basic set
3036 * from being determined to be empty prior to the call to isl_set_min_val,
3037 * at least at the point where this test case was introduced.
3039 static int test_min_special(isl_ctx
*ctx
)
3042 isl_basic_set
*bset1
, *bset2
;
3048 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
3049 bset1
= isl_basic_set_read_from_str(ctx
, str
);
3050 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
3051 bset2
= isl_basic_set_read_from_str(ctx
, str
);
3052 set
= isl_basic_set_union(bset1
, bset2
);
3053 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
3055 res
= isl_set_min_val(set
, obj
);
3056 ok
= isl_val_cmp_si(res
, 5) == 0;
3065 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
3071 /* A specialized isl_set_min_val test case that would return an error
3072 * in earlier versions of isl.
3074 static int test_min_special2(isl_ctx
*ctx
)
3077 isl_basic_set
*bset
;
3081 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
3082 bset
= isl_basic_set_read_from_str(ctx
, str
);
3084 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
3086 res
= isl_basic_set_max_val(bset
, obj
);
3088 isl_basic_set_free(bset
);
3101 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
3102 __isl_keep isl_aff
*obj
);
3105 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
3106 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
3107 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
3108 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
3109 &isl_set_max_val
, "30" },
3113 /* Perform basic isl_set_min_val and isl_set_max_val tests.
3114 * In particular, check the results on non-convex inputs.
3116 static int test_min(struct isl_ctx
*ctx
)
3124 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
3125 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
3126 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
3127 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
3128 val
= opt_tests
[i
].fn(set
, obj
);
3129 ok
= isl_val_eq(res
, val
);
3138 isl_die(ctx
, isl_error_unknown
,
3139 "unexpected optimum", return -1);
3142 if (test_min_special(ctx
) < 0)
3144 if (test_min_special2(ctx
) < 0)
3155 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
3156 void *dep_user
, void *user
)
3158 struct must_may
*mm
= (struct must_may
*)user
;
3161 mm
->must
= isl_map_union(mm
->must
, dep
);
3163 mm
->may
= isl_map_union(mm
->may
, dep
);
3168 static int common_space(void *first
, void *second
)
3170 int depth
= *(int *)first
;
3174 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
3182 map2
= isl_map_read_from_str(map
->ctx
, str
);
3183 equal
= isl_map_is_equal(map
, map2
);
3189 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
3193 equal
= map_is_equal(map
, str
);
3197 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
3198 "result not as expected", return -1);
3202 /* Is "set" equal to the set described by "str"?
3204 static isl_bool
set_is_equal(__isl_keep isl_set
*set
, const char *str
)
3210 return isl_bool_error
;
3212 set2
= isl_set_read_from_str(isl_set_get_ctx(set
), str
);
3213 equal
= isl_set_is_equal(set
, set2
);
3219 /* Check that "set" is equal to the set described by "str".
3221 static isl_stat
set_check_equal(__isl_keep isl_set
*set
, const char *str
)
3225 equal
= set_is_equal(set
, str
);
3227 return isl_stat_error
;
3229 isl_die(isl_set_get_ctx(set
), isl_error_unknown
,
3230 "result not as expected", return isl_stat_error
);
3234 /* Is "uset" equal to the union set described by "str"?
3236 static isl_bool
uset_is_equal(__isl_keep isl_union_set
*uset
, const char *str
)
3238 isl_union_set
*uset2
;
3242 return isl_bool_error
;
3244 uset2
= isl_union_set_read_from_str(isl_union_set_get_ctx(uset
), str
);
3245 equal
= isl_union_set_is_equal(uset
, uset2
);
3246 isl_union_set_free(uset2
);
3251 /* Check that "uset" is equal to the union set described by "str".
3253 static isl_stat
uset_check_equal(__isl_keep isl_union_set
*uset
,
3258 equal
= uset_is_equal(uset
, str
);
3260 return isl_stat_error
;
3262 isl_die(isl_union_set_get_ctx(uset
), isl_error_unknown
,
3263 "result not as expected", return isl_stat_error
);
3267 static int test_dep(struct isl_ctx
*ctx
)
3272 isl_access_info
*ai
;
3279 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3280 map
= isl_map_read_from_str(ctx
, str
);
3281 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3283 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3284 map
= isl_map_read_from_str(ctx
, str
);
3285 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3287 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3288 map
= isl_map_read_from_str(ctx
, str
);
3289 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3291 flow
= isl_access_info_compute_flow(ai
);
3292 space
= isl_space_alloc(ctx
, 0, 3, 3);
3293 mm
.must
= isl_map_empty(isl_space_copy(space
));
3294 mm
.may
= isl_map_empty(space
);
3296 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3298 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
3299 " [1,10,0] -> [2,5,0] }";
3300 assert(map_is_equal(mm
.must
, str
));
3301 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3302 assert(map_is_equal(mm
.may
, str
));
3304 isl_map_free(mm
.must
);
3305 isl_map_free(mm
.may
);
3306 isl_flow_free(flow
);
3309 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3310 map
= isl_map_read_from_str(ctx
, str
);
3311 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3313 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3314 map
= isl_map_read_from_str(ctx
, str
);
3315 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3317 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3318 map
= isl_map_read_from_str(ctx
, str
);
3319 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3321 flow
= isl_access_info_compute_flow(ai
);
3322 space
= isl_space_alloc(ctx
, 0, 3, 3);
3323 mm
.must
= isl_map_empty(isl_space_copy(space
));
3324 mm
.may
= isl_map_empty(space
);
3326 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3328 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
3329 assert(map_is_equal(mm
.must
, str
));
3330 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3331 assert(map_is_equal(mm
.may
, str
));
3333 isl_map_free(mm
.must
);
3334 isl_map_free(mm
.may
);
3335 isl_flow_free(flow
);
3338 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3339 map
= isl_map_read_from_str(ctx
, str
);
3340 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3342 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3343 map
= isl_map_read_from_str(ctx
, str
);
3344 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3346 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3347 map
= isl_map_read_from_str(ctx
, str
);
3348 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3350 flow
= isl_access_info_compute_flow(ai
);
3351 space
= isl_space_alloc(ctx
, 0, 3, 3);
3352 mm
.must
= isl_map_empty(isl_space_copy(space
));
3353 mm
.may
= isl_map_empty(space
);
3355 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3357 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
3358 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3359 assert(map_is_equal(mm
.may
, str
));
3360 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3361 assert(map_is_equal(mm
.must
, str
));
3363 isl_map_free(mm
.must
);
3364 isl_map_free(mm
.may
);
3365 isl_flow_free(flow
);
3368 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
3369 map
= isl_map_read_from_str(ctx
, str
);
3370 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3372 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3373 map
= isl_map_read_from_str(ctx
, str
);
3374 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3376 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3377 map
= isl_map_read_from_str(ctx
, str
);
3378 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3380 flow
= isl_access_info_compute_flow(ai
);
3381 space
= isl_space_alloc(ctx
, 0, 3, 3);
3382 mm
.must
= isl_map_empty(isl_space_copy(space
));
3383 mm
.may
= isl_map_empty(space
);
3385 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3387 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3388 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3389 assert(map_is_equal(mm
.may
, str
));
3390 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3391 assert(map_is_equal(mm
.must
, str
));
3393 isl_map_free(mm
.must
);
3394 isl_map_free(mm
.may
);
3395 isl_flow_free(flow
);
3398 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3399 map
= isl_map_read_from_str(ctx
, str
);
3400 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3402 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3403 map
= isl_map_read_from_str(ctx
, str
);
3404 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3406 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3407 map
= isl_map_read_from_str(ctx
, str
);
3408 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3410 flow
= isl_access_info_compute_flow(ai
);
3411 space
= isl_space_alloc(ctx
, 0, 3, 3);
3412 mm
.must
= isl_map_empty(isl_space_copy(space
));
3413 mm
.may
= isl_map_empty(space
);
3415 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3417 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3418 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3419 assert(map_is_equal(mm
.may
, str
));
3420 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3421 assert(map_is_equal(mm
.must
, str
));
3423 isl_map_free(mm
.must
);
3424 isl_map_free(mm
.may
);
3425 isl_flow_free(flow
);
3430 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3431 map
= isl_map_read_from_str(ctx
, str
);
3432 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
3434 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3435 map
= isl_map_read_from_str(ctx
, str
);
3436 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3438 flow
= isl_access_info_compute_flow(ai
);
3439 space
= isl_space_alloc(ctx
, 0, 5, 5);
3440 mm
.must
= isl_map_empty(isl_space_copy(space
));
3441 mm
.may
= isl_map_empty(space
);
3443 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3445 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3446 assert(map_is_equal(mm
.must
, str
));
3447 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3448 assert(map_is_equal(mm
.may
, str
));
3450 isl_map_free(mm
.must
);
3451 isl_map_free(mm
.may
);
3452 isl_flow_free(flow
);
3457 /* Check that the dependence analysis proceeds without errors.
3458 * Earlier versions of isl would break down during the analysis
3459 * due to the use of the wrong spaces.
3461 static int test_flow(isl_ctx
*ctx
)
3464 isl_union_map
*access
, *schedule
;
3465 isl_union_map
*must_dep
, *may_dep
;
3468 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3469 access
= isl_union_map_read_from_str(ctx
, str
);
3470 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3471 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3472 "S2[] -> [1,0,0,0]; "
3473 "S3[] -> [-1,0,0,0] }";
3474 schedule
= isl_union_map_read_from_str(ctx
, str
);
3475 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
3476 isl_union_map_copy(access
), schedule
,
3477 &must_dep
, &may_dep
, NULL
, NULL
);
3478 isl_union_map_free(may_dep
);
3479 isl_union_map_free(must_dep
);
3488 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3489 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3490 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3491 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3492 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3493 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3494 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3495 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3496 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3499 int test_sv(isl_ctx
*ctx
)
3501 isl_union_map
*umap
;
3505 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
3506 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
3507 sv
= isl_union_map_is_single_valued(umap
);
3508 isl_union_map_free(umap
);
3511 if (sv_tests
[i
].sv
&& !sv
)
3512 isl_die(ctx
, isl_error_internal
,
3513 "map not detected as single valued", return -1);
3514 if (!sv_tests
[i
].sv
&& sv
)
3515 isl_die(ctx
, isl_error_internal
,
3516 "map detected as single valued", return -1);
3525 } bijective_tests
[] = {
3526 { "[N,M]->{[i,j] -> [i]}", 0 },
3527 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3528 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3529 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3530 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3531 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3532 { "[N,M]->{[i,j] -> []}", 0 },
3533 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3534 { "[N,M]->{[i,j] -> [2i]}", 0 },
3535 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3536 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3537 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3538 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3541 static int test_bijective(struct isl_ctx
*ctx
)
3547 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
3548 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
3549 bijective
= isl_map_is_bijective(map
);
3553 if (bijective_tests
[i
].bijective
&& !bijective
)
3554 isl_die(ctx
, isl_error_internal
,
3555 "map not detected as bijective", return -1);
3556 if (!bijective_tests
[i
].bijective
&& bijective
)
3557 isl_die(ctx
, isl_error_internal
,
3558 "map detected as bijective", return -1);
3564 /* Inputs for isl_pw_qpolynomial_gist tests.
3565 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3571 } pwqp_gist_tests
[] = {
3572 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3573 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3574 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3575 "{ [i] -> -1/2 + 1/2 * i }" },
3576 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3579 /* Perform some basic isl_pw_qpolynomial_gist tests.
3581 static isl_stat
test_pwqp_gist(isl_ctx
*ctx
)
3586 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3589 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3590 str
= pwqp_gist_tests
[i
].pwqp
;
3591 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3592 str
= pwqp_gist_tests
[i
].set
;
3593 set
= isl_set_read_from_str(ctx
, str
);
3594 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3595 str
= pwqp_gist_tests
[i
].gist
;
3596 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3597 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3598 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3599 isl_pw_qpolynomial_free(pwqp1
);
3602 return isl_stat_error
;
3604 isl_die(ctx
, isl_error_unknown
,
3605 "unexpected result", return isl_stat_error
);
3611 /* Perform a basic isl_pw_qpolynomial_max test.
3613 static isl_stat
test_pwqp_max(isl_ctx
*ctx
)
3616 isl_pw_qpolynomial
*pwqp
;
3620 str
= "{ [x=2:9, y] -> floor((x + 1)/4)^3 - floor((2x)/3)^2 }";
3621 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3622 v
= isl_pw_qpolynomial_max(pwqp
);
3623 ok
= isl_val_cmp_si(v
, -1) == 0;
3627 return isl_stat_error
;
3629 isl_die(ctx
, isl_error_unknown
, "unexpected maximum",
3630 return isl_stat_error
);
3635 static int test_pwqp(struct isl_ctx
*ctx
)
3639 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3642 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3643 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3645 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3648 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3649 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3651 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3653 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3655 isl_pw_qpolynomial_free(pwqp1
);
3657 if (test_pwqp_gist(ctx
) < 0)
3660 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3661 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3662 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3663 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3665 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3667 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3669 isl_pw_qpolynomial_free(pwqp1
);
3671 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3672 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3673 str
= "{ [x] -> x }";
3674 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3676 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3678 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3680 isl_pw_qpolynomial_free(pwqp1
);
3682 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3683 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3684 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3685 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3686 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3687 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3688 isl_pw_qpolynomial_free(pwqp1
);
3690 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3691 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3692 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3693 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3694 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3695 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3696 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3697 isl_pw_qpolynomial_free(pwqp1
);
3698 isl_pw_qpolynomial_free(pwqp2
);
3702 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3704 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3705 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3706 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3707 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3708 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3710 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3711 isl_pw_qpolynomial_free(pwqp1
);
3712 isl_pw_qpolynomial_free(pwqp2
);
3716 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3718 if (test_pwqp_max(ctx
) < 0)
3724 static int test_split_periods(isl_ctx
*ctx
)
3727 isl_pw_qpolynomial
*pwqp
;
3729 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3730 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3731 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3732 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3734 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3736 isl_pw_qpolynomial_free(pwqp
);
3744 static int test_union(isl_ctx
*ctx
)
3747 isl_union_set
*uset1
, *uset2
;
3748 isl_union_map
*umap1
, *umap2
;
3751 str
= "{ [i] : 0 <= i <= 1 }";
3752 uset1
= isl_union_set_read_from_str(ctx
, str
);
3753 str
= "{ [1] -> [0] }";
3754 umap1
= isl_union_map_read_from_str(ctx
, str
);
3756 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3757 equal
= isl_union_map_is_equal(umap1
, umap2
);
3759 isl_union_map_free(umap1
);
3760 isl_union_map_free(umap2
);
3765 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3768 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3769 umap1
= isl_union_map_read_from_str(ctx
, str
);
3770 str
= "{ A[i]; B[i] }";
3771 uset1
= isl_union_set_read_from_str(ctx
, str
);
3773 uset2
= isl_union_map_domain(umap1
);
3775 equal
= isl_union_set_is_equal(uset1
, uset2
);
3777 isl_union_set_free(uset1
);
3778 isl_union_set_free(uset2
);
3783 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3789 /* Check that computing a bound of a non-zero polynomial over an unbounded
3790 * domain does not produce a rational value.
3791 * In particular, check that the upper bound is infinity.
3793 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
3796 isl_pw_qpolynomial
*pwqp
;
3797 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
3800 str
= "{ [m,n] -> -m * n }";
3801 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3802 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3804 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3805 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3806 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
3807 isl_pw_qpolynomial_fold_free(pwf
);
3808 isl_pw_qpolynomial_fold_free(pwf2
);
3813 isl_die(ctx
, isl_error_unknown
,
3814 "expecting infinite polynomial bound", return -1);
3819 static int test_bound(isl_ctx
*ctx
)
3823 isl_pw_qpolynomial
*pwqp
;
3824 isl_pw_qpolynomial_fold
*pwf
;
3826 if (test_bound_unbounded_domain(ctx
) < 0)
3829 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
3830 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3831 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3832 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3833 isl_pw_qpolynomial_fold_free(pwf
);
3837 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3840 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3841 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3842 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3843 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3844 isl_pw_qpolynomial_fold_free(pwf
);
3848 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3854 /* isl_set is defined to isl_map internally, so the corresponding elements
3855 * are isl_basic_map objects.
3859 #define EL_BASE basic_map
3860 #define SET_BASE set
3861 #include "isl_test_list_templ.c"
3865 #define EL_BASE basic_set
3866 #define SET_BASE union_set
3867 #include "isl_test_list_templ.c"
3872 #define SET_BASE union_set
3873 #include "isl_test_list_templ.c"
3877 #define EL_BASE basic_map
3878 #define SET_BASE map
3879 #include "isl_test_list_templ.c"
3884 #define SET_BASE union_map
3885 #include "isl_test_list_templ.c"
3887 /* Check that the conversion from isl objects to lists works as expected.
3889 static int test_get_list(isl_ctx
*ctx
)
3891 if (test_get_list_basic_map_from_set(ctx
, "{ [0]; [2]; [3] }"))
3893 if (test_get_list_basic_set_from_union_set(ctx
, "{ A[0]; B[2]; B[3] }"))
3895 if (test_get_list_set_from_union_set(ctx
, "{ A[0]; A[2]; B[3] }"))
3897 if (test_get_list_basic_map_from_map(ctx
,
3898 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"))
3900 if (test_get_list_map_from_union_map(ctx
,
3901 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"))
3907 static int test_lift(isl_ctx
*ctx
)
3910 isl_basic_map
*bmap
;
3911 isl_basic_set
*bset
;
3913 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
3914 bset
= isl_basic_set_read_from_str(ctx
, str
);
3915 bset
= isl_basic_set_lift(bset
);
3916 bmap
= isl_basic_map_from_range(bset
);
3917 bset
= isl_basic_map_domain(bmap
);
3918 isl_basic_set_free(bset
);
3923 /* Check that isl_set_is_subset is not confused by identical
3924 * integer divisions.
3925 * The call to isl_set_normalize ensures that the equality constraints
3926 * a = b = 0 are discovered, turning e0 and e1 into identical
3927 * integer divisions. Any further simplification would remove
3928 * the duplicate integer divisions.
3930 static isl_stat
test_subset_duplicate_integer_divisions(isl_ctx
*ctx
)
3934 isl_set
*set1
, *set2
;
3936 str
= "{ [a, b, c, d] : "
3937 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
3938 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
3939 "e3 = floor((-d + 4*floor((d)/4))/10): "
3940 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
3941 "b >= 0 and a <= 0 and b <= a) }";
3942 set1
= isl_set_read_from_str(ctx
, str
);
3943 set2
= isl_set_read_from_str(ctx
, str
);
3944 set2
= isl_set_normalize(set2
);
3946 is_subset
= isl_set_is_subset(set1
, set2
);
3952 return isl_stat_error
;
3954 isl_die(ctx
, isl_error_unknown
,
3955 "set is not considered to be a subset of itself",
3956 return isl_stat_error
);
3965 } subset_tests
[] = {
3967 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3968 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3969 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3971 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3972 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3973 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3974 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3975 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3976 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3977 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3978 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3979 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3980 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3981 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3982 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3983 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3984 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3985 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3986 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3987 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3988 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3989 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3990 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3991 "4e0 <= -57 + i0 + i1)) or "
3992 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3993 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3994 "4e0 >= -61 + i0 + i1)) or "
3995 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3996 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3999 static int test_subset(isl_ctx
*ctx
)
4002 isl_set
*set1
, *set2
;
4005 if (test_subset_duplicate_integer_divisions(ctx
) < 0)
4008 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
4009 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
4010 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
4011 subset
= isl_set_is_subset(set1
, set2
);
4016 if (subset
!= subset_tests
[i
].subset
)
4017 isl_die(ctx
, isl_error_unknown
,
4018 "incorrect subset result", return -1);
4024 /* Perform a set subtraction with a set that has a non-obviously empty disjunct.
4025 * Older versions of isl would fail on such cases.
4027 static isl_stat
test_subtract_empty(isl_ctx
*ctx
)
4032 s1
= isl_set_read_from_str(ctx
, "{ [0] }");
4033 str
= "{ [a] : (exists (e0, e1, e2: 1056e1 <= 32 + a - 33e0 and "
4034 "1089e1 >= a - 33e0 and 1089e1 <= 1 + a - 33e0 and "
4035 "33e2 >= -a + 33e0 + 1056e1 and "
4036 "33e2 < -2a + 66e0 + 2112e1)) or a = 0 }";
4037 s2
= isl_set_read_from_str(ctx
, str
);
4038 s1
= isl_set_subtract(s1
, s2
);
4041 return isl_stat_non_null(s1
);
4045 const char *minuend
;
4046 const char *subtrahend
;
4047 const char *difference
;
4048 } subtract_domain_tests
[] = {
4049 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
4050 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
4051 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
4054 static int test_subtract(isl_ctx
*ctx
)
4057 isl_union_map
*umap1
, *umap2
;
4058 isl_union_pw_multi_aff
*upma1
, *upma2
;
4059 isl_union_set
*uset
;
4062 if (test_subtract_empty(ctx
) < 0)
4065 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4066 umap1
= isl_union_map_read_from_str(ctx
,
4067 subtract_domain_tests
[i
].minuend
);
4068 uset
= isl_union_set_read_from_str(ctx
,
4069 subtract_domain_tests
[i
].subtrahend
);
4070 umap2
= isl_union_map_read_from_str(ctx
,
4071 subtract_domain_tests
[i
].difference
);
4072 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
4073 equal
= isl_union_map_is_equal(umap1
, umap2
);
4074 isl_union_map_free(umap1
);
4075 isl_union_map_free(umap2
);
4079 isl_die(ctx
, isl_error_unknown
,
4080 "incorrect subtract domain result", return -1);
4083 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4084 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4085 subtract_domain_tests
[i
].minuend
);
4086 uset
= isl_union_set_read_from_str(ctx
,
4087 subtract_domain_tests
[i
].subtrahend
);
4088 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4089 subtract_domain_tests
[i
].difference
);
4090 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
4091 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
4092 isl_union_pw_multi_aff_free(upma1
);
4093 isl_union_pw_multi_aff_free(upma2
);
4097 isl_die(ctx
, isl_error_unknown
,
4098 "incorrect subtract domain result", return -1);
4104 /* Check that intersecting the empty basic set with another basic set
4105 * does not increase the number of constraints. In particular,
4106 * the empty basic set should maintain its canonical representation.
4108 static int test_intersect_1(isl_ctx
*ctx
)
4111 isl_basic_set
*bset1
, *bset2
;
4113 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
4114 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
4115 n1
= isl_basic_set_n_constraint(bset1
);
4116 bset1
= isl_basic_set_intersect(bset1
, bset2
);
4117 n2
= isl_basic_set_n_constraint(bset1
);
4118 isl_basic_set_free(bset1
);
4119 if (n1
< 0 || n2
< 0)
4122 isl_die(ctx
, isl_error_unknown
,
4123 "number of constraints of empty set changed",
4129 /* Check that intersecting a set with itself does not cause
4130 * an explosion in the number of disjuncts.
4132 static isl_stat
test_intersect_2(isl_ctx
*ctx
)
4137 set
= isl_set_read_from_str(ctx
, "{ [x,y] : x >= 0 or y >= 0 }");
4138 for (i
= 0; i
< 100; ++i
)
4139 set
= isl_set_intersect(set
, isl_set_copy(set
));
4142 return isl_stat_error
;
4146 /* Perform some intersection tests.
4148 static int test_intersect(isl_ctx
*ctx
)
4150 if (test_intersect_1(ctx
) < 0)
4152 if (test_intersect_2(ctx
) < 0)
4158 int test_factorize(isl_ctx
*ctx
)
4161 isl_basic_set
*bset
;
4164 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
4165 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
4166 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
4167 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
4168 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
4169 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
4170 "3i5 >= -2i0 - i2 + 3i4 }";
4171 bset
= isl_basic_set_read_from_str(ctx
, str
);
4172 f
= isl_basic_set_factorizer(bset
);
4173 isl_basic_set_free(bset
);
4174 isl_factorizer_free(f
);
4176 isl_die(ctx
, isl_error_unknown
,
4177 "failed to construct factorizer", return -1);
4179 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
4180 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
4181 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
4182 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
4183 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
4184 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
4185 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
4186 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
4187 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
4188 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
4189 bset
= isl_basic_set_read_from_str(ctx
, str
);
4190 f
= isl_basic_set_factorizer(bset
);
4191 isl_basic_set_free(bset
);
4192 isl_factorizer_free(f
);
4194 isl_die(ctx
, isl_error_unknown
,
4195 "failed to construct factorizer", return -1);
4200 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
4202 int *injective
= user
;
4204 *injective
= isl_map_is_injective(map
);
4207 if (*injective
< 0 || !*injective
)
4208 return isl_stat_error
;
4213 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
4214 const char *r
, const char *s
, int tilable
, int parallel
)
4218 isl_union_map
*W
, *R
, *S
;
4219 isl_union_map
*empty
;
4220 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
4221 isl_union_map
*validity
, *proximity
, *coincidence
;
4222 isl_union_map
*schedule
;
4223 isl_union_map
*test
;
4224 isl_union_set
*delta
;
4225 isl_union_set
*domain
;
4229 isl_schedule_constraints
*sc
;
4230 isl_schedule
*sched
;
4231 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
4234 D
= isl_union_set_read_from_str(ctx
, d
);
4235 W
= isl_union_map_read_from_str(ctx
, w
);
4236 R
= isl_union_map_read_from_str(ctx
, r
);
4237 S
= isl_union_map_read_from_str(ctx
, s
);
4239 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
4240 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
4242 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
4243 isl_union_map_compute_flow(isl_union_map_copy(R
),
4244 isl_union_map_copy(W
), empty
,
4245 isl_union_map_copy(S
),
4246 &dep_raw
, NULL
, NULL
, NULL
);
4247 isl_union_map_compute_flow(isl_union_map_copy(W
),
4248 isl_union_map_copy(W
),
4249 isl_union_map_copy(R
),
4250 isl_union_map_copy(S
),
4251 &dep_waw
, &dep_war
, NULL
, NULL
);
4253 dep
= isl_union_map_union(dep_waw
, dep_war
);
4254 dep
= isl_union_map_union(dep
, dep_raw
);
4255 validity
= isl_union_map_copy(dep
);
4256 coincidence
= isl_union_map_copy(dep
);
4257 proximity
= isl_union_map_copy(dep
);
4259 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
4260 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4261 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
4262 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4263 sched
= isl_schedule_constraints_compute_schedule(sc
);
4264 schedule
= isl_schedule_get_map(sched
);
4265 isl_schedule_free(sched
);
4266 isl_union_map_free(W
);
4267 isl_union_map_free(R
);
4268 isl_union_map_free(S
);
4271 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
4273 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
4274 is_complete
= isl_union_set_is_subset(D
, domain
);
4275 isl_union_set_free(D
);
4276 isl_union_set_free(domain
);
4278 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
4279 test
= isl_union_map_apply_range(test
, dep
);
4280 test
= isl_union_map_apply_range(test
, schedule
);
4282 delta
= isl_union_map_deltas(test
);
4283 n
= isl_union_set_n_set(delta
);
4285 isl_union_set_free(delta
);
4292 isl_union_set_free(delta
);
4296 delta_set
= isl_set_from_union_set(delta
);
4298 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4299 for (i
= 0; i
< tilable
; ++i
)
4300 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
4301 is_tilable
= isl_set_is_subset(delta_set
, slice
);
4302 isl_set_free(slice
);
4304 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4305 for (i
= 0; i
< parallel
; ++i
)
4306 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
4307 is_parallel
= isl_set_is_subset(delta_set
, slice
);
4308 isl_set_free(slice
);
4310 origin
= isl_set_universe(isl_set_get_space(delta_set
));
4311 dim
= isl_set_dim(origin
, isl_dim_set
);
4313 origin
= isl_set_free(origin
);
4314 for (i
= 0; i
< dim
; ++i
)
4315 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
4317 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
4318 delta_set
= isl_set_lexmin(delta_set
);
4320 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
4322 isl_set_free(origin
);
4323 isl_set_free(delta_set
);
4326 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
4327 is_injection
< 0 || is_complete
< 0)
4330 isl_die(ctx
, isl_error_unknown
,
4331 "generated schedule incomplete", return -1);
4333 isl_die(ctx
, isl_error_unknown
,
4334 "generated schedule not injective on each statement",
4337 isl_die(ctx
, isl_error_unknown
,
4338 "negative dependences in generated schedule",
4341 isl_die(ctx
, isl_error_unknown
,
4342 "generated schedule not as tilable as expected",
4345 isl_die(ctx
, isl_error_unknown
,
4346 "generated schedule not as parallel as expected",
4352 /* Compute a schedule for the given instance set, validity constraints,
4353 * proximity constraints and context and return a corresponding union map
4356 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
4357 const char *domain
, const char *validity
, const char *proximity
,
4358 const char *context
)
4363 isl_union_map
*prox
;
4364 isl_schedule_constraints
*sc
;
4365 isl_schedule
*schedule
;
4366 isl_union_map
*sched
;
4368 con
= isl_set_read_from_str(ctx
, context
);
4369 dom
= isl_union_set_read_from_str(ctx
, domain
);
4370 dep
= isl_union_map_read_from_str(ctx
, validity
);
4371 prox
= isl_union_map_read_from_str(ctx
, proximity
);
4372 sc
= isl_schedule_constraints_on_domain(dom
);
4373 sc
= isl_schedule_constraints_set_context(sc
, con
);
4374 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
4375 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
4376 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4377 sched
= isl_schedule_get_map(schedule
);
4378 isl_schedule_free(schedule
);
4383 /* Compute a schedule for the given instance set, validity constraints and
4384 * proximity constraints and return a corresponding union map representation.
4386 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
4387 const char *domain
, const char *validity
, const char *proximity
)
4389 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
4393 /* Check that a schedule can be constructed on the given domain
4394 * with the given validity and proximity constraints.
4396 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
4397 const char *validity
, const char *proximity
)
4399 isl_union_map
*sched
;
4401 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
4405 isl_union_map_free(sched
);
4409 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
4410 const char *validity
, const char *proximity
, const char *expected_sched
)
4412 isl_union_map
*sched1
, *sched2
;
4415 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
4416 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
4418 equal
= isl_union_map_is_equal(sched1
, sched2
);
4419 isl_union_map_free(sched1
);
4420 isl_union_map_free(sched2
);
4425 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
4431 /* Check that the schedule map is properly padded, i.e., that the range
4432 * lives in a single space.
4434 static int test_padded_schedule(isl_ctx
*ctx
)
4438 isl_union_map
*validity
, *proximity
;
4439 isl_schedule_constraints
*sc
;
4440 isl_schedule
*sched
;
4441 isl_union_map
*umap
;
4442 isl_union_set
*range
;
4445 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4446 D
= isl_union_set_read_from_str(ctx
, str
);
4447 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
4448 proximity
= isl_union_map_copy(validity
);
4449 sc
= isl_schedule_constraints_on_domain(D
);
4450 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4451 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4452 sched
= isl_schedule_constraints_compute_schedule(sc
);
4453 umap
= isl_schedule_get_map(sched
);
4454 isl_schedule_free(sched
);
4455 range
= isl_union_map_range(umap
);
4456 set
= isl_set_from_union_set(range
);
4465 /* Check that conditional validity constraints are also taken into
4466 * account across bands.
4467 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4468 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4469 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4470 * is enforced by the rest of the schedule.
4472 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
4475 isl_union_set
*domain
;
4476 isl_union_map
*validity
, *proximity
, *condition
;
4477 isl_union_map
*sink
, *source
, *dep
;
4478 isl_schedule_constraints
*sc
;
4479 isl_schedule
*schedule
;
4480 isl_union_access_info
*access
;
4481 isl_union_flow
*flow
;
4484 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4485 "A[k] : k >= 1 and k <= -1 + n; "
4486 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4487 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4488 domain
= isl_union_set_read_from_str(ctx
, str
);
4489 sc
= isl_schedule_constraints_on_domain(domain
);
4490 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4491 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4492 "D[k, i] -> C[1 + k, i] : "
4493 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4494 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4495 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4496 validity
= isl_union_map_read_from_str(ctx
, str
);
4497 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4498 str
= "[n] -> { C[k, i] -> D[k, i] : "
4499 "0 <= i <= -1 + k and k <= -1 + n }";
4500 proximity
= isl_union_map_read_from_str(ctx
, str
);
4501 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4502 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4503 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4504 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4505 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4506 condition
= isl_union_map_read_from_str(ctx
, str
);
4507 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4508 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4509 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4510 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4511 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4512 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4513 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4514 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4515 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4516 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4517 validity
= isl_union_map_read_from_str(ctx
, str
);
4518 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4520 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4521 str
= "{ D[2,0] -> [] }";
4522 sink
= isl_union_map_read_from_str(ctx
, str
);
4523 access
= isl_union_access_info_from_sink(sink
);
4524 str
= "{ C[2,1] -> [] }";
4525 source
= isl_union_map_read_from_str(ctx
, str
);
4526 access
= isl_union_access_info_set_must_source(access
, source
);
4527 access
= isl_union_access_info_set_schedule(access
, schedule
);
4528 flow
= isl_union_access_info_compute_flow(access
);
4529 dep
= isl_union_flow_get_must_dependence(flow
);
4530 isl_union_flow_free(flow
);
4531 empty
= isl_union_map_is_empty(dep
);
4532 isl_union_map_free(dep
);
4537 isl_die(ctx
, isl_error_unknown
,
4538 "conditional validity not respected", return -1);
4543 /* Check that the test for violated conditional validity constraints
4544 * is not confused by domain compression.
4545 * In particular, earlier versions of isl would apply
4546 * a schedule on the compressed domains to the original domains,
4547 * resulting in a failure to detect that the default schedule
4548 * violates the conditional validity constraints.
4550 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
4554 isl_union_set
*domain
;
4555 isl_union_map
*validity
, *condition
;
4556 isl_schedule_constraints
*sc
;
4557 isl_schedule
*schedule
;
4558 isl_union_map
*umap
;
4561 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4562 domain
= isl_union_set_read_from_str(ctx
, str
);
4563 sc
= isl_schedule_constraints_on_domain(domain
);
4564 str
= "{ B[1, i] -> A[0, i + 1] }";
4565 condition
= isl_union_map_read_from_str(ctx
, str
);
4566 str
= "{ A[0, i] -> B[1, i - 1] }";
4567 validity
= isl_union_map_read_from_str(ctx
, str
);
4568 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4569 isl_union_map_copy(validity
));
4570 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4571 umap
= isl_schedule_get_map(schedule
);
4572 isl_schedule_free(schedule
);
4573 validity
= isl_union_map_apply_domain(validity
,
4574 isl_union_map_copy(umap
));
4575 validity
= isl_union_map_apply_range(validity
, umap
);
4576 map
= isl_map_from_union_map(validity
);
4577 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4578 map
= isl_map_intersect(map
, ge
);
4579 empty
= isl_map_is_empty(map
);
4585 isl_die(ctx
, isl_error_unknown
,
4586 "conditional validity constraints not satisfied",
4592 /* Input for testing of schedule construction based on
4593 * conditional constraints.
4595 * domain is the iteration domain
4596 * flow are the flow dependences, which determine the validity and
4597 * proximity constraints
4598 * condition are the conditions on the conditional validity constraints
4599 * conditional_validity are the conditional validity constraints
4600 * outer_band_n is the expected number of members in the outer band
4605 const char *condition
;
4606 const char *conditional_validity
;
4608 } live_range_tests
[] = {
4609 /* Contrived example that illustrates that we need to keep
4610 * track of tagged condition dependences and
4611 * tagged conditional validity dependences
4612 * in isl_sched_edge separately.
4613 * In particular, the conditional validity constraints on A
4614 * cannot be satisfied,
4615 * but they can be ignored because there are no corresponding
4616 * condition constraints. However, we do have an additional
4617 * conditional validity constraint that maps to the same
4618 * dependence relation
4619 * as the condition constraint on B. If we did not make a distinction
4620 * between tagged condition and tagged conditional validity
4621 * dependences, then we
4622 * could end up treating this shared dependence as an condition
4623 * constraint on A, forcing a localization of the conditions,
4624 * which is impossible.
4626 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4627 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4628 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4629 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4630 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4631 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4634 /* TACO 2013 Fig. 7 */
4635 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4636 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4637 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4638 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4639 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4640 "0 <= i < n and 0 <= j < n - 1 }",
4641 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4642 "0 <= i < n and 0 <= j < j' < n;"
4643 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4644 "0 <= i < i' < n and 0 <= j,j' < n;"
4645 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4646 "0 <= i,j,j' < n and j < j' }",
4649 /* TACO 2013 Fig. 7, without tags */
4650 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4651 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4652 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4653 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4654 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4655 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4656 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4657 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4660 /* TACO 2013 Fig. 12 */
4661 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4662 "S3[i,3] : 0 <= i <= 1 }",
4663 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4664 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4665 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4666 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4667 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4668 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4669 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4670 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4671 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4672 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4673 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4678 /* Test schedule construction based on conditional constraints.
4679 * In particular, check the number of members in the outer band node
4680 * as an indication of whether tiling is possible or not.
4682 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4685 isl_union_set
*domain
;
4686 isl_union_map
*condition
;
4687 isl_union_map
*flow
;
4688 isl_union_map
*validity
;
4689 isl_schedule_constraints
*sc
;
4690 isl_schedule
*schedule
;
4691 isl_schedule_node
*node
;
4694 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4696 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4699 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4700 domain
= isl_union_set_read_from_str(ctx
,
4701 live_range_tests
[i
].domain
);
4702 flow
= isl_union_map_read_from_str(ctx
,
4703 live_range_tests
[i
].flow
);
4704 condition
= isl_union_map_read_from_str(ctx
,
4705 live_range_tests
[i
].condition
);
4706 validity
= isl_union_map_read_from_str(ctx
,
4707 live_range_tests
[i
].conditional_validity
);
4708 sc
= isl_schedule_constraints_on_domain(domain
);
4709 sc
= isl_schedule_constraints_set_validity(sc
,
4710 isl_union_map_copy(flow
));
4711 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4712 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4713 condition
, validity
);
4714 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4715 node
= isl_schedule_get_root(schedule
);
4717 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4718 node
= isl_schedule_node_first_child(node
);
4719 n_member
= isl_schedule_node_band_n_member(node
);
4720 isl_schedule_node_free(node
);
4721 isl_schedule_free(schedule
);
4723 if (!schedule
|| n_member
< 0)
4725 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4726 isl_die(ctx
, isl_error_unknown
,
4727 "unexpected number of members in outer band",
4733 /* Check that the schedule computed for the given instance set and
4734 * dependence relation strongly satisfies the dependences.
4735 * In particular, check that no instance is scheduled before
4736 * or together with an instance on which it depends.
4737 * Earlier versions of isl would produce a schedule that
4738 * only weakly satisfies the dependences.
4740 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4742 const char *domain
, *dep
;
4743 isl_union_map
*D
, *schedule
;
4747 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4748 "A[i0] : 0 <= i0 <= 1 }";
4749 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4750 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4751 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
4752 D
= isl_union_map_read_from_str(ctx
, dep
);
4753 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
4754 D
= isl_union_map_apply_range(D
, schedule
);
4755 map
= isl_map_from_union_map(D
);
4756 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4757 map
= isl_map_intersect(map
, ge
);
4758 empty
= isl_map_is_empty(map
);
4764 isl_die(ctx
, isl_error_unknown
,
4765 "dependences not strongly satisfied", return -1);
4770 /* Compute a schedule for input where the instance set constraints
4771 * conflict with the context constraints.
4772 * Earlier versions of isl did not properly handle this situation.
4774 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
4776 isl_union_map
*schedule
;
4777 const char *domain
, *context
;
4779 domain
= "[n] -> { A[] : n >= 0 }";
4780 context
= "[n] -> { : n < 0 }";
4781 schedule
= compute_schedule_with_context(ctx
,
4782 domain
, "{}", "{}", context
);
4783 isl_union_map_free(schedule
);
4791 /* Check that a set of schedule constraints that only allow for
4792 * a coalescing schedule still produces a schedule even if the user
4793 * request a non-coalescing schedule. Earlier versions of isl
4794 * would not handle this case correctly.
4796 static int test_coalescing_schedule(isl_ctx
*ctx
)
4798 const char *domain
, *dep
;
4801 isl_schedule_constraints
*sc
;
4802 isl_schedule
*schedule
;
4803 int treat_coalescing
;
4805 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4806 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
4807 I
= isl_union_set_read_from_str(ctx
, domain
);
4808 D
= isl_union_map_read_from_str(ctx
, dep
);
4809 sc
= isl_schedule_constraints_on_domain(I
);
4810 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4811 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4812 isl_options_set_schedule_treat_coalescing(ctx
, 1);
4813 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4814 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4815 isl_schedule_free(schedule
);
4821 /* Check that the scheduler does not perform any needless
4822 * compound skewing. Earlier versions of isl would compute
4823 * schedules in terms of transformed schedule coefficients and
4824 * would not accurately keep track of the sum of the original
4825 * schedule coefficients. It could then produce the schedule
4826 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4827 * for the input below instead of the schedule below.
4829 static int test_skewing_schedule(isl_ctx
*ctx
)
4831 const char *D
, *V
, *P
, *S
;
4833 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4834 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4835 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4836 "-1 <= a-i + b-j + c-k <= 1 }";
4838 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4840 return test_special_schedule(ctx
, D
, V
, P
, S
);
4843 int test_schedule(isl_ctx
*ctx
)
4845 const char *D
, *W
, *R
, *V
, *P
, *S
;
4846 int max_coincidence
;
4847 int treat_coalescing
;
4849 /* Handle resulting schedule with zero bands. */
4850 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4854 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4855 W
= "{ S1[t,i] -> a[t,i] }";
4856 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4857 "S1[t,i] -> a[t-1,i+1] }";
4858 S
= "{ S1[t,i] -> [t,i] }";
4859 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4862 /* Fig. 5 of CC2008 */
4863 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4865 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4866 "j >= 2 and j <= -1 + N }";
4867 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4868 "j >= 2 and j <= -1 + N; "
4869 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4870 "j >= 2 and j <= -1 + N }";
4871 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4872 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4875 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4876 W
= "{ S1[i] -> a[i] }";
4877 R
= "{ S2[i] -> a[i+1] }";
4878 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4879 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4882 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4883 W
= "{ S1[i] -> a[i] }";
4884 R
= "{ S2[i] -> a[9-i] }";
4885 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4886 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4889 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4890 W
= "{ S1[i] -> a[i] }";
4891 R
= "[N] -> { S2[i] -> a[N-1-i] }";
4892 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4893 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4896 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4897 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4898 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4899 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4900 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4903 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4904 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4905 R
= "{ S2[i,j] -> a[i-1,j] }";
4906 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4907 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4910 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4911 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4912 R
= "{ S2[i,j] -> a[i,j-1] }";
4913 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4914 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4917 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4918 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4919 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4920 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4921 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4922 "S_0[] -> [0, 0, 0] }";
4923 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
4925 ctx
->opt
->schedule_parametric
= 0;
4926 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4928 ctx
->opt
->schedule_parametric
= 1;
4930 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4931 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4932 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4933 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4934 "S4[i] -> a[i,N] }";
4935 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4936 "S4[i] -> [4,i,0] }";
4937 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
4938 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
4939 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4941 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
4943 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4944 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4946 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4948 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4950 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4951 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4954 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4955 " S_2[t] : t >= 0 and t <= -1 + N; "
4956 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4958 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4959 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4960 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4961 "i >= 0 and i <= -1 + N }";
4962 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4963 "i >= 0 and i <= -1 + N; "
4964 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4965 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4966 " S_0[t] -> [0, t, 0] }";
4968 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4970 ctx
->opt
->schedule_parametric
= 0;
4971 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4973 ctx
->opt
->schedule_parametric
= 1;
4975 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4976 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4977 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
4980 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4981 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4982 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4983 "j >= 0 and j <= -1 + N; "
4984 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4985 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4986 "j >= 0 and j <= -1 + N; "
4987 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4988 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4989 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4992 D
= "{ S_0[i] : i >= 0 }";
4993 W
= "{ S_0[i] -> a[i] : i >= 0 }";
4994 R
= "{ S_0[i] -> a[0] : i >= 0 }";
4995 S
= "{ S_0[i] -> [0, i, 0] }";
4996 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4999 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
5000 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
5001 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
5002 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
5003 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5006 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
5007 "k <= -1 + n and k >= 0 }";
5008 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
5009 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
5010 "k <= -1 + n and k >= 0; "
5011 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
5012 "k <= -1 + n and k >= 0; "
5013 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
5014 "k <= -1 + n and k >= 0 }";
5015 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
5016 ctx
->opt
->schedule_outer_coincidence
= 1;
5017 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5019 ctx
->opt
->schedule_outer_coincidence
= 0;
5021 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
5022 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
5023 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
5024 "Stmt_for_body24[i0, i1, 1, 0]:"
5025 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
5026 "Stmt_for_body7[i0, i1, i2]:"
5027 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
5030 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
5031 "Stmt_for_body24[1, i1, i2, i3]:"
5032 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
5034 "Stmt_for_body24[0, i1, i2, i3] -> "
5035 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
5036 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
5038 "Stmt_for_body24[0, i1, i2, i3] ->"
5039 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
5040 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
5041 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
5042 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
5043 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
5044 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
5045 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
5046 "i1 <= 6 and i1 >= 0;"
5047 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
5048 "Stmt_for_body7[i0, i1, i2] -> "
5049 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
5050 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
5051 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
5052 "Stmt_for_body7[i0, i1, i2] -> "
5053 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
5054 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
5055 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
5058 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
5059 isl_options_set_schedule_treat_coalescing(ctx
, 0);
5060 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5062 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
5064 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
5065 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
5066 "j >= 1 and j <= 7;"
5067 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
5068 "j >= 1 and j <= 8 }";
5070 S
= "{ S_0[i, j] -> [i + j, i] }";
5071 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5072 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5074 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5076 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
5077 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
5078 "j >= 0 and j <= -1 + i }";
5079 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
5080 "i <= -1 + N and j >= 0;"
5081 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
5084 S
= "{ S_0[i, j] -> [i, j] }";
5085 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5086 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5088 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5090 /* Test both algorithms on a case with only proximity dependences. */
5091 D
= "{ S[i,j] : 0 <= i <= 10 }";
5093 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
5094 S
= "{ S[i, j] -> [j, i] }";
5095 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5096 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5098 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5099 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5102 D
= "{ A[a]; B[] }";
5104 P
= "{ A[a] -> B[] }";
5105 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5108 if (test_padded_schedule(ctx
) < 0)
5111 /* Check that check for progress is not confused by rational
5114 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
5115 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
5117 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
5118 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
5120 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5121 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5123 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5125 /* Check that we allow schedule rows that are only non-trivial
5126 * on some full-dimensional domains.
5128 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
5129 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
5130 "S1[j] -> S2[1] : 0 <= j <= 1 }";
5132 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5133 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5135 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5137 if (test_conditional_schedule_constraints(ctx
) < 0)
5140 if (test_strongly_satisfying_schedule(ctx
) < 0)
5143 if (test_conflicting_context_schedule(ctx
) < 0)
5146 if (test_coalescing_schedule(ctx
) < 0)
5148 if (test_skewing_schedule(ctx
) < 0)
5154 /* Perform scheduling tests using the whole component scheduler.
5156 static int test_schedule_whole(isl_ctx
*ctx
)
5161 whole
= isl_options_get_schedule_whole_component(ctx
);
5162 isl_options_set_schedule_whole_component(ctx
, 1);
5163 r
= test_schedule(ctx
);
5164 isl_options_set_schedule_whole_component(ctx
, whole
);
5169 /* Perform scheduling tests using the incremental scheduler.
5171 static int test_schedule_incremental(isl_ctx
*ctx
)
5176 whole
= isl_options_get_schedule_whole_component(ctx
);
5177 isl_options_set_schedule_whole_component(ctx
, 0);
5178 r
= test_schedule(ctx
);
5179 isl_options_set_schedule_whole_component(ctx
, whole
);
5184 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
5186 isl_union_map
*umap
;
5189 umap
= isl_union_map_read_from_str(ctx
, str
);
5190 test
= isl_union_map_plain_is_injective(umap
);
5191 isl_union_map_free(umap
);
5194 if (test
== injective
)
5197 isl_die(ctx
, isl_error_unknown
,
5198 "map not detected as injective", return -1);
5200 isl_die(ctx
, isl_error_unknown
,
5201 "map detected as injective", return -1);
5204 int test_injective(isl_ctx
*ctx
)
5208 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
5210 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
5212 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
5214 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
5216 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
5218 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
5220 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
5222 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
5225 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
5226 if (test_plain_injective(ctx
, str
, 1))
5228 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
5229 if (test_plain_injective(ctx
, str
, 0))
5237 #include "isl_test_plain_equal_templ.c"
5240 #define BASE pw_multi_aff
5241 #include "isl_test_plain_equal_templ.c"
5244 #define BASE union_pw_aff
5245 #include "isl_test_plain_equal_templ.c"
5247 /* Basic tests on isl_union_pw_aff.
5249 * In particular, check that isl_union_pw_aff_aff_on_domain
5250 * aligns the parameters of the input objects and
5251 * that isl_union_pw_aff_param_on_domain_id properly
5252 * introduces the parameter.
5254 static int test_upa(isl_ctx
*ctx
)
5259 isl_union_set
*domain
;
5260 isl_union_pw_aff
*upa
;
5263 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
5264 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5265 domain
= isl_union_set_read_from_str(ctx
, str
);
5266 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
5267 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5268 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5269 isl_union_pw_aff_free(upa
);
5273 id
= isl_id_alloc(ctx
, "N", NULL
);
5274 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5275 domain
= isl_union_set_read_from_str(ctx
, str
);
5276 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
5277 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5278 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5279 isl_union_pw_aff_free(upa
);
5287 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5288 __isl_take isl_aff
*aff2
);
5290 ['+'] = { &isl_aff_add
},
5291 ['-'] = { &isl_aff_sub
},
5292 ['*'] = { &isl_aff_mul
},
5293 ['/'] = { &isl_aff_div
},
5301 } aff_bin_tests
[] = {
5302 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5303 "{ [i] -> [2i] }" },
5304 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5306 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5307 "{ [i] -> [2i] }" },
5308 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5309 "{ [i] -> [2i] }" },
5310 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5311 "{ [i] -> [i/2] }" },
5312 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5314 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5315 "{ [i] -> [NaN] }" },
5316 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5317 "{ [i] -> [NaN] }" },
5318 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5319 "{ [i] -> [NaN] }" },
5320 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5321 "{ [i] -> [NaN] }" },
5322 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5323 "{ [i] -> [NaN] }" },
5324 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5325 "{ [i] -> [NaN] }" },
5326 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5327 "{ [i] -> [NaN] }" },
5328 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5329 "{ [i] -> [NaN] }" },
5330 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5331 "{ [i] -> [NaN] }" },
5332 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5333 "{ [i] -> [NaN] }" },
5334 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5335 "{ [i] -> [NaN] }" },
5336 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5337 "{ [i] -> [NaN] }" },
5340 /* Perform some basic tests of binary operations on isl_aff objects.
5342 static int test_bin_aff(isl_ctx
*ctx
)
5345 isl_aff
*aff1
, *aff2
, *res
;
5346 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5347 __isl_take isl_aff
*aff2
);
5350 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
5351 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
5352 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
5353 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
5354 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
5355 aff1
= fn(aff1
, aff2
);
5356 if (isl_aff_is_nan(res
))
5357 ok
= isl_aff_is_nan(aff1
);
5359 ok
= isl_aff_plain_is_equal(aff1
, res
);
5365 isl_die(ctx
, isl_error_unknown
,
5366 "unexpected result", return -1);
5373 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
5374 __isl_take isl_pw_aff
*pa2
);
5375 } pw_aff_bin_op
[] = {
5376 ['m'] = { &isl_pw_aff_min
},
5377 ['M'] = { &isl_pw_aff_max
},
5380 /* Inputs for binary isl_pw_aff operation tests.
5381 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5382 * defined by pw_aff_bin_op, and "res" is the expected result.
5389 } pw_aff_bin_tests
[] = {
5390 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5392 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5394 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5395 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5396 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5397 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5398 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5399 "{ [i] -> [NaN] }" },
5400 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5401 "{ [i] -> [NaN] }" },
5404 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5406 static int test_bin_pw_aff(isl_ctx
*ctx
)
5410 isl_pw_aff
*pa1
, *pa2
, *res
;
5412 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
5413 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
5414 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
5415 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
5416 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
5417 if (isl_pw_aff_involves_nan(res
))
5418 ok
= isl_pw_aff_involves_nan(pa1
);
5420 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
5421 isl_pw_aff_free(pa1
);
5422 isl_pw_aff_free(res
);
5426 isl_die(ctx
, isl_error_unknown
,
5427 "unexpected result", return -1);
5433 /* Inputs for basic tests of test operations on
5434 * isl_union_pw_multi_aff objects.
5435 * "fn" is the function that is being tested.
5436 * "arg" is a string description of the input.
5437 * "res" is the expected result.
5440 isl_bool (*fn
)(__isl_keep isl_union_pw_multi_aff
*upma1
);
5443 } upma_test_tests
[] = {
5444 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [1] }",
5446 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [NaN]; B[0] -> [1] }",
5448 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [NaN] }",
5450 { &isl_union_pw_multi_aff_involves_nan
,
5451 "{ A[] -> [0]; B[0] -> [1, NaN, 5] }",
5455 /* Perform some basic tests of test operations on
5456 * isl_union_pw_multi_aff objects.
5458 static isl_stat
test_upma_test(isl_ctx
*ctx
)
5461 isl_union_pw_multi_aff
*upma
;
5464 for (i
= 0; i
< ARRAY_SIZE(upma_test_tests
); ++i
) {
5467 str
= upma_test_tests
[i
].arg
;
5468 upma
= isl_union_pw_multi_aff_read_from_str(ctx
, str
);
5469 res
= upma_test_tests
[i
].fn(upma
);
5470 isl_union_pw_multi_aff_free(upma
);
5472 return isl_stat_error
;
5473 if (res
!= upma_test_tests
[i
].res
)
5474 isl_die(ctx
, isl_error_unknown
,
5475 "unexpected result", return isl_stat_error
);
5482 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5483 __isl_take isl_union_pw_multi_aff
*upma1
,
5484 __isl_take isl_union_pw_multi_aff
*upma2
);
5488 } upma_bin_tests
[] = {
5489 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
5490 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5491 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
5492 "{ B[x] -> [2] : x >= 0 }",
5493 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5494 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
5495 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5496 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5497 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5498 "D[i] -> B[2] : i >= 5 }" },
5499 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5500 "{ B[x] -> C[2] : x > 0 }",
5501 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5502 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5503 "{ B[x] -> A[2] : x >= 0 }",
5504 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5507 /* Perform some basic tests of binary operations on
5508 * isl_union_pw_multi_aff objects.
5510 static int test_bin_upma(isl_ctx
*ctx
)
5513 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
5516 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
5517 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5518 upma_bin_tests
[i
].arg1
);
5519 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5520 upma_bin_tests
[i
].arg2
);
5521 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5522 upma_bin_tests
[i
].res
);
5523 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
5524 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
5525 isl_union_pw_multi_aff_free(upma1
);
5526 isl_union_pw_multi_aff_free(res
);
5530 isl_die(ctx
, isl_error_unknown
,
5531 "unexpected result", return -1);
5538 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5539 __isl_take isl_union_pw_multi_aff
*upma1
,
5540 __isl_take isl_union_pw_multi_aff
*upma2
);
5543 } upma_bin_fail_tests
[] = {
5544 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5545 "{ B[x] -> C[2] : x >= 0 }" },
5548 /* Perform some basic tests of binary operations on
5549 * isl_union_pw_multi_aff objects that are expected to fail.
5551 static int test_bin_upma_fail(isl_ctx
*ctx
)
5554 isl_union_pw_multi_aff
*upma1
, *upma2
;
5557 on_error
= isl_options_get_on_error(ctx
);
5558 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5559 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5560 for (i
= 0; i
< n
; ++i
) {
5561 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5562 upma_bin_fail_tests
[i
].arg1
);
5563 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5564 upma_bin_fail_tests
[i
].arg2
);
5565 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5566 isl_union_pw_multi_aff_free(upma1
);
5570 isl_options_set_on_error(ctx
, on_error
);
5572 isl_die(ctx
, isl_error_unknown
,
5573 "operation not expected to succeed", return -1);
5578 /* Inputs for basic tests of binary operations on
5579 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5580 * "fn" is the function that is being tested.
5581 * "arg1" and "arg2" are string descriptions of the inputs.
5582 * "res" is a string description of the expected result.
5585 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5586 __isl_take isl_union_pw_multi_aff
*upma
,
5587 __isl_take isl_union_set
*uset
);
5591 } upma_uset_tests
[] = {
5592 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5593 "{ A[i] -> B[i] }", "{ B[0] }",
5595 { &isl_union_pw_multi_aff_intersect_domain_wrapped_domain
,
5596 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5597 "{ [A[1] -> B[1]] -> C[2] }" },
5598 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5599 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5600 "{ [A[0] -> B[0]] -> C[1] }" },
5601 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5602 "{ [A[i] -> B[i]] -> C[i + 1] }", "[N] -> { B[N] }",
5603 "[N] -> { [A[N] -> B[N]] -> C[N + 1] }" },
5604 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5605 "[M] -> { [A[M] -> B[M]] -> C[M + 1] }", "[N] -> { B[N] }",
5606 "[N, M] -> { [A[N] -> B[N]] -> C[N + 1] : N = M }" },
5607 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5608 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[]; [B[] -> A[]] -> E[] }",
5610 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[] }" },
5613 /* Perform some basic tests of binary operations on
5614 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5616 static isl_stat
test_upma_uset(isl_ctx
*ctx
)
5620 isl_union_pw_multi_aff
*upma
, *res
;
5621 isl_union_set
*uset
;
5623 for (i
= 0; i
< ARRAY_SIZE(upma_uset_tests
); ++i
) {
5624 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
5625 upma_uset_tests
[i
].arg1
);
5626 uset
= isl_union_set_read_from_str(ctx
,
5627 upma_uset_tests
[i
].arg2
);
5628 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5629 upma_uset_tests
[i
].res
);
5630 upma
= upma_uset_tests
[i
].fn(upma
, uset
);
5631 ok
= isl_union_pw_multi_aff_plain_is_equal(upma
, res
);
5632 isl_union_pw_multi_aff_free(upma
);
5633 isl_union_pw_multi_aff_free(res
);
5635 return isl_stat_error
;
5637 isl_die(ctx
, isl_error_unknown
,
5638 "unexpected result", return isl_stat_error
);
5644 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5645 * "fn" is the function that is tested.
5646 * "arg" is a string description of the input.
5647 * "res" is a string description of the expected result.
5650 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5653 } mpa_un_tests
[] = {
5654 { &isl_multi_pw_aff_range_factor_domain
,
5655 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5656 "{ A[x] -> B[(1 : x >= 5)] }" },
5657 { &isl_multi_pw_aff_range_factor_range
,
5658 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5659 "{ A[y] -> C[(2 : y <= 10)] }" },
5660 { &isl_multi_pw_aff_range_factor_domain
,
5661 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5662 "{ A[x] -> B[(1 : x >= 5)] }" },
5663 { &isl_multi_pw_aff_range_factor_range
,
5664 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5665 "{ A[y] -> C[] }" },
5666 { &isl_multi_pw_aff_range_factor_domain
,
5667 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5668 "{ A[x] -> B[] }" },
5669 { &isl_multi_pw_aff_range_factor_range
,
5670 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5671 "{ A[y] -> C[(2 : y <= 10)] }" },
5672 { &isl_multi_pw_aff_range_factor_domain
,
5673 "{ A[x] -> [B[] -> C[]] }",
5674 "{ A[x] -> B[] }" },
5675 { &isl_multi_pw_aff_range_factor_range
,
5676 "{ A[x] -> [B[] -> C[]] }",
5677 "{ A[y] -> C[] }" },
5678 { &isl_multi_pw_aff_factor_range
,
5681 { &isl_multi_pw_aff_range_factor_domain
,
5682 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5683 "{ A[x] -> B[] : x >= 0 }" },
5684 { &isl_multi_pw_aff_range_factor_range
,
5685 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5686 "{ A[y] -> C[] : y >= 0 }" },
5687 { &isl_multi_pw_aff_factor_range
,
5688 "[N] -> { [B[] -> C[]] : N >= 0 }",
5689 "[N] -> { C[] : N >= 0 }" },
5692 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5694 static int test_un_mpa(isl_ctx
*ctx
)
5698 isl_multi_pw_aff
*mpa
, *res
;
5700 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5701 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5702 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5703 mpa
= mpa_un_tests
[i
].fn(mpa
);
5704 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5705 isl_multi_pw_aff_free(mpa
);
5706 isl_multi_pw_aff_free(res
);
5710 isl_die(ctx
, isl_error_unknown
,
5711 "unexpected result", return -1);
5717 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5718 * "fn" is the function that is tested.
5719 * "arg1" and "arg2" are string descriptions of the inputs.
5720 * "res" is a string description of the expected result.
5723 __isl_give isl_multi_pw_aff
*(*fn
)(
5724 __isl_take isl_multi_pw_aff
*mpa1
,
5725 __isl_take isl_multi_pw_aff
*mpa2
);
5729 } mpa_bin_tests
[] = {
5730 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
5732 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
5733 "{ A[x] -> [(x : x <= 10)] }",
5734 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5735 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5736 "{ A[x] -> [] : x <= 10 }",
5737 "{ A[x] -> [] : 5 <= x <= 10 }" },
5738 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5739 "[N] -> { A[x] -> [] : x <= N }",
5740 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5741 { &isl_multi_pw_aff_add
,
5742 "[N] -> { A[x] -> [] : x <= N }",
5743 "{ A[x] -> [] : x >= 5 }",
5744 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5745 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5746 "{ A[y] -> C[(2 : y <= 10)] }",
5747 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5748 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5749 "{ A[y] -> C[2] : y <= 10 }",
5750 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5751 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5752 "[N] -> { A[y] -> C[2] : y <= N }",
5753 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5754 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
5755 "{ A[y] -> C[2] : y <= 10 }",
5756 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5757 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5758 "{ A[] -> [B[1] -> C[2]] }" },
5759 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5760 "{ A[] -> [B[] -> C[]] }" },
5761 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5762 "{ A[y] -> C[] : y <= 10 }",
5763 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5764 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
5765 "{ A[x] -> B[(1 : x >= 5)] }",
5766 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5767 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5768 "{ A[y] -> C[(2 : y <= 10)] }",
5769 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5770 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5771 "{ A[y] -> C[] : y <= 10 }",
5772 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5773 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
5774 "{ A[x] -> B[(1 : x >= 5)] }",
5775 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5776 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5777 "[N] -> { A[y] -> C[] : y <= N }",
5778 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5779 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
5780 "{ A[x] -> B[(1 : x >= 5)] }",
5781 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5782 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
5783 "{ A[y] -> C[] : y <= 10 }",
5784 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5785 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5786 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5787 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5788 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5789 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5790 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5791 "{ A[a,b] -> C[b + 2a] }" },
5792 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5793 "{ B[i,j] -> C[i + 2j] }",
5794 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5795 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5796 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5797 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5798 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5799 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5800 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5801 "{ B[i,j] -> C[] }",
5802 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5803 "{ A[a,b] -> C[] }" },
5804 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5805 "{ B[i,j] -> C[] : i > j }",
5806 "{ A[a,b] -> B[b,a] }",
5807 "{ A[a,b] -> C[] : b > a }" },
5808 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5809 "{ B[i,j] -> C[] : j > 5 }",
5810 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5811 "{ A[a,b] -> C[] : b > a > 5 }" },
5812 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5813 "[N] -> { B[i,j] -> C[] : j > N }",
5814 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5815 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5816 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5817 "[M,N] -> { B[] -> C[] : N > 5 }",
5818 "[M,N] -> { A[] -> B[] : M > N }",
5819 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5822 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5824 static int test_bin_mpa(isl_ctx
*ctx
)
5828 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
5830 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
5831 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
5832 mpa_bin_tests
[i
].arg1
);
5833 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
5834 mpa_bin_tests
[i
].arg2
);
5835 res
= isl_multi_pw_aff_read_from_str(ctx
,
5836 mpa_bin_tests
[i
].res
);
5837 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
5838 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
5839 isl_multi_pw_aff_free(mpa1
);
5840 isl_multi_pw_aff_free(res
);
5844 isl_die(ctx
, isl_error_unknown
,
5845 "unexpected result", return -1);
5851 /* Inputs for basic tests of unary operations on
5852 * isl_multi_union_pw_aff objects.
5853 * "fn" is the function that is tested.
5854 * "arg" is a string description of the input.
5855 * "res" is a string description of the expected result.
5858 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5859 __isl_take isl_multi_union_pw_aff
*mupa
);
5862 } mupa_un_tests
[] = {
5863 { &isl_multi_union_pw_aff_factor_range
,
5864 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5865 "C[{ A[] -> [2] }]" },
5866 { &isl_multi_union_pw_aff_factor_range
,
5867 "[B[] -> C[{ A[] -> [2] }]]",
5868 "C[{ A[] -> [2] }]" },
5869 { &isl_multi_union_pw_aff_factor_range
,
5870 "[B[{ A[] -> [1] }] -> C[]]",
5872 { &isl_multi_union_pw_aff_factor_range
,
5875 { &isl_multi_union_pw_aff_factor_range
,
5876 "([B[] -> C[]] : { A[x] : x >= 0 })",
5877 "(C[] : { A[x] : x >= 0 })" },
5878 { &isl_multi_union_pw_aff_factor_range
,
5879 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
5880 "[N] -> (C[] : { A[x] : x <= N })" },
5881 { &isl_multi_union_pw_aff_factor_range
,
5882 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
5883 "[N] -> (C[] : { : N >= 0 })" },
5886 /* Perform some basic tests of unary operations on
5887 * isl_multi_union_pw_aff objects.
5889 static int test_un_mupa(isl_ctx
*ctx
)
5893 isl_multi_union_pw_aff
*mupa
, *res
;
5895 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
5896 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
5897 mupa_un_tests
[i
].arg
);
5898 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
5899 mupa_un_tests
[i
].res
);
5900 mupa
= mupa_un_tests
[i
].fn(mupa
);
5901 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
5902 isl_multi_union_pw_aff_free(mupa
);
5903 isl_multi_union_pw_aff_free(res
);
5907 isl_die(ctx
, isl_error_unknown
,
5908 "unexpected result", return -1);
5914 /* Inputs for basic tests of binary operations on
5915 * isl_multi_union_pw_aff objects.
5916 * "fn" is the function that is tested.
5917 * "arg1" and "arg2" are string descriptions of the inputs.
5918 * "res" is a string description of the expected result.
5921 __isl_give isl_multi_union_pw_aff
*(*fn
)(
5922 __isl_take isl_multi_union_pw_aff
*mupa1
,
5923 __isl_take isl_multi_union_pw_aff
*mupa2
);
5927 } mupa_bin_tests
[] = {
5928 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5929 "[{ A[] -> [3] }]" },
5930 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5931 "[{ A[] -> [-1] }]" },
5932 { &isl_multi_union_pw_aff_add
,
5933 "[{ A[] -> [1]; B[] -> [4] }]",
5934 "[{ A[] -> [2]; C[] -> [5] }]",
5935 "[{ A[] -> [3] }]" },
5936 { &isl_multi_union_pw_aff_union_add
,
5937 "[{ A[] -> [1]; B[] -> [4] }]",
5938 "[{ A[] -> [2]; C[] -> [5] }]",
5939 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
5940 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5941 "[{ A[x] -> [(x)] : x <= 10 }]",
5942 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
5943 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5944 "([] : { A[x] : x <= 10 })",
5945 "([] : { A[x] : 5 <= x <= 10 })" },
5946 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
5947 "[N] -> ([] : { A[x] : x <= N })",
5948 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
5949 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
5950 "([] : { A[x] : x <= 10 })",
5951 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
5952 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
5953 "[{ A[x] -> [(x)] : x <= 10 }]",
5954 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
5955 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
5956 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
5957 "([] : { A[x] : x <= 10 })",
5958 "([] : { A[x] })" },
5959 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
5960 "[N] -> ([] : { A[x] : x >= N })",
5961 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
5962 { &isl_multi_union_pw_aff_union_add
,
5963 "[N] -> ([] : { A[] : N >= 0})",
5964 "[N] -> ([] : { A[] : N <= 0})",
5965 "[N] -> ([] : { A[] })" },
5966 { &isl_multi_union_pw_aff_union_add
,
5967 "[N] -> ([] : { A[] })",
5968 "[N] -> ([] : { : })",
5969 "[N] -> ([] : { : })" },
5970 { &isl_multi_union_pw_aff_union_add
,
5971 "[N] -> ([] : { : })",
5972 "[N] -> ([] : { A[] })",
5973 "[N] -> ([] : { : })" },
5974 { &isl_multi_union_pw_aff_union_add
,
5975 "[N] -> ([] : { : N >= 0})",
5976 "[N] -> ([] : { : N <= 0})",
5977 "[N] -> ([] : { : })" },
5978 { &isl_multi_union_pw_aff_range_product
,
5979 "B[{ A[] -> [1] }]",
5980 "C[{ A[] -> [2] }]",
5981 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
5982 { &isl_multi_union_pw_aff_range_product
,
5983 "(B[] : { A[x] : x >= 5 })",
5984 "(C[] : { A[x] : x <= 10 })",
5985 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
5986 { &isl_multi_union_pw_aff_range_product
,
5987 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5988 "(C[] : { A[x] : x <= 10 })",
5989 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
5990 { &isl_multi_union_pw_aff_range_product
,
5991 "(C[] : { A[x] : x <= 10 })",
5992 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5993 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
5994 { &isl_multi_union_pw_aff_range_product
,
5995 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5996 "[N] -> (C[] : { A[x] : x <= N })",
5997 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
5998 { &isl_multi_union_pw_aff_range_product
,
5999 "[N] -> (C[] : { A[x] : x <= N })",
6000 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6001 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
6002 { &isl_multi_union_pw_aff_range_product
,
6003 "B[{ A[] -> [1]; D[] -> [3] }]",
6004 "C[{ A[] -> [2] }]",
6005 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
6006 { &isl_multi_union_pw_aff_range_product
,
6009 "([B[] -> C[]] : { A[x] })" },
6010 { &isl_multi_union_pw_aff_range_product
,
6013 "([B[] -> C[]] : { A[x] })" },
6016 /* Perform some basic tests of binary operations on
6017 * isl_multi_union_pw_aff objects.
6019 static int test_bin_mupa(isl_ctx
*ctx
)
6023 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
6025 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
6026 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
6027 mupa_bin_tests
[i
].arg1
);
6028 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
6029 mupa_bin_tests
[i
].arg2
);
6030 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6031 mupa_bin_tests
[i
].res
);
6032 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
6033 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
6034 isl_multi_union_pw_aff_free(mupa1
);
6035 isl_multi_union_pw_aff_free(res
);
6039 isl_die(ctx
, isl_error_unknown
,
6040 "unexpected result", return -1);
6046 /* Inputs for basic tests of binary operations on
6047 * pairs of isl_multi_union_pw_aff and isl_set objects.
6048 * "fn" is the function that is tested.
6049 * "arg1" and "arg2" are string descriptions of the inputs.
6050 * "res" is a string description of the expected result.
6053 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6054 __isl_take isl_multi_union_pw_aff
*mupa
,
6055 __isl_take isl_set
*set
);
6059 } mupa_set_tests
[] = {
6060 { &isl_multi_union_pw_aff_intersect_range
,
6061 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
6062 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
6063 { &isl_multi_union_pw_aff_intersect_range
,
6064 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
6065 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
6066 { &isl_multi_union_pw_aff_intersect_range
,
6067 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
6068 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
6069 { &isl_multi_union_pw_aff_intersect_range
,
6070 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
6071 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
6072 { &isl_multi_union_pw_aff_intersect_range
,
6073 "C[]", "{ C[] }", "C[]" },
6074 { &isl_multi_union_pw_aff_intersect_range
,
6075 "[N] -> (C[] : { : N >= 0 })",
6077 "[N] -> (C[] : { : N >= 0 })" },
6078 { &isl_multi_union_pw_aff_intersect_range
,
6079 "(C[] : { A[a,b] })",
6081 "(C[] : { A[a,b] })" },
6082 { &isl_multi_union_pw_aff_intersect_range
,
6083 "[N] -> (C[] : { A[a,b] : a,b <= N })",
6085 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
6086 { &isl_multi_union_pw_aff_intersect_range
,
6088 "[N] -> { C[] : N >= 0 }",
6089 "[N] -> (C[] : { : N >= 0 })" },
6090 { &isl_multi_union_pw_aff_intersect_range
,
6091 "(C[] : { A[a,b] })",
6092 "[N] -> { C[] : N >= 0 }",
6093 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6094 { &isl_multi_union_pw_aff_intersect_range
,
6095 "[N] -> (C[] : { : N >= 0 })",
6096 "[N] -> { C[] : N < 1024 }",
6097 "[N] -> (C[] : { : 0 <= N < 1024 })" },
6098 { &isl_multi_union_pw_aff_intersect_params
,
6099 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
6100 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
6101 { &isl_multi_union_pw_aff_intersect_params
,
6102 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
6103 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
6104 { &isl_multi_union_pw_aff_intersect_params
,
6105 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
6106 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
6107 { &isl_multi_union_pw_aff_intersect_params
,
6108 "C[]", "[N] -> { : N >= 0 }",
6109 "[N] -> (C[] : { : N >= 0 })" },
6110 { &isl_multi_union_pw_aff_intersect_params
,
6111 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
6112 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6113 { &isl_multi_union_pw_aff_intersect_params
,
6114 "[N] -> (C[] : { A[a,N] })", "{ : }",
6115 "[N] -> (C[] : { A[a,N] })" },
6116 { &isl_multi_union_pw_aff_intersect_params
,
6117 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
6118 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
6121 /* Perform some basic tests of binary operations on
6122 * pairs of isl_multi_union_pw_aff and isl_set objects.
6124 static int test_mupa_set(isl_ctx
*ctx
)
6128 isl_multi_union_pw_aff
*mupa
, *res
;
6131 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
6132 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6133 mupa_set_tests
[i
].arg1
);
6134 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
6135 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6136 mupa_set_tests
[i
].res
);
6137 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
6138 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6139 isl_multi_union_pw_aff_free(mupa
);
6140 isl_multi_union_pw_aff_free(res
);
6144 isl_die(ctx
, isl_error_unknown
,
6145 "unexpected result", return -1);
6151 /* Inputs for basic tests of binary operations on
6152 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6153 * "fn" is the function that is tested.
6154 * "arg1" and "arg2" are string descriptions of the inputs.
6155 * "res" is a string description of the expected result.
6158 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6159 __isl_take isl_multi_union_pw_aff
*mupa
,
6160 __isl_take isl_union_set
*uset
);
6164 } mupa_uset_tests
[] = {
6165 { &isl_multi_union_pw_aff_intersect_domain
,
6166 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
6167 "C[{ B[i,i] -> [3i] }]" },
6168 { &isl_multi_union_pw_aff_intersect_domain
,
6169 "(C[] : { B[i,j] })", "{ B[i,i] }",
6170 "(C[] : { B[i,i] })" },
6171 { &isl_multi_union_pw_aff_intersect_domain
,
6172 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
6173 "[N] -> (C[] : { B[N,N] })" },
6174 { &isl_multi_union_pw_aff_intersect_domain
,
6175 "C[]", "{ B[i,i] }",
6176 "(C[] : { B[i,i] })" },
6177 { &isl_multi_union_pw_aff_intersect_domain
,
6178 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
6179 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
6182 /* Perform some basic tests of binary operations on
6183 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6185 static int test_mupa_uset(isl_ctx
*ctx
)
6189 isl_multi_union_pw_aff
*mupa
, *res
;
6190 isl_union_set
*uset
;
6192 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
6193 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6194 mupa_uset_tests
[i
].arg1
);
6195 uset
= isl_union_set_read_from_str(ctx
,
6196 mupa_uset_tests
[i
].arg2
);
6197 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6198 mupa_uset_tests
[i
].res
);
6199 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
6200 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6201 isl_multi_union_pw_aff_free(mupa
);
6202 isl_multi_union_pw_aff_free(res
);
6206 isl_die(ctx
, isl_error_unknown
,
6207 "unexpected result", return -1);
6213 /* Inputs for basic tests of binary operations on
6214 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6215 * "fn" is the function that is tested.
6216 * "arg1" and "arg2" are string descriptions of the inputs.
6217 * "res" is a string description of the expected result.
6220 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6221 __isl_take isl_multi_union_pw_aff
*mupa
,
6222 __isl_take isl_multi_aff
*ma
);
6226 } mupa_ma_tests
[] = {
6227 { &isl_multi_union_pw_aff_apply_multi_aff
,
6228 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6229 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6230 "{ C[a,b] -> D[b,a] }",
6231 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6232 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6233 { &isl_multi_union_pw_aff_apply_multi_aff
,
6234 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6235 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6236 "{ C[a,b] -> D[b,a] }",
6237 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6238 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6239 { &isl_multi_union_pw_aff_apply_multi_aff
,
6240 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6241 "[N] -> { C[a] -> D[a + N] }",
6242 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
6243 { &isl_multi_union_pw_aff_apply_multi_aff
,
6247 { &isl_multi_union_pw_aff_apply_multi_aff
,
6248 "[N] -> (C[] : { : N >= 0 })",
6250 "[N] -> (D[] : { : N >= 0 })" },
6251 { &isl_multi_union_pw_aff_apply_multi_aff
,
6253 "[N] -> { C[] -> D[N] }",
6254 "[N] -> D[{ [N] }]" },
6255 { &isl_multi_union_pw_aff_apply_multi_aff
,
6256 "(C[] : { A[i,j] : i >= j })",
6258 "(D[] : { A[i,j] : i >= j })" },
6259 { &isl_multi_union_pw_aff_apply_multi_aff
,
6260 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6262 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6263 { &isl_multi_union_pw_aff_apply_multi_aff
,
6264 "(C[] : { A[i,j] : i >= j })",
6265 "[N] -> { C[] -> D[N] }",
6266 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6269 /* Perform some basic tests of binary operations on
6270 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6272 static int test_mupa_ma(isl_ctx
*ctx
)
6276 isl_multi_union_pw_aff
*mupa
, *res
;
6279 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
6280 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6281 mupa_ma_tests
[i
].arg1
);
6282 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
6283 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6284 mupa_ma_tests
[i
].res
);
6285 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
6286 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6287 isl_multi_union_pw_aff_free(mupa
);
6288 isl_multi_union_pw_aff_free(res
);
6292 isl_die(ctx
, isl_error_unknown
,
6293 "unexpected result", return -1);
6299 /* Inputs for basic tests of binary operations on
6300 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6301 * "fn" is the function that is tested.
6302 * "arg1" and "arg2" are string descriptions of the inputs.
6303 * "res" is a string description of the expected result.
6306 __isl_give isl_union_pw_aff
*(*fn
)(
6307 __isl_take isl_multi_union_pw_aff
*mupa
,
6308 __isl_take isl_pw_aff
*pa
);
6312 } mupa_pa_tests
[] = {
6313 { &isl_multi_union_pw_aff_apply_pw_aff
,
6314 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6315 "[N] -> { C[a] -> [a + N] }",
6316 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
6317 { &isl_multi_union_pw_aff_apply_pw_aff
,
6318 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6319 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
6320 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6321 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
6322 { &isl_multi_union_pw_aff_apply_pw_aff
,
6324 "[N] -> { C[] -> [N] }",
6326 { &isl_multi_union_pw_aff_apply_pw_aff
,
6328 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6329 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
6330 { &isl_multi_union_pw_aff_apply_pw_aff
,
6331 "[N] -> (C[] : { : N >= 0 })",
6332 "[N] -> { C[] -> [N] }",
6333 "[N] -> { [N] : N >= 0 }" },
6334 { &isl_multi_union_pw_aff_apply_pw_aff
,
6335 "[N] -> (C[] : { : N >= 0 })",
6336 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6337 "[N] -> { [N] : N >= 0 }" },
6338 { &isl_multi_union_pw_aff_apply_pw_aff
,
6339 "[N] -> (C[] : { : N >= 0 })",
6341 "[N] -> { [0] : N >= 0 }" },
6342 { &isl_multi_union_pw_aff_apply_pw_aff
,
6343 "(C[] : { A[i,j] : i >= j })",
6344 "[N] -> { C[] -> [N] }",
6345 "[N] -> { A[i,j] -> [N] : i >= j }" },
6346 { &isl_multi_union_pw_aff_apply_pw_aff
,
6347 "(C[] : { A[i,j] : i >= j })",
6348 "[N] -> { C[] -> [N] : N >= 0 }",
6349 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6352 /* Perform some basic tests of binary operations on
6353 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6355 static int test_mupa_pa(isl_ctx
*ctx
)
6359 isl_multi_union_pw_aff
*mupa
;
6360 isl_union_pw_aff
*upa
, *res
;
6363 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
6364 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6365 mupa_pa_tests
[i
].arg1
);
6366 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
6367 res
= isl_union_pw_aff_read_from_str(ctx
,
6368 mupa_pa_tests
[i
].res
);
6369 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
6370 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
6371 isl_union_pw_aff_free(upa
);
6372 isl_union_pw_aff_free(res
);
6376 isl_die(ctx
, isl_error_unknown
,
6377 "unexpected result", return -1);
6383 /* Inputs for basic tests of binary operations on
6384 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6385 * "fn" is the function that is tested.
6386 * "arg1" and "arg2" are string descriptions of the inputs.
6387 * "res" is a string description of the expected result.
6390 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6391 __isl_take isl_multi_union_pw_aff
*mupa
,
6392 __isl_take isl_pw_multi_aff
*pma
);
6396 } mupa_pma_tests
[] = {
6397 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6398 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6399 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6400 "{ C[a,b] -> D[b,a] }",
6401 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6402 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6403 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6404 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6405 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6406 "{ C[a,b] -> D[b,a] }",
6407 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6408 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6409 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6410 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6411 "[N] -> { C[a] -> D[a + N] }",
6412 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6413 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6414 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6415 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6416 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6417 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6418 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6419 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6420 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6421 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6422 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6423 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6424 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6425 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6426 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6430 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6431 "[N] -> (C[] : { : N >= 0 })",
6433 "[N] -> (D[] : { : N >= 0 })" },
6434 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6436 "[N] -> { C[] -> D[N] }",
6437 "[N] -> D[{ [N] }]" },
6438 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6439 "(C[] : { A[i,j] : i >= j })",
6441 "(D[] : { A[i,j] : i >= j })" },
6442 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6443 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6445 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6446 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6447 "(C[] : { A[i,j] : i >= j })",
6448 "[N] -> { C[] -> D[N] }",
6449 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6450 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6452 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6453 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6454 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6455 "[N] -> (C[] : { : N >= 0 })",
6456 "[N] -> { C[] -> D[N] }",
6457 "[N] -> D[{ [N] : N >= 0 }]" },
6458 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6459 "[N] -> (C[] : { : N >= 0 })",
6460 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6461 "[N] -> D[{ [N] : N >= 0 }]" },
6462 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6463 "[N] -> (C[] : { : N >= 0 })",
6465 "[N] -> D[{ [0] : N >= 0 }]" },
6466 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6467 "(C[] : { A[i,j] : i >= j })",
6468 "[N] -> { C[] -> D[N] : N >= 0 }",
6469 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6472 /* Perform some basic tests of binary operations on
6473 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6475 static int test_mupa_pma(isl_ctx
*ctx
)
6479 isl_multi_union_pw_aff
*mupa
, *res
;
6480 isl_pw_multi_aff
*pma
;
6482 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
6483 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6484 mupa_pma_tests
[i
].arg1
);
6485 pma
= isl_pw_multi_aff_read_from_str(ctx
,
6486 mupa_pma_tests
[i
].arg2
);
6487 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6488 mupa_pma_tests
[i
].res
);
6489 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
6490 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6491 isl_multi_union_pw_aff_free(mupa
);
6492 isl_multi_union_pw_aff_free(res
);
6496 isl_die(ctx
, isl_error_unknown
,
6497 "unexpected result", return -1);
6503 /* Inputs for basic tests of binary operations on
6504 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6505 * "fn" is the function that is tested.
6506 * "arg1" and "arg2" are string descriptions of the inputs.
6507 * "res" is a string description of the expected result.
6510 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6511 __isl_take isl_multi_union_pw_aff
*mupa
,
6512 __isl_take isl_union_pw_multi_aff
*upma
);
6516 } mupa_upma_tests
[] = {
6517 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6518 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6519 "C[{ A[a,b] -> [b + 2a] }]" },
6520 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6521 "C[{ B[i,j] -> [i + 2j] }]",
6522 "{ A[a,b] -> B[b,a] : b > a }",
6523 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6524 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6525 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6526 "{ A[a,b] -> B[b,a] : b > a }",
6527 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6528 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6529 "C[{ B[i,j] -> [i + 2j] }]",
6530 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6531 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6532 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6533 "(C[] : { B[a,b] })",
6534 "{ A[a,b] -> B[b,a] }",
6535 "(C[] : { A[a,b] })" },
6536 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6537 "(C[] : { B[a,b] })",
6538 "{ B[a,b] -> A[b,a] }",
6540 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6541 "(C[] : { B[a,b] })",
6542 "{ A[a,b] -> B[b,a] : a > b }",
6543 "(C[] : { A[a,b] : a > b })" },
6544 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6545 "(C[] : { B[a,b] : a > b })",
6546 "{ A[a,b] -> B[b,a] }",
6547 "(C[] : { A[a,b] : b > a })" },
6548 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6549 "[N] -> (C[] : { B[a,b] : a > N })",
6550 "{ A[a,b] -> B[b,a] : a > b }",
6551 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6552 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6553 "(C[] : { B[a,b] : a > b })",
6554 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6555 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6556 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6558 "{ A[a,b] -> B[b,a] }",
6560 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6561 "[N] -> (C[] : { : N >= 0 })",
6562 "{ A[a,b] -> B[b,a] }",
6563 "[N] -> (C[] : { : N >= 0 })" },
6564 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6566 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6567 "[N] -> (C[] : { : N >= 0 })" },
6570 /* Perform some basic tests of binary operations on
6571 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6573 static int test_mupa_upma(isl_ctx
*ctx
)
6577 isl_multi_union_pw_aff
*mupa
, *res
;
6578 isl_union_pw_multi_aff
*upma
;
6580 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
6581 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6582 mupa_upma_tests
[i
].arg1
);
6583 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
6584 mupa_upma_tests
[i
].arg2
);
6585 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6586 mupa_upma_tests
[i
].res
);
6587 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
6588 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6589 isl_multi_union_pw_aff_free(mupa
);
6590 isl_multi_union_pw_aff_free(res
);
6594 isl_die(ctx
, isl_error_unknown
,
6595 "unexpected result", return -1);
6601 /* Check that the input tuple of an isl_aff can be set properly.
6603 static isl_stat
test_aff_set_tuple_id(isl_ctx
*ctx
)
6609 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x + 1] }");
6610 id
= isl_id_alloc(ctx
, "A", NULL
);
6611 aff
= isl_aff_set_tuple_id(aff
, isl_dim_in
, id
);
6612 equal
= aff_check_plain_equal(aff
, "{ A[x] -> [x + 1] }");
6615 return isl_stat_error
;
6620 /* Check that affine expressions get normalized on addition/subtraction.
6621 * In particular, check that (final) unused integer divisions get removed
6622 * such that an expression derived from expressions with integer divisions
6623 * is found to be obviously equal to one that is created directly.
6625 static isl_stat
test_aff_normalize(isl_ctx
*ctx
)
6627 isl_aff
*aff
, *aff2
;
6630 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x//2] }");
6631 aff2
= isl_aff_read_from_str(ctx
, "{ [x] -> [1 + x//2] }");
6632 aff
= isl_aff_sub(aff2
, aff
);
6633 ok
= aff_check_plain_equal(aff
, "{ [x] -> [1] }");
6639 int test_aff(isl_ctx
*ctx
)
6644 isl_local_space
*ls
;
6649 if (test_upa(ctx
) < 0)
6651 if (test_bin_aff(ctx
) < 0)
6653 if (test_bin_pw_aff(ctx
) < 0)
6655 if (test_upma_test(ctx
) < 0)
6657 if (test_bin_upma(ctx
) < 0)
6659 if (test_bin_upma_fail(ctx
) < 0)
6661 if (test_upma_uset(ctx
) < 0)
6663 if (test_un_mpa(ctx
) < 0)
6665 if (test_bin_mpa(ctx
) < 0)
6667 if (test_un_mupa(ctx
) < 0)
6669 if (test_bin_mupa(ctx
) < 0)
6671 if (test_mupa_set(ctx
) < 0)
6673 if (test_mupa_uset(ctx
) < 0)
6675 if (test_mupa_ma(ctx
) < 0)
6677 if (test_mupa_pa(ctx
) < 0)
6679 if (test_mupa_pma(ctx
) < 0)
6681 if (test_mupa_upma(ctx
) < 0)
6684 space
= isl_space_set_alloc(ctx
, 0, 1);
6685 ls
= isl_local_space_from_space(space
);
6686 aff
= isl_aff_zero_on_domain(ls
);
6688 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6689 aff
= isl_aff_scale_down_ui(aff
, 3);
6690 aff
= isl_aff_floor(aff
);
6691 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6692 aff
= isl_aff_scale_down_ui(aff
, 2);
6693 aff
= isl_aff_floor(aff
);
6694 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6697 set
= isl_set_read_from_str(ctx
, str
);
6698 aff
= isl_aff_gist(aff
, set
);
6700 aff
= isl_aff_add_constant_si(aff
, -16);
6701 zero
= isl_aff_plain_is_zero(aff
);
6707 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6709 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6710 aff
= isl_aff_scale_down_ui(aff
, 64);
6711 aff
= isl_aff_floor(aff
);
6712 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6717 if (test_aff_set_tuple_id(ctx
) < 0)
6719 if (test_aff_normalize(ctx
) < 0)
6725 /* Inputs for isl_set_bind tests.
6726 * "set" is the input set.
6727 * "tuple" is the binding tuple.
6728 * "res" is the expected result.
6735 } bind_set_tests
[] = {
6736 { "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6738 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6739 { "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }",
6741 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6742 { "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }",
6744 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6745 { "[M] -> { D[x, N] : x mod 2 = 0 and N mod 8 = 3 and M >= 0 }",
6747 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 and M >= 0 }" },
6750 /* Perform basic isl_set_bind tests.
6752 static isl_stat
test_bind_set(isl_ctx
*ctx
)
6756 for (i
= 0; i
< ARRAY_SIZE(bind_set_tests
); ++i
) {
6759 isl_multi_id
*tuple
;
6762 set
= isl_set_read_from_str(ctx
, bind_set_tests
[i
].set
);
6763 str
= bind_set_tests
[i
].tuple
;
6764 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6765 set
= isl_set_bind(set
, tuple
);
6766 r
= set_check_equal(set
, bind_set_tests
[i
].res
);
6769 return isl_stat_error
;
6775 /* Inputs for isl_map_bind_domain tests.
6776 * "map" is the input map.
6777 * "tuple" is the binding tuple.
6778 * "res" is the expected result.
6784 } bind_map_domain_tests
[] = {
6785 { "{ A[M, N] -> [M + floor(N/2)] }",
6787 "[M, N] -> { [M + floor(N/2)] }" },
6788 { "{ B[N, M] -> [M + floor(N/2)] }",
6790 "[N, M] -> { [M + floor(N/2)] }" },
6791 { "[M] -> { C[N] -> [M + floor(N/2)] }",
6793 "[M, N] -> { [M + floor(N/2)] }" },
6794 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
6796 "[M, N] -> { [M + floor(N/2)] }" },
6797 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
6799 "[M, N] -> { [M + floor(N/2)] }" },
6800 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
6802 "[A, N, M] -> { [M + floor(N/2)] }" },
6805 /* Perform basic isl_map_bind_domain tests.
6807 static isl_stat
test_bind_map_domain(isl_ctx
*ctx
)
6811 for (i
= 0; i
< ARRAY_SIZE(bind_map_domain_tests
); ++i
) {
6815 isl_multi_id
*tuple
;
6818 str
= bind_map_domain_tests
[i
].map
;
6819 map
= isl_map_read_from_str(ctx
, str
);
6820 str
= bind_map_domain_tests
[i
].tuple
;
6821 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6822 set
= isl_map_bind_domain(map
, tuple
);
6823 str
= bind_map_domain_tests
[i
].res
;
6824 r
= set_check_equal(set
, str
);
6827 return isl_stat_error
;
6833 /* Inputs for isl_union_map_bind_range tests.
6834 * "map" is the input union map.
6835 * "tuple" is the binding tuple.
6836 * "res" is the expected result.
6842 } bind_umap_range_tests
[] = {
6843 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6845 "[M, N] -> { B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
6846 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6849 { "{ A[] -> B[]; C[] -> D[]; E[] -> B[] }",
6854 /* Perform basic isl_union_map_bind_range tests.
6856 static isl_stat
test_bind_umap_range(isl_ctx
*ctx
)
6860 for (i
= 0; i
< ARRAY_SIZE(bind_umap_range_tests
); ++i
) {
6862 isl_union_map
*umap
;
6863 isl_union_set
*uset
;
6864 isl_multi_id
*tuple
;
6867 str
= bind_umap_range_tests
[i
].map
;
6868 umap
= isl_union_map_read_from_str(ctx
, str
);
6869 str
= bind_umap_range_tests
[i
].tuple
;
6870 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6871 uset
= isl_union_map_bind_range(umap
, tuple
);
6872 str
= bind_umap_range_tests
[i
].res
;
6873 r
= uset_check_equal(uset
, str
);
6874 isl_union_set_free(uset
);
6876 return isl_stat_error
;
6882 /* Inputs for isl_pw_multi_aff_bind_domain tests.
6883 * "pma" is the input expression.
6884 * "tuple" is the binding tuple.
6885 * "res" is the expected result.
6891 } bind_pma_domain_tests
[] = {
6892 { "{ A[M, N] -> [M + floor(N/2)] }",
6894 "[M, N] -> { [M + floor(N/2)] }" },
6895 { "{ B[N, M] -> [M + floor(N/2)] }",
6897 "[N, M] -> { [M + floor(N/2)] }" },
6898 { "[M] -> { C[N] -> [M + floor(N/2)] }",
6900 "[M, N] -> { [M + floor(N/2)] }" },
6901 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
6903 "[M, N] -> { [M + floor(N/2)] }" },
6904 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
6906 "[M, N] -> { [M + floor(N/2)] }" },
6907 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
6909 "[A, N, M] -> { [M + floor(N/2)] }" },
6912 /* Perform basic isl_pw_multi_aff_bind_domain tests.
6914 static isl_stat
test_bind_pma_domain(isl_ctx
*ctx
)
6918 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_tests
); ++i
) {
6920 isl_pw_multi_aff
*pma
;
6921 isl_multi_id
*tuple
;
6924 str
= bind_pma_domain_tests
[i
].pma
;
6925 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6926 str
= bind_pma_domain_tests
[i
].tuple
;
6927 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6928 pma
= isl_pw_multi_aff_bind_domain(pma
, tuple
);
6929 str
= bind_pma_domain_tests
[i
].res
;
6930 r
= pw_multi_aff_check_plain_equal(pma
, str
);
6931 isl_pw_multi_aff_free(pma
);
6933 return isl_stat_error
;
6939 /* Inputs for isl_pw_multi_aff_bind_domain_wrapped_domain tests.
6940 * "pma" is the input expression.
6941 * "tuple" is the binding tuple.
6942 * "res" is the expected result.
6948 } bind_pma_domain_wrapped_tests
[] = {
6949 { "{ [A[M, N] -> B[]] -> [M + floor(N/2)] }",
6951 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
6952 { "{ [B[N, M] -> D[]] -> [M + floor(N/2)] }",
6954 "[N, M] -> { D[] -> [M + floor(N/2)] }" },
6955 { "[M] -> { [C[N] -> B[x]] -> [x + M + floor(N/2)] }",
6957 "[M, N] -> { B[x] -> [x + M + floor(N/2)] }" },
6958 { "[M] -> { [C[x, N] -> B[]] -> [x + floor(N/2)] }",
6960 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
6961 { "[M] -> { [C[x, N] -> B[]] -> [M + floor(N/2)] }",
6963 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
6964 { "[A, M] -> { [C[N, x] -> B[]] -> [x + floor(N/2)] }",
6966 "[A, N, M] -> { B[] -> [M + floor(N/2)] }" },
6969 /* Perform basic isl_pw_multi_aff_bind_domain_wrapped_domain tests.
6971 static isl_stat
test_bind_pma_domain_wrapped(isl_ctx
*ctx
)
6975 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_wrapped_tests
); ++i
) {
6977 isl_pw_multi_aff
*pma
;
6978 isl_multi_id
*tuple
;
6981 str
= bind_pma_domain_wrapped_tests
[i
].pma
;
6982 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6983 str
= bind_pma_domain_wrapped_tests
[i
].tuple
;
6984 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6985 pma
= isl_pw_multi_aff_bind_domain_wrapped_domain(pma
, tuple
);
6986 str
= bind_pma_domain_wrapped_tests
[i
].res
;
6987 r
= pw_multi_aff_check_plain_equal(pma
, str
);
6988 isl_pw_multi_aff_free(pma
);
6990 return isl_stat_error
;
6996 /* Inputs for isl_aff_bind_id tests.
6997 * "aff" is the input expression.
6998 * "id" is the binding id.
6999 * "res" is the expected result.
7006 } bind_aff_tests
[] = {
7007 { "{ [4] }", "M", "[M = 4] -> { : }" },
7008 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7009 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7010 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7011 { "{ [NaN] }", "M", "{ : false }" },
7012 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7015 /* Perform basic isl_aff_bind_id tests.
7017 static isl_stat
test_bind_aff(isl_ctx
*ctx
)
7021 for (i
= 0; i
< ARRAY_SIZE(bind_aff_tests
); ++i
) {
7027 aff
= isl_aff_read_from_str(ctx
, bind_aff_tests
[i
].aff
);
7028 id
= isl_id_read_from_str(ctx
, bind_aff_tests
[i
].id
);
7029 res
= isl_set_from_basic_set(isl_aff_bind_id(aff
, id
));
7030 r
= set_check_equal(res
, bind_aff_tests
[i
].res
);
7033 return isl_stat_error
;
7039 /* Inputs for isl_pw_aff_bind_id tests.
7040 * "pa" is the input expression.
7041 * "id" is the binding id.
7042 * "res" is the expected result.
7049 } bind_pa_tests
[] = {
7050 { "{ [4] }", "M", "[M = 4] -> { : }" },
7051 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7052 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7053 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7054 { "[M] -> { [M] : M >= 0; [-M] : M < 0 }", "M", "[M] -> { : M >= 0 }" },
7055 { "{ [NaN] }", "M", "{ : false }" },
7056 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7059 /* Perform basic isl_pw_aff_bind_id tests.
7061 static isl_stat
test_bind_pa(isl_ctx
*ctx
)
7065 for (i
= 0; i
< ARRAY_SIZE(bind_pa_tests
); ++i
) {
7071 pa
= isl_pw_aff_read_from_str(ctx
, bind_pa_tests
[i
].pa
);
7072 id
= isl_id_read_from_str(ctx
, bind_pa_tests
[i
].id
);
7073 res
= isl_pw_aff_bind_id(pa
, id
);
7074 r
= set_check_equal(res
, bind_pa_tests
[i
].res
);
7077 return isl_stat_error
;
7083 /* Inputs for isl_multi_union_pw_aff_bind tests.
7084 * "mupa" is the input expression.
7085 * "tuple" is the binding tuple.
7086 * "res" is the expected result.
7093 } bind_mupa_tests
[] = {
7094 { "A[{ [4] }, { [5] }]",
7096 "[M = 4, N = 5] -> { : }" },
7097 { "A[{ B[x] -> [floor(x/2)] }, { B[y] -> [y + 5] }]",
7099 "[M, N] -> { B[x] : M = floor(x/2) and N = x + 5 }" },
7100 { "[M] -> A[{ [4] }, { [M + 1] }]",
7102 "[M = 4, N = 5] -> { : }" },
7105 /* Perform basic isl_multi_union_pw_aff_bind tests.
7107 static isl_stat
test_bind_mupa(isl_ctx
*ctx
)
7111 for (i
= 0; i
< ARRAY_SIZE(bind_mupa_tests
); ++i
) {
7113 isl_multi_union_pw_aff
*mupa
;
7115 isl_multi_id
*tuple
;
7118 str
= bind_mupa_tests
[i
].mupa
;
7119 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
7120 str
= bind_mupa_tests
[i
].tuple
;
7121 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7122 res
= isl_multi_union_pw_aff_bind(mupa
, tuple
);
7123 r
= uset_check_equal(res
, bind_mupa_tests
[i
].res
);
7124 isl_union_set_free(res
);
7126 return isl_stat_error
;
7132 /* Perform tests that reinterpret dimensions as parameters.
7134 static int test_bind(isl_ctx
*ctx
)
7136 if (test_bind_set(ctx
) < 0)
7138 if (test_bind_map_domain(ctx
) < 0)
7140 if (test_bind_umap_range(ctx
) < 0)
7142 if (test_bind_pma_domain(ctx
) < 0)
7144 if (test_bind_pma_domain_wrapped(ctx
) < 0)
7146 if (test_bind_aff(ctx
) < 0)
7148 if (test_bind_pa(ctx
) < 0)
7150 if (test_bind_mupa(ctx
) < 0)
7156 /* Inputs for isl_set_unbind_params tests.
7157 * "set" is the input parameter domain.
7158 * "tuple" is the tuple of the constructed set.
7159 * "res" is the expected result.
7165 } unbind_set_tests
[] = {
7166 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7168 "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7169 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7171 "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7172 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7174 "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }" },
7175 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7177 "[M] -> { D[x, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7180 /* Perform basic isl_set_unbind_params tests.
7182 static isl_stat
test_unbind_set(isl_ctx
*ctx
)
7186 for (i
= 0; i
< ARRAY_SIZE(unbind_set_tests
); ++i
) {
7189 isl_multi_id
*tuple
;
7192 set
= isl_set_read_from_str(ctx
, unbind_set_tests
[i
].set
);
7193 str
= unbind_set_tests
[i
].tuple
;
7194 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7195 set
= isl_set_unbind_params(set
, tuple
);
7196 r
= set_check_equal(set
, unbind_set_tests
[i
].res
);
7199 return isl_stat_error
;
7205 /* Inputs for isl_aff_unbind_params_insert_domain tests.
7206 * "aff" is the input affine expression defined over a parameter domain.
7207 * "tuple" is the tuple of the domain that gets introduced.
7208 * "res" is the expected result.
7214 } unbind_aff_tests
[] = {
7215 { "[M, N] -> { [M + floor(N/2)] }",
7217 "{ A[M, N] -> [M + floor(N/2)] }" },
7218 { "[M, N] -> { [M + floor(N/2)] }",
7220 "{ B[N, M] -> [M + floor(N/2)] }" },
7221 { "[M, N] -> { [M + floor(N/2)] }",
7223 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7224 { "[M, N] -> { [M + floor(N/2)] }",
7225 "{ D[A, B, C, N, Z] }",
7226 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7229 /* Perform basic isl_aff_unbind_params_insert_domain tests.
7231 static isl_stat
test_unbind_aff(isl_ctx
*ctx
)
7235 for (i
= 0; i
< ARRAY_SIZE(unbind_aff_tests
); ++i
) {
7238 isl_multi_id
*tuple
;
7241 aff
= isl_aff_read_from_str(ctx
, unbind_aff_tests
[i
].aff
);
7242 str
= unbind_aff_tests
[i
].tuple
;
7243 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7244 aff
= isl_aff_unbind_params_insert_domain(aff
, tuple
);
7245 r
= aff_check_plain_equal(aff
, unbind_aff_tests
[i
].res
);
7248 return isl_stat_error
;
7254 /* Perform tests that reinterpret parameters.
7256 static int test_unbind(isl_ctx
*ctx
)
7258 if (test_unbind_set(ctx
) < 0)
7260 if (test_unbind_aff(ctx
) < 0)
7266 /* Check that "pa" consists of a single expression.
7268 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
7272 n
= isl_pw_aff_n_piece(pa
);
7273 isl_pw_aff_free(pa
);
7278 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
7284 /* Check that the computation below results in a single expression.
7285 * One or two expressions may result depending on which constraint
7286 * ends up being considered as redundant with respect to the other
7287 * constraints after the projection that is performed internally
7288 * by isl_set_dim_min.
7290 static int test_dim_max_1(isl_ctx
*ctx
)
7296 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
7297 "-4a <= b <= 3 and b < n - 4a }";
7298 set
= isl_set_read_from_str(ctx
, str
);
7299 pa
= isl_set_dim_min(set
, 0);
7300 return check_single_piece(ctx
, pa
);
7303 /* Check that the computation below results in a single expression.
7304 * The PIP problem corresponding to these constraints has a row
7305 * that causes a split of the solution domain. The solver should
7306 * first pick rows that split off empty parts such that the actual
7307 * solution domain does not get split.
7308 * Note that the description contains some redundant constraints.
7309 * If these constraints get removed first, then the row mentioned
7310 * above does not appear in the PIP problem.
7312 static int test_dim_max_2(isl_ctx
*ctx
)
7318 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
7319 "N > 0 and P >= 0 }";
7320 set
= isl_set_read_from_str(ctx
, str
);
7321 pa
= isl_set_dim_max(set
, 0);
7322 return check_single_piece(ctx
, pa
);
7325 int test_dim_max(isl_ctx
*ctx
)
7329 isl_set
*set1
, *set2
;
7334 if (test_dim_max_1(ctx
) < 0)
7336 if (test_dim_max_2(ctx
) < 0)
7339 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
7340 set
= isl_set_read_from_str(ctx
, str
);
7341 pwaff
= isl_set_dim_max(set
, 0);
7342 set1
= isl_set_from_pw_aff(pwaff
);
7343 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
7344 set2
= isl_set_read_from_str(ctx
, str
);
7345 equal
= isl_set_is_equal(set1
, set2
);
7351 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7353 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
7354 set
= isl_set_read_from_str(ctx
, str
);
7355 pwaff
= isl_set_dim_max(set
, 0);
7356 set1
= isl_set_from_pw_aff(pwaff
);
7357 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7358 set2
= isl_set_read_from_str(ctx
, str
);
7359 equal
= isl_set_is_equal(set1
, set2
);
7365 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7367 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
7368 set
= isl_set_read_from_str(ctx
, str
);
7369 pwaff
= isl_set_dim_max(set
, 0);
7370 set1
= isl_set_from_pw_aff(pwaff
);
7371 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7372 set2
= isl_set_read_from_str(ctx
, str
);
7373 equal
= isl_set_is_equal(set1
, set2
);
7379 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7381 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
7382 "0 <= i < N and 0 <= j < M }";
7383 map
= isl_map_read_from_str(ctx
, str
);
7384 set
= isl_map_range(map
);
7386 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
7387 set1
= isl_set_from_pw_aff(pwaff
);
7388 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
7389 set2
= isl_set_read_from_str(ctx
, str
);
7390 equal
= isl_set_is_equal(set1
, set2
);
7394 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
7395 set1
= isl_set_from_pw_aff(pwaff
);
7396 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
7397 set2
= isl_set_read_from_str(ctx
, str
);
7398 if (equal
>= 0 && equal
)
7399 equal
= isl_set_is_equal(set1
, set2
);
7408 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7410 /* Check that solutions are properly merged. */
7411 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
7412 "c <= -1 + n - 4a - 2b and c >= -2b and "
7413 "4a >= -4 + n and c >= 0 }";
7414 set
= isl_set_read_from_str(ctx
, str
);
7415 pwaff
= isl_set_dim_min(set
, 2);
7416 set1
= isl_set_from_pw_aff(pwaff
);
7417 str
= "[n] -> { [(0)] : n >= 1 }";
7418 set2
= isl_set_read_from_str(ctx
, str
);
7419 equal
= isl_set_is_equal(set1
, set2
);
7426 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7428 /* Check that empty solution lie in the right space. */
7429 str
= "[n] -> { [t,a] : 1 = 0 }";
7430 set
= isl_set_read_from_str(ctx
, str
);
7431 pwaff
= isl_set_dim_max(set
, 0);
7432 set1
= isl_set_from_pw_aff(pwaff
);
7433 str
= "[n] -> { [t] : 1 = 0 }";
7434 set2
= isl_set_read_from_str(ctx
, str
);
7435 equal
= isl_set_is_equal(set1
, set2
);
7442 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7447 /* Basic test for isl_pw_multi_aff_product.
7449 * Check that multiple pieces are properly handled.
7451 static int test_product_pma(isl_ctx
*ctx
)
7455 isl_pw_multi_aff
*pma1
, *pma2
;
7457 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
7458 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7459 str
= "{ C[] -> D[] }";
7460 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7461 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
7462 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
7463 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
7464 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
7465 isl_pw_multi_aff_free(pma1
);
7472 int test_product(isl_ctx
*ctx
)
7476 isl_union_set
*uset1
, *uset2
;
7480 set
= isl_set_read_from_str(ctx
, str
);
7481 set
= isl_set_product(set
, isl_set_copy(set
));
7482 ok
= isl_set_is_wrapping(set
);
7487 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7490 uset1
= isl_union_set_read_from_str(ctx
, str
);
7491 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
7492 str
= "{ [[] -> []] }";
7493 uset2
= isl_union_set_read_from_str(ctx
, str
);
7494 ok
= isl_union_set_is_equal(uset1
, uset2
);
7495 isl_union_set_free(uset1
);
7496 isl_union_set_free(uset2
);
7500 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7502 if (test_product_pma(ctx
) < 0)
7508 /* Check that two sets are not considered disjoint just because
7509 * they have a different set of (named) parameters.
7511 static int test_disjoint(isl_ctx
*ctx
)
7514 isl_set
*set
, *set2
;
7517 str
= "[n] -> { [[]->[]] }";
7518 set
= isl_set_read_from_str(ctx
, str
);
7519 str
= "{ [[]->[]] }";
7520 set2
= isl_set_read_from_str(ctx
, str
);
7521 disjoint
= isl_set_is_disjoint(set
, set2
);
7527 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7532 /* Inputs for isl_pw_multi_aff_is_equal tests.
7533 * "f1" and "f2" are the two function that need to be compared.
7534 * "equal" is the expected result.
7540 } pma_equal_tests
[] = {
7541 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
7542 "[N] -> { [0] : 0 <= N <= 1 }" },
7543 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7544 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
7545 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7546 "[N] -> { [0] : 0 <= N <= 1 }" },
7547 { 0, "{ [NaN] }", "{ [NaN] }" },
7550 int test_equal(isl_ctx
*ctx
)
7554 isl_set
*set
, *set2
;
7558 set
= isl_set_read_from_str(ctx
, str
);
7560 set2
= isl_set_read_from_str(ctx
, str
);
7561 equal
= isl_set_is_equal(set
, set2
);
7567 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7569 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
7570 int expected
= pma_equal_tests
[i
].equal
;
7571 isl_pw_multi_aff
*f1
, *f2
;
7573 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
7574 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
7575 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
7576 isl_pw_multi_aff_free(f1
);
7577 isl_pw_multi_aff_free(f2
);
7580 if (equal
!= expected
)
7581 isl_die(ctx
, isl_error_unknown
,
7582 "unexpected equality result", return -1);
7588 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
7589 enum isl_dim_type type
, unsigned pos
, int fixed
)
7593 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
7600 isl_die(ctx
, isl_error_unknown
,
7601 "map not detected as fixed", return -1);
7603 isl_die(ctx
, isl_error_unknown
,
7604 "map detected as fixed", return -1);
7607 int test_fixed(isl_ctx
*ctx
)
7612 str
= "{ [i] -> [i] }";
7613 map
= isl_map_read_from_str(ctx
, str
);
7614 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
7616 str
= "{ [i] -> [1] }";
7617 map
= isl_map_read_from_str(ctx
, str
);
7618 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7620 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
7621 map
= isl_map_read_from_str(ctx
, str
);
7622 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7624 map
= isl_map_read_from_str(ctx
, str
);
7625 map
= isl_map_neg(map
);
7626 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7632 struct isl_vertices_test_data
{
7635 const char *vertex
[6];
7636 } vertices_tests
[] = {
7637 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
7638 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
7639 { "{ A[t, i] : t = 14 and i = 1 }",
7640 1, { "{ A[14, 1] }" } },
7641 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
7642 "c <= m and m <= n and m > 0 }",
7644 "[n, m] -> { [n, m, m] : 0 < m <= n }",
7645 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
7646 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
7647 "[n, m] -> { [m, m, m] : 0 < m <= n }",
7648 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
7649 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
7653 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
7655 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
7657 struct isl_vertices_test_data
*data
= user
;
7660 isl_basic_set
*bset
;
7661 isl_pw_multi_aff
*pma
;
7665 ctx
= isl_vertex_get_ctx(vertex
);
7666 bset
= isl_vertex_get_domain(vertex
);
7667 ma
= isl_vertex_get_expr(vertex
);
7668 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
7670 for (i
= 0; i
< data
->n
; ++i
) {
7671 isl_pw_multi_aff
*pma_i
;
7673 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
7674 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
7675 isl_pw_multi_aff_free(pma_i
);
7677 if (equal
< 0 || equal
)
7681 isl_pw_multi_aff_free(pma
);
7682 isl_vertex_free(vertex
);
7685 return isl_stat_error
;
7687 return equal
? isl_stat_ok
: isl_stat_error
;
7690 int test_vertices(isl_ctx
*ctx
)
7694 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
7695 isl_basic_set
*bset
;
7696 isl_vertices
*vertices
;
7700 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
7701 vertices
= isl_basic_set_compute_vertices(bset
);
7702 n
= isl_vertices_get_n_vertices(vertices
);
7703 if (vertices_tests
[i
].n
!= n
)
7705 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
7706 &vertices_tests
[i
]) < 0)
7708 isl_vertices_free(vertices
);
7709 isl_basic_set_free(bset
);
7714 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
7721 /* Inputs for basic tests of unary operations on isl_union_map.
7722 * "fn" is the function that is being tested.
7723 * "arg" is a string description of the input.
7724 * "res" is a string description of the expected result.
7727 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap
);
7730 } umap_un_tests
[] = {
7731 { &isl_union_map_range_reverse
,
7732 "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
7733 "{ A[] -> [C[] -> B[]]; A[0] -> N[B[2] -> B[1]] }" },
7734 { &isl_union_map_range_reverse
,
7735 "{ A[] -> N[B[] -> C[]] }",
7736 "{ A[] -> [C[] -> B[]] }" },
7737 { &isl_union_map_range_reverse
,
7738 "{ A[] -> N[B[x] -> B[y]] }",
7739 "{ A[] -> N[B[*] -> B[*]] }" },
7742 /* Perform basic tests of unary operations on isl_union_map.
7744 static isl_stat
test_un_union_map(isl_ctx
*ctx
)
7748 for (i
= 0; i
< ARRAY_SIZE(umap_un_tests
); ++i
) {
7750 isl_union_map
*umap
, *res
;
7753 str
= umap_un_tests
[i
].arg
;
7754 umap
= isl_union_map_read_from_str(ctx
, str
);
7755 str
= umap_un_tests
[i
].res
;
7756 res
= isl_union_map_read_from_str(ctx
, str
);
7757 umap
= umap_un_tests
[i
].fn(umap
);
7758 equal
= isl_union_map_is_equal(umap
, res
);
7759 isl_union_map_free(umap
);
7760 isl_union_map_free(res
);
7762 return isl_stat_error
;
7764 isl_die(ctx
, isl_error_unknown
,
7765 "unexpected result", return isl_stat_error
);
7771 /* Inputs for basic tests of binary operations on isl_union_map.
7772 * "fn" is the function that is being tested.
7773 * "arg1" and "arg2" are string descriptions of the inputs.
7774 * "res" is a string description of the expected result.
7777 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap1
,
7778 __isl_take isl_union_map
*umap2
);
7782 } umap_bin_tests
[] = {
7783 { &isl_union_map_intersect
,
7784 "[n] -> { A[i] -> [] : 0 <= i <= n; B[] -> [] }",
7785 "[m] -> { A[i] -> [] : 0 <= i <= m; C[] -> [] }",
7786 "[m, n] -> { A[i] -> [] : 0 <= i <= n and i <= m }" },
7787 { &isl_union_map_intersect_domain_factor_range
,
7788 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7789 "[N] -> { B[i] -> C[N] }",
7790 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
7791 { &isl_union_map_intersect_domain_factor_range
,
7792 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
7793 "[N] -> { B[i] -> C[N] }",
7794 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
7795 { &isl_union_map_intersect_domain_factor_range
,
7796 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7797 "[N] -> { A[i] -> C[N] }",
7799 { &isl_union_map_intersect_range_factor_domain
,
7800 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7801 "[N] -> { A[i] -> B[N] }",
7802 "[N] -> { A[N - 1] -> [B[N] -> C[N + 1]] }" },
7803 { &isl_union_map_intersect_range_factor_domain
,
7804 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
7805 "[N] -> { A[i] -> B[N] }",
7806 "[N] -> { A[N - 1] -> T[B[N] -> C[N + 1]] }" },
7807 { &isl_union_map_intersect_range_factor_domain
,
7808 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7809 "[N] -> { A[i] -> C[N] }",
7811 { &isl_union_map_intersect_range_factor_range
,
7812 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7813 "[N] -> { A[i] -> C[N] }",
7814 "[N] -> { A[N - 2] -> [B[N - 1] -> C[N]] }" },
7815 { &isl_union_map_intersect_range_factor_range
,
7816 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
7817 "[N] -> { A[i] -> C[N] }",
7818 "[N] -> { A[N - 2] -> T[B[N - 1] -> C[N]] }" },
7819 { &isl_union_map_intersect_range_factor_range
,
7820 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7821 "[N] -> { A[i] -> B[N] }",
7825 /* Perform basic tests of binary operations on isl_union_map.
7827 static isl_stat
test_bin_union_map(isl_ctx
*ctx
)
7831 for (i
= 0; i
< ARRAY_SIZE(umap_bin_tests
); ++i
) {
7833 isl_union_map
*umap1
, *umap2
, *res
;
7836 str
= umap_bin_tests
[i
].arg1
;
7837 umap1
= isl_union_map_read_from_str(ctx
, str
);
7838 str
= umap_bin_tests
[i
].arg2
;
7839 umap2
= isl_union_map_read_from_str(ctx
, str
);
7840 str
= umap_bin_tests
[i
].res
;
7841 res
= isl_union_map_read_from_str(ctx
, str
);
7842 umap1
= umap_bin_tests
[i
].fn(umap1
, umap2
);
7843 equal
= isl_union_map_is_equal(umap1
, res
);
7844 isl_union_map_free(umap1
);
7845 isl_union_map_free(res
);
7847 return isl_stat_error
;
7849 isl_die(ctx
, isl_error_unknown
,
7850 "unexpected result", return isl_stat_error
);
7856 /* Perform basic tests of operations on isl_union_map.
7858 static int test_union_map(isl_ctx
*ctx
)
7860 if (test_un_union_map(ctx
) < 0)
7862 if (test_bin_union_map(ctx
) < 0)
7867 int test_union_pw(isl_ctx
*ctx
)
7871 isl_union_set
*uset
;
7872 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
7874 str
= "{ [x] -> x^2 }";
7875 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
7876 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
7877 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
7878 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
7879 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
7880 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
7881 isl_union_pw_qpolynomial_free(upwqp1
);
7882 isl_union_pw_qpolynomial_free(upwqp2
);
7886 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7891 /* Inputs for basic tests of functions that select
7892 * subparts of the domain of an isl_multi_union_pw_aff.
7893 * "fn" is the function that is tested.
7894 * "arg" is a string description of the input.
7895 * "res" is a string description of the expected result.
7898 __isl_give isl_union_set
*(*fn
)(
7899 __isl_take isl_multi_union_pw_aff
*mupa
);
7902 } un_locus_tests
[] = {
7903 { &isl_multi_union_pw_aff_zero_union_set
,
7904 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
7905 "{ A[0,j]; B[0,j] }" },
7906 { &isl_multi_union_pw_aff_zero_union_set
,
7907 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
7908 "{ A[i,i]; B[i,i] : i >= 0 }" },
7909 { &isl_multi_union_pw_aff_zero_union_set
,
7910 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
7911 "{ A[i,j]; B[i,i] : i >= 0 }" },
7914 /* Perform some basic tests of functions that select
7915 * subparts of the domain of an isl_multi_union_pw_aff.
7917 static int test_un_locus(isl_ctx
*ctx
)
7921 isl_union_set
*uset
, *res
;
7922 isl_multi_union_pw_aff
*mupa
;
7924 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
7925 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
7926 un_locus_tests
[i
].arg
);
7927 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
7928 uset
= un_locus_tests
[i
].fn(mupa
);
7929 ok
= isl_union_set_is_equal(uset
, res
);
7930 isl_union_set_free(uset
);
7931 isl_union_set_free(res
);
7935 isl_die(ctx
, isl_error_unknown
,
7936 "unexpected result", return -1);
7942 /* Inputs for basic tests of functions that select
7943 * subparts of an isl_union_map based on a relation
7944 * specified by an isl_multi_union_pw_aff.
7945 * "fn" is the function that is tested.
7946 * "arg1" and "arg2" are string descriptions of the inputs.
7947 * "res" is a string description of the expected result.
7950 __isl_give isl_union_map
*(*fn
)(
7951 __isl_take isl_union_map
*umap
,
7952 __isl_take isl_multi_union_pw_aff
*mupa
);
7956 } bin_locus_tests
[] = {
7957 { &isl_union_map_eq_at_multi_union_pw_aff
,
7958 "{ A[i,j] -> B[i',j'] }",
7959 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
7960 "{ A[i,j] -> B[i,j'] }" },
7961 { &isl_union_map_eq_at_multi_union_pw_aff
,
7962 "{ A[i,j] -> B[i',j'] }",
7963 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
7964 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
7965 "{ A[i,j] -> B[i,j] }" },
7966 { &isl_union_map_eq_at_multi_union_pw_aff
,
7967 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
7968 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
7969 "{ A[i,j] -> B[i,j'] }" },
7970 { &isl_union_map_eq_at_multi_union_pw_aff
,
7971 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
7972 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
7973 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
7974 { &isl_union_map_eq_at_multi_union_pw_aff
,
7975 "{ A[i,j] -> B[i',j'] }",
7976 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
7977 "{ A[i,j] -> B[i,j'] : i > j }" },
7978 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
7979 "{ A[i,j] -> B[i',j'] }",
7980 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
7981 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
7982 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
7983 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
7984 "{ A[i,j] -> B[i',j'] }",
7985 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
7986 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
7987 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
7988 { &isl_union_map_eq_at_multi_union_pw_aff
,
7989 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
7990 "(F[] : { A[i,j]; B[i,j] })",
7991 "{ A[i,j] -> B[i',j'] }" },
7992 { &isl_union_map_eq_at_multi_union_pw_aff
,
7993 "{ A[i,j] -> B[i',j'] }",
7994 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
7995 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
7996 { &isl_union_map_eq_at_multi_union_pw_aff
,
7997 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
7998 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
7999 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
8000 { &isl_union_map_eq_at_multi_union_pw_aff
,
8001 "{ A[i,j] -> B[i',j'] }",
8002 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
8003 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
8004 { &isl_union_map_eq_at_multi_union_pw_aff
,
8005 "{ A[i,j] -> B[i',j'] }",
8006 "[N] -> (F[] : { : N >= 0 })",
8007 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
8010 /* Perform some basic tests of functions that select
8011 * subparts of an isl_union_map based on a relation
8012 * specified by an isl_multi_union_pw_aff.
8014 static int test_bin_locus(isl_ctx
*ctx
)
8018 isl_union_map
*umap
, *res
;
8019 isl_multi_union_pw_aff
*mupa
;
8021 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
8022 umap
= isl_union_map_read_from_str(ctx
,
8023 bin_locus_tests
[i
].arg1
);
8024 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
8025 bin_locus_tests
[i
].arg2
);
8026 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
8027 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
8028 ok
= isl_union_map_is_equal(umap
, res
);
8029 isl_union_map_free(umap
);
8030 isl_union_map_free(res
);
8034 isl_die(ctx
, isl_error_unknown
,
8035 "unexpected result", return -1);
8041 /* Perform basic locus tests.
8043 static int test_locus(isl_ctx
*ctx
)
8045 if (test_un_locus(ctx
) < 0)
8047 if (test_bin_locus(ctx
) < 0)
8052 /* Test that isl_union_pw_qpolynomial_eval picks up the function
8053 * defined over the correct domain space.
8055 static int test_eval_1(isl_ctx
*ctx
)
8060 isl_union_pw_qpolynomial
*upwqp
;
8064 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
8065 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8067 set
= isl_set_read_from_str(ctx
, str
);
8068 pnt
= isl_set_sample_point(set
);
8069 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
8070 cmp
= isl_val_cmp_si(v
, 36);
8076 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
8081 /* Check that isl_qpolynomial_eval handles getting called on a void point.
8083 static int test_eval_2(isl_ctx
*ctx
)
8088 isl_qpolynomial
*qp
;
8092 str
= "{ A[x] -> [x] }";
8093 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
8094 str
= "{ A[x] : false }";
8095 set
= isl_set_read_from_str(ctx
, str
);
8096 pnt
= isl_set_sample_point(set
);
8097 v
= isl_qpolynomial_eval(qp
, pnt
);
8098 ok
= isl_val_is_nan(v
);
8104 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
8109 /* Check that a polynomial (without local variables) can be evaluated
8110 * in a rational point.
8112 static isl_stat
test_eval_3(isl_ctx
*ctx
)
8114 isl_pw_qpolynomial
*pwqp
;
8119 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, "{ [x] -> x^2 }");
8120 pnt
= isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp
));
8121 v
= isl_val_read_from_str(ctx
, "1/2");
8122 pnt
= isl_point_set_coordinate_val(pnt
, isl_dim_set
, 0, v
);
8123 v
= isl_pw_qpolynomial_eval(pwqp
, pnt
);
8124 r
= val_check_equal(v
, "1/4");
8130 /* Inputs for isl_pw_aff_eval test.
8131 * "f" is the affine function.
8132 * "p" is the point where the function should be evaluated.
8133 * "res" is the expected result.
8139 } aff_eval_tests
[] = {
8140 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
8141 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
8142 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
8143 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
8144 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
8145 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
8146 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
8147 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
8148 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
8149 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
8150 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
8151 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
8152 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
8153 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
8154 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
8155 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
8156 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
8157 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
8158 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
8159 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
8160 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
8161 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
8162 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
8165 /* Perform basic isl_pw_aff_eval tests.
8167 static int test_eval_aff(isl_ctx
*ctx
)
8171 for (i
= 0; i
< ARRAY_SIZE(aff_eval_tests
); ++i
) {
8178 pa
= isl_pw_aff_read_from_str(ctx
, aff_eval_tests
[i
].f
);
8179 set
= isl_set_read_from_str(ctx
, aff_eval_tests
[i
].p
);
8180 pnt
= isl_set_sample_point(set
);
8181 v
= isl_pw_aff_eval(pa
, pnt
);
8182 r
= val_check_equal(v
, aff_eval_tests
[i
].res
);
8190 /* Perform basic evaluation tests.
8192 static int test_eval(isl_ctx
*ctx
)
8194 if (test_eval_1(ctx
) < 0)
8196 if (test_eval_2(ctx
) < 0)
8198 if (test_eval_3(ctx
) < 0)
8200 if (test_eval_aff(ctx
) < 0)
8205 /* Descriptions of sets that are tested for reparsing after printing.
8207 const char *output_tests
[] = {
8208 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
8211 "{ [x] : x mod 2 = 0 }",
8212 "{ [x] : x mod 2 = 1 }",
8213 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
8214 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
8215 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8216 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8217 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
8218 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
8221 /* Check that printing a set and reparsing a set from the printed output
8222 * results in the same set.
8224 static int test_output_set(isl_ctx
*ctx
)
8228 isl_set
*set1
, *set2
;
8231 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
8232 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
8233 str
= isl_set_to_str(set1
);
8234 set2
= isl_set_read_from_str(ctx
, str
);
8236 equal
= isl_set_is_equal(set1
, set2
);
8242 isl_die(ctx
, isl_error_unknown
,
8243 "parsed output not the same", return -1);
8249 /* Check that an isl_multi_aff is printed using a consistent space.
8251 static isl_stat
test_output_ma(isl_ctx
*ctx
)
8256 isl_multi_aff
*ma
, *ma2
;
8258 ma
= isl_multi_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8259 aff
= isl_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8260 ma
= isl_multi_aff_set_aff(ma
, 0, aff
);
8261 str
= isl_multi_aff_to_str(ma
);
8262 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8264 equal
= isl_multi_aff_plain_is_equal(ma
, ma2
);
8265 isl_multi_aff_free(ma2
);
8266 isl_multi_aff_free(ma
);
8269 return isl_stat_error
;
8271 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8272 return isl_stat_error
);
8277 /* Check that an isl_multi_pw_aff is printed using a consistent space.
8279 static isl_stat
test_output_mpa(isl_ctx
*ctx
)
8284 isl_multi_pw_aff
*mpa
, *mpa2
;
8286 mpa
= isl_multi_pw_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8287 pa
= isl_pw_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8288 mpa
= isl_multi_pw_aff_set_pw_aff(mpa
, 0, pa
);
8289 str
= isl_multi_pw_aff_to_str(mpa
);
8290 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8292 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
8293 isl_multi_pw_aff_free(mpa2
);
8294 isl_multi_pw_aff_free(mpa
);
8297 return isl_stat_error
;
8299 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8300 return isl_stat_error
);
8305 int test_output(isl_ctx
*ctx
)
8313 if (test_output_set(ctx
) < 0)
8315 if (test_output_ma(ctx
) < 0)
8317 if (test_output_mpa(ctx
) < 0)
8320 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
8321 pa
= isl_pw_aff_read_from_str(ctx
, str
);
8323 p
= isl_printer_to_str(ctx
);
8324 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
8325 p
= isl_printer_print_pw_aff(p
, pa
);
8326 s
= isl_printer_get_str(p
);
8327 isl_printer_free(p
);
8328 isl_pw_aff_free(pa
);
8332 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
8337 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
8342 int test_sample(isl_ctx
*ctx
)
8345 isl_basic_set
*bset1
, *bset2
;
8348 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
8349 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
8350 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
8351 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
8352 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
8353 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
8354 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
8355 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
8356 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
8357 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
8358 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
8359 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
8360 "d - 1073741821e and "
8361 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
8362 "3j >= 1 - a + b + 2e and "
8363 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
8364 "3i <= 4 - a + 4b - e and "
8365 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
8366 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
8367 "c <= -1 + a and 3i >= -2 - a + 3e and "
8368 "1073741822e <= 1073741823 - a + 1073741822b + c and "
8369 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
8370 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
8371 "1073741823e >= 1 + 1073741823b - d and "
8372 "3i >= 1073741823b + c - 1073741823e - f and "
8373 "3i >= 1 + 2b + e + 3g }";
8374 bset1
= isl_basic_set_read_from_str(ctx
, str
);
8375 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
8376 empty
= isl_basic_set_is_empty(bset2
);
8377 subset
= isl_basic_set_is_subset(bset2
, bset1
);
8378 isl_basic_set_free(bset1
);
8379 isl_basic_set_free(bset2
);
8380 if (empty
< 0 || subset
< 0)
8383 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
8385 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
8390 int test_fixed_power(isl_ctx
*ctx
)
8397 str
= "{ [i] -> [i + 1] }";
8398 map
= isl_map_read_from_str(ctx
, str
);
8399 exp
= isl_val_int_from_si(ctx
, 23);
8400 map
= isl_map_fixed_power_val(map
, exp
);
8401 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
8409 int test_slice(isl_ctx
*ctx
)
8415 str
= "{ [i] -> [j] }";
8416 map
= isl_map_read_from_str(ctx
, str
);
8417 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8418 equal
= map_check_equal(map
, "{ [i] -> [i] }");
8423 str
= "{ [i] -> [j] }";
8424 map
= isl_map_read_from_str(ctx
, str
);
8425 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8426 equal
= map_check_equal(map
, "{ [i] -> [j] }");
8431 str
= "{ [i] -> [j] }";
8432 map
= isl_map_read_from_str(ctx
, str
);
8433 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8434 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
8439 str
= "{ [i] -> [j] }";
8440 map
= isl_map_read_from_str(ctx
, str
);
8441 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8442 equal
= map_check_equal(map
, "{ [0] -> [j] }");
8447 str
= "{ [i] -> [j] }";
8448 map
= isl_map_read_from_str(ctx
, str
);
8449 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8450 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
8455 str
= "{ [i] -> [j] }";
8456 map
= isl_map_read_from_str(ctx
, str
);
8457 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8458 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
8466 int test_eliminate(isl_ctx
*ctx
)
8472 str
= "{ [i] -> [j] : i = 2j }";
8473 map
= isl_map_read_from_str(ctx
, str
);
8474 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
8475 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
8483 /* Check basic functionality of isl_map_deltas_map.
8485 static int test_deltas_map(isl_ctx
*ctx
)
8491 str
= "{ A[i] -> A[i + 1] }";
8492 map
= isl_map_read_from_str(ctx
, str
);
8493 map
= isl_map_deltas_map(map
);
8494 equal
= map_check_equal(map
, "{ [A[i] -> A[i + 1]] -> A[1] }");
8502 /* Check that isl_set_dim_residue_class detects that the values of j
8503 * in the set below are all odd and that it does not detect any spurious
8506 static int test_residue_class(isl_ctx
*ctx
)
8513 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
8514 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
8515 set
= isl_set_read_from_str(ctx
, str
);
8518 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
8520 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
8521 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
8522 res
= isl_stat_error
);
8530 static int test_align_parameters_1(isl_ctx
*ctx
)
8534 isl_multi_aff
*ma1
, *ma2
;
8537 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
8538 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
8540 space
= isl_space_params_alloc(ctx
, 1);
8541 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
8542 ma1
= isl_multi_aff_align_params(ma1
, space
);
8544 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
8545 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8547 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
8549 isl_multi_aff_free(ma1
);
8550 isl_multi_aff_free(ma2
);
8555 isl_die(ctx
, isl_error_unknown
,
8556 "result not as expected", return -1);
8561 /* Check the isl_multi_*_from_*_list operation in case inputs
8562 * have unaligned parameters.
8563 * In particular, older versions of isl would simply fail
8564 * (without printing any error message).
8566 static isl_stat
test_align_parameters_2(isl_ctx
*ctx
)
8573 map
= isl_map_read_from_str(ctx
, "{ A[] -> M[x] }");
8574 space
= isl_map_get_space(map
);
8577 aff
= isl_aff_read_from_str(ctx
, "[N] -> { A[] -> [N] }");
8578 ma
= isl_multi_aff_from_aff_list(space
, isl_aff_list_from_aff(aff
));
8579 isl_multi_aff_free(ma
);
8582 return isl_stat_error
;
8586 /* Perform basic parameter alignment tests.
8588 static int test_align_parameters(isl_ctx
*ctx
)
8590 if (test_align_parameters_1(ctx
) < 0)
8592 if (test_align_parameters_2(ctx
) < 0)
8598 /* Check that isl_*_drop_unused_params actually drops the unused parameters
8599 * by comparing the result using isl_*_plain_is_equal.
8600 * Note that this assumes that isl_*_plain_is_equal does not consider
8601 * objects that only differ by unused parameters to be equal.
8603 int test_drop_unused_parameters(isl_ctx
*ctx
)
8605 const char *str_with
, *str_without
;
8606 isl_basic_set
*bset1
, *bset2
;
8607 isl_set
*set1
, *set2
;
8608 isl_pw_aff
*pwa1
, *pwa2
;
8611 str_with
= "[n, m, o] -> { [m] }";
8612 str_without
= "[m] -> { [m] }";
8614 bset1
= isl_basic_set_read_from_str(ctx
, str_with
);
8615 bset2
= isl_basic_set_read_from_str(ctx
, str_without
);
8616 bset1
= isl_basic_set_drop_unused_params(bset1
);
8617 equal
= isl_basic_set_plain_is_equal(bset1
, bset2
);
8618 isl_basic_set_free(bset1
);
8619 isl_basic_set_free(bset2
);
8624 isl_die(ctx
, isl_error_unknown
,
8625 "result not as expected", return -1);
8627 set1
= isl_set_read_from_str(ctx
, str_with
);
8628 set2
= isl_set_read_from_str(ctx
, str_without
);
8629 set1
= isl_set_drop_unused_params(set1
);
8630 equal
= isl_set_plain_is_equal(set1
, set2
);
8637 isl_die(ctx
, isl_error_unknown
,
8638 "result not as expected", return -1);
8640 pwa1
= isl_pw_aff_read_from_str(ctx
, str_with
);
8641 pwa2
= isl_pw_aff_read_from_str(ctx
, str_without
);
8642 pwa1
= isl_pw_aff_drop_unused_params(pwa1
);
8643 equal
= isl_pw_aff_plain_is_equal(pwa1
, pwa2
);
8644 isl_pw_aff_free(pwa1
);
8645 isl_pw_aff_free(pwa2
);
8650 isl_die(ctx
, isl_error_unknown
,
8651 "result not as expected", return -1);
8656 static int test_list(isl_ctx
*ctx
)
8658 isl_id
*a
, *b
, *c
, *d
, *id
;
8663 a
= isl_id_alloc(ctx
, "a", NULL
);
8664 b
= isl_id_alloc(ctx
, "b", NULL
);
8665 c
= isl_id_alloc(ctx
, "c", NULL
);
8666 d
= isl_id_alloc(ctx
, "d", NULL
);
8668 list
= isl_id_list_alloc(ctx
, 4);
8669 list
= isl_id_list_add(list
, b
);
8670 list
= isl_id_list_insert(list
, 0, a
);
8671 list
= isl_id_list_add(list
, c
);
8672 list
= isl_id_list_add(list
, d
);
8673 list
= isl_id_list_drop(list
, 1, 1);
8675 n
= isl_id_list_n_id(list
);
8679 isl_id_list_free(list
);
8680 isl_die(ctx
, isl_error_unknown
,
8681 "unexpected number of elements in list", return -1);
8684 id
= isl_id_list_get_id(list
, 0);
8687 id
= isl_id_list_get_id(list
, 1);
8690 id
= isl_id_list_get_id(list
, 2);
8694 isl_id_list_free(list
);
8697 isl_die(ctx
, isl_error_unknown
,
8698 "unexpected elements in list", return -1);
8703 /* Check the conversion from an isl_multi_aff to an isl_basic_set.
8705 static isl_stat
test_ma_conversion(isl_ctx
*ctx
)
8710 isl_basic_set
*bset1
, *bset2
;
8712 str
= "[N] -> { A[0, N + 1] }";
8713 ma
= isl_multi_aff_read_from_str(ctx
, str
);
8714 bset1
= isl_basic_set_read_from_str(ctx
, str
);
8715 bset2
= isl_basic_set_from_multi_aff(ma
);
8716 equal
= isl_basic_set_is_equal(bset1
, bset2
);
8717 isl_basic_set_free(bset1
);
8718 isl_basic_set_free(bset2
);
8720 return isl_stat_error
;
8722 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8723 return isl_stat_error
);
8727 const char *set_conversion_tests
[] = {
8728 "[N] -> { [i] : N - 1 <= 2 i <= N }",
8729 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
8730 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
8731 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
8732 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
8733 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
8734 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
8735 "-3 + c <= d <= 28 + c) }",
8738 /* Check that converting from isl_set to isl_pw_multi_aff and back
8739 * to isl_set produces the original isl_set.
8741 static int test_set_conversion(isl_ctx
*ctx
)
8745 isl_set
*set1
, *set2
;
8746 isl_pw_multi_aff
*pma
;
8749 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
8750 str
= set_conversion_tests
[i
];
8751 set1
= isl_set_read_from_str(ctx
, str
);
8752 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
8753 set2
= isl_set_from_pw_multi_aff(pma
);
8754 equal
= isl_set_is_equal(set1
, set2
);
8761 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8768 const char *conversion_tests
[] = {
8769 "{ [a, b, c, d] -> s0[a, b, e, f] : "
8770 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
8771 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
8772 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
8774 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
8775 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
8776 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
8779 /* Check that converting from isl_map to isl_pw_multi_aff and back
8780 * to isl_map produces the original isl_map.
8782 static int test_map_conversion(isl_ctx
*ctx
)
8785 isl_map
*map1
, *map2
;
8786 isl_pw_multi_aff
*pma
;
8789 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
8790 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
8791 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
8792 map2
= isl_map_from_pw_multi_aff(pma
);
8793 equal
= isl_map_is_equal(map1
, map2
);
8800 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8807 /* Descriptions of isl_pw_multi_aff objects for testing conversion
8808 * to isl_multi_pw_aff and back.
8810 const char *mpa_conversion_tests
[] = {
8812 "{ [x] -> A[x] : x >= 0 }",
8813 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
8814 "{ [x] -> A[x, x + 1] }",
8816 "{ [x] -> A[] : x >= 0 }",
8819 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
8820 * back to isl_pw_multi_aff preserves the original meaning.
8822 static int test_mpa_conversion(isl_ctx
*ctx
)
8825 isl_pw_multi_aff
*pma1
, *pma2
;
8826 isl_multi_pw_aff
*mpa
;
8829 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
8831 str
= mpa_conversion_tests
[i
];
8832 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
8833 pma2
= isl_pw_multi_aff_copy(pma1
);
8834 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
8835 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
8836 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
8837 isl_pw_multi_aff_free(pma1
);
8838 isl_pw_multi_aff_free(pma2
);
8843 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8850 /* Descriptions of union maps that should be convertible
8851 * to an isl_multi_union_pw_aff.
8853 const char *umap_mupa_conversion_tests
[] = {
8854 "{ [a, b, c, d] -> s0[a, b, e, f] : "
8855 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
8856 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
8857 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
8859 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
8860 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
8861 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
8862 "{ A[] -> B[0]; C[] -> B[1] }",
8863 "{ A[] -> B[]; C[] -> B[] }",
8866 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
8867 * to isl_union_map produces the original isl_union_map.
8869 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
8872 isl_union_map
*umap1
, *umap2
;
8873 isl_multi_union_pw_aff
*mupa
;
8876 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
8878 str
= umap_mupa_conversion_tests
[i
];
8879 umap1
= isl_union_map_read_from_str(ctx
, str
);
8880 umap2
= isl_union_map_copy(umap1
);
8881 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
8882 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
8883 equal
= isl_union_map_is_equal(umap1
, umap2
);
8884 isl_union_map_free(umap1
);
8885 isl_union_map_free(umap2
);
8890 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8897 static int test_conversion(isl_ctx
*ctx
)
8899 if (test_ma_conversion(ctx
) < 0)
8901 if (test_set_conversion(ctx
) < 0)
8903 if (test_map_conversion(ctx
) < 0)
8905 if (test_mpa_conversion(ctx
) < 0)
8907 if (test_union_map_mupa_conversion(ctx
) < 0)
8912 /* Check that isl_basic_map_curry does not modify input.
8914 static int test_curry(isl_ctx
*ctx
)
8917 isl_basic_map
*bmap1
, *bmap2
;
8920 str
= "{ [A[] -> B[]] -> C[] }";
8921 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
8922 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
8923 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
8924 isl_basic_map_free(bmap1
);
8925 isl_basic_map_free(bmap2
);
8930 isl_die(ctx
, isl_error_unknown
,
8931 "curried map should not be equal to original",
8941 } preimage_tests
[] = {
8942 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
8943 "{ A[j,i] -> B[i,j] }",
8944 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
8945 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
8946 "{ A[a,b] -> B[a/2,b/6] }",
8947 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
8948 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
8949 "{ A[a,b] -> B[a/2,b/6] }",
8950 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
8951 "exists i,j : a = 2 i and b = 6 j }" },
8952 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
8953 "[n] -> { : 0 <= n <= 100 }" },
8954 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
8955 "{ A[a] -> B[2a] }",
8956 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
8957 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
8958 "{ A[a] -> B[([a/2])] }",
8959 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
8960 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
8961 "{ A[a] -> B[a,a,a/3] }",
8962 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
8963 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
8964 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
8967 static int test_preimage_basic_set(isl_ctx
*ctx
)
8970 isl_basic_set
*bset1
, *bset2
;
8974 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
8975 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
8976 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
8977 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
8978 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
8979 equal
= isl_basic_set_is_equal(bset1
, bset2
);
8980 isl_basic_set_free(bset1
);
8981 isl_basic_set_free(bset2
);
8985 isl_die(ctx
, isl_error_unknown
, "bad preimage",
8996 } preimage_domain_tests
[] = {
8997 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
8998 "{ A[j,i] -> B[i,j] }",
8999 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
9000 { "{ B[i] -> C[i]; D[i] -> E[i] }",
9001 "{ A[i] -> B[i + 1] }",
9002 "{ A[i] -> C[i + 1] }" },
9003 { "{ B[i] -> C[i]; B[i] -> E[i] }",
9004 "{ A[i] -> B[i + 1] }",
9005 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
9006 { "{ B[i] -> C[([i/2])] }",
9007 "{ A[i] -> B[2i] }",
9008 "{ A[i] -> C[i] }" },
9009 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
9010 "{ A[i] -> B[([i/5]), ([i/7])] }",
9011 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
9012 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
9013 "[N] -> { A[] -> B[([N/5])] }",
9014 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
9015 { "{ B[i] -> C[i] : exists a : i = 5 a }",
9016 "{ A[i] -> B[2i] }",
9017 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
9018 { "{ B[i] -> C[i] : exists a : i = 2 a; "
9019 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
9020 "{ A[i] -> B[2i] }",
9021 "{ A[i] -> C[2i] }" },
9022 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
9023 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
9026 static int test_preimage_union_map(isl_ctx
*ctx
)
9029 isl_union_map
*umap1
, *umap2
;
9033 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
9034 umap1
= isl_union_map_read_from_str(ctx
,
9035 preimage_domain_tests
[i
].map
);
9036 ma
= isl_multi_aff_read_from_str(ctx
,
9037 preimage_domain_tests
[i
].ma
);
9038 umap2
= isl_union_map_read_from_str(ctx
,
9039 preimage_domain_tests
[i
].res
);
9040 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
9041 equal
= isl_union_map_is_equal(umap1
, umap2
);
9042 isl_union_map_free(umap1
);
9043 isl_union_map_free(umap2
);
9047 isl_die(ctx
, isl_error_unknown
, "bad preimage",
9054 static int test_preimage(isl_ctx
*ctx
)
9056 if (test_preimage_basic_set(ctx
) < 0)
9058 if (test_preimage_union_map(ctx
) < 0)
9068 } pullback_tests
[] = {
9069 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
9070 "{ A[a,b] -> C[b + 2a] }" },
9071 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
9072 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
9073 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
9074 "{ A[a] -> C[(a)/6] }" },
9075 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
9076 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
9077 "{ A[a] -> C[(2a)/3] }" },
9078 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
9079 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
9080 "{ A[i,j] -> C[i + j, i + j] }"},
9081 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
9082 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
9083 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
9084 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
9085 "{ [i, j] -> [floor((i)/3), j] }",
9086 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
9089 static int test_pullback(isl_ctx
*ctx
)
9092 isl_multi_aff
*ma1
, *ma2
;
9096 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
9097 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
9098 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
9099 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
9100 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
9101 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
9102 isl_multi_aff_free(ma1
);
9103 isl_multi_aff_free(ma2
);
9107 isl_die(ctx
, isl_error_unknown
, "bad pullback",
9114 /* Check that negation is printed correctly and that equal expressions
9115 * are correctly identified.
9117 static int test_ast(isl_ctx
*ctx
)
9119 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
9123 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
9124 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
9125 expr
= isl_ast_expr_add(expr1
, expr2
);
9126 expr2
= isl_ast_expr_copy(expr
);
9127 expr
= isl_ast_expr_neg(expr
);
9128 expr2
= isl_ast_expr_neg(expr2
);
9129 equal
= isl_ast_expr_is_equal(expr
, expr2
);
9130 str
= isl_ast_expr_to_C_str(expr
);
9131 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
9133 isl_ast_expr_free(expr
);
9134 isl_ast_expr_free(expr2
);
9136 if (ok
< 0 || equal
< 0)
9139 isl_die(ctx
, isl_error_unknown
,
9140 "equal expressions not considered equal", return -1);
9142 isl_die(ctx
, isl_error_unknown
,
9143 "isl_ast_expr printed incorrectly", return -1);
9145 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
9146 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
9147 expr
= isl_ast_expr_add(expr1
, expr2
);
9148 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
9149 expr
= isl_ast_expr_sub(expr3
, expr
);
9150 str
= isl_ast_expr_to_C_str(expr
);
9151 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
9153 isl_ast_expr_free(expr
);
9158 isl_die(ctx
, isl_error_unknown
,
9159 "isl_ast_expr printed incorrectly", return -1);
9164 /* Check that isl_ast_build_expr_from_set returns a valid expression
9165 * for an empty set. Note that isl_ast_build_expr_from_set getting
9166 * called on an empty set probably indicates a bug in the caller.
9168 static int test_ast_build(isl_ctx
*ctx
)
9171 isl_ast_build
*build
;
9174 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9175 build
= isl_ast_build_from_context(set
);
9177 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
9178 expr
= isl_ast_build_expr_from_set(build
, set
);
9180 isl_ast_expr_free(expr
);
9181 isl_ast_build_free(build
);
9189 /* Internal data structure for before_for and after_for callbacks.
9191 * depth is the current depth
9192 * before is the number of times before_for has been called
9193 * after is the number of times after_for has been called
9195 struct isl_test_codegen_data
{
9201 /* This function is called before each for loop in the AST generated
9202 * from test_ast_gen1.
9204 * Increment the number of calls and the depth.
9205 * Check that the space returned by isl_ast_build_get_schedule_space
9206 * matches the target space of the schedule returned by
9207 * isl_ast_build_get_schedule.
9208 * Return an isl_id that is checked by the corresponding call
9211 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
9214 struct isl_test_codegen_data
*data
= user
;
9217 isl_union_map
*schedule
;
9218 isl_union_set
*uset
;
9224 ctx
= isl_ast_build_get_ctx(build
);
9226 if (data
->before
>= 3)
9227 isl_die(ctx
, isl_error_unknown
,
9228 "unexpected number of for nodes", return NULL
);
9229 if (data
->depth
>= 2)
9230 isl_die(ctx
, isl_error_unknown
,
9231 "unexpected depth", return NULL
);
9233 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
9237 schedule
= isl_ast_build_get_schedule(build
);
9238 uset
= isl_union_map_range(schedule
);
9239 n
= isl_union_set_n_set(uset
);
9241 isl_union_set_free(uset
);
9244 isl_die(ctx
, isl_error_unknown
,
9245 "expecting single range space", return NULL
);
9248 space
= isl_ast_build_get_schedule_space(build
);
9249 set
= isl_union_set_extract_set(uset
, space
);
9250 isl_union_set_free(uset
);
9251 empty
= isl_set_is_empty(set
);
9257 isl_die(ctx
, isl_error_unknown
,
9258 "spaces don't match", return NULL
);
9260 return isl_id_alloc(ctx
, name
, NULL
);
9263 /* This function is called after each for loop in the AST generated
9264 * from test_ast_gen1.
9266 * Increment the number of calls and decrement the depth.
9267 * Check that the annotation attached to the node matches
9268 * the isl_id returned by the corresponding call to before_for.
9270 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
9271 __isl_keep isl_ast_build
*build
, void *user
)
9273 struct isl_test_codegen_data
*data
= user
;
9281 if (data
->after
> data
->before
)
9282 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9283 "mismatch in number of for nodes",
9284 return isl_ast_node_free(node
));
9286 id
= isl_ast_node_get_annotation(node
);
9288 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9289 "missing annotation", return isl_ast_node_free(node
));
9291 name
= isl_id_get_name(id
);
9292 valid
= name
&& atoi(name
+ 1) == data
->depth
;
9296 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9297 "wrong annotation", return isl_ast_node_free(node
));
9302 /* Check that the before_each_for and after_each_for callbacks
9303 * are called for each for loop in the generated code,
9304 * that they are called in the right order and that the isl_id
9305 * returned from the before_each_for callback is attached to
9306 * the isl_ast_node passed to the corresponding after_each_for call.
9308 static int test_ast_gen1(isl_ctx
*ctx
)
9312 isl_union_map
*schedule
;
9313 isl_ast_build
*build
;
9315 struct isl_test_codegen_data data
;
9317 str
= "[N] -> { : N >= 10 }";
9318 set
= isl_set_read_from_str(ctx
, str
);
9319 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
9320 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
9321 schedule
= isl_union_map_read_from_str(ctx
, str
);
9326 build
= isl_ast_build_from_context(set
);
9327 build
= isl_ast_build_set_before_each_for(build
,
9328 &before_for
, &data
);
9329 build
= isl_ast_build_set_after_each_for(build
,
9331 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9332 isl_ast_build_free(build
);
9336 isl_ast_node_free(tree
);
9338 if (data
.before
!= 3 || data
.after
!= 3)
9339 isl_die(ctx
, isl_error_unknown
,
9340 "unexpected number of for nodes", return -1);
9345 /* Check that the AST generator handles domains that are integrally disjoint
9346 * but not rationally disjoint.
9348 static int test_ast_gen2(isl_ctx
*ctx
)
9352 isl_union_map
*schedule
;
9353 isl_union_map
*options
;
9354 isl_ast_build
*build
;
9357 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
9358 schedule
= isl_union_map_read_from_str(ctx
, str
);
9359 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9360 build
= isl_ast_build_from_context(set
);
9362 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
9363 options
= isl_union_map_read_from_str(ctx
, str
);
9364 build
= isl_ast_build_set_options(build
, options
);
9365 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9366 isl_ast_build_free(build
);
9369 isl_ast_node_free(tree
);
9374 /* Increment *user on each call.
9376 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
9377 __isl_keep isl_ast_build
*build
, void *user
)
9386 /* Test that unrolling tries to minimize the number of instances.
9387 * In particular, for the schedule given below, make sure it generates
9388 * 3 nodes (rather than 101).
9390 static int test_ast_gen3(isl_ctx
*ctx
)
9394 isl_union_map
*schedule
;
9395 isl_union_map
*options
;
9396 isl_ast_build
*build
;
9400 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
9401 schedule
= isl_union_map_read_from_str(ctx
, str
);
9402 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9404 str
= "{ [i] -> unroll[0] }";
9405 options
= isl_union_map_read_from_str(ctx
, str
);
9407 build
= isl_ast_build_from_context(set
);
9408 build
= isl_ast_build_set_options(build
, options
);
9409 build
= isl_ast_build_set_at_each_domain(build
,
9410 &count_domains
, &n_domain
);
9411 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9412 isl_ast_build_free(build
);
9416 isl_ast_node_free(tree
);
9419 isl_die(ctx
, isl_error_unknown
,
9420 "unexpected number of for nodes", return -1);
9425 /* Check that if the ast_build_exploit_nested_bounds options is set,
9426 * we do not get an outer if node in the generated AST,
9427 * while we do get such an outer if node if the options is not set.
9429 static int test_ast_gen4(isl_ctx
*ctx
)
9433 isl_union_map
*schedule
;
9434 isl_ast_build
*build
;
9436 enum isl_ast_node_type type
;
9439 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
9440 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
9442 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
9444 schedule
= isl_union_map_read_from_str(ctx
, str
);
9445 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9446 build
= isl_ast_build_from_context(set
);
9447 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9448 isl_ast_build_free(build
);
9452 type
= isl_ast_node_get_type(tree
);
9453 isl_ast_node_free(tree
);
9455 if (type
== isl_ast_node_if
)
9456 isl_die(ctx
, isl_error_unknown
,
9457 "not expecting if node", return -1);
9459 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
9461 schedule
= isl_union_map_read_from_str(ctx
, str
);
9462 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9463 build
= isl_ast_build_from_context(set
);
9464 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9465 isl_ast_build_free(build
);
9469 type
= isl_ast_node_get_type(tree
);
9470 isl_ast_node_free(tree
);
9472 if (type
!= isl_ast_node_if
)
9473 isl_die(ctx
, isl_error_unknown
,
9474 "expecting if node", return -1);
9476 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
9481 /* This function is called for each leaf in the AST generated
9482 * from test_ast_gen5.
9484 * We finalize the AST generation by extending the outer schedule
9485 * with a zero-dimensional schedule. If this results in any for loops,
9486 * then this means that we did not pass along enough information
9487 * about the outer schedule to the inner AST generation.
9489 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
9492 isl_union_map
*schedule
, *extra
;
9495 schedule
= isl_ast_build_get_schedule(build
);
9496 extra
= isl_union_map_copy(schedule
);
9497 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
9498 schedule
= isl_union_map_range_product(schedule
, extra
);
9499 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9500 isl_ast_build_free(build
);
9505 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
9506 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
9507 "code should not contain any for loop",
9508 return isl_ast_node_free(tree
));
9513 /* Check that we do not lose any information when going back and
9514 * forth between internal and external schedule.
9516 * In particular, we create an AST where we unroll the only
9517 * non-constant dimension in the schedule. We therefore do
9518 * not expect any for loops in the AST. However, older versions
9519 * of isl would not pass along enough information about the outer
9520 * schedule when performing an inner code generation from a create_leaf
9521 * callback, resulting in the inner code generation producing a for loop.
9523 static int test_ast_gen5(isl_ctx
*ctx
)
9527 isl_union_map
*schedule
, *options
;
9528 isl_ast_build
*build
;
9531 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
9532 schedule
= isl_union_map_read_from_str(ctx
, str
);
9534 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
9535 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
9536 options
= isl_union_map_read_from_str(ctx
, str
);
9538 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9539 build
= isl_ast_build_from_context(set
);
9540 build
= isl_ast_build_set_options(build
, options
);
9541 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
9542 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9543 isl_ast_build_free(build
);
9544 isl_ast_node_free(tree
);
9551 /* Check that the expression
9553 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
9555 * is not combined into
9559 * as this would result in n/2 being evaluated in parts of
9560 * the definition domain where n is not a multiple of 2.
9562 static int test_ast_expr(isl_ctx
*ctx
)
9566 isl_ast_build
*build
;
9571 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
9572 isl_options_set_ast_build_detect_min_max(ctx
, 1);
9574 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
9575 pa
= isl_pw_aff_read_from_str(ctx
, str
);
9576 build
= isl_ast_build_alloc(ctx
);
9577 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
9578 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
9579 isl_ast_expr_get_op_type(expr
) == isl_ast_expr_op_min
;
9580 isl_ast_build_free(build
);
9581 isl_ast_expr_free(expr
);
9583 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
9588 isl_die(ctx
, isl_error_unknown
,
9589 "expressions should not be combined", return -1);
9594 static int test_ast_gen(isl_ctx
*ctx
)
9596 if (test_ast_gen1(ctx
) < 0)
9598 if (test_ast_gen2(ctx
) < 0)
9600 if (test_ast_gen3(ctx
) < 0)
9602 if (test_ast_gen4(ctx
) < 0)
9604 if (test_ast_gen5(ctx
) < 0)
9606 if (test_ast_expr(ctx
) < 0)
9611 /* Check if dropping output dimensions from an isl_pw_multi_aff
9614 static int test_pw_multi_aff(isl_ctx
*ctx
)
9617 isl_pw_multi_aff
*pma1
, *pma2
;
9620 str
= "{ [i,j] -> [i+j, 4i-j] }";
9621 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9622 str
= "{ [i,j] -> [4i-j] }";
9623 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9625 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
9627 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
9629 isl_pw_multi_aff_free(pma1
);
9630 isl_pw_multi_aff_free(pma2
);
9634 isl_die(ctx
, isl_error_unknown
,
9635 "expressions not equal", return -1);
9640 /* Check that we can properly parse multi piecewise affine expressions
9641 * where the piecewise affine expressions have different domains.
9643 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
9646 isl_set
*dom
, *dom2
;
9647 isl_multi_pw_aff
*mpa1
, *mpa2
;
9652 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
9653 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
9654 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
9655 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
9656 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
9657 str
= "{ [i] -> [(i : i > 0), 2i] }";
9658 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
9660 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
9662 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
9663 dom
= isl_pw_aff_domain(pa
);
9664 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
9665 dom2
= isl_pw_aff_domain(pa
);
9666 equal_domain
= isl_set_is_equal(dom
, dom2
);
9670 isl_multi_pw_aff_free(mpa1
);
9671 isl_multi_pw_aff_free(mpa2
);
9676 isl_die(ctx
, isl_error_unknown
,
9677 "expressions not equal", return -1);
9679 if (equal_domain
< 0)
9682 isl_die(ctx
, isl_error_unknown
,
9683 "domains unexpectedly equal", return -1);
9688 /* Check that the dimensions in the explicit domain
9689 * of a multi piecewise affine expression are properly
9690 * taken into account.
9692 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
9695 isl_bool involves1
, involves2
, involves3
, equal
;
9696 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
9698 str
= "{ A[x,y] -> B[] : x >= y }";
9699 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
9700 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
9701 mpa1
= isl_multi_pw_aff_copy(mpa
);
9703 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
9704 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
9705 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
9706 str
= "{ [a,x,y] -> B[] : x >= y }";
9707 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
9708 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
9709 isl_multi_pw_aff_free(mpa2
);
9711 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
9712 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
9713 if (equal
>= 0 && equal
)
9714 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
9715 isl_multi_pw_aff_free(mpa1
);
9716 isl_multi_pw_aff_free(mpa
);
9718 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
9721 isl_die(ctx
, isl_error_unknown
,
9722 "incorrect result of dimension insertion/removal",
9723 return isl_stat_error
);
9724 if (!involves1
|| involves2
|| !involves3
)
9725 isl_die(ctx
, isl_error_unknown
,
9726 "incorrect characterization of involved dimensions",
9727 return isl_stat_error
);
9732 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
9733 * sets the explicit domain of a zero-dimensional result,
9734 * such that it can be converted to an isl_union_map.
9736 static isl_stat
test_multi_pw_aff_3(isl_ctx
*ctx
)
9741 isl_multi_union_pw_aff
*mupa
;
9742 isl_union_map
*umap
;
9744 dom
= isl_union_set_read_from_str(ctx
, "{ A[]; B[] }");
9745 space
= isl_union_set_get_space(dom
);
9746 mv
= isl_multi_val_zero(isl_space_set_from_params(space
));
9747 mupa
= isl_multi_union_pw_aff_multi_val_on_domain(dom
, mv
);
9748 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
9749 isl_union_map_free(umap
);
9751 return isl_stat_error
;
9756 /* Perform some tests on multi piecewise affine expressions.
9758 static int test_multi_pw_aff(isl_ctx
*ctx
)
9760 if (test_multi_pw_aff_1(ctx
) < 0)
9762 if (test_multi_pw_aff_2(ctx
) < 0)
9764 if (test_multi_pw_aff_3(ctx
) < 0)
9769 /* This is a regression test for a bug where isl_basic_map_simplify
9770 * would end up in an infinite loop. In particular, we construct
9771 * an empty basic set that is not obviously empty.
9772 * isl_basic_set_is_empty marks the basic set as empty.
9773 * After projecting out i3, the variable can be dropped completely,
9774 * but isl_basic_map_simplify refrains from doing so if the basic set
9775 * is empty and would end up in an infinite loop if it didn't test
9776 * explicitly for empty basic maps in the outer loop.
9778 static int test_simplify_1(isl_ctx
*ctx
)
9781 isl_basic_set
*bset
;
9784 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
9785 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
9786 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
9788 bset
= isl_basic_set_read_from_str(ctx
, str
);
9789 empty
= isl_basic_set_is_empty(bset
);
9790 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
9791 isl_basic_set_free(bset
);
9795 isl_die(ctx
, isl_error_unknown
,
9796 "basic set should be empty", return -1);
9801 /* Check that the equality in the set description below
9802 * is simplified away.
9804 static int test_simplify_2(isl_ctx
*ctx
)
9807 isl_basic_set
*bset
;
9810 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
9811 bset
= isl_basic_set_read_from_str(ctx
, str
);
9812 universe
= isl_basic_set_plain_is_universe(bset
);
9813 isl_basic_set_free(bset
);
9818 isl_die(ctx
, isl_error_unknown
,
9819 "equality not simplified away", return -1);
9823 /* Some simplification tests.
9825 static int test_simplify(isl_ctx
*ctx
)
9827 if (test_simplify_1(ctx
) < 0)
9829 if (test_simplify_2(ctx
) < 0)
9834 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
9835 * with gbr context would fail to disable the use of the shifted tableau
9836 * when transferring equalities for the input to the context, resulting
9837 * in invalid sample values.
9839 static int test_partial_lexmin(isl_ctx
*ctx
)
9842 isl_basic_set
*bset
;
9843 isl_basic_map
*bmap
;
9846 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
9847 bmap
= isl_basic_map_read_from_str(ctx
, str
);
9848 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
9849 bset
= isl_basic_set_read_from_str(ctx
, str
);
9850 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
9859 /* Check that the variable compression performed on the existentially
9860 * quantified variables inside isl_basic_set_compute_divs is not confused
9861 * by the implicit equalities among the parameters.
9863 static int test_compute_divs(isl_ctx
*ctx
)
9866 isl_basic_set
*bset
;
9869 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
9870 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
9871 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
9872 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
9873 bset
= isl_basic_set_read_from_str(ctx
, str
);
9874 set
= isl_basic_set_compute_divs(bset
);
9882 /* Check that isl_schedule_get_map is not confused by a schedule tree
9883 * with divergent filter node parameters, as can result from a call
9884 * to isl_schedule_intersect_domain.
9886 static int test_schedule_tree(isl_ctx
*ctx
)
9889 isl_union_set
*uset
;
9890 isl_schedule
*sched1
, *sched2
;
9891 isl_union_map
*umap
;
9893 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
9894 sched1
= isl_schedule_from_domain(uset
);
9895 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
9896 sched2
= isl_schedule_from_domain(uset
);
9898 sched1
= isl_schedule_sequence(sched1
, sched2
);
9899 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
9900 uset
= isl_union_set_read_from_str(ctx
, str
);
9901 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
9902 umap
= isl_schedule_get_map(sched1
);
9903 isl_schedule_free(sched1
);
9904 isl_union_map_free(umap
);
9911 /* Check that a zero-dimensional prefix schedule keeps track
9912 * of the domain and outer filters.
9914 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
9918 isl_union_set
*uset
;
9919 isl_union_set_list
*filters
;
9920 isl_multi_union_pw_aff
*mupa
, *mupa2
;
9921 isl_schedule_node
*node
;
9923 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
9924 uset
= isl_union_set_read_from_str(ctx
, str
);
9925 node
= isl_schedule_node_from_domain(uset
);
9926 node
= isl_schedule_node_child(node
, 0);
9928 str
= "{ S1[i,j] : i > j }";
9929 uset
= isl_union_set_read_from_str(ctx
, str
);
9930 filters
= isl_union_set_list_from_union_set(uset
);
9931 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
9932 uset
= isl_union_set_read_from_str(ctx
, str
);
9933 filters
= isl_union_set_list_add(filters
, uset
);
9934 node
= isl_schedule_node_insert_sequence(node
, filters
);
9936 node
= isl_schedule_node_child(node
, 0);
9937 node
= isl_schedule_node_child(node
, 0);
9938 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
9939 str
= "([] : { S1[i,j] : i > j })";
9940 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9941 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
9942 isl_multi_union_pw_aff_free(mupa2
);
9943 isl_multi_union_pw_aff_free(mupa
);
9944 isl_schedule_node_free(node
);
9949 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
9955 /* Check that the reaching domain elements and the prefix schedule
9956 * at a leaf node are the same before and after grouping.
9958 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
9963 isl_union_set
*uset
;
9964 isl_multi_union_pw_aff
*mupa
;
9965 isl_union_pw_multi_aff
*upma1
, *upma2
;
9966 isl_union_set
*domain1
, *domain2
;
9967 isl_union_map
*umap1
, *umap2
;
9968 isl_schedule_node
*node
;
9970 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
9971 uset
= isl_union_set_read_from_str(ctx
, str
);
9972 node
= isl_schedule_node_from_domain(uset
);
9973 node
= isl_schedule_node_child(node
, 0);
9974 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
9975 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9976 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
9977 node
= isl_schedule_node_child(node
, 0);
9978 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
9979 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
9980 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
9981 node
= isl_schedule_node_child(node
, 0);
9982 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
9983 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
9984 domain1
= isl_schedule_node_get_domain(node
);
9985 id
= isl_id_alloc(ctx
, "group", NULL
);
9986 node
= isl_schedule_node_parent(node
);
9987 node
= isl_schedule_node_group(node
, id
);
9988 node
= isl_schedule_node_child(node
, 0);
9989 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
9990 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
9991 domain2
= isl_schedule_node_get_domain(node
);
9992 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
9993 if (equal
>= 0 && equal
)
9994 equal
= isl_union_set_is_equal(domain1
, domain2
);
9995 if (equal
>= 0 && equal
)
9996 equal
= isl_union_map_is_equal(umap1
, umap2
);
9997 isl_union_map_free(umap1
);
9998 isl_union_map_free(umap2
);
9999 isl_union_set_free(domain1
);
10000 isl_union_set_free(domain2
);
10001 isl_union_pw_multi_aff_free(upma1
);
10002 isl_union_pw_multi_aff_free(upma2
);
10003 isl_schedule_node_free(node
);
10008 isl_die(ctx
, isl_error_unknown
,
10009 "expressions not equal", return -1);
10014 /* Check that we can have nested groupings and that the union map
10015 * schedule representation is the same before and after the grouping.
10016 * Note that after the grouping, the union map representation contains
10017 * the domain constraints from the ranges of the expansion nodes,
10018 * while they are missing from the union map representation of
10019 * the tree without expansion nodes.
10021 * Also check that the global expansion is as expected.
10023 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
10025 int equal
, equal_expansion
;
10028 isl_union_set
*uset
;
10029 isl_union_map
*umap1
, *umap2
;
10030 isl_union_map
*expansion1
, *expansion2
;
10031 isl_union_set_list
*filters
;
10032 isl_multi_union_pw_aff
*mupa
;
10033 isl_schedule
*schedule
;
10034 isl_schedule_node
*node
;
10036 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
10037 "S3[i,j] : 0 <= i,j < 10 }";
10038 uset
= isl_union_set_read_from_str(ctx
, str
);
10039 node
= isl_schedule_node_from_domain(uset
);
10040 node
= isl_schedule_node_child(node
, 0);
10041 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
10042 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10043 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10044 node
= isl_schedule_node_child(node
, 0);
10045 str
= "{ S1[i,j] }";
10046 uset
= isl_union_set_read_from_str(ctx
, str
);
10047 filters
= isl_union_set_list_from_union_set(uset
);
10048 str
= "{ S2[i,j]; S3[i,j] }";
10049 uset
= isl_union_set_read_from_str(ctx
, str
);
10050 filters
= isl_union_set_list_add(filters
, uset
);
10051 node
= isl_schedule_node_insert_sequence(node
, filters
);
10052 node
= isl_schedule_node_child(node
, 1);
10053 node
= isl_schedule_node_child(node
, 0);
10054 str
= "{ S2[i,j] }";
10055 uset
= isl_union_set_read_from_str(ctx
, str
);
10056 filters
= isl_union_set_list_from_union_set(uset
);
10057 str
= "{ S3[i,j] }";
10058 uset
= isl_union_set_read_from_str(ctx
, str
);
10059 filters
= isl_union_set_list_add(filters
, uset
);
10060 node
= isl_schedule_node_insert_sequence(node
, filters
);
10062 schedule
= isl_schedule_node_get_schedule(node
);
10063 umap1
= isl_schedule_get_map(schedule
);
10064 uset
= isl_schedule_get_domain(schedule
);
10065 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
10066 isl_schedule_free(schedule
);
10068 node
= isl_schedule_node_parent(node
);
10069 node
= isl_schedule_node_parent(node
);
10070 id
= isl_id_alloc(ctx
, "group1", NULL
);
10071 node
= isl_schedule_node_group(node
, id
);
10072 node
= isl_schedule_node_child(node
, 1);
10073 node
= isl_schedule_node_child(node
, 0);
10074 id
= isl_id_alloc(ctx
, "group2", NULL
);
10075 node
= isl_schedule_node_group(node
, id
);
10077 schedule
= isl_schedule_node_get_schedule(node
);
10078 umap2
= isl_schedule_get_map(schedule
);
10079 isl_schedule_free(schedule
);
10081 node
= isl_schedule_node_root(node
);
10082 node
= isl_schedule_node_child(node
, 0);
10083 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
10084 isl_schedule_node_free(node
);
10086 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
10087 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
10088 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
10090 expansion2
= isl_union_map_read_from_str(ctx
, str
);
10092 equal
= isl_union_map_is_equal(umap1
, umap2
);
10093 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
10095 isl_union_map_free(umap1
);
10096 isl_union_map_free(umap2
);
10097 isl_union_map_free(expansion1
);
10098 isl_union_map_free(expansion2
);
10100 if (equal
< 0 || equal_expansion
< 0)
10103 isl_die(ctx
, isl_error_unknown
,
10104 "expressions not equal", return -1);
10105 if (!equal_expansion
)
10106 isl_die(ctx
, isl_error_unknown
,
10107 "unexpected expansion", return -1);
10112 /* Some tests for the isl_schedule_node_group function.
10114 static int test_schedule_tree_group(isl_ctx
*ctx
)
10116 if (test_schedule_tree_group_1(ctx
) < 0)
10118 if (test_schedule_tree_group_2(ctx
) < 0)
10127 { "{ rat: [i] : 0 <= i <= 10 }",
10128 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
10129 { "{ rat: [i] : FALSE }",
10130 "{ rat: coefficients[[cst] -> [a]] }" },
10131 { "{ rat: [i] : }",
10132 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
10133 { "{ [0:,1,2:3] }",
10134 "{ rat: coefficients[[c_cst] -> [a, b, c]] : "
10135 "a >= 0 and 2c >= -c_cst - b and 3c >= -c_cst - b }" },
10136 { "[M, N] -> { [x = (1 - N):-1, -4x:(M - 4x)] }",
10137 "{ rat: coefficients[[c_cst, c_M = 0:, c_N = 0:] -> [a, b = -c_M:]] :"
10138 "4b >= -c_N + a and 4b >= -c_cst - 2c_N + a }" },
10139 { "{ rat : [x, y] : 1 <= 2x <= 9 and 2 <= 3y <= 16 }",
10140 "{ rat: coefficients[[c_cst] -> [c_x, c_y]] : "
10141 "4c_y >= -6c_cst - 3c_x and 4c_y >= -6c_cst - 27c_x and "
10142 "32c_y >= -6c_cst - 3c_x and 32c_y >= -6c_cst - 27c_x }" },
10143 { "{ [x, y, z] : 3y <= 2x - 2 and y >= -2 + 2x and 2y >= 2 - x }",
10144 "{ rat: coefficients[[cst] -> [a, b, c]] }" },
10151 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
10152 "{ rat: [i] : 0 <= i <= 10 }" },
10153 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
10155 { "{ rat: coefficients[[cst] -> [a]] }",
10156 "{ rat: [i] : FALSE }" },
10159 /* Test the basic functionality of isl_basic_set_coefficients and
10160 * isl_basic_set_solutions.
10162 static int test_dual(isl_ctx
*ctx
)
10166 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
10168 isl_basic_set
*bset1
, *bset2
;
10170 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
10171 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
10172 bset1
= isl_basic_set_coefficients(bset1
);
10173 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10174 isl_basic_set_free(bset1
);
10175 isl_basic_set_free(bset2
);
10179 isl_die(ctx
, isl_error_unknown
,
10180 "incorrect dual", return -1);
10183 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
10185 isl_basic_set
*bset1
, *bset2
;
10187 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
10188 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
10189 bset1
= isl_basic_set_solutions(bset1
);
10190 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10191 isl_basic_set_free(bset1
);
10192 isl_basic_set_free(bset2
);
10196 isl_die(ctx
, isl_error_unknown
,
10197 "incorrect dual", return -1);
10206 const char *domain
;
10207 const char *schedule
;
10212 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10213 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10215 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10216 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10218 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10219 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10221 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10222 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10224 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10225 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10227 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10228 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10230 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10231 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10233 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10234 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10238 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
10239 * tile the band and then check if the tile and point bands have the
10240 * expected partial schedule.
10242 static int test_tile(isl_ctx
*ctx
)
10248 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
10249 shift
= isl_options_get_tile_shift_point_loops(ctx
);
10251 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
10255 isl_union_set
*domain
;
10256 isl_multi_union_pw_aff
*mupa
, *mupa2
;
10257 isl_schedule_node
*node
;
10258 isl_multi_val
*sizes
;
10260 opt
= tile_tests
[i
].scale_tile
;
10261 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
10262 opt
= tile_tests
[i
].shift_point
;
10263 isl_options_set_tile_shift_point_loops(ctx
, opt
);
10265 str
= tile_tests
[i
].domain
;
10266 domain
= isl_union_set_read_from_str(ctx
, str
);
10267 node
= isl_schedule_node_from_domain(domain
);
10268 node
= isl_schedule_node_child(node
, 0);
10269 str
= tile_tests
[i
].schedule
;
10270 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10271 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10272 str
= tile_tests
[i
].sizes
;
10273 sizes
= isl_multi_val_read_from_str(ctx
, str
);
10274 node
= isl_schedule_node_band_tile(node
, sizes
);
10276 str
= tile_tests
[i
].tile
;
10277 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10278 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10279 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
10280 isl_multi_union_pw_aff_free(mupa
);
10281 isl_multi_union_pw_aff_free(mupa2
);
10283 node
= isl_schedule_node_child(node
, 0);
10285 str
= tile_tests
[i
].point
;
10286 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10287 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10288 if (equal
>= 0 && equal
)
10289 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
10291 isl_multi_union_pw_aff_free(mupa
);
10292 isl_multi_union_pw_aff_free(mupa2
);
10294 isl_schedule_node_free(node
);
10299 isl_die(ctx
, isl_error_unknown
,
10300 "unexpected result", return -1);
10303 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
10304 isl_options_set_tile_shift_point_loops(ctx
, shift
);
10309 /* Check that the domain hash of a space is equal to the hash
10310 * of the domain of the space.
10312 static int test_domain_hash(isl_ctx
*ctx
)
10316 uint32_t hash1
, hash2
;
10318 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
10319 space
= isl_map_get_space(map
);
10321 hash1
= isl_space_get_domain_hash(space
);
10322 space
= isl_space_domain(space
);
10323 hash2
= isl_space_get_hash(space
);
10324 isl_space_free(space
);
10328 if (hash1
!= hash2
)
10329 isl_die(ctx
, isl_error_unknown
,
10330 "domain hash not equal to hash of domain", return -1);
10335 /* Check that a universe basic set that is not obviously equal to the universe
10336 * is still recognized as being equal to the universe.
10338 static int test_universe(isl_ctx
*ctx
)
10341 isl_basic_set
*bset
;
10344 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
10345 bset
= isl_basic_set_read_from_str(ctx
, s
);
10346 is_univ
= isl_basic_set_is_universe(bset
);
10347 isl_basic_set_free(bset
);
10352 isl_die(ctx
, isl_error_unknown
,
10353 "not recognized as universe set", return -1);
10358 /* Sets for which chambers are computed and checked.
10360 const char *chambers_tests
[] = {
10361 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
10362 "z >= 0 and z <= C - y and z <= B - x - y }",
10365 /* Add the domain of "cell" to "cells".
10367 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
10369 isl_basic_set_list
**cells
= user
;
10370 isl_basic_set
*dom
;
10372 dom
= isl_cell_get_domain(cell
);
10373 isl_cell_free(cell
);
10374 *cells
= isl_basic_set_list_add(*cells
, dom
);
10376 return *cells
? isl_stat_ok
: isl_stat_error
;
10379 /* Check that the elements of "list" are pairwise disjoint.
10381 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
10386 n
= isl_basic_set_list_n_basic_set(list
);
10388 return isl_stat_error
;
10390 for (i
= 0; i
< n
; ++i
) {
10391 isl_basic_set
*bset_i
;
10393 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
10394 for (j
= i
+ 1; j
< n
; ++j
) {
10395 isl_basic_set
*bset_j
;
10398 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
10399 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
10400 isl_basic_set_free(bset_j
);
10402 isl_die(isl_basic_set_list_get_ctx(list
),
10403 isl_error_unknown
, "not disjoint",
10405 if (disjoint
< 0 || !disjoint
)
10408 isl_basic_set_free(bset_i
);
10410 return isl_stat_error
;
10413 return isl_stat_ok
;
10416 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
10417 * are pairwise disjoint.
10419 static int test_chambers(isl_ctx
*ctx
)
10423 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
10424 isl_basic_set
*bset
;
10425 isl_vertices
*vertices
;
10426 isl_basic_set_list
*cells
;
10429 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
10430 vertices
= isl_basic_set_compute_vertices(bset
);
10431 cells
= isl_basic_set_list_alloc(ctx
, 0);
10432 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
10434 cells
= isl_basic_set_list_free(cells
);
10435 ok
= check_pairwise_disjoint(cells
);
10436 isl_basic_set_list_free(cells
);
10437 isl_vertices_free(vertices
);
10438 isl_basic_set_free(bset
);
10449 int (*fn
)(isl_ctx
*ctx
);
10451 { "universe", &test_universe
},
10452 { "domain hash", &test_domain_hash
},
10453 { "dual", &test_dual
},
10454 { "dependence analysis", &test_flow
},
10455 { "val", &test_val
},
10456 { "compute divs", &test_compute_divs
},
10457 { "partial lexmin", &test_partial_lexmin
},
10458 { "simplify", &test_simplify
},
10459 { "curry", &test_curry
},
10460 { "piecewise multi affine expressions", &test_pw_multi_aff
},
10461 { "multi piecewise affine expressions", &test_multi_pw_aff
},
10462 { "conversion", &test_conversion
},
10463 { "list", &test_list
},
10464 { "align parameters", &test_align_parameters
},
10465 { "drop unused parameters", &test_drop_unused_parameters
},
10466 { "preimage", &test_preimage
},
10467 { "pullback", &test_pullback
},
10468 { "AST", &test_ast
},
10469 { "AST build", &test_ast_build
},
10470 { "AST generation", &test_ast_gen
},
10471 { "eliminate", &test_eliminate
},
10472 { "deltas_map", &test_deltas_map
},
10473 { "residue class", &test_residue_class
},
10474 { "div", &test_div
},
10475 { "slice", &test_slice
},
10476 { "fixed power", &test_fixed_power
},
10477 { "sample", &test_sample
},
10478 { "output", &test_output
},
10479 { "vertices", &test_vertices
},
10480 { "chambers", &test_chambers
},
10481 { "fixed", &test_fixed
},
10482 { "equal", &test_equal
},
10483 { "disjoint", &test_disjoint
},
10484 { "product", &test_product
},
10485 { "dim_max", &test_dim_max
},
10486 { "affine", &test_aff
},
10487 { "injective", &test_injective
},
10488 { "schedule (whole component)", &test_schedule_whole
},
10489 { "schedule (incremental)", &test_schedule_incremental
},
10490 { "schedule tree", &test_schedule_tree
},
10491 { "schedule tree prefix", &test_schedule_tree_prefix
},
10492 { "schedule tree grouping", &test_schedule_tree_group
},
10493 { "tile", &test_tile
},
10494 { "union map", &test_union_map
},
10495 { "union_pw", &test_union_pw
},
10496 { "locus", &test_locus
},
10497 { "eval", &test_eval
},
10498 { "parse", &test_parse
},
10499 { "single-valued", &test_sv
},
10500 { "recession cone", &test_recession_cone
},
10501 { "affine hull", &test_affine_hull
},
10502 { "simple_hull", &test_simple_hull
},
10503 { "box hull", &test_box_hull
},
10504 { "coalesce", &test_coalesce
},
10505 { "factorize", &test_factorize
},
10506 { "subset", &test_subset
},
10507 { "subtract", &test_subtract
},
10508 { "intersect", &test_intersect
},
10509 { "lexmin", &test_lexmin
},
10510 { "min", &test_min
},
10511 { "gist", &test_gist
},
10512 { "piecewise quasi-polynomials", &test_pwqp
},
10513 { "lift", &test_lift
},
10514 { "bind parameters", &test_bind
},
10515 { "unbind parameters", &test_unbind
},
10516 { "bound", &test_bound
},
10517 { "get lists", &test_get_list
},
10518 { "union", &test_union
},
10519 { "split periods", &test_split_periods
},
10520 { "lexicographic order", &test_lex
},
10521 { "bijectivity", &test_bijective
},
10522 { "dataflow analysis", &test_dep
},
10523 { "reading", &test_read
},
10524 { "bounded", &test_bounded
},
10525 { "construction", &test_construction
},
10526 { "dimension manipulation", &test_dim
},
10527 { "map application", &test_application
},
10528 { "convex hull", &test_convex_hull
},
10529 { "transitive closure", &test_closure
},
10530 { "isl_bool", &test_isl_bool
},
10533 int main(int argc
, char **argv
)
10536 struct isl_ctx
*ctx
;
10537 struct isl_options
*options
;
10539 options
= isl_options_new_with_defaults();
10541 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
10543 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
10544 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
10545 printf("%s\n", tests
[i
].name
);
10546 if (tests
[i
].fn(ctx
) < 0)