2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
5 * Copyright 2014 INRIA Rocquencourt
7 * Use of this software is governed by the MIT license
9 * Written by Sven Verdoolaege, K.U.Leuven, Departement
10 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
11 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
12 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
14 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
15 * B.P. 105 - 78153 Le Chesnay, France
21 #include <isl_ctx_private.h>
22 #include <isl_map_private.h>
23 #include <isl_aff_private.h>
24 #include <isl_space_private.h>
28 #include <isl_constraint_private.h>
29 #include <isl/polynomial.h>
30 #include <isl/union_set.h>
31 #include <isl/union_map.h>
32 #include <isl_factorization.h>
33 #include <isl/schedule.h>
34 #include <isl/schedule_node.h>
35 #include <isl_options_private.h>
36 #include <isl_vertices_private.h>
37 #include <isl/ast_build.h>
40 #include <isl_ast_build_expr.h>
41 #include <isl/options.h>
43 #include "isl_srcdir.c"
45 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
47 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
50 char *pattern
= "%s/test_inputs/%s.%s";
52 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
54 filename
= isl_alloc_array(ctx
, char, length
);
59 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
64 void test_parse_map(isl_ctx
*ctx
, const char *str
)
68 map
= isl_map_read_from_str(ctx
, str
);
73 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
78 map
= isl_map_read_from_str(ctx
, str
);
79 map2
= isl_map_read_from_str(ctx
, str2
);
80 equal
= isl_map_is_equal(map
, map2
);
87 isl_die(ctx
, isl_error_unknown
, "maps not equal",
93 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
95 isl_pw_qpolynomial
*pwqp
;
97 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
99 isl_pw_qpolynomial_free(pwqp
);
102 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
106 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
108 isl_pw_aff_free(pwaff
);
111 /* Check that we can read an isl_multi_val from "str" without errors.
113 static int test_parse_multi_val(isl_ctx
*ctx
, const char *str
)
117 mv
= isl_multi_val_read_from_str(ctx
, str
);
118 isl_multi_val_free(mv
);
123 /* String descriptions of multi piecewise affine expressions
124 * that are used for testing printing and parsing.
126 static const char *reparse_multi_pw_aff_tests
[] = {
127 "{ A[x, y] -> [] : x + y >= 0 }",
128 "{ A[x, y] -> B[] : x + y >= 0 }",
129 "{ A[x, y] -> [x] : x + y >= 0 }",
130 "[N] -> { A[x, y] -> [x] : x + y <= N }",
131 "{ A[x, y] -> [x, y] : x + y >= 0 }",
132 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
133 "[N] -> { [] : N >= 0 }",
134 "[N] -> { [] : N >= 0 }",
135 "[N] -> { [N] : N >= 0 }",
136 "[N] -> { [N, N + 1] : N >= 0 }",
137 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
141 #define BASE multi_pw_aff
143 #include "check_reparse_templ.c"
144 #include "check_reparse_test_templ.c"
146 /* String descriptions of piecewise multi affine expressions
147 * that are used for testing printing and parsing.
149 static const char *reparse_pw_multi_aff_tests
[] = {
151 "{ [x] -> [x % 4] }",
152 "{ [x] -> [x % 4] : x mod 3 = 1 }",
153 "{ [x, x] -> [x % 4] }",
154 "{ [x, x + 1] -> [x % 4] : x mod 3 = 1 }",
155 "{ [x, x mod 2] -> [x % 4] }",
159 #define BASE pw_multi_aff
161 #include "check_reparse_templ.c"
162 #include "check_reparse_test_templ.c"
164 /* Test parsing of piecewise multi affine expressions by printing
165 * the expressions and checking that parsing the output results
166 * in the same expression.
167 * Do this for an expression converted from a map with an output
168 * dimension name that is equal to an automatically generated name, and
169 * a set of expressions parsed from strings.
171 static isl_stat
test_parse_pma(isl_ctx
*ctx
)
174 isl_pw_multi_aff
*pma
;
176 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
177 pma
= isl_pw_multi_aff_from_map(map
);
178 if (check_reparse_pw_multi_aff(ctx
, pma
) < 0)
179 return isl_stat_error
;
181 if (check_reparse_pw_multi_aff_tests(ctx
) < 0)
182 return isl_stat_error
;
187 /* Test parsing of multi piecewise affine expressions by printing
188 * the expressions and checking that parsing the output results
189 * in the same expression.
190 * Do this for a couple of manually constructed expressions,
191 * an expression converted from a map with an output dimension name
192 * that is equal to an automatically generated name, and
193 * a set of expressions parsed from strings.
195 static int test_parse_mpa(isl_ctx
*ctx
)
200 isl_pw_multi_aff
*pma
;
201 isl_multi_pw_aff
*mpa
;
204 space
= isl_space_set_alloc(ctx
, 0, 0);
205 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
206 mpa
= isl_multi_pw_aff_zero(space
);
207 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
211 space
= isl_space_set_alloc(ctx
, 1, 0);
212 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
213 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
214 dom
= isl_set_universe(isl_space_params(isl_space_copy(space
)));
215 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
216 mpa
= isl_multi_pw_aff_zero(space
);
217 mpa
= isl_multi_pw_aff_intersect_domain(mpa
, dom
);
218 r
= check_reparse_multi_pw_aff(ctx
, mpa
);
222 map
= isl_map_read_from_str(ctx
, "{ [a, a] -> [i1 = a + 1] }");
223 pma
= isl_pw_multi_aff_from_map(map
);
224 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma
);
225 if (check_reparse_multi_pw_aff(ctx
, mpa
) < 0)
228 if (check_reparse_multi_pw_aff_tests(ctx
) < 0)
234 /* String descriptions of multi union piecewise affine expressions
235 * that are used for testing printing and parsing.
237 static const char *reparse_multi_union_pw_aff_tests
[] = {
241 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
243 "[N] -> (A[] : { })",
244 "[N] -> (A[] : { : N >= 0 })",
245 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
246 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
247 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
248 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
249 "{ S[x] : x > 0; T[y] : y >= 0 })",
253 #define BASE multi_union_pw_aff
255 #include "check_reparse_templ.c"
256 #include "check_reparse_test_templ.c"
258 /* Test parsing of multi union piecewise affine expressions by printing
259 * the expressions and checking that parsing the output results
260 * in the same expression.
261 * Do this for a couple of manually constructed expressions and
262 * a set of expressions parsed from strings.
264 static int test_parse_mupa(isl_ctx
*ctx
)
267 isl_multi_union_pw_aff
*mupa
;
272 space
= isl_space_set_alloc(ctx
, 0, 0);
273 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
274 mupa
= isl_multi_union_pw_aff_zero(space
);
275 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
279 space
= isl_space_set_alloc(ctx
, 1, 0);
280 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
281 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "A");
282 dom
= isl_set_universe(space
);
283 dom
= isl_set_lower_bound_si(dom
, isl_dim_param
, 0, 5);
284 uset
= isl_union_set_from_set(dom
);
285 space
= isl_space_set_alloc(ctx
, 1, 0);
286 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
287 space
= isl_space_set_tuple_name(space
, isl_dim_set
, "B");
288 mupa
= isl_multi_union_pw_aff_zero(space
);
289 mupa
= isl_multi_union_pw_aff_intersect_domain(mupa
, uset
);
290 r
= check_reparse_multi_union_pw_aff(ctx
, mupa
);
294 if (check_reparse_multi_union_pw_aff_tests(ctx
) < 0)
300 /* Test parsing of multi expressions.
302 static int test_parse_multi(isl_ctx
*ctx
)
304 if (test_parse_mpa(ctx
) < 0)
306 if (test_parse_mupa(ctx
) < 0)
312 /* Pairs of binary relation representations that should represent
313 * the same binary relations.
318 } parse_map_equal_tests
[] = {
319 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
320 "{ [x, y] : 2y >= 6 - x }" },
321 { "{ [x,y] : x <= min(y, 2*y+3) }",
322 "{ [x,y] : x <= y, 2*y + 3 }" },
323 { "{ [x,y] : x >= min(y, 2*y+3) }",
324 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
325 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
326 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
327 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
328 "{ [i,j] -> [min(i,j)] }" },
329 { "{ [i,j] : i != j }",
330 "{ [i,j] : i < j or i > j }" },
331 { "{ [i,j] : (i+1)*2 >= j }",
332 "{ [i, j] : j <= 2 + 2i }" },
333 { "{ [i] -> [i > 0 ? 4 : 5] }",
334 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
335 { "[N=2,M] -> { [i=[(M+N)/4]] }",
336 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
337 { "{ [x] : x >= 0 }",
338 "{ [x] : x-0 >= 0 }" },
339 { "{ [i] : ((i > 10)) }",
340 "{ [i] : i >= 11 }" },
342 "{ [i] -> [0 * i] }" },
343 { "{ [a] -> [b] : (not false) }",
344 "{ [a] -> [b] : true }" },
345 { "{ [i] : i/2 <= 5 }",
346 "{ [i] : i <= 10 }" },
347 { "{Sym=[n] [i] : i <= n }",
348 "[n] -> { [i] : i <= n }" },
351 { "{ [i] : 2*floor(i/2) = i }",
352 "{ [i] : exists a : i = 2 a }" },
353 { "{ [a] -> [b] : a = 5 implies b = 5 }",
354 "{ [a] -> [b] : a != 5 or b = 5 }" },
355 { "{ [a] -> [a - 1 : a > 0] }",
356 "{ [a] -> [a - 1] : a > 0 }" },
357 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
358 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
359 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
360 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
361 { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
362 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
363 { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
364 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
365 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
366 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
367 { "{ [a,b] -> [i,j] : a,b << i,j }",
368 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
369 { "{ [a,b] -> [i,j] : a,b <<= i,j }",
370 "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" },
371 { "{ [a,b] -> [i,j] : a,b >> i,j }",
372 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
373 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
374 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
375 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
376 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
377 "8c < n - 32a and i < n and c >= 0 and "
378 "c <= 3 and c >= -4a) }",
379 "{ [n] -> [i] : 0 <= i < n }" },
380 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
381 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
382 "{ [x] -> [] : 0 <= x <= 15 }" },
383 { "{ [x] -> [x] : }",
385 { "{ [x=4:5] -> [x + 1] }",
386 "{ [x] -> [x + 1] : 4 <= x <= 5 }" },
387 { "{ [x=4:5] -> [x + 1 : x + 1] }",
388 "{ [x=4:5] -> [x + 1] }" },
389 { "{ [x] -> [x - 1 : x + 1] }",
390 "{ [x] -> [y] : x - 1 <= y <= x + 1 }" },
391 { "{ [x=4:] -> [x + 1] }",
392 "{ [x] -> [x + 1] : 4 <= x }" },
393 { "{ [x=:5] -> [x + 1] }",
394 "{ [x] -> [x + 1] : x <= 5 }" },
395 { "{ [x=:] -> [x + 1] }",
396 "{ [x] -> [x + 1] }" },
400 "{ [x, floor(x/4)] }" },
405 int test_parse(struct isl_ctx
*ctx
)
409 const char *str
, *str2
;
411 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
413 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
415 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
417 if (test_parse_multi(ctx
) < 0)
419 if (test_parse_pma(ctx
) < 0)
422 str
= "{ [i] -> [-i] }";
423 map
= isl_map_read_from_str(ctx
, str
);
427 str
= "{ A[i] -> L[([i/3])] }";
428 map
= isl_map_read_from_str(ctx
, str
);
432 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
433 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
434 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
436 for (i
= 0; i
< ARRAY_SIZE(parse_map_equal_tests
); ++i
) {
437 str
= parse_map_equal_tests
[i
].map1
;
438 str2
= parse_map_equal_tests
[i
].map2
;
439 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
443 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
444 map
= isl_map_read_from_str(ctx
, str
);
445 str
= "{ [new, old] -> [o0, o1] : "
446 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
447 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
448 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
449 map2
= isl_map_read_from_str(ctx
, str
);
450 assert(isl_map_is_equal(map
, map2
));
454 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
455 map
= isl_map_read_from_str(ctx
, str
);
456 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
457 map2
= isl_map_read_from_str(ctx
, str
);
458 assert(isl_map_is_equal(map
, map2
));
462 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
463 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
464 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
465 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
466 test_parse_pwaff(ctx
, "{ [] -> [(100)] }");
471 static int test_read(isl_ctx
*ctx
)
475 isl_basic_set
*bset1
, *bset2
;
476 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
479 filename
= get_filename(ctx
, "set", "omega");
481 input
= fopen(filename
, "r");
484 bset1
= isl_basic_set_read_from_file(ctx
, input
);
485 bset2
= isl_basic_set_read_from_str(ctx
, str
);
487 equal
= isl_basic_set_is_equal(bset1
, bset2
);
489 isl_basic_set_free(bset1
);
490 isl_basic_set_free(bset2
);
498 isl_die(ctx
, isl_error_unknown
,
499 "read sets not equal", return -1);
504 static int test_bounded(isl_ctx
*ctx
)
509 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
510 bounded
= isl_set_is_bounded(set
);
516 isl_die(ctx
, isl_error_unknown
,
517 "set not considered bounded", return -1);
519 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
520 bounded
= isl_set_is_bounded(set
);
527 isl_die(ctx
, isl_error_unknown
,
528 "set considered bounded", return -1);
530 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
531 bounded
= isl_set_is_bounded(set
);
537 isl_die(ctx
, isl_error_unknown
,
538 "set considered bounded", return -1);
543 /* Construct the basic set { [i] : 5 <= i <= N } */
544 static int test_construction_1(isl_ctx
*ctx
)
551 space
= isl_space_set_alloc(ctx
, 1, 1);
552 bset
= isl_basic_set_universe(isl_space_copy(space
));
553 ls
= isl_local_space_from_space(space
);
555 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
556 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
557 c
= isl_constraint_set_coefficient_si(c
, isl_dim_param
, 0, 1);
558 bset
= isl_basic_set_add_constraint(bset
, c
);
560 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
561 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
562 c
= isl_constraint_set_constant_si(c
, -5);
563 bset
= isl_basic_set_add_constraint(bset
, c
);
565 isl_local_space_free(ls
);
566 isl_basic_set_free(bset
);
571 /* Construct the basic set { [x] : -100 <= x <= 100 }
572 * using isl_basic_set_{lower,upper}_bound_val and
573 * check that it is equal the same basic set parsed from a string.
575 static int test_construction_2(isl_ctx
*ctx
)
580 isl_basic_set
*bset1
, *bset2
;
582 v
= isl_val_int_from_si(ctx
, 100);
583 space
= isl_space_set_alloc(ctx
, 0, 1);
584 bset1
= isl_basic_set_universe(space
);
585 bset1
= isl_basic_set_upper_bound_val(bset1
, isl_dim_set
, 0,
587 bset1
= isl_basic_set_lower_bound_val(bset1
, isl_dim_set
, 0,
589 bset2
= isl_basic_set_read_from_str(ctx
, "{ [x] : -100 <= x <= 100 }");
590 equal
= isl_basic_set_is_equal(bset1
, bset2
);
591 isl_basic_set_free(bset1
);
592 isl_basic_set_free(bset2
);
597 isl_die(ctx
, isl_error_unknown
,
598 "failed construction", return -1);
603 /* Basic tests for constructing basic sets.
605 static int test_construction(isl_ctx
*ctx
)
607 if (test_construction_1(ctx
) < 0)
609 if (test_construction_2(ctx
) < 0)
614 static int test_dim(isl_ctx
*ctx
)
617 isl_map
*map1
, *map2
;
620 map1
= isl_map_read_from_str(ctx
,
621 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
622 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
623 map2
= isl_map_read_from_str(ctx
,
624 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
625 equal
= isl_map_is_equal(map1
, map2
);
628 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
629 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
630 if (equal
>= 0 && equal
)
631 equal
= isl_map_is_equal(map1
, map2
);
639 isl_die(ctx
, isl_error_unknown
,
640 "unexpected result", return -1);
642 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
643 map1
= isl_map_read_from_str(ctx
, str
);
644 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
645 map2
= isl_map_read_from_str(ctx
, str
);
646 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
647 equal
= isl_map_is_equal(map1
, map2
);
654 isl_die(ctx
, isl_error_unknown
,
655 "unexpected result", return -1);
661 #define BASE multi_val
662 #include "isl_test_plain_equal_templ.c"
665 #define BASE multi_aff
666 #include "isl_test_plain_equal_templ.c"
668 /* Check that "val" is equal to the value described by "str".
669 * If "str" is "NaN", then check for a NaN value explicitly.
671 static isl_stat
val_check_equal(__isl_keep isl_val
*val
, const char *str
)
678 return isl_stat_error
;
680 ctx
= isl_val_get_ctx(val
);
681 res
= isl_val_read_from_str(ctx
, str
);
682 is_nan
= isl_val_is_nan(res
);
686 ok
= isl_val_is_nan(val
);
688 ok
= isl_val_eq(val
, res
);
691 return isl_stat_error
;
693 isl_die(ctx
, isl_error_unknown
,
694 "unexpected result", return isl_stat_error
);
699 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
703 { &isl_val_neg
, "0", "0" },
704 { &isl_val_abs
, "0", "0" },
705 { &isl_val_pow2
, "0", "1" },
706 { &isl_val_floor
, "0", "0" },
707 { &isl_val_ceil
, "0", "0" },
708 { &isl_val_neg
, "1", "-1" },
709 { &isl_val_neg
, "-1", "1" },
710 { &isl_val_neg
, "1/2", "-1/2" },
711 { &isl_val_neg
, "-1/2", "1/2" },
712 { &isl_val_neg
, "infty", "-infty" },
713 { &isl_val_neg
, "-infty", "infty" },
714 { &isl_val_neg
, "NaN", "NaN" },
715 { &isl_val_abs
, "1", "1" },
716 { &isl_val_abs
, "-1", "1" },
717 { &isl_val_abs
, "1/2", "1/2" },
718 { &isl_val_abs
, "-1/2", "1/2" },
719 { &isl_val_abs
, "infty", "infty" },
720 { &isl_val_abs
, "-infty", "infty" },
721 { &isl_val_abs
, "NaN", "NaN" },
722 { &isl_val_floor
, "1", "1" },
723 { &isl_val_floor
, "-1", "-1" },
724 { &isl_val_floor
, "1/2", "0" },
725 { &isl_val_floor
, "-1/2", "-1" },
726 { &isl_val_floor
, "infty", "infty" },
727 { &isl_val_floor
, "-infty", "-infty" },
728 { &isl_val_floor
, "NaN", "NaN" },
729 { &isl_val_ceil
, "1", "1" },
730 { &isl_val_ceil
, "-1", "-1" },
731 { &isl_val_ceil
, "1/2", "1" },
732 { &isl_val_ceil
, "-1/2", "0" },
733 { &isl_val_ceil
, "infty", "infty" },
734 { &isl_val_ceil
, "-infty", "-infty" },
735 { &isl_val_ceil
, "NaN", "NaN" },
736 { &isl_val_pow2
, "-3", "1/8" },
737 { &isl_val_pow2
, "-1", "1/2" },
738 { &isl_val_pow2
, "1", "2" },
739 { &isl_val_pow2
, "2", "4" },
740 { &isl_val_pow2
, "3", "8" },
741 { &isl_val_inv
, "1", "1" },
742 { &isl_val_inv
, "2", "1/2" },
743 { &isl_val_inv
, "1/2", "2" },
744 { &isl_val_inv
, "-2", "-1/2" },
745 { &isl_val_inv
, "-1/2", "-2" },
746 { &isl_val_inv
, "0", "NaN" },
747 { &isl_val_inv
, "NaN", "NaN" },
748 { &isl_val_inv
, "infty", "0" },
749 { &isl_val_inv
, "-infty", "0" },
752 /* Perform some basic tests of unary operations on isl_val objects.
754 static int test_un_val(isl_ctx
*ctx
)
758 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
760 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
763 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
764 fn
= val_un_tests
[i
].op
;
766 r
= val_check_equal(v
, val_un_tests
[i
].res
);
776 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
777 __isl_take isl_val
*v2
);
779 ['+'] = { &isl_val_add
},
780 ['-'] = { &isl_val_sub
},
781 ['*'] = { &isl_val_mul
},
782 ['/'] = { &isl_val_div
},
783 ['g'] = { &isl_val_gcd
},
784 ['m'] = { &isl_val_min
},
785 ['M'] = { &isl_val_max
},
793 } val_bin_tests
[] = {
794 { "0", '+', "0", "0" },
795 { "1", '+', "0", "1" },
796 { "1", '+', "1", "2" },
797 { "1", '-', "1", "0" },
798 { "1", '*', "1", "1" },
799 { "1", '/', "1", "1" },
800 { "2", '*', "3", "6" },
801 { "2", '*', "1/2", "1" },
802 { "2", '*', "1/3", "2/3" },
803 { "2/3", '*', "3/5", "2/5" },
804 { "2/3", '*', "7/5", "14/15" },
805 { "2", '/', "1/2", "4" },
806 { "-2", '/', "-1/2", "4" },
807 { "-2", '/', "1/2", "-4" },
808 { "2", '/', "-1/2", "-4" },
809 { "2", '/', "2", "1" },
810 { "2", '/', "3", "2/3" },
811 { "2/3", '/', "5/3", "2/5" },
812 { "2/3", '/', "5/7", "14/15" },
813 { "0", '/', "0", "NaN" },
814 { "42", '/', "0", "NaN" },
815 { "-42", '/', "0", "NaN" },
816 { "infty", '/', "0", "NaN" },
817 { "-infty", '/', "0", "NaN" },
818 { "NaN", '/', "0", "NaN" },
819 { "0", '/', "NaN", "NaN" },
820 { "42", '/', "NaN", "NaN" },
821 { "-42", '/', "NaN", "NaN" },
822 { "infty", '/', "NaN", "NaN" },
823 { "-infty", '/', "NaN", "NaN" },
824 { "NaN", '/', "NaN", "NaN" },
825 { "0", '/', "infty", "0" },
826 { "42", '/', "infty", "0" },
827 { "-42", '/', "infty", "0" },
828 { "infty", '/', "infty", "NaN" },
829 { "-infty", '/', "infty", "NaN" },
830 { "NaN", '/', "infty", "NaN" },
831 { "0", '/', "-infty", "0" },
832 { "42", '/', "-infty", "0" },
833 { "-42", '/', "-infty", "0" },
834 { "infty", '/', "-infty", "NaN" },
835 { "-infty", '/', "-infty", "NaN" },
836 { "NaN", '/', "-infty", "NaN" },
837 { "1", '-', "1/3", "2/3" },
838 { "1/3", '+', "1/2", "5/6" },
839 { "1/2", '+', "1/2", "1" },
840 { "3/4", '-', "1/4", "1/2" },
841 { "1/2", '-', "1/3", "1/6" },
842 { "infty", '+', "42", "infty" },
843 { "infty", '+', "infty", "infty" },
844 { "42", '+', "infty", "infty" },
845 { "infty", '-', "infty", "NaN" },
846 { "infty", '*', "infty", "infty" },
847 { "infty", '*', "-infty", "-infty" },
848 { "-infty", '*', "infty", "-infty" },
849 { "-infty", '*', "-infty", "infty" },
850 { "0", '*', "infty", "NaN" },
851 { "1", '*', "infty", "infty" },
852 { "infty", '*', "0", "NaN" },
853 { "infty", '*', "42", "infty" },
854 { "42", '-', "infty", "-infty" },
855 { "infty", '+', "-infty", "NaN" },
856 { "4", 'g', "6", "2" },
857 { "5", 'g', "6", "1" },
858 { "42", 'm', "3", "3" },
859 { "42", 'M', "3", "42" },
860 { "3", 'm', "42", "3" },
861 { "3", 'M', "42", "42" },
862 { "42", 'm', "infty", "42" },
863 { "42", 'M', "infty", "infty" },
864 { "42", 'm', "-infty", "-infty" },
865 { "42", 'M', "-infty", "42" },
866 { "42", 'm', "NaN", "NaN" },
867 { "42", 'M', "NaN", "NaN" },
868 { "infty", 'm', "-infty", "-infty" },
869 { "infty", 'M', "-infty", "infty" },
872 /* Perform some basic tests of binary operations on isl_val objects.
874 static int test_bin_val(isl_ctx
*ctx
)
877 isl_val
*v1
, *v2
, *res
;
878 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
879 __isl_take isl_val
*v2
);
882 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
883 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
884 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
885 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
886 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
888 if (isl_val_is_nan(res
))
889 ok
= isl_val_is_nan(v1
);
891 ok
= isl_val_eq(v1
, res
);
897 isl_die(ctx
, isl_error_unknown
,
898 "unexpected result", return -1);
904 /* Perform some basic tests on isl_val objects.
906 static int test_val(isl_ctx
*ctx
)
908 if (test_un_val(ctx
) < 0)
910 if (test_bin_val(ctx
) < 0)
915 /* Sets described using existentially quantified variables that
916 * can also be described without.
918 static const char *elimination_tests
[] = {
919 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
920 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
921 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
924 /* Check that redundant existentially quantified variables are
927 static int test_elimination(isl_ctx
*ctx
)
933 for (i
= 0; i
< ARRAY_SIZE(elimination_tests
); ++i
) {
934 bset
= isl_basic_set_read_from_str(ctx
, elimination_tests
[i
]);
935 n
= isl_basic_set_dim(bset
, isl_dim_div
);
936 isl_basic_set_free(bset
);
940 isl_die(ctx
, isl_error_unknown
,
941 "expecting no existentials", return -1);
947 static int test_div(isl_ctx
*ctx
)
954 struct isl_basic_set
*bset
;
955 struct isl_constraint
*c
;
958 space
= isl_space_set_alloc(ctx
, 0, 3);
959 bset
= isl_basic_set_universe(isl_space_copy(space
));
960 ls
= isl_local_space_from_space(space
);
962 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
963 c
= isl_constraint_set_constant_si(c
, -1);
964 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
965 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
966 bset
= isl_basic_set_add_constraint(bset
, c
);
968 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
969 c
= isl_constraint_set_constant_si(c
, 1);
970 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
971 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
972 bset
= isl_basic_set_add_constraint(bset
, c
);
974 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
976 assert(bset
&& bset
->n_div
== 1);
977 isl_local_space_free(ls
);
978 isl_basic_set_free(bset
);
981 space
= isl_space_set_alloc(ctx
, 0, 3);
982 bset
= isl_basic_set_universe(isl_space_copy(space
));
983 ls
= isl_local_space_from_space(space
);
985 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
986 c
= isl_constraint_set_constant_si(c
, 1);
987 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
988 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
989 bset
= isl_basic_set_add_constraint(bset
, c
);
991 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
992 c
= isl_constraint_set_constant_si(c
, -1);
993 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
994 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
995 bset
= isl_basic_set_add_constraint(bset
, c
);
997 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
999 assert(bset
&& bset
->n_div
== 1);
1000 isl_local_space_free(ls
);
1001 isl_basic_set_free(bset
);
1004 space
= isl_space_set_alloc(ctx
, 0, 3);
1005 bset
= isl_basic_set_universe(isl_space_copy(space
));
1006 ls
= isl_local_space_from_space(space
);
1008 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1009 c
= isl_constraint_set_constant_si(c
, 1);
1010 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1011 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1012 bset
= isl_basic_set_add_constraint(bset
, c
);
1014 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1015 c
= isl_constraint_set_constant_si(c
, -3);
1016 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1017 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 4);
1018 bset
= isl_basic_set_add_constraint(bset
, c
);
1020 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1022 assert(bset
&& bset
->n_div
== 1);
1023 isl_local_space_free(ls
);
1024 isl_basic_set_free(bset
);
1027 space
= isl_space_set_alloc(ctx
, 0, 3);
1028 bset
= isl_basic_set_universe(isl_space_copy(space
));
1029 ls
= isl_local_space_from_space(space
);
1031 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1032 c
= isl_constraint_set_constant_si(c
, 2);
1033 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1034 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, 3);
1035 bset
= isl_basic_set_add_constraint(bset
, c
);
1037 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1038 c
= isl_constraint_set_constant_si(c
, -1);
1039 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1040 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1041 bset
= isl_basic_set_add_constraint(bset
, c
);
1043 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
1045 assert(isl_basic_set_is_empty(bset
));
1046 isl_local_space_free(ls
);
1047 isl_basic_set_free(bset
);
1050 space
= isl_space_set_alloc(ctx
, 0, 3);
1051 bset
= isl_basic_set_universe(isl_space_copy(space
));
1052 ls
= isl_local_space_from_space(space
);
1054 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1055 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1056 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 3);
1057 bset
= isl_basic_set_add_constraint(bset
, c
);
1059 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1060 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1061 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1062 bset
= isl_basic_set_add_constraint(bset
, c
);
1064 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1066 assert(bset
&& bset
->n_div
== 0);
1067 isl_basic_set_free(bset
);
1068 isl_local_space_free(ls
);
1071 space
= isl_space_set_alloc(ctx
, 0, 3);
1072 bset
= isl_basic_set_universe(isl_space_copy(space
));
1073 ls
= isl_local_space_from_space(space
);
1075 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1076 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1077 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 6);
1078 bset
= isl_basic_set_add_constraint(bset
, c
);
1080 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1081 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1082 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1083 bset
= isl_basic_set_add_constraint(bset
, c
);
1085 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1087 assert(bset
&& bset
->n_div
== 1);
1088 isl_basic_set_free(bset
);
1089 isl_local_space_free(ls
);
1092 /* This test is a bit tricky. We set up an equality
1093 * a + 3b + 3c = 6 e0
1094 * Normalization of divs creates _two_ divs
1097 * Afterwards e0 is removed again because it has coefficient -1
1098 * and we end up with the original equality and div again.
1099 * Perhaps we can avoid the introduction of this temporary div.
1101 space
= isl_space_set_alloc(ctx
, 0, 4);
1102 bset
= isl_basic_set_universe(isl_space_copy(space
));
1103 ls
= isl_local_space_from_space(space
);
1105 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1106 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1107 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1108 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -3);
1109 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 6);
1110 bset
= isl_basic_set_add_constraint(bset
, c
);
1112 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
1114 /* Test disabled for now */
1116 assert(bset && bset->n_div == 1);
1118 isl_local_space_free(ls
);
1119 isl_basic_set_free(bset
);
1122 space
= isl_space_set_alloc(ctx
, 0, 5);
1123 bset
= isl_basic_set_universe(isl_space_copy(space
));
1124 ls
= isl_local_space_from_space(space
);
1126 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1127 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1128 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -3);
1129 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, -3);
1130 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 4, 6);
1131 bset
= isl_basic_set_add_constraint(bset
, c
);
1133 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1134 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1135 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, 1);
1136 c
= isl_constraint_set_constant_si(c
, 1);
1137 bset
= isl_basic_set_add_constraint(bset
, c
);
1139 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
1141 /* Test disabled for now */
1143 assert(bset && bset->n_div == 1);
1145 isl_local_space_free(ls
);
1146 isl_basic_set_free(bset
);
1149 space
= isl_space_set_alloc(ctx
, 0, 4);
1150 bset
= isl_basic_set_universe(isl_space_copy(space
));
1151 ls
= isl_local_space_from_space(space
);
1153 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1154 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1155 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 1, -1);
1156 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1157 bset
= isl_basic_set_add_constraint(bset
, c
);
1159 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1160 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, -1);
1161 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 3, 3);
1162 c
= isl_constraint_set_constant_si(c
, 2);
1163 bset
= isl_basic_set_add_constraint(bset
, c
);
1165 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
1167 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1169 assert(!isl_basic_set_is_empty(bset
));
1171 isl_local_space_free(ls
);
1172 isl_basic_set_free(bset
);
1175 space
= isl_space_set_alloc(ctx
, 0, 3);
1176 bset
= isl_basic_set_universe(isl_space_copy(space
));
1177 ls
= isl_local_space_from_space(space
);
1179 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
1180 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 0, 1);
1181 c
= isl_constraint_set_coefficient_si(c
, isl_dim_set
, 2, -2);
1182 bset
= isl_basic_set_add_constraint(bset
, c
);
1184 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1186 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1188 isl_local_space_free(ls
);
1189 isl_basic_set_free(bset
);
1191 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1192 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1193 set
= isl_set_read_from_str(ctx
, str
);
1194 set
= isl_set_compute_divs(set
);
1199 if (test_elimination(ctx
) < 0)
1202 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1203 set
= isl_set_read_from_str(ctx
, str
);
1204 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
1205 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
1206 empty
= isl_set_is_empty(set
);
1211 isl_die(ctx
, isl_error_unknown
,
1212 "result not as accurate as expected", return -1);
1217 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
1221 struct isl_basic_set
*bset1
, *bset2
;
1222 struct isl_basic_map
*bmap
;
1224 filename
= get_filename(ctx
, name
, "omega");
1226 input
= fopen(filename
, "r");
1229 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1230 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1232 bset1
= isl_basic_set_apply(bset1
, bmap
);
1234 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1236 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1238 isl_basic_set_free(bset1
);
1239 isl_basic_set_free(bset2
);
1245 static int test_application(isl_ctx
*ctx
)
1247 test_application_case(ctx
, "application");
1248 test_application_case(ctx
, "application2");
1253 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1257 struct isl_basic_set
*bset1
, *bset2
;
1259 filename
= get_filename(ctx
, name
, "polylib");
1261 input
= fopen(filename
, "r");
1264 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1265 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1267 bset1
= isl_basic_set_affine_hull(bset1
);
1269 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1271 isl_basic_set_free(bset1
);
1272 isl_basic_set_free(bset2
);
1278 /* Pairs of sets and the corresponding expected results of
1279 * isl_basic_set_recession_cone.
1284 } recession_cone_tests
[] = {
1285 { "{ [i] : 0 <= i <= 10 }", "{ [0] }" },
1286 { "{ [i] : 0 <= i }", "{ [i] : 0 <= i }" },
1287 { "{ [i] : i <= 10 }", "{ [i] : i <= 0 }" },
1288 { "{ [i] : false }", "{ [i] : false }" },
1291 /* Perform some basic isl_basic_set_recession_cone tests.
1293 static int test_recession_cone(struct isl_ctx
*ctx
)
1297 for (i
= 0; i
< ARRAY_SIZE(recession_cone_tests
); ++i
) {
1299 isl_basic_set
*bset
;
1300 isl_basic_set
*cone
, *expected
;
1303 str
= recession_cone_tests
[i
].set
;
1304 bset
= isl_basic_set_read_from_str(ctx
, str
);
1305 str
= recession_cone_tests
[i
].cone
;
1306 expected
= isl_basic_set_read_from_str(ctx
, str
);
1307 cone
= isl_basic_set_recession_cone(bset
);
1308 equal
= isl_basic_set_is_equal(cone
, expected
);
1309 isl_basic_set_free(cone
);
1310 isl_basic_set_free(expected
);
1314 isl_die(ctx
, isl_error_unknown
, "unexpected cone",
1321 int test_affine_hull(struct isl_ctx
*ctx
)
1325 isl_basic_set
*bset
, *bset2
;
1329 test_affine_hull_case(ctx
, "affine2");
1330 test_affine_hull_case(ctx
, "affine");
1331 test_affine_hull_case(ctx
, "affine3");
1333 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1334 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1335 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1336 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1337 set
= isl_set_read_from_str(ctx
, str
);
1338 bset
= isl_set_affine_hull(set
);
1339 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1340 isl_basic_set_free(bset
);
1344 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1347 /* Check that isl_map_affine_hull is not confused by
1348 * the reordering of divs in isl_map_align_divs.
1350 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1351 "32e0 = b and 32e1 = c); "
1352 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1353 set
= isl_set_read_from_str(ctx
, str
);
1354 bset
= isl_set_affine_hull(set
);
1355 isl_basic_set_free(bset
);
1359 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1360 "32e2 = 31 + 31e0 }";
1361 set
= isl_set_read_from_str(ctx
, str
);
1362 bset
= isl_set_affine_hull(set
);
1363 str
= "{ [a] : exists e : a = 32 e }";
1364 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1365 subset
= isl_basic_set_is_subset(bset
, bset2
);
1366 isl_basic_set_free(bset
);
1367 isl_basic_set_free(bset2
);
1371 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1377 /* Test a special case of isl_set_plain_unshifted_simple_hull
1378 * where older versions of isl would include a redundant constraint
1380 * Check that the result does not have any constraints.
1382 static isl_stat
test_plain_unshifted_simple_hull_special(isl_ctx
*ctx
)
1385 isl_bool is_universe
;
1387 isl_basic_set
*bset
;
1389 str
= "{[x, y] : x = 0 or 2*((x+y)//2) <= y + 2 }";
1390 set
= isl_set_read_from_str(ctx
, str
);
1391 bset
= isl_set_plain_unshifted_simple_hull(set
);
1392 is_universe
= isl_basic_set_plain_is_universe(bset
);
1393 isl_basic_set_free(bset
);
1395 if (is_universe
< 0)
1396 return isl_stat_error
;
1398 isl_die(ctx
, isl_error_unknown
,
1399 "hull should not have any constraints",
1400 return isl_stat_error
);
1405 /* Inputs for simple hull tests, consisting of
1406 * the specific simple hull function, the input set and the expected result.
1409 __isl_give isl_basic_set
*(*fn
)(__isl_take isl_set
*set
);
1412 } simple_hull_tests
[] = {
1413 { &isl_set_plain_unshifted_simple_hull
,
1414 "{ [i,j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1415 "{ [i,j] : i >= 1 }" },
1416 { &isl_set_plain_unshifted_simple_hull
,
1417 "{ [n,i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1418 "(j mod 4 = 2 and k mod 6 = n) }",
1419 "{ [n,i,j,k] : j mod 4 = 2 }" },
1420 { &isl_set_unshifted_simple_hull
,
1421 "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1422 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1423 { &isl_set_simple_hull
,
1424 "{ [a, b] : b <= 0 and "
1425 "2*floor((-2*floor((b)/2))/5) >= a - floor((b)/2); "
1426 "[a, b] : a mod 2 = 0 }",
1430 /* Basic tests for various simple hull functions.
1432 static int test_various_simple_hull(isl_ctx
*ctx
)
1436 isl_basic_set
*hull
, *expected
;
1439 for (i
= 0; i
< ARRAY_SIZE(simple_hull_tests
); ++i
) {
1441 str
= simple_hull_tests
[i
].set
;
1442 set
= isl_set_read_from_str(ctx
, str
);
1443 str
= simple_hull_tests
[i
].hull
;
1444 expected
= isl_basic_set_read_from_str(ctx
, str
);
1445 hull
= simple_hull_tests
[i
].fn(set
);
1446 equal
= isl_basic_set_is_equal(hull
, expected
);
1447 isl_basic_set_free(hull
);
1448 isl_basic_set_free(expected
);
1452 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1459 static int test_simple_hull(struct isl_ctx
*ctx
)
1463 isl_basic_set
*bset
;
1466 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1467 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1468 set
= isl_set_read_from_str(ctx
, str
);
1469 bset
= isl_set_simple_hull(set
);
1470 is_empty
= isl_basic_set_is_empty(bset
);
1471 isl_basic_set_free(bset
);
1473 if (is_empty
== isl_bool_error
)
1476 if (is_empty
== isl_bool_false
)
1477 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1480 if (test_plain_unshifted_simple_hull_special(ctx
) < 0)
1482 if (test_various_simple_hull(ctx
) < 0)
1488 /* Inputs for isl_set_get_simple_fixed_box_hull tests.
1489 * "set" is the input set.
1490 * "offset" is the expected box offset.
1491 * "size" is the expected box size.
1497 } box_hull_tests
[] = {
1498 { "{ S[x, y] : 0 <= x, y < 10 }", "{ S[0, 0] }", "{ S[10, 10] }" },
1499 { "[N] -> { S[x, y] : N <= x, y < N + 10 }",
1500 "[N] -> { S[N, N] }", "{ S[10, 10] }" },
1501 { "{ S[x, y] : 0 <= x + y, x - y < 10 }",
1502 "{ S[0, -4] }", "{ S[10, 9] }" },
1503 { "{ [i=0:10] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1504 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1505 "{ [3] }", "{ [8] }" },
1506 { "[N] -> { [w = 0:17] : exists (e0: w < 2N and "
1507 "-1 + w <= e0 <= w and 2e0 >= N + w and w <= 2e0 <= 15 + w) }",
1508 "[N] -> { [N] }", "{ [9] }" },
1511 /* Perform basic isl_set_get_simple_fixed_box_hull tests.
1513 static int test_box_hull(struct isl_ctx
*ctx
)
1517 for (i
= 0; i
< ARRAY_SIZE(box_hull_tests
); ++i
) {
1521 isl_multi_aff
*offset
;
1522 isl_multi_val
*size
;
1525 set
= isl_set_read_from_str(ctx
, box_hull_tests
[i
].set
);
1526 box
= isl_set_get_simple_fixed_box_hull(set
);
1527 offset
= isl_fixed_box_get_offset(box
);
1528 size
= isl_fixed_box_get_size(box
);
1529 str
= box_hull_tests
[i
].offset
;
1530 r
= multi_aff_check_plain_equal(offset
, str
);
1531 str
= box_hull_tests
[i
].size
;
1533 r
= multi_val_check_plain_equal(size
, str
);
1534 isl_multi_aff_free(offset
);
1535 isl_multi_val_free(size
);
1536 isl_fixed_box_free(box
);
1545 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1549 struct isl_basic_set
*bset1
, *bset2
;
1550 struct isl_set
*set
;
1552 filename
= get_filename(ctx
, name
, "polylib");
1554 input
= fopen(filename
, "r");
1557 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1558 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1560 set
= isl_basic_set_union(bset1
, bset2
);
1561 bset1
= isl_set_convex_hull(set
);
1563 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1565 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1567 isl_basic_set_free(bset1
);
1568 isl_basic_set_free(bset2
);
1577 } convex_hull_tests
[] = {
1578 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1579 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1580 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1581 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1582 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1583 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1584 "i2 <= 5 and i2 >= 4; "
1585 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1586 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1587 "i2 <= 5 + i0 and i2 >= i0 }" },
1588 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1589 "{ [x, y] : 1 = 0 }" },
1590 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1591 "[x, y, 0] : x >= 0 and y < 0 }",
1592 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1593 { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and "
1595 "[0, 2, 0]; [3, 1, 0] }",
1596 "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and "
1597 "5c <= 6 - a - 3b }" },
1600 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1603 int orig_convex
= ctx
->opt
->convex
;
1604 ctx
->opt
->convex
= convex
;
1606 test_convex_hull_case(ctx
, "convex0");
1607 test_convex_hull_case(ctx
, "convex1");
1608 test_convex_hull_case(ctx
, "convex2");
1609 test_convex_hull_case(ctx
, "convex3");
1610 test_convex_hull_case(ctx
, "convex4");
1611 test_convex_hull_case(ctx
, "convex5");
1612 test_convex_hull_case(ctx
, "convex6");
1613 test_convex_hull_case(ctx
, "convex7");
1614 test_convex_hull_case(ctx
, "convex8");
1615 test_convex_hull_case(ctx
, "convex9");
1616 test_convex_hull_case(ctx
, "convex10");
1617 test_convex_hull_case(ctx
, "convex11");
1618 test_convex_hull_case(ctx
, "convex12");
1619 test_convex_hull_case(ctx
, "convex13");
1620 test_convex_hull_case(ctx
, "convex14");
1621 test_convex_hull_case(ctx
, "convex15");
1623 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1624 isl_set
*set1
, *set2
;
1627 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1628 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1629 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1630 equal
= isl_set_is_equal(set1
, set2
);
1637 isl_die(ctx
, isl_error_unknown
,
1638 "unexpected convex hull", return -1);
1641 ctx
->opt
->convex
= orig_convex
;
1646 static int test_convex_hull(isl_ctx
*ctx
)
1648 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1650 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1655 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1659 struct isl_basic_set
*bset1
, *bset2
;
1661 filename
= get_filename(ctx
, name
, "polylib");
1663 input
= fopen(filename
, "r");
1666 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1667 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1669 bset1
= isl_basic_set_gist(bset1
, bset2
);
1671 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1673 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1675 isl_basic_set_free(bset1
);
1676 isl_basic_set_free(bset2
);
1682 /* Check that computing the gist of "map" with respect to "context"
1683 * does not make any copy of "map" get marked empty.
1684 * Earlier versions of isl would end up doing that.
1686 static isl_stat
test_gist_empty_pair(isl_ctx
*ctx
, const char *map
,
1687 const char *context
)
1689 isl_map
*m1
, *m2
, *m3
;
1690 isl_bool empty_before
, empty_after
;
1692 m1
= isl_map_read_from_str(ctx
, map
);
1693 m2
= isl_map_read_from_str(ctx
, context
);
1694 m3
= isl_map_copy(m1
);
1695 empty_before
= isl_map_is_empty(m3
);
1696 m1
= isl_map_gist(m1
, m2
);
1697 empty_after
= isl_map_is_empty(m3
);
1701 if (empty_before
< 0 || empty_after
< 0)
1702 return isl_stat_error
;
1704 isl_die(ctx
, isl_error_unknown
, "map should not be empty",
1705 return isl_stat_error
);
1707 isl_die(ctx
, isl_error_unknown
, "map should still not be empty",
1708 return isl_stat_error
);
1713 /* Check that computing a gist does not make any copy of the input
1715 * Earlier versions of isl would end up doing that on some pairs of inputs.
1717 static isl_stat
test_gist_empty(isl_ctx
*ctx
)
1719 const char *map
, *context
;
1721 map
= "{ [] -> [a, b, c] : 2b = 1 + a }";
1722 context
= "{ [] -> [a, b, c] : 2c = 2 + a }";
1723 if (test_gist_empty_pair(ctx
, map
, context
) < 0)
1724 return isl_stat_error
;
1725 map
= "{ [] -> [0, 0] }";
1726 context
= "{ [] -> [a, b] : a > b }";
1727 if (test_gist_empty_pair(ctx
, map
, context
) < 0)
1728 return isl_stat_error
;
1733 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1737 const char *context
;
1739 } plain_gist_tests
[] = {
1740 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1741 "{ [i] -> [j] : i >= 1 }",
1742 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1743 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1744 "(j mod 4 = 2 and k mod 6 = n) }",
1745 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1746 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1747 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1748 "{ [i] -> [j] : i > j }",
1749 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1752 /* Basic tests for isl_map_plain_gist_basic_map.
1754 static int test_plain_gist(isl_ctx
*ctx
)
1758 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1761 isl_map
*map
, *gist
;
1762 isl_basic_map
*context
;
1764 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1765 str
= plain_gist_tests
[i
].context
;
1766 context
= isl_basic_map_read_from_str(ctx
, str
);
1767 map
= isl_map_plain_gist_basic_map(map
, context
);
1768 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1769 equal
= isl_map_is_equal(map
, gist
);
1775 isl_die(ctx
, isl_error_unknown
,
1776 "incorrect gist result", return -1);
1782 /* Inputs for isl_basic_set_gist tests that are expected to fail.
1786 const char *context
;
1787 } gist_fail_tests
[] = {
1788 { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1789 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1790 "{ [i] : i >= 0 }" },
1793 /* Check that isl_basic_set_gist fails (gracefully) when expected.
1794 * In particular, the user should be able to recover from the failure.
1796 static isl_stat
test_gist_fail(struct isl_ctx
*ctx
)
1801 on_error
= isl_options_get_on_error(ctx
);
1802 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
1803 n
= ARRAY_SIZE(gist_fail_tests
);
1804 for (i
= 0; i
< n
; ++i
) {
1806 isl_basic_set
*bset
, *context
;
1808 bset
= isl_basic_set_read_from_str(ctx
, gist_fail_tests
[i
].set
);
1809 str
= gist_fail_tests
[i
].context
;
1810 context
= isl_basic_set_read_from_str(ctx
, str
);
1811 bset
= isl_basic_set_gist(bset
, context
);
1812 isl_basic_set_free(bset
);
1816 isl_options_set_on_error(ctx
, on_error
);
1818 isl_die(ctx
, isl_error_unknown
,
1819 "operation not expected to succeed",
1820 return isl_stat_error
);
1827 const char *context
;
1830 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1831 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1832 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1833 "{ [a, b, c] : a <= 15 }" },
1834 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1835 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1836 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1837 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1838 { "{ [m, n, a, b] : a <= 2147 + n }",
1839 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1840 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1841 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1843 "{ [m, n, ku, kl] }" },
1844 { "{ [a, a, b] : a >= 10 }",
1845 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1846 "{ [a, a, b] : a >= 10 }" },
1847 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1848 "{ [0, j] : j >= 0 }" },
1849 /* Check that no constraints on i6 are introduced in the gist */
1850 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1851 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1852 "5e0 <= 381 - t1 and i4 <= 1) }",
1853 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1854 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1855 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1856 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1857 "20e0 >= 1511 - 4t1 - 5i4) }" },
1858 /* Check that no constraints on i6 are introduced in the gist */
1859 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1860 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1861 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1862 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1863 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1864 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1865 "20e1 <= 1530 - 4t1 - 5i4 and "
1866 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1867 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1868 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1869 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1870 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1871 "10e0 <= -91 + 5i4 + 4i6 and "
1872 "10e0 >= -105 + 5i4 + 4i6) }",
1873 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1874 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1875 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1876 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1877 "{ [a, b, q, p] : b >= 1 + a }",
1878 "{ [a, b, q, p] : false }" },
1879 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1880 "[n] -> { [x] : x mod 32 = 0 }",
1881 "[n] -> { [x = n] }" },
1882 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1883 "{ [x] : x mod 2 = 0 }" },
1884 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1885 "{ [x] : x mod 128 = 0 }" },
1886 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1887 "{ [x] : x mod 3200 = 0 }" },
1888 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1889 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1890 "{ [a, b, c = a] }" },
1891 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1892 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1893 "{ [a, b, c = a] : a mod 3 = 0 }" },
1894 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1895 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1897 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1898 "{ [x,y] : 1 <= y <= 3 }",
1902 /* Check that isl_set_gist behaves as expected.
1904 * For the test cases in gist_tests, besides checking that the result
1905 * is as expected, also check that applying the gist operation does
1906 * not modify the input set (an earlier version of isl would do that) and
1907 * that the test case is consistent, i.e., that the gist has the same
1908 * intersection with the context as the input set.
1910 static int test_gist(struct isl_ctx
*ctx
)
1914 isl_basic_set
*bset1
, *bset2
;
1915 isl_map
*map1
, *map2
;
1919 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1920 isl_bool equal_input
, equal_intersection
;
1921 isl_set
*set1
, *set2
, *copy
, *context
;
1923 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1924 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1925 copy
= isl_set_copy(set1
);
1926 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1927 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1928 equal
= isl_set_is_equal(set1
, set2
);
1930 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1931 equal_input
= isl_set_is_equal(set1
, copy
);
1933 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1934 set2
= isl_set_intersect(set2
, context
);
1935 equal_intersection
= isl_set_is_equal(set1
, set2
);
1938 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1941 isl_die(ctx
, isl_error_unknown
,
1942 "incorrect gist result", return -1);
1944 isl_die(ctx
, isl_error_unknown
,
1945 "gist modified input", return -1);
1947 isl_die(ctx
, isl_error_unknown
,
1948 "inconsistent gist test case", return -1);
1951 if (test_gist_fail(ctx
) < 0)
1954 test_gist_case(ctx
, "gist1");
1956 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1957 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1958 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1959 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1960 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1961 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1962 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1963 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1964 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1965 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1966 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1967 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1968 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1969 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1970 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1971 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1972 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1973 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1974 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1975 bset1
= isl_basic_set_gist(bset1
, bset2
);
1976 assert(bset1
&& bset1
->n_div
== 0);
1977 isl_basic_set_free(bset1
);
1979 /* Check that the integer divisions of the second disjunct
1980 * do not spread to the first disjunct.
1982 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1983 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1984 "(exists (e0 = [(-1 + t1)/16], "
1985 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1986 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1987 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1988 "o0 <= 4294967295 and t1 <= -1)) }";
1989 map1
= isl_map_read_from_str(ctx
, str
);
1990 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1991 map2
= isl_map_read_from_str(ctx
, str
);
1992 map1
= isl_map_gist(map1
, map2
);
1996 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1997 isl_map_free(map1
); return -1);
1998 n_div
= isl_basic_map_dim(map1
->p
[0], isl_dim_div
);
2003 isl_die(ctx
, isl_error_unknown
, "expecting single div",
2006 if (test_gist_empty(ctx
) < 0)
2008 if (test_plain_gist(ctx
) < 0)
2014 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
2016 isl_set
*set
, *set2
;
2020 set
= isl_set_read_from_str(ctx
, str
);
2021 set
= isl_set_coalesce(set
);
2022 set2
= isl_set_read_from_str(ctx
, str
);
2023 equal
= isl_set_is_equal(set
, set2
);
2024 one
= set
&& set
->n
== 1;
2031 isl_die(ctx
, isl_error_unknown
,
2032 "coalesced set not equal to input", return -1);
2033 if (check_one
&& !one
)
2034 isl_die(ctx
, isl_error_unknown
,
2035 "coalesced set should not be a union", return -1);
2040 /* Inputs for coalescing tests with unbounded wrapping.
2041 * "str" is a string representation of the input set.
2042 * "single_disjunct" is set if we expect the result to consist of
2043 * a single disjunct.
2046 int single_disjunct
;
2048 } coalesce_unbounded_tests
[] = {
2049 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
2050 "-x - y + 1 >= 0 and -3 <= z <= 3;"
2051 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
2052 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
2054 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
2055 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
2056 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
2057 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
2058 { 0, "{ [x, y, z] : 0 <= x,y,z <= 100 and 0 < z <= 2 + 2x + 2y; "
2059 "[x, y, 0] : x,y <= 100 and y <= 9 + 11x and x <= 9 + 11y }" },
2060 { 1, "{ [0:1, 0:1]; [0, 2:3] }" },
2061 { 1, "{ [0:1, 0:1]; [0, 2:3]; [1, -2:-1] }" },
2062 { 1, "{ [0:3, 0:1]; [1:2, 2:5] }" },
2063 { 1, "{ [0:3, 0:1]; [0:2, 2:5] }" },
2064 { 1, "{ [0:3, 0:1]; [1:3, 2:5] }" },
2065 { 0, "{ [0:3, 0:1]; [1:4, 2:5] }" },
2066 { 0, "{ [0:3, 0:1]; [1:5, 2:5] }" },
2069 /* Test the functionality of isl_set_coalesce with the bounded wrapping
2070 * option turned off.
2072 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
2078 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
2079 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
2081 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
2082 const char *str
= coalesce_unbounded_tests
[i
].str
;
2083 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
2084 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
2090 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
2095 /* Inputs for coalescing tests.
2096 * "str" is a string representation of the input set.
2097 * "single_disjunct" is set if we expect the result to consist of
2098 * a single disjunct.
2101 int single_disjunct
;
2103 } coalesce_tests
[] = {
2104 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
2105 "y >= x & x >= 2 & 5 >= y }" },
2106 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2107 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
2108 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2109 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
2110 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2111 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
2112 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2113 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
2114 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2115 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
2116 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
2117 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
2118 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
2119 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
2120 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
2121 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
2122 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
2123 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2124 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2125 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2126 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
2127 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
2128 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
2129 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
2130 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
2131 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2132 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2133 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2134 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
2135 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
2136 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
2137 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
2138 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
2139 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
2140 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
2141 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
2142 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
2143 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
2144 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
2145 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
2146 "[o0, o1, o2, o3, o4, o5, o6]] : "
2147 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
2148 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
2149 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
2150 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
2151 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
2152 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
2153 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
2154 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
2155 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
2156 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
2157 "o6 >= i3 + i6 - o3 and M >= 0 and "
2158 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
2159 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
2160 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
2161 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
2162 "(o0 = 0 and M >= 2 and N >= 3) or "
2163 "(M = 0 and o0 = 0 and N >= 3) }" },
2164 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
2165 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
2166 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
2167 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
2168 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
2169 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
2170 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
2171 "(y = 3 and x = 1) }" },
2172 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
2173 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
2174 "i1 <= M and i3 <= M and i4 <= M) or "
2175 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
2176 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
2177 "i4 <= -1 + M) }" },
2178 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
2179 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
2180 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
2181 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
2182 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
2183 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
2184 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
2185 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
2186 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
2187 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
2188 { 0, "{ [a, b] : exists e : 2e = a and "
2189 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
2190 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
2191 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
2192 "j >= 1 and j' <= i + j - i' and i >= 1; "
2194 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
2195 "[i,j] : exists a : j = 3a }" },
2196 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
2197 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
2199 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
2200 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
2201 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
2202 "c <= 6 + 8a and a >= 3; "
2203 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
2204 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
2205 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2206 "[x,0] : 3 <= x <= 4 }" },
2207 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
2208 "[x,0] : 4 <= x <= 5 }" },
2209 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2210 "[x,0] : 3 <= x <= 5 }" },
2211 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
2212 "[x,0] : 3 <= x <= 4 }" },
2213 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
2215 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
2216 { 1, "{ [0,0]; [1,1] }" },
2217 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
2218 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
2220 "[k, 0, k] : k <= 6 and k >= 1 }" },
2221 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
2222 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
2223 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
2224 { 1, "[n] -> { [1] : n >= 0;"
2225 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
2226 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
2227 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
2228 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
2229 "2e0 <= x and 2e0 <= n);"
2230 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
2232 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
2233 "128e0 >= -134 + 127t1 and t1 >= 2 and "
2234 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
2236 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
2237 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
2239 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
2240 "t1 >= 13 and t1 <= 16);"
2241 "[t1] : t1 <= 15 and t1 >= 12 }" },
2242 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2243 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2244 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2245 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2246 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2247 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2249 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2250 "(exists (e0 : 3e0 = -2 + c0)) }" },
2251 { 0, "[n, b0, t0] -> "
2252 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2253 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2254 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2255 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2256 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2257 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2258 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2259 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2260 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2261 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2262 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2263 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2264 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2265 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2266 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2267 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2268 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2269 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2270 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2271 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2272 { 0, "{ [i0, i1, i2] : "
2273 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2274 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2275 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2276 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2277 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2278 "32e0 <= 31 + i0)) or "
2280 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2281 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2282 "2*floor((c)/2) = c and 0 <= a <= 192;"
2283 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2285 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2286 "(0 <= a <= b <= n) }" },
2287 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2288 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2289 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2290 { 1, "{ [a, b, c] : (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, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2295 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2296 "(a = 4 and b = 3 and "
2297 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2298 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2299 "(b = -1 + a and 0 < a <= 3 and "
2300 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2301 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2302 "b = 3 and 9e0 <= -19 + 2c)) }" },
2303 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2305 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2307 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2308 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2309 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2310 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2311 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2312 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2313 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2314 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2315 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2316 { 1, "{ [a] : a <= 8 and "
2317 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2318 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2319 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2320 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2321 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2322 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2323 "(a < 0 and 3*floor((a)/3) < a) }" },
2324 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2325 "(a < -1 and 3*floor((a)/3) < a) }" },
2326 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2327 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2328 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2329 "or (2 <= a <= 15 and b < a)) }" },
2330 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2331 "32*floor((a)/32) < a) or a <= 15) }" },
2332 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2333 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2334 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2335 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2336 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2337 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2338 "S_0[n] : n <= m <= 2 + n }" },
2339 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2340 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2342 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2343 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2344 "2e0 < -a + 2b) }" },
2345 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2346 "[i, 0, i] : 0 <= i <= 7 }" },
2347 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2348 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2349 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2350 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2351 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2352 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2353 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2354 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2355 "a > 0 and a <= 5) }" },
2356 { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" },
2357 { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and "
2358 "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; "
2359 "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" },
2360 { 0, "{ [0:1, 0:1]; [0, 2:3] }" },
2361 { 1, "{ [a] : (a = 0 or ((1 + a) mod 2 = 0 and 0 < a <= 15) or "
2362 "((a) mod 2 = 0 and 0 < a <= 15)) }" },
2365 /* A specialized coalescing test case that would result
2366 * in a segmentation fault or a failed assertion in earlier versions of isl.
2368 static int test_coalesce_special(struct isl_ctx
*ctx
)
2371 isl_map
*map1
, *map2
;
2373 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2374 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2375 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2376 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2377 "o1 <= 239 and o1 >= 212)) or "
2378 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2379 "o1 <= 241 and o1 >= 240));"
2380 "[S_L220_OUT[] -> T7[]] -> "
2381 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2382 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2383 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2384 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2385 map1
= isl_map_read_from_str(ctx
, str
);
2386 map1
= isl_map_align_divs_internal(map1
);
2387 map1
= isl_map_coalesce(map1
);
2388 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2389 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2390 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2391 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2392 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2393 map2
= isl_map_read_from_str(ctx
, str
);
2394 map2
= isl_map_union(map2
, map1
);
2395 map2
= isl_map_align_divs_internal(map2
);
2396 map2
= isl_map_coalesce(map2
);
2404 /* A specialized coalescing test case that would result in an assertion
2405 * in an earlier version of isl.
2406 * The explicit call to isl_basic_set_union prevents the implicit
2407 * equality constraints in the first basic map from being detected prior
2408 * to the call to isl_set_coalesce, at least at the point
2409 * where this test case was introduced.
2411 static int test_coalesce_special2(struct isl_ctx
*ctx
)
2414 isl_basic_set
*bset1
, *bset2
;
2417 str
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2418 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2419 str
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2420 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2421 set
= isl_basic_set_union(bset1
, bset2
);
2422 set
= isl_set_coalesce(set
);
2430 /* Check that calling isl_set_coalesce does not leave other sets
2431 * that may share some information with the input to isl_set_coalesce
2432 * in an inconsistent state.
2433 * In particular, older versions of isl would modify all copies
2434 * of the basic sets in the isl_set_coalesce input in a way
2435 * that could leave them in an inconsistent state.
2436 * The result of printing any other set containing one of these
2437 * basic sets would then result in an invalid set description.
2439 static int test_coalesce_special3(isl_ctx
*ctx
)
2443 isl_set
*set1
, *set2
;
2446 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2447 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2448 set2
= isl_set_read_from_str(ctx
, str
);
2449 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2450 set1
= isl_set_coalesce(set1
);
2453 p
= isl_printer_to_str(ctx
);
2454 p
= isl_printer_print_set(p
, set2
);
2456 s
= isl_printer_get_str(p
);
2457 isl_printer_free(p
);
2458 set1
= isl_set_read_from_str(ctx
, s
);
2468 /* Check that calling isl_set_coalesce on the intersection of
2469 * the sets described by "s1" and "s2" does not leave other sets
2470 * that may share some information with the input to isl_set_coalesce
2471 * in an inconsistent state.
2472 * In particular, when isl_set_coalesce detects equality constraints,
2473 * it does not immediately perform Gaussian elimination on them,
2474 * but then it needs to ensure that it is performed at some point.
2475 * The input set has implicit equality constraints in the first disjunct.
2476 * It is constructed as an intersection, because otherwise
2477 * those equality constraints would already be detected during parsing.
2479 static isl_stat
test_coalesce_intersection(isl_ctx
*ctx
,
2480 const char *s1
, const char *s2
)
2482 isl_set
*set1
, *set2
;
2484 set1
= isl_set_read_from_str(ctx
, s1
);
2485 set2
= isl_set_read_from_str(ctx
, s2
);
2486 set1
= isl_set_intersect(set1
, set2
);
2487 isl_set_free(isl_set_coalesce(isl_set_copy(set1
)));
2488 set1
= isl_set_coalesce(set1
);
2492 return isl_stat_error
;
2497 /* Check that calling isl_set_coalesce does not leave other sets
2498 * that may share some information with the input to isl_set_coalesce
2499 * in an inconsistent state, for the case where one disjunct
2500 * is a subset of the other.
2502 static isl_stat
test_coalesce_special4(isl_ctx
*ctx
)
2504 const char *s1
, *s2
;
2506 s1
= "{ [a, b] : b <= 0 or a <= 1 }";
2507 s2
= "{ [a, b] : -1 <= -a < b }";
2508 return test_coalesce_intersection(ctx
, s1
, s2
);
2511 /* Check that calling isl_set_coalesce does not leave other sets
2512 * that may share some information with the input to isl_set_coalesce
2513 * in an inconsistent state, for the case where two disjuncts
2516 static isl_stat
test_coalesce_special5(isl_ctx
*ctx
)
2518 const char *s1
, *s2
;
2520 s1
= "{ [a, b, c] : b <= 0 }";
2521 s2
= "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }";
2522 return test_coalesce_intersection(ctx
, s1
, s2
);
2525 /* Check that calling isl_set_coalesce does not leave other sets
2526 * that may share some information with the input to isl_set_coalesce
2527 * in an inconsistent state, for the case where two disjuncts
2528 * can be fused and where both disjuncts have implicit equality constraints.
2530 static isl_stat
test_coalesce_special6(isl_ctx
*ctx
)
2532 const char *s1
, *s2
;
2534 s1
= "{ [a, b, c] : c <= 0 }";
2535 s2
= "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }";
2536 return test_coalesce_intersection(ctx
, s1
, s2
);
2539 /* Test the functionality of isl_set_coalesce.
2540 * That is, check that the output is always equal to the input
2541 * and in some cases that the result consists of a single disjunct.
2543 static int test_coalesce(struct isl_ctx
*ctx
)
2547 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2548 const char *str
= coalesce_tests
[i
].str
;
2549 int check_one
= coalesce_tests
[i
].single_disjunct
;
2550 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2554 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2556 if (test_coalesce_special(ctx
) < 0)
2558 if (test_coalesce_special2(ctx
) < 0)
2560 if (test_coalesce_special3(ctx
) < 0)
2562 if (test_coalesce_special4(ctx
) < 0)
2564 if (test_coalesce_special5(ctx
) < 0)
2566 if (test_coalesce_special6(ctx
) < 0)
2573 /* Construct a representation of the graph on the right of Figure 1
2574 * in "Computing the Transitive Closure of a Union of
2575 * Affine Integer Tuple Relations".
2577 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2580 isl_map
*up
, *right
;
2582 dom
= isl_set_read_from_str(ctx
,
2583 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2584 "2 x - 3 y + 3 >= 0 }");
2585 right
= isl_map_read_from_str(ctx
,
2586 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2587 up
= isl_map_read_from_str(ctx
,
2588 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2589 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2590 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2591 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2592 up
= isl_map_intersect_range(up
, dom
);
2593 return isl_map_union(up
, right
);
2596 /* Construct a representation of the power 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_power(isl_ctx
*ctx
)
2602 return isl_map_read_from_str(ctx
,
2603 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2604 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2605 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2608 /* Construct a representation of the transitive closure of the graph
2609 * on the right of Figure 1 in "Computing the Transitive Closure of
2610 * a Union of Affine Integer Tuple Relations".
2612 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2614 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2617 static int test_closure(isl_ctx
*ctx
)
2620 isl_map
*map
, *map2
;
2621 isl_bool exact
, equal
;
2623 /* COCOA example 1 */
2624 map
= isl_map_read_from_str(ctx
,
2625 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2626 "1 <= i and i < n and 1 <= j and j < n or "
2627 "i2 = i + 1 and j2 = j - 1 and "
2628 "1 <= i and i < n and 2 <= j and j <= n }");
2629 map
= isl_map_power(map
, &exact
);
2633 /* COCOA example 1 */
2634 map
= isl_map_read_from_str(ctx
,
2635 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2636 "1 <= i and i < n and 1 <= j and j < n or "
2637 "i2 = i + 1 and j2 = j - 1 and "
2638 "1 <= i and i < n and 2 <= j and j <= n }");
2639 map
= isl_map_transitive_closure(map
, &exact
);
2641 map2
= isl_map_read_from_str(ctx
,
2642 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2643 "1 <= i and i < n and 1 <= j and j <= n and "
2644 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2645 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2646 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2647 assert(isl_map_is_equal(map
, map2
));
2651 map
= isl_map_read_from_str(ctx
,
2652 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2653 " 0 <= y and y <= n }");
2654 map
= isl_map_transitive_closure(map
, &exact
);
2655 map2
= isl_map_read_from_str(ctx
,
2656 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2657 " 0 <= y and y <= n }");
2658 assert(isl_map_is_equal(map
, map2
));
2662 /* COCOA example 2 */
2663 map
= isl_map_read_from_str(ctx
,
2664 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2665 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2666 "i2 = i + 2 and j2 = j - 2 and "
2667 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2668 map
= isl_map_transitive_closure(map
, &exact
);
2670 map2
= isl_map_read_from_str(ctx
,
2671 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2672 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2673 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2674 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2675 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2676 assert(isl_map_is_equal(map
, map2
));
2680 /* COCOA Fig.2 left */
2681 map
= isl_map_read_from_str(ctx
,
2682 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2683 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2685 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2686 "j <= 2 i - 3 and j <= n - 2 or "
2687 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2688 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2689 map
= isl_map_transitive_closure(map
, &exact
);
2693 /* COCOA Fig.2 right */
2694 map
= isl_map_read_from_str(ctx
,
2695 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2696 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2698 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2699 "j <= 2 i - 4 and j <= n - 3 or "
2700 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2701 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2702 map
= isl_map_power(map
, &exact
);
2706 /* COCOA Fig.2 right */
2707 map
= isl_map_read_from_str(ctx
,
2708 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2709 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2711 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2712 "j <= 2 i - 4 and j <= n - 3 or "
2713 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2714 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2715 map
= isl_map_transitive_closure(map
, &exact
);
2717 map2
= isl_map_read_from_str(ctx
,
2718 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2719 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2720 "j <= n and 3 + i + 2 j <= 3 n and "
2721 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2722 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2723 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2724 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2725 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2726 assert(isl_map_is_equal(map
, map2
));
2730 map
= cocoa_fig_1_right_graph(ctx
);
2731 map
= isl_map_transitive_closure(map
, &exact
);
2733 map2
= cocoa_fig_1_right_tc(ctx
);
2734 assert(isl_map_is_equal(map
, map2
));
2738 map
= cocoa_fig_1_right_graph(ctx
);
2739 map
= isl_map_power(map
, &exact
);
2740 map2
= cocoa_fig_1_right_power(ctx
);
2741 equal
= isl_map_is_equal(map
, map2
);
2747 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2749 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2751 /* COCOA Theorem 1 counter example */
2752 map
= isl_map_read_from_str(ctx
,
2753 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2754 "i2 = 1 and j2 = j or "
2755 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2756 map
= isl_map_transitive_closure(map
, &exact
);
2760 map
= isl_map_read_from_str(ctx
,
2761 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2762 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2763 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2764 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2765 map
= isl_map_transitive_closure(map
, &exact
);
2769 /* Kelly et al 1996, fig 12 */
2770 map
= isl_map_read_from_str(ctx
,
2771 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2772 "1 <= i,j,j+1 <= n or "
2773 "j = n and j2 = 1 and i2 = i + 1 and "
2774 "1 <= i,i+1 <= n }");
2775 map
= isl_map_transitive_closure(map
, &exact
);
2777 map2
= isl_map_read_from_str(ctx
,
2778 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2779 "1 <= i <= n and i = i2 or "
2780 "1 <= i < i2 <= n and 1 <= j <= n and "
2782 assert(isl_map_is_equal(map
, map2
));
2786 /* Omega's closure4 */
2787 map
= isl_map_read_from_str(ctx
,
2788 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2789 "1 <= x,y <= 10 or "
2790 "x2 = x + 1 and y2 = y and "
2791 "1 <= x <= 20 && 5 <= y <= 15 }");
2792 map
= isl_map_transitive_closure(map
, &exact
);
2796 map
= isl_map_read_from_str(ctx
,
2797 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2798 map
= isl_map_transitive_closure(map
, &exact
);
2800 map2
= isl_map_read_from_str(ctx
,
2801 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2802 assert(isl_map_is_equal(map
, map2
));
2806 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2807 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2808 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2809 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2810 map
= isl_map_read_from_str(ctx
, str
);
2811 map
= isl_map_transitive_closure(map
, &exact
);
2813 map2
= isl_map_read_from_str(ctx
, str
);
2814 assert(isl_map_is_equal(map
, map2
));
2818 str
= "{[0] -> [1]; [2] -> [3]}";
2819 map
= isl_map_read_from_str(ctx
, str
);
2820 map
= isl_map_transitive_closure(map
, &exact
);
2822 map2
= isl_map_read_from_str(ctx
, str
);
2823 assert(isl_map_is_equal(map
, map2
));
2827 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2828 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2829 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2830 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2831 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2832 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2833 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2834 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2835 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2836 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2837 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2838 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2839 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2840 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2841 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2842 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2843 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2844 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2845 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2846 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2847 map
= isl_map_read_from_str(ctx
, str
);
2848 map
= isl_map_transitive_closure(map
, NULL
);
2855 /* Check that the actual result of a boolean operation is equal
2856 * to the expected result.
2858 static isl_stat
check_bool(isl_ctx
*ctx
, isl_bool actual
, isl_bool expected
)
2860 if (actual
!= expected
)
2861 isl_die(ctx
, isl_error_unknown
,
2862 "incorrect boolean operation", return isl_stat_error
);
2866 /* Test operations on isl_bool values.
2873 static int test_isl_bool(isl_ctx
*ctx
)
2875 if (check_bool(ctx
, isl_bool_not(isl_bool_true
), isl_bool_false
) < 0)
2877 if (check_bool(ctx
, isl_bool_not(isl_bool_false
), isl_bool_true
) < 0)
2879 if (check_bool(ctx
, isl_bool_not(isl_bool_error
), isl_bool_error
) < 0)
2881 if (check_bool(ctx
, isl_bool_ok(0), isl_bool_false
) < 0)
2883 if (check_bool(ctx
, isl_bool_ok(1), isl_bool_true
) < 0)
2885 if (check_bool(ctx
, isl_bool_ok(-1), isl_bool_true
) < 0)
2887 if (check_bool(ctx
, isl_bool_ok(2), isl_bool_true
) < 0)
2889 if (check_bool(ctx
, isl_bool_ok(-2), isl_bool_true
) < 0)
2895 static int test_lex(struct isl_ctx
*ctx
)
2901 space
= isl_space_set_alloc(ctx
, 0, 0);
2902 map
= isl_map_lex_le(space
);
2903 empty
= isl_map_is_empty(map
);
2909 isl_die(ctx
, isl_error_unknown
,
2910 "expecting non-empty result", return -1);
2915 /* Inputs for isl_map_lexmin tests.
2916 * "map" is the input and "lexmin" is the expected result.
2921 } lexmin_tests
[] = {
2922 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2923 "{ [x] -> [5] : 6 <= x <= 8; "
2924 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2925 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2926 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2927 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2928 "{ [x] -> [y] : (4y = x and x >= 0) or "
2929 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2930 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2931 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2932 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2933 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2934 /* Check that empty pieces are properly combined. */
2935 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2936 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2937 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2938 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2939 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2941 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2942 "a <= 255 and c <= 255 and d <= 255 - j and "
2943 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2944 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2945 "247d <= 247 + i and 248 - b <= 248d <= c and "
2946 "254d >= i - a + b and 254d >= -a + b and "
2947 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2949 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2950 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2951 "247j >= 62738 - i and 509j <= 129795 + i and "
2952 "742j >= 188724 - i; "
2953 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2954 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2955 "16*floor((8 + b)/16) <= 7 + b; "
2957 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2958 "[a] -> [b = 0] : 0 < a <= 509 }" },
2959 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2960 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2961 { "{ rat: [i] : 21 <= 2i <= 29 or i = 5 }", "{ rat: [5] }" },
2964 static int test_lexmin(struct isl_ctx
*ctx
)
2969 isl_basic_map
*bmap
;
2970 isl_map
*map
, *map2
;
2973 isl_pw_multi_aff
*pma
;
2975 str
= "[p0, p1] -> { [] -> [] : "
2976 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2977 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2978 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2979 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2980 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2981 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2982 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2983 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2984 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2985 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2986 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2987 map
= isl_map_read_from_str(ctx
, str
);
2988 map
= isl_map_lexmin(map
);
2993 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2994 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2995 set
= isl_set_read_from_str(ctx
, str
);
2996 set
= isl_set_lexmax(set
);
2997 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
2998 set2
= isl_set_read_from_str(ctx
, str
);
2999 set
= isl_set_intersect(set
, set2
);
3000 assert(!isl_set_is_empty(set
));
3003 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
3004 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
3005 map
= isl_map_lexmin(map
);
3006 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
3007 equal
= isl_map_is_equal(map
, map2
);
3014 isl_die(ctx
, isl_error_unknown
,
3015 "unexpected result", return -1);
3018 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3019 " 8i' <= i and 8i' >= -7 + i }";
3020 bmap
= isl_basic_map_read_from_str(ctx
, str
);
3021 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
3022 map2
= isl_map_from_pw_multi_aff(pma
);
3023 map
= isl_map_from_basic_map(bmap
);
3024 assert(isl_map_is_equal(map
, map2
));
3028 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3029 " 8i' <= i and 8i' >= -7 + i }";
3030 set
= isl_set_read_from_str(ctx
, str
);
3031 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
3032 set2
= isl_set_from_pw_multi_aff(pma
);
3033 equal
= isl_set_is_equal(set
, set2
);
3039 isl_die(ctx
, isl_error_unknown
,
3040 "unexpected difference between set and "
3041 "piecewise affine expression", return -1);
3046 /* Inputs for isl_pw_multi_aff_max_multi_val tests.
3047 * "pma" is the input.
3048 * "res" is the expected result.
3053 } opt_pw_tests
[] = {
3054 { "{ [-1] -> [-1]; [1] -> [1] }", "{ [1] }" },
3055 { "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] : "
3056 "0 <= a, b <= 100 and b mod 2 = 0}", "{ [30] }" },
3057 { "[N] -> { [i,j] -> A[i, -i, i + j] : 0 <= i,j <= N <= 10 }",
3058 "{ A[10, 0, 20] }" },
3059 { "[N] -> {A[N, -N, 2N] : 0 <= N }", "{ A[infty, 0, infty] }" },
3062 /* Perform basic isl_pw_multi_aff_max_multi_val tests.
3064 static isl_stat
test_pw_max(struct isl_ctx
*ctx
)
3067 isl_pw_multi_aff
*pma
;
3071 for (i
= 0; i
< ARRAY_SIZE(opt_pw_tests
); ++i
) {
3072 pma
= isl_pw_multi_aff_read_from_str(ctx
, opt_pw_tests
[i
].pma
);
3073 mv
= isl_pw_multi_aff_max_multi_val(pma
);
3074 r
= multi_val_check_plain_equal(mv
, opt_pw_tests
[i
].res
);
3075 isl_multi_val_free(mv
);
3078 return isl_stat_error
;
3084 /* A specialized isl_set_min_val test case that would return the wrong result
3085 * in earlier versions of isl.
3086 * The explicit call to isl_basic_set_union prevents the second basic set
3087 * from being determined to be empty prior to the call to isl_set_min_val,
3088 * at least at the point where this test case was introduced.
3090 static int test_min_special(isl_ctx
*ctx
)
3093 isl_basic_set
*bset1
, *bset2
;
3099 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
3100 bset1
= isl_basic_set_read_from_str(ctx
, str
);
3101 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
3102 bset2
= isl_basic_set_read_from_str(ctx
, str
);
3103 set
= isl_basic_set_union(bset1
, bset2
);
3104 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
3106 res
= isl_set_min_val(set
, obj
);
3107 ok
= isl_val_cmp_si(res
, 5) == 0;
3116 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
3122 /* A specialized isl_set_min_val test case that would return an error
3123 * in earlier versions of isl.
3125 static int test_min_special2(isl_ctx
*ctx
)
3128 isl_basic_set
*bset
;
3132 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
3133 bset
= isl_basic_set_read_from_str(ctx
, str
);
3135 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
3137 res
= isl_basic_set_max_val(bset
, obj
);
3139 isl_basic_set_free(bset
);
3149 /* Check that the result of isl_set_min_multi_pw_aff
3150 * on the union of the sets with string descriptions "s1" and "s2"
3151 * consists of a single expression (on a single cell).
3153 static isl_stat
check_single_expr_min(isl_ctx
*ctx
, const char *s1
,
3157 isl_set
*set1
, *set2
;
3158 isl_multi_pw_aff
*mpa
;
3159 isl_pw_multi_aff
*pma
;
3161 set1
= isl_set_read_from_str(ctx
, s1
);
3162 set2
= isl_set_read_from_str(ctx
, s2
);
3163 set1
= isl_set_union(set1
, set2
);
3164 mpa
= isl_set_min_multi_pw_aff(set1
);
3165 pma
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
3166 n
= isl_pw_multi_aff_n_piece(pma
);
3167 isl_pw_multi_aff_free(pma
);
3170 return isl_stat_error
;
3172 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
3173 return isl_stat_error
);
3177 /* A specialized isl_set_min_multi_pw_aff test that checks
3178 * that the minimum of 2N and 3N for N >= 0 is represented
3179 * by a single expression, without splitting off the special case N = 0.
3180 * Do this for both orderings.
3182 static int test_min_mpa(isl_ctx
*ctx
)
3184 const char *s1
, *s2
;
3186 s1
= "[N=0:] -> { [1, 3N:] }";
3187 s2
= "[N=0:] -> { [10, 2N:] }";
3188 if (check_single_expr_min(ctx
, s1
, s2
) < 0)
3190 if (check_single_expr_min(ctx
, s2
, s1
) < 0)
3199 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
3200 __isl_keep isl_aff
*obj
);
3203 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
3204 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
3205 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
3206 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
3207 &isl_set_max_val
, "30" },
3211 /* Perform basic isl_set_min_val and isl_set_max_val tests.
3212 * In particular, check the results on non-convex inputs.
3214 static int test_min(struct isl_ctx
*ctx
)
3222 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
3223 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
3224 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
3225 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
3226 val
= opt_tests
[i
].fn(set
, obj
);
3227 ok
= isl_val_eq(res
, val
);
3236 isl_die(ctx
, isl_error_unknown
,
3237 "unexpected optimum", return -1);
3240 if (test_pw_max(ctx
) < 0)
3242 if (test_min_special(ctx
) < 0)
3244 if (test_min_special2(ctx
) < 0)
3255 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
3256 void *dep_user
, void *user
)
3258 struct must_may
*mm
= (struct must_may
*)user
;
3261 mm
->must
= isl_map_union(mm
->must
, dep
);
3263 mm
->may
= isl_map_union(mm
->may
, dep
);
3268 static int common_space(void *first
, void *second
)
3270 int depth
= *(int *)first
;
3274 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
3282 map2
= isl_map_read_from_str(map
->ctx
, str
);
3283 equal
= isl_map_is_equal(map
, map2
);
3289 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
3293 equal
= map_is_equal(map
, str
);
3297 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
3298 "result not as expected", return -1);
3302 /* Is "set" equal to the set described by "str"?
3304 static isl_bool
set_is_equal(__isl_keep isl_set
*set
, const char *str
)
3310 return isl_bool_error
;
3312 set2
= isl_set_read_from_str(isl_set_get_ctx(set
), str
);
3313 equal
= isl_set_is_equal(set
, set2
);
3319 /* Check that "set" is equal to the set described by "str".
3321 static isl_stat
set_check_equal(__isl_keep isl_set
*set
, const char *str
)
3325 equal
= set_is_equal(set
, str
);
3327 return isl_stat_error
;
3329 isl_die(isl_set_get_ctx(set
), isl_error_unknown
,
3330 "result not as expected", return isl_stat_error
);
3334 /* Is "uset" equal to the union set described by "str"?
3336 static isl_bool
uset_is_equal(__isl_keep isl_union_set
*uset
, const char *str
)
3338 isl_union_set
*uset2
;
3342 return isl_bool_error
;
3344 uset2
= isl_union_set_read_from_str(isl_union_set_get_ctx(uset
), str
);
3345 equal
= isl_union_set_is_equal(uset
, uset2
);
3346 isl_union_set_free(uset2
);
3351 /* Check that "uset" is equal to the union set described by "str".
3353 static isl_stat
uset_check_equal(__isl_keep isl_union_set
*uset
,
3358 equal
= uset_is_equal(uset
, str
);
3360 return isl_stat_error
;
3362 isl_die(isl_union_set_get_ctx(uset
), isl_error_unknown
,
3363 "result not as expected", return isl_stat_error
);
3367 static int test_dep(struct isl_ctx
*ctx
)
3372 isl_access_info
*ai
;
3379 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3380 map
= isl_map_read_from_str(ctx
, str
);
3381 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3383 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3384 map
= isl_map_read_from_str(ctx
, str
);
3385 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3387 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3388 map
= isl_map_read_from_str(ctx
, str
);
3389 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3391 flow
= isl_access_info_compute_flow(ai
);
3392 space
= isl_space_alloc(ctx
, 0, 3, 3);
3393 mm
.must
= isl_map_empty(isl_space_copy(space
));
3394 mm
.may
= isl_map_empty(space
);
3396 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3398 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
3399 " [1,10,0] -> [2,5,0] }";
3400 assert(map_is_equal(mm
.must
, str
));
3401 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3402 assert(map_is_equal(mm
.may
, str
));
3404 isl_map_free(mm
.must
);
3405 isl_map_free(mm
.may
);
3406 isl_flow_free(flow
);
3409 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3410 map
= isl_map_read_from_str(ctx
, str
);
3411 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3413 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3414 map
= isl_map_read_from_str(ctx
, str
);
3415 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3417 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3418 map
= isl_map_read_from_str(ctx
, str
);
3419 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3421 flow
= isl_access_info_compute_flow(ai
);
3422 space
= isl_space_alloc(ctx
, 0, 3, 3);
3423 mm
.must
= isl_map_empty(isl_space_copy(space
));
3424 mm
.may
= isl_map_empty(space
);
3426 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3428 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
3429 assert(map_is_equal(mm
.must
, str
));
3430 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3431 assert(map_is_equal(mm
.may
, str
));
3433 isl_map_free(mm
.must
);
3434 isl_map_free(mm
.may
);
3435 isl_flow_free(flow
);
3438 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3439 map
= isl_map_read_from_str(ctx
, str
);
3440 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3442 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3443 map
= isl_map_read_from_str(ctx
, str
);
3444 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3446 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3447 map
= isl_map_read_from_str(ctx
, str
);
3448 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3450 flow
= isl_access_info_compute_flow(ai
);
3451 space
= isl_space_alloc(ctx
, 0, 3, 3);
3452 mm
.must
= isl_map_empty(isl_space_copy(space
));
3453 mm
.may
= isl_map_empty(space
);
3455 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3457 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
3458 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3459 assert(map_is_equal(mm
.may
, str
));
3460 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3461 assert(map_is_equal(mm
.must
, str
));
3463 isl_map_free(mm
.must
);
3464 isl_map_free(mm
.may
);
3465 isl_flow_free(flow
);
3468 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
3469 map
= isl_map_read_from_str(ctx
, str
);
3470 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3472 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3473 map
= isl_map_read_from_str(ctx
, str
);
3474 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3476 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3477 map
= isl_map_read_from_str(ctx
, str
);
3478 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3480 flow
= isl_access_info_compute_flow(ai
);
3481 space
= isl_space_alloc(ctx
, 0, 3, 3);
3482 mm
.must
= isl_map_empty(isl_space_copy(space
));
3483 mm
.may
= isl_map_empty(space
);
3485 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3487 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3488 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3489 assert(map_is_equal(mm
.may
, str
));
3490 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3491 assert(map_is_equal(mm
.must
, str
));
3493 isl_map_free(mm
.must
);
3494 isl_map_free(mm
.may
);
3495 isl_flow_free(flow
);
3498 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3499 map
= isl_map_read_from_str(ctx
, str
);
3500 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
3502 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3503 map
= isl_map_read_from_str(ctx
, str
);
3504 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3506 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3507 map
= isl_map_read_from_str(ctx
, str
);
3508 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
3510 flow
= isl_access_info_compute_flow(ai
);
3511 space
= isl_space_alloc(ctx
, 0, 3, 3);
3512 mm
.must
= isl_map_empty(isl_space_copy(space
));
3513 mm
.may
= isl_map_empty(space
);
3515 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3517 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3518 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3519 assert(map_is_equal(mm
.may
, str
));
3520 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3521 assert(map_is_equal(mm
.must
, str
));
3523 isl_map_free(mm
.must
);
3524 isl_map_free(mm
.may
);
3525 isl_flow_free(flow
);
3530 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3531 map
= isl_map_read_from_str(ctx
, str
);
3532 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
3534 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3535 map
= isl_map_read_from_str(ctx
, str
);
3536 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
3538 flow
= isl_access_info_compute_flow(ai
);
3539 space
= isl_space_alloc(ctx
, 0, 5, 5);
3540 mm
.must
= isl_map_empty(isl_space_copy(space
));
3541 mm
.may
= isl_map_empty(space
);
3543 isl_flow_foreach(flow
, collect_must_may
, &mm
);
3545 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3546 assert(map_is_equal(mm
.must
, str
));
3547 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3548 assert(map_is_equal(mm
.may
, str
));
3550 isl_map_free(mm
.must
);
3551 isl_map_free(mm
.may
);
3552 isl_flow_free(flow
);
3557 /* Check that the dependence analysis proceeds without errors.
3558 * Earlier versions of isl would break down during the analysis
3559 * due to the use of the wrong spaces.
3561 static int test_flow(isl_ctx
*ctx
)
3564 isl_union_map
*access
, *schedule
;
3565 isl_union_map
*must_dep
, *may_dep
;
3568 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3569 access
= isl_union_map_read_from_str(ctx
, str
);
3570 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3571 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3572 "S2[] -> [1,0,0,0]; "
3573 "S3[] -> [-1,0,0,0] }";
3574 schedule
= isl_union_map_read_from_str(ctx
, str
);
3575 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
3576 isl_union_map_copy(access
), schedule
,
3577 &must_dep
, &may_dep
, NULL
, NULL
);
3578 isl_union_map_free(may_dep
);
3579 isl_union_map_free(must_dep
);
3588 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3589 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3590 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3591 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3592 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3593 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3594 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3595 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3596 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3599 int test_sv(isl_ctx
*ctx
)
3601 isl_union_map
*umap
;
3605 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
3606 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
3607 sv
= isl_union_map_is_single_valued(umap
);
3608 isl_union_map_free(umap
);
3611 if (sv_tests
[i
].sv
&& !sv
)
3612 isl_die(ctx
, isl_error_internal
,
3613 "map not detected as single valued", return -1);
3614 if (!sv_tests
[i
].sv
&& sv
)
3615 isl_die(ctx
, isl_error_internal
,
3616 "map detected as single valued", return -1);
3625 } bijective_tests
[] = {
3626 { "[N,M]->{[i,j] -> [i]}", 0 },
3627 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3628 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3629 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3630 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3631 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3632 { "[N,M]->{[i,j] -> []}", 0 },
3633 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3634 { "[N,M]->{[i,j] -> [2i]}", 0 },
3635 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3636 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3637 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3638 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3641 static int test_bijective(struct isl_ctx
*ctx
)
3647 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
3648 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
3649 bijective
= isl_map_is_bijective(map
);
3653 if (bijective_tests
[i
].bijective
&& !bijective
)
3654 isl_die(ctx
, isl_error_internal
,
3655 "map not detected as bijective", return -1);
3656 if (!bijective_tests
[i
].bijective
&& bijective
)
3657 isl_die(ctx
, isl_error_internal
,
3658 "map detected as bijective", return -1);
3664 /* Inputs for isl_pw_qpolynomial_gist tests.
3665 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3671 } pwqp_gist_tests
[] = {
3672 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3673 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3674 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3675 "{ [i] -> -1/2 + 1/2 * i }" },
3676 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3679 /* Perform some basic isl_pw_qpolynomial_gist tests.
3681 static isl_stat
test_pwqp_gist(isl_ctx
*ctx
)
3686 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3689 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3690 str
= pwqp_gist_tests
[i
].pwqp
;
3691 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3692 str
= pwqp_gist_tests
[i
].set
;
3693 set
= isl_set_read_from_str(ctx
, str
);
3694 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3695 str
= pwqp_gist_tests
[i
].gist
;
3696 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3697 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3698 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3699 isl_pw_qpolynomial_free(pwqp1
);
3702 return isl_stat_error
;
3704 isl_die(ctx
, isl_error_unknown
,
3705 "unexpected result", return isl_stat_error
);
3711 /* Perform a basic isl_pw_qpolynomial_max test.
3713 static isl_stat
test_pwqp_max(isl_ctx
*ctx
)
3716 isl_pw_qpolynomial
*pwqp
;
3720 str
= "{ [x=2:9, y] -> floor((x + 1)/4)^3 - floor((2x)/3)^2 }";
3721 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3722 v
= isl_pw_qpolynomial_max(pwqp
);
3723 ok
= isl_val_cmp_si(v
, -1) == 0;
3727 return isl_stat_error
;
3729 isl_die(ctx
, isl_error_unknown
, "unexpected maximum",
3730 return isl_stat_error
);
3735 static int test_pwqp(struct isl_ctx
*ctx
)
3739 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3742 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3743 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3745 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3748 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3749 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3751 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3753 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3755 isl_pw_qpolynomial_free(pwqp1
);
3757 if (test_pwqp_gist(ctx
) < 0)
3760 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3761 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3762 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3763 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3765 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3767 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3769 isl_pw_qpolynomial_free(pwqp1
);
3771 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3772 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3773 str
= "{ [x] -> x }";
3774 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3776 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3778 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3780 isl_pw_qpolynomial_free(pwqp1
);
3782 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3783 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3784 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3785 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3786 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3787 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3788 isl_pw_qpolynomial_free(pwqp1
);
3790 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3791 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3792 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3793 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3794 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3795 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3796 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3797 isl_pw_qpolynomial_free(pwqp1
);
3798 isl_pw_qpolynomial_free(pwqp2
);
3802 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3804 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3805 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3806 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3807 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3808 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3810 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3811 isl_pw_qpolynomial_free(pwqp1
);
3812 isl_pw_qpolynomial_free(pwqp2
);
3816 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3818 if (test_pwqp_max(ctx
) < 0)
3824 static int test_split_periods(isl_ctx
*ctx
)
3827 isl_pw_qpolynomial
*pwqp
;
3829 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3830 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3831 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3832 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3834 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3836 isl_pw_qpolynomial_free(pwqp
);
3844 static int test_union(isl_ctx
*ctx
)
3847 isl_union_set
*uset1
, *uset2
;
3848 isl_union_map
*umap1
, *umap2
;
3851 str
= "{ [i] : 0 <= i <= 1 }";
3852 uset1
= isl_union_set_read_from_str(ctx
, str
);
3853 str
= "{ [1] -> [0] }";
3854 umap1
= isl_union_map_read_from_str(ctx
, str
);
3856 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3857 equal
= isl_union_map_is_equal(umap1
, umap2
);
3859 isl_union_map_free(umap1
);
3860 isl_union_map_free(umap2
);
3865 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3868 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3869 umap1
= isl_union_map_read_from_str(ctx
, str
);
3870 str
= "{ A[i]; B[i] }";
3871 uset1
= isl_union_set_read_from_str(ctx
, str
);
3873 uset2
= isl_union_map_domain(umap1
);
3875 equal
= isl_union_set_is_equal(uset1
, uset2
);
3877 isl_union_set_free(uset1
);
3878 isl_union_set_free(uset2
);
3883 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3889 /* Check that computing a bound of a non-zero polynomial over an unbounded
3890 * domain does not produce a rational value.
3891 * In particular, check that the upper bound is infinity.
3893 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
3896 isl_pw_qpolynomial
*pwqp
;
3897 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
3900 str
= "{ [m,n] -> -m * n }";
3901 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3902 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3904 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3905 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3906 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
3907 isl_pw_qpolynomial_fold_free(pwf
);
3908 isl_pw_qpolynomial_fold_free(pwf2
);
3913 isl_die(ctx
, isl_error_unknown
,
3914 "expecting infinite polynomial bound", return -1);
3919 /* Check that the bound computation can handle differences
3920 * in domain dimension names of the input polynomial and its domain.
3922 static isl_stat
test_bound_space(isl_ctx
*ctx
)
3926 isl_pw_qpolynomial
*pwqp
;
3927 isl_pw_qpolynomial_fold
*pwf
;
3929 str
= "{ [[c] -> [c]] }";
3930 set
= isl_set_read_from_str(ctx
, str
);
3931 str
= "{ [[a] -> [b]] -> 1 }";
3932 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3933 pwqp
= isl_pw_qpolynomial_intersect_domain(pwqp
, set
);
3934 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3935 isl_pw_qpolynomial_fold_free(pwf
);
3937 return isl_stat_non_null(pwf
);
3940 static int test_bound(isl_ctx
*ctx
)
3944 isl_pw_qpolynomial
*pwqp
;
3945 isl_pw_qpolynomial_fold
*pwf
;
3947 if (test_bound_unbounded_domain(ctx
) < 0)
3949 if (test_bound_space(ctx
) < 0)
3952 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
3953 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3954 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3955 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3956 isl_pw_qpolynomial_fold_free(pwf
);
3960 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3963 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3964 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3965 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3966 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3967 isl_pw_qpolynomial_fold_free(pwf
);
3971 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3977 /* isl_set is defined to isl_map internally, so the corresponding elements
3978 * are isl_basic_map objects.
3982 #define EL_BASE basic_map
3983 #define SET_BASE set
3984 #include "isl_test_list_templ.c"
3988 #define EL_BASE basic_set
3989 #define SET_BASE union_set
3990 #include "isl_test_list_templ.c"
3995 #define SET_BASE union_set
3996 #include "isl_test_list_templ.c"
4000 #define EL_BASE basic_map
4001 #define SET_BASE map
4002 #include "isl_test_list_templ.c"
4007 #define SET_BASE union_map
4008 #include "isl_test_list_templ.c"
4010 /* Check that the conversion from isl objects to lists works as expected.
4012 static int test_get_list(isl_ctx
*ctx
)
4014 if (test_get_list_basic_map_from_set(ctx
, "{ [0]; [2]; [3] }"))
4016 if (test_get_list_basic_set_from_union_set(ctx
, "{ A[0]; B[2]; B[3] }"))
4018 if (test_get_list_set_from_union_set(ctx
, "{ A[0]; A[2]; B[3] }"))
4020 if (test_get_list_basic_map_from_map(ctx
,
4021 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"))
4023 if (test_get_list_map_from_union_map(ctx
,
4024 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"))
4030 static int test_lift(isl_ctx
*ctx
)
4033 isl_basic_map
*bmap
;
4034 isl_basic_set
*bset
;
4036 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
4037 bset
= isl_basic_set_read_from_str(ctx
, str
);
4038 bset
= isl_basic_set_lift(bset
);
4039 bmap
= isl_basic_map_from_range(bset
);
4040 bset
= isl_basic_map_domain(bmap
);
4041 isl_basic_set_free(bset
);
4046 /* Check that isl_set_is_subset is not confused by identical
4047 * integer divisions.
4048 * The call to isl_set_normalize ensures that the equality constraints
4049 * a = b = 0 are discovered, turning e0 and e1 into identical
4050 * integer divisions. Any further simplification would remove
4051 * the duplicate integer divisions.
4053 static isl_stat
test_subset_duplicate_integer_divisions(isl_ctx
*ctx
)
4057 isl_set
*set1
, *set2
;
4059 str
= "{ [a, b, c, d] : "
4060 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
4061 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
4062 "e3 = floor((-d + 4*floor((d)/4))/10): "
4063 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
4064 "b >= 0 and a <= 0 and b <= a) }";
4065 set1
= isl_set_read_from_str(ctx
, str
);
4066 set2
= isl_set_read_from_str(ctx
, str
);
4067 set2
= isl_set_normalize(set2
);
4069 is_subset
= isl_set_is_subset(set1
, set2
);
4075 return isl_stat_error
;
4077 isl_die(ctx
, isl_error_unknown
,
4078 "set is not considered to be a subset of itself",
4079 return isl_stat_error
);
4088 } subset_tests
[] = {
4090 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
4091 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
4092 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
4094 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
4095 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
4096 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
4097 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
4098 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
4099 "256e0 <= 255i and 256e0 >= -255 + 255i and "
4100 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
4101 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
4102 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
4103 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
4104 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
4105 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
4106 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
4107 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
4108 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
4109 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
4110 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
4111 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
4112 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
4113 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
4114 "4e0 <= -57 + i0 + i1)) or "
4115 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
4116 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
4117 "4e0 >= -61 + i0 + i1)) or "
4118 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
4119 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
4122 static int test_subset(isl_ctx
*ctx
)
4125 isl_set
*set1
, *set2
;
4128 if (test_subset_duplicate_integer_divisions(ctx
) < 0)
4131 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
4132 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
4133 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
4134 subset
= isl_set_is_subset(set1
, set2
);
4139 if (subset
!= subset_tests
[i
].subset
)
4140 isl_die(ctx
, isl_error_unknown
,
4141 "incorrect subset result", return -1);
4147 /* Perform a set subtraction with a set that has a non-obviously empty disjunct.
4148 * Older versions of isl would fail on such cases.
4150 static isl_stat
test_subtract_empty(isl_ctx
*ctx
)
4155 s1
= isl_set_read_from_str(ctx
, "{ [0] }");
4156 str
= "{ [a] : (exists (e0, e1, e2: 1056e1 <= 32 + a - 33e0 and "
4157 "1089e1 >= a - 33e0 and 1089e1 <= 1 + a - 33e0 and "
4158 "33e2 >= -a + 33e0 + 1056e1 and "
4159 "33e2 < -2a + 66e0 + 2112e1)) or a = 0 }";
4160 s2
= isl_set_read_from_str(ctx
, str
);
4161 s1
= isl_set_subtract(s1
, s2
);
4164 return isl_stat_non_null(s1
);
4168 const char *minuend
;
4169 const char *subtrahend
;
4170 const char *difference
;
4171 } subtract_domain_tests
[] = {
4172 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
4173 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
4174 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
4177 static int test_subtract(isl_ctx
*ctx
)
4180 isl_union_map
*umap1
, *umap2
;
4181 isl_union_pw_multi_aff
*upma1
, *upma2
;
4182 isl_union_set
*uset
;
4185 if (test_subtract_empty(ctx
) < 0)
4188 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4189 umap1
= isl_union_map_read_from_str(ctx
,
4190 subtract_domain_tests
[i
].minuend
);
4191 uset
= isl_union_set_read_from_str(ctx
,
4192 subtract_domain_tests
[i
].subtrahend
);
4193 umap2
= isl_union_map_read_from_str(ctx
,
4194 subtract_domain_tests
[i
].difference
);
4195 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
4196 equal
= isl_union_map_is_equal(umap1
, umap2
);
4197 isl_union_map_free(umap1
);
4198 isl_union_map_free(umap2
);
4202 isl_die(ctx
, isl_error_unknown
,
4203 "incorrect subtract domain result", return -1);
4206 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
4207 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4208 subtract_domain_tests
[i
].minuend
);
4209 uset
= isl_union_set_read_from_str(ctx
,
4210 subtract_domain_tests
[i
].subtrahend
);
4211 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4212 subtract_domain_tests
[i
].difference
);
4213 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
4214 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
4215 isl_union_pw_multi_aff_free(upma1
);
4216 isl_union_pw_multi_aff_free(upma2
);
4220 isl_die(ctx
, isl_error_unknown
,
4221 "incorrect subtract domain result", return -1);
4227 /* Check that intersecting the empty basic set with another basic set
4228 * does not increase the number of constraints. In particular,
4229 * the empty basic set should maintain its canonical representation.
4231 static int test_intersect_1(isl_ctx
*ctx
)
4234 isl_basic_set
*bset1
, *bset2
;
4236 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
4237 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
4238 n1
= isl_basic_set_n_constraint(bset1
);
4239 bset1
= isl_basic_set_intersect(bset1
, bset2
);
4240 n2
= isl_basic_set_n_constraint(bset1
);
4241 isl_basic_set_free(bset1
);
4242 if (n1
< 0 || n2
< 0)
4245 isl_die(ctx
, isl_error_unknown
,
4246 "number of constraints of empty set changed",
4252 /* Check that intersecting a set with itself does not cause
4253 * an explosion in the number of disjuncts.
4255 static isl_stat
test_intersect_2(isl_ctx
*ctx
)
4260 set
= isl_set_read_from_str(ctx
, "{ [x,y] : x >= 0 or y >= 0 }");
4261 for (i
= 0; i
< 100; ++i
)
4262 set
= isl_set_intersect(set
, isl_set_copy(set
));
4265 return isl_stat_error
;
4269 /* Perform some intersection tests.
4271 static int test_intersect(isl_ctx
*ctx
)
4273 if (test_intersect_1(ctx
) < 0)
4275 if (test_intersect_2(ctx
) < 0)
4281 int test_factorize(isl_ctx
*ctx
)
4284 isl_basic_set
*bset
;
4287 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
4288 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
4289 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
4290 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
4291 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
4292 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
4293 "3i5 >= -2i0 - i2 + 3i4 }";
4294 bset
= isl_basic_set_read_from_str(ctx
, str
);
4295 f
= isl_basic_set_factorizer(bset
);
4296 isl_basic_set_free(bset
);
4297 isl_factorizer_free(f
);
4299 isl_die(ctx
, isl_error_unknown
,
4300 "failed to construct factorizer", return -1);
4302 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
4303 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
4304 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
4305 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
4306 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
4307 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
4308 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
4309 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
4310 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
4311 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
4312 bset
= isl_basic_set_read_from_str(ctx
, str
);
4313 f
= isl_basic_set_factorizer(bset
);
4314 isl_basic_set_free(bset
);
4315 isl_factorizer_free(f
);
4317 isl_die(ctx
, isl_error_unknown
,
4318 "failed to construct factorizer", return -1);
4323 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
4325 int *injective
= user
;
4327 *injective
= isl_map_is_injective(map
);
4330 if (*injective
< 0 || !*injective
)
4331 return isl_stat_error
;
4336 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
4337 const char *r
, const char *s
, int tilable
, int parallel
)
4341 isl_union_map
*W
, *R
, *S
;
4342 isl_union_map
*empty
;
4343 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
4344 isl_union_map
*validity
, *proximity
, *coincidence
;
4345 isl_union_map
*schedule
;
4346 isl_union_map
*test
;
4347 isl_union_set
*delta
;
4348 isl_union_set
*domain
;
4352 isl_schedule_constraints
*sc
;
4353 isl_schedule
*sched
;
4354 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
4357 D
= isl_union_set_read_from_str(ctx
, d
);
4358 W
= isl_union_map_read_from_str(ctx
, w
);
4359 R
= isl_union_map_read_from_str(ctx
, r
);
4360 S
= isl_union_map_read_from_str(ctx
, s
);
4362 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
4363 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
4365 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
4366 isl_union_map_compute_flow(isl_union_map_copy(R
),
4367 isl_union_map_copy(W
), empty
,
4368 isl_union_map_copy(S
),
4369 &dep_raw
, NULL
, NULL
, NULL
);
4370 isl_union_map_compute_flow(isl_union_map_copy(W
),
4371 isl_union_map_copy(W
),
4372 isl_union_map_copy(R
),
4373 isl_union_map_copy(S
),
4374 &dep_waw
, &dep_war
, NULL
, NULL
);
4376 dep
= isl_union_map_union(dep_waw
, dep_war
);
4377 dep
= isl_union_map_union(dep
, dep_raw
);
4378 validity
= isl_union_map_copy(dep
);
4379 coincidence
= isl_union_map_copy(dep
);
4380 proximity
= isl_union_map_copy(dep
);
4382 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
4383 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4384 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
4385 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4386 sched
= isl_schedule_constraints_compute_schedule(sc
);
4387 schedule
= isl_schedule_get_map(sched
);
4388 isl_schedule_free(sched
);
4389 isl_union_map_free(W
);
4390 isl_union_map_free(R
);
4391 isl_union_map_free(S
);
4394 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
4396 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
4397 is_complete
= isl_union_set_is_subset(D
, domain
);
4398 isl_union_set_free(D
);
4399 isl_union_set_free(domain
);
4401 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
4402 test
= isl_union_map_apply_range(test
, dep
);
4403 test
= isl_union_map_apply_range(test
, schedule
);
4405 delta
= isl_union_map_deltas(test
);
4406 n
= isl_union_set_n_set(delta
);
4408 isl_union_set_free(delta
);
4415 isl_union_set_free(delta
);
4419 delta_set
= isl_set_from_union_set(delta
);
4421 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4422 for (i
= 0; i
< tilable
; ++i
)
4423 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
4424 is_tilable
= isl_set_is_subset(delta_set
, slice
);
4425 isl_set_free(slice
);
4427 slice
= isl_set_universe(isl_set_get_space(delta_set
));
4428 for (i
= 0; i
< parallel
; ++i
)
4429 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
4430 is_parallel
= isl_set_is_subset(delta_set
, slice
);
4431 isl_set_free(slice
);
4433 origin
= isl_set_universe(isl_set_get_space(delta_set
));
4434 dim
= isl_set_dim(origin
, isl_dim_set
);
4436 origin
= isl_set_free(origin
);
4437 for (i
= 0; i
< dim
; ++i
)
4438 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
4440 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
4441 delta_set
= isl_set_lexmin(delta_set
);
4443 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
4445 isl_set_free(origin
);
4446 isl_set_free(delta_set
);
4449 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
4450 is_injection
< 0 || is_complete
< 0)
4453 isl_die(ctx
, isl_error_unknown
,
4454 "generated schedule incomplete", return -1);
4456 isl_die(ctx
, isl_error_unknown
,
4457 "generated schedule not injective on each statement",
4460 isl_die(ctx
, isl_error_unknown
,
4461 "negative dependences in generated schedule",
4464 isl_die(ctx
, isl_error_unknown
,
4465 "generated schedule not as tilable as expected",
4468 isl_die(ctx
, isl_error_unknown
,
4469 "generated schedule not as parallel as expected",
4475 /* Compute a schedule for the given instance set, validity constraints,
4476 * proximity constraints and context and return a corresponding union map
4479 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
4480 const char *domain
, const char *validity
, const char *proximity
,
4481 const char *context
)
4486 isl_union_map
*prox
;
4487 isl_schedule_constraints
*sc
;
4488 isl_schedule
*schedule
;
4489 isl_union_map
*sched
;
4491 con
= isl_set_read_from_str(ctx
, context
);
4492 dom
= isl_union_set_read_from_str(ctx
, domain
);
4493 dep
= isl_union_map_read_from_str(ctx
, validity
);
4494 prox
= isl_union_map_read_from_str(ctx
, proximity
);
4495 sc
= isl_schedule_constraints_on_domain(dom
);
4496 sc
= isl_schedule_constraints_set_context(sc
, con
);
4497 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
4498 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
4499 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4500 sched
= isl_schedule_get_map(schedule
);
4501 isl_schedule_free(schedule
);
4506 /* Compute a schedule for the given instance set, validity constraints and
4507 * proximity constraints and return a corresponding union map representation.
4509 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
4510 const char *domain
, const char *validity
, const char *proximity
)
4512 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
4516 /* Check that a schedule can be constructed on the given domain
4517 * with the given validity and proximity constraints.
4519 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
4520 const char *validity
, const char *proximity
)
4522 isl_union_map
*sched
;
4524 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
4528 isl_union_map_free(sched
);
4532 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
4533 const char *validity
, const char *proximity
, const char *expected_sched
)
4535 isl_union_map
*sched1
, *sched2
;
4538 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
4539 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
4541 equal
= isl_union_map_is_equal(sched1
, sched2
);
4542 isl_union_map_free(sched1
);
4543 isl_union_map_free(sched2
);
4548 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
4554 /* Check that the schedule map is properly padded, i.e., that the range
4555 * lives in a single space.
4557 static int test_padded_schedule(isl_ctx
*ctx
)
4561 isl_union_map
*validity
, *proximity
;
4562 isl_schedule_constraints
*sc
;
4563 isl_schedule
*sched
;
4564 isl_union_map
*umap
;
4565 isl_union_set
*range
;
4568 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4569 D
= isl_union_set_read_from_str(ctx
, str
);
4570 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
4571 proximity
= isl_union_map_copy(validity
);
4572 sc
= isl_schedule_constraints_on_domain(D
);
4573 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4574 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4575 sched
= isl_schedule_constraints_compute_schedule(sc
);
4576 umap
= isl_schedule_get_map(sched
);
4577 isl_schedule_free(sched
);
4578 range
= isl_union_map_range(umap
);
4579 set
= isl_set_from_union_set(range
);
4588 /* Check that conditional validity constraints are also taken into
4589 * account across bands.
4590 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4591 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4592 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4593 * is enforced by the rest of the schedule.
4595 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
4598 isl_union_set
*domain
;
4599 isl_union_map
*validity
, *proximity
, *condition
;
4600 isl_union_map
*sink
, *source
, *dep
;
4601 isl_schedule_constraints
*sc
;
4602 isl_schedule
*schedule
;
4603 isl_union_access_info
*access
;
4604 isl_union_flow
*flow
;
4607 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4608 "A[k] : k >= 1 and k <= -1 + n; "
4609 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4610 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4611 domain
= isl_union_set_read_from_str(ctx
, str
);
4612 sc
= isl_schedule_constraints_on_domain(domain
);
4613 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4614 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4615 "D[k, i] -> C[1 + k, i] : "
4616 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4617 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4618 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4619 validity
= isl_union_map_read_from_str(ctx
, str
);
4620 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
4621 str
= "[n] -> { C[k, i] -> D[k, i] : "
4622 "0 <= i <= -1 + k and k <= -1 + n }";
4623 proximity
= isl_union_map_read_from_str(ctx
, str
);
4624 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
4625 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4626 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4627 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4628 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4629 condition
= isl_union_map_read_from_str(ctx
, str
);
4630 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4631 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4632 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4633 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4634 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4635 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4636 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4637 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4638 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4639 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4640 validity
= isl_union_map_read_from_str(ctx
, str
);
4641 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4643 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4644 str
= "{ D[2,0] -> [] }";
4645 sink
= isl_union_map_read_from_str(ctx
, str
);
4646 access
= isl_union_access_info_from_sink(sink
);
4647 str
= "{ C[2,1] -> [] }";
4648 source
= isl_union_map_read_from_str(ctx
, str
);
4649 access
= isl_union_access_info_set_must_source(access
, source
);
4650 access
= isl_union_access_info_set_schedule(access
, schedule
);
4651 flow
= isl_union_access_info_compute_flow(access
);
4652 dep
= isl_union_flow_get_must_dependence(flow
);
4653 isl_union_flow_free(flow
);
4654 empty
= isl_union_map_is_empty(dep
);
4655 isl_union_map_free(dep
);
4660 isl_die(ctx
, isl_error_unknown
,
4661 "conditional validity not respected", return -1);
4666 /* Check that the test for violated conditional validity constraints
4667 * is not confused by domain compression.
4668 * In particular, earlier versions of isl would apply
4669 * a schedule on the compressed domains to the original domains,
4670 * resulting in a failure to detect that the default schedule
4671 * violates the conditional validity constraints.
4673 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
4677 isl_union_set
*domain
;
4678 isl_union_map
*validity
, *condition
;
4679 isl_schedule_constraints
*sc
;
4680 isl_schedule
*schedule
;
4681 isl_union_map
*umap
;
4684 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4685 domain
= isl_union_set_read_from_str(ctx
, str
);
4686 sc
= isl_schedule_constraints_on_domain(domain
);
4687 str
= "{ B[1, i] -> A[0, i + 1] }";
4688 condition
= isl_union_map_read_from_str(ctx
, str
);
4689 str
= "{ A[0, i] -> B[1, i - 1] }";
4690 validity
= isl_union_map_read_from_str(ctx
, str
);
4691 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
4692 isl_union_map_copy(validity
));
4693 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4694 umap
= isl_schedule_get_map(schedule
);
4695 isl_schedule_free(schedule
);
4696 validity
= isl_union_map_apply_domain(validity
,
4697 isl_union_map_copy(umap
));
4698 validity
= isl_union_map_apply_range(validity
, umap
);
4699 map
= isl_map_from_union_map(validity
);
4700 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4701 map
= isl_map_intersect(map
, ge
);
4702 empty
= isl_map_is_empty(map
);
4708 isl_die(ctx
, isl_error_unknown
,
4709 "conditional validity constraints not satisfied",
4715 /* Input for testing of schedule construction based on
4716 * conditional constraints.
4718 * domain is the iteration domain
4719 * flow are the flow dependences, which determine the validity and
4720 * proximity constraints
4721 * condition are the conditions on the conditional validity constraints
4722 * conditional_validity are the conditional validity constraints
4723 * outer_band_n is the expected number of members in the outer band
4728 const char *condition
;
4729 const char *conditional_validity
;
4731 } live_range_tests
[] = {
4732 /* Contrived example that illustrates that we need to keep
4733 * track of tagged condition dependences and
4734 * tagged conditional validity dependences
4735 * in isl_sched_edge separately.
4736 * In particular, the conditional validity constraints on A
4737 * cannot be satisfied,
4738 * but they can be ignored because there are no corresponding
4739 * condition constraints. However, we do have an additional
4740 * conditional validity constraint that maps to the same
4741 * dependence relation
4742 * as the condition constraint on B. If we did not make a distinction
4743 * between tagged condition and tagged conditional validity
4744 * dependences, then we
4745 * could end up treating this shared dependence as an condition
4746 * constraint on A, forcing a localization of the conditions,
4747 * which is impossible.
4749 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4750 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4751 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4752 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4753 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4754 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4757 /* TACO 2013 Fig. 7 */
4758 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4759 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4760 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4761 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4762 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4763 "0 <= i < n and 0 <= j < n - 1 }",
4764 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4765 "0 <= i < n and 0 <= j < j' < n;"
4766 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4767 "0 <= i < i' < n and 0 <= j,j' < n;"
4768 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4769 "0 <= i,j,j' < n and j < j' }",
4772 /* TACO 2013 Fig. 7, without tags */
4773 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4774 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4775 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4776 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4777 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4778 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4779 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4780 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4783 /* TACO 2013 Fig. 12 */
4784 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4785 "S3[i,3] : 0 <= i <= 1 }",
4786 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4787 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4788 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4789 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4790 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4791 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4792 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4793 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4794 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4795 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4796 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4801 /* Test schedule construction based on conditional constraints.
4802 * In particular, check the number of members in the outer band node
4803 * as an indication of whether tiling is possible or not.
4805 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
4808 isl_union_set
*domain
;
4809 isl_union_map
*condition
;
4810 isl_union_map
*flow
;
4811 isl_union_map
*validity
;
4812 isl_schedule_constraints
*sc
;
4813 isl_schedule
*schedule
;
4814 isl_schedule_node
*node
;
4817 if (test_special_conditional_schedule_constraints(ctx
) < 0)
4819 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
4822 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
4823 domain
= isl_union_set_read_from_str(ctx
,
4824 live_range_tests
[i
].domain
);
4825 flow
= isl_union_map_read_from_str(ctx
,
4826 live_range_tests
[i
].flow
);
4827 condition
= isl_union_map_read_from_str(ctx
,
4828 live_range_tests
[i
].condition
);
4829 validity
= isl_union_map_read_from_str(ctx
,
4830 live_range_tests
[i
].conditional_validity
);
4831 sc
= isl_schedule_constraints_on_domain(domain
);
4832 sc
= isl_schedule_constraints_set_validity(sc
,
4833 isl_union_map_copy(flow
));
4834 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
4835 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
4836 condition
, validity
);
4837 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4838 node
= isl_schedule_get_root(schedule
);
4840 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
4841 node
= isl_schedule_node_first_child(node
);
4842 n_member
= isl_schedule_node_band_n_member(node
);
4843 isl_schedule_node_free(node
);
4844 isl_schedule_free(schedule
);
4846 if (!schedule
|| n_member
< 0)
4848 if (n_member
!= live_range_tests
[i
].outer_band_n
)
4849 isl_die(ctx
, isl_error_unknown
,
4850 "unexpected number of members in outer band",
4856 /* Check that the schedule computed for the given instance set and
4857 * dependence relation strongly satisfies the dependences.
4858 * In particular, check that no instance is scheduled before
4859 * or together with an instance on which it depends.
4860 * Earlier versions of isl would produce a schedule that
4861 * only weakly satisfies the dependences.
4863 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
4865 const char *domain
, *dep
;
4866 isl_union_map
*D
, *schedule
;
4870 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4871 "A[i0] : 0 <= i0 <= 1 }";
4872 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4873 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4874 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
4875 D
= isl_union_map_read_from_str(ctx
, dep
);
4876 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
4877 D
= isl_union_map_apply_range(D
, schedule
);
4878 map
= isl_map_from_union_map(D
);
4879 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
4880 map
= isl_map_intersect(map
, ge
);
4881 empty
= isl_map_is_empty(map
);
4887 isl_die(ctx
, isl_error_unknown
,
4888 "dependences not strongly satisfied", return -1);
4893 /* Compute a schedule for input where the instance set constraints
4894 * conflict with the context constraints.
4895 * Earlier versions of isl did not properly handle this situation.
4897 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
4899 isl_union_map
*schedule
;
4900 const char *domain
, *context
;
4902 domain
= "[n] -> { A[] : n >= 0 }";
4903 context
= "[n] -> { : n < 0 }";
4904 schedule
= compute_schedule_with_context(ctx
,
4905 domain
, "{}", "{}", context
);
4906 isl_union_map_free(schedule
);
4914 /* Check that a set of schedule constraints that only allow for
4915 * a coalescing schedule still produces a schedule even if the user
4916 * request a non-coalescing schedule. Earlier versions of isl
4917 * would not handle this case correctly.
4919 static int test_coalescing_schedule(isl_ctx
*ctx
)
4921 const char *domain
, *dep
;
4924 isl_schedule_constraints
*sc
;
4925 isl_schedule
*schedule
;
4926 int treat_coalescing
;
4928 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4929 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
4930 I
= isl_union_set_read_from_str(ctx
, domain
);
4931 D
= isl_union_map_read_from_str(ctx
, dep
);
4932 sc
= isl_schedule_constraints_on_domain(I
);
4933 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4934 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4935 isl_options_set_schedule_treat_coalescing(ctx
, 1);
4936 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4937 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4938 isl_schedule_free(schedule
);
4944 /* Check that the scheduler does not perform any needless
4945 * compound skewing. Earlier versions of isl would compute
4946 * schedules in terms of transformed schedule coefficients and
4947 * would not accurately keep track of the sum of the original
4948 * schedule coefficients. It could then produce the schedule
4949 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4950 * for the input below instead of the schedule below.
4952 static int test_skewing_schedule(isl_ctx
*ctx
)
4954 const char *D
, *V
, *P
, *S
;
4956 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4957 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4958 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4959 "-1 <= a-i + b-j + c-k <= 1 }";
4961 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4963 return test_special_schedule(ctx
, D
, V
, P
, S
);
4966 int test_schedule(isl_ctx
*ctx
)
4968 const char *D
, *W
, *R
, *V
, *P
, *S
;
4969 int max_coincidence
;
4970 int treat_coalescing
;
4972 /* Handle resulting schedule with zero bands. */
4973 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4977 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4978 W
= "{ S1[t,i] -> a[t,i] }";
4979 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4980 "S1[t,i] -> a[t-1,i+1] }";
4981 S
= "{ S1[t,i] -> [t,i] }";
4982 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4985 /* Fig. 5 of CC2008 */
4986 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4988 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4989 "j >= 2 and j <= -1 + N }";
4990 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4991 "j >= 2 and j <= -1 + N; "
4992 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4993 "j >= 2 and j <= -1 + N }";
4994 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4995 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4998 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4999 W
= "{ S1[i] -> a[i] }";
5000 R
= "{ S2[i] -> a[i+1] }";
5001 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5002 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5005 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
5006 W
= "{ S1[i] -> a[i] }";
5007 R
= "{ S2[i] -> a[9-i] }";
5008 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5009 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5012 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
5013 W
= "{ S1[i] -> a[i] }";
5014 R
= "[N] -> { S2[i] -> a[N-1-i] }";
5015 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
5016 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
5019 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
5020 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
5021 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
5022 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
5023 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5026 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
5027 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
5028 R
= "{ S2[i,j] -> a[i-1,j] }";
5029 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5030 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5033 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
5034 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
5035 R
= "{ S2[i,j] -> a[i,j-1] }";
5036 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5037 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5040 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
5041 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
5042 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
5043 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
5044 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
5045 "S_0[] -> [0, 0, 0] }";
5046 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
5048 ctx
->opt
->schedule_parametric
= 0;
5049 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5051 ctx
->opt
->schedule_parametric
= 1;
5053 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
5054 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
5055 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
5056 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
5057 "S4[i] -> a[i,N] }";
5058 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
5059 "S4[i] -> [4,i,0] }";
5060 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
5061 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
5062 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
5064 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
5066 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
5067 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5069 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5071 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
5073 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
5074 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5077 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
5078 " S_2[t] : t >= 0 and t <= -1 + N; "
5079 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
5081 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
5082 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
5083 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
5084 "i >= 0 and i <= -1 + N }";
5085 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
5086 "i >= 0 and i <= -1 + N; "
5087 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
5088 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
5089 " S_0[t] -> [0, t, 0] }";
5091 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
5093 ctx
->opt
->schedule_parametric
= 0;
5094 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5096 ctx
->opt
->schedule_parametric
= 1;
5098 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
5099 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
5100 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
5103 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
5104 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
5105 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
5106 "j >= 0 and j <= -1 + N; "
5107 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5108 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
5109 "j >= 0 and j <= -1 + N; "
5110 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5111 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
5112 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5115 D
= "{ S_0[i] : i >= 0 }";
5116 W
= "{ S_0[i] -> a[i] : i >= 0 }";
5117 R
= "{ S_0[i] -> a[0] : i >= 0 }";
5118 S
= "{ S_0[i] -> [0, i, 0] }";
5119 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5122 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
5123 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
5124 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
5125 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
5126 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5129 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
5130 "k <= -1 + n and k >= 0 }";
5131 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
5132 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
5133 "k <= -1 + n and k >= 0; "
5134 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
5135 "k <= -1 + n and k >= 0; "
5136 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
5137 "k <= -1 + n and k >= 0 }";
5138 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
5139 ctx
->opt
->schedule_outer_coincidence
= 1;
5140 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
5142 ctx
->opt
->schedule_outer_coincidence
= 0;
5144 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
5145 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
5146 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
5147 "Stmt_for_body24[i0, i1, 1, 0]:"
5148 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
5149 "Stmt_for_body7[i0, i1, i2]:"
5150 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
5153 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
5154 "Stmt_for_body24[1, i1, i2, i3]:"
5155 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
5157 "Stmt_for_body24[0, i1, i2, i3] -> "
5158 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
5159 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
5161 "Stmt_for_body24[0, i1, i2, i3] ->"
5162 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
5163 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
5164 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
5165 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
5166 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
5167 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
5168 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
5169 "i1 <= 6 and i1 >= 0;"
5170 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
5171 "Stmt_for_body7[i0, i1, i2] -> "
5172 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
5173 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
5174 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
5175 "Stmt_for_body7[i0, i1, i2] -> "
5176 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
5177 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
5178 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
5181 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
5182 isl_options_set_schedule_treat_coalescing(ctx
, 0);
5183 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5185 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
5187 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
5188 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
5189 "j >= 1 and j <= 7;"
5190 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
5191 "j >= 1 and j <= 8 }";
5193 S
= "{ S_0[i, j] -> [i + j, i] }";
5194 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5195 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5197 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5199 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
5200 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
5201 "j >= 0 and j <= -1 + i }";
5202 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
5203 "i <= -1 + N and j >= 0;"
5204 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
5207 S
= "{ S_0[i, j] -> [i, j] }";
5208 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5209 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5211 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5213 /* Test both algorithms on a case with only proximity dependences. */
5214 D
= "{ S[i,j] : 0 <= i <= 10 }";
5216 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
5217 S
= "{ S[i, j] -> [j, i] }";
5218 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5219 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5221 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5222 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
5225 D
= "{ A[a]; B[] }";
5227 P
= "{ A[a] -> B[] }";
5228 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5231 if (test_padded_schedule(ctx
) < 0)
5234 /* Check that check for progress is not confused by rational
5237 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
5238 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
5240 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
5241 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
5243 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5244 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5246 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5248 /* Check that we allow schedule rows that are only non-trivial
5249 * on some full-dimensional domains.
5251 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
5252 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
5253 "S1[j] -> S2[1] : 0 <= j <= 1 }";
5255 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
5256 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
5258 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
5260 if (test_conditional_schedule_constraints(ctx
) < 0)
5263 if (test_strongly_satisfying_schedule(ctx
) < 0)
5266 if (test_conflicting_context_schedule(ctx
) < 0)
5269 if (test_coalescing_schedule(ctx
) < 0)
5271 if (test_skewing_schedule(ctx
) < 0)
5277 /* Perform scheduling tests using the whole component scheduler.
5279 static int test_schedule_whole(isl_ctx
*ctx
)
5284 whole
= isl_options_get_schedule_whole_component(ctx
);
5285 isl_options_set_schedule_whole_component(ctx
, 1);
5286 r
= test_schedule(ctx
);
5287 isl_options_set_schedule_whole_component(ctx
, whole
);
5292 /* Perform scheduling tests using the incremental scheduler.
5294 static int test_schedule_incremental(isl_ctx
*ctx
)
5299 whole
= isl_options_get_schedule_whole_component(ctx
);
5300 isl_options_set_schedule_whole_component(ctx
, 0);
5301 r
= test_schedule(ctx
);
5302 isl_options_set_schedule_whole_component(ctx
, whole
);
5307 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
5309 isl_union_map
*umap
;
5312 umap
= isl_union_map_read_from_str(ctx
, str
);
5313 test
= isl_union_map_plain_is_injective(umap
);
5314 isl_union_map_free(umap
);
5317 if (test
== injective
)
5320 isl_die(ctx
, isl_error_unknown
,
5321 "map not detected as injective", return -1);
5323 isl_die(ctx
, isl_error_unknown
,
5324 "map detected as injective", return -1);
5327 int test_injective(isl_ctx
*ctx
)
5331 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
5333 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
5335 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
5337 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
5339 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
5341 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
5343 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
5345 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
5348 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
5349 if (test_plain_injective(ctx
, str
, 1))
5351 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
5352 if (test_plain_injective(ctx
, str
, 0))
5360 #include "isl_test_plain_equal_templ.c"
5363 #define BASE pw_multi_aff
5364 #include "isl_test_plain_equal_templ.c"
5367 #define BASE union_pw_aff
5368 #include "isl_test_plain_equal_templ.c"
5370 /* Basic tests on isl_union_pw_aff.
5372 * In particular, check that isl_union_pw_aff_aff_on_domain
5373 * aligns the parameters of the input objects and
5374 * that isl_union_pw_aff_param_on_domain_id properly
5375 * introduces the parameter.
5377 static int test_upa(isl_ctx
*ctx
)
5382 isl_union_set
*domain
;
5383 isl_union_pw_aff
*upa
;
5386 aff
= isl_aff_read_from_str(ctx
, "[N] -> { [N] }");
5387 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5388 domain
= isl_union_set_read_from_str(ctx
, str
);
5389 upa
= isl_union_pw_aff_aff_on_domain(domain
, aff
);
5390 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5391 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5392 isl_union_pw_aff_free(upa
);
5396 id
= isl_id_alloc(ctx
, "N", NULL
);
5397 str
= "[M] -> { A[i] : 0 <= i < M; B[] }";
5398 domain
= isl_union_set_read_from_str(ctx
, str
);
5399 upa
= isl_union_pw_aff_param_on_domain_id(domain
, id
);
5400 str
= "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5401 ok
= union_pw_aff_check_plain_equal(upa
, str
);
5402 isl_union_pw_aff_free(upa
);
5410 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5411 __isl_take isl_aff
*aff2
);
5413 ['+'] = { &isl_aff_add
},
5414 ['-'] = { &isl_aff_sub
},
5415 ['*'] = { &isl_aff_mul
},
5416 ['/'] = { &isl_aff_div
},
5424 } aff_bin_tests
[] = {
5425 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5426 "{ [i] -> [2i] }" },
5427 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5429 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5430 "{ [i] -> [2i] }" },
5431 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5432 "{ [i] -> [2i] }" },
5433 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5434 "{ [i] -> [i/2] }" },
5435 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5437 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5438 "{ [i] -> [NaN] }" },
5439 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5440 "{ [i] -> [NaN] }" },
5441 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5442 "{ [i] -> [NaN] }" },
5443 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5444 "{ [i] -> [NaN] }" },
5445 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5446 "{ [i] -> [NaN] }" },
5447 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5448 "{ [i] -> [NaN] }" },
5449 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5450 "{ [i] -> [NaN] }" },
5451 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5452 "{ [i] -> [NaN] }" },
5453 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5454 "{ [i] -> [NaN] }" },
5455 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5456 "{ [i] -> [NaN] }" },
5457 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5458 "{ [i] -> [NaN] }" },
5459 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5460 "{ [i] -> [NaN] }" },
5461 { "{ [i] -> [i] }", '/', "{ [i] -> [0] }",
5462 "{ [i] -> [NaN] }" },
5465 /* Perform some basic tests of binary operations on isl_aff objects.
5467 static int test_bin_aff(isl_ctx
*ctx
)
5470 isl_aff
*aff1
, *aff2
, *res
;
5471 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
5472 __isl_take isl_aff
*aff2
);
5475 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
5476 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
5477 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
5478 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
5479 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
5480 aff1
= fn(aff1
, aff2
);
5481 if (isl_aff_is_nan(res
))
5482 ok
= isl_aff_is_nan(aff1
);
5484 ok
= isl_aff_plain_is_equal(aff1
, res
);
5490 isl_die(ctx
, isl_error_unknown
,
5491 "unexpected result", return -1);
5498 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
5499 __isl_take isl_pw_aff
*pa2
);
5500 } pw_aff_bin_op
[] = {
5501 ['m'] = { &isl_pw_aff_min
},
5502 ['M'] = { &isl_pw_aff_max
},
5505 /* Inputs for binary isl_pw_aff operation tests.
5506 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5507 * defined by pw_aff_bin_op, and "res" is the expected result.
5514 } pw_aff_bin_tests
[] = {
5515 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5517 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5519 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5520 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5521 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5522 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5523 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5524 "{ [i] -> [NaN] }" },
5525 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5526 "{ [i] -> [NaN] }" },
5529 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5531 static int test_bin_pw_aff(isl_ctx
*ctx
)
5535 isl_pw_aff
*pa1
, *pa2
, *res
;
5537 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
5538 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
5539 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
5540 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
5541 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
5542 if (isl_pw_aff_involves_nan(res
))
5543 ok
= isl_pw_aff_involves_nan(pa1
);
5545 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
5546 isl_pw_aff_free(pa1
);
5547 isl_pw_aff_free(res
);
5551 isl_die(ctx
, isl_error_unknown
,
5552 "unexpected result", return -1);
5558 /* Inputs for basic tests of test operations on
5559 * isl_union_pw_multi_aff objects.
5560 * "fn" is the function that is being tested.
5561 * "arg" is a string description of the input.
5562 * "res" is the expected result.
5565 isl_bool (*fn
)(__isl_keep isl_union_pw_multi_aff
*upma1
);
5568 } upma_test_tests
[] = {
5569 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [1] }",
5571 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [NaN]; B[0] -> [1] }",
5573 { &isl_union_pw_multi_aff_involves_nan
, "{ A[] -> [0]; B[0] -> [NaN] }",
5575 { &isl_union_pw_multi_aff_involves_nan
,
5576 "{ A[] -> [0]; B[0] -> [1, NaN, 5] }",
5578 { &isl_union_pw_multi_aff_involves_locals
,
5579 "{ A[] -> [0]; B[0] -> [1] }",
5581 { &isl_union_pw_multi_aff_involves_locals
,
5582 "{ A[] -> [0]; B[x] -> [1] : x mod 2 = 0 }",
5584 { &isl_union_pw_multi_aff_involves_locals
,
5585 "{ A[] -> [0]; B[x] -> [x // 2] }",
5587 { &isl_union_pw_multi_aff_involves_locals
,
5588 "{ A[i] -> [i // 2]; B[0] -> [1] }",
5592 /* Perform some basic tests of test operations on
5593 * isl_union_pw_multi_aff objects.
5595 static isl_stat
test_upma_test(isl_ctx
*ctx
)
5598 isl_union_pw_multi_aff
*upma
;
5601 for (i
= 0; i
< ARRAY_SIZE(upma_test_tests
); ++i
) {
5604 str
= upma_test_tests
[i
].arg
;
5605 upma
= isl_union_pw_multi_aff_read_from_str(ctx
, str
);
5606 res
= upma_test_tests
[i
].fn(upma
);
5607 isl_union_pw_multi_aff_free(upma
);
5609 return isl_stat_error
;
5610 if (res
!= upma_test_tests
[i
].res
)
5611 isl_die(ctx
, isl_error_unknown
,
5612 "unexpected result", return isl_stat_error
);
5619 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5620 __isl_take isl_union_pw_multi_aff
*upma1
,
5621 __isl_take isl_union_pw_multi_aff
*upma2
);
5625 } upma_bin_tests
[] = {
5626 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
5627 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5628 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
5629 "{ B[x] -> [2] : x >= 0 }",
5630 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5631 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
5632 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5633 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5634 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5635 "D[i] -> B[2] : i >= 5 }" },
5636 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5637 "{ B[x] -> C[2] : x > 0 }",
5638 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5639 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5640 "{ B[x] -> A[2] : x >= 0 }",
5641 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5643 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5644 "{ B[x] -> C[x + 2] }",
5645 "{ D[y] -> B[2y] }",
5648 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5649 "{ [A[x] -> B[x + 1]] -> C[x + 2] }",
5650 "{ D[y] -> B[2y] }",
5653 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5654 "{ [A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5655 "{ D[y] -> A[2y] }",
5656 "{ [D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5658 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff
,
5659 "{ T[A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5660 "{ D[y] -> A[2y] }",
5661 "{ T[D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5664 /* Perform some basic tests of binary operations on
5665 * isl_union_pw_multi_aff objects.
5667 static int test_bin_upma(isl_ctx
*ctx
)
5670 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
5673 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
5674 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5675 upma_bin_tests
[i
].arg1
);
5676 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5677 upma_bin_tests
[i
].arg2
);
5678 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5679 upma_bin_tests
[i
].res
);
5680 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
5681 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
5682 isl_union_pw_multi_aff_free(upma1
);
5683 isl_union_pw_multi_aff_free(res
);
5687 isl_die(ctx
, isl_error_unknown
,
5688 "unexpected result", return -1);
5695 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5696 __isl_take isl_union_pw_multi_aff
*upma1
,
5697 __isl_take isl_union_pw_multi_aff
*upma2
);
5700 } upma_bin_fail_tests
[] = {
5701 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
5702 "{ B[x] -> C[2] : x >= 0 }" },
5705 /* Perform some basic tests of binary operations on
5706 * isl_union_pw_multi_aff objects that are expected to fail.
5708 static int test_bin_upma_fail(isl_ctx
*ctx
)
5711 isl_union_pw_multi_aff
*upma1
, *upma2
;
5714 on_error
= isl_options_get_on_error(ctx
);
5715 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
5716 n
= ARRAY_SIZE(upma_bin_fail_tests
);
5717 for (i
= 0; i
< n
; ++i
) {
5718 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
5719 upma_bin_fail_tests
[i
].arg1
);
5720 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
5721 upma_bin_fail_tests
[i
].arg2
);
5722 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
5723 isl_union_pw_multi_aff_free(upma1
);
5727 isl_options_set_on_error(ctx
, on_error
);
5729 isl_die(ctx
, isl_error_unknown
,
5730 "operation not expected to succeed", return -1);
5735 /* Inputs for basic tests of binary operations on
5736 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5737 * "fn" is the function that is being tested.
5738 * "arg1" and "arg2" are string descriptions of the inputs.
5739 * "res" is a string description of the expected result.
5742 __isl_give isl_union_pw_multi_aff
*(*fn
)(
5743 __isl_take isl_union_pw_multi_aff
*upma
,
5744 __isl_take isl_union_set
*uset
);
5748 } upma_uset_tests
[] = {
5749 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5750 "{ A[i] -> B[i] }", "{ B[0] }",
5752 { &isl_union_pw_multi_aff_intersect_domain_wrapped_domain
,
5753 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5754 "{ [A[1] -> B[1]] -> C[2] }" },
5755 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5756 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5757 "{ [A[0] -> B[0]] -> C[1] }" },
5758 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5759 "{ [A[i] -> B[i]] -> C[i + 1] }", "[N] -> { B[N] }",
5760 "[N] -> { [A[N] -> B[N]] -> C[N + 1] }" },
5761 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5762 "[M] -> { [A[M] -> B[M]] -> C[M + 1] }", "[N] -> { B[N] }",
5763 "[N, M] -> { [A[N] -> B[N]] -> C[N + 1] : N = M }" },
5764 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range
,
5765 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[]; [B[] -> A[]] -> E[] }",
5767 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[] }" },
5770 /* Perform some basic tests of binary operations on
5771 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5773 static isl_stat
test_upma_uset(isl_ctx
*ctx
)
5777 isl_union_pw_multi_aff
*upma
, *res
;
5778 isl_union_set
*uset
;
5780 for (i
= 0; i
< ARRAY_SIZE(upma_uset_tests
); ++i
) {
5781 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
5782 upma_uset_tests
[i
].arg1
);
5783 uset
= isl_union_set_read_from_str(ctx
,
5784 upma_uset_tests
[i
].arg2
);
5785 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
5786 upma_uset_tests
[i
].res
);
5787 upma
= upma_uset_tests
[i
].fn(upma
, uset
);
5788 ok
= isl_union_pw_multi_aff_plain_is_equal(upma
, res
);
5789 isl_union_pw_multi_aff_free(upma
);
5790 isl_union_pw_multi_aff_free(res
);
5792 return isl_stat_error
;
5794 isl_die(ctx
, isl_error_unknown
,
5795 "unexpected result", return isl_stat_error
);
5801 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5802 * "fn" is the function that is tested.
5803 * "arg" is a string description of the input.
5804 * "res" is a string description of the expected result.
5807 __isl_give isl_multi_pw_aff
*(*fn
)(__isl_take isl_multi_pw_aff
*mpa
);
5810 } mpa_un_tests
[] = {
5811 { &isl_multi_pw_aff_range_factor_domain
,
5812 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5813 "{ A[x] -> B[(1 : x >= 5)] }" },
5814 { &isl_multi_pw_aff_range_factor_range
,
5815 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5816 "{ A[y] -> C[(2 : y <= 10)] }" },
5817 { &isl_multi_pw_aff_range_factor_domain
,
5818 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5819 "{ A[x] -> B[(1 : x >= 5)] }" },
5820 { &isl_multi_pw_aff_range_factor_range
,
5821 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5822 "{ A[y] -> C[] }" },
5823 { &isl_multi_pw_aff_range_factor_domain
,
5824 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5825 "{ A[x] -> B[] }" },
5826 { &isl_multi_pw_aff_range_factor_range
,
5827 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5828 "{ A[y] -> C[(2 : y <= 10)] }" },
5829 { &isl_multi_pw_aff_range_factor_domain
,
5830 "{ A[x] -> [B[] -> C[]] }",
5831 "{ A[x] -> B[] }" },
5832 { &isl_multi_pw_aff_range_factor_range
,
5833 "{ A[x] -> [B[] -> C[]] }",
5834 "{ A[y] -> C[] }" },
5835 { &isl_multi_pw_aff_factor_range
,
5838 { &isl_multi_pw_aff_range_factor_domain
,
5839 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5840 "{ A[x] -> B[] : x >= 0 }" },
5841 { &isl_multi_pw_aff_range_factor_range
,
5842 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5843 "{ A[y] -> C[] : y >= 0 }" },
5844 { &isl_multi_pw_aff_factor_range
,
5845 "[N] -> { [B[] -> C[]] : N >= 0 }",
5846 "[N] -> { C[] : N >= 0 }" },
5849 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5851 static int test_un_mpa(isl_ctx
*ctx
)
5855 isl_multi_pw_aff
*mpa
, *res
;
5857 for (i
= 0; i
< ARRAY_SIZE(mpa_un_tests
); ++i
) {
5858 mpa
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].arg
);
5859 res
= isl_multi_pw_aff_read_from_str(ctx
, mpa_un_tests
[i
].res
);
5860 mpa
= mpa_un_tests
[i
].fn(mpa
);
5861 ok
= isl_multi_pw_aff_plain_is_equal(mpa
, res
);
5862 isl_multi_pw_aff_free(mpa
);
5863 isl_multi_pw_aff_free(res
);
5867 isl_die(ctx
, isl_error_unknown
,
5868 "unexpected result", return -1);
5874 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5875 * "fn" is the function that is tested.
5876 * "arg1" and "arg2" are string descriptions of the inputs.
5877 * "res" is a string description of the expected result.
5880 __isl_give isl_multi_pw_aff
*(*fn
)(
5881 __isl_take isl_multi_pw_aff
*mpa1
,
5882 __isl_take isl_multi_pw_aff
*mpa2
);
5886 } mpa_bin_tests
[] = {
5887 { &isl_multi_pw_aff_add
, "{ A[] -> [1] }", "{ A[] -> [2] }",
5889 { &isl_multi_pw_aff_add
, "{ A[x] -> [(1 : x >= 5)] }",
5890 "{ A[x] -> [(x : x <= 10)] }",
5891 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5892 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5893 "{ A[x] -> [] : x <= 10 }",
5894 "{ A[x] -> [] : 5 <= x <= 10 }" },
5895 { &isl_multi_pw_aff_add
, "{ A[x] -> [] : x >= 5 }",
5896 "[N] -> { A[x] -> [] : x <= N }",
5897 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5898 { &isl_multi_pw_aff_add
,
5899 "[N] -> { A[x] -> [] : x <= N }",
5900 "{ A[x] -> [] : x >= 5 }",
5901 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5902 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5903 "{ A[y] -> C[(2 : y <= 10)] }",
5904 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5905 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5906 "{ A[y] -> C[2] : y <= 10 }",
5907 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5908 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[1] : x >= 5 }",
5909 "[N] -> { A[y] -> C[2] : y <= N }",
5910 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5911 { &isl_multi_pw_aff_range_product
, "[N] -> { A[x] -> B[1] : x >= N }",
5912 "{ A[y] -> C[2] : y <= 10 }",
5913 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5914 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5915 "{ A[] -> [B[1] -> C[2]] }" },
5916 { &isl_multi_pw_aff_range_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5917 "{ A[] -> [B[] -> C[]] }" },
5918 { &isl_multi_pw_aff_range_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5919 "{ A[y] -> C[] : y <= 10 }",
5920 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5921 { &isl_multi_pw_aff_range_product
, "{ A[y] -> C[] : y <= 10 }",
5922 "{ A[x] -> B[(1 : x >= 5)] }",
5923 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5924 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5925 "{ A[y] -> C[(2 : y <= 10)] }",
5926 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5927 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5928 "{ A[y] -> C[] : y <= 10 }",
5929 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5930 { &isl_multi_pw_aff_product
, "{ A[y] -> C[] : y <= 10 }",
5931 "{ A[x] -> B[(1 : x >= 5)] }",
5932 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5933 { &isl_multi_pw_aff_product
, "{ A[x] -> B[(1 : x >= 5)] }",
5934 "[N] -> { A[y] -> C[] : y <= N }",
5935 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5936 { &isl_multi_pw_aff_product
, "[N] -> { A[y] -> C[] : y <= N }",
5937 "{ A[x] -> B[(1 : x >= 5)] }",
5938 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5939 { &isl_multi_pw_aff_product
, "{ A[x] -> B[] : x >= 5 }",
5940 "{ A[y] -> C[] : y <= 10 }",
5941 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5942 { &isl_multi_pw_aff_product
, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5943 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5944 { &isl_multi_pw_aff_product
, "{ A[] -> B[] }", "{ A[] -> C[] }",
5945 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5946 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5947 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5948 "{ A[a,b] -> C[b + 2a] }" },
5949 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5950 "{ B[i,j] -> C[i + 2j] }",
5951 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5952 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5953 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5954 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5955 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5956 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5957 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5958 "{ B[i,j] -> C[] }",
5959 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5960 "{ A[a,b] -> C[] }" },
5961 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5962 "{ B[i,j] -> C[] : i > j }",
5963 "{ A[a,b] -> B[b,a] }",
5964 "{ A[a,b] -> C[] : b > a }" },
5965 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5966 "{ B[i,j] -> C[] : j > 5 }",
5967 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5968 "{ A[a,b] -> C[] : b > a > 5 }" },
5969 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5970 "[N] -> { B[i,j] -> C[] : j > N }",
5971 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5972 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5973 { &isl_multi_pw_aff_pullback_multi_pw_aff
,
5974 "[M,N] -> { B[] -> C[] : N > 5 }",
5975 "[M,N] -> { A[] -> B[] : M > N }",
5976 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5979 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5981 static int test_bin_mpa(isl_ctx
*ctx
)
5985 isl_multi_pw_aff
*mpa1
, *mpa2
, *res
;
5987 for (i
= 0; i
< ARRAY_SIZE(mpa_bin_tests
); ++i
) {
5988 mpa1
= isl_multi_pw_aff_read_from_str(ctx
,
5989 mpa_bin_tests
[i
].arg1
);
5990 mpa2
= isl_multi_pw_aff_read_from_str(ctx
,
5991 mpa_bin_tests
[i
].arg2
);
5992 res
= isl_multi_pw_aff_read_from_str(ctx
,
5993 mpa_bin_tests
[i
].res
);
5994 mpa1
= mpa_bin_tests
[i
].fn(mpa1
, mpa2
);
5995 ok
= isl_multi_pw_aff_plain_is_equal(mpa1
, res
);
5996 isl_multi_pw_aff_free(mpa1
);
5997 isl_multi_pw_aff_free(res
);
6001 isl_die(ctx
, isl_error_unknown
,
6002 "unexpected result", return -1);
6008 /* Inputs for basic tests of unary operations on
6009 * isl_multi_union_pw_aff objects.
6010 * "fn" is the function that is tested.
6011 * "arg" is a string description of the input.
6012 * "res" is a string description of the expected result.
6015 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6016 __isl_take isl_multi_union_pw_aff
*mupa
);
6019 } mupa_un_tests
[] = {
6020 { &isl_multi_union_pw_aff_factor_range
,
6021 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
6022 "C[{ A[] -> [2] }]" },
6023 { &isl_multi_union_pw_aff_factor_range
,
6024 "[B[] -> C[{ A[] -> [2] }]]",
6025 "C[{ A[] -> [2] }]" },
6026 { &isl_multi_union_pw_aff_factor_range
,
6027 "[B[{ A[] -> [1] }] -> C[]]",
6029 { &isl_multi_union_pw_aff_factor_range
,
6032 { &isl_multi_union_pw_aff_factor_range
,
6033 "([B[] -> C[]] : { A[x] : x >= 0 })",
6034 "(C[] : { A[x] : x >= 0 })" },
6035 { &isl_multi_union_pw_aff_factor_range
,
6036 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
6037 "[N] -> (C[] : { A[x] : x <= N })" },
6038 { &isl_multi_union_pw_aff_factor_range
,
6039 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
6040 "[N] -> (C[] : { : N >= 0 })" },
6043 /* Perform some basic tests of unary operations on
6044 * isl_multi_union_pw_aff objects.
6046 static int test_un_mupa(isl_ctx
*ctx
)
6050 isl_multi_union_pw_aff
*mupa
, *res
;
6052 for (i
= 0; i
< ARRAY_SIZE(mupa_un_tests
); ++i
) {
6053 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6054 mupa_un_tests
[i
].arg
);
6055 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6056 mupa_un_tests
[i
].res
);
6057 mupa
= mupa_un_tests
[i
].fn(mupa
);
6058 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6059 isl_multi_union_pw_aff_free(mupa
);
6060 isl_multi_union_pw_aff_free(res
);
6064 isl_die(ctx
, isl_error_unknown
,
6065 "unexpected result", return -1);
6071 /* Inputs for basic tests of binary operations on
6072 * isl_multi_union_pw_aff objects.
6073 * "fn" is the function that is tested.
6074 * "arg1" and "arg2" are string descriptions of the inputs.
6075 * "res" is a string description of the expected result.
6078 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6079 __isl_take isl_multi_union_pw_aff
*mupa1
,
6080 __isl_take isl_multi_union_pw_aff
*mupa2
);
6084 } mupa_bin_tests
[] = {
6085 { &isl_multi_union_pw_aff_add
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6086 "[{ A[] -> [3] }]" },
6087 { &isl_multi_union_pw_aff_sub
, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6088 "[{ A[] -> [-1] }]" },
6089 { &isl_multi_union_pw_aff_add
,
6090 "[{ A[] -> [1]; B[] -> [4] }]",
6091 "[{ A[] -> [2]; C[] -> [5] }]",
6092 "[{ A[] -> [3] }]" },
6093 { &isl_multi_union_pw_aff_union_add
,
6094 "[{ A[] -> [1]; B[] -> [4] }]",
6095 "[{ A[] -> [2]; C[] -> [5] }]",
6096 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
6097 { &isl_multi_union_pw_aff_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
6098 "[{ A[x] -> [(x)] : x <= 10 }]",
6099 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
6100 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
6101 "([] : { A[x] : x <= 10 })",
6102 "([] : { A[x] : 5 <= x <= 10 })" },
6103 { &isl_multi_union_pw_aff_add
, "([] : { A[x] : x >= 5 })",
6104 "[N] -> ([] : { A[x] : x <= N })",
6105 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
6106 { &isl_multi_union_pw_aff_add
, "[N] -> ([] : { A[x] : x >= N })",
6107 "([] : { A[x] : x <= 10 })",
6108 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
6109 { &isl_multi_union_pw_aff_union_add
, "[{ A[x] -> [(1)] : x >= 5 }]",
6110 "[{ A[x] -> [(x)] : x <= 10 }]",
6111 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
6112 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
6113 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 5 })",
6114 "([] : { A[x] : x <= 10 })",
6115 "([] : { A[x] })" },
6116 { &isl_multi_union_pw_aff_union_add
, "([] : { A[x] : x >= 0 })",
6117 "[N] -> ([] : { A[x] : x >= N })",
6118 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
6119 { &isl_multi_union_pw_aff_union_add
,
6120 "[N] -> ([] : { A[] : N >= 0})",
6121 "[N] -> ([] : { A[] : N <= 0})",
6122 "[N] -> ([] : { A[] })" },
6123 { &isl_multi_union_pw_aff_union_add
,
6124 "[N] -> ([] : { A[] })",
6125 "[N] -> ([] : { : })",
6126 "[N] -> ([] : { : })" },
6127 { &isl_multi_union_pw_aff_union_add
,
6128 "[N] -> ([] : { : })",
6129 "[N] -> ([] : { A[] })",
6130 "[N] -> ([] : { : })" },
6131 { &isl_multi_union_pw_aff_union_add
,
6132 "[N] -> ([] : { : N >= 0})",
6133 "[N] -> ([] : { : N <= 0})",
6134 "[N] -> ([] : { : })" },
6135 { &isl_multi_union_pw_aff_range_product
,
6136 "B[{ A[] -> [1] }]",
6137 "C[{ A[] -> [2] }]",
6138 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
6139 { &isl_multi_union_pw_aff_range_product
,
6140 "(B[] : { A[x] : x >= 5 })",
6141 "(C[] : { A[x] : x <= 10 })",
6142 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
6143 { &isl_multi_union_pw_aff_range_product
,
6144 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6145 "(C[] : { A[x] : x <= 10 })",
6146 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
6147 { &isl_multi_union_pw_aff_range_product
,
6148 "(C[] : { A[x] : x <= 10 })",
6149 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6150 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
6151 { &isl_multi_union_pw_aff_range_product
,
6152 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6153 "[N] -> (C[] : { A[x] : x <= N })",
6154 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
6155 { &isl_multi_union_pw_aff_range_product
,
6156 "[N] -> (C[] : { A[x] : x <= N })",
6157 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6158 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
6159 { &isl_multi_union_pw_aff_range_product
,
6160 "B[{ A[] -> [1]; D[] -> [3] }]",
6161 "C[{ A[] -> [2] }]",
6162 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
6163 { &isl_multi_union_pw_aff_range_product
,
6166 "([B[] -> C[]] : { A[x] })" },
6167 { &isl_multi_union_pw_aff_range_product
,
6170 "([B[] -> C[]] : { A[x] })" },
6173 /* Perform some basic tests of binary operations on
6174 * isl_multi_union_pw_aff objects.
6176 static int test_bin_mupa(isl_ctx
*ctx
)
6180 isl_multi_union_pw_aff
*mupa1
, *mupa2
, *res
;
6182 for (i
= 0; i
< ARRAY_SIZE(mupa_bin_tests
); ++i
) {
6183 mupa1
= isl_multi_union_pw_aff_read_from_str(ctx
,
6184 mupa_bin_tests
[i
].arg1
);
6185 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
,
6186 mupa_bin_tests
[i
].arg2
);
6187 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6188 mupa_bin_tests
[i
].res
);
6189 mupa1
= mupa_bin_tests
[i
].fn(mupa1
, mupa2
);
6190 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa1
, res
);
6191 isl_multi_union_pw_aff_free(mupa1
);
6192 isl_multi_union_pw_aff_free(res
);
6196 isl_die(ctx
, isl_error_unknown
,
6197 "unexpected result", return -1);
6203 /* Inputs for basic tests of binary operations on
6204 * pairs of isl_multi_union_pw_aff and isl_set objects.
6205 * "fn" is the function that is tested.
6206 * "arg1" and "arg2" are string descriptions of the inputs.
6207 * "res" is a string description of the expected result.
6210 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6211 __isl_take isl_multi_union_pw_aff
*mupa
,
6212 __isl_take isl_set
*set
);
6216 } mupa_set_tests
[] = {
6217 { &isl_multi_union_pw_aff_intersect_range
,
6218 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
6219 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
6220 { &isl_multi_union_pw_aff_intersect_range
,
6221 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
6222 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
6223 { &isl_multi_union_pw_aff_intersect_range
,
6224 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
6225 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
6226 { &isl_multi_union_pw_aff_intersect_range
,
6227 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
6228 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
6229 { &isl_multi_union_pw_aff_intersect_range
,
6230 "C[]", "{ C[] }", "C[]" },
6231 { &isl_multi_union_pw_aff_intersect_range
,
6232 "[N] -> (C[] : { : N >= 0 })",
6234 "[N] -> (C[] : { : N >= 0 })" },
6235 { &isl_multi_union_pw_aff_intersect_range
,
6236 "(C[] : { A[a,b] })",
6238 "(C[] : { A[a,b] })" },
6239 { &isl_multi_union_pw_aff_intersect_range
,
6240 "[N] -> (C[] : { A[a,b] : a,b <= N })",
6242 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
6243 { &isl_multi_union_pw_aff_intersect_range
,
6245 "[N] -> { C[] : N >= 0 }",
6246 "[N] -> (C[] : { : N >= 0 })" },
6247 { &isl_multi_union_pw_aff_intersect_range
,
6248 "(C[] : { A[a,b] })",
6249 "[N] -> { C[] : N >= 0 }",
6250 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6251 { &isl_multi_union_pw_aff_intersect_range
,
6252 "[N] -> (C[] : { : N >= 0 })",
6253 "[N] -> { C[] : N < 1024 }",
6254 "[N] -> (C[] : { : 0 <= N < 1024 })" },
6255 { &isl_multi_union_pw_aff_intersect_params
,
6256 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
6257 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
6258 { &isl_multi_union_pw_aff_intersect_params
,
6259 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
6260 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
6261 { &isl_multi_union_pw_aff_intersect_params
,
6262 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
6263 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
6264 { &isl_multi_union_pw_aff_intersect_params
,
6265 "C[]", "[N] -> { : N >= 0 }",
6266 "[N] -> (C[] : { : N >= 0 })" },
6267 { &isl_multi_union_pw_aff_intersect_params
,
6268 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
6269 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6270 { &isl_multi_union_pw_aff_intersect_params
,
6271 "[N] -> (C[] : { A[a,N] })", "{ : }",
6272 "[N] -> (C[] : { A[a,N] })" },
6273 { &isl_multi_union_pw_aff_intersect_params
,
6274 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
6275 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
6278 /* Perform some basic tests of binary operations on
6279 * pairs of isl_multi_union_pw_aff and isl_set objects.
6281 static int test_mupa_set(isl_ctx
*ctx
)
6285 isl_multi_union_pw_aff
*mupa
, *res
;
6288 for (i
= 0; i
< ARRAY_SIZE(mupa_set_tests
); ++i
) {
6289 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6290 mupa_set_tests
[i
].arg1
);
6291 set
= isl_set_read_from_str(ctx
, mupa_set_tests
[i
].arg2
);
6292 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6293 mupa_set_tests
[i
].res
);
6294 mupa
= mupa_set_tests
[i
].fn(mupa
, set
);
6295 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6296 isl_multi_union_pw_aff_free(mupa
);
6297 isl_multi_union_pw_aff_free(res
);
6301 isl_die(ctx
, isl_error_unknown
,
6302 "unexpected result", return -1);
6308 /* Inputs for basic tests of binary operations on
6309 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6310 * "fn" is the function that is tested.
6311 * "arg1" and "arg2" are string descriptions of the inputs.
6312 * "res" is a string description of the expected result.
6315 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6316 __isl_take isl_multi_union_pw_aff
*mupa
,
6317 __isl_take isl_union_set
*uset
);
6321 } mupa_uset_tests
[] = {
6322 { &isl_multi_union_pw_aff_intersect_domain
,
6323 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
6324 "C[{ B[i,i] -> [3i] }]" },
6325 { &isl_multi_union_pw_aff_intersect_domain
,
6326 "(C[] : { B[i,j] })", "{ B[i,i] }",
6327 "(C[] : { B[i,i] })" },
6328 { &isl_multi_union_pw_aff_intersect_domain
,
6329 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
6330 "[N] -> (C[] : { B[N,N] })" },
6331 { &isl_multi_union_pw_aff_intersect_domain
,
6332 "C[]", "{ B[i,i] }",
6333 "(C[] : { B[i,i] })" },
6334 { &isl_multi_union_pw_aff_intersect_domain
,
6335 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
6336 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
6339 /* Perform some basic tests of binary operations on
6340 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6342 static int test_mupa_uset(isl_ctx
*ctx
)
6346 isl_multi_union_pw_aff
*mupa
, *res
;
6347 isl_union_set
*uset
;
6349 for (i
= 0; i
< ARRAY_SIZE(mupa_uset_tests
); ++i
) {
6350 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6351 mupa_uset_tests
[i
].arg1
);
6352 uset
= isl_union_set_read_from_str(ctx
,
6353 mupa_uset_tests
[i
].arg2
);
6354 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6355 mupa_uset_tests
[i
].res
);
6356 mupa
= mupa_uset_tests
[i
].fn(mupa
, uset
);
6357 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6358 isl_multi_union_pw_aff_free(mupa
);
6359 isl_multi_union_pw_aff_free(res
);
6363 isl_die(ctx
, isl_error_unknown
,
6364 "unexpected result", return -1);
6370 /* Inputs for basic tests of binary operations on
6371 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6372 * "fn" is the function that is tested.
6373 * "arg1" and "arg2" are string descriptions of the inputs.
6374 * "res" is a string description of the expected result.
6377 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6378 __isl_take isl_multi_union_pw_aff
*mupa
,
6379 __isl_take isl_multi_aff
*ma
);
6383 } mupa_ma_tests
[] = {
6384 { &isl_multi_union_pw_aff_apply_multi_aff
,
6385 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6386 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6387 "{ C[a,b] -> D[b,a] }",
6388 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6389 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6390 { &isl_multi_union_pw_aff_apply_multi_aff
,
6391 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6392 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6393 "{ C[a,b] -> D[b,a] }",
6394 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6395 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6396 { &isl_multi_union_pw_aff_apply_multi_aff
,
6397 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6398 "[N] -> { C[a] -> D[a + N] }",
6399 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
6400 { &isl_multi_union_pw_aff_apply_multi_aff
,
6404 { &isl_multi_union_pw_aff_apply_multi_aff
,
6405 "[N] -> (C[] : { : N >= 0 })",
6407 "[N] -> (D[] : { : N >= 0 })" },
6408 { &isl_multi_union_pw_aff_apply_multi_aff
,
6410 "[N] -> { C[] -> D[N] }",
6411 "[N] -> D[{ [N] }]" },
6412 { &isl_multi_union_pw_aff_apply_multi_aff
,
6413 "(C[] : { A[i,j] : i >= j })",
6415 "(D[] : { A[i,j] : i >= j })" },
6416 { &isl_multi_union_pw_aff_apply_multi_aff
,
6417 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6419 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6420 { &isl_multi_union_pw_aff_apply_multi_aff
,
6421 "(C[] : { A[i,j] : i >= j })",
6422 "[N] -> { C[] -> D[N] }",
6423 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6426 /* Perform some basic tests of binary operations on
6427 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6429 static int test_mupa_ma(isl_ctx
*ctx
)
6433 isl_multi_union_pw_aff
*mupa
, *res
;
6436 for (i
= 0; i
< ARRAY_SIZE(mupa_ma_tests
); ++i
) {
6437 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6438 mupa_ma_tests
[i
].arg1
);
6439 ma
= isl_multi_aff_read_from_str(ctx
, mupa_ma_tests
[i
].arg2
);
6440 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6441 mupa_ma_tests
[i
].res
);
6442 mupa
= mupa_ma_tests
[i
].fn(mupa
, ma
);
6443 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6444 isl_multi_union_pw_aff_free(mupa
);
6445 isl_multi_union_pw_aff_free(res
);
6449 isl_die(ctx
, isl_error_unknown
,
6450 "unexpected result", return -1);
6456 /* Inputs for basic tests of binary operations on
6457 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6458 * "fn" is the function that is tested.
6459 * "arg1" and "arg2" are string descriptions of the inputs.
6460 * "res" is a string description of the expected result.
6463 __isl_give isl_union_pw_aff
*(*fn
)(
6464 __isl_take isl_multi_union_pw_aff
*mupa
,
6465 __isl_take isl_pw_aff
*pa
);
6469 } mupa_pa_tests
[] = {
6470 { &isl_multi_union_pw_aff_apply_pw_aff
,
6471 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6472 "[N] -> { C[a] -> [a + N] }",
6473 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
6474 { &isl_multi_union_pw_aff_apply_pw_aff
,
6475 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6476 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
6477 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6478 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
6479 { &isl_multi_union_pw_aff_apply_pw_aff
,
6481 "[N] -> { C[] -> [N] }",
6483 { &isl_multi_union_pw_aff_apply_pw_aff
,
6485 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6486 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
6487 { &isl_multi_union_pw_aff_apply_pw_aff
,
6488 "[N] -> (C[] : { : N >= 0 })",
6489 "[N] -> { C[] -> [N] }",
6490 "[N] -> { [N] : N >= 0 }" },
6491 { &isl_multi_union_pw_aff_apply_pw_aff
,
6492 "[N] -> (C[] : { : N >= 0 })",
6493 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6494 "[N] -> { [N] : N >= 0 }" },
6495 { &isl_multi_union_pw_aff_apply_pw_aff
,
6496 "[N] -> (C[] : { : N >= 0 })",
6498 "[N] -> { [0] : N >= 0 }" },
6499 { &isl_multi_union_pw_aff_apply_pw_aff
,
6500 "(C[] : { A[i,j] : i >= j })",
6501 "[N] -> { C[] -> [N] }",
6502 "[N] -> { A[i,j] -> [N] : i >= j }" },
6503 { &isl_multi_union_pw_aff_apply_pw_aff
,
6504 "(C[] : { A[i,j] : i >= j })",
6505 "[N] -> { C[] -> [N] : N >= 0 }",
6506 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6509 /* Perform some basic tests of binary operations on
6510 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6512 static int test_mupa_pa(isl_ctx
*ctx
)
6516 isl_multi_union_pw_aff
*mupa
;
6517 isl_union_pw_aff
*upa
, *res
;
6520 for (i
= 0; i
< ARRAY_SIZE(mupa_pa_tests
); ++i
) {
6521 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6522 mupa_pa_tests
[i
].arg1
);
6523 pa
= isl_pw_aff_read_from_str(ctx
, mupa_pa_tests
[i
].arg2
);
6524 res
= isl_union_pw_aff_read_from_str(ctx
,
6525 mupa_pa_tests
[i
].res
);
6526 upa
= mupa_pa_tests
[i
].fn(mupa
, pa
);
6527 ok
= isl_union_pw_aff_plain_is_equal(upa
, res
);
6528 isl_union_pw_aff_free(upa
);
6529 isl_union_pw_aff_free(res
);
6533 isl_die(ctx
, isl_error_unknown
,
6534 "unexpected result", return -1);
6540 /* Inputs for basic tests of binary operations on
6541 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6542 * "fn" is the function that is tested.
6543 * "arg1" and "arg2" are string descriptions of the inputs.
6544 * "res" is a string description of the expected result.
6547 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6548 __isl_take isl_multi_union_pw_aff
*mupa
,
6549 __isl_take isl_pw_multi_aff
*pma
);
6553 } mupa_pma_tests
[] = {
6554 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6555 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6556 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6557 "{ C[a,b] -> D[b,a] }",
6558 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6559 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6560 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6561 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6562 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6563 "{ C[a,b] -> D[b,a] }",
6564 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6565 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6566 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6567 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6568 "[N] -> { C[a] -> D[a + N] }",
6569 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6570 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6571 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6572 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6573 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6574 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6575 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6576 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6577 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6578 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6579 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6580 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6581 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6582 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6583 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6587 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6588 "[N] -> (C[] : { : N >= 0 })",
6590 "[N] -> (D[] : { : N >= 0 })" },
6591 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6593 "[N] -> { C[] -> D[N] }",
6594 "[N] -> D[{ [N] }]" },
6595 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6596 "(C[] : { A[i,j] : i >= j })",
6598 "(D[] : { A[i,j] : i >= j })" },
6599 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6600 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6602 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6603 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6604 "(C[] : { A[i,j] : i >= j })",
6605 "[N] -> { C[] -> D[N] }",
6606 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6607 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6609 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6610 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6611 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6612 "[N] -> (C[] : { : N >= 0 })",
6613 "[N] -> { C[] -> D[N] }",
6614 "[N] -> D[{ [N] : N >= 0 }]" },
6615 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6616 "[N] -> (C[] : { : N >= 0 })",
6617 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6618 "[N] -> D[{ [N] : N >= 0 }]" },
6619 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6620 "[N] -> (C[] : { : N >= 0 })",
6622 "[N] -> D[{ [0] : N >= 0 }]" },
6623 { &isl_multi_union_pw_aff_apply_pw_multi_aff
,
6624 "(C[] : { A[i,j] : i >= j })",
6625 "[N] -> { C[] -> D[N] : N >= 0 }",
6626 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6629 /* Perform some basic tests of binary operations on
6630 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6632 static int test_mupa_pma(isl_ctx
*ctx
)
6636 isl_multi_union_pw_aff
*mupa
, *res
;
6637 isl_pw_multi_aff
*pma
;
6639 for (i
= 0; i
< ARRAY_SIZE(mupa_pma_tests
); ++i
) {
6640 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6641 mupa_pma_tests
[i
].arg1
);
6642 pma
= isl_pw_multi_aff_read_from_str(ctx
,
6643 mupa_pma_tests
[i
].arg2
);
6644 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6645 mupa_pma_tests
[i
].res
);
6646 mupa
= mupa_pma_tests
[i
].fn(mupa
, pma
);
6647 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6648 isl_multi_union_pw_aff_free(mupa
);
6649 isl_multi_union_pw_aff_free(res
);
6653 isl_die(ctx
, isl_error_unknown
,
6654 "unexpected result", return -1);
6660 /* Inputs for basic tests of binary operations on
6661 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6662 * "fn" is the function that is tested.
6663 * "arg1" and "arg2" are string descriptions of the inputs.
6664 * "res" is a string description of the expected result.
6667 __isl_give isl_multi_union_pw_aff
*(*fn
)(
6668 __isl_take isl_multi_union_pw_aff
*mupa
,
6669 __isl_take isl_union_pw_multi_aff
*upma
);
6673 } mupa_upma_tests
[] = {
6674 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6675 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6676 "C[{ A[a,b] -> [b + 2a] }]" },
6677 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6678 "C[{ B[i,j] -> [i + 2j] }]",
6679 "{ A[a,b] -> B[b,a] : b > a }",
6680 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6681 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6682 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6683 "{ A[a,b] -> B[b,a] : b > a }",
6684 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6685 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6686 "C[{ B[i,j] -> [i + 2j] }]",
6687 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6688 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6689 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6690 "(C[] : { B[a,b] })",
6691 "{ A[a,b] -> B[b,a] }",
6692 "(C[] : { A[a,b] })" },
6693 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6694 "(C[] : { B[a,b] })",
6695 "{ B[a,b] -> A[b,a] }",
6697 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6698 "(C[] : { B[a,b] })",
6699 "{ A[a,b] -> B[b,a] : a > b }",
6700 "(C[] : { A[a,b] : a > b })" },
6701 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6702 "(C[] : { B[a,b] : a > b })",
6703 "{ A[a,b] -> B[b,a] }",
6704 "(C[] : { A[a,b] : b > a })" },
6705 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6706 "[N] -> (C[] : { B[a,b] : a > N })",
6707 "{ A[a,b] -> B[b,a] : a > b }",
6708 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6709 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6710 "(C[] : { B[a,b] : a > b })",
6711 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6712 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6713 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6715 "{ A[a,b] -> B[b,a] }",
6717 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6718 "[N] -> (C[] : { : N >= 0 })",
6719 "{ A[a,b] -> B[b,a] }",
6720 "[N] -> (C[] : { : N >= 0 })" },
6721 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff
,
6723 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6724 "[N] -> (C[] : { : N >= 0 })" },
6727 /* Perform some basic tests of binary operations on
6728 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6730 static int test_mupa_upma(isl_ctx
*ctx
)
6734 isl_multi_union_pw_aff
*mupa
, *res
;
6735 isl_union_pw_multi_aff
*upma
;
6737 for (i
= 0; i
< ARRAY_SIZE(mupa_upma_tests
); ++i
) {
6738 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
6739 mupa_upma_tests
[i
].arg1
);
6740 upma
= isl_union_pw_multi_aff_read_from_str(ctx
,
6741 mupa_upma_tests
[i
].arg2
);
6742 res
= isl_multi_union_pw_aff_read_from_str(ctx
,
6743 mupa_upma_tests
[i
].res
);
6744 mupa
= mupa_upma_tests
[i
].fn(mupa
, upma
);
6745 ok
= isl_multi_union_pw_aff_plain_is_equal(mupa
, res
);
6746 isl_multi_union_pw_aff_free(mupa
);
6747 isl_multi_union_pw_aff_free(res
);
6751 isl_die(ctx
, isl_error_unknown
,
6752 "unexpected result", return -1);
6758 /* Check that the input tuple of an isl_aff can be set properly.
6760 static isl_stat
test_aff_set_tuple_id(isl_ctx
*ctx
)
6766 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x + 1] }");
6767 id
= isl_id_alloc(ctx
, "A", NULL
);
6768 aff
= isl_aff_set_tuple_id(aff
, isl_dim_in
, id
);
6769 equal
= aff_check_plain_equal(aff
, "{ A[x] -> [x + 1] }");
6772 return isl_stat_error
;
6777 /* Check that affine expressions get normalized on addition/subtraction.
6778 * In particular, check that (final) unused integer divisions get removed
6779 * such that an expression derived from expressions with integer divisions
6780 * is found to be obviously equal to one that is created directly.
6782 static isl_stat
test_aff_normalize(isl_ctx
*ctx
)
6784 isl_aff
*aff
, *aff2
;
6787 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x//2] }");
6788 aff2
= isl_aff_read_from_str(ctx
, "{ [x] -> [1 + x//2] }");
6789 aff
= isl_aff_sub(aff2
, aff
);
6790 ok
= aff_check_plain_equal(aff
, "{ [x] -> [1] }");
6796 int test_aff(isl_ctx
*ctx
)
6801 isl_local_space
*ls
;
6806 if (test_upa(ctx
) < 0)
6808 if (test_bin_aff(ctx
) < 0)
6810 if (test_bin_pw_aff(ctx
) < 0)
6812 if (test_upma_test(ctx
) < 0)
6814 if (test_bin_upma(ctx
) < 0)
6816 if (test_bin_upma_fail(ctx
) < 0)
6818 if (test_upma_uset(ctx
) < 0)
6820 if (test_un_mpa(ctx
) < 0)
6822 if (test_bin_mpa(ctx
) < 0)
6824 if (test_un_mupa(ctx
) < 0)
6826 if (test_bin_mupa(ctx
) < 0)
6828 if (test_mupa_set(ctx
) < 0)
6830 if (test_mupa_uset(ctx
) < 0)
6832 if (test_mupa_ma(ctx
) < 0)
6834 if (test_mupa_pa(ctx
) < 0)
6836 if (test_mupa_pma(ctx
) < 0)
6838 if (test_mupa_upma(ctx
) < 0)
6841 space
= isl_space_set_alloc(ctx
, 0, 1);
6842 ls
= isl_local_space_from_space(space
);
6843 aff
= isl_aff_zero_on_domain(ls
);
6845 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6846 aff
= isl_aff_scale_down_ui(aff
, 3);
6847 aff
= isl_aff_floor(aff
);
6848 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6849 aff
= isl_aff_scale_down_ui(aff
, 2);
6850 aff
= isl_aff_floor(aff
);
6851 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
6854 set
= isl_set_read_from_str(ctx
, str
);
6855 aff
= isl_aff_gist(aff
, set
);
6857 aff
= isl_aff_add_constant_si(aff
, -16);
6858 zero
= isl_aff_plain_is_zero(aff
);
6864 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
6866 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
6867 aff
= isl_aff_scale_down_ui(aff
, 64);
6868 aff
= isl_aff_floor(aff
);
6869 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
6874 if (test_aff_set_tuple_id(ctx
) < 0)
6876 if (test_aff_normalize(ctx
) < 0)
6882 /* Inputs for isl_set_bind tests.
6883 * "set" is the input set.
6884 * "tuple" is the binding tuple.
6885 * "res" is the expected result.
6892 } bind_set_tests
[] = {
6893 { "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6895 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6896 { "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }",
6898 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6899 { "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }",
6901 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6902 { "[M] -> { D[x, N] : x mod 2 = 0 and N mod 8 = 3 and M >= 0 }",
6904 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 and M >= 0 }" },
6907 /* Perform basic isl_set_bind tests.
6909 static isl_stat
test_bind_set(isl_ctx
*ctx
)
6913 for (i
= 0; i
< ARRAY_SIZE(bind_set_tests
); ++i
) {
6916 isl_multi_id
*tuple
;
6919 set
= isl_set_read_from_str(ctx
, bind_set_tests
[i
].set
);
6920 str
= bind_set_tests
[i
].tuple
;
6921 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6922 set
= isl_set_bind(set
, tuple
);
6923 r
= set_check_equal(set
, bind_set_tests
[i
].res
);
6926 return isl_stat_error
;
6932 /* Inputs for isl_map_bind_domain tests.
6933 * "map" is the input map.
6934 * "tuple" is the binding tuple.
6935 * "res" is the expected result.
6941 } bind_map_domain_tests
[] = {
6942 { "{ A[M, N] -> [M + floor(N/2)] }",
6944 "[M, N] -> { [M + floor(N/2)] }" },
6945 { "{ B[N, M] -> [M + floor(N/2)] }",
6947 "[N, M] -> { [M + floor(N/2)] }" },
6948 { "[M] -> { C[N] -> [M + floor(N/2)] }",
6950 "[M, N] -> { [M + floor(N/2)] }" },
6951 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
6953 "[M, N] -> { [M + floor(N/2)] }" },
6954 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
6956 "[M, N] -> { [M + floor(N/2)] }" },
6957 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
6959 "[A, N, M] -> { [M + floor(N/2)] }" },
6962 /* Perform basic isl_map_bind_domain tests.
6964 static isl_stat
test_bind_map_domain(isl_ctx
*ctx
)
6968 for (i
= 0; i
< ARRAY_SIZE(bind_map_domain_tests
); ++i
) {
6972 isl_multi_id
*tuple
;
6975 str
= bind_map_domain_tests
[i
].map
;
6976 map
= isl_map_read_from_str(ctx
, str
);
6977 str
= bind_map_domain_tests
[i
].tuple
;
6978 tuple
= isl_multi_id_read_from_str(ctx
, str
);
6979 set
= isl_map_bind_domain(map
, tuple
);
6980 str
= bind_map_domain_tests
[i
].res
;
6981 r
= set_check_equal(set
, str
);
6984 return isl_stat_error
;
6990 /* Inputs for isl_union_map_bind_range tests.
6991 * "map" is the input union map.
6992 * "tuple" is the binding tuple.
6993 * "res" is the expected result.
6999 } bind_umap_range_tests
[] = {
7000 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
7002 "[M, N] -> { B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7003 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
7006 { "{ A[] -> B[]; C[] -> D[]; E[] -> B[] }",
7011 /* Perform basic isl_union_map_bind_range tests.
7013 static isl_stat
test_bind_umap_range(isl_ctx
*ctx
)
7017 for (i
= 0; i
< ARRAY_SIZE(bind_umap_range_tests
); ++i
) {
7019 isl_union_map
*umap
;
7020 isl_union_set
*uset
;
7021 isl_multi_id
*tuple
;
7024 str
= bind_umap_range_tests
[i
].map
;
7025 umap
= isl_union_map_read_from_str(ctx
, str
);
7026 str
= bind_umap_range_tests
[i
].tuple
;
7027 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7028 uset
= isl_union_map_bind_range(umap
, tuple
);
7029 str
= bind_umap_range_tests
[i
].res
;
7030 r
= uset_check_equal(uset
, str
);
7031 isl_union_set_free(uset
);
7033 return isl_stat_error
;
7039 /* Inputs for isl_pw_multi_aff_bind_domain tests.
7040 * "pma" is the input expression.
7041 * "tuple" is the binding tuple.
7042 * "res" is the expected result.
7048 } bind_pma_domain_tests
[] = {
7049 { "{ A[M, N] -> [M + floor(N/2)] }",
7051 "[M, N] -> { [M + floor(N/2)] }" },
7052 { "{ B[N, M] -> [M + floor(N/2)] }",
7054 "[N, M] -> { [M + floor(N/2)] }" },
7055 { "[M] -> { C[N] -> [M + floor(N/2)] }",
7057 "[M, N] -> { [M + floor(N/2)] }" },
7058 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
7060 "[M, N] -> { [M + floor(N/2)] }" },
7061 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
7063 "[M, N] -> { [M + floor(N/2)] }" },
7064 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
7066 "[A, N, M] -> { [M + floor(N/2)] }" },
7069 /* Perform basic isl_pw_multi_aff_bind_domain tests.
7071 static isl_stat
test_bind_pma_domain(isl_ctx
*ctx
)
7075 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_tests
); ++i
) {
7077 isl_pw_multi_aff
*pma
;
7078 isl_multi_id
*tuple
;
7081 str
= bind_pma_domain_tests
[i
].pma
;
7082 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7083 str
= bind_pma_domain_tests
[i
].tuple
;
7084 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7085 pma
= isl_pw_multi_aff_bind_domain(pma
, tuple
);
7086 str
= bind_pma_domain_tests
[i
].res
;
7087 r
= pw_multi_aff_check_plain_equal(pma
, str
);
7088 isl_pw_multi_aff_free(pma
);
7090 return isl_stat_error
;
7096 /* Inputs for isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7097 * "pma" is the input expression.
7098 * "tuple" is the binding tuple.
7099 * "res" is the expected result.
7105 } bind_pma_domain_wrapped_tests
[] = {
7106 { "{ [A[M, N] -> B[]] -> [M + floor(N/2)] }",
7108 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7109 { "{ [B[N, M] -> D[]] -> [M + floor(N/2)] }",
7111 "[N, M] -> { D[] -> [M + floor(N/2)] }" },
7112 { "[M] -> { [C[N] -> B[x]] -> [x + M + floor(N/2)] }",
7114 "[M, N] -> { B[x] -> [x + M + floor(N/2)] }" },
7115 { "[M] -> { [C[x, N] -> B[]] -> [x + floor(N/2)] }",
7117 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7118 { "[M] -> { [C[x, N] -> B[]] -> [M + floor(N/2)] }",
7120 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7121 { "[A, M] -> { [C[N, x] -> B[]] -> [x + floor(N/2)] }",
7123 "[A, N, M] -> { B[] -> [M + floor(N/2)] }" },
7126 /* Perform basic isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7128 static isl_stat
test_bind_pma_domain_wrapped(isl_ctx
*ctx
)
7132 for (i
= 0; i
< ARRAY_SIZE(bind_pma_domain_wrapped_tests
); ++i
) {
7134 isl_pw_multi_aff
*pma
;
7135 isl_multi_id
*tuple
;
7138 str
= bind_pma_domain_wrapped_tests
[i
].pma
;
7139 pma
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7140 str
= bind_pma_domain_wrapped_tests
[i
].tuple
;
7141 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7142 pma
= isl_pw_multi_aff_bind_domain_wrapped_domain(pma
, tuple
);
7143 str
= bind_pma_domain_wrapped_tests
[i
].res
;
7144 r
= pw_multi_aff_check_plain_equal(pma
, str
);
7145 isl_pw_multi_aff_free(pma
);
7147 return isl_stat_error
;
7153 /* Inputs for isl_aff_bind_id tests.
7154 * "aff" is the input expression.
7155 * "id" is the binding id.
7156 * "res" is the expected result.
7163 } bind_aff_tests
[] = {
7164 { "{ [4] }", "M", "[M = 4] -> { : }" },
7165 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7166 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7167 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7168 { "{ [NaN] }", "M", "{ : false }" },
7169 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7172 /* Perform basic isl_aff_bind_id tests.
7174 static isl_stat
test_bind_aff(isl_ctx
*ctx
)
7178 for (i
= 0; i
< ARRAY_SIZE(bind_aff_tests
); ++i
) {
7184 aff
= isl_aff_read_from_str(ctx
, bind_aff_tests
[i
].aff
);
7185 id
= isl_id_read_from_str(ctx
, bind_aff_tests
[i
].id
);
7186 res
= isl_set_from_basic_set(isl_aff_bind_id(aff
, id
));
7187 r
= set_check_equal(res
, bind_aff_tests
[i
].res
);
7190 return isl_stat_error
;
7196 /* Inputs for isl_pw_aff_bind_id tests.
7197 * "pa" is the input expression.
7198 * "id" is the binding id.
7199 * "res" is the expected result.
7206 } bind_pa_tests
[] = {
7207 { "{ [4] }", "M", "[M = 4] -> { : }" },
7208 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7209 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7210 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7211 { "[M] -> { [M] : M >= 0; [-M] : M < 0 }", "M", "[M] -> { : M >= 0 }" },
7212 { "{ [NaN] }", "M", "{ : false }" },
7213 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7216 /* Perform basic isl_pw_aff_bind_id tests.
7218 static isl_stat
test_bind_pa(isl_ctx
*ctx
)
7222 for (i
= 0; i
< ARRAY_SIZE(bind_pa_tests
); ++i
) {
7228 pa
= isl_pw_aff_read_from_str(ctx
, bind_pa_tests
[i
].pa
);
7229 id
= isl_id_read_from_str(ctx
, bind_pa_tests
[i
].id
);
7230 res
= isl_pw_aff_bind_id(pa
, id
);
7231 r
= set_check_equal(res
, bind_pa_tests
[i
].res
);
7234 return isl_stat_error
;
7240 /* Inputs for isl_multi_union_pw_aff_bind tests.
7241 * "mupa" is the input expression.
7242 * "tuple" is the binding tuple.
7243 * "res" is the expected result.
7250 } bind_mupa_tests
[] = {
7251 { "A[{ [4] }, { [5] }]",
7253 "[M = 4, N = 5] -> { : }" },
7254 { "A[{ B[x] -> [floor(x/2)] }, { B[y] -> [y + 5] }]",
7256 "[M, N] -> { B[x] : M = floor(x/2) and N = x + 5 }" },
7257 { "[M] -> A[{ [4] }, { [M + 1] }]",
7259 "[M = 4, N = 5] -> { : }" },
7262 /* Perform basic isl_multi_union_pw_aff_bind tests.
7264 static isl_stat
test_bind_mupa(isl_ctx
*ctx
)
7268 for (i
= 0; i
< ARRAY_SIZE(bind_mupa_tests
); ++i
) {
7270 isl_multi_union_pw_aff
*mupa
;
7272 isl_multi_id
*tuple
;
7275 str
= bind_mupa_tests
[i
].mupa
;
7276 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
7277 str
= bind_mupa_tests
[i
].tuple
;
7278 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7279 res
= isl_multi_union_pw_aff_bind(mupa
, tuple
);
7280 r
= uset_check_equal(res
, bind_mupa_tests
[i
].res
);
7281 isl_union_set_free(res
);
7283 return isl_stat_error
;
7289 /* Perform tests that reinterpret dimensions as parameters.
7291 static int test_bind(isl_ctx
*ctx
)
7293 if (test_bind_set(ctx
) < 0)
7295 if (test_bind_map_domain(ctx
) < 0)
7297 if (test_bind_umap_range(ctx
) < 0)
7299 if (test_bind_pma_domain(ctx
) < 0)
7301 if (test_bind_pma_domain_wrapped(ctx
) < 0)
7303 if (test_bind_aff(ctx
) < 0)
7305 if (test_bind_pa(ctx
) < 0)
7307 if (test_bind_mupa(ctx
) < 0)
7313 /* Inputs for isl_set_unbind_params tests.
7314 * "set" is the input parameter domain.
7315 * "tuple" is the tuple of the constructed set.
7316 * "res" is the expected result.
7322 } unbind_set_tests
[] = {
7323 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7325 "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7326 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7328 "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7329 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7331 "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }" },
7332 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7334 "[M] -> { D[x, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7337 /* Perform basic isl_set_unbind_params tests.
7339 static isl_stat
test_unbind_set(isl_ctx
*ctx
)
7343 for (i
= 0; i
< ARRAY_SIZE(unbind_set_tests
); ++i
) {
7346 isl_multi_id
*tuple
;
7349 set
= isl_set_read_from_str(ctx
, unbind_set_tests
[i
].set
);
7350 str
= unbind_set_tests
[i
].tuple
;
7351 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7352 set
= isl_set_unbind_params(set
, tuple
);
7353 r
= set_check_equal(set
, unbind_set_tests
[i
].res
);
7356 return isl_stat_error
;
7362 /* Inputs for isl_aff_unbind_params_insert_domain tests.
7363 * "aff" is the input affine expression defined over a parameter domain.
7364 * "tuple" is the tuple of the domain that gets introduced.
7365 * "res" is the expected result.
7371 } unbind_aff_tests
[] = {
7372 { "[M, N] -> { [M + floor(N/2)] }",
7374 "{ A[M, N] -> [M + floor(N/2)] }" },
7375 { "[M, N] -> { [M + floor(N/2)] }",
7377 "{ B[N, M] -> [M + floor(N/2)] }" },
7378 { "[M, N] -> { [M + floor(N/2)] }",
7380 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7381 { "[M, N] -> { [M + floor(N/2)] }",
7382 "{ D[A, B, C, N, Z] }",
7383 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7386 /* Perform basic isl_aff_unbind_params_insert_domain tests.
7388 static isl_stat
test_unbind_aff(isl_ctx
*ctx
)
7392 for (i
= 0; i
< ARRAY_SIZE(unbind_aff_tests
); ++i
) {
7395 isl_multi_id
*tuple
;
7398 aff
= isl_aff_read_from_str(ctx
, unbind_aff_tests
[i
].aff
);
7399 str
= unbind_aff_tests
[i
].tuple
;
7400 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7401 aff
= isl_aff_unbind_params_insert_domain(aff
, tuple
);
7402 r
= aff_check_plain_equal(aff
, unbind_aff_tests
[i
].res
);
7405 return isl_stat_error
;
7411 /* Inputs for isl_multi_aff_unbind_params_insert_domain tests.
7412 * "ma" is the input multi affine expression defined over a parameter domain.
7413 * "tuple" is the tuple of the domain that gets introduced.
7414 * "res" is the expected result.
7420 } unbind_multi_aff_tests
[] = {
7421 { "[M, N] -> { T[M + floor(N/2)] }",
7423 "{ A[M, N] -> T[M + floor(N/2)] }" },
7424 { "[M, N] -> { [M + floor(N/2)] }",
7426 "{ B[N, M] -> [M + floor(N/2)] }" },
7427 { "[M, N] -> { [M + floor(N/2)] }",
7429 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7430 { "[M, N] -> { [M + floor(N/2)] }",
7431 "{ D[A, B, C, N, Z] }",
7432 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7433 { "[M, N] -> { T[M + floor(N/2), N + floor(M/3)] }",
7435 "{ A[M, N] -> T[M + floor(N/2), N + floor(M/3)] }" },
7438 /* Perform basic isl_multi_aff_unbind_params_insert_domain tests.
7440 static isl_stat
test_unbind_multi_aff(isl_ctx
*ctx
)
7444 for (i
= 0; i
< ARRAY_SIZE(unbind_multi_aff_tests
); ++i
) {
7447 isl_multi_id
*tuple
;
7450 str
= unbind_multi_aff_tests
[i
].ma
;
7451 ma
= isl_multi_aff_read_from_str(ctx
, str
);
7452 str
= unbind_multi_aff_tests
[i
].tuple
;
7453 tuple
= isl_multi_id_read_from_str(ctx
, str
);
7454 ma
= isl_multi_aff_unbind_params_insert_domain(ma
, tuple
);
7455 str
= unbind_multi_aff_tests
[i
].res
;
7456 r
= multi_aff_check_plain_equal(ma
, str
);
7457 isl_multi_aff_free(ma
);
7459 return isl_stat_error
;
7465 /* Perform tests that reinterpret parameters.
7467 static int test_unbind(isl_ctx
*ctx
)
7469 if (test_unbind_set(ctx
) < 0)
7471 if (test_unbind_aff(ctx
) < 0)
7473 if (test_unbind_multi_aff(ctx
) < 0)
7479 /* Check that "pa" consists of a single expression.
7481 static int check_single_piece(isl_ctx
*ctx
, __isl_take isl_pw_aff
*pa
)
7485 n
= isl_pw_aff_n_piece(pa
);
7486 isl_pw_aff_free(pa
);
7491 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
7497 /* Check that the computation below results in a single expression.
7498 * One or two expressions may result depending on which constraint
7499 * ends up being considered as redundant with respect to the other
7500 * constraints after the projection that is performed internally
7501 * by isl_set_dim_min.
7503 static int test_dim_max_1(isl_ctx
*ctx
)
7509 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
7510 "-4a <= b <= 3 and b < n - 4a }";
7511 set
= isl_set_read_from_str(ctx
, str
);
7512 pa
= isl_set_dim_min(set
, 0);
7513 return check_single_piece(ctx
, pa
);
7516 /* Check that the computation below results in a single expression.
7517 * The PIP problem corresponding to these constraints has a row
7518 * that causes a split of the solution domain. The solver should
7519 * first pick rows that split off empty parts such that the actual
7520 * solution domain does not get split.
7521 * Note that the description contains some redundant constraints.
7522 * If these constraints get removed first, then the row mentioned
7523 * above does not appear in the PIP problem.
7525 static int test_dim_max_2(isl_ctx
*ctx
)
7531 str
= "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
7532 "N > 0 and P >= 0 }";
7533 set
= isl_set_read_from_str(ctx
, str
);
7534 pa
= isl_set_dim_max(set
, 0);
7535 return check_single_piece(ctx
, pa
);
7538 int test_dim_max(isl_ctx
*ctx
)
7542 isl_set
*set1
, *set2
;
7547 if (test_dim_max_1(ctx
) < 0)
7549 if (test_dim_max_2(ctx
) < 0)
7552 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
7553 set
= isl_set_read_from_str(ctx
, str
);
7554 pwaff
= isl_set_dim_max(set
, 0);
7555 set1
= isl_set_from_pw_aff(pwaff
);
7556 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
7557 set2
= isl_set_read_from_str(ctx
, str
);
7558 equal
= isl_set_is_equal(set1
, set2
);
7564 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7566 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
7567 set
= isl_set_read_from_str(ctx
, str
);
7568 pwaff
= isl_set_dim_max(set
, 0);
7569 set1
= isl_set_from_pw_aff(pwaff
);
7570 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7571 set2
= isl_set_read_from_str(ctx
, str
);
7572 equal
= isl_set_is_equal(set1
, set2
);
7578 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7580 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
7581 set
= isl_set_read_from_str(ctx
, str
);
7582 pwaff
= isl_set_dim_max(set
, 0);
7583 set1
= isl_set_from_pw_aff(pwaff
);
7584 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7585 set2
= isl_set_read_from_str(ctx
, str
);
7586 equal
= isl_set_is_equal(set1
, set2
);
7592 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7594 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
7595 "0 <= i < N and 0 <= j < M }";
7596 map
= isl_map_read_from_str(ctx
, str
);
7597 set
= isl_map_range(map
);
7599 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
7600 set1
= isl_set_from_pw_aff(pwaff
);
7601 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
7602 set2
= isl_set_read_from_str(ctx
, str
);
7603 equal
= isl_set_is_equal(set1
, set2
);
7607 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
7608 set1
= isl_set_from_pw_aff(pwaff
);
7609 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
7610 set2
= isl_set_read_from_str(ctx
, str
);
7611 if (equal
>= 0 && equal
)
7612 equal
= isl_set_is_equal(set1
, set2
);
7621 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7623 /* Check that solutions are properly merged. */
7624 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
7625 "c <= -1 + n - 4a - 2b and c >= -2b and "
7626 "4a >= -4 + n and c >= 0 }";
7627 set
= isl_set_read_from_str(ctx
, str
);
7628 pwaff
= isl_set_dim_min(set
, 2);
7629 set1
= isl_set_from_pw_aff(pwaff
);
7630 str
= "[n] -> { [(0)] : n >= 1 }";
7631 set2
= isl_set_read_from_str(ctx
, str
);
7632 equal
= isl_set_is_equal(set1
, set2
);
7639 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7641 /* Check that empty solution lie in the right space. */
7642 str
= "[n] -> { [t,a] : 1 = 0 }";
7643 set
= isl_set_read_from_str(ctx
, str
);
7644 pwaff
= isl_set_dim_max(set
, 0);
7645 set1
= isl_set_from_pw_aff(pwaff
);
7646 str
= "[n] -> { [t] : 1 = 0 }";
7647 set2
= isl_set_read_from_str(ctx
, str
);
7648 equal
= isl_set_is_equal(set1
, set2
);
7655 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7660 /* Basic test for isl_pw_multi_aff_product.
7662 * Check that multiple pieces are properly handled.
7664 static int test_product_pma(isl_ctx
*ctx
)
7668 isl_pw_multi_aff
*pma1
, *pma2
;
7670 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
7671 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7672 str
= "{ C[] -> D[] }";
7673 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
7674 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
7675 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
7676 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
7677 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
7678 isl_pw_multi_aff_free(pma1
);
7685 int test_product(isl_ctx
*ctx
)
7689 isl_union_set
*uset1
, *uset2
;
7693 set
= isl_set_read_from_str(ctx
, str
);
7694 set
= isl_set_product(set
, isl_set_copy(set
));
7695 ok
= isl_set_is_wrapping(set
);
7700 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7703 uset1
= isl_union_set_read_from_str(ctx
, str
);
7704 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
7705 str
= "{ [[] -> []] }";
7706 uset2
= isl_union_set_read_from_str(ctx
, str
);
7707 ok
= isl_union_set_is_equal(uset1
, uset2
);
7708 isl_union_set_free(uset1
);
7709 isl_union_set_free(uset2
);
7713 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7715 if (test_product_pma(ctx
) < 0)
7721 /* Check that two sets are not considered disjoint just because
7722 * they have a different set of (named) parameters.
7724 static int test_disjoint(isl_ctx
*ctx
)
7727 isl_set
*set
, *set2
;
7730 str
= "[n] -> { [[]->[]] }";
7731 set
= isl_set_read_from_str(ctx
, str
);
7732 str
= "{ [[]->[]] }";
7733 set2
= isl_set_read_from_str(ctx
, str
);
7734 disjoint
= isl_set_is_disjoint(set
, set2
);
7740 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7745 /* Inputs for isl_pw_multi_aff_is_equal tests.
7746 * "f1" and "f2" are the two function that need to be compared.
7747 * "equal" is the expected result.
7753 } pma_equal_tests
[] = {
7754 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
7755 "[N] -> { [0] : 0 <= N <= 1 }" },
7756 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7757 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
7758 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7759 "[N] -> { [0] : 0 <= N <= 1 }" },
7760 { 0, "{ [NaN] }", "{ [NaN] }" },
7763 int test_equal(isl_ctx
*ctx
)
7767 isl_set
*set
, *set2
;
7771 set
= isl_set_read_from_str(ctx
, str
);
7773 set2
= isl_set_read_from_str(ctx
, str
);
7774 equal
= isl_set_is_equal(set
, set2
);
7780 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
7782 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
7783 int expected
= pma_equal_tests
[i
].equal
;
7784 isl_pw_multi_aff
*f1
, *f2
;
7786 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
7787 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
7788 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
7789 isl_pw_multi_aff_free(f1
);
7790 isl_pw_multi_aff_free(f2
);
7793 if (equal
!= expected
)
7794 isl_die(ctx
, isl_error_unknown
,
7795 "unexpected equality result", return -1);
7801 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
7802 enum isl_dim_type type
, unsigned pos
, int fixed
)
7806 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
7813 isl_die(ctx
, isl_error_unknown
,
7814 "map not detected as fixed", return -1);
7816 isl_die(ctx
, isl_error_unknown
,
7817 "map detected as fixed", return -1);
7820 int test_fixed(isl_ctx
*ctx
)
7825 str
= "{ [i] -> [i] }";
7826 map
= isl_map_read_from_str(ctx
, str
);
7827 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
7829 str
= "{ [i] -> [1] }";
7830 map
= isl_map_read_from_str(ctx
, str
);
7831 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7833 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
7834 map
= isl_map_read_from_str(ctx
, str
);
7835 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7837 map
= isl_map_read_from_str(ctx
, str
);
7838 map
= isl_map_neg(map
);
7839 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
7845 struct isl_vertices_test_data
{
7848 const char *vertex
[6];
7849 } vertices_tests
[] = {
7850 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
7851 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
7852 { "{ A[t, i] : t = 14 and i = 1 }",
7853 1, { "{ A[14, 1] }" } },
7854 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
7855 "c <= m and m <= n and m > 0 }",
7857 "[n, m] -> { [n, m, m] : 0 < m <= n }",
7858 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
7859 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
7860 "[n, m] -> { [m, m, m] : 0 < m <= n }",
7861 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
7862 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
7864 /* An input with implicit equality constraints among the parameters. */
7865 { "[N, M] -> { [a, b] : M >= 3 and 9 + 3M <= a <= 29 + 2N + 11M and "
7866 "2b >= M + a and 5 - 2N - M + a <= 2b <= 3 + a and "
7869 "[N, M] -> { [(21), (12)] : M = 3 and N >= 0 }",
7870 "[N, M] -> { [(61 + 2N), (32 + N)] : M = 3 and N >= 0 }",
7875 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
7877 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
7879 struct isl_vertices_test_data
*data
= user
;
7882 isl_basic_set
*bset
;
7883 isl_pw_multi_aff
*pma
;
7887 ctx
= isl_vertex_get_ctx(vertex
);
7888 bset
= isl_vertex_get_domain(vertex
);
7889 ma
= isl_vertex_get_expr(vertex
);
7890 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
7892 for (i
= 0; i
< data
->n
; ++i
) {
7893 isl_pw_multi_aff
*pma_i
;
7895 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
7896 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
7897 isl_pw_multi_aff_free(pma_i
);
7899 if (equal
< 0 || equal
)
7903 isl_pw_multi_aff_free(pma
);
7904 isl_vertex_free(vertex
);
7907 return isl_stat_error
;
7909 return equal
? isl_stat_ok
: isl_stat_error
;
7912 int test_vertices(isl_ctx
*ctx
)
7916 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
7917 isl_basic_set
*bset
;
7918 isl_vertices
*vertices
;
7922 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
7923 vertices
= isl_basic_set_compute_vertices(bset
);
7924 n
= isl_vertices_get_n_vertices(vertices
);
7925 if (vertices_tests
[i
].n
!= n
)
7927 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
7928 &vertices_tests
[i
]) < 0)
7930 isl_vertices_free(vertices
);
7931 isl_basic_set_free(bset
);
7936 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
7943 /* Inputs for basic tests of unary operations on isl_union_map.
7944 * "fn" is the function that is being tested.
7945 * "arg" is a string description of the input.
7946 * "res" is a string description of the expected result.
7949 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap
);
7952 } umap_un_tests
[] = {
7953 { &isl_union_map_range_reverse
,
7954 "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
7955 "{ A[] -> [C[] -> B[]]; A[0] -> N[B[2] -> B[1]] }" },
7956 { &isl_union_map_range_reverse
,
7957 "{ A[] -> N[B[] -> C[]] }",
7958 "{ A[] -> [C[] -> B[]] }" },
7959 { &isl_union_map_range_reverse
,
7960 "{ A[] -> N[B[x] -> B[y]] }",
7961 "{ A[] -> N[B[*] -> B[*]] }" },
7964 /* Perform basic tests of unary operations on isl_union_map.
7966 static isl_stat
test_un_union_map(isl_ctx
*ctx
)
7970 for (i
= 0; i
< ARRAY_SIZE(umap_un_tests
); ++i
) {
7972 isl_union_map
*umap
, *res
;
7975 str
= umap_un_tests
[i
].arg
;
7976 umap
= isl_union_map_read_from_str(ctx
, str
);
7977 str
= umap_un_tests
[i
].res
;
7978 res
= isl_union_map_read_from_str(ctx
, str
);
7979 umap
= umap_un_tests
[i
].fn(umap
);
7980 equal
= isl_union_map_is_equal(umap
, res
);
7981 isl_union_map_free(umap
);
7982 isl_union_map_free(res
);
7984 return isl_stat_error
;
7986 isl_die(ctx
, isl_error_unknown
,
7987 "unexpected result", return isl_stat_error
);
7993 /* Inputs for basic tests of binary operations on isl_union_map.
7994 * "fn" is the function that is being tested.
7995 * "arg1" and "arg2" are string descriptions of the inputs.
7996 * "res" is a string description of the expected result.
7999 __isl_give isl_union_map
*(*fn
)(__isl_take isl_union_map
*umap1
,
8000 __isl_take isl_union_map
*umap2
);
8004 } umap_bin_tests
[] = {
8005 { &isl_union_map_intersect
,
8006 "[n] -> { A[i] -> [] : 0 <= i <= n; B[] -> [] }",
8007 "[m] -> { A[i] -> [] : 0 <= i <= m; C[] -> [] }",
8008 "[m, n] -> { A[i] -> [] : 0 <= i <= n and i <= m }" },
8009 { &isl_union_map_intersect_domain_factor_domain
,
8010 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8011 "[N] -> { B[i] -> C[N] }",
8013 { &isl_union_map_intersect_domain_factor_domain
,
8014 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8015 "[N] -> { A[i] -> C[N] }",
8016 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
8017 { &isl_union_map_intersect_domain_factor_domain
,
8018 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
8019 "[N] -> { A[i] -> C[N] }",
8020 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
8021 { &isl_union_map_intersect_domain_factor_range
,
8022 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8023 "[N] -> { B[i] -> C[N] }",
8024 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
8025 { &isl_union_map_intersect_domain_factor_range
,
8026 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
8027 "[N] -> { B[i] -> C[N] }",
8028 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
8029 { &isl_union_map_intersect_domain_factor_range
,
8030 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
8031 "[N] -> { A[i] -> C[N] }",
8033 { &isl_union_map_intersect_range_factor_domain
,
8034 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8035 "[N] -> { A[i] -> B[N] }",
8036 "[N] -> { A[N - 1] -> [B[N] -> C[N + 1]] }" },
8037 { &isl_union_map_intersect_range_factor_domain
,
8038 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
8039 "[N] -> { A[i] -> B[N] }",
8040 "[N] -> { A[N - 1] -> T[B[N] -> C[N + 1]] }" },
8041 { &isl_union_map_intersect_range_factor_domain
,
8042 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8043 "[N] -> { A[i] -> C[N] }",
8045 { &isl_union_map_intersect_range_factor_range
,
8046 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8047 "[N] -> { A[i] -> C[N] }",
8048 "[N] -> { A[N - 2] -> [B[N - 1] -> C[N]] }" },
8049 { &isl_union_map_intersect_range_factor_range
,
8050 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
8051 "[N] -> { A[i] -> C[N] }",
8052 "[N] -> { A[N - 2] -> T[B[N - 1] -> C[N]] }" },
8053 { &isl_union_map_intersect_range_factor_range
,
8054 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8055 "[N] -> { A[i] -> B[N] }",
8059 /* Perform basic tests of binary operations on isl_union_map.
8061 static isl_stat
test_bin_union_map(isl_ctx
*ctx
)
8065 for (i
= 0; i
< ARRAY_SIZE(umap_bin_tests
); ++i
) {
8067 isl_union_map
*umap1
, *umap2
, *res
;
8070 str
= umap_bin_tests
[i
].arg1
;
8071 umap1
= isl_union_map_read_from_str(ctx
, str
);
8072 str
= umap_bin_tests
[i
].arg2
;
8073 umap2
= isl_union_map_read_from_str(ctx
, str
);
8074 str
= umap_bin_tests
[i
].res
;
8075 res
= isl_union_map_read_from_str(ctx
, str
);
8076 umap1
= umap_bin_tests
[i
].fn(umap1
, umap2
);
8077 equal
= isl_union_map_is_equal(umap1
, res
);
8078 isl_union_map_free(umap1
);
8079 isl_union_map_free(res
);
8081 return isl_stat_error
;
8083 isl_die(ctx
, isl_error_unknown
,
8084 "unexpected result", return isl_stat_error
);
8090 /* Check that isl_union_set_contains finds space independently
8091 * of the parameters.
8093 static isl_stat
test_union_set_contains(isl_ctx
*ctx
)
8099 isl_union_set
*uset
;
8101 str
= "[N] -> { A[0:N]; B[*,*] }";
8102 uset
= isl_union_set_read_from_str(ctx
, str
);
8103 space
= isl_space_unit(ctx
);
8104 id
= isl_id_alloc(ctx
, "A", NULL
);
8105 space
= isl_space_add_named_tuple_id_ui(space
, id
, 1);
8106 ok
= isl_union_set_contains(uset
, space
);
8107 isl_space_free(space
);
8108 isl_union_set_free(uset
);
8111 return isl_stat_error
;
8113 isl_die(ctx
, isl_error_unknown
,
8114 "unexpected result", return isl_stat_error
);
8119 /* Perform basic tests of operations on isl_union_map or isl_union_set.
8121 static int test_union_map(isl_ctx
*ctx
)
8123 if (test_un_union_map(ctx
) < 0)
8125 if (test_bin_union_map(ctx
) < 0)
8127 if (test_union_set_contains(ctx
) < 0)
8132 int test_union_pw(isl_ctx
*ctx
)
8136 isl_union_set
*uset
;
8137 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
8139 str
= "{ [x] -> x^2 }";
8140 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8141 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
8142 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
8143 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
8144 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
8145 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
8146 isl_union_pw_qpolynomial_free(upwqp1
);
8147 isl_union_pw_qpolynomial_free(upwqp2
);
8151 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
8156 /* Inputs for basic tests of functions that select
8157 * subparts of the domain of an isl_multi_union_pw_aff.
8158 * "fn" is the function that is tested.
8159 * "arg" is a string description of the input.
8160 * "res" is a string description of the expected result.
8163 __isl_give isl_union_set
*(*fn
)(
8164 __isl_take isl_multi_union_pw_aff
*mupa
);
8167 } un_locus_tests
[] = {
8168 { &isl_multi_union_pw_aff_zero_union_set
,
8169 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8170 "{ A[0,j]; B[0,j] }" },
8171 { &isl_multi_union_pw_aff_zero_union_set
,
8172 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
8173 "{ A[i,i]; B[i,i] : i >= 0 }" },
8174 { &isl_multi_union_pw_aff_zero_union_set
,
8175 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
8176 "{ A[i,j]; B[i,i] : i >= 0 }" },
8179 /* Perform some basic tests of functions that select
8180 * subparts of the domain of an isl_multi_union_pw_aff.
8182 static int test_un_locus(isl_ctx
*ctx
)
8186 isl_union_set
*uset
, *res
;
8187 isl_multi_union_pw_aff
*mupa
;
8189 for (i
= 0; i
< ARRAY_SIZE(un_locus_tests
); ++i
) {
8190 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
8191 un_locus_tests
[i
].arg
);
8192 res
= isl_union_set_read_from_str(ctx
, un_locus_tests
[i
].res
);
8193 uset
= un_locus_tests
[i
].fn(mupa
);
8194 ok
= isl_union_set_is_equal(uset
, res
);
8195 isl_union_set_free(uset
);
8196 isl_union_set_free(res
);
8200 isl_die(ctx
, isl_error_unknown
,
8201 "unexpected result", return -1);
8207 /* Inputs for basic tests of functions that select
8208 * subparts of an isl_union_map based on a relation
8209 * specified by an isl_multi_union_pw_aff.
8210 * "fn" is the function that is tested.
8211 * "arg1" and "arg2" are string descriptions of the inputs.
8212 * "res" is a string description of the expected result.
8215 __isl_give isl_union_map
*(*fn
)(
8216 __isl_take isl_union_map
*umap
,
8217 __isl_take isl_multi_union_pw_aff
*mupa
);
8221 } bin_locus_tests
[] = {
8222 { &isl_union_map_eq_at_multi_union_pw_aff
,
8223 "{ A[i,j] -> B[i',j'] }",
8224 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8225 "{ A[i,j] -> B[i,j'] }" },
8226 { &isl_union_map_eq_at_multi_union_pw_aff
,
8227 "{ A[i,j] -> B[i',j'] }",
8228 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8229 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8230 "{ A[i,j] -> B[i,j] }" },
8231 { &isl_union_map_eq_at_multi_union_pw_aff
,
8232 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8233 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8234 "{ A[i,j] -> B[i,j'] }" },
8235 { &isl_union_map_eq_at_multi_union_pw_aff
,
8236 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8237 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
8238 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
8239 { &isl_union_map_eq_at_multi_union_pw_aff
,
8240 "{ A[i,j] -> B[i',j'] }",
8241 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
8242 "{ A[i,j] -> B[i,j'] : i > j }" },
8243 { &isl_union_map_lex_le_at_multi_union_pw_aff
,
8244 "{ A[i,j] -> B[i',j'] }",
8245 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8246 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8247 "{ A[i,j] -> B[i',j'] : i,j <<= i',j' }" },
8248 { &isl_union_map_lex_lt_at_multi_union_pw_aff
,
8249 "{ A[i,j] -> B[i',j'] }",
8250 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8251 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8252 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
8253 { &isl_union_map_lex_ge_at_multi_union_pw_aff
,
8254 "{ A[i,j] -> B[i',j'] }",
8255 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8256 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8257 "{ A[i,j] -> B[i',j'] : i,j >>= i',j' }" },
8258 { &isl_union_map_lex_gt_at_multi_union_pw_aff
,
8259 "{ A[i,j] -> B[i',j'] }",
8260 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8261 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8262 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
8263 { &isl_union_map_eq_at_multi_union_pw_aff
,
8264 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8265 "(F[] : { A[i,j]; B[i,j] })",
8266 "{ A[i,j] -> B[i',j'] }" },
8267 { &isl_union_map_eq_at_multi_union_pw_aff
,
8268 "{ A[i,j] -> B[i',j'] }",
8269 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8270 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
8271 { &isl_union_map_eq_at_multi_union_pw_aff
,
8272 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
8273 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8274 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
8275 { &isl_union_map_eq_at_multi_union_pw_aff
,
8276 "{ A[i,j] -> B[i',j'] }",
8277 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
8278 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
8279 { &isl_union_map_eq_at_multi_union_pw_aff
,
8280 "{ A[i,j] -> B[i',j'] }",
8281 "[N] -> (F[] : { : N >= 0 })",
8282 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
8285 /* Perform some basic tests of functions that select
8286 * subparts of an isl_union_map based on a relation
8287 * specified by an isl_multi_union_pw_aff.
8289 static int test_bin_locus(isl_ctx
*ctx
)
8293 isl_union_map
*umap
, *res
;
8294 isl_multi_union_pw_aff
*mupa
;
8296 for (i
= 0; i
< ARRAY_SIZE(bin_locus_tests
); ++i
) {
8297 umap
= isl_union_map_read_from_str(ctx
,
8298 bin_locus_tests
[i
].arg1
);
8299 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
,
8300 bin_locus_tests
[i
].arg2
);
8301 res
= isl_union_map_read_from_str(ctx
, bin_locus_tests
[i
].res
);
8302 umap
= bin_locus_tests
[i
].fn(umap
, mupa
);
8303 ok
= isl_union_map_is_equal(umap
, res
);
8304 isl_union_map_free(umap
);
8305 isl_union_map_free(res
);
8309 isl_die(ctx
, isl_error_unknown
,
8310 "unexpected result", return -1);
8316 /* Inputs for basic tests of functions that determine
8317 * the part of the domain where two isl_multi_aff objects
8318 * related to each other in a specific way.
8319 * "fn" is the function that is being tested.
8320 * "arg1" and "arg2" are string descriptions of the inputs.
8321 * "res" is a string description of the expected result.
8324 __isl_give isl_set
*(*fn
)(__isl_take isl_multi_aff
*ma1
,
8325 __isl_take isl_multi_aff
*ma2
);
8329 } bin_locus_ma_tests
[] = {
8330 { &isl_multi_aff_lex_le_set
, "{ [] }", "{ [] }", "{ : }" },
8331 { &isl_multi_aff_lex_lt_set
, "{ [] }", "{ [] }", "{ : false }" },
8332 { &isl_multi_aff_lex_le_set
,
8333 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8334 "{ A[i] : i <= 0 }" },
8335 { &isl_multi_aff_lex_lt_set
,
8336 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8337 "{ A[i] : i < 0 }" },
8338 { &isl_multi_aff_lex_le_set
,
8339 "{ A[i] -> [i, i] }", "{ A[i] -> [0, 0] }",
8340 "{ A[i] : i <= 0 }" },
8341 { &isl_multi_aff_lex_le_set
,
8342 "{ A[i] -> [i, 0] }", "{ A[i] -> [0, 0] }",
8343 "{ A[i] : i <= 0 }" },
8344 { &isl_multi_aff_lex_le_set
,
8345 "{ A[i] -> [i, 1] }", "{ A[i] -> [0, 0] }",
8346 "{ A[i] : i < 0 }" },
8349 /* Perform some basic tests of functions that determine
8350 * the part of the domain where two isl_multi_aff objects
8351 * related to each other in a specific way.
8353 static isl_stat
test_bin_locus_ma(isl_ctx
*ctx
)
8357 for (i
= 0; i
< ARRAY_SIZE(bin_locus_ma_tests
); ++i
) {
8360 isl_multi_aff
*ma1
, *ma2
;
8363 str
= bin_locus_ma_tests
[i
].arg1
;
8364 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
8365 str
= bin_locus_ma_tests
[i
].arg2
;
8366 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8367 res
= isl_set_read_from_str(ctx
, bin_locus_ma_tests
[i
].res
);
8368 set
= bin_locus_ma_tests
[i
].fn(ma1
, ma2
);
8369 ok
= isl_set_is_equal(set
, res
);
8373 return isl_stat_error
;
8375 isl_die(ctx
, isl_error_unknown
,
8376 "unexpected result", return isl_stat_error
);
8382 /* Perform basic locus tests.
8384 static int test_locus(isl_ctx
*ctx
)
8386 if (test_un_locus(ctx
) < 0)
8388 if (test_bin_locus(ctx
) < 0)
8390 if (test_bin_locus_ma(ctx
) < 0)
8395 /* Test that isl_union_pw_qpolynomial_eval picks up the function
8396 * defined over the correct domain space.
8398 static int test_eval_1(isl_ctx
*ctx
)
8403 isl_union_pw_qpolynomial
*upwqp
;
8407 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
8408 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
8410 set
= isl_set_read_from_str(ctx
, str
);
8411 pnt
= isl_set_sample_point(set
);
8412 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
8413 cmp
= isl_val_cmp_si(v
, 36);
8419 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
8424 /* Check that isl_qpolynomial_eval handles getting called on a void point.
8426 static int test_eval_2(isl_ctx
*ctx
)
8431 isl_qpolynomial
*qp
;
8435 str
= "{ A[x] -> [x] }";
8436 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
8437 str
= "{ A[x] : false }";
8438 set
= isl_set_read_from_str(ctx
, str
);
8439 pnt
= isl_set_sample_point(set
);
8440 v
= isl_qpolynomial_eval(qp
, pnt
);
8441 ok
= isl_val_is_nan(v
);
8447 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
8452 /* Check that a polynomial (without local variables) can be evaluated
8453 * in a rational point.
8455 static isl_stat
test_eval_3(isl_ctx
*ctx
)
8457 isl_pw_qpolynomial
*pwqp
;
8462 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, "{ [x] -> x^2 }");
8463 pnt
= isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp
));
8464 v
= isl_val_read_from_str(ctx
, "1/2");
8465 pnt
= isl_point_set_coordinate_val(pnt
, isl_dim_set
, 0, v
);
8466 v
= isl_pw_qpolynomial_eval(pwqp
, pnt
);
8467 r
= val_check_equal(v
, "1/4");
8473 /* Inputs for isl_pw_aff_eval test.
8474 * "f" is the affine function.
8475 * "p" is the point where the function should be evaluated.
8476 * "res" is the expected result.
8482 } aff_eval_tests
[] = {
8483 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
8484 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
8485 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
8486 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
8487 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
8488 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
8489 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
8490 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
8491 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
8492 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
8493 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
8494 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
8495 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
8496 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
8497 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
8498 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
8499 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
8500 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
8501 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
8502 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
8503 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
8504 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
8505 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
8508 /* Perform basic isl_pw_aff_eval tests.
8510 static int test_eval_aff(isl_ctx
*ctx
)
8514 for (i
= 0; i
< ARRAY_SIZE(aff_eval_tests
); ++i
) {
8521 pa
= isl_pw_aff_read_from_str(ctx
, aff_eval_tests
[i
].f
);
8522 set
= isl_set_read_from_str(ctx
, aff_eval_tests
[i
].p
);
8523 pnt
= isl_set_sample_point(set
);
8524 v
= isl_pw_aff_eval(pa
, pnt
);
8525 r
= val_check_equal(v
, aff_eval_tests
[i
].res
);
8533 /* Perform basic evaluation tests.
8535 static int test_eval(isl_ctx
*ctx
)
8537 if (test_eval_1(ctx
) < 0)
8539 if (test_eval_2(ctx
) < 0)
8541 if (test_eval_3(ctx
) < 0)
8543 if (test_eval_aff(ctx
) < 0)
8548 /* Descriptions of sets that are tested for reparsing after printing.
8550 const char *output_tests
[] = {
8551 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
8554 "{ [x] : x mod 2 = 0 }",
8555 "{ [x] : x mod 2 = 1 }",
8556 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
8557 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
8558 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8559 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8560 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
8561 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
8564 /* Check that printing a set and reparsing a set from the printed output
8565 * results in the same set.
8567 static int test_output_set(isl_ctx
*ctx
)
8571 isl_set
*set1
, *set2
;
8574 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
8575 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
8576 str
= isl_set_to_str(set1
);
8577 set2
= isl_set_read_from_str(ctx
, str
);
8579 equal
= isl_set_is_equal(set1
, set2
);
8585 isl_die(ctx
, isl_error_unknown
,
8586 "parsed output not the same", return -1);
8592 /* Check that an isl_multi_aff is printed using a consistent space.
8594 static isl_stat
test_output_ma(isl_ctx
*ctx
)
8599 isl_multi_aff
*ma
, *ma2
;
8601 ma
= isl_multi_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8602 aff
= isl_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8603 ma
= isl_multi_aff_set_aff(ma
, 0, aff
);
8604 str
= isl_multi_aff_to_str(ma
);
8605 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8607 equal
= isl_multi_aff_plain_is_equal(ma
, ma2
);
8608 isl_multi_aff_free(ma2
);
8609 isl_multi_aff_free(ma
);
8612 return isl_stat_error
;
8614 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8615 return isl_stat_error
);
8620 /* Check that an isl_multi_pw_aff is printed using a consistent space.
8622 static isl_stat
test_output_mpa(isl_ctx
*ctx
)
8627 isl_multi_pw_aff
*mpa
, *mpa2
;
8629 mpa
= isl_multi_pw_aff_read_from_str(ctx
, "{ [a, b] -> [a + b] }");
8630 pa
= isl_pw_aff_read_from_str(ctx
, "{ [c, d] -> [c + d] }");
8631 mpa
= isl_multi_pw_aff_set_pw_aff(mpa
, 0, pa
);
8632 str
= isl_multi_pw_aff_to_str(mpa
);
8633 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
8635 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
8636 isl_multi_pw_aff_free(mpa2
);
8637 isl_multi_pw_aff_free(mpa
);
8640 return isl_stat_error
;
8642 isl_die(ctx
, isl_error_unknown
, "bad conversion",
8643 return isl_stat_error
);
8648 int test_output(isl_ctx
*ctx
)
8656 if (test_output_set(ctx
) < 0)
8658 if (test_output_ma(ctx
) < 0)
8660 if (test_output_mpa(ctx
) < 0)
8663 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
8664 pa
= isl_pw_aff_read_from_str(ctx
, str
);
8666 p
= isl_printer_to_str(ctx
);
8667 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
8668 p
= isl_printer_print_pw_aff(p
, pa
);
8669 s
= isl_printer_get_str(p
);
8670 isl_printer_free(p
);
8671 isl_pw_aff_free(pa
);
8675 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
8680 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
8685 int test_sample(isl_ctx
*ctx
)
8688 isl_basic_set
*bset1
, *bset2
;
8691 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
8692 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
8693 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
8694 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
8695 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
8696 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
8697 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
8698 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
8699 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
8700 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
8701 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
8702 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
8703 "d - 1073741821e and "
8704 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
8705 "3j >= 1 - a + b + 2e and "
8706 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
8707 "3i <= 4 - a + 4b - e and "
8708 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
8709 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
8710 "c <= -1 + a and 3i >= -2 - a + 3e and "
8711 "1073741822e <= 1073741823 - a + 1073741822b + c and "
8712 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
8713 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
8714 "1073741823e >= 1 + 1073741823b - d and "
8715 "3i >= 1073741823b + c - 1073741823e - f and "
8716 "3i >= 1 + 2b + e + 3g }";
8717 bset1
= isl_basic_set_read_from_str(ctx
, str
);
8718 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
8719 empty
= isl_basic_set_is_empty(bset2
);
8720 subset
= isl_basic_set_is_subset(bset2
, bset1
);
8721 isl_basic_set_free(bset1
);
8722 isl_basic_set_free(bset2
);
8723 if (empty
< 0 || subset
< 0)
8726 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
8728 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
8733 /* Perform a projection on a basic set that is known to be empty
8734 * but that has not been assigned a canonical representation.
8735 * Earlier versions of isl would run into a stack overflow
8738 static int test_empty_projection(isl_ctx
*ctx
)
8742 isl_basic_set
*bset
;
8744 str
= "{ [a, b, c, d, e, f, g, h] : 5f = 1 + 4a - b + 5c - d - 2e and "
8745 "3h = 2 + b + c and 14c >= 9 - 3a + 25b and "
8746 "4c <= 50 - 3a + 23b and 6b <= -39 + a and "
8747 "9g >= -6 + 3a + b + c and e < a + b - 2d and "
8748 "7d >= -5 + 2a + 2b and 5g >= -14 + a - 4b + d + 2e and "
8749 "9g <= -28 - 5b - 2c + 3d + 6e }";
8750 bset
= isl_basic_set_read_from_str(ctx
, str
);
8751 empty
= isl_basic_set_is_empty(bset
);
8752 bset
= isl_basic_set_params(bset
);
8753 isl_basic_set_free(bset
);
8761 int test_fixed_power(isl_ctx
*ctx
)
8768 str
= "{ [i] -> [i + 1] }";
8769 map
= isl_map_read_from_str(ctx
, str
);
8770 exp
= isl_val_int_from_si(ctx
, 23);
8771 map
= isl_map_fixed_power_val(map
, exp
);
8772 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
8780 int test_slice(isl_ctx
*ctx
)
8786 str
= "{ [i] -> [j] }";
8787 map
= isl_map_read_from_str(ctx
, str
);
8788 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8789 equal
= map_check_equal(map
, "{ [i] -> [i] }");
8794 str
= "{ [i] -> [j] }";
8795 map
= isl_map_read_from_str(ctx
, str
);
8796 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8797 equal
= map_check_equal(map
, "{ [i] -> [j] }");
8802 str
= "{ [i] -> [j] }";
8803 map
= isl_map_read_from_str(ctx
, str
);
8804 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8805 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
8810 str
= "{ [i] -> [j] }";
8811 map
= isl_map_read_from_str(ctx
, str
);
8812 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8813 equal
= map_check_equal(map
, "{ [0] -> [j] }");
8818 str
= "{ [i] -> [j] }";
8819 map
= isl_map_read_from_str(ctx
, str
);
8820 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
8821 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
8826 str
= "{ [i] -> [j] }";
8827 map
= isl_map_read_from_str(ctx
, str
);
8828 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
8829 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
8837 int test_eliminate(isl_ctx
*ctx
)
8843 str
= "{ [i] -> [j] : i = 2j }";
8844 map
= isl_map_read_from_str(ctx
, str
);
8845 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
8846 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
8854 /* Check basic functionality of isl_map_deltas_map.
8856 static int test_deltas_map(isl_ctx
*ctx
)
8862 str
= "{ A[i] -> A[i + 1] }";
8863 map
= isl_map_read_from_str(ctx
, str
);
8864 map
= isl_map_deltas_map(map
);
8865 equal
= map_check_equal(map
, "{ [A[i] -> A[i + 1]] -> A[1] }");
8873 /* Check that isl_set_dim_residue_class detects that the values of j
8874 * in the set below are all odd and that it does not detect any spurious
8877 static int test_residue_class(isl_ctx
*ctx
)
8884 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
8885 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
8886 set
= isl_set_read_from_str(ctx
, str
);
8889 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
8891 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
8892 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
8893 res
= isl_stat_error
);
8901 static int test_align_parameters_1(isl_ctx
*ctx
)
8905 isl_multi_aff
*ma1
, *ma2
;
8908 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
8909 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
8911 space
= isl_space_params_alloc(ctx
, 1);
8912 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
8913 ma1
= isl_multi_aff_align_params(ma1
, space
);
8915 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
8916 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
8918 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
8920 isl_multi_aff_free(ma1
);
8921 isl_multi_aff_free(ma2
);
8926 isl_die(ctx
, isl_error_unknown
,
8927 "result not as expected", return -1);
8932 /* Check the isl_multi_*_from_*_list operation in case inputs
8933 * have unaligned parameters.
8934 * In particular, older versions of isl would simply fail
8935 * (without printing any error message).
8937 static isl_stat
test_align_parameters_2(isl_ctx
*ctx
)
8944 map
= isl_map_read_from_str(ctx
, "{ A[] -> M[x] }");
8945 space
= isl_map_get_space(map
);
8948 aff
= isl_aff_read_from_str(ctx
, "[N] -> { A[] -> [N] }");
8949 ma
= isl_multi_aff_from_aff_list(space
, isl_aff_list_from_aff(aff
));
8950 isl_multi_aff_free(ma
);
8953 return isl_stat_error
;
8957 /* Perform basic parameter alignment tests.
8959 static int test_align_parameters(isl_ctx
*ctx
)
8961 if (test_align_parameters_1(ctx
) < 0)
8963 if (test_align_parameters_2(ctx
) < 0)
8969 /* Check that isl_*_drop_unused_params actually drops the unused parameters
8970 * by comparing the result using isl_*_plain_is_equal.
8971 * Note that this assumes that isl_*_plain_is_equal does not consider
8972 * objects that only differ by unused parameters to be equal.
8974 int test_drop_unused_parameters(isl_ctx
*ctx
)
8976 const char *str_with
, *str_without
;
8977 isl_basic_set
*bset1
, *bset2
;
8978 isl_set
*set1
, *set2
;
8979 isl_pw_aff
*pwa1
, *pwa2
;
8982 str_with
= "[n, m, o] -> { [m] }";
8983 str_without
= "[m] -> { [m] }";
8985 bset1
= isl_basic_set_read_from_str(ctx
, str_with
);
8986 bset2
= isl_basic_set_read_from_str(ctx
, str_without
);
8987 bset1
= isl_basic_set_drop_unused_params(bset1
);
8988 equal
= isl_basic_set_plain_is_equal(bset1
, bset2
);
8989 isl_basic_set_free(bset1
);
8990 isl_basic_set_free(bset2
);
8995 isl_die(ctx
, isl_error_unknown
,
8996 "result not as expected", return -1);
8998 set1
= isl_set_read_from_str(ctx
, str_with
);
8999 set2
= isl_set_read_from_str(ctx
, str_without
);
9000 set1
= isl_set_drop_unused_params(set1
);
9001 equal
= isl_set_plain_is_equal(set1
, set2
);
9008 isl_die(ctx
, isl_error_unknown
,
9009 "result not as expected", return -1);
9011 pwa1
= isl_pw_aff_read_from_str(ctx
, str_with
);
9012 pwa2
= isl_pw_aff_read_from_str(ctx
, str_without
);
9013 pwa1
= isl_pw_aff_drop_unused_params(pwa1
);
9014 equal
= isl_pw_aff_plain_is_equal(pwa1
, pwa2
);
9015 isl_pw_aff_free(pwa1
);
9016 isl_pw_aff_free(pwa2
);
9021 isl_die(ctx
, isl_error_unknown
,
9022 "result not as expected", return -1);
9027 static int test_list(isl_ctx
*ctx
)
9029 isl_id
*a
, *b
, *c
, *d
, *id
;
9034 a
= isl_id_alloc(ctx
, "a", NULL
);
9035 b
= isl_id_alloc(ctx
, "b", NULL
);
9036 c
= isl_id_alloc(ctx
, "c", NULL
);
9037 d
= isl_id_alloc(ctx
, "d", NULL
);
9039 list
= isl_id_list_alloc(ctx
, 4);
9040 list
= isl_id_list_add(list
, b
);
9041 list
= isl_id_list_insert(list
, 0, a
);
9042 list
= isl_id_list_add(list
, c
);
9043 list
= isl_id_list_add(list
, d
);
9044 list
= isl_id_list_drop(list
, 1, 1);
9046 n
= isl_id_list_n_id(list
);
9050 isl_id_list_free(list
);
9051 isl_die(ctx
, isl_error_unknown
,
9052 "unexpected number of elements in list", return -1);
9055 id
= isl_id_list_get_id(list
, 0);
9058 id
= isl_id_list_get_id(list
, 1);
9061 id
= isl_id_list_get_id(list
, 2);
9065 isl_id_list_free(list
);
9068 isl_die(ctx
, isl_error_unknown
,
9069 "unexpected elements in list", return -1);
9074 /* Check the conversion from an isl_multi_aff to an isl_basic_set.
9076 static isl_stat
test_ma_conversion(isl_ctx
*ctx
)
9081 isl_basic_set
*bset1
, *bset2
;
9083 str
= "[N] -> { A[0, N + 1] }";
9084 ma
= isl_multi_aff_read_from_str(ctx
, str
);
9085 bset1
= isl_basic_set_read_from_str(ctx
, str
);
9086 bset2
= isl_basic_set_from_multi_aff(ma
);
9087 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9088 isl_basic_set_free(bset1
);
9089 isl_basic_set_free(bset2
);
9091 return isl_stat_error
;
9093 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9094 return isl_stat_error
);
9098 const char *set_conversion_tests
[] = {
9099 "[N] -> { [i] : N - 1 <= 2 i <= N }",
9100 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
9101 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9102 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9103 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
9104 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
9105 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
9106 "-3 + c <= d <= 28 + c) }",
9109 /* Check that converting from isl_set to isl_pw_multi_aff and back
9110 * to isl_set produces the original isl_set.
9112 static int test_set_conversion(isl_ctx
*ctx
)
9116 isl_set
*set1
, *set2
;
9117 isl_pw_multi_aff
*pma
;
9120 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
9121 str
= set_conversion_tests
[i
];
9122 set1
= isl_set_read_from_str(ctx
, str
);
9123 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
9124 set2
= isl_set_from_pw_multi_aff(pma
);
9125 equal
= isl_set_is_equal(set1
, set2
);
9132 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9139 const char *conversion_tests
[] = {
9140 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9141 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9142 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9143 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9145 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9146 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9147 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9150 /* Check that converting from isl_map to isl_pw_multi_aff and back
9151 * to isl_map produces the original isl_map.
9153 static int test_map_conversion(isl_ctx
*ctx
)
9156 isl_map
*map1
, *map2
;
9157 isl_pw_multi_aff
*pma
;
9160 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
9161 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
9162 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
9163 map2
= isl_map_from_pw_multi_aff(pma
);
9164 equal
= isl_map_is_equal(map1
, map2
);
9171 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9178 /* Descriptions of isl_pw_multi_aff objects for testing conversion
9179 * to isl_multi_pw_aff and back.
9181 const char *mpa_conversion_tests
[] = {
9183 "{ [x] -> A[x] : x >= 0 }",
9184 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
9185 "{ [x] -> A[x, x + 1] }",
9187 "{ [x] -> A[] : x >= 0 }",
9190 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
9191 * back to isl_pw_multi_aff preserves the original meaning.
9193 static int test_mpa_conversion(isl_ctx
*ctx
)
9196 isl_pw_multi_aff
*pma1
, *pma2
;
9197 isl_multi_pw_aff
*mpa
;
9200 for (i
= 0; i
< ARRAY_SIZE(mpa_conversion_tests
); ++i
) {
9202 str
= mpa_conversion_tests
[i
];
9203 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9204 pma2
= isl_pw_multi_aff_copy(pma1
);
9205 mpa
= isl_multi_pw_aff_from_pw_multi_aff(pma1
);
9206 pma1
= isl_pw_multi_aff_from_multi_pw_aff(mpa
);
9207 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
9208 isl_pw_multi_aff_free(pma1
);
9209 isl_pw_multi_aff_free(pma2
);
9214 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9221 /* Descriptions of union maps that should be convertible
9222 * to an isl_multi_union_pw_aff.
9224 const char *umap_mupa_conversion_tests
[] = {
9225 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9226 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9227 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9228 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9230 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9231 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9232 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9233 "{ A[] -> B[0]; C[] -> B[1] }",
9234 "{ A[] -> B[]; C[] -> B[] }",
9237 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
9238 * to isl_union_map produces the original isl_union_map.
9240 static int test_union_map_mupa_conversion(isl_ctx
*ctx
)
9243 isl_union_map
*umap1
, *umap2
;
9244 isl_multi_union_pw_aff
*mupa
;
9247 for (i
= 0; i
< ARRAY_SIZE(umap_mupa_conversion_tests
); ++i
) {
9249 str
= umap_mupa_conversion_tests
[i
];
9250 umap1
= isl_union_map_read_from_str(ctx
, str
);
9251 umap2
= isl_union_map_copy(umap1
);
9252 mupa
= isl_multi_union_pw_aff_from_union_map(umap2
);
9253 umap2
= isl_union_map_from_multi_union_pw_aff(mupa
);
9254 equal
= isl_union_map_is_equal(umap1
, umap2
);
9255 isl_union_map_free(umap1
);
9256 isl_union_map_free(umap2
);
9261 isl_die(ctx
, isl_error_unknown
, "bad conversion",
9268 static int test_conversion(isl_ctx
*ctx
)
9270 if (test_ma_conversion(ctx
) < 0)
9272 if (test_set_conversion(ctx
) < 0)
9274 if (test_map_conversion(ctx
) < 0)
9276 if (test_mpa_conversion(ctx
) < 0)
9278 if (test_union_map_mupa_conversion(ctx
) < 0)
9283 /* Check that isl_basic_map_curry does not modify input.
9285 static int test_curry(isl_ctx
*ctx
)
9288 isl_basic_map
*bmap1
, *bmap2
;
9291 str
= "{ [A[] -> B[]] -> C[] }";
9292 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
9293 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
9294 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
9295 isl_basic_map_free(bmap1
);
9296 isl_basic_map_free(bmap2
);
9301 isl_die(ctx
, isl_error_unknown
,
9302 "curried map should not be equal to original",
9312 } preimage_tests
[] = {
9313 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
9314 "{ A[j,i] -> B[i,j] }",
9315 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
9316 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
9317 "{ A[a,b] -> B[a/2,b/6] }",
9318 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
9319 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
9320 "{ A[a,b] -> B[a/2,b/6] }",
9321 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
9322 "exists i,j : a = 2 i and b = 6 j }" },
9323 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
9324 "[n] -> { : 0 <= n <= 100 }" },
9325 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
9326 "{ A[a] -> B[2a] }",
9327 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
9328 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
9329 "{ A[a] -> B[([a/2])] }",
9330 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
9331 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
9332 "{ A[a] -> B[a,a,a/3] }",
9333 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
9334 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
9335 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
9338 static int test_preimage_basic_set(isl_ctx
*ctx
)
9341 isl_basic_set
*bset1
, *bset2
;
9345 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
9346 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
9347 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
9348 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
9349 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
9350 equal
= isl_basic_set_is_equal(bset1
, bset2
);
9351 isl_basic_set_free(bset1
);
9352 isl_basic_set_free(bset2
);
9356 isl_die(ctx
, isl_error_unknown
, "bad preimage",
9367 } preimage_domain_tests
[] = {
9368 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
9369 "{ A[j,i] -> B[i,j] }",
9370 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
9371 { "{ B[i] -> C[i]; D[i] -> E[i] }",
9372 "{ A[i] -> B[i + 1] }",
9373 "{ A[i] -> C[i + 1] }" },
9374 { "{ B[i] -> C[i]; B[i] -> E[i] }",
9375 "{ A[i] -> B[i + 1] }",
9376 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
9377 { "{ B[i] -> C[([i/2])] }",
9378 "{ A[i] -> B[2i] }",
9379 "{ A[i] -> C[i] }" },
9380 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
9381 "{ A[i] -> B[([i/5]), ([i/7])] }",
9382 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
9383 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
9384 "[N] -> { A[] -> B[([N/5])] }",
9385 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
9386 { "{ B[i] -> C[i] : exists a : i = 5 a }",
9387 "{ A[i] -> B[2i] }",
9388 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
9389 { "{ B[i] -> C[i] : exists a : i = 2 a; "
9390 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
9391 "{ A[i] -> B[2i] }",
9392 "{ A[i] -> C[2i] }" },
9393 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
9394 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
9397 static int test_preimage_union_map(isl_ctx
*ctx
)
9400 isl_union_map
*umap1
, *umap2
;
9404 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
9405 umap1
= isl_union_map_read_from_str(ctx
,
9406 preimage_domain_tests
[i
].map
);
9407 ma
= isl_multi_aff_read_from_str(ctx
,
9408 preimage_domain_tests
[i
].ma
);
9409 umap2
= isl_union_map_read_from_str(ctx
,
9410 preimage_domain_tests
[i
].res
);
9411 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
9412 equal
= isl_union_map_is_equal(umap1
, umap2
);
9413 isl_union_map_free(umap1
);
9414 isl_union_map_free(umap2
);
9418 isl_die(ctx
, isl_error_unknown
, "bad preimage",
9425 static int test_preimage(isl_ctx
*ctx
)
9427 if (test_preimage_basic_set(ctx
) < 0)
9429 if (test_preimage_union_map(ctx
) < 0)
9439 } pullback_tests
[] = {
9440 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
9441 "{ A[a,b] -> C[b + 2a] }" },
9442 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
9443 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
9444 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
9445 "{ A[a] -> C[(a)/6] }" },
9446 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
9447 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
9448 "{ A[a] -> C[(2a)/3] }" },
9449 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
9450 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
9451 "{ A[i,j] -> C[i + j, i + j] }"},
9452 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
9453 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
9454 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
9455 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
9456 "{ [i, j] -> [floor((i)/3), j] }",
9457 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
9460 static int test_pullback(isl_ctx
*ctx
)
9463 isl_multi_aff
*ma1
, *ma2
;
9467 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
9468 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
9469 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
9470 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
9471 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
9472 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
9473 isl_multi_aff_free(ma1
);
9474 isl_multi_aff_free(ma2
);
9478 isl_die(ctx
, isl_error_unknown
, "bad pullback",
9485 /* Check that negation is printed correctly and that equal expressions
9486 * are correctly identified.
9488 static int test_ast(isl_ctx
*ctx
)
9490 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
9494 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
9495 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
9496 expr
= isl_ast_expr_add(expr1
, expr2
);
9497 expr2
= isl_ast_expr_copy(expr
);
9498 expr
= isl_ast_expr_neg(expr
);
9499 expr2
= isl_ast_expr_neg(expr2
);
9500 equal
= isl_ast_expr_is_equal(expr
, expr2
);
9501 str
= isl_ast_expr_to_C_str(expr
);
9502 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
9504 isl_ast_expr_free(expr
);
9505 isl_ast_expr_free(expr2
);
9507 if (ok
< 0 || equal
< 0)
9510 isl_die(ctx
, isl_error_unknown
,
9511 "equal expressions not considered equal", return -1);
9513 isl_die(ctx
, isl_error_unknown
,
9514 "isl_ast_expr printed incorrectly", return -1);
9516 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
9517 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
9518 expr
= isl_ast_expr_add(expr1
, expr2
);
9519 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
9520 expr
= isl_ast_expr_sub(expr3
, expr
);
9521 str
= isl_ast_expr_to_C_str(expr
);
9522 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
9524 isl_ast_expr_free(expr
);
9529 isl_die(ctx
, isl_error_unknown
,
9530 "isl_ast_expr printed incorrectly", return -1);
9535 /* Check that isl_ast_build_expr_from_set returns a valid expression
9536 * for an empty set. Note that isl_ast_build_expr_from_set getting
9537 * called on an empty set probably indicates a bug in the caller.
9539 static int test_ast_build(isl_ctx
*ctx
)
9542 isl_ast_build
*build
;
9545 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9546 build
= isl_ast_build_from_context(set
);
9548 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
9549 expr
= isl_ast_build_expr_from_set(build
, set
);
9551 isl_ast_expr_free(expr
);
9552 isl_ast_build_free(build
);
9560 /* Internal data structure for before_for and after_for callbacks.
9562 * depth is the current depth
9563 * before is the number of times before_for has been called
9564 * after is the number of times after_for has been called
9566 struct isl_test_codegen_data
{
9572 /* This function is called before each for loop in the AST generated
9573 * from test_ast_gen1.
9575 * Increment the number of calls and the depth.
9576 * Check that the space returned by isl_ast_build_get_schedule_space
9577 * matches the target space of the schedule returned by
9578 * isl_ast_build_get_schedule.
9579 * Return an isl_id that is checked by the corresponding call
9582 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
9585 struct isl_test_codegen_data
*data
= user
;
9588 isl_union_map
*schedule
;
9589 isl_union_set
*uset
;
9595 ctx
= isl_ast_build_get_ctx(build
);
9597 if (data
->before
>= 3)
9598 isl_die(ctx
, isl_error_unknown
,
9599 "unexpected number of for nodes", return NULL
);
9600 if (data
->depth
< 0 || data
->depth
>= 2)
9601 isl_die(ctx
, isl_error_unknown
,
9602 "unexpected depth", return NULL
);
9604 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
9608 schedule
= isl_ast_build_get_schedule(build
);
9609 uset
= isl_union_map_range(schedule
);
9610 n
= isl_union_set_n_set(uset
);
9612 isl_union_set_free(uset
);
9615 isl_die(ctx
, isl_error_unknown
,
9616 "expecting single range space", return NULL
);
9619 space
= isl_ast_build_get_schedule_space(build
);
9620 set
= isl_union_set_extract_set(uset
, space
);
9621 isl_union_set_free(uset
);
9622 empty
= isl_set_is_empty(set
);
9628 isl_die(ctx
, isl_error_unknown
,
9629 "spaces don't match", return NULL
);
9631 return isl_id_alloc(ctx
, name
, NULL
);
9634 /* This function is called after each for loop in the AST generated
9635 * from test_ast_gen1.
9637 * Increment the number of calls and decrement the depth.
9638 * Check that the annotation attached to the node matches
9639 * the isl_id returned by the corresponding call to before_for.
9641 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
9642 __isl_keep isl_ast_build
*build
, void *user
)
9644 struct isl_test_codegen_data
*data
= user
;
9652 if (data
->after
> data
->before
)
9653 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9654 "mismatch in number of for nodes",
9655 return isl_ast_node_free(node
));
9657 id
= isl_ast_node_get_annotation(node
);
9659 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9660 "missing annotation", return isl_ast_node_free(node
));
9662 name
= isl_id_get_name(id
);
9663 valid
= name
&& atoi(name
+ 1) == data
->depth
;
9667 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
9668 "wrong annotation", return isl_ast_node_free(node
));
9673 /* Check that the before_each_for and after_each_for callbacks
9674 * are called for each for loop in the generated code,
9675 * that they are called in the right order and that the isl_id
9676 * returned from the before_each_for callback is attached to
9677 * the isl_ast_node passed to the corresponding after_each_for call.
9679 static int test_ast_gen1(isl_ctx
*ctx
)
9683 isl_union_map
*schedule
;
9684 isl_ast_build
*build
;
9686 struct isl_test_codegen_data data
;
9688 str
= "[N] -> { : N >= 10 }";
9689 set
= isl_set_read_from_str(ctx
, str
);
9690 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
9691 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
9692 schedule
= isl_union_map_read_from_str(ctx
, str
);
9697 build
= isl_ast_build_from_context(set
);
9698 build
= isl_ast_build_set_before_each_for(build
,
9699 &before_for
, &data
);
9700 build
= isl_ast_build_set_after_each_for(build
,
9702 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9703 isl_ast_build_free(build
);
9707 isl_ast_node_free(tree
);
9709 if (data
.before
!= 3 || data
.after
!= 3)
9710 isl_die(ctx
, isl_error_unknown
,
9711 "unexpected number of for nodes", return -1);
9716 /* Check that the AST generator handles domains that are integrally disjoint
9717 * but not rationally disjoint.
9719 static int test_ast_gen2(isl_ctx
*ctx
)
9723 isl_union_map
*schedule
;
9724 isl_union_map
*options
;
9725 isl_ast_build
*build
;
9728 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
9729 schedule
= isl_union_map_read_from_str(ctx
, str
);
9730 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9731 build
= isl_ast_build_from_context(set
);
9733 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
9734 options
= isl_union_map_read_from_str(ctx
, str
);
9735 build
= isl_ast_build_set_options(build
, options
);
9736 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9737 isl_ast_build_free(build
);
9740 isl_ast_node_free(tree
);
9745 /* Increment *user on each call.
9747 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
9748 __isl_keep isl_ast_build
*build
, void *user
)
9757 /* Test that unrolling tries to minimize the number of instances.
9758 * In particular, for the schedule given below, make sure it generates
9759 * 3 nodes (rather than 101).
9761 static int test_ast_gen3(isl_ctx
*ctx
)
9765 isl_union_map
*schedule
;
9766 isl_union_map
*options
;
9767 isl_ast_build
*build
;
9771 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
9772 schedule
= isl_union_map_read_from_str(ctx
, str
);
9773 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9775 str
= "{ [i] -> unroll[0] }";
9776 options
= isl_union_map_read_from_str(ctx
, str
);
9778 build
= isl_ast_build_from_context(set
);
9779 build
= isl_ast_build_set_options(build
, options
);
9780 build
= isl_ast_build_set_at_each_domain(build
,
9781 &count_domains
, &n_domain
);
9782 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9783 isl_ast_build_free(build
);
9787 isl_ast_node_free(tree
);
9790 isl_die(ctx
, isl_error_unknown
,
9791 "unexpected number of for nodes", return -1);
9796 /* Check that if the ast_build_exploit_nested_bounds options is set,
9797 * we do not get an outer if node in the generated AST,
9798 * while we do get such an outer if node if the options is not set.
9800 static int test_ast_gen4(isl_ctx
*ctx
)
9804 isl_union_map
*schedule
;
9805 isl_ast_build
*build
;
9807 enum isl_ast_node_type type
;
9810 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
9811 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
9813 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
9815 schedule
= isl_union_map_read_from_str(ctx
, str
);
9816 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9817 build
= isl_ast_build_from_context(set
);
9818 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9819 isl_ast_build_free(build
);
9823 type
= isl_ast_node_get_type(tree
);
9824 isl_ast_node_free(tree
);
9826 if (type
== isl_ast_node_if
)
9827 isl_die(ctx
, isl_error_unknown
,
9828 "not expecting if node", return -1);
9830 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
9832 schedule
= isl_union_map_read_from_str(ctx
, str
);
9833 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9834 build
= isl_ast_build_from_context(set
);
9835 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9836 isl_ast_build_free(build
);
9840 type
= isl_ast_node_get_type(tree
);
9841 isl_ast_node_free(tree
);
9843 if (type
!= isl_ast_node_if
)
9844 isl_die(ctx
, isl_error_unknown
,
9845 "expecting if node", return -1);
9847 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
9852 /* This function is called for each leaf in the AST generated
9853 * from test_ast_gen5.
9855 * We finalize the AST generation by extending the outer schedule
9856 * with a zero-dimensional schedule. If this results in any for loops,
9857 * then this means that we did not pass along enough information
9858 * about the outer schedule to the inner AST generation.
9860 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
9863 isl_union_map
*schedule
, *extra
;
9866 schedule
= isl_ast_build_get_schedule(build
);
9867 extra
= isl_union_map_copy(schedule
);
9868 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
9869 schedule
= isl_union_map_range_product(schedule
, extra
);
9870 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9871 isl_ast_build_free(build
);
9876 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
9877 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
9878 "code should not contain any for loop",
9879 return isl_ast_node_free(tree
));
9884 /* Check that we do not lose any information when going back and
9885 * forth between internal and external schedule.
9887 * In particular, we create an AST where we unroll the only
9888 * non-constant dimension in the schedule. We therefore do
9889 * not expect any for loops in the AST. However, older versions
9890 * of isl would not pass along enough information about the outer
9891 * schedule when performing an inner code generation from a create_leaf
9892 * callback, resulting in the inner code generation producing a for loop.
9894 static int test_ast_gen5(isl_ctx
*ctx
)
9898 isl_union_map
*schedule
, *options
;
9899 isl_ast_build
*build
;
9902 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
9903 schedule
= isl_union_map_read_from_str(ctx
, str
);
9905 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
9906 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
9907 options
= isl_union_map_read_from_str(ctx
, str
);
9909 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
9910 build
= isl_ast_build_from_context(set
);
9911 build
= isl_ast_build_set_options(build
, options
);
9912 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
9913 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
9914 isl_ast_build_free(build
);
9915 isl_ast_node_free(tree
);
9922 /* Check that the expression
9924 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
9926 * is not combined into
9930 * as this would result in n/2 being evaluated in parts of
9931 * the definition domain where n is not a multiple of 2.
9933 static int test_ast_expr(isl_ctx
*ctx
)
9937 isl_ast_build
*build
;
9942 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
9943 isl_options_set_ast_build_detect_min_max(ctx
, 1);
9945 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
9946 pa
= isl_pw_aff_read_from_str(ctx
, str
);
9947 build
= isl_ast_build_alloc(ctx
);
9948 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
9949 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
9950 isl_ast_expr_get_op_type(expr
) == isl_ast_expr_op_min
;
9951 isl_ast_build_free(build
);
9952 isl_ast_expr_free(expr
);
9954 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
9959 isl_die(ctx
, isl_error_unknown
,
9960 "expressions should not be combined", return -1);
9965 static int test_ast_gen(isl_ctx
*ctx
)
9967 if (test_ast_gen1(ctx
) < 0)
9969 if (test_ast_gen2(ctx
) < 0)
9971 if (test_ast_gen3(ctx
) < 0)
9973 if (test_ast_gen4(ctx
) < 0)
9975 if (test_ast_gen5(ctx
) < 0)
9977 if (test_ast_expr(ctx
) < 0)
9982 /* Check if dropping output dimensions from an isl_pw_multi_aff
9985 static int test_pw_multi_aff(isl_ctx
*ctx
)
9988 isl_pw_multi_aff
*pma1
, *pma2
;
9991 str
= "{ [i,j] -> [i+j, 4i-j] }";
9992 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9993 str
= "{ [i,j] -> [4i-j] }";
9994 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
9996 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
9998 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
10000 isl_pw_multi_aff_free(pma1
);
10001 isl_pw_multi_aff_free(pma2
);
10005 isl_die(ctx
, isl_error_unknown
,
10006 "expressions not equal", return -1);
10011 /* Check that we can properly parse multi piecewise affine expressions
10012 * where the piecewise affine expressions have different domains.
10014 static int test_multi_pw_aff_1(isl_ctx
*ctx
)
10017 isl_set
*dom
, *dom2
;
10018 isl_multi_pw_aff
*mpa1
, *mpa2
;
10023 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
10024 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
10025 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
10026 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
10027 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
10028 str
= "{ [i] -> [(i : i > 0), 2i] }";
10029 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
10031 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
10033 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
10034 dom
= isl_pw_aff_domain(pa
);
10035 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
10036 dom2
= isl_pw_aff_domain(pa
);
10037 equal_domain
= isl_set_is_equal(dom
, dom2
);
10040 isl_set_free(dom2
);
10041 isl_multi_pw_aff_free(mpa1
);
10042 isl_multi_pw_aff_free(mpa2
);
10047 isl_die(ctx
, isl_error_unknown
,
10048 "expressions not equal", return -1);
10050 if (equal_domain
< 0)
10053 isl_die(ctx
, isl_error_unknown
,
10054 "domains unexpectedly equal", return -1);
10059 /* Check that the dimensions in the explicit domain
10060 * of a multi piecewise affine expression are properly
10061 * taken into account.
10063 static int test_multi_pw_aff_2(isl_ctx
*ctx
)
10066 isl_bool involves1
, involves2
, involves3
, equal
;
10067 isl_multi_pw_aff
*mpa
, *mpa1
, *mpa2
;
10069 str
= "{ A[x,y] -> B[] : x >= y }";
10070 mpa
= isl_multi_pw_aff_read_from_str(ctx
, str
);
10071 involves1
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 2);
10072 mpa1
= isl_multi_pw_aff_copy(mpa
);
10074 mpa
= isl_multi_pw_aff_insert_dims(mpa
, isl_dim_in
, 0, 1);
10075 involves2
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 0, 1);
10076 involves3
= isl_multi_pw_aff_involves_dims(mpa
, isl_dim_in
, 1, 2);
10077 str
= "{ [a,x,y] -> B[] : x >= y }";
10078 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, str
);
10079 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa2
);
10080 isl_multi_pw_aff_free(mpa2
);
10082 mpa
= isl_multi_pw_aff_drop_dims(mpa
, isl_dim_in
, 0, 1);
10083 mpa
= isl_multi_pw_aff_set_tuple_name(mpa
, isl_dim_in
, "A");
10084 if (equal
>= 0 && equal
)
10085 equal
= isl_multi_pw_aff_plain_is_equal(mpa
, mpa1
);
10086 isl_multi_pw_aff_free(mpa1
);
10087 isl_multi_pw_aff_free(mpa
);
10089 if (involves1
< 0 || involves2
< 0 || involves3
< 0 || equal
< 0)
10092 isl_die(ctx
, isl_error_unknown
,
10093 "incorrect result of dimension insertion/removal",
10094 return isl_stat_error
);
10095 if (!involves1
|| involves2
|| !involves3
)
10096 isl_die(ctx
, isl_error_unknown
,
10097 "incorrect characterization of involved dimensions",
10098 return isl_stat_error
);
10103 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
10104 * sets the explicit domain of a zero-dimensional result,
10105 * such that it can be converted to an isl_union_map.
10107 static isl_stat
test_multi_pw_aff_3(isl_ctx
*ctx
)
10110 isl_union_set
*dom
;
10112 isl_multi_union_pw_aff
*mupa
;
10113 isl_union_map
*umap
;
10115 dom
= isl_union_set_read_from_str(ctx
, "{ A[]; B[] }");
10116 space
= isl_union_set_get_space(dom
);
10117 mv
= isl_multi_val_zero(isl_space_set_from_params(space
));
10118 mupa
= isl_multi_union_pw_aff_multi_val_on_domain(dom
, mv
);
10119 umap
= isl_union_map_from_multi_union_pw_aff(mupa
);
10120 isl_union_map_free(umap
);
10122 return isl_stat_error
;
10124 return isl_stat_ok
;
10127 /* String descriptions of boxes that
10128 * are used for reconstructing box maps from their lower and upper bounds.
10130 static const char *multi_pw_aff_box_tests
[] = {
10131 "{ A[x, y] -> [] : x + y >= 0 }",
10132 "[N] -> { A[x, y] -> [x] : x + y <= N }",
10133 "[N] -> { A[x, y] -> [x : y] : x + y <= N }",
10136 /* Check that map representations of boxes can be reconstructed
10137 * from their lower and upper bounds.
10139 static isl_stat
test_multi_pw_aff_box(isl_ctx
*ctx
)
10143 for (i
= 0; i
< ARRAY_SIZE(multi_pw_aff_box_tests
); ++i
) {
10146 isl_map
*map
, *box
;
10147 isl_multi_pw_aff
*min
, *max
;
10149 str
= multi_pw_aff_box_tests
[i
];
10150 map
= isl_map_read_from_str(ctx
, str
);
10151 min
= isl_map_min_multi_pw_aff(isl_map_copy(map
));
10152 max
= isl_map_max_multi_pw_aff(isl_map_copy(map
));
10153 box
= isl_map_universe(isl_map_get_space(map
));
10154 box
= isl_map_lower_bound_multi_pw_aff(box
, min
);
10155 box
= isl_map_upper_bound_multi_pw_aff(box
, max
);
10156 equal
= isl_map_is_equal(map
, box
);
10160 return isl_stat_error
;
10162 isl_die(ctx
, isl_error_unknown
,
10163 "unexpected result", return isl_stat_error
);
10166 return isl_stat_ok
;
10169 /* Perform some tests on multi piecewise affine expressions.
10171 static int test_multi_pw_aff(isl_ctx
*ctx
)
10173 if (test_multi_pw_aff_1(ctx
) < 0)
10175 if (test_multi_pw_aff_2(ctx
) < 0)
10177 if (test_multi_pw_aff_3(ctx
) < 0)
10179 if (test_multi_pw_aff_box(ctx
) < 0)
10184 /* This is a regression test for a bug where isl_basic_map_simplify
10185 * would end up in an infinite loop. In particular, we construct
10186 * an empty basic set that is not obviously empty.
10187 * isl_basic_set_is_empty marks the basic set as empty.
10188 * After projecting out i3, the variable can be dropped completely,
10189 * but isl_basic_map_simplify refrains from doing so if the basic set
10190 * is empty and would end up in an infinite loop if it didn't test
10191 * explicitly for empty basic maps in the outer loop.
10193 static int test_simplify_1(isl_ctx
*ctx
)
10196 isl_basic_set
*bset
;
10199 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
10200 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
10201 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
10203 bset
= isl_basic_set_read_from_str(ctx
, str
);
10204 empty
= isl_basic_set_is_empty(bset
);
10205 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
10206 isl_basic_set_free(bset
);
10210 isl_die(ctx
, isl_error_unknown
,
10211 "basic set should be empty", return -1);
10216 /* Check that the equality in the set description below
10217 * is simplified away.
10219 static int test_simplify_2(isl_ctx
*ctx
)
10222 isl_basic_set
*bset
;
10225 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
10226 bset
= isl_basic_set_read_from_str(ctx
, str
);
10227 universe
= isl_basic_set_plain_is_universe(bset
);
10228 isl_basic_set_free(bset
);
10233 isl_die(ctx
, isl_error_unknown
,
10234 "equality not simplified away", return -1);
10238 /* Some simplification tests.
10240 static int test_simplify(isl_ctx
*ctx
)
10242 if (test_simplify_1(ctx
) < 0)
10244 if (test_simplify_2(ctx
) < 0)
10249 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
10250 * with gbr context would fail to disable the use of the shifted tableau
10251 * when transferring equalities for the input to the context, resulting
10252 * in invalid sample values.
10254 static int test_partial_lexmin(isl_ctx
*ctx
)
10257 isl_basic_set
*bset
;
10258 isl_basic_map
*bmap
;
10261 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
10262 bmap
= isl_basic_map_read_from_str(ctx
, str
);
10263 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
10264 bset
= isl_basic_set_read_from_str(ctx
, str
);
10265 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
10274 /* Check that the variable compression performed on the existentially
10275 * quantified variables inside isl_basic_set_compute_divs is not confused
10276 * by the implicit equalities among the parameters.
10278 static int test_compute_divs(isl_ctx
*ctx
)
10281 isl_basic_set
*bset
;
10284 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
10285 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
10286 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
10287 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
10288 bset
= isl_basic_set_read_from_str(ctx
, str
);
10289 set
= isl_basic_set_compute_divs(bset
);
10297 /* Check that isl_schedule_get_map is not confused by a schedule tree
10298 * with divergent filter node parameters, as can result from a call
10299 * to isl_schedule_intersect_domain.
10301 static int test_schedule_tree(isl_ctx
*ctx
)
10304 isl_union_set
*uset
;
10305 isl_schedule
*sched1
, *sched2
;
10306 isl_union_map
*umap
;
10308 uset
= isl_union_set_read_from_str(ctx
, "{ A[i] }");
10309 sched1
= isl_schedule_from_domain(uset
);
10310 uset
= isl_union_set_read_from_str(ctx
, "{ B[] }");
10311 sched2
= isl_schedule_from_domain(uset
);
10313 sched1
= isl_schedule_sequence(sched1
, sched2
);
10314 str
= "[n] -> { A[i] : 0 <= i < n; B[] }";
10315 uset
= isl_union_set_read_from_str(ctx
, str
);
10316 sched1
= isl_schedule_intersect_domain(sched1
, uset
);
10317 umap
= isl_schedule_get_map(sched1
);
10318 isl_schedule_free(sched1
);
10319 isl_union_map_free(umap
);
10326 /* Check that a zero-dimensional prefix schedule keeps track
10327 * of the domain and outer filters.
10329 static int test_schedule_tree_prefix(isl_ctx
*ctx
)
10333 isl_union_set
*uset
;
10334 isl_union_set_list
*filters
;
10335 isl_multi_union_pw_aff
*mupa
, *mupa2
;
10336 isl_schedule_node
*node
;
10338 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10339 uset
= isl_union_set_read_from_str(ctx
, str
);
10340 node
= isl_schedule_node_from_domain(uset
);
10341 node
= isl_schedule_node_child(node
, 0);
10343 str
= "{ S1[i,j] : i > j }";
10344 uset
= isl_union_set_read_from_str(ctx
, str
);
10345 filters
= isl_union_set_list_from_union_set(uset
);
10346 str
= "{ S1[i,j] : i <= j; S2[i,j] }";
10347 uset
= isl_union_set_read_from_str(ctx
, str
);
10348 filters
= isl_union_set_list_add(filters
, uset
);
10349 node
= isl_schedule_node_insert_sequence(node
, filters
);
10351 node
= isl_schedule_node_child(node
, 0);
10352 node
= isl_schedule_node_child(node
, 0);
10353 mupa
= isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node
);
10354 str
= "([] : { S1[i,j] : i > j })";
10355 mupa2
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10356 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
10357 isl_multi_union_pw_aff_free(mupa2
);
10358 isl_multi_union_pw_aff_free(mupa
);
10359 isl_schedule_node_free(node
);
10364 isl_die(ctx
, isl_error_unknown
, "unexpected prefix schedule",
10370 /* Check that the reaching domain elements and the prefix schedule
10371 * at a leaf node are the same before and after grouping.
10373 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
10378 isl_union_set
*uset
;
10379 isl_multi_union_pw_aff
*mupa
;
10380 isl_union_pw_multi_aff
*upma1
, *upma2
;
10381 isl_union_set
*domain1
, *domain2
;
10382 isl_union_map
*umap1
, *umap2
;
10383 isl_schedule_node
*node
;
10385 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10386 uset
= isl_union_set_read_from_str(ctx
, str
);
10387 node
= isl_schedule_node_from_domain(uset
);
10388 node
= isl_schedule_node_child(node
, 0);
10389 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
10390 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10391 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10392 node
= isl_schedule_node_child(node
, 0);
10393 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
10394 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10395 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10396 node
= isl_schedule_node_child(node
, 0);
10397 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
10398 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
10399 domain1
= isl_schedule_node_get_domain(node
);
10400 id
= isl_id_alloc(ctx
, "group", NULL
);
10401 node
= isl_schedule_node_parent(node
);
10402 node
= isl_schedule_node_group(node
, id
);
10403 node
= isl_schedule_node_child(node
, 0);
10404 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
10405 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
10406 domain2
= isl_schedule_node_get_domain(node
);
10407 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
10408 if (equal
>= 0 && equal
)
10409 equal
= isl_union_set_is_equal(domain1
, domain2
);
10410 if (equal
>= 0 && equal
)
10411 equal
= isl_union_map_is_equal(umap1
, umap2
);
10412 isl_union_map_free(umap1
);
10413 isl_union_map_free(umap2
);
10414 isl_union_set_free(domain1
);
10415 isl_union_set_free(domain2
);
10416 isl_union_pw_multi_aff_free(upma1
);
10417 isl_union_pw_multi_aff_free(upma2
);
10418 isl_schedule_node_free(node
);
10423 isl_die(ctx
, isl_error_unknown
,
10424 "expressions not equal", return -1);
10429 /* Check that we can have nested groupings and that the union map
10430 * schedule representation is the same before and after the grouping.
10431 * Note that after the grouping, the union map representation contains
10432 * the domain constraints from the ranges of the expansion nodes,
10433 * while they are missing from the union map representation of
10434 * the tree without expansion nodes.
10436 * Also check that the global expansion is as expected.
10438 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
10440 int equal
, equal_expansion
;
10443 isl_union_set
*uset
;
10444 isl_union_map
*umap1
, *umap2
;
10445 isl_union_map
*expansion1
, *expansion2
;
10446 isl_union_set_list
*filters
;
10447 isl_multi_union_pw_aff
*mupa
;
10448 isl_schedule
*schedule
;
10449 isl_schedule_node
*node
;
10451 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
10452 "S3[i,j] : 0 <= i,j < 10 }";
10453 uset
= isl_union_set_read_from_str(ctx
, str
);
10454 node
= isl_schedule_node_from_domain(uset
);
10455 node
= isl_schedule_node_child(node
, 0);
10456 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
10457 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10458 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10459 node
= isl_schedule_node_child(node
, 0);
10460 str
= "{ S1[i,j] }";
10461 uset
= isl_union_set_read_from_str(ctx
, str
);
10462 filters
= isl_union_set_list_from_union_set(uset
);
10463 str
= "{ S2[i,j]; S3[i,j] }";
10464 uset
= isl_union_set_read_from_str(ctx
, str
);
10465 filters
= isl_union_set_list_add(filters
, uset
);
10466 node
= isl_schedule_node_insert_sequence(node
, filters
);
10467 node
= isl_schedule_node_child(node
, 1);
10468 node
= isl_schedule_node_child(node
, 0);
10469 str
= "{ S2[i,j] }";
10470 uset
= isl_union_set_read_from_str(ctx
, str
);
10471 filters
= isl_union_set_list_from_union_set(uset
);
10472 str
= "{ S3[i,j] }";
10473 uset
= isl_union_set_read_from_str(ctx
, str
);
10474 filters
= isl_union_set_list_add(filters
, uset
);
10475 node
= isl_schedule_node_insert_sequence(node
, filters
);
10477 schedule
= isl_schedule_node_get_schedule(node
);
10478 umap1
= isl_schedule_get_map(schedule
);
10479 uset
= isl_schedule_get_domain(schedule
);
10480 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
10481 isl_schedule_free(schedule
);
10483 node
= isl_schedule_node_parent(node
);
10484 node
= isl_schedule_node_parent(node
);
10485 id
= isl_id_alloc(ctx
, "group1", NULL
);
10486 node
= isl_schedule_node_group(node
, id
);
10487 node
= isl_schedule_node_child(node
, 1);
10488 node
= isl_schedule_node_child(node
, 0);
10489 id
= isl_id_alloc(ctx
, "group2", NULL
);
10490 node
= isl_schedule_node_group(node
, id
);
10492 schedule
= isl_schedule_node_get_schedule(node
);
10493 umap2
= isl_schedule_get_map(schedule
);
10494 isl_schedule_free(schedule
);
10496 node
= isl_schedule_node_root(node
);
10497 node
= isl_schedule_node_child(node
, 0);
10498 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
10499 isl_schedule_node_free(node
);
10501 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
10502 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
10503 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
10505 expansion2
= isl_union_map_read_from_str(ctx
, str
);
10507 equal
= isl_union_map_is_equal(umap1
, umap2
);
10508 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
10510 isl_union_map_free(umap1
);
10511 isl_union_map_free(umap2
);
10512 isl_union_map_free(expansion1
);
10513 isl_union_map_free(expansion2
);
10515 if (equal
< 0 || equal_expansion
< 0)
10518 isl_die(ctx
, isl_error_unknown
,
10519 "expressions not equal", return -1);
10520 if (!equal_expansion
)
10521 isl_die(ctx
, isl_error_unknown
,
10522 "unexpected expansion", return -1);
10527 /* Some tests for the isl_schedule_node_group function.
10529 static int test_schedule_tree_group(isl_ctx
*ctx
)
10531 if (test_schedule_tree_group_1(ctx
) < 0)
10533 if (test_schedule_tree_group_2(ctx
) < 0)
10542 { "{ rat: [i] : 0 <= i <= 10 }",
10543 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
10544 { "{ rat: [i] : FALSE }",
10545 "{ rat: coefficients[[cst] -> [a]] }" },
10546 { "{ rat: [i] : }",
10547 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
10548 { "{ [0:,1,2:3] }",
10549 "{ rat: coefficients[[c_cst] -> [a, b, c]] : "
10550 "a >= 0 and 2c >= -c_cst - b and 3c >= -c_cst - b }" },
10551 { "[M, N] -> { [x = (1 - N):-1, -4x:(M - 4x)] }",
10552 "{ rat: coefficients[[c_cst, c_M = 0:, c_N = 0:] -> [a, b = -c_M:]] :"
10553 "4b >= -c_N + a and 4b >= -c_cst - 2c_N + a }" },
10554 { "{ rat : [x, y] : 1 <= 2x <= 9 and 2 <= 3y <= 16 }",
10555 "{ rat: coefficients[[c_cst] -> [c_x, c_y]] : "
10556 "4c_y >= -6c_cst - 3c_x and 4c_y >= -6c_cst - 27c_x and "
10557 "32c_y >= -6c_cst - 3c_x and 32c_y >= -6c_cst - 27c_x }" },
10558 { "{ [x, y, z] : 3y <= 2x - 2 and y >= -2 + 2x and 2y >= 2 - x }",
10559 "{ rat: coefficients[[cst] -> [a, b, c]] }" },
10566 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
10567 "{ rat: [i] : 0 <= i <= 10 }" },
10568 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
10570 { "{ rat: coefficients[[cst] -> [a]] }",
10571 "{ rat: [i] : FALSE }" },
10574 /* Test the basic functionality of isl_basic_set_coefficients and
10575 * isl_basic_set_solutions.
10577 static int test_dual(isl_ctx
*ctx
)
10581 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
10583 isl_basic_set
*bset1
, *bset2
;
10585 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
10586 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
10587 bset1
= isl_basic_set_coefficients(bset1
);
10588 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10589 isl_basic_set_free(bset1
);
10590 isl_basic_set_free(bset2
);
10594 isl_die(ctx
, isl_error_unknown
,
10595 "incorrect dual", return -1);
10598 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
10600 isl_basic_set
*bset1
, *bset2
;
10602 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
10603 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
10604 bset1
= isl_basic_set_solutions(bset1
);
10605 equal
= isl_basic_set_is_equal(bset1
, bset2
);
10606 isl_basic_set_free(bset1
);
10607 isl_basic_set_free(bset2
);
10611 isl_die(ctx
, isl_error_unknown
,
10612 "incorrect dual", return -1);
10621 const char *domain
;
10622 const char *schedule
;
10627 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10628 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10630 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10631 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10633 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10634 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10636 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10637 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10639 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10640 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10642 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10643 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10645 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10646 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10648 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10649 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10653 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
10654 * tile the band and then check if the tile and point bands have the
10655 * expected partial schedule.
10657 static int test_tile(isl_ctx
*ctx
)
10663 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
10664 shift
= isl_options_get_tile_shift_point_loops(ctx
);
10666 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
10670 isl_union_set
*domain
;
10671 isl_multi_union_pw_aff
*mupa
, *mupa2
;
10672 isl_schedule_node
*node
;
10673 isl_multi_val
*sizes
;
10675 opt
= tile_tests
[i
].scale_tile
;
10676 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
10677 opt
= tile_tests
[i
].shift_point
;
10678 isl_options_set_tile_shift_point_loops(ctx
, opt
);
10680 str
= tile_tests
[i
].domain
;
10681 domain
= isl_union_set_read_from_str(ctx
, str
);
10682 node
= isl_schedule_node_from_domain(domain
);
10683 node
= isl_schedule_node_child(node
, 0);
10684 str
= tile_tests
[i
].schedule
;
10685 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10686 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
10687 str
= tile_tests
[i
].sizes
;
10688 sizes
= isl_multi_val_read_from_str(ctx
, str
);
10689 node
= isl_schedule_node_band_tile(node
, sizes
);
10691 str
= tile_tests
[i
].tile
;
10692 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10693 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10694 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
10695 isl_multi_union_pw_aff_free(mupa
);
10696 isl_multi_union_pw_aff_free(mupa2
);
10698 node
= isl_schedule_node_child(node
, 0);
10700 str
= tile_tests
[i
].point
;
10701 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
10702 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
10703 if (equal
>= 0 && equal
)
10704 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
10706 isl_multi_union_pw_aff_free(mupa
);
10707 isl_multi_union_pw_aff_free(mupa2
);
10709 isl_schedule_node_free(node
);
10714 isl_die(ctx
, isl_error_unknown
,
10715 "unexpected result", return -1);
10718 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
10719 isl_options_set_tile_shift_point_loops(ctx
, shift
);
10724 /* Check that the domain hash of a space is equal to the hash
10725 * of the domain of the space, both ignoring parameters.
10727 static int test_domain_hash(isl_ctx
*ctx
)
10731 uint32_t hash1
, hash2
;
10733 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
10734 space
= isl_map_get_space(map
);
10736 hash1
= isl_space_get_tuple_domain_hash(space
);
10737 space
= isl_space_domain(space
);
10738 hash2
= isl_space_get_tuple_hash(space
);
10739 isl_space_free(space
);
10743 if (hash1
!= hash2
)
10744 isl_die(ctx
, isl_error_unknown
,
10745 "domain hash not equal to hash of domain", return -1);
10750 /* Check that a universe basic set that is not obviously equal to the universe
10751 * is still recognized as being equal to the universe.
10753 static int test_universe(isl_ctx
*ctx
)
10756 isl_basic_set
*bset
;
10759 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
10760 bset
= isl_basic_set_read_from_str(ctx
, s
);
10761 is_univ
= isl_basic_set_is_universe(bset
);
10762 isl_basic_set_free(bset
);
10767 isl_die(ctx
, isl_error_unknown
,
10768 "not recognized as universe set", return -1);
10773 /* Sets for which chambers are computed and checked.
10775 const char *chambers_tests
[] = {
10776 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
10777 "z >= 0 and z <= C - y and z <= B - x - y }",
10780 /* Add the domain of "cell" to "cells".
10782 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
10784 isl_basic_set_list
**cells
= user
;
10785 isl_basic_set
*dom
;
10787 dom
= isl_cell_get_domain(cell
);
10788 isl_cell_free(cell
);
10789 *cells
= isl_basic_set_list_add(*cells
, dom
);
10791 return *cells
? isl_stat_ok
: isl_stat_error
;
10794 /* Check that the elements of "list" are pairwise disjoint.
10796 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
10801 n
= isl_basic_set_list_n_basic_set(list
);
10803 return isl_stat_error
;
10805 for (i
= 0; i
< n
; ++i
) {
10806 isl_basic_set
*bset_i
;
10808 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
10809 for (j
= i
+ 1; j
< n
; ++j
) {
10810 isl_basic_set
*bset_j
;
10813 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
10814 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
10815 isl_basic_set_free(bset_j
);
10817 isl_die(isl_basic_set_list_get_ctx(list
),
10818 isl_error_unknown
, "not disjoint",
10820 if (disjoint
< 0 || !disjoint
)
10823 isl_basic_set_free(bset_i
);
10825 return isl_stat_error
;
10828 return isl_stat_ok
;
10831 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
10832 * are pairwise disjoint.
10834 static int test_chambers(isl_ctx
*ctx
)
10838 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
10839 isl_basic_set
*bset
;
10840 isl_vertices
*vertices
;
10841 isl_basic_set_list
*cells
;
10844 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
10845 vertices
= isl_basic_set_compute_vertices(bset
);
10846 cells
= isl_basic_set_list_alloc(ctx
, 0);
10847 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
10849 cells
= isl_basic_set_list_free(cells
);
10850 ok
= check_pairwise_disjoint(cells
);
10851 isl_basic_set_list_free(cells
);
10852 isl_vertices_free(vertices
);
10853 isl_basic_set_free(bset
);
10864 int (*fn
)(isl_ctx
*ctx
);
10866 { "universe", &test_universe
},
10867 { "domain hash", &test_domain_hash
},
10868 { "dual", &test_dual
},
10869 { "dependence analysis", &test_flow
},
10870 { "val", &test_val
},
10871 { "compute divs", &test_compute_divs
},
10872 { "partial lexmin", &test_partial_lexmin
},
10873 { "simplify", &test_simplify
},
10874 { "curry", &test_curry
},
10875 { "piecewise multi affine expressions", &test_pw_multi_aff
},
10876 { "multi piecewise affine expressions", &test_multi_pw_aff
},
10877 { "conversion", &test_conversion
},
10878 { "list", &test_list
},
10879 { "align parameters", &test_align_parameters
},
10880 { "drop unused parameters", &test_drop_unused_parameters
},
10881 { "preimage", &test_preimage
},
10882 { "pullback", &test_pullback
},
10883 { "AST", &test_ast
},
10884 { "AST build", &test_ast_build
},
10885 { "AST generation", &test_ast_gen
},
10886 { "eliminate", &test_eliminate
},
10887 { "deltas_map", &test_deltas_map
},
10888 { "residue class", &test_residue_class
},
10889 { "div", &test_div
},
10890 { "slice", &test_slice
},
10891 { "fixed power", &test_fixed_power
},
10892 { "sample", &test_sample
},
10893 { "empty projection", &test_empty_projection
},
10894 { "output", &test_output
},
10895 { "vertices", &test_vertices
},
10896 { "chambers", &test_chambers
},
10897 { "fixed", &test_fixed
},
10898 { "equal", &test_equal
},
10899 { "disjoint", &test_disjoint
},
10900 { "product", &test_product
},
10901 { "dim_max", &test_dim_max
},
10902 { "affine", &test_aff
},
10903 { "injective", &test_injective
},
10904 { "schedule (whole component)", &test_schedule_whole
},
10905 { "schedule (incremental)", &test_schedule_incremental
},
10906 { "schedule tree", &test_schedule_tree
},
10907 { "schedule tree prefix", &test_schedule_tree_prefix
},
10908 { "schedule tree grouping", &test_schedule_tree_group
},
10909 { "tile", &test_tile
},
10910 { "union map", &test_union_map
},
10911 { "union_pw", &test_union_pw
},
10912 { "locus", &test_locus
},
10913 { "eval", &test_eval
},
10914 { "parse", &test_parse
},
10915 { "single-valued", &test_sv
},
10916 { "recession cone", &test_recession_cone
},
10917 { "affine hull", &test_affine_hull
},
10918 { "simple_hull", &test_simple_hull
},
10919 { "box hull", &test_box_hull
},
10920 { "coalesce", &test_coalesce
},
10921 { "factorize", &test_factorize
},
10922 { "subset", &test_subset
},
10923 { "subtract", &test_subtract
},
10924 { "intersect", &test_intersect
},
10925 { "lexmin", &test_lexmin
},
10926 { "min", &test_min
},
10927 { "set lower bounds", &test_min_mpa
},
10928 { "gist", &test_gist
},
10929 { "piecewise quasi-polynomials", &test_pwqp
},
10930 { "lift", &test_lift
},
10931 { "bind parameters", &test_bind
},
10932 { "unbind parameters", &test_unbind
},
10933 { "bound", &test_bound
},
10934 { "get lists", &test_get_list
},
10935 { "union", &test_union
},
10936 { "split periods", &test_split_periods
},
10937 { "lexicographic order", &test_lex
},
10938 { "bijectivity", &test_bijective
},
10939 { "dataflow analysis", &test_dep
},
10940 { "reading", &test_read
},
10941 { "bounded", &test_bounded
},
10942 { "construction", &test_construction
},
10943 { "dimension manipulation", &test_dim
},
10944 { "map application", &test_application
},
10945 { "convex hull", &test_convex_hull
},
10946 { "transitive closure", &test_closure
},
10947 { "isl_bool", &test_isl_bool
},
10950 int main(int argc
, char **argv
)
10953 struct isl_ctx
*ctx
;
10954 struct isl_options
*options
;
10956 options
= isl_options_new_with_defaults();
10958 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
10960 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
10961 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
10962 printf("%s\n", tests
[i
].name
);
10963 if (tests
[i
].fn(ctx
) < 0)