add isl_union_{set,map}_plain_unshifted_simple_hull
[isl.git] / isl_test.c
blob7cd51c32d83ac85a7efe855da0d9ba1e8a9b7442
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
5 * Copyright 2014 INRIA Rocquencourt
6 * Copyright 2022 Cerebras Systems
8 * Use of this software is governed by the MIT license
10 * Written by Sven Verdoolaege, K.U.Leuven, Departement
11 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
12 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
13 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
14 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
15 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
16 * B.P. 105 - 78153 Le Chesnay, France
17 * and Cerebras Systems, 1237 E Arques Ave, Sunnyvale, CA, USA
20 #include <assert.h>
21 #include <stdio.h>
22 #include <limits.h>
23 #include <isl_ctx_private.h>
24 #include <isl_map_private.h>
25 #include <isl_aff_private.h>
26 #include <isl_space_private.h>
27 #include <isl/id.h>
28 #include <isl/set.h>
29 #include <isl/flow.h>
30 #include <isl_constraint_private.h>
31 #include <isl/polynomial.h>
32 #include <isl/union_set.h>
33 #include <isl/union_map.h>
34 #include <isl_factorization.h>
35 #include <isl/schedule.h>
36 #include <isl/schedule_node.h>
37 #include <isl_options_private.h>
38 #include <isl_vertices_private.h>
39 #include <isl/ast_build.h>
40 #include <isl/val.h>
41 #include <isl/ilp.h>
42 #include <isl_ast_build_expr.h>
43 #include <isl/options.h>
45 #include "isl_srcdir.c"
47 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
49 static char *get_filename(isl_ctx *ctx, const char *name, const char *suffix) {
50 char *filename;
51 int length;
52 char *pattern = "%s/test_inputs/%s.%s";
54 length = strlen(pattern) - 6 + strlen(srcdir) + strlen(name)
55 + strlen(suffix) + 1;
56 filename = isl_alloc_array(ctx, char, length);
58 if (!filename)
59 return NULL;
61 sprintf(filename, pattern, srcdir, name, suffix);
63 return filename;
66 void test_parse_map(isl_ctx *ctx, const char *str)
68 isl_map *map;
70 map = isl_map_read_from_str(ctx, str);
71 assert(map);
72 isl_map_free(map);
75 int test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
77 isl_map *map, *map2;
78 int equal;
80 map = isl_map_read_from_str(ctx, str);
81 map2 = isl_map_read_from_str(ctx, str2);
82 equal = isl_map_is_equal(map, map2);
83 isl_map_free(map);
84 isl_map_free(map2);
86 if (equal < 0)
87 return -1;
88 if (!equal)
89 isl_die(ctx, isl_error_unknown, "maps not equal",
90 return -1);
92 return 0;
95 void test_parse_pwqp(isl_ctx *ctx, const char *str)
97 isl_pw_qpolynomial *pwqp;
99 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
100 assert(pwqp);
101 isl_pw_qpolynomial_free(pwqp);
104 static void test_parse_pwaff(isl_ctx *ctx, const char *str)
106 isl_pw_aff *pwaff;
108 pwaff = isl_pw_aff_read_from_str(ctx, str);
109 assert(pwaff);
110 isl_pw_aff_free(pwaff);
113 /* Check that we can read an isl_multi_val from "str" without errors.
115 static int test_parse_multi_val(isl_ctx *ctx, const char *str)
117 isl_multi_val *mv;
119 mv = isl_multi_val_read_from_str(ctx, str);
120 isl_multi_val_free(mv);
122 return mv ? 0 : -1;
125 /* String descriptions of multi piecewise affine expressions
126 * that are used for testing printing and parsing.
128 static const char *reparse_multi_pw_aff_tests[] = {
129 "{ A[x, y] -> [] : x + y >= 0 }",
130 "{ A[x, y] -> B[] : x + y >= 0 }",
131 "{ A[x, y] -> [x] : x + y >= 0 }",
132 "[N] -> { A[x, y] -> [x] : x + y <= N }",
133 "{ A[x, y] -> [x, y] : x + y >= 0 }",
134 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
135 "[N] -> { [] : N >= 0 }",
136 "[N] -> { [] : N >= 0 }",
137 "[N] -> { [N] : N >= 0 }",
138 "[N] -> { [N, N + 1] : N >= 0 }",
139 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
140 "{ [a] -> [b = a] }",
141 "{ [a] -> [b = a] : a >= 0 }",
144 #undef BASE
145 #define BASE multi_pw_aff
147 #include "check_reparse_templ.c"
148 #include "check_reparse_test_templ.c"
150 /* String descriptions that cannot be parsed
151 * as multi piecewise affine expressions.
153 static const char *parse_multi_pw_aff_fail_tests[] = {
154 "{ [a] -> [b] : b = a }",
155 "{ [a] -> [b = a] : b >= 0 }",
158 #include "check_parse_fail_test_templ.c"
160 /* String descriptions of piecewise multi affine expressions
161 * that are used for testing printing and parsing.
163 static const char *reparse_pw_multi_aff_tests[] = {
164 "{ [x] -> [x] }",
165 "{ [x] -> [x % 4] }",
166 "{ [x] -> [x % 4] : x mod 3 = 1 }",
167 "{ [x, x] -> [x % 4] }",
168 "{ [x, x + 1] -> [x % 4] : x mod 3 = 1 }",
169 "{ [x, x mod 2] -> [x % 4] }",
170 "{ [a] -> [a//2] : exists (e0: 8*floor((-a + e0)/8) <= -8 - a + 8e0) }",
171 "{ [a, b] -> [(2*floor((a)/8) + floor((b)/6))] }",
172 "{ [] : false }",
173 "{ A[*,*] -> B[0,0] : false }",
176 #undef BASE
177 #define BASE pw_multi_aff
179 #include "check_reparse_templ.c"
180 #include "check_reparse_test_templ.c"
182 /* Test parsing of piecewise multi affine expressions by printing
183 * the expressions and checking that parsing the output results
184 * in the same expression.
185 * Do this for an expression converted from a map with an output
186 * dimension name that is equal to an automatically generated name, and
187 * a set of expressions parsed from strings.
189 static isl_stat test_parse_pma(isl_ctx *ctx)
191 isl_map *map;
192 isl_pw_multi_aff *pma;
194 map = isl_map_read_from_str(ctx, "{ [a, a] -> [i1 = a + 1] }");
195 pma = isl_pw_multi_aff_from_map(map);
196 if (check_reparse_pw_multi_aff(ctx, pma) < 0)
197 return isl_stat_error;
199 if (check_reparse_pw_multi_aff_tests(ctx) < 0)
200 return isl_stat_error;
202 return isl_stat_ok;
205 /* String descriptions that cannot be parsed
206 * as union piecewise multi affine expressions.
208 static const char *parse_union_pw_multi_aff_fail_tests[] = {
209 "{ [a] -> [b] : b = a }",
210 "{ [a] -> [b = a] : b >= 0 }",
213 #undef BASE
214 #define BASE union_pw_multi_aff
216 #include "check_parse_fail_test_templ.c"
218 /* Test parsing of union piecewise multi affine expressions.
220 * In particular, check some cases where parsing is supposed to fail.
222 static isl_stat test_parse_upma(isl_ctx *ctx)
224 if (check_parse_union_pw_multi_aff_fail_tests(ctx) < 0)
225 return isl_stat_error;
227 return isl_stat_ok;
230 /* Test parsing of multi piecewise affine expressions by printing
231 * the expressions and checking that parsing the output results
232 * in the same expression.
233 * Do this for a couple of manually constructed expressions,
234 * an expression converted from a map with an output dimension name
235 * that is equal to an automatically generated name, and
236 * a set of expressions parsed from strings.
238 * Additionally, check some cases where parsing is supposed to fail.
240 static int test_parse_mpa(isl_ctx *ctx)
242 isl_space *space;
243 isl_set *dom;
244 isl_map *map;
245 isl_pw_multi_aff *pma;
246 isl_multi_pw_aff *mpa;
247 isl_stat r;
249 space = isl_space_set_alloc(ctx, 0, 0);
250 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
251 mpa = isl_multi_pw_aff_zero(space);
252 r = check_reparse_multi_pw_aff(ctx, mpa);
253 if (r < 0)
254 return -1;
256 space = isl_space_set_alloc(ctx, 1, 0);
257 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
258 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
259 dom = isl_set_universe(isl_space_params(isl_space_copy(space)));
260 dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5);
261 mpa = isl_multi_pw_aff_zero(space);
262 mpa = isl_multi_pw_aff_intersect_domain(mpa, dom);
263 r = check_reparse_multi_pw_aff(ctx, mpa);
264 if (r < 0)
265 return -1;
267 map = isl_map_read_from_str(ctx, "{ [a, a] -> [i1 = a + 1] }");
268 pma = isl_pw_multi_aff_from_map(map);
269 mpa = isl_multi_pw_aff_from_pw_multi_aff(pma);
270 if (check_reparse_multi_pw_aff(ctx, mpa) < 0)
271 return -1;
273 if (check_reparse_multi_pw_aff_tests(ctx) < 0)
274 return -1;
275 if (check_parse_multi_pw_aff_fail_tests(ctx) < 0)
276 return -1;
278 return 0;
281 /* String descriptions of multi union piecewise affine expressions
282 * that are used for testing printing and parsing.
284 static const char *reparse_multi_union_pw_aff_tests[] = {
285 "[]",
286 "A[]",
287 "A[B[] -> C[]]",
288 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
289 "(A[] : { })",
290 "[N] -> (A[] : { })",
291 "[N] -> (A[] : { : N >= 0 })",
292 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
293 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
294 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
295 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
296 "{ S[x] : x > 0; T[y] : y >= 0 })",
297 "A[{ }]",
298 "A[{ }, { S[x] -> [x + 1]; T[x] -> [x] }]",
301 #undef BASE
302 #define BASE multi_union_pw_aff
304 #include "check_reparse_templ.c"
305 #include "check_reparse_test_templ.c"
307 /* Test parsing of multi union piecewise affine expressions by printing
308 * the expressions and checking that parsing the output results
309 * in the same expression.
310 * Do this for a couple of manually constructed expressions and
311 * a set of expressions parsed from strings.
313 static int test_parse_mupa(isl_ctx *ctx)
315 isl_space *space;
316 isl_multi_union_pw_aff *mupa;
317 isl_set *dom;
318 isl_union_set *uset;
319 isl_stat r;
321 space = isl_space_set_alloc(ctx, 0, 0);
322 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
323 mupa = isl_multi_union_pw_aff_zero(space);
324 r = check_reparse_multi_union_pw_aff(ctx, mupa);
325 if (r < 0)
326 return -1;
328 space = isl_space_set_alloc(ctx, 1, 0);
329 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
330 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
331 dom = isl_set_universe(space);
332 dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5);
333 uset = isl_union_set_from_set(dom);
334 space = isl_space_set_alloc(ctx, 1, 0);
335 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
336 space = isl_space_set_tuple_name(space, isl_dim_set, "B");
337 mupa = isl_multi_union_pw_aff_zero(space);
338 mupa = isl_multi_union_pw_aff_intersect_domain(mupa, uset);
339 r = check_reparse_multi_union_pw_aff(ctx, mupa);
340 if (r < 0)
341 return -1;
343 if (check_reparse_multi_union_pw_aff_tests(ctx) < 0)
344 return -1;
346 return 0;
349 /* Test parsing of multi expressions.
351 static int test_parse_multi(isl_ctx *ctx)
353 if (test_parse_mpa(ctx) < 0)
354 return -1;
355 if (test_parse_mupa(ctx) < 0)
356 return -1;
358 return 0;
361 /* Pairs of binary relation representations that should represent
362 * the same binary relations.
364 struct {
365 const char *map1;
366 const char *map2;
367 } parse_map_equal_tests[] = {
368 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
369 "{ [x, y] : 2y >= 6 - x }" },
370 { "{ [x,y] : x <= min(y, 2*y+3) }",
371 "{ [x,y] : x <= y, 2*y + 3 }" },
372 { "{ [x,y] : x >= min(y, 2*y+3) }",
373 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
374 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
375 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
376 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
377 "{ [i,j] -> [min(i,j)] }" },
378 { "{ [i,j] : i != j }",
379 "{ [i,j] : i < j or i > j }" },
380 { "{ [i,j] : (i+1)*2 >= j }",
381 "{ [i, j] : j <= 2 + 2i }" },
382 { "{ [i] -> [i > 0 ? 4 : 5] }",
383 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
384 { "[N=2,M] -> { [i=[(M+N)/4]] }",
385 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
386 { "{ [x] : x >= 0 }",
387 "{ [x] : x-0 >= 0 }" },
388 { "{ [i] : ((i > 10)) }",
389 "{ [i] : i >= 11 }" },
390 { "{ [i] -> [0] }",
391 "{ [i] -> [0 * i] }" },
392 { "{ [a] -> [b] : (not false) }",
393 "{ [a] -> [b] : true }" },
394 { "{ [i] : i/2 <= 5 }",
395 "{ [i] : i <= 10 }" },
396 { "{Sym=[n] [i] : i <= n }",
397 "[n] -> { [i] : i <= n }" },
398 { "{ [*] }",
399 "{ [a] }" },
400 { "{ [i] : 2*floor(i/2) = i }",
401 "{ [i] : exists a : i = 2 a }" },
402 { "{ [a] -> [b] : a = 5 implies b = 5 }",
403 "{ [a] -> [b] : a != 5 or b = 5 }" },
404 { "{ [a] -> [a - 1 : a > 0] }",
405 "{ [a] -> [a - 1] : a > 0 }" },
406 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
407 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
408 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
409 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
410 { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
411 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
412 { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
413 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
414 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
415 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
416 { "{ [a,b] -> [i,j] : a,b << i,j }",
417 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
418 { "{ [a,b] -> [i,j] : a,b <<= i,j }",
419 "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" },
420 { "{ [a,b] -> [i,j] : a,b >> i,j }",
421 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
422 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
423 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
424 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
425 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
426 "8c < n - 32a and i < n and c >= 0 and "
427 "c <= 3 and c >= -4a) }",
428 "{ [n] -> [i] : 0 <= i < n }" },
429 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
430 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
431 "{ [x] -> [] : 0 <= x <= 15 }" },
432 { "{ [x] -> [x] : }",
433 "{ [x] -> [x] }" },
434 { "{ [x=4:5] -> [x + 1] }",
435 "{ [x] -> [x + 1] : 4 <= x <= 5 }" },
436 { "{ [x=4:5] -> [x + 1 : x + 1] }",
437 "{ [x=4:5] -> [x + 1] }" },
438 { "{ [x] -> [x - 1 : x + 1] }",
439 "{ [x] -> [y] : x - 1 <= y <= x + 1 }" },
440 { "{ [x=4:] -> [x + 1] }",
441 "{ [x] -> [x + 1] : 4 <= x }" },
442 { "{ [x=:5] -> [x + 1] }",
443 "{ [x] -> [x + 1] : x <= 5 }" },
444 { "{ [x=:] -> [x + 1] }",
445 "{ [x] -> [x + 1] }" },
446 { "{ [:] -> [:] }",
447 "{ [x] -> [y] }" },
448 { "{ [x, x//4] }",
449 "{ [x, floor(x/4)] }" },
450 { "{ [10//4] }",
451 "{ [2] }" },
452 { "{ [-1//4] }",
453 "{ [-1] }" },
454 { "{ [0-1//4] }",
455 "{ [0] }" },
456 { "{ [- 1//4] }",
457 "{ [-1] }" },
458 { "{ [0 - 1//4] }",
459 "{ [0] }" },
460 { "{ [0--1//4] }",
461 "{ [1] }" },
462 { "{ [0 - -1//4] }",
463 "{ [1] }" },
464 { "{ [-2^2:2^2-1] }",
465 "{ [-4:3] }" },
466 { "{ [2*-2] }",
467 "{ [-4] }" },
468 { "{ [i,i*-2] }",
469 "{ [i,-2i] }" },
470 { "{ [a = 0:3, b = 0:15, c = 0:15, d] : "
471 "256*floor((-1 - (256a + 16b + c))/256) >= d }",
472 "{ [a = 0:3, b = 0:15, c = 0:15, d] : 256a <= -256 - d }" },
473 { "[a, b, c, d] -> { [max(a,b,c,d)] }",
474 "[a, b, c, d] -> { [a] : b < a and c < a and d < a; "
475 "[b] : b >= a and c < b and d < b; "
476 "[c] : c >= a and c >= b and d < c; "
477 "[d] : d >= a and d >= b and d >= c }" },
478 { "[a, b, c, d] -> { [min(a,b,c,d)] }",
479 "[a, b, c, d] -> { [a] : b >= a and c >= a and d >= a; "
480 "[b] : b < a and c >= b and d >= b; "
481 "[c] : c < b and c < a and d >= c; "
482 "[d] : d < c and d < b and d < a }" },
485 int test_parse(struct isl_ctx *ctx)
487 int i;
488 isl_map *map, *map2;
489 const char *str, *str2;
491 if (test_parse_multi_val(ctx, "{ A[B[2] -> C[5, 7]] }") < 0)
492 return -1;
493 if (test_parse_multi_val(ctx, "[n] -> { [2] }") < 0)
494 return -1;
495 if (test_parse_multi_val(ctx, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
496 return -1;
497 if (test_parse_multi(ctx) < 0)
498 return -1;
499 if (test_parse_pma(ctx) < 0)
500 return -1;
501 if (test_parse_upma(ctx) < 0)
502 return -1;
504 str = "{ [i] -> [-i] }";
505 map = isl_map_read_from_str(ctx, str);
506 assert(map);
507 isl_map_free(map);
509 str = "{ A[i] -> L[([i/3])] }";
510 map = isl_map_read_from_str(ctx, str);
511 assert(map);
512 isl_map_free(map);
514 test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
515 test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : "
516 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
518 for (i = 0; i < ARRAY_SIZE(parse_map_equal_tests); ++i) {
519 str = parse_map_equal_tests[i].map1;
520 str2 = parse_map_equal_tests[i].map2;
521 if (test_parse_map_equal(ctx, str, str2) < 0)
522 return -1;
525 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
526 map = isl_map_read_from_str(ctx, str);
527 str = "{ [new, old] -> [o0, o1] : "
528 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
529 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
530 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
531 map2 = isl_map_read_from_str(ctx, str);
532 assert(isl_map_is_equal(map, map2));
533 isl_map_free(map);
534 isl_map_free(map2);
536 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
537 map = isl_map_read_from_str(ctx, str);
538 str = "{[new,old] -> [(new+1)%2,(old+1)%2]}";
539 map2 = isl_map_read_from_str(ctx, str);
540 assert(isl_map_is_equal(map, map2));
541 isl_map_free(map);
542 isl_map_free(map2);
544 test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
545 test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
546 test_parse_pwaff(ctx, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
547 test_parse_pwqp(ctx, "{ [x] -> ([(x)/2] * [(x)/3]) }");
548 test_parse_pwaff(ctx, "{ [] -> [(100)] }");
550 return 0;
553 static int test_read(isl_ctx *ctx)
555 char *filename;
556 FILE *input;
557 isl_basic_set *bset1, *bset2;
558 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
559 int equal;
561 filename = get_filename(ctx, "set", "omega");
562 assert(filename);
563 input = fopen(filename, "r");
564 assert(input);
566 bset1 = isl_basic_set_read_from_file(ctx, input);
567 bset2 = isl_basic_set_read_from_str(ctx, str);
569 equal = isl_basic_set_is_equal(bset1, bset2);
571 isl_basic_set_free(bset1);
572 isl_basic_set_free(bset2);
573 free(filename);
575 fclose(input);
577 if (equal < 0)
578 return -1;
579 if (!equal)
580 isl_die(ctx, isl_error_unknown,
581 "read sets not equal", return -1);
583 return 0;
586 static int test_bounded(isl_ctx *ctx)
588 isl_set *set;
589 isl_bool bounded;
591 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }");
592 bounded = isl_set_is_bounded(set);
593 isl_set_free(set);
595 if (bounded < 0)
596 return -1;
597 if (!bounded)
598 isl_die(ctx, isl_error_unknown,
599 "set not considered bounded", return -1);
601 set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }");
602 bounded = isl_set_is_bounded(set);
603 assert(!bounded);
604 isl_set_free(set);
606 if (bounded < 0)
607 return -1;
608 if (bounded)
609 isl_die(ctx, isl_error_unknown,
610 "set considered bounded", return -1);
612 set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }");
613 bounded = isl_set_is_bounded(set);
614 isl_set_free(set);
616 if (bounded < 0)
617 return -1;
618 if (bounded)
619 isl_die(ctx, isl_error_unknown,
620 "set considered bounded", return -1);
622 return 0;
625 /* Construct the basic set { [i] : 5 <= i <= N } */
626 static int test_construction_1(isl_ctx *ctx)
628 isl_space *space;
629 isl_local_space *ls;
630 isl_basic_set *bset;
631 isl_constraint *c;
633 space = isl_space_set_alloc(ctx, 1, 1);
634 bset = isl_basic_set_universe(isl_space_copy(space));
635 ls = isl_local_space_from_space(space);
637 c = isl_constraint_alloc_inequality(isl_local_space_copy(ls));
638 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
639 c = isl_constraint_set_coefficient_si(c, isl_dim_param, 0, 1);
640 bset = isl_basic_set_add_constraint(bset, c);
642 c = isl_constraint_alloc_inequality(isl_local_space_copy(ls));
643 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
644 c = isl_constraint_set_constant_si(c, -5);
645 bset = isl_basic_set_add_constraint(bset, c);
647 isl_local_space_free(ls);
648 isl_basic_set_free(bset);
650 return 0;
653 /* Construct the basic set { [x] : -100 <= x <= 100 }
654 * using isl_basic_set_{lower,upper}_bound_val and
655 * check that it is equal the same basic set parsed from a string.
657 static int test_construction_2(isl_ctx *ctx)
659 isl_bool equal;
660 isl_val *v;
661 isl_space *space;
662 isl_basic_set *bset1, *bset2;
664 v = isl_val_int_from_si(ctx, 100);
665 space = isl_space_set_alloc(ctx, 0, 1);
666 bset1 = isl_basic_set_universe(space);
667 bset1 = isl_basic_set_upper_bound_val(bset1, isl_dim_set, 0,
668 isl_val_copy(v));
669 bset1 = isl_basic_set_lower_bound_val(bset1, isl_dim_set, 0,
670 isl_val_neg(v));
671 bset2 = isl_basic_set_read_from_str(ctx, "{ [x] : -100 <= x <= 100 }");
672 equal = isl_basic_set_is_equal(bset1, bset2);
673 isl_basic_set_free(bset1);
674 isl_basic_set_free(bset2);
676 if (equal < 0)
677 return -1;
678 if (!equal)
679 isl_die(ctx, isl_error_unknown,
680 "failed construction", return -1);
682 return 0;
685 /* Basic tests for constructing basic sets.
687 static int test_construction(isl_ctx *ctx)
689 if (test_construction_1(ctx) < 0)
690 return -1;
691 if (test_construction_2(ctx) < 0)
692 return -1;
693 return 0;
696 static int test_dim(isl_ctx *ctx)
698 const char *str;
699 isl_map *map1, *map2;
700 int equal;
702 map1 = isl_map_read_from_str(ctx,
703 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
704 map1 = isl_map_add_dims(map1, isl_dim_in, 1);
705 map2 = isl_map_read_from_str(ctx,
706 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
707 equal = isl_map_is_equal(map1, map2);
708 isl_map_free(map2);
710 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
711 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }");
712 if (equal >= 0 && equal)
713 equal = isl_map_is_equal(map1, map2);
715 isl_map_free(map1);
716 isl_map_free(map2);
718 if (equal < 0)
719 return -1;
720 if (!equal)
721 isl_die(ctx, isl_error_unknown,
722 "unexpected result", return -1);
724 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
725 map1 = isl_map_read_from_str(ctx, str);
726 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
727 map2 = isl_map_read_from_str(ctx, str);
728 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
729 equal = isl_map_is_equal(map1, map2);
730 isl_map_free(map1);
731 isl_map_free(map2);
733 if (equal < 0)
734 return -1;
735 if (!equal)
736 isl_die(ctx, isl_error_unknown,
737 "unexpected result", return -1);
739 return 0;
742 #undef BASE
743 #define BASE multi_val
744 #include "isl_test_plain_equal_templ.c"
746 #undef BASE
747 #define BASE multi_aff
748 #include "isl_test_plain_equal_templ.c"
750 /* Check that "val" is equal to the value described by "str".
751 * If "str" is "NaN", then check for a NaN value explicitly.
753 static isl_stat val_check_equal(__isl_keep isl_val *val, const char *str)
755 isl_bool ok, is_nan;
756 isl_ctx *ctx;
757 isl_val *res;
759 if (!val)
760 return isl_stat_error;
762 ctx = isl_val_get_ctx(val);
763 res = isl_val_read_from_str(ctx, str);
764 is_nan = isl_val_is_nan(res);
765 if (is_nan < 0)
766 ok = isl_bool_error;
767 else if (is_nan)
768 ok = isl_val_is_nan(val);
769 else
770 ok = isl_val_eq(val, res);
771 isl_val_free(res);
772 if (ok < 0)
773 return isl_stat_error;
774 if (!ok)
775 isl_die(ctx, isl_error_unknown,
776 "unexpected result", return isl_stat_error);
777 return isl_stat_ok;
780 struct {
781 __isl_give isl_val *(*op)(__isl_take isl_val *v);
782 const char *arg;
783 const char *res;
784 } val_un_tests[] = {
785 { &isl_val_neg, "0", "0" },
786 { &isl_val_abs, "0", "0" },
787 { &isl_val_pow2, "0", "1" },
788 { &isl_val_floor, "0", "0" },
789 { &isl_val_ceil, "0", "0" },
790 { &isl_val_neg, "1", "-1" },
791 { &isl_val_neg, "-1", "1" },
792 { &isl_val_neg, "1/2", "-1/2" },
793 { &isl_val_neg, "-1/2", "1/2" },
794 { &isl_val_neg, "infty", "-infty" },
795 { &isl_val_neg, "-infty", "infty" },
796 { &isl_val_neg, "NaN", "NaN" },
797 { &isl_val_abs, "1", "1" },
798 { &isl_val_abs, "-1", "1" },
799 { &isl_val_abs, "1/2", "1/2" },
800 { &isl_val_abs, "-1/2", "1/2" },
801 { &isl_val_abs, "infty", "infty" },
802 { &isl_val_abs, "-infty", "infty" },
803 { &isl_val_abs, "NaN", "NaN" },
804 { &isl_val_floor, "1", "1" },
805 { &isl_val_floor, "-1", "-1" },
806 { &isl_val_floor, "1/2", "0" },
807 { &isl_val_floor, "-1/2", "-1" },
808 { &isl_val_floor, "infty", "infty" },
809 { &isl_val_floor, "-infty", "-infty" },
810 { &isl_val_floor, "NaN", "NaN" },
811 { &isl_val_ceil, "1", "1" },
812 { &isl_val_ceil, "-1", "-1" },
813 { &isl_val_ceil, "1/2", "1" },
814 { &isl_val_ceil, "-1/2", "0" },
815 { &isl_val_ceil, "infty", "infty" },
816 { &isl_val_ceil, "-infty", "-infty" },
817 { &isl_val_ceil, "NaN", "NaN" },
818 { &isl_val_pow2, "-3", "1/8" },
819 { &isl_val_pow2, "-1", "1/2" },
820 { &isl_val_pow2, "1", "2" },
821 { &isl_val_pow2, "2", "4" },
822 { &isl_val_pow2, "3", "8" },
823 { &isl_val_inv, "1", "1" },
824 { &isl_val_inv, "2", "1/2" },
825 { &isl_val_inv, "1/2", "2" },
826 { &isl_val_inv, "-2", "-1/2" },
827 { &isl_val_inv, "-1/2", "-2" },
828 { &isl_val_inv, "0", "NaN" },
829 { &isl_val_inv, "NaN", "NaN" },
830 { &isl_val_inv, "infty", "0" },
831 { &isl_val_inv, "-infty", "0" },
834 /* Perform some basic tests of unary operations on isl_val objects.
836 static int test_un_val(isl_ctx *ctx)
838 int i;
839 isl_val *v;
840 __isl_give isl_val *(*fn)(__isl_take isl_val *v);
842 for (i = 0; i < ARRAY_SIZE(val_un_tests); ++i) {
843 isl_stat r;
845 v = isl_val_read_from_str(ctx, val_un_tests[i].arg);
846 fn = val_un_tests[i].op;
847 v = fn(v);
848 r = val_check_equal(v, val_un_tests[i].res);
849 isl_val_free(v);
850 if (r < 0)
851 return -1;
854 return 0;
857 struct {
858 __isl_give isl_val *(*fn)(__isl_take isl_val *v1,
859 __isl_take isl_val *v2);
860 } val_bin_op[] = {
861 ['+'] = { &isl_val_add },
862 ['-'] = { &isl_val_sub },
863 ['*'] = { &isl_val_mul },
864 ['/'] = { &isl_val_div },
865 ['g'] = { &isl_val_gcd },
866 ['m'] = { &isl_val_min },
867 ['M'] = { &isl_val_max },
870 struct {
871 const char *arg1;
872 unsigned char op;
873 const char *arg2;
874 const char *res;
875 } val_bin_tests[] = {
876 { "0", '+', "0", "0" },
877 { "1", '+', "0", "1" },
878 { "1", '+', "1", "2" },
879 { "1", '-', "1", "0" },
880 { "1", '*', "1", "1" },
881 { "1", '/', "1", "1" },
882 { "2", '*', "3", "6" },
883 { "2", '*', "1/2", "1" },
884 { "2", '*', "1/3", "2/3" },
885 { "2/3", '*', "3/5", "2/5" },
886 { "2/3", '*', "7/5", "14/15" },
887 { "2", '/', "1/2", "4" },
888 { "-2", '/', "-1/2", "4" },
889 { "-2", '/', "1/2", "-4" },
890 { "2", '/', "-1/2", "-4" },
891 { "2", '/', "2", "1" },
892 { "2", '/', "3", "2/3" },
893 { "2/3", '/', "5/3", "2/5" },
894 { "2/3", '/', "5/7", "14/15" },
895 { "0", '/', "0", "NaN" },
896 { "42", '/', "0", "NaN" },
897 { "-42", '/', "0", "NaN" },
898 { "infty", '/', "0", "NaN" },
899 { "-infty", '/', "0", "NaN" },
900 { "NaN", '/', "0", "NaN" },
901 { "0", '/', "NaN", "NaN" },
902 { "42", '/', "NaN", "NaN" },
903 { "-42", '/', "NaN", "NaN" },
904 { "infty", '/', "NaN", "NaN" },
905 { "-infty", '/', "NaN", "NaN" },
906 { "NaN", '/', "NaN", "NaN" },
907 { "0", '/', "infty", "0" },
908 { "42", '/', "infty", "0" },
909 { "-42", '/', "infty", "0" },
910 { "infty", '/', "infty", "NaN" },
911 { "-infty", '/', "infty", "NaN" },
912 { "NaN", '/', "infty", "NaN" },
913 { "0", '/', "-infty", "0" },
914 { "42", '/', "-infty", "0" },
915 { "-42", '/', "-infty", "0" },
916 { "infty", '/', "-infty", "NaN" },
917 { "-infty", '/', "-infty", "NaN" },
918 { "NaN", '/', "-infty", "NaN" },
919 { "1", '-', "1/3", "2/3" },
920 { "1/3", '+', "1/2", "5/6" },
921 { "1/2", '+', "1/2", "1" },
922 { "3/4", '-', "1/4", "1/2" },
923 { "1/2", '-', "1/3", "1/6" },
924 { "infty", '+', "42", "infty" },
925 { "infty", '+', "infty", "infty" },
926 { "42", '+', "infty", "infty" },
927 { "infty", '-', "infty", "NaN" },
928 { "infty", '*', "infty", "infty" },
929 { "infty", '*', "-infty", "-infty" },
930 { "-infty", '*', "infty", "-infty" },
931 { "-infty", '*', "-infty", "infty" },
932 { "0", '*', "infty", "NaN" },
933 { "1", '*', "infty", "infty" },
934 { "infty", '*', "0", "NaN" },
935 { "infty", '*', "42", "infty" },
936 { "42", '-', "infty", "-infty" },
937 { "infty", '+', "-infty", "NaN" },
938 { "4", 'g', "6", "2" },
939 { "5", 'g', "6", "1" },
940 { "42", 'm', "3", "3" },
941 { "42", 'M', "3", "42" },
942 { "3", 'm', "42", "3" },
943 { "3", 'M', "42", "42" },
944 { "42", 'm', "infty", "42" },
945 { "42", 'M', "infty", "infty" },
946 { "42", 'm', "-infty", "-infty" },
947 { "42", 'M', "-infty", "42" },
948 { "42", 'm', "NaN", "NaN" },
949 { "42", 'M', "NaN", "NaN" },
950 { "infty", 'm', "-infty", "-infty" },
951 { "infty", 'M', "-infty", "infty" },
954 /* Perform some basic tests of binary operations on isl_val objects.
956 static int test_bin_val(isl_ctx *ctx)
958 int i;
959 isl_val *v1, *v2, *res;
960 __isl_give isl_val *(*fn)(__isl_take isl_val *v1,
961 __isl_take isl_val *v2);
962 int ok;
964 for (i = 0; i < ARRAY_SIZE(val_bin_tests); ++i) {
965 v1 = isl_val_read_from_str(ctx, val_bin_tests[i].arg1);
966 v2 = isl_val_read_from_str(ctx, val_bin_tests[i].arg2);
967 res = isl_val_read_from_str(ctx, val_bin_tests[i].res);
968 fn = val_bin_op[val_bin_tests[i].op].fn;
969 v1 = fn(v1, v2);
970 if (isl_val_is_nan(res))
971 ok = isl_val_is_nan(v1);
972 else
973 ok = isl_val_eq(v1, res);
974 isl_val_free(v1);
975 isl_val_free(res);
976 if (ok < 0)
977 return -1;
978 if (!ok)
979 isl_die(ctx, isl_error_unknown,
980 "unexpected result", return -1);
983 return 0;
986 /* Perform some basic tests on isl_val objects.
988 static int test_val(isl_ctx *ctx)
990 if (test_un_val(ctx) < 0)
991 return -1;
992 if (test_bin_val(ctx) < 0)
993 return -1;
994 return 0;
997 /* Sets described using existentially quantified variables that
998 * can also be described without.
1000 static const char *elimination_tests[] = {
1001 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
1002 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
1003 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
1006 /* Check that redundant existentially quantified variables are
1007 * getting removed.
1009 static int test_elimination(isl_ctx *ctx)
1011 int i;
1012 isl_size n;
1013 isl_basic_set *bset;
1015 for (i = 0; i < ARRAY_SIZE(elimination_tests); ++i) {
1016 bset = isl_basic_set_read_from_str(ctx, elimination_tests[i]);
1017 n = isl_basic_set_dim(bset, isl_dim_div);
1018 isl_basic_set_free(bset);
1019 if (n < 0)
1020 return -1;
1021 if (n != 0)
1022 isl_die(ctx, isl_error_unknown,
1023 "expecting no existentials", return -1);
1026 return 0;
1029 static int test_div(isl_ctx *ctx)
1031 const char *str;
1032 int empty;
1033 isl_space *space;
1034 isl_set *set;
1035 isl_local_space *ls;
1036 struct isl_basic_set *bset;
1037 struct isl_constraint *c;
1039 /* test 1 */
1040 space = isl_space_set_alloc(ctx, 0, 3);
1041 bset = isl_basic_set_universe(isl_space_copy(space));
1042 ls = isl_local_space_from_space(space);
1044 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1045 c = isl_constraint_set_constant_si(c, -1);
1046 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1047 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
1048 bset = isl_basic_set_add_constraint(bset, c);
1050 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1051 c = isl_constraint_set_constant_si(c, 1);
1052 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1053 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3);
1054 bset = isl_basic_set_add_constraint(bset, c);
1056 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
1058 assert(bset && bset->n_div == 1);
1059 isl_local_space_free(ls);
1060 isl_basic_set_free(bset);
1062 /* test 2 */
1063 space = isl_space_set_alloc(ctx, 0, 3);
1064 bset = isl_basic_set_universe(isl_space_copy(space));
1065 ls = isl_local_space_from_space(space);
1067 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1068 c = isl_constraint_set_constant_si(c, 1);
1069 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1070 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
1071 bset = isl_basic_set_add_constraint(bset, c);
1073 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1074 c = isl_constraint_set_constant_si(c, -1);
1075 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1076 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3);
1077 bset = isl_basic_set_add_constraint(bset, c);
1079 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
1081 assert(bset && bset->n_div == 1);
1082 isl_local_space_free(ls);
1083 isl_basic_set_free(bset);
1085 /* test 3 */
1086 space = isl_space_set_alloc(ctx, 0, 3);
1087 bset = isl_basic_set_universe(isl_space_copy(space));
1088 ls = isl_local_space_from_space(space);
1090 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1091 c = isl_constraint_set_constant_si(c, 1);
1092 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1093 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
1094 bset = isl_basic_set_add_constraint(bset, c);
1096 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1097 c = isl_constraint_set_constant_si(c, -3);
1098 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1099 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 4);
1100 bset = isl_basic_set_add_constraint(bset, c);
1102 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
1104 assert(bset && bset->n_div == 1);
1105 isl_local_space_free(ls);
1106 isl_basic_set_free(bset);
1108 /* test 4 */
1109 space = isl_space_set_alloc(ctx, 0, 3);
1110 bset = isl_basic_set_universe(isl_space_copy(space));
1111 ls = isl_local_space_from_space(space);
1113 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1114 c = isl_constraint_set_constant_si(c, 2);
1115 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1116 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
1117 bset = isl_basic_set_add_constraint(bset, c);
1119 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1120 c = isl_constraint_set_constant_si(c, -1);
1121 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1122 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 6);
1123 bset = isl_basic_set_add_constraint(bset, c);
1125 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
1127 assert(isl_basic_set_is_empty(bset));
1128 isl_local_space_free(ls);
1129 isl_basic_set_free(bset);
1131 /* test 5 */
1132 space = isl_space_set_alloc(ctx, 0, 3);
1133 bset = isl_basic_set_universe(isl_space_copy(space));
1134 ls = isl_local_space_from_space(space);
1136 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1137 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1138 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3);
1139 bset = isl_basic_set_add_constraint(bset, c);
1141 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1142 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1143 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1144 bset = isl_basic_set_add_constraint(bset, c);
1146 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
1148 assert(bset && bset->n_div == 0);
1149 isl_basic_set_free(bset);
1150 isl_local_space_free(ls);
1152 /* test 6 */
1153 space = isl_space_set_alloc(ctx, 0, 3);
1154 bset = isl_basic_set_universe(isl_space_copy(space));
1155 ls = isl_local_space_from_space(space);
1157 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1158 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1159 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 6);
1160 bset = isl_basic_set_add_constraint(bset, c);
1162 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1163 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1164 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1165 bset = isl_basic_set_add_constraint(bset, c);
1167 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
1169 assert(bset && bset->n_div == 1);
1170 isl_basic_set_free(bset);
1171 isl_local_space_free(ls);
1173 /* test 7 */
1174 /* This test is a bit tricky. We set up an equality
1175 * a + 3b + 3c = 6 e0
1176 * Normalization of divs creates _two_ divs
1177 * a = 3 e0
1178 * c - b - e0 = 2 e1
1179 * Afterwards e0 is removed again because it has coefficient -1
1180 * and we end up with the original equality and div again.
1181 * Perhaps we can avoid the introduction of this temporary div.
1183 space = isl_space_set_alloc(ctx, 0, 4);
1184 bset = isl_basic_set_universe(isl_space_copy(space));
1185 ls = isl_local_space_from_space(space);
1187 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1188 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1189 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1190 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -3);
1191 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, 6);
1192 bset = isl_basic_set_add_constraint(bset, c);
1194 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
1196 /* Test disabled for now */
1198 assert(bset && bset->n_div == 1);
1200 isl_local_space_free(ls);
1201 isl_basic_set_free(bset);
1203 /* test 8 */
1204 space = isl_space_set_alloc(ctx, 0, 5);
1205 bset = isl_basic_set_universe(isl_space_copy(space));
1206 ls = isl_local_space_from_space(space);
1208 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1209 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1210 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1211 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, -3);
1212 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 4, 6);
1213 bset = isl_basic_set_add_constraint(bset, c);
1215 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1216 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1217 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 1);
1218 c = isl_constraint_set_constant_si(c, 1);
1219 bset = isl_basic_set_add_constraint(bset, c);
1221 bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1);
1223 /* Test disabled for now */
1225 assert(bset && bset->n_div == 1);
1227 isl_local_space_free(ls);
1228 isl_basic_set_free(bset);
1230 /* test 9 */
1231 space = isl_space_set_alloc(ctx, 0, 4);
1232 bset = isl_basic_set_universe(isl_space_copy(space));
1233 ls = isl_local_space_from_space(space);
1235 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1236 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1237 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -1);
1238 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -2);
1239 bset = isl_basic_set_add_constraint(bset, c);
1241 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1242 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1243 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, 3);
1244 c = isl_constraint_set_constant_si(c, 2);
1245 bset = isl_basic_set_add_constraint(bset, c);
1247 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2);
1249 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
1251 assert(!isl_basic_set_is_empty(bset));
1253 isl_local_space_free(ls);
1254 isl_basic_set_free(bset);
1256 /* test 10 */
1257 space = isl_space_set_alloc(ctx, 0, 3);
1258 bset = isl_basic_set_universe(isl_space_copy(space));
1259 ls = isl_local_space_from_space(space);
1261 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1262 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1263 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -2);
1264 bset = isl_basic_set_add_constraint(bset, c);
1266 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
1268 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
1270 isl_local_space_free(ls);
1271 isl_basic_set_free(bset);
1273 str = "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1274 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1275 set = isl_set_read_from_str(ctx, str);
1276 set = isl_set_compute_divs(set);
1277 isl_set_free(set);
1278 if (!set)
1279 return -1;
1281 if (test_elimination(ctx) < 0)
1282 return -1;
1284 str = "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1285 set = isl_set_read_from_str(ctx, str);
1286 set = isl_set_remove_divs_involving_dims(set, isl_dim_set, 0, 2);
1287 set = isl_set_fix_si(set, isl_dim_set, 2, -3);
1288 empty = isl_set_is_empty(set);
1289 isl_set_free(set);
1290 if (empty < 0)
1291 return -1;
1292 if (!empty)
1293 isl_die(ctx, isl_error_unknown,
1294 "result not as accurate as expected", return -1);
1296 return 0;
1299 void test_application_case(struct isl_ctx *ctx, const char *name)
1301 char *filename;
1302 FILE *input;
1303 struct isl_basic_set *bset1, *bset2;
1304 struct isl_basic_map *bmap;
1306 filename = get_filename(ctx, name, "omega");
1307 assert(filename);
1308 input = fopen(filename, "r");
1309 assert(input);
1311 bset1 = isl_basic_set_read_from_file(ctx, input);
1312 bmap = isl_basic_map_read_from_file(ctx, input);
1314 bset1 = isl_basic_set_apply(bset1, bmap);
1316 bset2 = isl_basic_set_read_from_file(ctx, input);
1318 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1320 isl_basic_set_free(bset1);
1321 isl_basic_set_free(bset2);
1322 free(filename);
1324 fclose(input);
1327 static int test_application(isl_ctx *ctx)
1329 test_application_case(ctx, "application");
1330 test_application_case(ctx, "application2");
1332 return 0;
1335 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
1337 char *filename;
1338 FILE *input;
1339 struct isl_basic_set *bset1, *bset2;
1341 filename = get_filename(ctx, name, "polylib");
1342 assert(filename);
1343 input = fopen(filename, "r");
1344 assert(input);
1346 bset1 = isl_basic_set_read_from_file(ctx, input);
1347 bset2 = isl_basic_set_read_from_file(ctx, input);
1349 bset1 = isl_basic_set_affine_hull(bset1);
1351 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1353 isl_basic_set_free(bset1);
1354 isl_basic_set_free(bset2);
1355 free(filename);
1357 fclose(input);
1360 /* Pairs of sets and the corresponding expected results of
1361 * isl_basic_set_recession_cone.
1363 struct {
1364 const char *set;
1365 const char *cone;
1366 } recession_cone_tests[] = {
1367 { "{ [i] : 0 <= i <= 10 }", "{ [0] }" },
1368 { "{ [i] : 0 <= i }", "{ [i] : 0 <= i }" },
1369 { "{ [i] : i <= 10 }", "{ [i] : i <= 0 }" },
1370 { "{ [i] : false }", "{ [i] : false }" },
1373 /* Perform some basic isl_basic_set_recession_cone tests.
1375 static int test_recession_cone(struct isl_ctx *ctx)
1377 int i;
1379 for (i = 0; i < ARRAY_SIZE(recession_cone_tests); ++i) {
1380 const char *str;
1381 isl_basic_set *bset;
1382 isl_basic_set *cone, *expected;
1383 isl_bool equal;
1385 str = recession_cone_tests[i].set;
1386 bset = isl_basic_set_read_from_str(ctx, str);
1387 str = recession_cone_tests[i].cone;
1388 expected = isl_basic_set_read_from_str(ctx, str);
1389 cone = isl_basic_set_recession_cone(bset);
1390 equal = isl_basic_set_is_equal(cone, expected);
1391 isl_basic_set_free(cone);
1392 isl_basic_set_free(expected);
1393 if (equal < 0)
1394 return -1;
1395 if (!equal)
1396 isl_die(ctx, isl_error_unknown, "unexpected cone",
1397 return -1);
1400 return 0;
1403 int test_affine_hull(struct isl_ctx *ctx)
1405 const char *str;
1406 isl_set *set;
1407 isl_basic_set *bset, *bset2;
1408 isl_size n;
1409 isl_bool subset;
1411 test_affine_hull_case(ctx, "affine2");
1412 test_affine_hull_case(ctx, "affine");
1413 test_affine_hull_case(ctx, "affine3");
1415 str = "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1416 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1417 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1418 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1419 set = isl_set_read_from_str(ctx, str);
1420 bset = isl_set_affine_hull(set);
1421 n = isl_basic_set_dim(bset, isl_dim_div);
1422 isl_basic_set_free(bset);
1423 if (n < 0)
1424 return -1;
1425 if (n != 0)
1426 isl_die(ctx, isl_error_unknown, "not expecting any divs",
1427 return -1);
1429 /* Check that isl_map_affine_hull is not confused by
1430 * the reordering of divs in isl_map_align_divs.
1432 str = "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1433 "32e0 = b and 32e1 = c); "
1434 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1435 set = isl_set_read_from_str(ctx, str);
1436 bset = isl_set_affine_hull(set);
1437 isl_basic_set_free(bset);
1438 if (!bset)
1439 return -1;
1441 str = "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1442 "32e2 = 31 + 31e0 }";
1443 set = isl_set_read_from_str(ctx, str);
1444 bset = isl_set_affine_hull(set);
1445 str = "{ [a] : exists e : a = 32 e }";
1446 bset2 = isl_basic_set_read_from_str(ctx, str);
1447 subset = isl_basic_set_is_subset(bset, bset2);
1448 isl_basic_set_free(bset);
1449 isl_basic_set_free(bset2);
1450 if (subset < 0)
1451 return -1;
1452 if (!subset)
1453 isl_die(ctx, isl_error_unknown, "not as accurate as expected",
1454 return -1);
1456 return 0;
1459 /* Test a special case of isl_set_plain_unshifted_simple_hull
1460 * where older versions of isl would include a redundant constraint
1461 * in the result.
1462 * Check that the result does not have any constraints.
1464 static isl_stat test_plain_unshifted_simple_hull_special(isl_ctx *ctx)
1466 const char *str;
1467 isl_bool is_universe;
1468 isl_set *set;
1469 isl_basic_set *bset;
1471 str = "{[x, y] : x = 0 or 2*((x+y)//2) <= y + 2 }";
1472 set = isl_set_read_from_str(ctx, str);
1473 bset = isl_set_plain_unshifted_simple_hull(set);
1474 is_universe = isl_basic_set_plain_is_universe(bset);
1475 isl_basic_set_free(bset);
1477 if (is_universe < 0)
1478 return isl_stat_error;
1479 if (!is_universe)
1480 isl_die(ctx, isl_error_unknown,
1481 "hull should not have any constraints",
1482 return isl_stat_error);
1484 return isl_stat_ok;
1487 /* Inputs for simple hull tests, consisting of
1488 * the specific simple hull function, the input set and the expected result.
1490 struct {
1491 __isl_give isl_basic_set *(*fn)(__isl_take isl_set *set);
1492 const char *set;
1493 const char *hull;
1494 } simple_hull_tests[] = {
1495 { &isl_set_plain_unshifted_simple_hull,
1496 "{ [i,j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1497 "{ [i,j] : i >= 1 }" },
1498 { &isl_set_plain_unshifted_simple_hull,
1499 "{ [n,i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1500 "(j mod 4 = 2 and k mod 6 = n) }",
1501 "{ [n,i,j,k] : j mod 4 = 2 }" },
1502 { &isl_set_unshifted_simple_hull,
1503 "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1504 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1505 { &isl_set_simple_hull,
1506 "{ [a, b] : b <= 0 and "
1507 "2*floor((-2*floor((b)/2))/5) >= a - floor((b)/2); "
1508 "[a, b] : a mod 2 = 0 }",
1509 "{ [a, b] }" },
1512 /* Basic tests for various simple hull functions.
1514 static int test_various_simple_hull(isl_ctx *ctx)
1516 int i;
1517 isl_set *set;
1518 isl_basic_set *hull, *expected;
1519 isl_bool equal;
1521 for (i = 0; i < ARRAY_SIZE(simple_hull_tests); ++i) {
1522 const char *str;
1523 str = simple_hull_tests[i].set;
1524 set = isl_set_read_from_str(ctx, str);
1525 str = simple_hull_tests[i].hull;
1526 expected = isl_basic_set_read_from_str(ctx, str);
1527 hull = simple_hull_tests[i].fn(set);
1528 equal = isl_basic_set_is_equal(hull, expected);
1529 isl_basic_set_free(hull);
1530 isl_basic_set_free(expected);
1531 if (equal < 0)
1532 return -1;
1533 if (!equal)
1534 isl_die(ctx, isl_error_unknown, "unexpected hull",
1535 return -1);
1538 return 0;
1541 static int test_simple_hull(struct isl_ctx *ctx)
1543 const char *str;
1544 isl_set *set;
1545 isl_basic_set *bset;
1546 isl_bool is_empty;
1548 str = "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1549 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1550 set = isl_set_read_from_str(ctx, str);
1551 bset = isl_set_simple_hull(set);
1552 is_empty = isl_basic_set_is_empty(bset);
1553 isl_basic_set_free(bset);
1555 if (is_empty == isl_bool_error)
1556 return -1;
1558 if (is_empty == isl_bool_false)
1559 isl_die(ctx, isl_error_unknown, "Empty set should be detected",
1560 return -1);
1562 if (test_plain_unshifted_simple_hull_special(ctx) < 0)
1563 return -1;
1564 if (test_various_simple_hull(ctx) < 0)
1565 return -1;
1567 return 0;
1570 /* Inputs for isl_set_get_simple_fixed_box_hull tests.
1571 * "set" is the input set.
1572 * "offset" is the expected box offset.
1573 * "size" is the expected box size.
1575 static struct {
1576 const char *set;
1577 const char *offset;
1578 const char *size;
1579 } box_hull_tests[] = {
1580 { "{ S[x, y] : 0 <= x, y < 10 }", "{ S[0, 0] }", "{ S[10, 10] }" },
1581 { "[N] -> { S[x, y] : N <= x, y < N + 10 }",
1582 "[N] -> { S[N, N] }", "{ S[10, 10] }" },
1583 { "{ S[x, y] : 0 <= x + y, x - y < 10 }",
1584 "{ S[0, -4] }", "{ S[10, 9] }" },
1585 { "{ [i=0:10] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1586 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1587 "{ [3] }", "{ [8] }" },
1588 { "[N] -> { [w = 0:17] : exists (e0: w < 2N and "
1589 "-1 + w <= e0 <= w and 2e0 >= N + w and w <= 2e0 <= 15 + w) }",
1590 "[N] -> { [N] }", "{ [9] }" },
1593 /* Perform basic isl_set_get_simple_fixed_box_hull tests.
1595 static int test_box_hull(struct isl_ctx *ctx)
1597 int i;
1599 for (i = 0; i < ARRAY_SIZE(box_hull_tests); ++i) {
1600 const char *str;
1601 isl_stat r;
1602 isl_set *set;
1603 isl_multi_aff *offset;
1604 isl_multi_val *size;
1605 isl_fixed_box *box;
1607 set = isl_set_read_from_str(ctx, box_hull_tests[i].set);
1608 box = isl_set_get_simple_fixed_box_hull(set);
1609 offset = isl_fixed_box_get_offset(box);
1610 size = isl_fixed_box_get_size(box);
1611 str = box_hull_tests[i].offset;
1612 r = multi_aff_check_plain_equal(offset, str);
1613 str = box_hull_tests[i].size;
1614 if (r >= 0)
1615 r = multi_val_check_plain_equal(size, str);
1616 isl_multi_aff_free(offset);
1617 isl_multi_val_free(size);
1618 isl_fixed_box_free(box);
1619 isl_set_free(set);
1620 if (r < 0)
1621 return -1;
1624 return 0;
1627 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
1629 char *filename;
1630 FILE *input;
1631 struct isl_basic_set *bset1, *bset2;
1632 struct isl_set *set;
1634 filename = get_filename(ctx, name, "polylib");
1635 assert(filename);
1636 input = fopen(filename, "r");
1637 assert(input);
1639 bset1 = isl_basic_set_read_from_file(ctx, input);
1640 bset2 = isl_basic_set_read_from_file(ctx, input);
1642 set = isl_basic_set_union(bset1, bset2);
1643 bset1 = isl_set_convex_hull(set);
1645 bset2 = isl_basic_set_read_from_file(ctx, input);
1647 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1649 isl_basic_set_free(bset1);
1650 isl_basic_set_free(bset2);
1651 free(filename);
1653 fclose(input);
1656 struct {
1657 const char *set;
1658 const char *hull;
1659 } convex_hull_tests[] = {
1660 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1661 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1662 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1663 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1664 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1665 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1666 "i2 <= 5 and i2 >= 4; "
1667 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1668 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1669 "i2 <= 5 + i0 and i2 >= i0 }" },
1670 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1671 "{ [x, y] : 1 = 0 }" },
1672 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1673 "[x, y, 0] : x >= 0 and y < 0 }",
1674 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1675 { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and "
1676 "c <= a; "
1677 "[0, 2, 0]; [3, 1, 0] }",
1678 "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and "
1679 "5c <= 6 - a - 3b }" },
1682 static int test_convex_hull_algo(isl_ctx *ctx, int convex)
1684 int i;
1685 int orig_convex = ctx->opt->convex;
1686 ctx->opt->convex = convex;
1688 test_convex_hull_case(ctx, "convex0");
1689 test_convex_hull_case(ctx, "convex1");
1690 test_convex_hull_case(ctx, "convex2");
1691 test_convex_hull_case(ctx, "convex3");
1692 test_convex_hull_case(ctx, "convex4");
1693 test_convex_hull_case(ctx, "convex5");
1694 test_convex_hull_case(ctx, "convex6");
1695 test_convex_hull_case(ctx, "convex7");
1696 test_convex_hull_case(ctx, "convex8");
1697 test_convex_hull_case(ctx, "convex9");
1698 test_convex_hull_case(ctx, "convex10");
1699 test_convex_hull_case(ctx, "convex11");
1700 test_convex_hull_case(ctx, "convex12");
1701 test_convex_hull_case(ctx, "convex13");
1702 test_convex_hull_case(ctx, "convex14");
1703 test_convex_hull_case(ctx, "convex15");
1705 for (i = 0; i < ARRAY_SIZE(convex_hull_tests); ++i) {
1706 isl_set *set1, *set2;
1707 int equal;
1709 set1 = isl_set_read_from_str(ctx, convex_hull_tests[i].set);
1710 set2 = isl_set_read_from_str(ctx, convex_hull_tests[i].hull);
1711 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
1712 equal = isl_set_is_equal(set1, set2);
1713 isl_set_free(set1);
1714 isl_set_free(set2);
1716 if (equal < 0)
1717 return -1;
1718 if (!equal)
1719 isl_die(ctx, isl_error_unknown,
1720 "unexpected convex hull", return -1);
1723 ctx->opt->convex = orig_convex;
1725 return 0;
1728 static int test_convex_hull(isl_ctx *ctx)
1730 if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM) < 0)
1731 return -1;
1732 if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP) < 0)
1733 return -1;
1734 return 0;
1737 /* Check that computing the gist of "map" with respect to "context"
1738 * does not make any copy of "map" get marked empty.
1739 * Earlier versions of isl would end up doing that.
1741 static isl_stat test_gist_empty_pair(isl_ctx *ctx, const char *map,
1742 const char *context)
1744 isl_map *m1, *m2, *m3;
1745 isl_bool empty_before, empty_after;
1747 m1 = isl_map_read_from_str(ctx, map);
1748 m2 = isl_map_read_from_str(ctx, context);
1749 m3 = isl_map_copy(m1);
1750 empty_before = isl_map_is_empty(m3);
1751 m1 = isl_map_gist(m1, m2);
1752 empty_after = isl_map_is_empty(m3);
1753 isl_map_free(m1);
1754 isl_map_free(m3);
1756 if (empty_before < 0 || empty_after < 0)
1757 return isl_stat_error;
1758 if (empty_before)
1759 isl_die(ctx, isl_error_unknown, "map should not be empty",
1760 return isl_stat_error);
1761 if (empty_after)
1762 isl_die(ctx, isl_error_unknown, "map should still not be empty",
1763 return isl_stat_error);
1765 return isl_stat_ok;
1768 /* Check that computing a gist does not make any copy of the input
1769 * get marked empty.
1770 * Earlier versions of isl would end up doing that on some pairs of inputs.
1772 static isl_stat test_gist_empty(isl_ctx *ctx)
1774 const char *map, *context;
1776 map = "{ [] -> [a, b, c] : 2b = 1 + a }";
1777 context = "{ [] -> [a, b, c] : 2c = 2 + a }";
1778 if (test_gist_empty_pair(ctx, map, context) < 0)
1779 return isl_stat_error;
1780 map = "{ [] -> [0, 0] }";
1781 context = "{ [] -> [a, b] : a > b }";
1782 if (test_gist_empty_pair(ctx, map, context) < 0)
1783 return isl_stat_error;
1785 return isl_stat_ok;
1788 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1790 struct {
1791 const char *map;
1792 const char *context;
1793 const char *gist;
1794 } plain_gist_tests[] = {
1795 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1796 "{ [i] -> [j] : i >= 1 }",
1797 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1798 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1799 "(j mod 4 = 2 and k mod 6 = n) }",
1800 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1801 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1802 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1803 "{ [i] -> [j] : i > j }",
1804 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1807 /* Basic tests for isl_map_plain_gist_basic_map.
1809 static int test_plain_gist(isl_ctx *ctx)
1811 int i;
1813 for (i = 0; i < ARRAY_SIZE(plain_gist_tests); ++i) {
1814 const char *str;
1815 int equal;
1816 isl_map *map, *gist;
1817 isl_basic_map *context;
1819 map = isl_map_read_from_str(ctx, plain_gist_tests[i].map);
1820 str = plain_gist_tests[i].context;
1821 context = isl_basic_map_read_from_str(ctx, str);
1822 map = isl_map_plain_gist_basic_map(map, context);
1823 gist = isl_map_read_from_str(ctx, plain_gist_tests[i].gist);
1824 equal = isl_map_is_equal(map, gist);
1825 isl_map_free(map);
1826 isl_map_free(gist);
1827 if (equal < 0)
1828 return -1;
1829 if (!equal)
1830 isl_die(ctx, isl_error_unknown,
1831 "incorrect gist result", return -1);
1834 return 0;
1837 /* Check that isl_set_gist behaves as expected.
1839 static int test_gist(struct isl_ctx *ctx)
1841 const char *str;
1842 isl_basic_set *bset1, *bset2;
1843 isl_map *map1, *map2;
1844 isl_size n_div;
1846 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
1847 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1848 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1849 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1850 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1851 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1852 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1853 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1854 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1855 bset1 = isl_basic_set_read_from_str(ctx, str);
1856 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1857 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1858 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1859 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1860 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1861 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1862 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1863 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1864 bset2 = isl_basic_set_read_from_str(ctx, str);
1865 bset1 = isl_basic_set_gist(bset1, bset2);
1866 assert(bset1 && bset1->n_div == 0);
1867 isl_basic_set_free(bset1);
1869 /* Check that the integer divisions of the second disjunct
1870 * do not spread to the first disjunct.
1872 str = "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1873 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1874 "(exists (e0 = [(-1 + t1)/16], "
1875 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1876 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1877 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1878 "o0 <= 4294967295 and t1 <= -1)) }";
1879 map1 = isl_map_read_from_str(ctx, str);
1880 str = "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1881 map2 = isl_map_read_from_str(ctx, str);
1882 map1 = isl_map_gist(map1, map2);
1883 if (!map1)
1884 return -1;
1885 if (map1->n != 1)
1886 isl_die(ctx, isl_error_unknown, "expecting single disjunct",
1887 isl_map_free(map1); return -1);
1888 n_div = isl_basic_map_dim(map1->p[0], isl_dim_div);
1889 isl_map_free(map1);
1890 if (n_div < 0)
1891 return -1;
1892 if (n_div != 1)
1893 isl_die(ctx, isl_error_unknown, "expecting single div",
1894 return -1);
1896 if (test_gist_empty(ctx) < 0)
1897 return -1;
1898 if (test_plain_gist(ctx) < 0)
1899 return -1;
1901 return 0;
1904 int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
1906 isl_set *set, *set2;
1907 int equal;
1908 int one;
1910 set = isl_set_read_from_str(ctx, str);
1911 set = isl_set_coalesce(set);
1912 set2 = isl_set_read_from_str(ctx, str);
1913 equal = isl_set_is_equal(set, set2);
1914 one = set && set->n == 1;
1915 isl_set_free(set);
1916 isl_set_free(set2);
1918 if (equal < 0)
1919 return -1;
1920 if (!equal)
1921 isl_die(ctx, isl_error_unknown,
1922 "coalesced set not equal to input", return -1);
1923 if (check_one && !one)
1924 isl_die(ctx, isl_error_unknown,
1925 "coalesced set should not be a union", return -1);
1927 return 0;
1930 /* Inputs for coalescing tests with unbounded wrapping.
1931 * "str" is a string representation of the input set.
1932 * "single_disjunct" is set if we expect the result to consist of
1933 * a single disjunct.
1935 struct {
1936 int single_disjunct;
1937 const char *str;
1938 } coalesce_unbounded_tests[] = {
1939 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1940 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1941 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1942 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1943 "-10 <= y <= 0}" },
1944 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1945 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1946 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1947 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1948 { 0, "{ [x, y, z] : 0 <= x,y,z <= 100 and 0 < z <= 2 + 2x + 2y; "
1949 "[x, y, 0] : x,y <= 100 and y <= 9 + 11x and x <= 9 + 11y }" },
1950 { 1, "{ [0:1, 0:1]; [0, 2:3] }" },
1951 { 1, "{ [0:1, 0:1]; [0, 2:3]; [1, -2:-1] }" },
1952 { 1, "{ [0:3, 0:1]; [1:2, 2:5] }" },
1953 { 1, "{ [0:3, 0:1]; [0:2, 2:5] }" },
1954 { 1, "{ [0:3, 0:1]; [1:3, 2:5] }" },
1955 { 0, "{ [0:3, 0:1]; [1:4, 2:5] }" },
1956 { 0, "{ [0:3, 0:1]; [1:5, 2:5] }" },
1959 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1960 * option turned off.
1962 int test_coalesce_unbounded_wrapping(isl_ctx *ctx)
1964 int i;
1965 int r = 0;
1966 int bounded;
1968 bounded = isl_options_get_coalesce_bounded_wrapping(ctx);
1969 isl_options_set_coalesce_bounded_wrapping(ctx, 0);
1971 for (i = 0; i < ARRAY_SIZE(coalesce_unbounded_tests); ++i) {
1972 const char *str = coalesce_unbounded_tests[i].str;
1973 int check_one = coalesce_unbounded_tests[i].single_disjunct;
1974 if (test_coalesce_set(ctx, str, check_one) >= 0)
1975 continue;
1976 r = -1;
1977 break;
1980 isl_options_set_coalesce_bounded_wrapping(ctx, bounded);
1982 return r;
1985 /* Inputs for coalescing tests.
1986 * "str" is a string representation of the input set.
1987 * "single_disjunct" is set if we expect the result to consist of
1988 * a single disjunct.
1990 struct {
1991 int single_disjunct;
1992 const char *str;
1993 } coalesce_tests[] = {
1994 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1995 "y >= x & x >= 2 & 5 >= y }" },
1996 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1997 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1998 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1999 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
2000 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2001 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
2002 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2003 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
2004 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2005 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
2006 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
2007 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
2008 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
2009 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
2010 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
2011 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
2012 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
2013 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2014 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2015 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2016 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
2017 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
2018 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
2019 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
2020 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
2021 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2022 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2023 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2024 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
2025 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
2026 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
2027 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
2028 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
2029 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
2030 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
2031 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
2032 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
2033 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
2034 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
2035 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
2036 "[o0, o1, o2, o3, o4, o5, o6]] : "
2037 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
2038 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
2039 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
2040 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
2041 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
2042 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
2043 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
2044 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
2045 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
2046 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
2047 "o6 >= i3 + i6 - o3 and M >= 0 and "
2048 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
2049 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
2050 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
2051 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
2052 "(o0 = 0 and M >= 2 and N >= 3) or "
2053 "(M = 0 and o0 = 0 and N >= 3) }" },
2054 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
2055 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
2056 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
2057 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
2058 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
2059 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
2060 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
2061 "(y = 3 and x = 1) }" },
2062 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
2063 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
2064 "i1 <= M and i3 <= M and i4 <= M) or "
2065 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
2066 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
2067 "i4 <= -1 + M) }" },
2068 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
2069 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
2070 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
2071 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
2072 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
2073 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
2074 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
2075 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
2076 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
2077 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
2078 { 0, "{ [a, b] : exists e : 2e = a and "
2079 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
2080 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
2081 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
2082 "j >= 1 and j' <= i + j - i' and i >= 1; "
2083 "[1, 1, 1, 1] }" },
2084 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
2085 "[i,j] : exists a : j = 3a }" },
2086 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
2087 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
2088 "a >= 3) or "
2089 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
2090 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
2091 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
2092 "c <= 6 + 8a and a >= 3; "
2093 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
2094 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
2095 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2096 "[x,0] : 3 <= x <= 4 }" },
2097 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
2098 "[x,0] : 4 <= x <= 5 }" },
2099 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2100 "[x,0] : 3 <= x <= 5 }" },
2101 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
2102 "[x,0] : 3 <= x <= 4 }" },
2103 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
2104 "i1 <= 0; "
2105 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
2106 { 1, "{ [0,0]; [1,1] }" },
2107 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
2108 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
2109 "ii <= k;"
2110 "[k, 0, k] : k <= 6 and k >= 1 }" },
2111 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
2112 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
2113 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
2114 { 1, "[n] -> { [1] : n >= 0;"
2115 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
2116 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
2117 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
2118 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
2119 "2e0 <= x and 2e0 <= n);"
2120 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
2121 "n >= 0) }" },
2122 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
2123 "128e0 >= -134 + 127t1 and t1 >= 2 and "
2124 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
2125 "t1 = 1 }" },
2126 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
2127 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
2128 "[0, 0] }" },
2129 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
2130 "t1 >= 13 and t1 <= 16);"
2131 "[t1] : t1 <= 15 and t1 >= 12 }" },
2132 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2133 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2134 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2135 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2136 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2137 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2138 "i <= 4j + 2 }" },
2139 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2140 "(exists (e0 : 3e0 = -2 + c0)) }" },
2141 { 0, "[n, b0, t0] -> "
2142 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2143 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2144 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2145 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2146 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2147 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2148 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2149 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2150 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2151 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2152 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2153 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2154 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2155 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2156 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2157 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2158 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2159 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2160 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2161 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2162 { 0, "{ [i0, i1, i2] : "
2163 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2164 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2165 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2166 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2167 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2168 "32e0 <= 31 + i0)) or "
2169 "i0 >= 0 }" },
2170 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2171 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2172 "2*floor((c)/2) = c and 0 <= a <= 192;"
2173 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2175 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2176 "(0 <= a <= b <= n) }" },
2177 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2178 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2179 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2180 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2181 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2182 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2183 "b = 3 and 9e0 <= -19 + 2c)) }" },
2184 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2185 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2186 "(a = 4 and b = 3 and "
2187 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2188 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2189 "(b = -1 + a and 0 < a <= 3 and "
2190 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2191 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2192 "b = 3 and 9e0 <= -19 + 2c)) }" },
2193 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2194 "[1, 0] }" },
2195 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2196 "[0, 1] }" },
2197 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2198 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2199 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2200 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2201 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2202 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2203 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2204 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2205 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2206 { 1, "{ [a] : a <= 8 and "
2207 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2208 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2209 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2210 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2211 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2212 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2213 "(a < 0 and 3*floor((a)/3) < a) }" },
2214 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2215 "(a < -1 and 3*floor((a)/3) < a) }" },
2216 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2217 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2218 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2219 "or (2 <= a <= 15 and b < a)) }" },
2220 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2221 "32*floor((a)/32) < a) or a <= 15) }" },
2222 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2223 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2224 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2225 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2226 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2227 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2228 "S_0[n] : n <= m <= 2 + n }" },
2229 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2230 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2231 "2e0 <= a + b); "
2232 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2233 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2234 "2e0 < -a + 2b) }" },
2235 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2236 "[i, 0, i] : 0 <= i <= 7 }" },
2237 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2238 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2239 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2240 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2241 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2242 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2243 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2244 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2245 "a > 0 and a <= 5) }" },
2246 { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" },
2247 { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and "
2248 "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; "
2249 "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" },
2250 { 0, "{ [0:1, 0:1]; [0, 2:3] }" },
2251 { 1, "{ [a] : (a = 0 or ((1 + a) mod 2 = 0 and 0 < a <= 15) or "
2252 "((a) mod 2 = 0 and 0 < a <= 15)) }" },
2253 { 1, "{ rat: [0:2]; rat: [1:3] }" },
2254 { 1, "{ [a = 1:14] : a mod 4 = 0 and 4*floor((1 + a)/4) <= a; [0] }" },
2255 { 0, "{ [a = 4:6, b = 1:7, 8] : a mod 2 = 1 and b mod 2 = 1;"
2256 "[a = 1:7, 1:7, a] }" },
2257 { 1, "{ [a] : a mod 2 = 0 and (a <= 3 or a >= 12 or 4 <= a <= 11) }" },
2258 { 1, "{ [a] : 0 < a <= 341 or "
2259 "(0 < a <= 700 and 360*floor(a/360) >= -340 + a) }" },
2260 { 0, "{ [a] : 0 < a <= 341 or "
2261 "(0 < a <= 701 and 360*floor(a/360) >= -340 + a) }" },
2264 /* A specialized coalescing test case that would result
2265 * in a segmentation fault or a failed assertion in earlier versions of isl.
2267 static int test_coalesce_special(struct isl_ctx *ctx)
2269 const char *str;
2270 isl_map *map1, *map2;
2272 str = "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2273 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2274 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2275 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2276 "o1 <= 239 and o1 >= 212)) or "
2277 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2278 "o1 <= 241 and o1 >= 240));"
2279 "[S_L220_OUT[] -> T7[]] -> "
2280 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2281 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2282 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2283 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2284 map1 = isl_map_read_from_str(ctx, str);
2285 map1 = isl_map_align_divs_internal(map1);
2286 map1 = isl_map_coalesce(map1);
2287 str = "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2288 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2289 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2290 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2291 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2292 map2 = isl_map_read_from_str(ctx, str);
2293 map2 = isl_map_union(map2, map1);
2294 map2 = isl_map_align_divs_internal(map2);
2295 map2 = isl_map_coalesce(map2);
2296 isl_map_free(map2);
2297 if (!map2)
2298 return -1;
2300 return 0;
2303 /* Check that the union of the basic sets described by "str1" and "str2"
2304 * can be coalesced and that the result is equal to the union.
2305 * The explicit call to isl_basic_set_union prevents the implicit
2306 * equality constraints in the basic maps from being detected prior
2307 * to the call to isl_set_coalesce, at least at the point
2308 * where this function was introduced.
2310 static isl_stat test_coalesce_union(isl_ctx *ctx, const char *str1,
2311 const char *str2)
2313 isl_basic_set *bset1, *bset2;
2314 isl_set *set, *set2;
2315 isl_bool equal;
2317 bset1 = isl_basic_set_read_from_str(ctx, str1);
2318 bset2 = isl_basic_set_read_from_str(ctx, str2);
2319 set = isl_basic_set_union(bset1, bset2);
2320 set = isl_set_coalesce(set);
2322 bset1 = isl_basic_set_read_from_str(ctx, str1);
2323 bset2 = isl_basic_set_read_from_str(ctx, str2);
2324 set2 = isl_basic_set_union(bset1, bset2);
2326 equal = isl_set_is_equal(set, set2);
2327 isl_set_free(set);
2328 isl_set_free(set2);
2330 if (equal < 0)
2331 return isl_stat_error;
2332 if (!equal)
2333 isl_die(ctx, isl_error_unknown,
2334 "coalesced set not equal to input",
2335 return isl_stat_error);
2337 return isl_stat_non_null(set);
2340 /* A specialized coalescing test case that would result in an assertion
2341 * in an earlier version of isl. Use test_coalesce_union with
2342 * an explicit call to isl_basic_set_union to prevent the implicit
2343 * equality constraints in the first basic map from being detected prior
2344 * to the call to isl_set_coalesce, at least at the point
2345 * where this test case was introduced.
2347 static isl_stat test_coalesce_special2(struct isl_ctx *ctx)
2349 const char *str1;
2350 const char *str2;
2352 str1 = "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2353 str2 = "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }";
2354 return test_coalesce_union(ctx, str1, str2);
2357 /* Check that calling isl_set_coalesce does not leave other sets
2358 * that may share some information with the input to isl_set_coalesce
2359 * in an inconsistent state.
2360 * In particular, older versions of isl would modify all copies
2361 * of the basic sets in the isl_set_coalesce input in a way
2362 * that could leave them in an inconsistent state.
2363 * The result of printing any other set containing one of these
2364 * basic sets would then result in an invalid set description.
2366 static int test_coalesce_special3(isl_ctx *ctx)
2368 const char *str;
2369 char *s;
2370 isl_set *set1, *set2;
2371 isl_printer *p;
2373 set1 = isl_set_read_from_str(ctx, "{ [0, 0, 0] }");
2374 str = "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2375 set2 = isl_set_read_from_str(ctx, str);
2376 set1 = isl_set_union(set1, isl_set_copy(set2));
2377 set1 = isl_set_coalesce(set1);
2378 isl_set_free(set1);
2380 p = isl_printer_to_str(ctx);
2381 p = isl_printer_print_set(p, set2);
2382 isl_set_free(set2);
2383 s = isl_printer_get_str(p);
2384 isl_printer_free(p);
2385 set1 = isl_set_read_from_str(ctx, s);
2386 free(s);
2387 isl_set_free(set1);
2389 if (!set1)
2390 return -1;
2392 return 0;
2395 /* Check that calling isl_set_coalesce on the intersection of
2396 * the sets described by "s1" and "s2" does not leave other sets
2397 * that may share some information with the input to isl_set_coalesce
2398 * in an inconsistent state.
2399 * In particular, when isl_set_coalesce detects equality constraints,
2400 * it does not immediately perform Gaussian elimination on them,
2401 * but then it needs to ensure that it is performed at some point.
2402 * The input set has implicit equality constraints in the first disjunct.
2403 * It is constructed as an intersection, because otherwise
2404 * those equality constraints would already be detected during parsing.
2406 static isl_stat test_coalesce_intersection(isl_ctx *ctx,
2407 const char *s1, const char *s2)
2409 isl_set *set1, *set2;
2411 set1 = isl_set_read_from_str(ctx, s1);
2412 set2 = isl_set_read_from_str(ctx, s2);
2413 set1 = isl_set_intersect(set1, set2);
2414 isl_set_free(isl_set_coalesce(isl_set_copy(set1)));
2415 set1 = isl_set_coalesce(set1);
2416 isl_set_free(set1);
2418 if (!set1)
2419 return isl_stat_error;
2421 return isl_stat_ok;
2424 /* Check that calling isl_set_coalesce does not leave other sets
2425 * that may share some information with the input to isl_set_coalesce
2426 * in an inconsistent state, for the case where one disjunct
2427 * is a subset of the other.
2429 static isl_stat test_coalesce_special4(isl_ctx *ctx)
2431 const char *s1, *s2;
2433 s1 = "{ [a, b] : b <= 0 or a <= 1 }";
2434 s2 = "{ [a, b] : -1 <= -a < b }";
2435 return test_coalesce_intersection(ctx, s1, s2);
2438 /* Check that calling isl_set_coalesce does not leave other sets
2439 * that may share some information with the input to isl_set_coalesce
2440 * in an inconsistent state, for the case where two disjuncts
2441 * can be fused.
2443 static isl_stat test_coalesce_special5(isl_ctx *ctx)
2445 const char *s1, *s2;
2447 s1 = "{ [a, b, c] : b <= 0 }";
2448 s2 = "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }";
2449 return test_coalesce_intersection(ctx, s1, s2);
2452 /* Check that calling isl_set_coalesce does not leave other sets
2453 * that may share some information with the input to isl_set_coalesce
2454 * in an inconsistent state, for the case where two disjuncts
2455 * can be fused and where both disjuncts have implicit equality constraints.
2457 static isl_stat test_coalesce_special6(isl_ctx *ctx)
2459 const char *s1, *s2;
2461 s1 = "{ [a, b, c] : c <= 0 }";
2462 s2 = "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }";
2463 return test_coalesce_intersection(ctx, s1, s2);
2466 /* A specialized coalescing test case that would result in an assertion failure
2467 * in an earlier version of isl. Use test_coalesce_union with
2468 * an explicit call to isl_basic_set_union to prevent the implicit
2469 * equality constraints in the basic maps from being detected prior
2470 * to the call to isl_set_coalesce, at least at the point
2471 * where this test case was introduced.
2473 static isl_stat test_coalesce_special7(isl_ctx *ctx)
2475 const char *str1;
2476 const char *str2;
2478 str1 = "{ [a, b, c=0:17] : a <= 7 and 2b <= 11 - a and "
2479 "c <= -7 + 2a and 2c >= - 3 + 3a - 2b }";
2480 str2 = "{ [a, b, c] : c > -15a and c >= -7 + 2a and c < 0 and "
2481 "3c <= -5 + 5a - 3b and 2b >= 11 - a }";
2482 return test_coalesce_union(ctx, str1, str2);
2485 /* A specialized coalescing test case that would result in a disjunct
2486 * getting dropped in an earlier version of isl. Use test_coalesce_union with
2487 * an explicit call to isl_basic_set_union to prevent the implicit
2488 * equality constraints in the basic maps from being detected prior
2489 * to the call to isl_set_coalesce, at least at the point
2490 * where this test case was introduced.
2492 static isl_stat test_coalesce_special8(isl_ctx *ctx)
2494 const char *str1;
2495 const char *str2;
2497 str1 = "{ [a, b, c] : 2c <= -a and b >= -a and b <= 5 and "
2498 "6c > -7a and 11c >= -5a - b and a <= 3 }";
2499 str2 = "{ [a, b, c] : 6c > -7a and b >= -a and b <= 5 and "
2500 "11c >= -5a - b and a >= 4 and 2b <= a and 2c <= -a }";
2501 return test_coalesce_union(ctx, str1, str2);
2504 /* Test the functionality of isl_set_coalesce.
2505 * That is, check that the output is always equal to the input
2506 * and in some cases that the result consists of a single disjunct.
2508 static int test_coalesce(struct isl_ctx *ctx)
2510 int i;
2512 for (i = 0; i < ARRAY_SIZE(coalesce_tests); ++i) {
2513 const char *str = coalesce_tests[i].str;
2514 int check_one = coalesce_tests[i].single_disjunct;
2515 if (test_coalesce_set(ctx, str, check_one) < 0)
2516 return -1;
2519 if (test_coalesce_unbounded_wrapping(ctx) < 0)
2520 return -1;
2521 if (test_coalesce_special(ctx) < 0)
2522 return -1;
2523 if (test_coalesce_special2(ctx) < 0)
2524 return -1;
2525 if (test_coalesce_special3(ctx) < 0)
2526 return -1;
2527 if (test_coalesce_special4(ctx) < 0)
2528 return -1;
2529 if (test_coalesce_special5(ctx) < 0)
2530 return -1;
2531 if (test_coalesce_special6(ctx) < 0)
2532 return -1;
2533 if (test_coalesce_special7(ctx) < 0)
2534 return -1;
2535 if (test_coalesce_special8(ctx) < 0)
2536 return -1;
2538 return 0;
2541 /* Construct a representation of the graph on the right of Figure 1
2542 * in "Computing the Transitive Closure of a Union of
2543 * Affine Integer Tuple Relations".
2545 static __isl_give isl_map *cocoa_fig_1_right_graph(isl_ctx *ctx)
2547 isl_set *dom;
2548 isl_map *up, *right;
2550 dom = isl_set_read_from_str(ctx,
2551 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2552 "2 x - 3 y + 3 >= 0 }");
2553 right = isl_map_read_from_str(ctx,
2554 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2555 up = isl_map_read_from_str(ctx,
2556 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2557 right = isl_map_intersect_domain(right, isl_set_copy(dom));
2558 right = isl_map_intersect_range(right, isl_set_copy(dom));
2559 up = isl_map_intersect_domain(up, isl_set_copy(dom));
2560 up = isl_map_intersect_range(up, dom);
2561 return isl_map_union(up, right);
2564 /* Construct a representation of the power of the graph
2565 * on the right of Figure 1 in "Computing the Transitive Closure of
2566 * a Union of Affine Integer Tuple Relations".
2568 static __isl_give isl_map *cocoa_fig_1_right_power(isl_ctx *ctx)
2570 return isl_map_read_from_str(ctx,
2571 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2572 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2573 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2576 /* Construct a representation of the transitive closure of the graph
2577 * on the right of Figure 1 in "Computing the Transitive Closure of
2578 * a Union of Affine Integer Tuple Relations".
2580 static __isl_give isl_map *cocoa_fig_1_right_tc(isl_ctx *ctx)
2582 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx)));
2585 static int test_closure(isl_ctx *ctx)
2587 const char *str;
2588 isl_map *map, *map2;
2589 isl_bool exact, equal;
2591 /* COCOA example 1 */
2592 map = isl_map_read_from_str(ctx,
2593 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2594 "1 <= i and i < n and 1 <= j and j < n or "
2595 "i2 = i + 1 and j2 = j - 1 and "
2596 "1 <= i and i < n and 2 <= j and j <= n }");
2597 map = isl_map_power(map, &exact);
2598 assert(exact);
2599 isl_map_free(map);
2601 /* COCOA example 1 */
2602 map = isl_map_read_from_str(ctx,
2603 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2604 "1 <= i and i < n and 1 <= j and j < n or "
2605 "i2 = i + 1 and j2 = j - 1 and "
2606 "1 <= i and i < n and 2 <= j and j <= n }");
2607 map = isl_map_transitive_closure(map, &exact);
2608 assert(exact);
2609 map2 = isl_map_read_from_str(ctx,
2610 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2611 "1 <= i and i < n and 1 <= j and j <= n and "
2612 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2613 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2614 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2615 assert(isl_map_is_equal(map, map2));
2616 isl_map_free(map2);
2617 isl_map_free(map);
2619 map = isl_map_read_from_str(ctx,
2620 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2621 " 0 <= y and y <= n }");
2622 map = isl_map_transitive_closure(map, &exact);
2623 map2 = isl_map_read_from_str(ctx,
2624 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2625 " 0 <= y and y <= n }");
2626 assert(isl_map_is_equal(map, map2));
2627 isl_map_free(map2);
2628 isl_map_free(map);
2630 /* COCOA example 2 */
2631 map = isl_map_read_from_str(ctx,
2632 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2633 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2634 "i2 = i + 2 and j2 = j - 2 and "
2635 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2636 map = isl_map_transitive_closure(map, &exact);
2637 assert(exact);
2638 map2 = isl_map_read_from_str(ctx,
2639 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2640 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2641 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2642 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2643 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2644 assert(isl_map_is_equal(map, map2));
2645 isl_map_free(map);
2646 isl_map_free(map2);
2648 /* COCOA Fig.2 left */
2649 map = isl_map_read_from_str(ctx,
2650 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2651 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2652 "j <= n or "
2653 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2654 "j <= 2 i - 3 and j <= n - 2 or "
2655 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2656 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2657 map = isl_map_transitive_closure(map, &exact);
2658 assert(exact);
2659 isl_map_free(map);
2661 /* COCOA Fig.2 right */
2662 map = isl_map_read_from_str(ctx,
2663 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2664 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2665 "j <= n or "
2666 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2667 "j <= 2 i - 4 and j <= n - 3 or "
2668 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2669 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2670 map = isl_map_power(map, &exact);
2671 assert(exact);
2672 isl_map_free(map);
2674 /* COCOA Fig.2 right */
2675 map = isl_map_read_from_str(ctx,
2676 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2677 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2678 "j <= n or "
2679 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2680 "j <= 2 i - 4 and j <= n - 3 or "
2681 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2682 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2683 map = isl_map_transitive_closure(map, &exact);
2684 assert(exact);
2685 map2 = isl_map_read_from_str(ctx,
2686 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2687 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2688 "j <= n and 3 + i + 2 j <= 3 n and "
2689 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2690 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2691 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2692 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2693 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2694 assert(isl_map_is_equal(map, map2));
2695 isl_map_free(map2);
2696 isl_map_free(map);
2698 map = cocoa_fig_1_right_graph(ctx);
2699 map = isl_map_transitive_closure(map, &exact);
2700 assert(exact);
2701 map2 = cocoa_fig_1_right_tc(ctx);
2702 assert(isl_map_is_equal(map, map2));
2703 isl_map_free(map2);
2704 isl_map_free(map);
2706 map = cocoa_fig_1_right_graph(ctx);
2707 map = isl_map_power(map, &exact);
2708 map2 = cocoa_fig_1_right_power(ctx);
2709 equal = isl_map_is_equal(map, map2);
2710 isl_map_free(map2);
2711 isl_map_free(map);
2712 if (equal < 0)
2713 return -1;
2714 if (!exact)
2715 isl_die(ctx, isl_error_unknown, "power not exact", return -1);
2716 if (!equal)
2717 isl_die(ctx, isl_error_unknown, "unexpected power", return -1);
2719 /* COCOA Theorem 1 counter example */
2720 map = isl_map_read_from_str(ctx,
2721 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2722 "i2 = 1 and j2 = j or "
2723 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2724 map = isl_map_transitive_closure(map, &exact);
2725 assert(exact);
2726 isl_map_free(map);
2728 map = isl_map_read_from_str(ctx,
2729 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2730 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2731 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2732 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2733 map = isl_map_transitive_closure(map, &exact);
2734 assert(exact);
2735 isl_map_free(map);
2737 /* Kelly et al 1996, fig 12 */
2738 map = isl_map_read_from_str(ctx,
2739 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2740 "1 <= i,j,j+1 <= n or "
2741 "j = n and j2 = 1 and i2 = i + 1 and "
2742 "1 <= i,i+1 <= n }");
2743 map = isl_map_transitive_closure(map, &exact);
2744 assert(exact);
2745 map2 = isl_map_read_from_str(ctx,
2746 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2747 "1 <= i <= n and i = i2 or "
2748 "1 <= i < i2 <= n and 1 <= j <= n and "
2749 "1 <= j2 <= n }");
2750 assert(isl_map_is_equal(map, map2));
2751 isl_map_free(map2);
2752 isl_map_free(map);
2754 /* Omega's closure4 */
2755 map = isl_map_read_from_str(ctx,
2756 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2757 "1 <= x,y <= 10 or "
2758 "x2 = x + 1 and y2 = y and "
2759 "1 <= x <= 20 && 5 <= y <= 15 }");
2760 map = isl_map_transitive_closure(map, &exact);
2761 assert(exact);
2762 isl_map_free(map);
2764 map = isl_map_read_from_str(ctx,
2765 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2766 map = isl_map_transitive_closure(map, &exact);
2767 assert(!exact);
2768 map2 = isl_map_read_from_str(ctx,
2769 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2770 assert(isl_map_is_equal(map, map2));
2771 isl_map_free(map);
2772 isl_map_free(map2);
2774 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2775 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2776 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2777 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2778 map = isl_map_read_from_str(ctx, str);
2779 map = isl_map_transitive_closure(map, &exact);
2780 assert(exact);
2781 map2 = isl_map_read_from_str(ctx, str);
2782 assert(isl_map_is_equal(map, map2));
2783 isl_map_free(map);
2784 isl_map_free(map2);
2786 str = "{[0] -> [1]; [2] -> [3]}";
2787 map = isl_map_read_from_str(ctx, str);
2788 map = isl_map_transitive_closure(map, &exact);
2789 assert(exact);
2790 map2 = isl_map_read_from_str(ctx, str);
2791 assert(isl_map_is_equal(map, map2));
2792 isl_map_free(map);
2793 isl_map_free(map2);
2795 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2796 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2797 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2798 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2799 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2800 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2801 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2802 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2803 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2804 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2805 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2806 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2807 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2808 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2809 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2810 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2811 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2812 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2813 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2814 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2815 map = isl_map_read_from_str(ctx, str);
2816 map = isl_map_transitive_closure(map, NULL);
2817 assert(map);
2818 isl_map_free(map);
2820 return 0;
2823 /* Check that the actual result of a boolean operation is equal
2824 * to the expected result.
2826 static isl_stat check_bool(isl_ctx *ctx, isl_bool actual, isl_bool expected)
2828 if (actual != expected)
2829 isl_die(ctx, isl_error_unknown,
2830 "incorrect boolean operation", return isl_stat_error);
2831 return isl_stat_ok;
2834 /* Test operations on isl_bool values.
2836 * This tests:
2838 * isl_bool_not
2839 * isl_bool_ok
2841 static int test_isl_bool(isl_ctx *ctx)
2843 if (check_bool(ctx, isl_bool_not(isl_bool_true), isl_bool_false) < 0)
2844 return -1;
2845 if (check_bool(ctx, isl_bool_not(isl_bool_false), isl_bool_true) < 0)
2846 return -1;
2847 if (check_bool(ctx, isl_bool_not(isl_bool_error), isl_bool_error) < 0)
2848 return -1;
2849 if (check_bool(ctx, isl_bool_ok(0), isl_bool_false) < 0)
2850 return -1;
2851 if (check_bool(ctx, isl_bool_ok(1), isl_bool_true) < 0)
2852 return -1;
2853 if (check_bool(ctx, isl_bool_ok(-1), isl_bool_true) < 0)
2854 return -1;
2855 if (check_bool(ctx, isl_bool_ok(2), isl_bool_true) < 0)
2856 return -1;
2857 if (check_bool(ctx, isl_bool_ok(-2), isl_bool_true) < 0)
2858 return -1;
2860 return 0;
2863 static int test_lex(struct isl_ctx *ctx)
2865 isl_space *space;
2866 isl_map *map;
2867 int empty;
2869 space = isl_space_set_alloc(ctx, 0, 0);
2870 map = isl_map_lex_le(space);
2871 empty = isl_map_is_empty(map);
2872 isl_map_free(map);
2874 if (empty < 0)
2875 return -1;
2876 if (empty)
2877 isl_die(ctx, isl_error_unknown,
2878 "expecting non-empty result", return -1);
2880 return 0;
2883 /* Inputs for isl_map_lexmin tests.
2884 * "map" is the input and "lexmin" is the expected result.
2886 struct {
2887 const char *map;
2888 const char *lexmin;
2889 } lexmin_tests [] = {
2890 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2891 "{ [x] -> [5] : 6 <= x <= 8; "
2892 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2893 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2894 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2895 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2896 "{ [x] -> [y] : (4y = x and x >= 0) or "
2897 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2898 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2899 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2900 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2901 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2902 /* Check that empty pieces are properly combined. */
2903 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2904 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2905 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2906 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2907 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2908 "x >= 4 }" },
2909 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2910 "a <= 255 and c <= 255 and d <= 255 - j and "
2911 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2912 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2913 "247d <= 247 + i and 248 - b <= 248d <= c and "
2914 "254d >= i - a + b and 254d >= -a + b and "
2915 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2916 "{ [i, k, j] -> "
2917 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2918 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2919 "247j >= 62738 - i and 509j <= 129795 + i and "
2920 "742j >= 188724 - i; "
2921 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2922 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2923 "16*floor((8 + b)/16) <= 7 + b; "
2924 "[a] -> [1] }",
2925 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2926 "[a] -> [b = 0] : 0 < a <= 509 }" },
2927 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2928 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2929 { "{ rat: [i] : 21 <= 2i <= 29 or i = 5 }", "{ rat: [5] }" },
2932 static int test_lexmin(struct isl_ctx *ctx)
2934 int i;
2935 int equal;
2936 const char *str;
2937 isl_basic_map *bmap;
2938 isl_map *map, *map2;
2939 isl_set *set;
2940 isl_set *set2;
2941 isl_pw_multi_aff *pma;
2943 str = "[p0, p1] -> { [] -> [] : "
2944 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2945 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2946 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2947 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2948 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2949 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2950 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2951 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2952 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2953 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2954 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2955 map = isl_map_read_from_str(ctx, str);
2956 map = isl_map_lexmin(map);
2957 isl_map_free(map);
2958 if (!map)
2959 return -1;
2961 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2962 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2963 set = isl_set_read_from_str(ctx, str);
2964 set = isl_set_lexmax(set);
2965 str = "[C] -> { [obj,a,b,c] : C = 8 }";
2966 set2 = isl_set_read_from_str(ctx, str);
2967 set = isl_set_intersect(set, set2);
2968 assert(!isl_set_is_empty(set));
2969 isl_set_free(set);
2971 for (i = 0; i < ARRAY_SIZE(lexmin_tests); ++i) {
2972 map = isl_map_read_from_str(ctx, lexmin_tests[i].map);
2973 map = isl_map_lexmin(map);
2974 map2 = isl_map_read_from_str(ctx, lexmin_tests[i].lexmin);
2975 equal = isl_map_is_equal(map, map2);
2976 isl_map_free(map);
2977 isl_map_free(map2);
2979 if (equal < 0)
2980 return -1;
2981 if (!equal)
2982 isl_die(ctx, isl_error_unknown,
2983 "unexpected result", return -1);
2986 str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2987 " 8i' <= i and 8i' >= -7 + i }";
2988 bmap = isl_basic_map_read_from_str(ctx, str);
2989 pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap));
2990 map2 = isl_map_from_pw_multi_aff(pma);
2991 map = isl_map_from_basic_map(bmap);
2992 assert(isl_map_is_equal(map, map2));
2993 isl_map_free(map);
2994 isl_map_free(map2);
2996 str = "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2997 " 8i' <= i and 8i' >= -7 + i }";
2998 set = isl_set_read_from_str(ctx, str);
2999 pma = isl_set_lexmin_pw_multi_aff(isl_set_copy(set));
3000 set2 = isl_set_from_pw_multi_aff(pma);
3001 equal = isl_set_is_equal(set, set2);
3002 isl_set_free(set);
3003 isl_set_free(set2);
3004 if (equal < 0)
3005 return -1;
3006 if (!equal)
3007 isl_die(ctx, isl_error_unknown,
3008 "unexpected difference between set and "
3009 "piecewise affine expression", return -1);
3011 return 0;
3014 /* Inputs for isl_pw_multi_aff_max_multi_val tests.
3015 * "pma" is the input.
3016 * "res" is the expected result.
3018 static struct {
3019 const char *pma;
3020 const char *res;
3021 } opt_pw_tests[] = {
3022 { "{ [-1] -> [-1]; [1] -> [1] }", "{ [1] }" },
3023 { "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] : "
3024 "0 <= a, b <= 100 and b mod 2 = 0}", "{ [30] }" },
3025 { "[N] -> { [i,j] -> A[i, -i, i + j] : 0 <= i,j <= N <= 10 }",
3026 "{ A[10, 0, 20] }" },
3027 { "[N] -> {A[N, -N, 2N] : 0 <= N }", "{ A[infty, 0, infty] }" },
3030 /* Perform basic isl_pw_multi_aff_max_multi_val tests.
3032 static isl_stat test_pw_max(struct isl_ctx *ctx)
3034 int i;
3035 isl_pw_multi_aff *pma;
3036 isl_multi_val *mv;
3037 isl_stat r;
3039 for (i = 0; i < ARRAY_SIZE(opt_pw_tests); ++i) {
3040 pma = isl_pw_multi_aff_read_from_str(ctx, opt_pw_tests[i].pma);
3041 mv = isl_pw_multi_aff_max_multi_val(pma);
3042 r = multi_val_check_plain_equal(mv, opt_pw_tests[i].res);
3043 isl_multi_val_free(mv);
3045 if (r < 0)
3046 return isl_stat_error;
3049 return isl_stat_ok;
3052 /* A specialized isl_set_min_val test case that would return the wrong result
3053 * in earlier versions of isl.
3054 * The explicit call to isl_basic_set_union prevents the second basic set
3055 * from being determined to be empty prior to the call to isl_set_min_val,
3056 * at least at the point where this test case was introduced.
3058 static int test_min_special(isl_ctx *ctx)
3060 const char *str;
3061 isl_basic_set *bset1, *bset2;
3062 isl_set *set;
3063 isl_aff *obj;
3064 isl_val *res;
3065 int ok;
3067 str = "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
3068 bset1 = isl_basic_set_read_from_str(ctx, str);
3069 str = "{ [a, b] : 1 <= a, b and a + b <= 1 }";
3070 bset2 = isl_basic_set_read_from_str(ctx, str);
3071 set = isl_basic_set_union(bset1, bset2);
3072 obj = isl_aff_read_from_str(ctx, "{ [a, b] -> [a] }");
3074 res = isl_set_min_val(set, obj);
3075 ok = isl_val_cmp_si(res, 5) == 0;
3077 isl_aff_free(obj);
3078 isl_set_free(set);
3079 isl_val_free(res);
3081 if (!res)
3082 return -1;
3083 if (!ok)
3084 isl_die(ctx, isl_error_unknown, "unexpected minimum",
3085 return -1);
3087 return 0;
3090 /* A specialized isl_set_min_val test case that would return an error
3091 * in earlier versions of isl.
3093 static int test_min_special2(isl_ctx *ctx)
3095 const char *str;
3096 isl_basic_set *bset;
3097 isl_aff *obj;
3098 isl_val *res;
3100 str = "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
3101 bset = isl_basic_set_read_from_str(ctx, str);
3103 obj = isl_aff_read_from_str(ctx, "{ [i, j, k] -> [i] }");
3105 res = isl_basic_set_max_val(bset, obj);
3107 isl_basic_set_free(bset);
3108 isl_aff_free(obj);
3109 isl_val_free(res);
3111 if (!res)
3112 return -1;
3114 return 0;
3117 /* Check that the result of isl_set_min_multi_pw_aff
3118 * on the union of the sets with string descriptions "s1" and "s2"
3119 * consists of a single expression (on a single cell).
3121 static isl_stat check_single_expr_min(isl_ctx *ctx, const char *s1,
3122 const char *s2)
3124 isl_size n;
3125 isl_set *set1, *set2;
3126 isl_multi_pw_aff *mpa;
3127 isl_pw_multi_aff *pma;
3129 set1 = isl_set_read_from_str(ctx, s1);
3130 set2 = isl_set_read_from_str(ctx, s2);
3131 set1 = isl_set_union(set1, set2);
3132 mpa = isl_set_min_multi_pw_aff(set1);
3133 pma = isl_pw_multi_aff_from_multi_pw_aff(mpa);
3134 n = isl_pw_multi_aff_n_piece(pma);
3135 isl_pw_multi_aff_free(pma);
3137 if (n < 0)
3138 return isl_stat_error;
3139 if (n != 1)
3140 isl_die(ctx, isl_error_unknown, "expecting single expression",
3141 return isl_stat_error);
3142 return isl_stat_ok;
3145 /* A specialized isl_set_min_multi_pw_aff test that checks
3146 * that the minimum of 2N and 3N for N >= 0 is represented
3147 * by a single expression, without splitting off the special case N = 0.
3148 * Do this for both orderings.
3150 static int test_min_mpa(isl_ctx *ctx)
3152 const char *s1, *s2;
3154 s1 = "[N=0:] -> { [1, 3N:] }";
3155 s2 = "[N=0:] -> { [10, 2N:] }";
3156 if (check_single_expr_min(ctx, s1, s2) < 0)
3157 return -1;
3158 if (check_single_expr_min(ctx, s2, s1) < 0)
3159 return -1;
3161 return 0;
3164 struct {
3165 const char *set;
3166 const char *obj;
3167 __isl_give isl_val *(*fn)(__isl_keep isl_set *set,
3168 __isl_keep isl_aff *obj);
3169 const char *res;
3170 } opt_tests[] = {
3171 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val, "-1" },
3172 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val, "1" },
3173 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
3174 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
3175 &isl_set_max_val, "30" },
3179 /* Perform basic isl_set_min_val and isl_set_max_val tests.
3180 * In particular, check the results on non-convex inputs.
3182 static int test_min(struct isl_ctx *ctx)
3184 int i;
3185 isl_set *set;
3186 isl_aff *obj;
3187 isl_val *val, *res;
3188 isl_bool ok;
3190 for (i = 0; i < ARRAY_SIZE(opt_tests); ++i) {
3191 set = isl_set_read_from_str(ctx, opt_tests[i].set);
3192 obj = isl_aff_read_from_str(ctx, opt_tests[i].obj);
3193 res = isl_val_read_from_str(ctx, opt_tests[i].res);
3194 val = opt_tests[i].fn(set, obj);
3195 ok = isl_val_eq(res, val);
3196 isl_val_free(res);
3197 isl_val_free(val);
3198 isl_aff_free(obj);
3199 isl_set_free(set);
3201 if (ok < 0)
3202 return -1;
3203 if (!ok)
3204 isl_die(ctx, isl_error_unknown,
3205 "unexpected optimum", return -1);
3208 if (test_pw_max(ctx) < 0)
3209 return -1;
3210 if (test_min_special(ctx) < 0)
3211 return -1;
3212 if (test_min_special2(ctx) < 0)
3213 return -1;
3215 return 0;
3218 struct must_may {
3219 isl_map *must;
3220 isl_map *may;
3223 static isl_stat collect_must_may(__isl_take isl_map *dep, int must,
3224 void *dep_user, void *user)
3226 struct must_may *mm = (struct must_may *)user;
3228 if (must)
3229 mm->must = isl_map_union(mm->must, dep);
3230 else
3231 mm->may = isl_map_union(mm->may, dep);
3233 return isl_stat_ok;
3236 static int common_space(void *first, void *second)
3238 int depth = *(int *)first;
3239 return 2 * depth;
3242 static int map_is_equal(__isl_keep isl_map *map, const char *str)
3244 isl_map *map2;
3245 int equal;
3247 if (!map)
3248 return -1;
3250 map2 = isl_map_read_from_str(map->ctx, str);
3251 equal = isl_map_is_equal(map, map2);
3252 isl_map_free(map2);
3254 return equal;
3257 static int map_check_equal(__isl_keep isl_map *map, const char *str)
3259 int equal;
3261 equal = map_is_equal(map, str);
3262 if (equal < 0)
3263 return -1;
3264 if (!equal)
3265 isl_die(isl_map_get_ctx(map), isl_error_unknown,
3266 "result not as expected", return -1);
3267 return 0;
3270 /* Is "set" equal to the set described by "str"?
3272 static isl_bool set_is_equal(__isl_keep isl_set *set, const char *str)
3274 isl_set *set2;
3275 isl_bool equal;
3277 if (!set)
3278 return isl_bool_error;
3280 set2 = isl_set_read_from_str(isl_set_get_ctx(set), str);
3281 equal = isl_set_is_equal(set, set2);
3282 isl_set_free(set2);
3284 return equal;
3287 /* Check that "set" is equal to the set described by "str".
3289 static isl_stat set_check_equal(__isl_keep isl_set *set, const char *str)
3291 isl_bool equal;
3293 equal = set_is_equal(set, str);
3294 if (equal < 0)
3295 return isl_stat_error;
3296 if (!equal)
3297 isl_die(isl_set_get_ctx(set), isl_error_unknown,
3298 "result not as expected", return isl_stat_error);
3299 return isl_stat_ok;
3302 /* Is "uset" equal to the union set described by "str"?
3304 static isl_bool uset_is_equal(__isl_keep isl_union_set *uset, const char *str)
3306 isl_union_set *uset2;
3307 isl_bool equal;
3309 if (!uset)
3310 return isl_bool_error;
3312 uset2 = isl_union_set_read_from_str(isl_union_set_get_ctx(uset), str);
3313 equal = isl_union_set_is_equal(uset, uset2);
3314 isl_union_set_free(uset2);
3316 return equal;
3319 /* Check that "uset" is equal to the union set described by "str".
3321 static isl_stat uset_check_equal(__isl_keep isl_union_set *uset,
3322 const char *str)
3324 isl_bool equal;
3326 equal = uset_is_equal(uset, str);
3327 if (equal < 0)
3328 return isl_stat_error;
3329 if (!equal)
3330 isl_die(isl_union_set_get_ctx(uset), isl_error_unknown,
3331 "result not as expected", return isl_stat_error);
3332 return isl_stat_ok;
3335 static int test_dep(struct isl_ctx *ctx)
3337 const char *str;
3338 isl_space *space;
3339 isl_map *map;
3340 isl_access_info *ai;
3341 isl_flow *flow;
3342 int depth;
3343 struct must_may mm;
3345 depth = 3;
3347 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3348 map = isl_map_read_from_str(ctx, str);
3349 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3351 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3352 map = isl_map_read_from_str(ctx, str);
3353 ai = isl_access_info_add_source(ai, map, 1, &depth);
3355 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3356 map = isl_map_read_from_str(ctx, str);
3357 ai = isl_access_info_add_source(ai, map, 1, &depth);
3359 flow = isl_access_info_compute_flow(ai);
3360 space = isl_space_alloc(ctx, 0, 3, 3);
3361 mm.must = isl_map_empty(isl_space_copy(space));
3362 mm.may = isl_map_empty(space);
3364 isl_flow_foreach(flow, collect_must_may, &mm);
3366 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
3367 " [1,10,0] -> [2,5,0] }";
3368 assert(map_is_equal(mm.must, str));
3369 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3370 assert(map_is_equal(mm.may, str));
3372 isl_map_free(mm.must);
3373 isl_map_free(mm.may);
3374 isl_flow_free(flow);
3377 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3378 map = isl_map_read_from_str(ctx, str);
3379 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3381 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3382 map = isl_map_read_from_str(ctx, str);
3383 ai = isl_access_info_add_source(ai, map, 1, &depth);
3385 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3386 map = isl_map_read_from_str(ctx, str);
3387 ai = isl_access_info_add_source(ai, map, 0, &depth);
3389 flow = isl_access_info_compute_flow(ai);
3390 space = isl_space_alloc(ctx, 0, 3, 3);
3391 mm.must = isl_map_empty(isl_space_copy(space));
3392 mm.may = isl_map_empty(space);
3394 isl_flow_foreach(flow, collect_must_may, &mm);
3396 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
3397 assert(map_is_equal(mm.must, str));
3398 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3399 assert(map_is_equal(mm.may, str));
3401 isl_map_free(mm.must);
3402 isl_map_free(mm.may);
3403 isl_flow_free(flow);
3406 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3407 map = isl_map_read_from_str(ctx, str);
3408 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3410 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3411 map = isl_map_read_from_str(ctx, str);
3412 ai = isl_access_info_add_source(ai, map, 0, &depth);
3414 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3415 map = isl_map_read_from_str(ctx, str);
3416 ai = isl_access_info_add_source(ai, map, 0, &depth);
3418 flow = isl_access_info_compute_flow(ai);
3419 space = isl_space_alloc(ctx, 0, 3, 3);
3420 mm.must = isl_map_empty(isl_space_copy(space));
3421 mm.may = isl_map_empty(space);
3423 isl_flow_foreach(flow, collect_must_may, &mm);
3425 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
3426 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3427 assert(map_is_equal(mm.may, str));
3428 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3429 assert(map_is_equal(mm.must, str));
3431 isl_map_free(mm.must);
3432 isl_map_free(mm.may);
3433 isl_flow_free(flow);
3436 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
3437 map = isl_map_read_from_str(ctx, str);
3438 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3440 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3441 map = isl_map_read_from_str(ctx, str);
3442 ai = isl_access_info_add_source(ai, map, 0, &depth);
3444 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3445 map = isl_map_read_from_str(ctx, str);
3446 ai = isl_access_info_add_source(ai, map, 0, &depth);
3448 flow = isl_access_info_compute_flow(ai);
3449 space = isl_space_alloc(ctx, 0, 3, 3);
3450 mm.must = isl_map_empty(isl_space_copy(space));
3451 mm.may = isl_map_empty(space);
3453 isl_flow_foreach(flow, collect_must_may, &mm);
3455 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3456 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3457 assert(map_is_equal(mm.may, str));
3458 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3459 assert(map_is_equal(mm.must, str));
3461 isl_map_free(mm.must);
3462 isl_map_free(mm.may);
3463 isl_flow_free(flow);
3466 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3467 map = isl_map_read_from_str(ctx, str);
3468 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3470 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3471 map = isl_map_read_from_str(ctx, str);
3472 ai = isl_access_info_add_source(ai, map, 0, &depth);
3474 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3475 map = isl_map_read_from_str(ctx, str);
3476 ai = isl_access_info_add_source(ai, map, 0, &depth);
3478 flow = isl_access_info_compute_flow(ai);
3479 space = isl_space_alloc(ctx, 0, 3, 3);
3480 mm.must = isl_map_empty(isl_space_copy(space));
3481 mm.may = isl_map_empty(space);
3483 isl_flow_foreach(flow, collect_must_may, &mm);
3485 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3486 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3487 assert(map_is_equal(mm.may, str));
3488 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3489 assert(map_is_equal(mm.must, str));
3491 isl_map_free(mm.must);
3492 isl_map_free(mm.may);
3493 isl_flow_free(flow);
3496 depth = 5;
3498 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3499 map = isl_map_read_from_str(ctx, str);
3500 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
3502 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3503 map = isl_map_read_from_str(ctx, str);
3504 ai = isl_access_info_add_source(ai, map, 1, &depth);
3506 flow = isl_access_info_compute_flow(ai);
3507 space = isl_space_alloc(ctx, 0, 5, 5);
3508 mm.must = isl_map_empty(isl_space_copy(space));
3509 mm.may = isl_map_empty(space);
3511 isl_flow_foreach(flow, collect_must_may, &mm);
3513 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3514 assert(map_is_equal(mm.must, str));
3515 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3516 assert(map_is_equal(mm.may, str));
3518 isl_map_free(mm.must);
3519 isl_map_free(mm.may);
3520 isl_flow_free(flow);
3522 return 0;
3525 /* Check that the dependence analysis proceeds without errors.
3526 * Earlier versions of isl would break down during the analysis
3527 * due to the use of the wrong spaces.
3529 static int test_flow(isl_ctx *ctx)
3531 const char *str;
3532 isl_union_map *access, *schedule;
3533 isl_union_map *must_dep, *may_dep;
3534 int r;
3536 str = "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3537 access = isl_union_map_read_from_str(ctx, str);
3538 str = "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3539 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3540 "S2[] -> [1,0,0,0]; "
3541 "S3[] -> [-1,0,0,0] }";
3542 schedule = isl_union_map_read_from_str(ctx, str);
3543 r = isl_union_map_compute_flow(access, isl_union_map_copy(access),
3544 isl_union_map_copy(access), schedule,
3545 &must_dep, &may_dep, NULL, NULL);
3546 isl_union_map_free(may_dep);
3547 isl_union_map_free(must_dep);
3549 return r;
3552 struct {
3553 const char *map;
3554 int sv;
3555 } sv_tests[] = {
3556 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3557 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3558 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3559 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3560 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3561 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3562 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3563 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3564 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3567 int test_sv(isl_ctx *ctx)
3569 isl_union_map *umap;
3570 int i;
3571 int sv;
3573 for (i = 0; i < ARRAY_SIZE(sv_tests); ++i) {
3574 umap = isl_union_map_read_from_str(ctx, sv_tests[i].map);
3575 sv = isl_union_map_is_single_valued(umap);
3576 isl_union_map_free(umap);
3577 if (sv < 0)
3578 return -1;
3579 if (sv_tests[i].sv && !sv)
3580 isl_die(ctx, isl_error_internal,
3581 "map not detected as single valued", return -1);
3582 if (!sv_tests[i].sv && sv)
3583 isl_die(ctx, isl_error_internal,
3584 "map detected as single valued", return -1);
3587 return 0;
3590 struct {
3591 const char *str;
3592 int bijective;
3593 } bijective_tests[] = {
3594 { "[N,M]->{[i,j] -> [i]}", 0 },
3595 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3596 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3597 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3598 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3599 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3600 { "[N,M]->{[i,j] -> []}", 0 },
3601 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3602 { "[N,M]->{[i,j] -> [2i]}", 0 },
3603 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3604 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3605 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3606 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3609 static int test_bijective(struct isl_ctx *ctx)
3611 isl_map *map;
3612 int i;
3613 int bijective;
3615 for (i = 0; i < ARRAY_SIZE(bijective_tests); ++i) {
3616 map = isl_map_read_from_str(ctx, bijective_tests[i].str);
3617 bijective = isl_map_is_bijective(map);
3618 isl_map_free(map);
3619 if (bijective < 0)
3620 return -1;
3621 if (bijective_tests[i].bijective && !bijective)
3622 isl_die(ctx, isl_error_internal,
3623 "map not detected as bijective", return -1);
3624 if (!bijective_tests[i].bijective && bijective)
3625 isl_die(ctx, isl_error_internal,
3626 "map detected as bijective", return -1);
3629 return 0;
3632 /* Inputs for isl_pw_qpolynomial_gist tests.
3633 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3635 struct {
3636 const char *pwqp;
3637 const char *set;
3638 const char *gist;
3639 } pwqp_gist_tests[] = {
3640 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3641 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3642 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3643 "{ [i] -> -1/2 + 1/2 * i }" },
3644 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3645 { "{ [i] -> i^2 : i > 0; [i] -> i^2 : i < 0 }", "{ [i] : i != 0 }",
3646 "{ [i] -> i^2 }" },
3649 /* Perform some basic isl_pw_qpolynomial_gist tests.
3651 static isl_stat test_pwqp_gist(isl_ctx *ctx)
3653 int i;
3654 const char *str;
3655 isl_set *set;
3656 isl_pw_qpolynomial *pwqp1, *pwqp2;
3657 isl_bool equal;
3659 for (i = 0; i < ARRAY_SIZE(pwqp_gist_tests); ++i) {
3660 str = pwqp_gist_tests[i].pwqp;
3661 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3662 str = pwqp_gist_tests[i].set;
3663 set = isl_set_read_from_str(ctx, str);
3664 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
3665 str = pwqp_gist_tests[i].gist;
3666 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3667 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3668 equal = isl_pw_qpolynomial_is_zero(pwqp1);
3669 isl_pw_qpolynomial_free(pwqp1);
3671 if (equal < 0)
3672 return isl_stat_error;
3673 if (!equal)
3674 isl_die(ctx, isl_error_unknown,
3675 "unexpected result", return isl_stat_error);
3678 return isl_stat_ok;
3681 /* Perform a basic isl_pw_qpolynomial_max test.
3683 static isl_stat test_pwqp_max(isl_ctx *ctx)
3685 const char *str;
3686 isl_pw_qpolynomial *pwqp;
3687 isl_val *v;
3688 int ok;
3690 str = "{ [x=2:9, y] -> floor((x + 1)/4)^3 - floor((2x)/3)^2 }";
3691 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3692 v = isl_pw_qpolynomial_max(pwqp);
3693 ok = isl_val_cmp_si(v, -1) == 0;
3694 isl_val_free(v);
3696 if (!v)
3697 return isl_stat_error;
3698 if (!ok)
3699 isl_die(ctx, isl_error_unknown, "unexpected maximum",
3700 return isl_stat_error);
3702 return isl_stat_ok;
3705 static int test_pwqp(struct isl_ctx *ctx)
3707 const char *str;
3708 isl_set *set;
3709 isl_pw_qpolynomial *pwqp1, *pwqp2;
3710 int equal;
3712 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3713 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3715 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
3716 isl_dim_in, 1, 1);
3718 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3719 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3721 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3723 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3725 isl_pw_qpolynomial_free(pwqp1);
3727 if (test_pwqp_gist(ctx) < 0)
3728 return -1;
3730 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
3731 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3732 str = "{ [i] -> ([(2 * [i/2])/5]) }";
3733 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3735 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3737 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3739 isl_pw_qpolynomial_free(pwqp1);
3741 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
3742 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3743 str = "{ [x] -> x }";
3744 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3746 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3748 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3750 isl_pw_qpolynomial_free(pwqp1);
3752 str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3753 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3754 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3755 pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
3756 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3757 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3758 isl_pw_qpolynomial_free(pwqp1);
3760 str = "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3761 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3762 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3763 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3764 set = isl_set_read_from_str(ctx, "{ [a,b,a] }");
3765 pwqp1 = isl_pw_qpolynomial_intersect_domain(pwqp1, set);
3766 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
3767 isl_pw_qpolynomial_free(pwqp1);
3768 isl_pw_qpolynomial_free(pwqp2);
3769 if (equal < 0)
3770 return -1;
3771 if (!equal)
3772 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3774 str = "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3775 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3776 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3777 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3778 pwqp1 = isl_pw_qpolynomial_fix_val(pwqp1, isl_dim_set, 1,
3779 isl_val_one(ctx));
3780 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
3781 isl_pw_qpolynomial_free(pwqp1);
3782 isl_pw_qpolynomial_free(pwqp2);
3783 if (equal < 0)
3784 return -1;
3785 if (!equal)
3786 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3788 if (test_pwqp_max(ctx) < 0)
3789 return -1;
3791 return 0;
3794 static int test_split_periods(isl_ctx *ctx)
3796 const char *str;
3797 isl_pw_qpolynomial *pwqp;
3799 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3800 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3801 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3802 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3804 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
3806 isl_pw_qpolynomial_free(pwqp);
3808 if (!pwqp)
3809 return -1;
3811 return 0;
3814 static int test_union(isl_ctx *ctx)
3816 const char *str;
3817 isl_union_set *uset1, *uset2;
3818 isl_union_map *umap1, *umap2;
3819 int equal;
3821 str = "{ [i] : 0 <= i <= 1 }";
3822 uset1 = isl_union_set_read_from_str(ctx, str);
3823 str = "{ [1] -> [0] }";
3824 umap1 = isl_union_map_read_from_str(ctx, str);
3826 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
3827 equal = isl_union_map_is_equal(umap1, umap2);
3829 isl_union_map_free(umap1);
3830 isl_union_map_free(umap2);
3832 if (equal < 0)
3833 return -1;
3834 if (!equal)
3835 isl_die(ctx, isl_error_unknown, "union maps not equal",
3836 return -1);
3838 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3839 umap1 = isl_union_map_read_from_str(ctx, str);
3840 str = "{ A[i]; B[i] }";
3841 uset1 = isl_union_set_read_from_str(ctx, str);
3843 uset2 = isl_union_map_domain(umap1);
3845 equal = isl_union_set_is_equal(uset1, uset2);
3847 isl_union_set_free(uset1);
3848 isl_union_set_free(uset2);
3850 if (equal < 0)
3851 return -1;
3852 if (!equal)
3853 isl_die(ctx, isl_error_unknown, "union sets not equal",
3854 return -1);
3856 return 0;
3859 /* Inputs for basic isl_pw_qpolynomial_bound tests.
3860 * "type" is the type of bound that should be computed.
3861 * "poly" is a string representation of the input.
3862 * "bound" is a string representation of the expected result.
3863 * "tight" is set if the result is expected to be tight.
3865 static struct {
3866 int tight;
3867 enum isl_fold type;
3868 const char *poly;
3869 const char *bound;
3870 } bound_tests[] = {
3871 /* Check that computing a bound of a non-zero polynomial
3872 * over an unbounded domain does not produce a rational value.
3873 * In particular, check that the upper bound is infinity.
3875 { 0, isl_fold_max, "{ [m, n] -> -m * n }", "{ max(infty) }" },
3876 { 1, isl_fold_max, "{ [[a, b, c, d] -> [e]] -> 0 }",
3877 "{ [a, b, c, d] -> max(0) }" },
3878 { 1, isl_fold_max, "{ [[x] -> [x]] -> 1 : exists a : x = 2 a }",
3879 "{ [x] -> max(1) : x mod 2 = 0 }" },
3880 { 1, isl_fold_min, "{ [x=5:10] -> (x + 2)^2 }", "{ min(49) }" },
3881 { 1, isl_fold_max, "{ [0:10] -> 1 }", "{ max(1) }" },
3882 { 1, isl_fold_max, "{ [[m] -> [0:m]] -> m^2 }",
3883 "{ [m] -> max(m^2) : m >= 0 }" },
3884 { 1, isl_fold_max, "{ [[a=0:1] -> [b=0:1]] -> (floor((a + b)/2)) }",
3885 "{ [a=0:1] -> max(a) }" },
3888 /* Check that the bound computation can handle differences
3889 * in domain dimension names of the input polynomial and its domain.
3891 static isl_stat test_bound_space(isl_ctx *ctx)
3893 const char *str;
3894 isl_set *set;
3895 isl_pw_qpolynomial *pwqp;
3896 isl_pw_qpolynomial_fold *pwf;
3898 str = "{ [[c] -> [c]] }";
3899 set = isl_set_read_from_str(ctx, str);
3900 str = "{ [[a] -> [b]] -> 1 }";
3901 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3902 pwqp = isl_pw_qpolynomial_intersect_domain(pwqp, set);
3903 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3904 isl_pw_qpolynomial_fold_free(pwf);
3906 return isl_stat_non_null(pwf);
3909 /* Perform basic isl_pw_qpolynomial_bound tests.
3911 static int test_bound(isl_ctx *ctx)
3913 int i;
3915 if (test_bound_space(ctx) < 0)
3916 return -1;
3918 for (i = 0; i < ARRAY_SIZE(bound_tests); ++i) {
3919 const char *str;
3920 enum isl_fold type;
3921 isl_bool equal, tight;
3922 isl_pw_qpolynomial *pwqp;
3923 isl_pw_qpolynomial_fold *pwf1, *pwf2;
3925 str = bound_tests[i].poly;
3926 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3927 type = bound_tests[i].type;
3928 pwf1 = isl_pw_qpolynomial_bound(pwqp, type, &tight);
3929 str = bound_tests[i].bound;
3930 pwf2 = isl_pw_qpolynomial_fold_read_from_str(ctx, str);
3931 equal = isl_pw_qpolynomial_fold_plain_is_equal(pwf1, pwf2);
3932 isl_pw_qpolynomial_fold_free(pwf2);
3933 isl_pw_qpolynomial_fold_free(pwf1);
3934 if (equal < 0)
3935 return -1;
3936 if (!equal)
3937 isl_die(ctx, isl_error_unknown,
3938 "incorrect bound result", return -1);
3939 if (bound_tests[i].tight && !tight)
3940 isl_die(ctx, isl_error_unknown,
3941 "bound unexpectedly not tight", return -1);
3944 return 0;
3947 /* isl_set is defined to isl_map internally, so the corresponding elements
3948 * are isl_basic_map objects.
3950 #undef EL_BASE
3951 #undef SET_BASE
3952 #define EL_BASE basic_map
3953 #define SET_BASE set
3954 #include "isl_test_list_templ.c"
3956 #undef EL_BASE
3957 #undef SET_BASE
3958 #define EL_BASE basic_set
3959 #define SET_BASE union_set
3960 #include "isl_test_list_templ.c"
3962 #undef EL_BASE
3963 #undef SET_BASE
3964 #define EL_BASE set
3965 #define SET_BASE union_set
3966 #include "isl_test_list_templ.c"
3968 #undef EL_BASE
3969 #undef SET_BASE
3970 #define EL_BASE basic_map
3971 #define SET_BASE map
3972 #include "isl_test_list_templ.c"
3974 #undef EL_BASE
3975 #undef SET_BASE
3976 #define EL_BASE map
3977 #define SET_BASE union_map
3978 #include "isl_test_list_templ.c"
3980 /* Check that the conversion from isl objects to lists works as expected.
3982 static int test_get_list(isl_ctx *ctx)
3984 if (test_get_list_basic_map_from_set(ctx, "{ [0]; [2]; [3] }"))
3985 return -1;
3986 if (test_get_list_basic_set_from_union_set(ctx, "{ A[0]; B[2]; B[3] }"))
3987 return -1;
3988 if (test_get_list_set_from_union_set(ctx, "{ A[0]; A[2]; B[3] }"))
3989 return -1;
3990 if (test_get_list_basic_map_from_map(ctx,
3991 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"))
3992 return -1;
3993 if (test_get_list_map_from_union_map(ctx,
3994 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"))
3995 return -1;
3997 return 0;
4000 static int test_lift(isl_ctx *ctx)
4002 const char *str;
4003 isl_basic_map *bmap;
4004 isl_basic_set *bset;
4006 str = "{ [i0] : exists e0 : i0 = 4e0 }";
4007 bset = isl_basic_set_read_from_str(ctx, str);
4008 bset = isl_basic_set_lift(bset);
4009 bmap = isl_basic_map_from_range(bset);
4010 bset = isl_basic_map_domain(bmap);
4011 isl_basic_set_free(bset);
4013 return 0;
4016 /* Check that isl_set_is_subset is not confused by identical
4017 * integer divisions.
4018 * The call to isl_set_normalize ensures that the equality constraints
4019 * a = b = 0 are discovered, turning e0 and e1 into identical
4020 * integer divisions. Any further simplification would remove
4021 * the duplicate integer divisions.
4023 static isl_stat test_subset_duplicate_integer_divisions(isl_ctx *ctx)
4025 const char *str;
4026 isl_bool is_subset;
4027 isl_set *set1, *set2;
4029 str = "{ [a, b, c, d] : "
4030 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
4031 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
4032 "e3 = floor((-d + 4*floor((d)/4))/10): "
4033 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
4034 "b >= 0 and a <= 0 and b <= a) }";
4035 set1 = isl_set_read_from_str(ctx, str);
4036 set2 = isl_set_read_from_str(ctx, str);
4037 set2 = isl_set_normalize(set2);
4039 is_subset = isl_set_is_subset(set1, set2);
4041 isl_set_free(set1);
4042 isl_set_free(set2);
4044 if (is_subset < 0)
4045 return isl_stat_error;
4046 if (!is_subset)
4047 isl_die(ctx, isl_error_unknown,
4048 "set is not considered to be a subset of itself",
4049 return isl_stat_error);
4051 return isl_stat_ok;
4054 struct {
4055 const char *set1;
4056 const char *set2;
4057 int subset;
4058 } subset_tests[] = {
4059 { "{ [112, 0] }",
4060 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
4061 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
4062 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
4063 { "{ [65] }",
4064 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
4065 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
4066 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
4067 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
4068 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
4069 "256e0 <= 255i and 256e0 >= -255 + 255i and "
4070 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
4071 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
4072 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
4073 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
4074 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
4075 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
4076 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
4077 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
4078 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
4079 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
4080 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
4081 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
4082 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
4083 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
4084 "4e0 <= -57 + i0 + i1)) or "
4085 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
4086 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
4087 "4e0 >= -61 + i0 + i1)) or "
4088 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
4089 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
4092 static int test_subset(isl_ctx *ctx)
4094 int i;
4095 isl_set *set1, *set2;
4096 int subset;
4098 if (test_subset_duplicate_integer_divisions(ctx) < 0)
4099 return -1;
4101 for (i = 0; i < ARRAY_SIZE(subset_tests); ++i) {
4102 set1 = isl_set_read_from_str(ctx, subset_tests[i].set1);
4103 set2 = isl_set_read_from_str(ctx, subset_tests[i].set2);
4104 subset = isl_set_is_subset(set1, set2);
4105 isl_set_free(set1);
4106 isl_set_free(set2);
4107 if (subset < 0)
4108 return -1;
4109 if (subset != subset_tests[i].subset)
4110 isl_die(ctx, isl_error_unknown,
4111 "incorrect subset result", return -1);
4114 return 0;
4117 /* Perform a set subtraction with a set that has a non-obviously empty disjunct.
4118 * Older versions of isl would fail on such cases.
4120 static isl_stat test_subtract_empty(isl_ctx *ctx)
4122 const char *str;
4123 isl_set *s1, *s2;
4125 s1 = isl_set_read_from_str(ctx, "{ [0] }");
4126 str = "{ [a] : (exists (e0, e1, e2: 1056e1 <= 32 + a - 33e0 and "
4127 "1089e1 >= a - 33e0 and 1089e1 <= 1 + a - 33e0 and "
4128 "33e2 >= -a + 33e0 + 1056e1 and "
4129 "33e2 < -2a + 66e0 + 2112e1)) or a = 0 }";
4130 s2 = isl_set_read_from_str(ctx, str);
4131 s1 = isl_set_subtract(s1, s2);
4132 isl_set_free(s1);
4134 return isl_stat_non_null(s1);
4137 struct {
4138 const char *minuend;
4139 const char *subtrahend;
4140 const char *difference;
4141 } subtract_domain_tests[] = {
4142 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
4143 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
4144 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
4147 static int test_subtract(isl_ctx *ctx)
4149 int i;
4150 isl_union_map *umap1, *umap2;
4151 isl_union_pw_multi_aff *upma1, *upma2;
4152 isl_union_set *uset;
4153 int equal;
4155 if (test_subtract_empty(ctx) < 0)
4156 return -1;
4158 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests); ++i) {
4159 umap1 = isl_union_map_read_from_str(ctx,
4160 subtract_domain_tests[i].minuend);
4161 uset = isl_union_set_read_from_str(ctx,
4162 subtract_domain_tests[i].subtrahend);
4163 umap2 = isl_union_map_read_from_str(ctx,
4164 subtract_domain_tests[i].difference);
4165 umap1 = isl_union_map_subtract_domain(umap1, uset);
4166 equal = isl_union_map_is_equal(umap1, umap2);
4167 isl_union_map_free(umap1);
4168 isl_union_map_free(umap2);
4169 if (equal < 0)
4170 return -1;
4171 if (!equal)
4172 isl_die(ctx, isl_error_unknown,
4173 "incorrect subtract domain result", return -1);
4176 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests); ++i) {
4177 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
4178 subtract_domain_tests[i].minuend);
4179 uset = isl_union_set_read_from_str(ctx,
4180 subtract_domain_tests[i].subtrahend);
4181 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
4182 subtract_domain_tests[i].difference);
4183 upma1 = isl_union_pw_multi_aff_subtract_domain(upma1, uset);
4184 equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2);
4185 isl_union_pw_multi_aff_free(upma1);
4186 isl_union_pw_multi_aff_free(upma2);
4187 if (equal < 0)
4188 return -1;
4189 if (!equal)
4190 isl_die(ctx, isl_error_unknown,
4191 "incorrect subtract domain result", return -1);
4194 return 0;
4197 /* Check that intersecting the empty basic set with another basic set
4198 * does not increase the number of constraints. In particular,
4199 * the empty basic set should maintain its canonical representation.
4201 static int test_intersect_1(isl_ctx *ctx)
4203 isl_size n1, n2;
4204 isl_basic_set *bset1, *bset2;
4206 bset1 = isl_basic_set_read_from_str(ctx, "{ [a,b,c] : 1 = 0 }");
4207 bset2 = isl_basic_set_read_from_str(ctx, "{ [1,2,3] }");
4208 n1 = isl_basic_set_n_constraint(bset1);
4209 bset1 = isl_basic_set_intersect(bset1, bset2);
4210 n2 = isl_basic_set_n_constraint(bset1);
4211 isl_basic_set_free(bset1);
4212 if (n1 < 0 || n2 < 0)
4213 return -1;
4214 if (n1 != n2)
4215 isl_die(ctx, isl_error_unknown,
4216 "number of constraints of empty set changed",
4217 return -1);
4219 return 0;
4222 /* Check that intersecting a set with itself does not cause
4223 * an explosion in the number of disjuncts.
4225 static isl_stat test_intersect_2(isl_ctx *ctx)
4227 int i;
4228 isl_set *set;
4230 set = isl_set_read_from_str(ctx, "{ [x,y] : x >= 0 or y >= 0 }");
4231 for (i = 0; i < 100; ++i)
4232 set = isl_set_intersect(set, isl_set_copy(set));
4233 isl_set_free(set);
4234 if (!set)
4235 return isl_stat_error;
4236 return isl_stat_ok;
4239 /* Perform some intersection tests.
4241 static int test_intersect(isl_ctx *ctx)
4243 if (test_intersect_1(ctx) < 0)
4244 return -1;
4245 if (test_intersect_2(ctx) < 0)
4246 return -1;
4248 return 0;
4251 int test_factorize(isl_ctx *ctx)
4253 const char *str;
4254 isl_basic_set *bset;
4255 isl_factorizer *f;
4257 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
4258 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
4259 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
4260 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
4261 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
4262 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
4263 "3i5 >= -2i0 - i2 + 3i4 }";
4264 bset = isl_basic_set_read_from_str(ctx, str);
4265 f = isl_basic_set_factorizer(bset);
4266 isl_basic_set_free(bset);
4267 isl_factorizer_free(f);
4268 if (!f)
4269 isl_die(ctx, isl_error_unknown,
4270 "failed to construct factorizer", return -1);
4272 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
4273 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
4274 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
4275 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
4276 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
4277 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
4278 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
4279 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
4280 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
4281 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
4282 bset = isl_basic_set_read_from_str(ctx, str);
4283 f = isl_basic_set_factorizer(bset);
4284 isl_basic_set_free(bset);
4285 isl_factorizer_free(f);
4286 if (!f)
4287 isl_die(ctx, isl_error_unknown,
4288 "failed to construct factorizer", return -1);
4290 return 0;
4293 static isl_stat check_injective(__isl_take isl_map *map, void *user)
4295 int *injective = user;
4297 *injective = isl_map_is_injective(map);
4298 isl_map_free(map);
4300 if (*injective < 0 || !*injective)
4301 return isl_stat_error;
4303 return isl_stat_ok;
4306 int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
4307 const char *r, const char *s, int tilable, int parallel)
4309 int i;
4310 isl_union_set *D;
4311 isl_union_map *W, *R, *S;
4312 isl_union_map *empty;
4313 isl_union_map *dep_raw, *dep_war, *dep_waw, *dep;
4314 isl_union_map *validity, *proximity, *coincidence;
4315 isl_union_map *schedule;
4316 isl_union_map *test;
4317 isl_union_set *delta;
4318 isl_union_set *domain;
4319 isl_set *delta_set;
4320 isl_set *slice;
4321 isl_set *origin;
4322 isl_schedule_constraints *sc;
4323 isl_schedule *sched;
4324 int is_nonneg, is_parallel, is_tilable, is_injection, is_complete;
4325 isl_size n;
4327 D = isl_union_set_read_from_str(ctx, d);
4328 W = isl_union_map_read_from_str(ctx, w);
4329 R = isl_union_map_read_from_str(ctx, r);
4330 S = isl_union_map_read_from_str(ctx, s);
4332 W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
4333 R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
4335 empty = isl_union_map_empty(isl_union_map_get_space(S));
4336 isl_union_map_compute_flow(isl_union_map_copy(R),
4337 isl_union_map_copy(W), empty,
4338 isl_union_map_copy(S),
4339 &dep_raw, NULL, NULL, NULL);
4340 isl_union_map_compute_flow(isl_union_map_copy(W),
4341 isl_union_map_copy(W),
4342 isl_union_map_copy(R),
4343 isl_union_map_copy(S),
4344 &dep_waw, &dep_war, NULL, NULL);
4346 dep = isl_union_map_union(dep_waw, dep_war);
4347 dep = isl_union_map_union(dep, dep_raw);
4348 validity = isl_union_map_copy(dep);
4349 coincidence = isl_union_map_copy(dep);
4350 proximity = isl_union_map_copy(dep);
4352 sc = isl_schedule_constraints_on_domain(isl_union_set_copy(D));
4353 sc = isl_schedule_constraints_set_validity(sc, validity);
4354 sc = isl_schedule_constraints_set_coincidence(sc, coincidence);
4355 sc = isl_schedule_constraints_set_proximity(sc, proximity);
4356 sched = isl_schedule_constraints_compute_schedule(sc);
4357 schedule = isl_schedule_get_map(sched);
4358 isl_schedule_free(sched);
4359 isl_union_map_free(W);
4360 isl_union_map_free(R);
4361 isl_union_map_free(S);
4363 is_injection = 1;
4364 isl_union_map_foreach_map(schedule, &check_injective, &is_injection);
4366 domain = isl_union_map_domain(isl_union_map_copy(schedule));
4367 is_complete = isl_union_set_is_subset(D, domain);
4368 isl_union_set_free(D);
4369 isl_union_set_free(domain);
4371 test = isl_union_map_reverse(isl_union_map_copy(schedule));
4372 test = isl_union_map_apply_range(test, dep);
4373 test = isl_union_map_apply_range(test, schedule);
4375 delta = isl_union_map_deltas(test);
4376 n = isl_union_set_n_set(delta);
4377 if (n < 0) {
4378 isl_union_set_free(delta);
4379 return -1;
4381 if (n == 0) {
4382 is_tilable = 1;
4383 is_parallel = 1;
4384 is_nonneg = 1;
4385 isl_union_set_free(delta);
4386 } else {
4387 isl_size dim;
4389 delta_set = isl_set_from_union_set(delta);
4391 slice = isl_set_universe(isl_set_get_space(delta_set));
4392 for (i = 0; i < tilable; ++i)
4393 slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
4394 is_tilable = isl_set_is_subset(delta_set, slice);
4395 isl_set_free(slice);
4397 slice = isl_set_universe(isl_set_get_space(delta_set));
4398 for (i = 0; i < parallel; ++i)
4399 slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
4400 is_parallel = isl_set_is_subset(delta_set, slice);
4401 isl_set_free(slice);
4403 origin = isl_set_universe(isl_set_get_space(delta_set));
4404 dim = isl_set_dim(origin, isl_dim_set);
4405 if (dim < 0)
4406 origin = isl_set_free(origin);
4407 for (i = 0; i < dim; ++i)
4408 origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
4410 delta_set = isl_set_union(delta_set, isl_set_copy(origin));
4411 delta_set = isl_set_lexmin(delta_set);
4413 is_nonneg = isl_set_is_equal(delta_set, origin);
4415 isl_set_free(origin);
4416 isl_set_free(delta_set);
4419 if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
4420 is_injection < 0 || is_complete < 0)
4421 return -1;
4422 if (!is_complete)
4423 isl_die(ctx, isl_error_unknown,
4424 "generated schedule incomplete", return -1);
4425 if (!is_injection)
4426 isl_die(ctx, isl_error_unknown,
4427 "generated schedule not injective on each statement",
4428 return -1);
4429 if (!is_nonneg)
4430 isl_die(ctx, isl_error_unknown,
4431 "negative dependences in generated schedule",
4432 return -1);
4433 if (!is_tilable)
4434 isl_die(ctx, isl_error_unknown,
4435 "generated schedule not as tilable as expected",
4436 return -1);
4437 if (!is_parallel)
4438 isl_die(ctx, isl_error_unknown,
4439 "generated schedule not as parallel as expected",
4440 return -1);
4442 return 0;
4445 /* Compute a schedule for the given instance set, validity constraints,
4446 * proximity constraints and context and return a corresponding union map
4447 * representation.
4449 static __isl_give isl_union_map *compute_schedule_with_context(isl_ctx *ctx,
4450 const char *domain, const char *validity, const char *proximity,
4451 const char *context)
4453 isl_set *con;
4454 isl_union_set *dom;
4455 isl_union_map *dep;
4456 isl_union_map *prox;
4457 isl_schedule_constraints *sc;
4458 isl_schedule *schedule;
4459 isl_union_map *sched;
4461 con = isl_set_read_from_str(ctx, context);
4462 dom = isl_union_set_read_from_str(ctx, domain);
4463 dep = isl_union_map_read_from_str(ctx, validity);
4464 prox = isl_union_map_read_from_str(ctx, proximity);
4465 sc = isl_schedule_constraints_on_domain(dom);
4466 sc = isl_schedule_constraints_set_context(sc, con);
4467 sc = isl_schedule_constraints_set_validity(sc, dep);
4468 sc = isl_schedule_constraints_set_proximity(sc, prox);
4469 schedule = isl_schedule_constraints_compute_schedule(sc);
4470 sched = isl_schedule_get_map(schedule);
4471 isl_schedule_free(schedule);
4473 return sched;
4476 /* Compute a schedule for the given instance set, validity constraints and
4477 * proximity constraints and return a corresponding union map representation.
4479 static __isl_give isl_union_map *compute_schedule(isl_ctx *ctx,
4480 const char *domain, const char *validity, const char *proximity)
4482 return compute_schedule_with_context(ctx, domain, validity, proximity,
4483 "{ : }");
4486 /* Check that a schedule can be constructed on the given domain
4487 * with the given validity and proximity constraints.
4489 static int test_has_schedule(isl_ctx *ctx, const char *domain,
4490 const char *validity, const char *proximity)
4492 isl_union_map *sched;
4494 sched = compute_schedule(ctx, domain, validity, proximity);
4495 if (!sched)
4496 return -1;
4498 isl_union_map_free(sched);
4499 return 0;
4502 int test_special_schedule(isl_ctx *ctx, const char *domain,
4503 const char *validity, const char *proximity, const char *expected_sched)
4505 isl_union_map *sched1, *sched2;
4506 int equal;
4508 sched1 = compute_schedule(ctx, domain, validity, proximity);
4509 sched2 = isl_union_map_read_from_str(ctx, expected_sched);
4511 equal = isl_union_map_is_equal(sched1, sched2);
4512 isl_union_map_free(sched1);
4513 isl_union_map_free(sched2);
4515 if (equal < 0)
4516 return -1;
4517 if (!equal)
4518 isl_die(ctx, isl_error_unknown, "unexpected schedule",
4519 return -1);
4521 return 0;
4524 /* Check that the schedule map is properly padded, i.e., that the range
4525 * lives in a single space.
4527 static int test_padded_schedule(isl_ctx *ctx)
4529 const char *str;
4530 isl_union_set *D;
4531 isl_union_map *validity, *proximity;
4532 isl_schedule_constraints *sc;
4533 isl_schedule *sched;
4534 isl_union_map *umap;
4535 isl_union_set *range;
4536 isl_set *set;
4538 str = "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4539 D = isl_union_set_read_from_str(ctx, str);
4540 validity = isl_union_map_empty(isl_union_set_get_space(D));
4541 proximity = isl_union_map_copy(validity);
4542 sc = isl_schedule_constraints_on_domain(D);
4543 sc = isl_schedule_constraints_set_validity(sc, validity);
4544 sc = isl_schedule_constraints_set_proximity(sc, proximity);
4545 sched = isl_schedule_constraints_compute_schedule(sc);
4546 umap = isl_schedule_get_map(sched);
4547 isl_schedule_free(sched);
4548 range = isl_union_map_range(umap);
4549 set = isl_set_from_union_set(range);
4550 isl_set_free(set);
4552 if (!set)
4553 return -1;
4555 return 0;
4558 /* Check that conditional validity constraints are also taken into
4559 * account across bands.
4560 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4561 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4562 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4563 * is enforced by the rest of the schedule.
4565 static int test_special_conditional_schedule_constraints(isl_ctx *ctx)
4567 const char *str;
4568 isl_union_set *domain;
4569 isl_union_map *validity, *proximity, *condition;
4570 isl_union_map *sink, *source, *dep;
4571 isl_schedule_constraints *sc;
4572 isl_schedule *schedule;
4573 isl_union_access_info *access;
4574 isl_union_flow *flow;
4575 int empty;
4577 str = "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4578 "A[k] : k >= 1 and k <= -1 + n; "
4579 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4580 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4581 domain = isl_union_set_read_from_str(ctx, str);
4582 sc = isl_schedule_constraints_on_domain(domain);
4583 str = "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4584 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4585 "D[k, i] -> C[1 + k, i] : "
4586 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4587 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4588 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4589 validity = isl_union_map_read_from_str(ctx, str);
4590 sc = isl_schedule_constraints_set_validity(sc, validity);
4591 str = "[n] -> { C[k, i] -> D[k, i] : "
4592 "0 <= i <= -1 + k and k <= -1 + n }";
4593 proximity = isl_union_map_read_from_str(ctx, str);
4594 sc = isl_schedule_constraints_set_proximity(sc, proximity);
4595 str = "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4596 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4597 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4598 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4599 condition = isl_union_map_read_from_str(ctx, str);
4600 str = "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4601 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4602 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4603 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4604 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4605 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4606 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4607 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4608 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4609 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4610 validity = isl_union_map_read_from_str(ctx, str);
4611 sc = isl_schedule_constraints_set_conditional_validity(sc, condition,
4612 validity);
4613 schedule = isl_schedule_constraints_compute_schedule(sc);
4614 str = "{ D[2,0] -> [] }";
4615 sink = isl_union_map_read_from_str(ctx, str);
4616 access = isl_union_access_info_from_sink(sink);
4617 str = "{ C[2,1] -> [] }";
4618 source = isl_union_map_read_from_str(ctx, str);
4619 access = isl_union_access_info_set_must_source(access, source);
4620 access = isl_union_access_info_set_schedule(access, schedule);
4621 flow = isl_union_access_info_compute_flow(access);
4622 dep = isl_union_flow_get_must_dependence(flow);
4623 isl_union_flow_free(flow);
4624 empty = isl_union_map_is_empty(dep);
4625 isl_union_map_free(dep);
4627 if (empty < 0)
4628 return -1;
4629 if (empty)
4630 isl_die(ctx, isl_error_unknown,
4631 "conditional validity not respected", return -1);
4633 return 0;
4636 /* Check that the test for violated conditional validity constraints
4637 * is not confused by domain compression.
4638 * In particular, earlier versions of isl would apply
4639 * a schedule on the compressed domains to the original domains,
4640 * resulting in a failure to detect that the default schedule
4641 * violates the conditional validity constraints.
4643 static int test_special_conditional_schedule_constraints_2(isl_ctx *ctx)
4645 const char *str;
4646 isl_bool empty;
4647 isl_union_set *domain;
4648 isl_union_map *validity, *condition;
4649 isl_schedule_constraints *sc;
4650 isl_schedule *schedule;
4651 isl_union_map *umap;
4652 isl_map *map, *ge;
4654 str = "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4655 domain = isl_union_set_read_from_str(ctx, str);
4656 sc = isl_schedule_constraints_on_domain(domain);
4657 str = "{ B[1, i] -> A[0, i + 1] }";
4658 condition = isl_union_map_read_from_str(ctx, str);
4659 str = "{ A[0, i] -> B[1, i - 1] }";
4660 validity = isl_union_map_read_from_str(ctx, str);
4661 sc = isl_schedule_constraints_set_conditional_validity(sc, condition,
4662 isl_union_map_copy(validity));
4663 schedule = isl_schedule_constraints_compute_schedule(sc);
4664 umap = isl_schedule_get_map(schedule);
4665 isl_schedule_free(schedule);
4666 validity = isl_union_map_apply_domain(validity,
4667 isl_union_map_copy(umap));
4668 validity = isl_union_map_apply_range(validity, umap);
4669 map = isl_map_from_union_map(validity);
4670 ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map)));
4671 map = isl_map_intersect(map, ge);
4672 empty = isl_map_is_empty(map);
4673 isl_map_free(map);
4675 if (empty < 0)
4676 return -1;
4677 if (!empty)
4678 isl_die(ctx, isl_error_unknown,
4679 "conditional validity constraints not satisfied",
4680 return -1);
4682 return 0;
4685 /* Input for testing of schedule construction based on
4686 * conditional constraints.
4688 * domain is the iteration domain
4689 * flow are the flow dependences, which determine the validity and
4690 * proximity constraints
4691 * condition are the conditions on the conditional validity constraints
4692 * conditional_validity are the conditional validity constraints
4693 * outer_band_n is the expected number of members in the outer band
4695 struct {
4696 const char *domain;
4697 const char *flow;
4698 const char *condition;
4699 const char *conditional_validity;
4700 int outer_band_n;
4701 } live_range_tests[] = {
4702 /* Contrived example that illustrates that we need to keep
4703 * track of tagged condition dependences and
4704 * tagged conditional validity dependences
4705 * in isl_sched_edge separately.
4706 * In particular, the conditional validity constraints on A
4707 * cannot be satisfied,
4708 * but they can be ignored because there are no corresponding
4709 * condition constraints. However, we do have an additional
4710 * conditional validity constraint that maps to the same
4711 * dependence relation
4712 * as the condition constraint on B. If we did not make a distinction
4713 * between tagged condition and tagged conditional validity
4714 * dependences, then we
4715 * could end up treating this shared dependence as an condition
4716 * constraint on A, forcing a localization of the conditions,
4717 * which is impossible.
4719 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4720 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4721 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4722 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4723 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4724 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4727 /* TACO 2013 Fig. 7 */
4728 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4729 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4730 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4731 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4732 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4733 "0 <= i < n and 0 <= j < n - 1 }",
4734 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4735 "0 <= i < n and 0 <= j < j' < n;"
4736 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4737 "0 <= i < i' < n and 0 <= j,j' < n;"
4738 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4739 "0 <= i,j,j' < n and j < j' }",
4742 /* TACO 2013 Fig. 7, without tags */
4743 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4744 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4745 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4746 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4747 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4748 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4749 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4750 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4753 /* TACO 2013 Fig. 12 */
4754 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4755 "S3[i,3] : 0 <= i <= 1 }",
4756 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4757 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4758 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4759 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4760 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4761 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4762 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4763 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4764 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4765 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4766 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4771 /* Test schedule construction based on conditional constraints.
4772 * In particular, check the number of members in the outer band node
4773 * as an indication of whether tiling is possible or not.
4775 static int test_conditional_schedule_constraints(isl_ctx *ctx)
4777 int i;
4778 isl_union_set *domain;
4779 isl_union_map *condition;
4780 isl_union_map *flow;
4781 isl_union_map *validity;
4782 isl_schedule_constraints *sc;
4783 isl_schedule *schedule;
4784 isl_schedule_node *node;
4785 isl_size n_member;
4787 if (test_special_conditional_schedule_constraints(ctx) < 0)
4788 return -1;
4789 if (test_special_conditional_schedule_constraints_2(ctx) < 0)
4790 return -1;
4792 for (i = 0; i < ARRAY_SIZE(live_range_tests); ++i) {
4793 domain = isl_union_set_read_from_str(ctx,
4794 live_range_tests[i].domain);
4795 flow = isl_union_map_read_from_str(ctx,
4796 live_range_tests[i].flow);
4797 condition = isl_union_map_read_from_str(ctx,
4798 live_range_tests[i].condition);
4799 validity = isl_union_map_read_from_str(ctx,
4800 live_range_tests[i].conditional_validity);
4801 sc = isl_schedule_constraints_on_domain(domain);
4802 sc = isl_schedule_constraints_set_validity(sc,
4803 isl_union_map_copy(flow));
4804 sc = isl_schedule_constraints_set_proximity(sc, flow);
4805 sc = isl_schedule_constraints_set_conditional_validity(sc,
4806 condition, validity);
4807 schedule = isl_schedule_constraints_compute_schedule(sc);
4808 node = isl_schedule_get_root(schedule);
4809 while (node &&
4810 isl_schedule_node_get_type(node) != isl_schedule_node_band)
4811 node = isl_schedule_node_first_child(node);
4812 n_member = isl_schedule_node_band_n_member(node);
4813 isl_schedule_node_free(node);
4814 isl_schedule_free(schedule);
4816 if (!schedule || n_member < 0)
4817 return -1;
4818 if (n_member != live_range_tests[i].outer_band_n)
4819 isl_die(ctx, isl_error_unknown,
4820 "unexpected number of members in outer band",
4821 return -1);
4823 return 0;
4826 /* Check that the schedule computed for the given instance set and
4827 * dependence relation strongly satisfies the dependences.
4828 * In particular, check that no instance is scheduled before
4829 * or together with an instance on which it depends.
4830 * Earlier versions of isl would produce a schedule that
4831 * only weakly satisfies the dependences.
4833 static int test_strongly_satisfying_schedule(isl_ctx *ctx)
4835 const char *domain, *dep;
4836 isl_union_map *D, *schedule;
4837 isl_map *map, *ge;
4838 int empty;
4840 domain = "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4841 "A[i0] : 0 <= i0 <= 1 }";
4842 dep = "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4843 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4844 schedule = compute_schedule(ctx, domain, dep, dep);
4845 D = isl_union_map_read_from_str(ctx, dep);
4846 D = isl_union_map_apply_domain(D, isl_union_map_copy(schedule));
4847 D = isl_union_map_apply_range(D, schedule);
4848 map = isl_map_from_union_map(D);
4849 ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map)));
4850 map = isl_map_intersect(map, ge);
4851 empty = isl_map_is_empty(map);
4852 isl_map_free(map);
4854 if (empty < 0)
4855 return -1;
4856 if (!empty)
4857 isl_die(ctx, isl_error_unknown,
4858 "dependences not strongly satisfied", return -1);
4860 return 0;
4863 /* Compute a schedule for input where the instance set constraints
4864 * conflict with the context constraints.
4865 * Earlier versions of isl did not properly handle this situation.
4867 static int test_conflicting_context_schedule(isl_ctx *ctx)
4869 isl_union_map *schedule;
4870 const char *domain, *context;
4872 domain = "[n] -> { A[] : n >= 0 }";
4873 context = "[n] -> { : n < 0 }";
4874 schedule = compute_schedule_with_context(ctx,
4875 domain, "{}", "{}", context);
4876 isl_union_map_free(schedule);
4878 if (!schedule)
4879 return -1;
4881 return 0;
4884 /* Check that a set of schedule constraints that only allow for
4885 * a coalescing schedule still produces a schedule even if the user
4886 * request a non-coalescing schedule. Earlier versions of isl
4887 * would not handle this case correctly.
4889 static int test_coalescing_schedule(isl_ctx *ctx)
4891 const char *domain, *dep;
4892 isl_union_set *I;
4893 isl_union_map *D;
4894 isl_schedule_constraints *sc;
4895 isl_schedule *schedule;
4896 int treat_coalescing;
4898 domain = "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4899 dep = "{ S[a, b] -> S[a + b, 1 - b] }";
4900 I = isl_union_set_read_from_str(ctx, domain);
4901 D = isl_union_map_read_from_str(ctx, dep);
4902 sc = isl_schedule_constraints_on_domain(I);
4903 sc = isl_schedule_constraints_set_validity(sc, D);
4904 treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx);
4905 isl_options_set_schedule_treat_coalescing(ctx, 1);
4906 schedule = isl_schedule_constraints_compute_schedule(sc);
4907 isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing);
4908 isl_schedule_free(schedule);
4909 if (!schedule)
4910 return -1;
4911 return 0;
4914 /* Check that the scheduler does not perform any needless
4915 * compound skewing. Earlier versions of isl would compute
4916 * schedules in terms of transformed schedule coefficients and
4917 * would not accurately keep track of the sum of the original
4918 * schedule coefficients. It could then produce the schedule
4919 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4920 * for the input below instead of the schedule below.
4922 static int test_skewing_schedule(isl_ctx *ctx)
4924 const char *D, *V, *P, *S;
4926 D = "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4927 V = "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4928 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4929 "-1 <= a-i + b-j + c-k <= 1 }";
4930 P = "{ }";
4931 S = "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4933 return test_special_schedule(ctx, D, V, P, S);
4936 int test_schedule(isl_ctx *ctx)
4938 const char *D, *W, *R, *V, *P, *S;
4939 int max_coincidence;
4940 int treat_coalescing;
4942 /* Handle resulting schedule with zero bands. */
4943 if (test_one_schedule(ctx, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4944 return -1;
4946 /* Jacobi */
4947 D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4948 W = "{ S1[t,i] -> a[t,i] }";
4949 R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4950 "S1[t,i] -> a[t-1,i+1] }";
4951 S = "{ S1[t,i] -> [t,i] }";
4952 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4953 return -1;
4955 /* Fig. 5 of CC2008 */
4956 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4957 "j <= -1 + N }";
4958 W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4959 "j >= 2 and j <= -1 + N }";
4960 R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4961 "j >= 2 and j <= -1 + N; "
4962 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4963 "j >= 2 and j <= -1 + N }";
4964 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4965 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4966 return -1;
4968 D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4969 W = "{ S1[i] -> a[i] }";
4970 R = "{ S2[i] -> a[i+1] }";
4971 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4972 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4973 return -1;
4975 D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4976 W = "{ S1[i] -> a[i] }";
4977 R = "{ S2[i] -> a[9-i] }";
4978 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4979 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4980 return -1;
4982 D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4983 W = "{ S1[i] -> a[i] }";
4984 R = "[N] -> { S2[i] -> a[N-1-i] }";
4985 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4986 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4987 return -1;
4989 D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4990 W = "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4991 R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4992 S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4993 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4994 return -1;
4996 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4997 W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4998 R = "{ S2[i,j] -> a[i-1,j] }";
4999 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5000 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
5001 return -1;
5003 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
5004 W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
5005 R = "{ S2[i,j] -> a[i,j-1] }";
5006 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5007 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
5008 return -1;
5010 D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
5011 W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
5012 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
5013 R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
5014 S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
5015 "S_0[] -> [0, 0, 0] }";
5016 if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0)
5017 return -1;
5018 ctx->opt->schedule_parametric = 0;
5019 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5020 return -1;
5021 ctx->opt->schedule_parametric = 1;
5023 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
5024 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
5025 W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
5026 R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
5027 "S4[i] -> a[i,N] }";
5028 S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
5029 "S4[i] -> [4,i,0] }";
5030 max_coincidence = isl_options_get_schedule_maximize_coincidence(ctx);
5031 isl_options_set_schedule_maximize_coincidence(ctx, 0);
5032 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
5033 return -1;
5034 isl_options_set_schedule_maximize_coincidence(ctx, max_coincidence);
5036 D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
5037 W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5038 "j <= N }";
5039 R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5040 "j <= N; "
5041 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
5042 "j <= N }";
5043 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
5044 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5045 return -1;
5047 D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
5048 " S_2[t] : t >= 0 and t <= -1 + N; "
5049 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
5050 "i <= -1 + N }";
5051 W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
5052 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
5053 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
5054 "i >= 0 and i <= -1 + N }";
5055 R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
5056 "i >= 0 and i <= -1 + N; "
5057 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
5058 S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
5059 " S_0[t] -> [0, t, 0] }";
5061 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
5062 return -1;
5063 ctx->opt->schedule_parametric = 0;
5064 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5065 return -1;
5066 ctx->opt->schedule_parametric = 1;
5068 D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
5069 S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
5070 if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0)
5071 return -1;
5073 D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
5074 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
5075 W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
5076 "j >= 0 and j <= -1 + N; "
5077 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5078 R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
5079 "j >= 0 and j <= -1 + N; "
5080 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5081 S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
5082 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5083 return -1;
5085 D = "{ S_0[i] : i >= 0 }";
5086 W = "{ S_0[i] -> a[i] : i >= 0 }";
5087 R = "{ S_0[i] -> a[0] : i >= 0 }";
5088 S = "{ S_0[i] -> [0, i, 0] }";
5089 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5090 return -1;
5092 D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
5093 W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
5094 R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
5095 S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
5096 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5097 return -1;
5099 D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
5100 "k <= -1 + n and k >= 0 }";
5101 W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
5102 R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
5103 "k <= -1 + n and k >= 0; "
5104 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
5105 "k <= -1 + n and k >= 0; "
5106 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
5107 "k <= -1 + n and k >= 0 }";
5108 S = "[n] -> { S_0[j, k] -> [2, j, k] }";
5109 ctx->opt->schedule_outer_coincidence = 1;
5110 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5111 return -1;
5112 ctx->opt->schedule_outer_coincidence = 0;
5114 D = "{Stmt_for_body24[i0, i1, i2, i3]:"
5115 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
5116 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
5117 "Stmt_for_body24[i0, i1, 1, 0]:"
5118 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
5119 "Stmt_for_body7[i0, i1, i2]:"
5120 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
5121 "i2 <= 7 }";
5123 V = "{Stmt_for_body24[0, i1, i2, i3] -> "
5124 "Stmt_for_body24[1, i1, i2, i3]:"
5125 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
5126 "i2 >= 1;"
5127 "Stmt_for_body24[0, i1, i2, i3] -> "
5128 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
5129 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
5130 "i3 >= 0;"
5131 "Stmt_for_body24[0, i1, i2, i3] ->"
5132 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
5133 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
5134 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
5135 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
5136 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
5137 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
5138 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
5139 "i1 <= 6 and i1 >= 0;"
5140 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
5141 "Stmt_for_body7[i0, i1, i2] -> "
5142 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
5143 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
5144 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
5145 "Stmt_for_body7[i0, i1, i2] -> "
5146 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
5147 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
5148 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
5149 P = V;
5151 treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx);
5152 isl_options_set_schedule_treat_coalescing(ctx, 0);
5153 if (test_has_schedule(ctx, D, V, P) < 0)
5154 return -1;
5155 isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing);
5157 D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
5158 V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
5159 "j >= 1 and j <= 7;"
5160 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
5161 "j >= 1 and j <= 8 }";
5162 P = "{ }";
5163 S = "{ S_0[i, j] -> [i + j, i] }";
5164 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5165 if (test_special_schedule(ctx, D, V, P, S) < 0)
5166 return -1;
5167 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5169 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
5170 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
5171 "j >= 0 and j <= -1 + i }";
5172 V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
5173 "i <= -1 + N and j >= 0;"
5174 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
5175 "i <= -2 + N }";
5176 P = "{ }";
5177 S = "{ S_0[i, j] -> [i, j] }";
5178 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5179 if (test_special_schedule(ctx, D, V, P, S) < 0)
5180 return -1;
5181 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5183 /* Test both algorithms on a case with only proximity dependences. */
5184 D = "{ S[i,j] : 0 <= i <= 10 }";
5185 V = "{ }";
5186 P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
5187 S = "{ S[i, j] -> [j, i] }";
5188 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5189 if (test_special_schedule(ctx, D, V, P, S) < 0)
5190 return -1;
5191 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5192 if (test_special_schedule(ctx, D, V, P, S) < 0)
5193 return -1;
5195 D = "{ A[a]; B[] }";
5196 V = "{}";
5197 P = "{ A[a] -> B[] }";
5198 if (test_has_schedule(ctx, D, V, P) < 0)
5199 return -1;
5201 if (test_padded_schedule(ctx) < 0)
5202 return -1;
5204 /* Check that check for progress is not confused by rational
5205 * solution.
5207 D = "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
5208 V = "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
5209 "i0 <= -2 + N; "
5210 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
5211 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
5212 P = "{}";
5213 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5214 if (test_has_schedule(ctx, D, V, P) < 0)
5215 return -1;
5216 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5218 /* Check that we allow schedule rows that are only non-trivial
5219 * on some full-dimensional domains.
5221 D = "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
5222 V = "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
5223 "S1[j] -> S2[1] : 0 <= j <= 1 }";
5224 P = "{}";
5225 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5226 if (test_has_schedule(ctx, D, V, P) < 0)
5227 return -1;
5228 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5230 if (test_conditional_schedule_constraints(ctx) < 0)
5231 return -1;
5233 if (test_strongly_satisfying_schedule(ctx) < 0)
5234 return -1;
5236 if (test_conflicting_context_schedule(ctx) < 0)
5237 return -1;
5239 if (test_coalescing_schedule(ctx) < 0)
5240 return -1;
5241 if (test_skewing_schedule(ctx) < 0)
5242 return -1;
5244 return 0;
5247 /* Perform scheduling tests using the whole component scheduler.
5249 static int test_schedule_whole(isl_ctx *ctx)
5251 int whole;
5252 int r;
5254 whole = isl_options_get_schedule_whole_component(ctx);
5255 isl_options_set_schedule_whole_component(ctx, 1);
5256 r = test_schedule(ctx);
5257 isl_options_set_schedule_whole_component(ctx, whole);
5259 return r;
5262 /* Perform scheduling tests using the incremental scheduler.
5264 static int test_schedule_incremental(isl_ctx *ctx)
5266 int whole;
5267 int r;
5269 whole = isl_options_get_schedule_whole_component(ctx);
5270 isl_options_set_schedule_whole_component(ctx, 0);
5271 r = test_schedule(ctx);
5272 isl_options_set_schedule_whole_component(ctx, whole);
5274 return r;
5277 int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
5279 isl_union_map *umap;
5280 int test;
5282 umap = isl_union_map_read_from_str(ctx, str);
5283 test = isl_union_map_plain_is_injective(umap);
5284 isl_union_map_free(umap);
5285 if (test < 0)
5286 return -1;
5287 if (test == injective)
5288 return 0;
5289 if (injective)
5290 isl_die(ctx, isl_error_unknown,
5291 "map not detected as injective", return -1);
5292 else
5293 isl_die(ctx, isl_error_unknown,
5294 "map detected as injective", return -1);
5297 int test_injective(isl_ctx *ctx)
5299 const char *str;
5301 if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
5302 return -1;
5303 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
5304 return -1;
5305 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
5306 return -1;
5307 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
5308 return -1;
5309 if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
5310 return -1;
5311 if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
5312 return -1;
5313 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
5314 return -1;
5315 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
5316 return -1;
5318 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
5319 if (test_plain_injective(ctx, str, 1))
5320 return -1;
5321 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
5322 if (test_plain_injective(ctx, str, 0))
5323 return -1;
5325 return 0;
5328 #undef BASE
5329 #define BASE aff
5330 #include "isl_test_plain_equal_templ.c"
5332 #undef BASE
5333 #define BASE pw_multi_aff
5334 #include "isl_test_plain_equal_templ.c"
5336 #undef BASE
5337 #define BASE union_pw_aff
5338 #include "isl_test_plain_equal_templ.c"
5340 /* Basic tests on isl_union_pw_aff.
5342 * In particular, check that isl_union_pw_aff_aff_on_domain
5343 * aligns the parameters of the input objects and
5344 * that isl_union_pw_aff_param_on_domain_id properly
5345 * introduces the parameter.
5347 static int test_upa(isl_ctx *ctx)
5349 const char *str;
5350 isl_id *id;
5351 isl_aff *aff;
5352 isl_union_set *domain;
5353 isl_union_pw_aff *upa;
5354 isl_stat ok;
5356 aff = isl_aff_read_from_str(ctx, "[N] -> { [N] }");
5357 str = "[M] -> { A[i] : 0 <= i < M; B[] }";
5358 domain = isl_union_set_read_from_str(ctx, str);
5359 upa = isl_union_pw_aff_aff_on_domain(domain, aff);
5360 str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5361 ok = union_pw_aff_check_plain_equal(upa, str);
5362 isl_union_pw_aff_free(upa);
5363 if (ok < 0)
5364 return -1;
5366 id = isl_id_alloc(ctx, "N", NULL);
5367 str = "[M] -> { A[i] : 0 <= i < M; B[] }";
5368 domain = isl_union_set_read_from_str(ctx, str);
5369 upa = isl_union_pw_aff_param_on_domain_id(domain, id);
5370 str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5371 ok = union_pw_aff_check_plain_equal(upa, str);
5372 isl_union_pw_aff_free(upa);
5373 if (ok < 0)
5374 return -1;
5376 return 0;
5379 struct {
5380 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
5381 __isl_take isl_aff *aff2);
5382 } aff_bin_op[] = {
5383 ['+'] = { &isl_aff_add },
5384 ['-'] = { &isl_aff_sub },
5385 ['*'] = { &isl_aff_mul },
5386 ['/'] = { &isl_aff_div },
5389 struct {
5390 const char *arg1;
5391 unsigned char op;
5392 const char *arg2;
5393 const char *res;
5394 } aff_bin_tests[] = {
5395 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5396 "{ [i] -> [2i] }" },
5397 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5398 "{ [i] -> [0] }" },
5399 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5400 "{ [i] -> [2i] }" },
5401 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5402 "{ [i] -> [2i] }" },
5403 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5404 "{ [i] -> [i/2] }" },
5405 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5406 "{ [i] -> [i] }" },
5407 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5408 "{ [i] -> [NaN] }" },
5409 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5410 "{ [i] -> [NaN] }" },
5411 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5412 "{ [i] -> [NaN] }" },
5413 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5414 "{ [i] -> [NaN] }" },
5415 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5416 "{ [i] -> [NaN] }" },
5417 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5418 "{ [i] -> [NaN] }" },
5419 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5420 "{ [i] -> [NaN] }" },
5421 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5422 "{ [i] -> [NaN] }" },
5423 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5424 "{ [i] -> [NaN] }" },
5425 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5426 "{ [i] -> [NaN] }" },
5427 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5428 "{ [i] -> [NaN] }" },
5429 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5430 "{ [i] -> [NaN] }" },
5431 { "{ [i] -> [i] }", '/', "{ [i] -> [0] }",
5432 "{ [i] -> [NaN] }" },
5435 /* Perform some basic tests of binary operations on isl_aff objects.
5437 static int test_bin_aff(isl_ctx *ctx)
5439 int i;
5440 isl_aff *aff1, *aff2, *res;
5441 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
5442 __isl_take isl_aff *aff2);
5443 int ok;
5445 for (i = 0; i < ARRAY_SIZE(aff_bin_tests); ++i) {
5446 aff1 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg1);
5447 aff2 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg2);
5448 res = isl_aff_read_from_str(ctx, aff_bin_tests[i].res);
5449 fn = aff_bin_op[aff_bin_tests[i].op].fn;
5450 aff1 = fn(aff1, aff2);
5451 if (isl_aff_is_nan(res))
5452 ok = isl_aff_is_nan(aff1);
5453 else
5454 ok = isl_aff_plain_is_equal(aff1, res);
5455 isl_aff_free(aff1);
5456 isl_aff_free(res);
5457 if (ok < 0)
5458 return -1;
5459 if (!ok)
5460 isl_die(ctx, isl_error_unknown,
5461 "unexpected result", return -1);
5464 return 0;
5467 struct {
5468 __isl_give isl_pw_aff *(*fn)(__isl_take isl_pw_aff *pa1,
5469 __isl_take isl_pw_aff *pa2);
5470 } pw_aff_bin_op[] = {
5471 ['m'] = { &isl_pw_aff_min },
5472 ['M'] = { &isl_pw_aff_max },
5475 /* Inputs for binary isl_pw_aff operation tests.
5476 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5477 * defined by pw_aff_bin_op, and "res" is the expected result.
5479 struct {
5480 const char *arg1;
5481 unsigned char op;
5482 const char *arg2;
5483 const char *res;
5484 } pw_aff_bin_tests[] = {
5485 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5486 "{ [i] -> [i] }" },
5487 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5488 "{ [i] -> [i] }" },
5489 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5490 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5491 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5492 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5493 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5494 "{ [i] -> [NaN] }" },
5495 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5496 "{ [i] -> [NaN] }" },
5499 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5501 static int test_bin_pw_aff(isl_ctx *ctx)
5503 int i;
5504 isl_bool ok;
5505 isl_pw_aff *pa1, *pa2, *res;
5507 for (i = 0; i < ARRAY_SIZE(pw_aff_bin_tests); ++i) {
5508 pa1 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg1);
5509 pa2 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg2);
5510 res = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].res);
5511 pa1 = pw_aff_bin_op[pw_aff_bin_tests[i].op].fn(pa1, pa2);
5512 if (isl_pw_aff_involves_nan(res))
5513 ok = isl_pw_aff_involves_nan(pa1);
5514 else
5515 ok = isl_pw_aff_plain_is_equal(pa1, res);
5516 isl_pw_aff_free(pa1);
5517 isl_pw_aff_free(res);
5518 if (ok < 0)
5519 return -1;
5520 if (!ok)
5521 isl_die(ctx, isl_error_unknown,
5522 "unexpected result", return -1);
5525 return 0;
5528 /* Inputs for basic tests of test operations on
5529 * isl_union_pw_multi_aff objects.
5530 * "fn" is the function that is being tested.
5531 * "arg" is a string description of the input.
5532 * "res" is the expected result.
5534 static struct {
5535 isl_bool (*fn)(__isl_keep isl_union_pw_multi_aff *upma1);
5536 const char *arg;
5537 isl_bool res;
5538 } upma_test_tests[] = {
5539 { &isl_union_pw_multi_aff_involves_nan, "{ A[] -> [0]; B[0] -> [1] }",
5540 isl_bool_false },
5541 { &isl_union_pw_multi_aff_involves_nan, "{ A[] -> [NaN]; B[0] -> [1] }",
5542 isl_bool_true },
5543 { &isl_union_pw_multi_aff_involves_nan, "{ A[] -> [0]; B[0] -> [NaN] }",
5544 isl_bool_true },
5545 { &isl_union_pw_multi_aff_involves_nan,
5546 "{ A[] -> [0]; B[0] -> [1, NaN, 5] }",
5547 isl_bool_true },
5548 { &isl_union_pw_multi_aff_involves_locals,
5549 "{ A[] -> [0]; B[0] -> [1] }",
5550 isl_bool_false },
5551 { &isl_union_pw_multi_aff_involves_locals,
5552 "{ A[] -> [0]; B[x] -> [1] : x mod 2 = 0 }",
5553 isl_bool_true },
5554 { &isl_union_pw_multi_aff_involves_locals,
5555 "{ A[] -> [0]; B[x] -> [x // 2] }",
5556 isl_bool_true },
5557 { &isl_union_pw_multi_aff_involves_locals,
5558 "{ A[i] -> [i // 2]; B[0] -> [1] }",
5559 isl_bool_true },
5562 /* Perform some basic tests of test operations on
5563 * isl_union_pw_multi_aff objects.
5565 static isl_stat test_upma_test(isl_ctx *ctx)
5567 int i;
5568 isl_union_pw_multi_aff *upma;
5569 isl_bool res;
5571 for (i = 0; i < ARRAY_SIZE(upma_test_tests); ++i) {
5572 const char *str;
5574 str = upma_test_tests[i].arg;
5575 upma = isl_union_pw_multi_aff_read_from_str(ctx, str);
5576 res = upma_test_tests[i].fn(upma);
5577 isl_union_pw_multi_aff_free(upma);
5578 if (res < 0)
5579 return isl_stat_error;
5580 if (res != upma_test_tests[i].res)
5581 isl_die(ctx, isl_error_unknown,
5582 "unexpected result", return isl_stat_error);
5585 return isl_stat_ok;
5588 struct {
5589 __isl_give isl_union_pw_multi_aff *(*fn)(
5590 __isl_take isl_union_pw_multi_aff *upma1,
5591 __isl_take isl_union_pw_multi_aff *upma2);
5592 const char *arg1;
5593 const char *arg2;
5594 const char *res;
5595 } upma_bin_tests[] = {
5596 { &isl_union_pw_multi_aff_add, "{ A[] -> [0]; B[0] -> [1] }",
5597 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5598 { &isl_union_pw_multi_aff_union_add, "{ A[] -> [0]; B[0] -> [1] }",
5599 "{ B[x] -> [2] : x >= 0 }",
5600 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5601 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff,
5602 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5603 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5604 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5605 "D[i] -> B[2] : i >= 5 }" },
5606 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5607 "{ B[x] -> C[2] : x > 0 }",
5608 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5609 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5610 "{ B[x] -> A[2] : x >= 0 }",
5611 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5613 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff,
5614 "{ B[x] -> C[x + 2] }",
5615 "{ D[y] -> B[2y] }",
5616 "{ }" },
5618 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff,
5619 "{ [A[x] -> B[x + 1]] -> C[x + 2] }",
5620 "{ D[y] -> B[2y] }",
5621 "{ }" },
5623 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff,
5624 "{ [A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5625 "{ D[y] -> A[2y] }",
5626 "{ [D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5628 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff,
5629 "{ T[A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5630 "{ D[y] -> A[2y] }",
5631 "{ T[D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5634 /* Perform some basic tests of binary operations on
5635 * isl_union_pw_multi_aff objects.
5637 static int test_bin_upma(isl_ctx *ctx)
5639 int i;
5640 isl_union_pw_multi_aff *upma1, *upma2, *res;
5641 int ok;
5643 for (i = 0; i < ARRAY_SIZE(upma_bin_tests); ++i) {
5644 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
5645 upma_bin_tests[i].arg1);
5646 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
5647 upma_bin_tests[i].arg2);
5648 res = isl_union_pw_multi_aff_read_from_str(ctx,
5649 upma_bin_tests[i].res);
5650 upma1 = upma_bin_tests[i].fn(upma1, upma2);
5651 ok = isl_union_pw_multi_aff_plain_is_equal(upma1, res);
5652 isl_union_pw_multi_aff_free(upma1);
5653 isl_union_pw_multi_aff_free(res);
5654 if (ok < 0)
5655 return -1;
5656 if (!ok)
5657 isl_die(ctx, isl_error_unknown,
5658 "unexpected result", return -1);
5661 return 0;
5664 struct {
5665 __isl_give isl_union_pw_multi_aff *(*fn)(
5666 __isl_take isl_union_pw_multi_aff *upma1,
5667 __isl_take isl_union_pw_multi_aff *upma2);
5668 const char *arg1;
5669 const char *arg2;
5670 } upma_bin_fail_tests[] = {
5671 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5672 "{ B[x] -> C[2] : x >= 0 }" },
5675 /* Perform some basic tests of binary operations on
5676 * isl_union_pw_multi_aff objects that are expected to fail.
5678 static int test_bin_upma_fail(isl_ctx *ctx)
5680 int i, n;
5681 isl_union_pw_multi_aff *upma1, *upma2;
5682 int on_error;
5684 on_error = isl_options_get_on_error(ctx);
5685 isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE);
5686 n = ARRAY_SIZE(upma_bin_fail_tests);
5687 for (i = 0; i < n; ++i) {
5688 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
5689 upma_bin_fail_tests[i].arg1);
5690 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
5691 upma_bin_fail_tests[i].arg2);
5692 upma1 = upma_bin_fail_tests[i].fn(upma1, upma2);
5693 isl_union_pw_multi_aff_free(upma1);
5694 if (upma1)
5695 break;
5697 isl_options_set_on_error(ctx, on_error);
5698 if (i < n)
5699 isl_die(ctx, isl_error_unknown,
5700 "operation not expected to succeed", return -1);
5702 return 0;
5705 /* Inputs for basic tests of binary operations on
5706 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5707 * "fn" is the function that is being tested.
5708 * "arg1" and "arg2" are string descriptions of the inputs.
5709 * "res" is a string description of the expected result.
5711 struct {
5712 __isl_give isl_union_pw_multi_aff *(*fn)(
5713 __isl_take isl_union_pw_multi_aff *upma,
5714 __isl_take isl_union_set *uset);
5715 const char *arg1;
5716 const char *arg2;
5717 const char *res;
5718 } upma_uset_tests[] = {
5719 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5720 "{ A[i] -> B[i] }", "{ B[0] }",
5721 "{ }" },
5722 { &isl_union_pw_multi_aff_intersect_domain_wrapped_domain,
5723 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5724 "{ [A[1] -> B[1]] -> C[2] }" },
5725 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5726 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5727 "{ [A[0] -> B[0]] -> C[1] }" },
5728 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5729 "{ [A[i] -> B[i]] -> C[i + 1] }", "[N] -> { B[N] }",
5730 "[N] -> { [A[N] -> B[N]] -> C[N + 1] }" },
5731 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5732 "[M] -> { [A[M] -> B[M]] -> C[M + 1] }", "[N] -> { B[N] }",
5733 "[N, M] -> { [A[N] -> B[N]] -> C[N + 1] : N = M }" },
5734 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5735 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[]; [B[] -> A[]] -> E[] }",
5736 "{ B[] }",
5737 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[] }" },
5740 /* Perform some basic tests of binary operations on
5741 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5743 static isl_stat test_upma_uset(isl_ctx *ctx)
5745 int i;
5746 isl_bool ok;
5747 isl_union_pw_multi_aff *upma, *res;
5748 isl_union_set *uset;
5750 for (i = 0; i < ARRAY_SIZE(upma_uset_tests); ++i) {
5751 upma = isl_union_pw_multi_aff_read_from_str(ctx,
5752 upma_uset_tests[i].arg1);
5753 uset = isl_union_set_read_from_str(ctx,
5754 upma_uset_tests[i].arg2);
5755 res = isl_union_pw_multi_aff_read_from_str(ctx,
5756 upma_uset_tests[i].res);
5757 upma = upma_uset_tests[i].fn(upma, uset);
5758 ok = isl_union_pw_multi_aff_plain_is_equal(upma, res);
5759 isl_union_pw_multi_aff_free(upma);
5760 isl_union_pw_multi_aff_free(res);
5761 if (ok < 0)
5762 return isl_stat_error;
5763 if (!ok)
5764 isl_die(ctx, isl_error_unknown,
5765 "unexpected result", return isl_stat_error);
5768 return isl_stat_ok;
5771 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5772 * "fn" is the function that is tested.
5773 * "arg" is a string description of the input.
5774 * "res" is a string description of the expected result.
5776 struct {
5777 __isl_give isl_multi_pw_aff *(*fn)(__isl_take isl_multi_pw_aff *mpa);
5778 const char *arg;
5779 const char *res;
5780 } mpa_un_tests[] = {
5781 { &isl_multi_pw_aff_range_factor_domain,
5782 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5783 "{ A[x] -> B[(1 : x >= 5)] }" },
5784 { &isl_multi_pw_aff_range_factor_range,
5785 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5786 "{ A[y] -> C[(2 : y <= 10)] }" },
5787 { &isl_multi_pw_aff_range_factor_domain,
5788 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5789 "{ A[x] -> B[(1 : x >= 5)] }" },
5790 { &isl_multi_pw_aff_range_factor_range,
5791 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5792 "{ A[y] -> C[] }" },
5793 { &isl_multi_pw_aff_range_factor_domain,
5794 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5795 "{ A[x] -> B[] }" },
5796 { &isl_multi_pw_aff_range_factor_range,
5797 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5798 "{ A[y] -> C[(2 : y <= 10)] }" },
5799 { &isl_multi_pw_aff_range_factor_domain,
5800 "{ A[x] -> [B[] -> C[]] }",
5801 "{ A[x] -> B[] }" },
5802 { &isl_multi_pw_aff_range_factor_range,
5803 "{ A[x] -> [B[] -> C[]] }",
5804 "{ A[y] -> C[] }" },
5805 { &isl_multi_pw_aff_factor_range,
5806 "{ [B[] -> C[]] }",
5807 "{ C[] }" },
5808 { &isl_multi_pw_aff_range_factor_domain,
5809 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5810 "{ A[x] -> B[] : x >= 0 }" },
5811 { &isl_multi_pw_aff_range_factor_range,
5812 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5813 "{ A[y] -> C[] : y >= 0 }" },
5814 { &isl_multi_pw_aff_factor_range,
5815 "[N] -> { [B[] -> C[]] : N >= 0 }",
5816 "[N] -> { C[] : N >= 0 }" },
5819 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5821 static int test_un_mpa(isl_ctx *ctx)
5823 int i;
5824 isl_bool ok;
5825 isl_multi_pw_aff *mpa, *res;
5827 for (i = 0; i < ARRAY_SIZE(mpa_un_tests); ++i) {
5828 mpa = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].arg);
5829 res = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].res);
5830 mpa = mpa_un_tests[i].fn(mpa);
5831 ok = isl_multi_pw_aff_plain_is_equal(mpa, res);
5832 isl_multi_pw_aff_free(mpa);
5833 isl_multi_pw_aff_free(res);
5834 if (ok < 0)
5835 return -1;
5836 if (!ok)
5837 isl_die(ctx, isl_error_unknown,
5838 "unexpected result", return -1);
5841 return 0;
5844 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5845 * "fn" is the function that is tested.
5846 * "arg1" and "arg2" are string descriptions of the inputs.
5847 * "res" is a string description of the expected result.
5849 struct {
5850 __isl_give isl_multi_pw_aff *(*fn)(
5851 __isl_take isl_multi_pw_aff *mpa1,
5852 __isl_take isl_multi_pw_aff *mpa2);
5853 const char *arg1;
5854 const char *arg2;
5855 const char *res;
5856 } mpa_bin_tests[] = {
5857 { &isl_multi_pw_aff_add, "{ A[] -> [1] }", "{ A[] -> [2] }",
5858 "{ A[] -> [3] }" },
5859 { &isl_multi_pw_aff_add, "{ A[x] -> [(1 : x >= 5)] }",
5860 "{ A[x] -> [(x : x <= 10)] }",
5861 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5862 { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }",
5863 "{ A[x] -> [] : x <= 10 }",
5864 "{ A[x] -> [] : 5 <= x <= 10 }" },
5865 { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }",
5866 "[N] -> { A[x] -> [] : x <= N }",
5867 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5868 { &isl_multi_pw_aff_add,
5869 "[N] -> { A[x] -> [] : x <= N }",
5870 "{ A[x] -> [] : x >= 5 }",
5871 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5872 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }",
5873 "{ A[y] -> C[(2 : y <= 10)] }",
5874 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5875 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }",
5876 "{ A[y] -> C[2] : y <= 10 }",
5877 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5878 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }",
5879 "[N] -> { A[y] -> C[2] : y <= N }",
5880 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5881 { &isl_multi_pw_aff_range_product, "[N] -> { A[x] -> B[1] : x >= N }",
5882 "{ A[y] -> C[2] : y <= 10 }",
5883 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5884 { &isl_multi_pw_aff_range_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5885 "{ A[] -> [B[1] -> C[2]] }" },
5886 { &isl_multi_pw_aff_range_product, "{ A[] -> B[] }", "{ A[] -> C[] }",
5887 "{ A[] -> [B[] -> C[]] }" },
5888 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }",
5889 "{ A[y] -> C[] : y <= 10 }",
5890 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5891 { &isl_multi_pw_aff_range_product, "{ A[y] -> C[] : y <= 10 }",
5892 "{ A[x] -> B[(1 : x >= 5)] }",
5893 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5894 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5895 "{ A[y] -> C[(2 : y <= 10)] }",
5896 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5897 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5898 "{ A[y] -> C[] : y <= 10 }",
5899 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5900 { &isl_multi_pw_aff_product, "{ A[y] -> C[] : y <= 10 }",
5901 "{ A[x] -> B[(1 : x >= 5)] }",
5902 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5903 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5904 "[N] -> { A[y] -> C[] : y <= N }",
5905 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5906 { &isl_multi_pw_aff_product, "[N] -> { A[y] -> C[] : y <= N }",
5907 "{ A[x] -> B[(1 : x >= 5)] }",
5908 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5909 { &isl_multi_pw_aff_product, "{ A[x] -> B[] : x >= 5 }",
5910 "{ A[y] -> C[] : y <= 10 }",
5911 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5912 { &isl_multi_pw_aff_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5913 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5914 { &isl_multi_pw_aff_product, "{ A[] -> B[] }", "{ A[] -> C[] }",
5915 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5916 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5917 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5918 "{ A[a,b] -> C[b + 2a] }" },
5919 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5920 "{ B[i,j] -> C[i + 2j] }",
5921 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5922 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5923 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5924 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5925 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5926 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5927 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5928 "{ B[i,j] -> C[] }",
5929 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5930 "{ A[a,b] -> C[] }" },
5931 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5932 "{ B[i,j] -> C[] : i > j }",
5933 "{ A[a,b] -> B[b,a] }",
5934 "{ A[a,b] -> C[] : b > a }" },
5935 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5936 "{ B[i,j] -> C[] : j > 5 }",
5937 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5938 "{ A[a,b] -> C[] : b > a > 5 }" },
5939 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5940 "[N] -> { B[i,j] -> C[] : j > N }",
5941 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5942 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5943 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5944 "[M,N] -> { B[] -> C[] : N > 5 }",
5945 "[M,N] -> { A[] -> B[] : M > N }",
5946 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5949 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5951 static int test_bin_mpa(isl_ctx *ctx)
5953 int i;
5954 isl_bool ok;
5955 isl_multi_pw_aff *mpa1, *mpa2, *res;
5957 for (i = 0; i < ARRAY_SIZE(mpa_bin_tests); ++i) {
5958 mpa1 = isl_multi_pw_aff_read_from_str(ctx,
5959 mpa_bin_tests[i].arg1);
5960 mpa2 = isl_multi_pw_aff_read_from_str(ctx,
5961 mpa_bin_tests[i].arg2);
5962 res = isl_multi_pw_aff_read_from_str(ctx,
5963 mpa_bin_tests[i].res);
5964 mpa1 = mpa_bin_tests[i].fn(mpa1, mpa2);
5965 ok = isl_multi_pw_aff_plain_is_equal(mpa1, res);
5966 isl_multi_pw_aff_free(mpa1);
5967 isl_multi_pw_aff_free(res);
5968 if (ok < 0)
5969 return -1;
5970 if (!ok)
5971 isl_die(ctx, isl_error_unknown,
5972 "unexpected result", return -1);
5975 return 0;
5978 /* Inputs for basic tests of unary operations on
5979 * isl_multi_union_pw_aff objects.
5980 * "fn" is the function that is tested.
5981 * "arg" is a string description of the input.
5982 * "res" is a string description of the expected result.
5984 struct {
5985 __isl_give isl_multi_union_pw_aff *(*fn)(
5986 __isl_take isl_multi_union_pw_aff *mupa);
5987 const char *arg;
5988 const char *res;
5989 } mupa_un_tests[] = {
5990 { &isl_multi_union_pw_aff_factor_range,
5991 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5992 "C[{ A[] -> [2] }]" },
5993 { &isl_multi_union_pw_aff_factor_range,
5994 "[B[] -> C[{ A[] -> [2] }]]",
5995 "C[{ A[] -> [2] }]" },
5996 { &isl_multi_union_pw_aff_factor_range,
5997 "[B[{ A[] -> [1] }] -> C[]]",
5998 "C[]" },
5999 { &isl_multi_union_pw_aff_factor_range,
6000 "[B[] -> C[]]",
6001 "C[]" },
6002 { &isl_multi_union_pw_aff_factor_range,
6003 "([B[] -> C[]] : { A[x] : x >= 0 })",
6004 "(C[] : { A[x] : x >= 0 })" },
6005 { &isl_multi_union_pw_aff_factor_range,
6006 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
6007 "[N] -> (C[] : { A[x] : x <= N })" },
6008 { &isl_multi_union_pw_aff_factor_range,
6009 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
6010 "[N] -> (C[] : { : N >= 0 })" },
6013 /* Perform some basic tests of unary operations on
6014 * isl_multi_union_pw_aff objects.
6016 static int test_un_mupa(isl_ctx *ctx)
6018 int i;
6019 isl_bool ok;
6020 isl_multi_union_pw_aff *mupa, *res;
6022 for (i = 0; i < ARRAY_SIZE(mupa_un_tests); ++i) {
6023 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6024 mupa_un_tests[i].arg);
6025 res = isl_multi_union_pw_aff_read_from_str(ctx,
6026 mupa_un_tests[i].res);
6027 mupa = mupa_un_tests[i].fn(mupa);
6028 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6029 isl_multi_union_pw_aff_free(mupa);
6030 isl_multi_union_pw_aff_free(res);
6031 if (ok < 0)
6032 return -1;
6033 if (!ok)
6034 isl_die(ctx, isl_error_unknown,
6035 "unexpected result", return -1);
6038 return 0;
6041 /* Inputs for basic tests of binary operations on
6042 * isl_multi_union_pw_aff objects.
6043 * "fn" is the function that is tested.
6044 * "arg1" and "arg2" are string descriptions of the inputs.
6045 * "res" is a string description of the expected result.
6047 struct {
6048 __isl_give isl_multi_union_pw_aff *(*fn)(
6049 __isl_take isl_multi_union_pw_aff *mupa1,
6050 __isl_take isl_multi_union_pw_aff *mupa2);
6051 const char *arg1;
6052 const char *arg2;
6053 const char *res;
6054 } mupa_bin_tests[] = {
6055 { &isl_multi_union_pw_aff_add, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6056 "[{ A[] -> [3] }]" },
6057 { &isl_multi_union_pw_aff_sub, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6058 "[{ A[] -> [-1] }]" },
6059 { &isl_multi_union_pw_aff_add,
6060 "[{ A[] -> [1]; B[] -> [4] }]",
6061 "[{ A[] -> [2]; C[] -> [5] }]",
6062 "[{ A[] -> [3] }]" },
6063 { &isl_multi_union_pw_aff_union_add,
6064 "[{ A[] -> [1]; B[] -> [4] }]",
6065 "[{ A[] -> [2]; C[] -> [5] }]",
6066 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
6067 { &isl_multi_union_pw_aff_add, "[{ A[x] -> [(1)] : x >= 5 }]",
6068 "[{ A[x] -> [(x)] : x <= 10 }]",
6069 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
6070 { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })",
6071 "([] : { A[x] : x <= 10 })",
6072 "([] : { A[x] : 5 <= x <= 10 })" },
6073 { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })",
6074 "[N] -> ([] : { A[x] : x <= N })",
6075 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
6076 { &isl_multi_union_pw_aff_add, "[N] -> ([] : { A[x] : x >= N })",
6077 "([] : { A[x] : x <= 10 })",
6078 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
6079 { &isl_multi_union_pw_aff_union_add, "[{ A[x] -> [(1)] : x >= 5 }]",
6080 "[{ A[x] -> [(x)] : x <= 10 }]",
6081 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
6082 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
6083 { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 5 })",
6084 "([] : { A[x] : x <= 10 })",
6085 "([] : { A[x] })" },
6086 { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 0 })",
6087 "[N] -> ([] : { A[x] : x >= N })",
6088 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
6089 { &isl_multi_union_pw_aff_union_add,
6090 "[N] -> ([] : { A[] : N >= 0})",
6091 "[N] -> ([] : { A[] : N <= 0})",
6092 "[N] -> ([] : { A[] })" },
6093 { &isl_multi_union_pw_aff_union_add,
6094 "[N] -> ([] : { A[] })",
6095 "[N] -> ([] : { : })",
6096 "[N] -> ([] : { : })" },
6097 { &isl_multi_union_pw_aff_union_add,
6098 "[N] -> ([] : { : })",
6099 "[N] -> ([] : { A[] })",
6100 "[N] -> ([] : { : })" },
6101 { &isl_multi_union_pw_aff_union_add,
6102 "[N] -> ([] : { : N >= 0})",
6103 "[N] -> ([] : { : N <= 0})",
6104 "[N] -> ([] : { : })" },
6105 { &isl_multi_union_pw_aff_range_product,
6106 "B[{ A[] -> [1] }]",
6107 "C[{ A[] -> [2] }]",
6108 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
6109 { &isl_multi_union_pw_aff_range_product,
6110 "(B[] : { A[x] : x >= 5 })",
6111 "(C[] : { A[x] : x <= 10 })",
6112 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
6113 { &isl_multi_union_pw_aff_range_product,
6114 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6115 "(C[] : { A[x] : x <= 10 })",
6116 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
6117 { &isl_multi_union_pw_aff_range_product,
6118 "(C[] : { A[x] : x <= 10 })",
6119 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6120 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
6121 { &isl_multi_union_pw_aff_range_product,
6122 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6123 "[N] -> (C[] : { A[x] : x <= N })",
6124 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
6125 { &isl_multi_union_pw_aff_range_product,
6126 "[N] -> (C[] : { A[x] : x <= N })",
6127 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6128 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
6129 { &isl_multi_union_pw_aff_range_product,
6130 "B[{ A[] -> [1]; D[] -> [3] }]",
6131 "C[{ A[] -> [2] }]",
6132 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
6133 { &isl_multi_union_pw_aff_range_product,
6134 "B[] }]",
6135 "(C[] : { A[x] })",
6136 "([B[] -> C[]] : { A[x] })" },
6137 { &isl_multi_union_pw_aff_range_product,
6138 "(B[] : { A[x] })",
6139 "C[] }]",
6140 "([B[] -> C[]] : { A[x] })" },
6143 /* Perform some basic tests of binary operations on
6144 * isl_multi_union_pw_aff objects.
6146 static int test_bin_mupa(isl_ctx *ctx)
6148 int i;
6149 isl_bool ok;
6150 isl_multi_union_pw_aff *mupa1, *mupa2, *res;
6152 for (i = 0; i < ARRAY_SIZE(mupa_bin_tests); ++i) {
6153 mupa1 = isl_multi_union_pw_aff_read_from_str(ctx,
6154 mupa_bin_tests[i].arg1);
6155 mupa2 = isl_multi_union_pw_aff_read_from_str(ctx,
6156 mupa_bin_tests[i].arg2);
6157 res = isl_multi_union_pw_aff_read_from_str(ctx,
6158 mupa_bin_tests[i].res);
6159 mupa1 = mupa_bin_tests[i].fn(mupa1, mupa2);
6160 ok = isl_multi_union_pw_aff_plain_is_equal(mupa1, res);
6161 isl_multi_union_pw_aff_free(mupa1);
6162 isl_multi_union_pw_aff_free(res);
6163 if (ok < 0)
6164 return -1;
6165 if (!ok)
6166 isl_die(ctx, isl_error_unknown,
6167 "unexpected result", return -1);
6170 return 0;
6173 /* Inputs for basic tests of binary operations on
6174 * pairs of isl_multi_union_pw_aff and isl_set objects.
6175 * "fn" is the function that is tested.
6176 * "arg1" and "arg2" are string descriptions of the inputs.
6177 * "res" is a string description of the expected result.
6179 struct {
6180 __isl_give isl_multi_union_pw_aff *(*fn)(
6181 __isl_take isl_multi_union_pw_aff *mupa,
6182 __isl_take isl_set *set);
6183 const char *arg1;
6184 const char *arg2;
6185 const char *res;
6186 } mupa_set_tests[] = {
6187 { &isl_multi_union_pw_aff_intersect_range,
6188 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
6189 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
6190 { &isl_multi_union_pw_aff_intersect_range,
6191 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
6192 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
6193 { &isl_multi_union_pw_aff_intersect_range,
6194 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
6195 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
6196 { &isl_multi_union_pw_aff_intersect_range,
6197 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
6198 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
6199 { &isl_multi_union_pw_aff_intersect_range,
6200 "C[]", "{ C[] }", "C[]" },
6201 { &isl_multi_union_pw_aff_intersect_range,
6202 "[N] -> (C[] : { : N >= 0 })",
6203 "{ C[] }",
6204 "[N] -> (C[] : { : N >= 0 })" },
6205 { &isl_multi_union_pw_aff_intersect_range,
6206 "(C[] : { A[a,b] })",
6207 "{ C[] }",
6208 "(C[] : { A[a,b] })" },
6209 { &isl_multi_union_pw_aff_intersect_range,
6210 "[N] -> (C[] : { A[a,b] : a,b <= N })",
6211 "{ C[] }",
6212 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
6213 { &isl_multi_union_pw_aff_intersect_range,
6214 "C[]",
6215 "[N] -> { C[] : N >= 0 }",
6216 "[N] -> (C[] : { : N >= 0 })" },
6217 { &isl_multi_union_pw_aff_intersect_range,
6218 "(C[] : { A[a,b] })",
6219 "[N] -> { C[] : N >= 0 }",
6220 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6221 { &isl_multi_union_pw_aff_intersect_range,
6222 "[N] -> (C[] : { : N >= 0 })",
6223 "[N] -> { C[] : N < 1024 }",
6224 "[N] -> (C[] : { : 0 <= N < 1024 })" },
6225 { &isl_multi_union_pw_aff_intersect_params,
6226 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
6227 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
6228 { &isl_multi_union_pw_aff_intersect_params,
6229 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
6230 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
6231 { &isl_multi_union_pw_aff_intersect_params,
6232 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
6233 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
6234 { &isl_multi_union_pw_aff_intersect_params,
6235 "C[]", "[N] -> { : N >= 0 }",
6236 "[N] -> (C[] : { : N >= 0 })" },
6237 { &isl_multi_union_pw_aff_intersect_params,
6238 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
6239 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6240 { &isl_multi_union_pw_aff_intersect_params,
6241 "[N] -> (C[] : { A[a,N] })", "{ : }",
6242 "[N] -> (C[] : { A[a,N] })" },
6243 { &isl_multi_union_pw_aff_intersect_params,
6244 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
6245 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
6248 /* Perform some basic tests of binary operations on
6249 * pairs of isl_multi_union_pw_aff and isl_set objects.
6251 static int test_mupa_set(isl_ctx *ctx)
6253 int i;
6254 isl_bool ok;
6255 isl_multi_union_pw_aff *mupa, *res;
6256 isl_set *set;
6258 for (i = 0; i < ARRAY_SIZE(mupa_set_tests); ++i) {
6259 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6260 mupa_set_tests[i].arg1);
6261 set = isl_set_read_from_str(ctx, mupa_set_tests[i].arg2);
6262 res = isl_multi_union_pw_aff_read_from_str(ctx,
6263 mupa_set_tests[i].res);
6264 mupa = mupa_set_tests[i].fn(mupa, set);
6265 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6266 isl_multi_union_pw_aff_free(mupa);
6267 isl_multi_union_pw_aff_free(res);
6268 if (ok < 0)
6269 return -1;
6270 if (!ok)
6271 isl_die(ctx, isl_error_unknown,
6272 "unexpected result", return -1);
6275 return 0;
6278 /* Inputs for basic tests of binary operations on
6279 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6280 * "fn" is the function that is tested.
6281 * "arg1" and "arg2" are string descriptions of the inputs.
6282 * "res" is a string description of the expected result.
6284 struct {
6285 __isl_give isl_multi_union_pw_aff *(*fn)(
6286 __isl_take isl_multi_union_pw_aff *mupa,
6287 __isl_take isl_union_set *uset);
6288 const char *arg1;
6289 const char *arg2;
6290 const char *res;
6291 } mupa_uset_tests[] = {
6292 { &isl_multi_union_pw_aff_intersect_domain,
6293 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
6294 "C[{ B[i,i] -> [3i] }]" },
6295 { &isl_multi_union_pw_aff_intersect_domain,
6296 "(C[] : { B[i,j] })", "{ B[i,i] }",
6297 "(C[] : { B[i,i] })" },
6298 { &isl_multi_union_pw_aff_intersect_domain,
6299 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
6300 "[N] -> (C[] : { B[N,N] })" },
6301 { &isl_multi_union_pw_aff_intersect_domain,
6302 "C[]", "{ B[i,i] }",
6303 "(C[] : { B[i,i] })" },
6304 { &isl_multi_union_pw_aff_intersect_domain,
6305 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
6306 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
6309 /* Perform some basic tests of binary operations on
6310 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6312 static int test_mupa_uset(isl_ctx *ctx)
6314 int i;
6315 isl_bool ok;
6316 isl_multi_union_pw_aff *mupa, *res;
6317 isl_union_set *uset;
6319 for (i = 0; i < ARRAY_SIZE(mupa_uset_tests); ++i) {
6320 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6321 mupa_uset_tests[i].arg1);
6322 uset = isl_union_set_read_from_str(ctx,
6323 mupa_uset_tests[i].arg2);
6324 res = isl_multi_union_pw_aff_read_from_str(ctx,
6325 mupa_uset_tests[i].res);
6326 mupa = mupa_uset_tests[i].fn(mupa, uset);
6327 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6328 isl_multi_union_pw_aff_free(mupa);
6329 isl_multi_union_pw_aff_free(res);
6330 if (ok < 0)
6331 return -1;
6332 if (!ok)
6333 isl_die(ctx, isl_error_unknown,
6334 "unexpected result", return -1);
6337 return 0;
6340 /* Inputs for basic tests of binary operations on
6341 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6342 * "fn" is the function that is tested.
6343 * "arg1" and "arg2" are string descriptions of the inputs.
6344 * "res" is a string description of the expected result.
6346 struct {
6347 __isl_give isl_multi_union_pw_aff *(*fn)(
6348 __isl_take isl_multi_union_pw_aff *mupa,
6349 __isl_take isl_multi_aff *ma);
6350 const char *arg1;
6351 const char *arg2;
6352 const char *res;
6353 } mupa_ma_tests[] = {
6354 { &isl_multi_union_pw_aff_apply_multi_aff,
6355 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6356 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6357 "{ C[a,b] -> D[b,a] }",
6358 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6359 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6360 { &isl_multi_union_pw_aff_apply_multi_aff,
6361 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6362 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6363 "{ C[a,b] -> D[b,a] }",
6364 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6365 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6366 { &isl_multi_union_pw_aff_apply_multi_aff,
6367 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6368 "[N] -> { C[a] -> D[a + N] }",
6369 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
6370 { &isl_multi_union_pw_aff_apply_multi_aff,
6371 "C[]",
6372 "{ C[] -> D[] }",
6373 "D[]" },
6374 { &isl_multi_union_pw_aff_apply_multi_aff,
6375 "[N] -> (C[] : { : N >= 0 })",
6376 "{ C[] -> D[] }",
6377 "[N] -> (D[] : { : N >= 0 })" },
6378 { &isl_multi_union_pw_aff_apply_multi_aff,
6379 "C[]",
6380 "[N] -> { C[] -> D[N] }",
6381 "[N] -> D[{ [N] }]" },
6382 { &isl_multi_union_pw_aff_apply_multi_aff,
6383 "(C[] : { A[i,j] : i >= j })",
6384 "{ C[] -> D[] }",
6385 "(D[] : { A[i,j] : i >= j })" },
6386 { &isl_multi_union_pw_aff_apply_multi_aff,
6387 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6388 "{ C[] -> D[] }",
6389 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6390 { &isl_multi_union_pw_aff_apply_multi_aff,
6391 "(C[] : { A[i,j] : i >= j })",
6392 "[N] -> { C[] -> D[N] }",
6393 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6396 /* Perform some basic tests of binary operations on
6397 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6399 static int test_mupa_ma(isl_ctx *ctx)
6401 int i;
6402 isl_bool ok;
6403 isl_multi_union_pw_aff *mupa, *res;
6404 isl_multi_aff *ma;
6406 for (i = 0; i < ARRAY_SIZE(mupa_ma_tests); ++i) {
6407 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6408 mupa_ma_tests[i].arg1);
6409 ma = isl_multi_aff_read_from_str(ctx, mupa_ma_tests[i].arg2);
6410 res = isl_multi_union_pw_aff_read_from_str(ctx,
6411 mupa_ma_tests[i].res);
6412 mupa = mupa_ma_tests[i].fn(mupa, ma);
6413 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6414 isl_multi_union_pw_aff_free(mupa);
6415 isl_multi_union_pw_aff_free(res);
6416 if (ok < 0)
6417 return -1;
6418 if (!ok)
6419 isl_die(ctx, isl_error_unknown,
6420 "unexpected result", return -1);
6423 return 0;
6426 /* Inputs for basic tests of binary operations on
6427 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6428 * "fn" is the function that is tested.
6429 * "arg1" and "arg2" are string descriptions of the inputs.
6430 * "res" is a string description of the expected result.
6432 struct {
6433 __isl_give isl_union_pw_aff *(*fn)(
6434 __isl_take isl_multi_union_pw_aff *mupa,
6435 __isl_take isl_pw_aff *pa);
6436 const char *arg1;
6437 const char *arg2;
6438 const char *res;
6439 } mupa_pa_tests[] = {
6440 { &isl_multi_union_pw_aff_apply_pw_aff,
6441 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6442 "[N] -> { C[a] -> [a + N] }",
6443 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
6444 { &isl_multi_union_pw_aff_apply_pw_aff,
6445 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6446 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
6447 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6448 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
6449 { &isl_multi_union_pw_aff_apply_pw_aff,
6450 "C[]",
6451 "[N] -> { C[] -> [N] }",
6452 "[N] -> { [N] }" },
6453 { &isl_multi_union_pw_aff_apply_pw_aff,
6454 "C[]",
6455 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6456 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
6457 { &isl_multi_union_pw_aff_apply_pw_aff,
6458 "[N] -> (C[] : { : N >= 0 })",
6459 "[N] -> { C[] -> [N] }",
6460 "[N] -> { [N] : N >= 0 }" },
6461 { &isl_multi_union_pw_aff_apply_pw_aff,
6462 "[N] -> (C[] : { : N >= 0 })",
6463 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6464 "[N] -> { [N] : N >= 0 }" },
6465 { &isl_multi_union_pw_aff_apply_pw_aff,
6466 "[N] -> (C[] : { : N >= 0 })",
6467 "{ C[] -> [0] }",
6468 "[N] -> { [0] : N >= 0 }" },
6469 { &isl_multi_union_pw_aff_apply_pw_aff,
6470 "(C[] : { A[i,j] : i >= j })",
6471 "[N] -> { C[] -> [N] }",
6472 "[N] -> { A[i,j] -> [N] : i >= j }" },
6473 { &isl_multi_union_pw_aff_apply_pw_aff,
6474 "(C[] : { A[i,j] : i >= j })",
6475 "[N] -> { C[] -> [N] : N >= 0 }",
6476 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6479 /* Perform some basic tests of binary operations on
6480 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6482 static int test_mupa_pa(isl_ctx *ctx)
6484 int i;
6485 isl_bool ok;
6486 isl_multi_union_pw_aff *mupa;
6487 isl_union_pw_aff *upa, *res;
6488 isl_pw_aff *pa;
6490 for (i = 0; i < ARRAY_SIZE(mupa_pa_tests); ++i) {
6491 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6492 mupa_pa_tests[i].arg1);
6493 pa = isl_pw_aff_read_from_str(ctx, mupa_pa_tests[i].arg2);
6494 res = isl_union_pw_aff_read_from_str(ctx,
6495 mupa_pa_tests[i].res);
6496 upa = mupa_pa_tests[i].fn(mupa, pa);
6497 ok = isl_union_pw_aff_plain_is_equal(upa, res);
6498 isl_union_pw_aff_free(upa);
6499 isl_union_pw_aff_free(res);
6500 if (ok < 0)
6501 return -1;
6502 if (!ok)
6503 isl_die(ctx, isl_error_unknown,
6504 "unexpected result", return -1);
6507 return 0;
6510 /* Inputs for basic tests of binary operations on
6511 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6512 * "fn" is the function that is tested.
6513 * "arg1" and "arg2" are string descriptions of the inputs.
6514 * "res" is a string description of the expected result.
6516 struct {
6517 __isl_give isl_multi_union_pw_aff *(*fn)(
6518 __isl_take isl_multi_union_pw_aff *mupa,
6519 __isl_take isl_pw_multi_aff *pma);
6520 const char *arg1;
6521 const char *arg2;
6522 const char *res;
6523 } mupa_pma_tests[] = {
6524 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6525 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6526 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6527 "{ C[a,b] -> D[b,a] }",
6528 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6529 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6530 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6531 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6532 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6533 "{ C[a,b] -> D[b,a] }",
6534 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6535 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6536 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6537 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6538 "[N] -> { C[a] -> D[a + N] }",
6539 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6540 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6541 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6542 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6543 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6544 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6545 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6546 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6547 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6548 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6549 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6550 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6551 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6552 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6553 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6554 "C[]",
6555 "{ C[] -> D[] }",
6556 "D[]" },
6557 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6558 "[N] -> (C[] : { : N >= 0 })",
6559 "{ C[] -> D[] }",
6560 "[N] -> (D[] : { : N >= 0 })" },
6561 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6562 "C[]",
6563 "[N] -> { C[] -> D[N] }",
6564 "[N] -> D[{ [N] }]" },
6565 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6566 "(C[] : { A[i,j] : i >= j })",
6567 "{ C[] -> D[] }",
6568 "(D[] : { A[i,j] : i >= j })" },
6569 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6570 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6571 "{ C[] -> D[] }",
6572 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6573 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6574 "(C[] : { A[i,j] : i >= j })",
6575 "[N] -> { C[] -> D[N] }",
6576 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6577 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6578 "C[]",
6579 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6580 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6581 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6582 "[N] -> (C[] : { : N >= 0 })",
6583 "[N] -> { C[] -> D[N] }",
6584 "[N] -> D[{ [N] : N >= 0 }]" },
6585 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6586 "[N] -> (C[] : { : N >= 0 })",
6587 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6588 "[N] -> D[{ [N] : N >= 0 }]" },
6589 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6590 "[N] -> (C[] : { : N >= 0 })",
6591 "{ C[] -> D[0] }",
6592 "[N] -> D[{ [0] : N >= 0 }]" },
6593 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6594 "(C[] : { A[i,j] : i >= j })",
6595 "[N] -> { C[] -> D[N] : N >= 0 }",
6596 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6599 /* Perform some basic tests of binary operations on
6600 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6602 static int test_mupa_pma(isl_ctx *ctx)
6604 int i;
6605 isl_bool ok;
6606 isl_multi_union_pw_aff *mupa, *res;
6607 isl_pw_multi_aff *pma;
6609 for (i = 0; i < ARRAY_SIZE(mupa_pma_tests); ++i) {
6610 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6611 mupa_pma_tests[i].arg1);
6612 pma = isl_pw_multi_aff_read_from_str(ctx,
6613 mupa_pma_tests[i].arg2);
6614 res = isl_multi_union_pw_aff_read_from_str(ctx,
6615 mupa_pma_tests[i].res);
6616 mupa = mupa_pma_tests[i].fn(mupa, pma);
6617 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6618 isl_multi_union_pw_aff_free(mupa);
6619 isl_multi_union_pw_aff_free(res);
6620 if (ok < 0)
6621 return -1;
6622 if (!ok)
6623 isl_die(ctx, isl_error_unknown,
6624 "unexpected result", return -1);
6627 return 0;
6630 /* Inputs for basic tests of binary operations on
6631 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6632 * "fn" is the function that is tested.
6633 * "arg1" and "arg2" are string descriptions of the inputs.
6634 * "res" is a string description of the expected result.
6636 struct {
6637 __isl_give isl_multi_union_pw_aff *(*fn)(
6638 __isl_take isl_multi_union_pw_aff *mupa,
6639 __isl_take isl_union_pw_multi_aff *upma);
6640 const char *arg1;
6641 const char *arg2;
6642 const char *res;
6643 } mupa_upma_tests[] = {
6644 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6645 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6646 "C[{ A[a,b] -> [b + 2a] }]" },
6647 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6648 "C[{ B[i,j] -> [i + 2j] }]",
6649 "{ A[a,b] -> B[b,a] : b > a }",
6650 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6651 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6652 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6653 "{ A[a,b] -> B[b,a] : b > a }",
6654 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6655 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6656 "C[{ B[i,j] -> [i + 2j] }]",
6657 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6658 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6659 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6660 "(C[] : { B[a,b] })",
6661 "{ A[a,b] -> B[b,a] }",
6662 "(C[] : { A[a,b] })" },
6663 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6664 "(C[] : { B[a,b] })",
6665 "{ B[a,b] -> A[b,a] }",
6666 "(C[] : { })" },
6667 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6668 "(C[] : { B[a,b] })",
6669 "{ A[a,b] -> B[b,a] : a > b }",
6670 "(C[] : { A[a,b] : a > b })" },
6671 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6672 "(C[] : { B[a,b] : a > b })",
6673 "{ A[a,b] -> B[b,a] }",
6674 "(C[] : { A[a,b] : b > a })" },
6675 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6676 "[N] -> (C[] : { B[a,b] : a > N })",
6677 "{ A[a,b] -> B[b,a] : a > b }",
6678 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6679 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6680 "(C[] : { B[a,b] : a > b })",
6681 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6682 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6683 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6684 "C[]",
6685 "{ A[a,b] -> B[b,a] }",
6686 "C[]" },
6687 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6688 "[N] -> (C[] : { : N >= 0 })",
6689 "{ A[a,b] -> B[b,a] }",
6690 "[N] -> (C[] : { : N >= 0 })" },
6691 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6692 "C[]",
6693 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6694 "[N] -> (C[] : { : N >= 0 })" },
6697 /* Perform some basic tests of binary operations on
6698 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6700 static int test_mupa_upma(isl_ctx *ctx)
6702 int i;
6703 isl_bool ok;
6704 isl_multi_union_pw_aff *mupa, *res;
6705 isl_union_pw_multi_aff *upma;
6707 for (i = 0; i < ARRAY_SIZE(mupa_upma_tests); ++i) {
6708 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6709 mupa_upma_tests[i].arg1);
6710 upma = isl_union_pw_multi_aff_read_from_str(ctx,
6711 mupa_upma_tests[i].arg2);
6712 res = isl_multi_union_pw_aff_read_from_str(ctx,
6713 mupa_upma_tests[i].res);
6714 mupa = mupa_upma_tests[i].fn(mupa, upma);
6715 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6716 isl_multi_union_pw_aff_free(mupa);
6717 isl_multi_union_pw_aff_free(res);
6718 if (ok < 0)
6719 return -1;
6720 if (!ok)
6721 isl_die(ctx, isl_error_unknown,
6722 "unexpected result", return -1);
6725 return 0;
6728 /* Check that the input tuple of an isl_aff can be set properly.
6730 static isl_stat test_aff_set_tuple_id(isl_ctx *ctx)
6732 isl_id *id;
6733 isl_aff *aff;
6734 isl_stat equal;
6736 aff = isl_aff_read_from_str(ctx, "{ [x] -> [x + 1] }");
6737 id = isl_id_alloc(ctx, "A", NULL);
6738 aff = isl_aff_set_tuple_id(aff, isl_dim_in, id);
6739 equal = aff_check_plain_equal(aff, "{ A[x] -> [x + 1] }");
6740 isl_aff_free(aff);
6741 if (equal < 0)
6742 return isl_stat_error;
6744 return isl_stat_ok;
6747 /* Check that affine expressions get normalized on addition/subtraction.
6748 * In particular, check that (final) unused integer divisions get removed
6749 * such that an expression derived from expressions with integer divisions
6750 * is found to be obviously equal to one that is created directly.
6752 static isl_stat test_aff_normalize(isl_ctx *ctx)
6754 isl_aff *aff, *aff2;
6755 isl_stat ok;
6757 aff = isl_aff_read_from_str(ctx, "{ [x] -> [x//2] }");
6758 aff2 = isl_aff_read_from_str(ctx, "{ [x] -> [1 + x//2] }");
6759 aff = isl_aff_sub(aff2, aff);
6760 ok = aff_check_plain_equal(aff, "{ [x] -> [1] }");
6761 isl_aff_free(aff);
6763 return ok;
6766 int test_aff(isl_ctx *ctx)
6768 const char *str;
6769 isl_set *set;
6770 isl_space *space;
6771 isl_local_space *ls;
6772 isl_aff *aff;
6773 int zero;
6774 isl_stat equal;
6776 if (test_upa(ctx) < 0)
6777 return -1;
6778 if (test_bin_aff(ctx) < 0)
6779 return -1;
6780 if (test_bin_pw_aff(ctx) < 0)
6781 return -1;
6782 if (test_upma_test(ctx) < 0)
6783 return -1;
6784 if (test_bin_upma(ctx) < 0)
6785 return -1;
6786 if (test_bin_upma_fail(ctx) < 0)
6787 return -1;
6788 if (test_upma_uset(ctx) < 0)
6789 return -1;
6790 if (test_un_mpa(ctx) < 0)
6791 return -1;
6792 if (test_bin_mpa(ctx) < 0)
6793 return -1;
6794 if (test_un_mupa(ctx) < 0)
6795 return -1;
6796 if (test_bin_mupa(ctx) < 0)
6797 return -1;
6798 if (test_mupa_set(ctx) < 0)
6799 return -1;
6800 if (test_mupa_uset(ctx) < 0)
6801 return -1;
6802 if (test_mupa_ma(ctx) < 0)
6803 return -1;
6804 if (test_mupa_pa(ctx) < 0)
6805 return -1;
6806 if (test_mupa_pma(ctx) < 0)
6807 return -1;
6808 if (test_mupa_upma(ctx) < 0)
6809 return -1;
6811 space = isl_space_set_alloc(ctx, 0, 1);
6812 ls = isl_local_space_from_space(space);
6813 aff = isl_aff_zero_on_domain(ls);
6815 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6816 aff = isl_aff_scale_down_ui(aff, 3);
6817 aff = isl_aff_floor(aff);
6818 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6819 aff = isl_aff_scale_down_ui(aff, 2);
6820 aff = isl_aff_floor(aff);
6821 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6823 str = "{ [10] }";
6824 set = isl_set_read_from_str(ctx, str);
6825 aff = isl_aff_gist(aff, set);
6827 aff = isl_aff_add_constant_si(aff, -16);
6828 zero = isl_aff_plain_is_zero(aff);
6829 isl_aff_free(aff);
6831 if (zero < 0)
6832 return -1;
6833 if (!zero)
6834 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6836 aff = isl_aff_read_from_str(ctx, "{ [-1] }");
6837 aff = isl_aff_scale_down_ui(aff, 64);
6838 aff = isl_aff_floor(aff);
6839 equal = aff_check_plain_equal(aff, "{ [-1] }");
6840 isl_aff_free(aff);
6841 if (equal < 0)
6842 return -1;
6844 if (test_aff_set_tuple_id(ctx) < 0)
6845 return -1;
6846 if (test_aff_normalize(ctx) < 0)
6847 return -1;
6849 return 0;
6852 /* Inputs for isl_set_bind tests.
6853 * "set" is the input set.
6854 * "tuple" is the binding tuple.
6855 * "res" is the expected result.
6857 static
6858 struct {
6859 const char *set;
6860 const char *tuple;
6861 const char *res;
6862 } bind_set_tests[] = {
6863 { "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6864 "{ A[M, N] }",
6865 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6866 { "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }",
6867 "{ B[N, M] }",
6868 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6869 { "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }",
6870 "{ C[N] }",
6871 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6872 { "[M] -> { D[x, N] : x mod 2 = 0 and N mod 8 = 3 and M >= 0 }",
6873 "{ D[M, N] }",
6874 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 and M >= 0 }" },
6877 /* Perform basic isl_set_bind tests.
6879 static isl_stat test_bind_set(isl_ctx *ctx)
6881 int i;
6883 for (i = 0; i < ARRAY_SIZE(bind_set_tests); ++i) {
6884 const char *str;
6885 isl_set *set;
6886 isl_multi_id *tuple;
6887 isl_stat r;
6889 set = isl_set_read_from_str(ctx, bind_set_tests[i].set);
6890 str = bind_set_tests[i].tuple;
6891 tuple = isl_multi_id_read_from_str(ctx, str);
6892 set = isl_set_bind(set, tuple);
6893 r = set_check_equal(set, bind_set_tests[i].res);
6894 isl_set_free(set);
6895 if (r < 0)
6896 return isl_stat_error;
6899 return isl_stat_ok;
6902 /* Inputs for isl_map_bind_domain tests.
6903 * "map" is the input map.
6904 * "tuple" is the binding tuple.
6905 * "res" is the expected result.
6907 struct {
6908 const char *map;
6909 const char *tuple;
6910 const char *res;
6911 } bind_map_domain_tests[] = {
6912 { "{ A[M, N] -> [M + floor(N/2)] }",
6913 "{ A[M, N] }",
6914 "[M, N] -> { [M + floor(N/2)] }" },
6915 { "{ B[N, M] -> [M + floor(N/2)] }",
6916 "{ B[N, M] }",
6917 "[N, M] -> { [M + floor(N/2)] }" },
6918 { "[M] -> { C[N] -> [M + floor(N/2)] }",
6919 "{ C[N] }",
6920 "[M, N] -> { [M + floor(N/2)] }" },
6921 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
6922 "{ C[M, N] }",
6923 "[M, N] -> { [M + floor(N/2)] }" },
6924 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
6925 "{ C[M, N] }",
6926 "[M, N] -> { [M + floor(N/2)] }" },
6927 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
6928 "{ C[N, M] }",
6929 "[A, N, M] -> { [M + floor(N/2)] }" },
6932 /* Perform basic isl_map_bind_domain tests.
6934 static isl_stat test_bind_map_domain(isl_ctx *ctx)
6936 int i;
6938 for (i = 0; i < ARRAY_SIZE(bind_map_domain_tests); ++i) {
6939 const char *str;
6940 isl_map *map;
6941 isl_set *set;
6942 isl_multi_id *tuple;
6943 isl_stat r;
6945 str = bind_map_domain_tests[i].map;
6946 map = isl_map_read_from_str(ctx, str);
6947 str = bind_map_domain_tests[i].tuple;
6948 tuple = isl_multi_id_read_from_str(ctx, str);
6949 set = isl_map_bind_domain(map, tuple);
6950 str = bind_map_domain_tests[i].res;
6951 r = set_check_equal(set, str);
6952 isl_set_free(set);
6953 if (r < 0)
6954 return isl_stat_error;
6957 return isl_stat_ok;
6960 /* Inputs for isl_union_map_bind_range tests.
6961 * "map" is the input union map.
6962 * "tuple" is the binding tuple.
6963 * "res" is the expected result.
6965 struct {
6966 const char *map;
6967 const char *tuple;
6968 const char *res;
6969 } bind_umap_range_tests[] = {
6970 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6971 "{ A[M, N] }",
6972 "[M, N] -> { B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
6973 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6974 "{ B[M, N] }",
6975 "{ }" },
6976 { "{ A[] -> B[]; C[] -> D[]; E[] -> B[] }",
6977 "{ B[] }",
6978 "{ A[]; E[] }" },
6981 /* Perform basic isl_union_map_bind_range tests.
6983 static isl_stat test_bind_umap_range(isl_ctx *ctx)
6985 int i;
6987 for (i = 0; i < ARRAY_SIZE(bind_umap_range_tests); ++i) {
6988 const char *str;
6989 isl_union_map *umap;
6990 isl_union_set *uset;
6991 isl_multi_id *tuple;
6992 isl_stat r;
6994 str = bind_umap_range_tests[i].map;
6995 umap = isl_union_map_read_from_str(ctx, str);
6996 str = bind_umap_range_tests[i].tuple;
6997 tuple = isl_multi_id_read_from_str(ctx, str);
6998 uset = isl_union_map_bind_range(umap, tuple);
6999 str = bind_umap_range_tests[i].res;
7000 r = uset_check_equal(uset, str);
7001 isl_union_set_free(uset);
7002 if (r < 0)
7003 return isl_stat_error;
7006 return isl_stat_ok;
7009 /* Inputs for isl_pw_multi_aff_bind_domain tests.
7010 * "pma" is the input expression.
7011 * "tuple" is the binding tuple.
7012 * "res" is the expected result.
7014 struct {
7015 const char *pma;
7016 const char *tuple;
7017 const char *res;
7018 } bind_pma_domain_tests[] = {
7019 { "{ A[M, N] -> [M + floor(N/2)] }",
7020 "{ A[M, N] }",
7021 "[M, N] -> { [M + floor(N/2)] }" },
7022 { "{ B[N, M] -> [M + floor(N/2)] }",
7023 "{ B[N, M] }",
7024 "[N, M] -> { [M + floor(N/2)] }" },
7025 { "[M] -> { C[N] -> [M + floor(N/2)] }",
7026 "{ C[N] }",
7027 "[M, N] -> { [M + floor(N/2)] }" },
7028 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
7029 "{ C[M, N] }",
7030 "[M, N] -> { [M + floor(N/2)] }" },
7031 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
7032 "{ C[M, N] }",
7033 "[M, N] -> { [M + floor(N/2)] }" },
7034 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
7035 "{ C[N, M] }",
7036 "[A, N, M] -> { [M + floor(N/2)] }" },
7039 /* Perform basic isl_pw_multi_aff_bind_domain tests.
7041 static isl_stat test_bind_pma_domain(isl_ctx *ctx)
7043 int i;
7045 for (i = 0; i < ARRAY_SIZE(bind_pma_domain_tests); ++i) {
7046 const char *str;
7047 isl_pw_multi_aff *pma;
7048 isl_multi_id *tuple;
7049 isl_stat r;
7051 str = bind_pma_domain_tests[i].pma;
7052 pma = isl_pw_multi_aff_read_from_str(ctx, str);
7053 str = bind_pma_domain_tests[i].tuple;
7054 tuple = isl_multi_id_read_from_str(ctx, str);
7055 pma = isl_pw_multi_aff_bind_domain(pma, tuple);
7056 str = bind_pma_domain_tests[i].res;
7057 r = pw_multi_aff_check_plain_equal(pma, str);
7058 isl_pw_multi_aff_free(pma);
7059 if (r < 0)
7060 return isl_stat_error;
7063 return isl_stat_ok;
7066 /* Inputs for isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7067 * "pma" is the input expression.
7068 * "tuple" is the binding tuple.
7069 * "res" is the expected result.
7071 struct {
7072 const char *pma;
7073 const char *tuple;
7074 const char *res;
7075 } bind_pma_domain_wrapped_tests[] = {
7076 { "{ [A[M, N] -> B[]] -> [M + floor(N/2)] }",
7077 "{ A[M, N] }",
7078 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7079 { "{ [B[N, M] -> D[]] -> [M + floor(N/2)] }",
7080 "{ B[N, M] }",
7081 "[N, M] -> { D[] -> [M + floor(N/2)] }" },
7082 { "[M] -> { [C[N] -> B[x]] -> [x + M + floor(N/2)] }",
7083 "{ C[N] }",
7084 "[M, N] -> { B[x] -> [x + M + floor(N/2)] }" },
7085 { "[M] -> { [C[x, N] -> B[]] -> [x + floor(N/2)] }",
7086 "{ C[M, N] }",
7087 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7088 { "[M] -> { [C[x, N] -> B[]] -> [M + floor(N/2)] }",
7089 "{ C[M, N] }",
7090 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7091 { "[A, M] -> { [C[N, x] -> B[]] -> [x + floor(N/2)] }",
7092 "{ C[N, M] }",
7093 "[A, N, M] -> { B[] -> [M + floor(N/2)] }" },
7096 /* Perform basic isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7098 static isl_stat test_bind_pma_domain_wrapped(isl_ctx *ctx)
7100 int i;
7102 for (i = 0; i < ARRAY_SIZE(bind_pma_domain_wrapped_tests); ++i) {
7103 const char *str;
7104 isl_pw_multi_aff *pma;
7105 isl_multi_id *tuple;
7106 isl_stat r;
7108 str = bind_pma_domain_wrapped_tests[i].pma;
7109 pma = isl_pw_multi_aff_read_from_str(ctx, str);
7110 str = bind_pma_domain_wrapped_tests[i].tuple;
7111 tuple = isl_multi_id_read_from_str(ctx, str);
7112 pma = isl_pw_multi_aff_bind_domain_wrapped_domain(pma, tuple);
7113 str = bind_pma_domain_wrapped_tests[i].res;
7114 r = pw_multi_aff_check_plain_equal(pma, str);
7115 isl_pw_multi_aff_free(pma);
7116 if (r < 0)
7117 return isl_stat_error;
7120 return isl_stat_ok;
7123 /* Inputs for isl_aff_bind_id tests.
7124 * "aff" is the input expression.
7125 * "id" is the binding id.
7126 * "res" is the expected result.
7128 static
7129 struct {
7130 const char *aff;
7131 const char *id;
7132 const char *res;
7133 } bind_aff_tests[] = {
7134 { "{ [4] }", "M", "[M = 4] -> { : }" },
7135 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7136 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7137 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7138 { "{ [NaN] }", "M", "{ : false }" },
7139 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7142 /* Perform basic isl_aff_bind_id tests.
7144 static isl_stat test_bind_aff(isl_ctx *ctx)
7146 int i;
7148 for (i = 0; i < ARRAY_SIZE(bind_aff_tests); ++i) {
7149 isl_aff *aff;
7150 isl_set *res;
7151 isl_id *id;
7152 isl_stat r;
7154 aff = isl_aff_read_from_str(ctx, bind_aff_tests[i].aff);
7155 id = isl_id_read_from_str(ctx, bind_aff_tests[i].id);
7156 res = isl_set_from_basic_set(isl_aff_bind_id(aff, id));
7157 r = set_check_equal(res, bind_aff_tests[i].res);
7158 isl_set_free(res);
7159 if (r < 0)
7160 return isl_stat_error;
7163 return isl_stat_ok;
7166 /* Inputs for isl_pw_aff_bind_id tests.
7167 * "pa" is the input expression.
7168 * "id" is the binding id.
7169 * "res" is the expected result.
7171 static
7172 struct {
7173 const char *pa;
7174 const char *id;
7175 const char *res;
7176 } bind_pa_tests[] = {
7177 { "{ [4] }", "M", "[M = 4] -> { : }" },
7178 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7179 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7180 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7181 { "[M] -> { [M] : M >= 0; [-M] : M < 0 }", "M", "[M] -> { : M >= 0 }" },
7182 { "{ [NaN] }", "M", "{ : false }" },
7183 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7186 /* Perform basic isl_pw_aff_bind_id tests.
7188 static isl_stat test_bind_pa(isl_ctx *ctx)
7190 int i;
7192 for (i = 0; i < ARRAY_SIZE(bind_pa_tests); ++i) {
7193 isl_pw_aff *pa;
7194 isl_set *res;
7195 isl_id *id;
7196 isl_stat r;
7198 pa = isl_pw_aff_read_from_str(ctx, bind_pa_tests[i].pa);
7199 id = isl_id_read_from_str(ctx, bind_pa_tests[i].id);
7200 res = isl_pw_aff_bind_id(pa, id);
7201 r = set_check_equal(res, bind_pa_tests[i].res);
7202 isl_set_free(res);
7203 if (r < 0)
7204 return isl_stat_error;
7207 return isl_stat_ok;
7210 /* Inputs for isl_multi_union_pw_aff_bind tests.
7211 * "mupa" is the input expression.
7212 * "tuple" is the binding tuple.
7213 * "res" is the expected result.
7215 static
7216 struct {
7217 const char *mupa;
7218 const char *tuple;
7219 const char *res;
7220 } bind_mupa_tests[] = {
7221 { "A[{ [4] }, { [5] }]",
7222 "{ A[M, N] }",
7223 "[M = 4, N = 5] -> { : }" },
7224 { "A[{ B[x] -> [floor(x/2)] }, { B[y] -> [y + 5] }]",
7225 "{ A[M, N] }",
7226 "[M, N] -> { B[x] : M = floor(x/2) and N = x + 5 }" },
7227 { "[M] -> A[{ [4] }, { [M + 1] }]",
7228 "{ A[M, N] }",
7229 "[M = 4, N = 5] -> { : }" },
7232 /* Perform basic isl_multi_union_pw_aff_bind tests.
7234 static isl_stat test_bind_mupa(isl_ctx *ctx)
7236 int i;
7238 for (i = 0; i < ARRAY_SIZE(bind_mupa_tests); ++i) {
7239 const char *str;
7240 isl_multi_union_pw_aff *mupa;
7241 isl_union_set *res;
7242 isl_multi_id *tuple;
7243 isl_stat r;
7245 str = bind_mupa_tests[i].mupa;
7246 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
7247 str = bind_mupa_tests[i].tuple;
7248 tuple = isl_multi_id_read_from_str(ctx, str);
7249 res = isl_multi_union_pw_aff_bind(mupa, tuple);
7250 r = uset_check_equal(res, bind_mupa_tests[i].res);
7251 isl_union_set_free(res);
7252 if (r < 0)
7253 return isl_stat_error;
7256 return isl_stat_ok;
7259 /* Perform tests that reinterpret dimensions as parameters.
7261 static int test_bind(isl_ctx *ctx)
7263 if (test_bind_set(ctx) < 0)
7264 return -1;
7265 if (test_bind_map_domain(ctx) < 0)
7266 return -1;
7267 if (test_bind_umap_range(ctx) < 0)
7268 return -1;
7269 if (test_bind_pma_domain(ctx) < 0)
7270 return -1;
7271 if (test_bind_pma_domain_wrapped(ctx) < 0)
7272 return -1;
7273 if (test_bind_aff(ctx) < 0)
7274 return -1;
7275 if (test_bind_pa(ctx) < 0)
7276 return -1;
7277 if (test_bind_mupa(ctx) < 0)
7278 return -1;
7280 return 0;
7283 /* Inputs for isl_set_unbind_params tests.
7284 * "set" is the input parameter domain.
7285 * "tuple" is the tuple of the constructed set.
7286 * "res" is the expected result.
7288 struct {
7289 const char *set;
7290 const char *tuple;
7291 const char *res;
7292 } unbind_set_tests[] = {
7293 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7294 "{ A[M, N] }",
7295 "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7296 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7297 "{ B[N, M] }",
7298 "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7299 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7300 "{ C[N] }",
7301 "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }" },
7302 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7303 "{ D[T, N] }",
7304 "[M] -> { D[x, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7307 /* Perform basic isl_set_unbind_params tests.
7309 static isl_stat test_unbind_set(isl_ctx *ctx)
7311 int i;
7313 for (i = 0; i < ARRAY_SIZE(unbind_set_tests); ++i) {
7314 const char *str;
7315 isl_set *set;
7316 isl_multi_id *tuple;
7317 isl_stat r;
7319 set = isl_set_read_from_str(ctx, unbind_set_tests[i].set);
7320 str = unbind_set_tests[i].tuple;
7321 tuple = isl_multi_id_read_from_str(ctx, str);
7322 set = isl_set_unbind_params(set, tuple);
7323 r = set_check_equal(set, unbind_set_tests[i].res);
7324 isl_set_free(set);
7325 if (r < 0)
7326 return isl_stat_error;
7329 return isl_stat_ok;
7332 /* Inputs for isl_aff_unbind_params_insert_domain tests.
7333 * "aff" is the input affine expression defined over a parameter domain.
7334 * "tuple" is the tuple of the domain that gets introduced.
7335 * "res" is the expected result.
7337 struct {
7338 const char *aff;
7339 const char *tuple;
7340 const char *res;
7341 } unbind_aff_tests[] = {
7342 { "[M, N] -> { [M + floor(N/2)] }",
7343 "{ A[M, N] }",
7344 "{ A[M, N] -> [M + floor(N/2)] }" },
7345 { "[M, N] -> { [M + floor(N/2)] }",
7346 "{ B[N, M] }",
7347 "{ B[N, M] -> [M + floor(N/2)] }" },
7348 { "[M, N] -> { [M + floor(N/2)] }",
7349 "{ C[N] }",
7350 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7351 { "[M, N] -> { [M + floor(N/2)] }",
7352 "{ D[A, B, C, N, Z] }",
7353 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7356 /* Perform basic isl_aff_unbind_params_insert_domain tests.
7358 static isl_stat test_unbind_aff(isl_ctx *ctx)
7360 int i;
7362 for (i = 0; i < ARRAY_SIZE(unbind_aff_tests); ++i) {
7363 const char *str;
7364 isl_aff *aff;
7365 isl_multi_id *tuple;
7366 isl_stat r;
7368 aff = isl_aff_read_from_str(ctx, unbind_aff_tests[i].aff);
7369 str = unbind_aff_tests[i].tuple;
7370 tuple = isl_multi_id_read_from_str(ctx, str);
7371 aff = isl_aff_unbind_params_insert_domain(aff, tuple);
7372 r = aff_check_plain_equal(aff, unbind_aff_tests[i].res);
7373 isl_aff_free(aff);
7374 if (r < 0)
7375 return isl_stat_error;
7378 return isl_stat_ok;
7381 /* Inputs for isl_multi_aff_unbind_params_insert_domain tests.
7382 * "ma" is the input multi affine expression defined over a parameter domain.
7383 * "tuple" is the tuple of the domain that gets introduced.
7384 * "res" is the expected result.
7386 static struct {
7387 const char *ma;
7388 const char *tuple;
7389 const char *res;
7390 } unbind_multi_aff_tests[] = {
7391 { "[M, N] -> { T[M + floor(N/2)] }",
7392 "{ A[M, N] }",
7393 "{ A[M, N] -> T[M + floor(N/2)] }" },
7394 { "[M, N] -> { [M + floor(N/2)] }",
7395 "{ B[N, M] }",
7396 "{ B[N, M] -> [M + floor(N/2)] }" },
7397 { "[M, N] -> { [M + floor(N/2)] }",
7398 "{ C[N] }",
7399 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7400 { "[M, N] -> { [M + floor(N/2)] }",
7401 "{ D[A, B, C, N, Z] }",
7402 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7403 { "[M, N] -> { T[M + floor(N/2), N + floor(M/3)] }",
7404 "{ A[M, N] }",
7405 "{ A[M, N] -> T[M + floor(N/2), N + floor(M/3)] }" },
7408 /* Perform basic isl_multi_aff_unbind_params_insert_domain tests.
7410 static isl_stat test_unbind_multi_aff(isl_ctx *ctx)
7412 int i;
7414 for (i = 0; i < ARRAY_SIZE(unbind_multi_aff_tests); ++i) {
7415 const char *str;
7416 isl_multi_aff *ma;
7417 isl_multi_id *tuple;
7418 isl_stat r;
7420 str = unbind_multi_aff_tests[i].ma;
7421 ma = isl_multi_aff_read_from_str(ctx, str);
7422 str = unbind_multi_aff_tests[i].tuple;
7423 tuple = isl_multi_id_read_from_str(ctx, str);
7424 ma = isl_multi_aff_unbind_params_insert_domain(ma, tuple);
7425 str = unbind_multi_aff_tests[i].res;
7426 r = multi_aff_check_plain_equal(ma, str);
7427 isl_multi_aff_free(ma);
7428 if (r < 0)
7429 return isl_stat_error;
7432 return isl_stat_ok;
7435 /* Perform tests that reinterpret parameters.
7437 static int test_unbind(isl_ctx *ctx)
7439 if (test_unbind_set(ctx) < 0)
7440 return -1;
7441 if (test_unbind_aff(ctx) < 0)
7442 return -1;
7443 if (test_unbind_multi_aff(ctx) < 0)
7444 return -1;
7446 return 0;
7449 /* Check that "pa" consists of a single expression.
7451 static int check_single_piece(isl_ctx *ctx, __isl_take isl_pw_aff *pa)
7453 isl_size n;
7455 n = isl_pw_aff_n_piece(pa);
7456 isl_pw_aff_free(pa);
7458 if (n < 0)
7459 return -1;
7460 if (n != 1)
7461 isl_die(ctx, isl_error_unknown, "expecting single expression",
7462 return -1);
7464 return 0;
7467 /* Check that the computation below results in a single expression.
7468 * One or two expressions may result depending on which constraint
7469 * ends up being considered as redundant with respect to the other
7470 * constraints after the projection that is performed internally
7471 * by isl_set_dim_min.
7473 static int test_dim_max_1(isl_ctx *ctx)
7475 const char *str;
7476 isl_set *set;
7477 isl_pw_aff *pa;
7479 str = "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
7480 "-4a <= b <= 3 and b < n - 4a }";
7481 set = isl_set_read_from_str(ctx, str);
7482 pa = isl_set_dim_min(set, 0);
7483 return check_single_piece(ctx, pa);
7486 /* Check that the computation below results in a single expression.
7487 * The PIP problem corresponding to these constraints has a row
7488 * that causes a split of the solution domain. The solver should
7489 * first pick rows that split off empty parts such that the actual
7490 * solution domain does not get split.
7491 * Note that the description contains some redundant constraints.
7492 * If these constraints get removed first, then the row mentioned
7493 * above does not appear in the PIP problem.
7495 static int test_dim_max_2(isl_ctx *ctx)
7497 const char *str;
7498 isl_set *set;
7499 isl_pw_aff *pa;
7501 str = "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
7502 "N > 0 and P >= 0 }";
7503 set = isl_set_read_from_str(ctx, str);
7504 pa = isl_set_dim_max(set, 0);
7505 return check_single_piece(ctx, pa);
7508 int test_dim_max(isl_ctx *ctx)
7510 int equal;
7511 const char *str;
7512 isl_set *set1, *set2;
7513 isl_set *set;
7514 isl_map *map;
7515 isl_pw_aff *pwaff;
7517 if (test_dim_max_1(ctx) < 0)
7518 return -1;
7519 if (test_dim_max_2(ctx) < 0)
7520 return -1;
7522 str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
7523 set = isl_set_read_from_str(ctx, str);
7524 pwaff = isl_set_dim_max(set, 0);
7525 set1 = isl_set_from_pw_aff(pwaff);
7526 str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
7527 set2 = isl_set_read_from_str(ctx, str);
7528 equal = isl_set_is_equal(set1, set2);
7529 isl_set_free(set1);
7530 isl_set_free(set2);
7531 if (equal < 0)
7532 return -1;
7533 if (!equal)
7534 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7536 str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
7537 set = isl_set_read_from_str(ctx, str);
7538 pwaff = isl_set_dim_max(set, 0);
7539 set1 = isl_set_from_pw_aff(pwaff);
7540 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7541 set2 = isl_set_read_from_str(ctx, str);
7542 equal = isl_set_is_equal(set1, set2);
7543 isl_set_free(set1);
7544 isl_set_free(set2);
7545 if (equal < 0)
7546 return -1;
7547 if (!equal)
7548 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7550 str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
7551 set = isl_set_read_from_str(ctx, str);
7552 pwaff = isl_set_dim_max(set, 0);
7553 set1 = isl_set_from_pw_aff(pwaff);
7554 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7555 set2 = isl_set_read_from_str(ctx, str);
7556 equal = isl_set_is_equal(set1, set2);
7557 isl_set_free(set1);
7558 isl_set_free(set2);
7559 if (equal < 0)
7560 return -1;
7561 if (!equal)
7562 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7564 str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
7565 "0 <= i < N and 0 <= j < M }";
7566 map = isl_map_read_from_str(ctx, str);
7567 set = isl_map_range(map);
7569 pwaff = isl_set_dim_max(isl_set_copy(set), 0);
7570 set1 = isl_set_from_pw_aff(pwaff);
7571 str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
7572 set2 = isl_set_read_from_str(ctx, str);
7573 equal = isl_set_is_equal(set1, set2);
7574 isl_set_free(set1);
7575 isl_set_free(set2);
7577 pwaff = isl_set_dim_max(isl_set_copy(set), 3);
7578 set1 = isl_set_from_pw_aff(pwaff);
7579 str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
7580 set2 = isl_set_read_from_str(ctx, str);
7581 if (equal >= 0 && equal)
7582 equal = isl_set_is_equal(set1, set2);
7583 isl_set_free(set1);
7584 isl_set_free(set2);
7586 isl_set_free(set);
7588 if (equal < 0)
7589 return -1;
7590 if (!equal)
7591 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7593 /* Check that solutions are properly merged. */
7594 str = "[n] -> { [a, b, c] : c >= -4a - 2b and "
7595 "c <= -1 + n - 4a - 2b and c >= -2b and "
7596 "4a >= -4 + n and c >= 0 }";
7597 set = isl_set_read_from_str(ctx, str);
7598 pwaff = isl_set_dim_min(set, 2);
7599 set1 = isl_set_from_pw_aff(pwaff);
7600 str = "[n] -> { [(0)] : n >= 1 }";
7601 set2 = isl_set_read_from_str(ctx, str);
7602 equal = isl_set_is_equal(set1, set2);
7603 isl_set_free(set1);
7604 isl_set_free(set2);
7606 if (equal < 0)
7607 return -1;
7608 if (!equal)
7609 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7611 /* Check that empty solution lie in the right space. */
7612 str = "[n] -> { [t,a] : 1 = 0 }";
7613 set = isl_set_read_from_str(ctx, str);
7614 pwaff = isl_set_dim_max(set, 0);
7615 set1 = isl_set_from_pw_aff(pwaff);
7616 str = "[n] -> { [t] : 1 = 0 }";
7617 set2 = isl_set_read_from_str(ctx, str);
7618 equal = isl_set_is_equal(set1, set2);
7619 isl_set_free(set1);
7620 isl_set_free(set2);
7622 if (equal < 0)
7623 return -1;
7624 if (!equal)
7625 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7627 return 0;
7630 /* Basic test for isl_pw_multi_aff_product.
7632 * Check that multiple pieces are properly handled.
7634 static int test_product_pma(isl_ctx *ctx)
7636 isl_stat equal;
7637 const char *str;
7638 isl_pw_multi_aff *pma1, *pma2;
7640 str = "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
7641 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
7642 str = "{ C[] -> D[] }";
7643 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
7644 pma1 = isl_pw_multi_aff_product(pma1, pma2);
7645 str = "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
7646 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
7647 equal = pw_multi_aff_check_plain_equal(pma1, str);
7648 isl_pw_multi_aff_free(pma1);
7649 if (equal < 0)
7650 return -1;
7652 return 0;
7655 int test_product(isl_ctx *ctx)
7657 const char *str;
7658 isl_set *set;
7659 isl_union_set *uset1, *uset2;
7660 int ok;
7662 str = "{ A[i] }";
7663 set = isl_set_read_from_str(ctx, str);
7664 set = isl_set_product(set, isl_set_copy(set));
7665 ok = isl_set_is_wrapping(set);
7666 isl_set_free(set);
7667 if (ok < 0)
7668 return -1;
7669 if (!ok)
7670 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7672 str = "{ [] }";
7673 uset1 = isl_union_set_read_from_str(ctx, str);
7674 uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1));
7675 str = "{ [[] -> []] }";
7676 uset2 = isl_union_set_read_from_str(ctx, str);
7677 ok = isl_union_set_is_equal(uset1, uset2);
7678 isl_union_set_free(uset1);
7679 isl_union_set_free(uset2);
7680 if (ok < 0)
7681 return -1;
7682 if (!ok)
7683 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7685 if (test_product_pma(ctx) < 0)
7686 return -1;
7688 return 0;
7691 /* Check that two sets are not considered disjoint just because
7692 * they have a different set of (named) parameters.
7694 static int test_disjoint(isl_ctx *ctx)
7696 const char *str;
7697 isl_set *set, *set2;
7698 int disjoint;
7700 str = "[n] -> { [[]->[]] }";
7701 set = isl_set_read_from_str(ctx, str);
7702 str = "{ [[]->[]] }";
7703 set2 = isl_set_read_from_str(ctx, str);
7704 disjoint = isl_set_is_disjoint(set, set2);
7705 isl_set_free(set);
7706 isl_set_free(set2);
7707 if (disjoint < 0)
7708 return -1;
7709 if (disjoint)
7710 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7712 return 0;
7715 /* Inputs for isl_pw_multi_aff_is_equal tests.
7716 * "f1" and "f2" are the two function that need to be compared.
7717 * "equal" is the expected result.
7719 struct {
7720 int equal;
7721 const char *f1;
7722 const char *f2;
7723 } pma_equal_tests[] = {
7724 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
7725 "[N] -> { [0] : 0 <= N <= 1 }" },
7726 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7727 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
7728 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7729 "[N] -> { [0] : 0 <= N <= 1 }" },
7730 { 0, "{ [NaN] }", "{ [NaN] }" },
7733 int test_equal(isl_ctx *ctx)
7735 int i;
7736 const char *str;
7737 isl_set *set, *set2;
7738 int equal;
7740 str = "{ S_6[i] }";
7741 set = isl_set_read_from_str(ctx, str);
7742 str = "{ S_7[i] }";
7743 set2 = isl_set_read_from_str(ctx, str);
7744 equal = isl_set_is_equal(set, set2);
7745 isl_set_free(set);
7746 isl_set_free(set2);
7747 if (equal < 0)
7748 return -1;
7749 if (equal)
7750 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7752 for (i = 0; i < ARRAY_SIZE(pma_equal_tests); ++i) {
7753 int expected = pma_equal_tests[i].equal;
7754 isl_pw_multi_aff *f1, *f2;
7756 f1 = isl_pw_multi_aff_read_from_str(ctx, pma_equal_tests[i].f1);
7757 f2 = isl_pw_multi_aff_read_from_str(ctx, pma_equal_tests[i].f2);
7758 equal = isl_pw_multi_aff_is_equal(f1, f2);
7759 isl_pw_multi_aff_free(f1);
7760 isl_pw_multi_aff_free(f2);
7761 if (equal < 0)
7762 return -1;
7763 if (equal != expected)
7764 isl_die(ctx, isl_error_unknown,
7765 "unexpected equality result", return -1);
7768 return 0;
7771 static int test_plain_fixed(isl_ctx *ctx, __isl_take isl_map *map,
7772 enum isl_dim_type type, unsigned pos, int fixed)
7774 isl_bool test;
7776 test = isl_map_plain_is_fixed(map, type, pos, NULL);
7777 isl_map_free(map);
7778 if (test < 0)
7779 return -1;
7780 if (test == fixed)
7781 return 0;
7782 if (fixed)
7783 isl_die(ctx, isl_error_unknown,
7784 "map not detected as fixed", return -1);
7785 else
7786 isl_die(ctx, isl_error_unknown,
7787 "map detected as fixed", return -1);
7790 int test_fixed(isl_ctx *ctx)
7792 const char *str;
7793 isl_map *map;
7795 str = "{ [i] -> [i] }";
7796 map = isl_map_read_from_str(ctx, str);
7797 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 0))
7798 return -1;
7799 str = "{ [i] -> [1] }";
7800 map = isl_map_read_from_str(ctx, str);
7801 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
7802 return -1;
7803 str = "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
7804 map = isl_map_read_from_str(ctx, str);
7805 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
7806 return -1;
7807 map = isl_map_read_from_str(ctx, str);
7808 map = isl_map_neg(map);
7809 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
7810 return -1;
7812 return 0;
7815 struct isl_vertices_test_data {
7816 const char *set;
7817 int n;
7818 const char *vertex[6];
7819 } vertices_tests[] = {
7820 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
7821 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
7822 { "{ A[t, i] : t = 14 and i = 1 }",
7823 1, { "{ A[14, 1] }" } },
7824 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
7825 "c <= m and m <= n and m > 0 }",
7826 6, {
7827 "[n, m] -> { [n, m, m] : 0 < m <= n }",
7828 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
7829 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
7830 "[n, m] -> { [m, m, m] : 0 < m <= n }",
7831 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
7832 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
7833 } },
7834 /* An input with implicit equality constraints among the parameters. */
7835 { "[N, M] -> { [a, b] : M >= 3 and 9 + 3M <= a <= 29 + 2N + 11M and "
7836 "2b >= M + a and 5 - 2N - M + a <= 2b <= 3 + a and "
7837 "3b >= 15 + a }",
7838 2, {
7839 "[N, M] -> { [(21), (12)] : M = 3 and N >= 0 }",
7840 "[N, M] -> { [(61 + 2N), (32 + N)] : M = 3 and N >= 0 }",
7845 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
7847 static isl_stat find_vertex(__isl_take isl_vertex *vertex, void *user)
7849 struct isl_vertices_test_data *data = user;
7850 isl_ctx *ctx;
7851 isl_multi_aff *ma;
7852 isl_basic_set *bset;
7853 isl_pw_multi_aff *pma;
7854 int i;
7855 isl_bool equal;
7857 ctx = isl_vertex_get_ctx(vertex);
7858 bset = isl_vertex_get_domain(vertex);
7859 ma = isl_vertex_get_expr(vertex);
7860 pma = isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset), ma);
7862 for (i = 0; i < data->n; ++i) {
7863 isl_pw_multi_aff *pma_i;
7865 pma_i = isl_pw_multi_aff_read_from_str(ctx, data->vertex[i]);
7866 equal = isl_pw_multi_aff_plain_is_equal(pma, pma_i);
7867 isl_pw_multi_aff_free(pma_i);
7869 if (equal < 0 || equal)
7870 break;
7873 isl_pw_multi_aff_free(pma);
7874 isl_vertex_free(vertex);
7876 if (equal < 0)
7877 return isl_stat_error;
7879 return equal ? isl_stat_ok : isl_stat_error;
7882 int test_vertices(isl_ctx *ctx)
7884 int i;
7886 for (i = 0; i < ARRAY_SIZE(vertices_tests); ++i) {
7887 isl_basic_set *bset;
7888 isl_vertices *vertices;
7889 int ok = 1;
7890 isl_size n;
7892 bset = isl_basic_set_read_from_str(ctx, vertices_tests[i].set);
7893 vertices = isl_basic_set_compute_vertices(bset);
7894 n = isl_vertices_get_n_vertices(vertices);
7895 if (vertices_tests[i].n != n)
7896 ok = 0;
7897 if (isl_vertices_foreach_vertex(vertices, &find_vertex,
7898 &vertices_tests[i]) < 0)
7899 ok = 0;
7900 isl_vertices_free(vertices);
7901 isl_basic_set_free(bset);
7903 if (n < 0)
7904 return -1;
7905 if (!ok)
7906 isl_die(ctx, isl_error_unknown, "unexpected vertices",
7907 return -1);
7910 return 0;
7913 /* Inputs for basic tests of binary operations on isl_union_map.
7914 * "fn" is the function that is being tested.
7915 * "arg1" and "arg2" are string descriptions of the inputs.
7916 * "res" is a string description of the expected result.
7918 static struct {
7919 __isl_give isl_union_map *(*fn)(__isl_take isl_union_map *umap1,
7920 __isl_take isl_union_map *umap2);
7921 const char *arg1;
7922 const char *arg2;
7923 const char *res;
7924 } umap_bin_tests[] = {
7925 { &isl_union_map_intersect,
7926 "[n] -> { A[i] -> [] : 0 <= i <= n; B[] -> [] }",
7927 "[m] -> { A[i] -> [] : 0 <= i <= m; C[] -> [] }",
7928 "[m, n] -> { A[i] -> [] : 0 <= i <= n and i <= m }" },
7929 { &isl_union_map_intersect_domain_factor_domain,
7930 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7931 "[N] -> { B[i] -> C[N] }",
7932 "{ }" },
7933 { &isl_union_map_intersect_domain_factor_domain,
7934 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7935 "[N] -> { A[i] -> C[N] }",
7936 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
7937 { &isl_union_map_intersect_domain_factor_domain,
7938 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
7939 "[N] -> { A[i] -> C[N] }",
7940 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
7941 { &isl_union_map_intersect_domain_factor_range,
7942 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7943 "[N] -> { B[i] -> C[N] }",
7944 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
7945 { &isl_union_map_intersect_domain_factor_range,
7946 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
7947 "[N] -> { B[i] -> C[N] }",
7948 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
7949 { &isl_union_map_intersect_domain_factor_range,
7950 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7951 "[N] -> { A[i] -> C[N] }",
7952 "{ }" },
7953 { &isl_union_map_intersect_range_factor_domain,
7954 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7955 "[N] -> { A[i] -> B[N] }",
7956 "[N] -> { A[N - 1] -> [B[N] -> C[N + 1]] }" },
7957 { &isl_union_map_intersect_range_factor_domain,
7958 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
7959 "[N] -> { A[i] -> B[N] }",
7960 "[N] -> { A[N - 1] -> T[B[N] -> C[N + 1]] }" },
7961 { &isl_union_map_intersect_range_factor_domain,
7962 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7963 "[N] -> { A[i] -> C[N] }",
7964 "{ }" },
7965 { &isl_union_map_intersect_range_factor_range,
7966 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7967 "[N] -> { A[i] -> C[N] }",
7968 "[N] -> { A[N - 2] -> [B[N - 1] -> C[N]] }" },
7969 { &isl_union_map_intersect_range_factor_range,
7970 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
7971 "[N] -> { A[i] -> C[N] }",
7972 "[N] -> { A[N - 2] -> T[B[N - 1] -> C[N]] }" },
7973 { &isl_union_map_intersect_range_factor_range,
7974 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7975 "[N] -> { A[i] -> B[N] }",
7976 "{ }" },
7979 /* Perform basic tests of binary operations on isl_union_map.
7981 static isl_stat test_bin_union_map(isl_ctx *ctx)
7983 int i;
7985 for (i = 0; i < ARRAY_SIZE(umap_bin_tests); ++i) {
7986 const char *str;
7987 isl_union_map *umap1, *umap2, *res;
7988 isl_bool equal;
7990 str = umap_bin_tests[i].arg1;
7991 umap1 = isl_union_map_read_from_str(ctx, str);
7992 str = umap_bin_tests[i].arg2;
7993 umap2 = isl_union_map_read_from_str(ctx, str);
7994 str = umap_bin_tests[i].res;
7995 res = isl_union_map_read_from_str(ctx, str);
7996 umap1 = umap_bin_tests[i].fn(umap1, umap2);
7997 equal = isl_union_map_is_equal(umap1, res);
7998 isl_union_map_free(umap1);
7999 isl_union_map_free(res);
8000 if (equal < 0)
8001 return isl_stat_error;
8002 if (!equal)
8003 isl_die(ctx, isl_error_unknown,
8004 "unexpected result", return isl_stat_error);
8007 return isl_stat_ok;
8010 /* Check that isl_union_set_contains finds space independently
8011 * of the parameters.
8013 static isl_stat test_union_set_contains(isl_ctx *ctx)
8015 const char *str;
8016 isl_bool ok;
8017 isl_space *space;
8018 isl_id *id;
8019 isl_union_set *uset;
8021 str = "[N] -> { A[0:N]; B[*,*] }";
8022 uset = isl_union_set_read_from_str(ctx, str);
8023 space = isl_space_unit(ctx);
8024 id = isl_id_alloc(ctx, "A", NULL);
8025 space = isl_space_add_named_tuple_id_ui(space, id, 1);
8026 ok = isl_union_set_contains(uset, space);
8027 isl_space_free(space);
8028 isl_union_set_free(uset);
8030 if (ok < 0)
8031 return isl_stat_error;
8032 if (!ok)
8033 isl_die(ctx, isl_error_unknown,
8034 "unexpected result", return isl_stat_error);
8036 return isl_stat_ok;
8039 /* Perform basic tests of operations on isl_union_map or isl_union_set.
8041 static int test_union_map(isl_ctx *ctx)
8043 if (test_bin_union_map(ctx) < 0)
8044 return -1;
8045 if (test_union_set_contains(ctx) < 0)
8046 return -1;
8047 return 0;
8050 #undef BASE
8051 #define BASE union_pw_qpolynomial
8052 #include "isl_test_plain_equal_templ.c"
8054 /* Check that the result of applying "fn" to "a" and "b"
8055 * in (obviously) equal to "res".
8057 static isl_stat test_union_pw_op(isl_ctx *ctx, const char *a, const char *b,
8058 __isl_give isl_union_pw_qpolynomial *(*fn)(
8059 __isl_take isl_union_pw_qpolynomial *upwqp1,
8060 __isl_take isl_union_pw_qpolynomial *upwqp2),
8061 const char *res)
8063 isl_stat r;
8064 isl_union_pw_qpolynomial *upwqp1, *upwqp2;
8066 upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, a);
8067 upwqp2 = isl_union_pw_qpolynomial_read_from_str(ctx, b);
8068 upwqp1 = fn(upwqp1, upwqp2);
8069 r = union_pw_qpolynomial_check_plain_equal(upwqp1, res);
8070 isl_union_pw_qpolynomial_free(upwqp1);
8072 return r;
8075 int test_union_pw(isl_ctx *ctx)
8077 int equal;
8078 isl_stat r;
8079 const char *str;
8080 isl_union_set *uset;
8081 isl_union_pw_qpolynomial *upwqp1, *upwqp2;
8082 const char *a, *b;
8084 str = "{ [x] -> x^2 }";
8085 upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str);
8086 upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1);
8087 uset = isl_union_pw_qpolynomial_domain(upwqp1);
8088 upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2);
8089 upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset);
8090 equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2);
8091 isl_union_pw_qpolynomial_free(upwqp1);
8092 isl_union_pw_qpolynomial_free(upwqp2);
8093 if (equal < 0)
8094 return -1;
8095 if (!equal)
8096 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
8098 a = "{ A[x] -> x^2 : x >= 0; B[x] -> x }";
8099 b = "{ A[x] -> x }";
8100 str = "{ A[x] -> x^2 + x : x >= 0; A[x] -> x : x < 0; B[x] -> x }";
8101 if (test_union_pw_op(ctx, a, b, &isl_union_pw_qpolynomial_add, str) < 0)
8102 return -1;
8103 str = "{ A[x] -> x^2 - x : x >= 0; A[x] -> -x : x < 0; B[x] -> x }";
8104 if (test_union_pw_op(ctx, a, b, &isl_union_pw_qpolynomial_sub, str) < 0)
8105 return -1;
8107 str = "{ A[x] -> 0 }";
8108 a = "{ A[x] -> 1 }";
8109 b = "{ A[x] -> -1 }";
8110 if (test_union_pw_op(ctx, a, b, &isl_union_pw_qpolynomial_add, str) < 0)
8111 return -1;
8112 a = "{ A[x] -> 1 }";
8113 b = "{ A[x] -> 1 }";
8114 if (test_union_pw_op(ctx, a, b, &isl_union_pw_qpolynomial_sub, str) < 0)
8115 return -1;
8117 str = "{ [A[x] -> B[y,z]] -> x^2 + y * floor(x/4) * floor(z/2); "
8118 "C[z] -> z^3 }";
8119 upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str);
8120 upwqp1 = isl_union_pw_qpolynomial_domain_reverse(upwqp1);
8121 str = "{ [B[y,z] -> A[x]] -> x^2 + y * floor(x/4) * floor(z/2) }";
8122 r = union_pw_qpolynomial_check_plain_equal(upwqp1, str);
8123 isl_union_pw_qpolynomial_free(upwqp1);
8124 if (r < 0)
8125 return -1;
8127 return 0;
8130 /* Inputs for basic tests of functions that select
8131 * subparts of the domain of an isl_multi_union_pw_aff.
8132 * "fn" is the function that is tested.
8133 * "arg" is a string description of the input.
8134 * "res" is a string description of the expected result.
8136 struct {
8137 __isl_give isl_union_set *(*fn)(
8138 __isl_take isl_multi_union_pw_aff *mupa);
8139 const char *arg;
8140 const char *res;
8141 } un_locus_tests[] = {
8142 { &isl_multi_union_pw_aff_zero_union_set,
8143 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8144 "{ A[0,j]; B[0,j] }" },
8145 { &isl_multi_union_pw_aff_zero_union_set,
8146 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
8147 "{ A[i,i]; B[i,i] : i >= 0 }" },
8148 { &isl_multi_union_pw_aff_zero_union_set,
8149 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
8150 "{ A[i,j]; B[i,i] : i >= 0 }" },
8153 /* Perform some basic tests of functions that select
8154 * subparts of the domain of an isl_multi_union_pw_aff.
8156 static int test_un_locus(isl_ctx *ctx)
8158 int i;
8159 isl_bool ok;
8160 isl_union_set *uset, *res;
8161 isl_multi_union_pw_aff *mupa;
8163 for (i = 0; i < ARRAY_SIZE(un_locus_tests); ++i) {
8164 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
8165 un_locus_tests[i].arg);
8166 res = isl_union_set_read_from_str(ctx, un_locus_tests[i].res);
8167 uset = un_locus_tests[i].fn(mupa);
8168 ok = isl_union_set_is_equal(uset, res);
8169 isl_union_set_free(uset);
8170 isl_union_set_free(res);
8171 if (ok < 0)
8172 return -1;
8173 if (!ok)
8174 isl_die(ctx, isl_error_unknown,
8175 "unexpected result", return -1);
8178 return 0;
8181 /* Inputs for basic tests of functions that select
8182 * subparts of an isl_union_map based on a relation
8183 * specified by an isl_multi_union_pw_aff.
8184 * "fn" is the function that is tested.
8185 * "arg1" and "arg2" are string descriptions of the inputs.
8186 * "res" is a string description of the expected result.
8188 struct {
8189 __isl_give isl_union_map *(*fn)(
8190 __isl_take isl_union_map *umap,
8191 __isl_take isl_multi_union_pw_aff *mupa);
8192 const char *arg1;
8193 const char *arg2;
8194 const char *res;
8195 } bin_locus_tests[] = {
8196 { &isl_union_map_eq_at_multi_union_pw_aff,
8197 "{ A[i,j] -> B[i',j'] }",
8198 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8199 "{ A[i,j] -> B[i,j'] }" },
8200 { &isl_union_map_eq_at_multi_union_pw_aff,
8201 "{ A[i,j] -> B[i',j'] }",
8202 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8203 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8204 "{ A[i,j] -> B[i,j] }" },
8205 { &isl_union_map_eq_at_multi_union_pw_aff,
8206 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8207 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8208 "{ A[i,j] -> B[i,j'] }" },
8209 { &isl_union_map_eq_at_multi_union_pw_aff,
8210 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8211 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
8212 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
8213 { &isl_union_map_eq_at_multi_union_pw_aff,
8214 "{ A[i,j] -> B[i',j'] }",
8215 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
8216 "{ A[i,j] -> B[i,j'] : i > j }" },
8217 { &isl_union_map_lex_le_at_multi_union_pw_aff,
8218 "{ A[i,j] -> B[i',j'] }",
8219 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8220 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8221 "{ A[i,j] -> B[i',j'] : i,j <<= i',j' }" },
8222 { &isl_union_map_lex_lt_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] -> [j]; B[i,j] -> [j] }]",
8226 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
8227 { &isl_union_map_lex_ge_at_multi_union_pw_aff,
8228 "{ A[i,j] -> B[i',j'] }",
8229 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8230 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8231 "{ A[i,j] -> B[i',j'] : i,j >>= i',j' }" },
8232 { &isl_union_map_lex_gt_at_multi_union_pw_aff,
8233 "{ A[i,j] -> B[i',j'] }",
8234 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8235 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8236 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
8237 { &isl_union_map_eq_at_multi_union_pw_aff,
8238 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8239 "(F[] : { A[i,j]; B[i,j] })",
8240 "{ A[i,j] -> B[i',j'] }" },
8241 { &isl_union_map_eq_at_multi_union_pw_aff,
8242 "{ A[i,j] -> B[i',j'] }",
8243 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8244 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
8245 { &isl_union_map_eq_at_multi_union_pw_aff,
8246 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
8247 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8248 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
8249 { &isl_union_map_eq_at_multi_union_pw_aff,
8250 "{ A[i,j] -> B[i',j'] }",
8251 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
8252 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
8253 { &isl_union_map_eq_at_multi_union_pw_aff,
8254 "{ A[i,j] -> B[i',j'] }",
8255 "[N] -> (F[] : { : N >= 0 })",
8256 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
8259 /* Perform some basic tests of functions that select
8260 * subparts of an isl_union_map based on a relation
8261 * specified by an isl_multi_union_pw_aff.
8263 static int test_bin_locus(isl_ctx *ctx)
8265 int i;
8266 isl_bool ok;
8267 isl_union_map *umap, *res;
8268 isl_multi_union_pw_aff *mupa;
8270 for (i = 0; i < ARRAY_SIZE(bin_locus_tests); ++i) {
8271 umap = isl_union_map_read_from_str(ctx,
8272 bin_locus_tests[i].arg1);
8273 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
8274 bin_locus_tests[i].arg2);
8275 res = isl_union_map_read_from_str(ctx, bin_locus_tests[i].res);
8276 umap = bin_locus_tests[i].fn(umap, mupa);
8277 ok = isl_union_map_is_equal(umap, res);
8278 isl_union_map_free(umap);
8279 isl_union_map_free(res);
8280 if (ok < 0)
8281 return -1;
8282 if (!ok)
8283 isl_die(ctx, isl_error_unknown,
8284 "unexpected result", return -1);
8287 return 0;
8290 /* Inputs for basic tests of functions that determine
8291 * the part of the domain where two isl_multi_aff objects
8292 * related to each other in a specific way.
8293 * "fn" is the function that is being tested.
8294 * "arg1" and "arg2" are string descriptions of the inputs.
8295 * "res" is a string description of the expected result.
8297 static struct {
8298 __isl_give isl_set *(*fn)(__isl_take isl_multi_aff *ma1,
8299 __isl_take isl_multi_aff *ma2);
8300 const char *arg1;
8301 const char *arg2;
8302 const char *res;
8303 } bin_locus_ma_tests[] = {
8304 { &isl_multi_aff_lex_le_set, "{ [] }", "{ [] }", "{ : }" },
8305 { &isl_multi_aff_lex_lt_set, "{ [] }", "{ [] }", "{ : false }" },
8306 { &isl_multi_aff_lex_le_set,
8307 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8308 "{ A[i] : i <= 0 }" },
8309 { &isl_multi_aff_lex_lt_set,
8310 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8311 "{ A[i] : i < 0 }" },
8312 { &isl_multi_aff_lex_le_set,
8313 "{ A[i] -> [i, i] }", "{ A[i] -> [0, 0] }",
8314 "{ A[i] : i <= 0 }" },
8315 { &isl_multi_aff_lex_le_set,
8316 "{ A[i] -> [i, 0] }", "{ A[i] -> [0, 0] }",
8317 "{ A[i] : i <= 0 }" },
8318 { &isl_multi_aff_lex_le_set,
8319 "{ A[i] -> [i, 1] }", "{ A[i] -> [0, 0] }",
8320 "{ A[i] : i < 0 }" },
8323 /* Perform some basic tests of functions that determine
8324 * the part of the domain where two isl_multi_aff objects
8325 * related to each other in a specific way.
8327 static isl_stat test_bin_locus_ma(isl_ctx *ctx)
8329 int i;
8331 for (i = 0; i < ARRAY_SIZE(bin_locus_ma_tests); ++i) {
8332 const char *str;
8333 isl_bool ok;
8334 isl_multi_aff *ma1, *ma2;
8335 isl_set *set, *res;
8337 str = bin_locus_ma_tests[i].arg1;
8338 ma1 = isl_multi_aff_read_from_str(ctx, str);
8339 str = bin_locus_ma_tests[i].arg2;
8340 ma2 = isl_multi_aff_read_from_str(ctx, str);
8341 res = isl_set_read_from_str(ctx, bin_locus_ma_tests[i].res);
8342 set = bin_locus_ma_tests[i].fn(ma1, ma2);
8343 ok = isl_set_is_equal(set, res);
8344 isl_set_free(set);
8345 isl_set_free(res);
8346 if (ok < 0)
8347 return isl_stat_error;
8348 if (!ok)
8349 isl_die(ctx, isl_error_unknown,
8350 "unexpected result", return isl_stat_error);
8353 return isl_stat_ok;
8356 /* Perform basic locus tests.
8358 static int test_locus(isl_ctx *ctx)
8360 if (test_un_locus(ctx) < 0)
8361 return -1;
8362 if (test_bin_locus(ctx) < 0)
8363 return -1;
8364 if (test_bin_locus_ma(ctx) < 0)
8365 return -1;
8366 return 0;
8369 /* Test that isl_union_pw_qpolynomial_eval picks up the function
8370 * defined over the correct domain space.
8372 static int test_eval_1(isl_ctx *ctx)
8374 const char *str;
8375 isl_point *pnt;
8376 isl_set *set;
8377 isl_union_pw_qpolynomial *upwqp;
8378 isl_val *v;
8379 int cmp;
8381 str = "{ A[x] -> x^2; B[x] -> -x^2 }";
8382 upwqp = isl_union_pw_qpolynomial_read_from_str(ctx, str);
8383 str = "{ A[6] }";
8384 set = isl_set_read_from_str(ctx, str);
8385 pnt = isl_set_sample_point(set);
8386 v = isl_union_pw_qpolynomial_eval(upwqp, pnt);
8387 cmp = isl_val_cmp_si(v, 36);
8388 isl_val_free(v);
8390 if (!v)
8391 return -1;
8392 if (cmp != 0)
8393 isl_die(ctx, isl_error_unknown, "unexpected value", return -1);
8395 return 0;
8398 /* Check that isl_qpolynomial_eval handles getting called on a void point.
8400 static int test_eval_2(isl_ctx *ctx)
8402 const char *str;
8403 isl_point *pnt;
8404 isl_set *set;
8405 isl_qpolynomial *qp;
8406 isl_val *v;
8407 isl_bool ok;
8409 str = "{ A[x] -> [x] }";
8410 qp = isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx, str));
8411 str = "{ A[x] : false }";
8412 set = isl_set_read_from_str(ctx, str);
8413 pnt = isl_set_sample_point(set);
8414 v = isl_qpolynomial_eval(qp, pnt);
8415 ok = isl_val_is_nan(v);
8416 isl_val_free(v);
8418 if (ok < 0)
8419 return -1;
8420 if (!ok)
8421 isl_die(ctx, isl_error_unknown, "expecting NaN", return -1);
8423 return 0;
8426 /* Check that a polynomial (without local variables) can be evaluated
8427 * in a rational point.
8429 static isl_stat test_eval_3(isl_ctx *ctx)
8431 isl_pw_qpolynomial *pwqp;
8432 isl_point *pnt;
8433 isl_val *v;
8434 isl_stat r;
8436 pwqp = isl_pw_qpolynomial_read_from_str(ctx, "{ [x] -> x^2 }");
8437 pnt = isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp));
8438 v = isl_val_read_from_str(ctx, "1/2");
8439 pnt = isl_point_set_coordinate_val(pnt, isl_dim_set, 0, v);
8440 v = isl_pw_qpolynomial_eval(pwqp, pnt);
8441 r = val_check_equal(v, "1/4");
8442 isl_val_free(v);
8444 return r;
8447 /* Inputs for isl_pw_aff_eval test.
8448 * "f" is the affine function.
8449 * "p" is the point where the function should be evaluated.
8450 * "res" is the expected result.
8452 struct {
8453 const char *f;
8454 const char *p;
8455 const char *res;
8456 } aff_eval_tests[] = {
8457 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
8458 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
8459 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
8460 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
8461 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
8462 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
8463 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
8464 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
8465 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
8466 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
8467 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
8468 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
8469 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
8470 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
8471 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
8472 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
8473 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
8474 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
8475 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
8476 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
8477 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
8478 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
8479 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
8480 { "[m, n] -> { [2m + 3n] }", "[n=1, m=10] -> { : }", "23" },
8483 /* Perform basic isl_pw_aff_eval tests.
8485 static int test_eval_aff(isl_ctx *ctx)
8487 int i;
8489 for (i = 0; i < ARRAY_SIZE(aff_eval_tests); ++i) {
8490 isl_stat r;
8491 isl_pw_aff *pa;
8492 isl_set *set;
8493 isl_point *pnt;
8494 isl_val *v;
8496 pa = isl_pw_aff_read_from_str(ctx, aff_eval_tests[i].f);
8497 set = isl_set_read_from_str(ctx, aff_eval_tests[i].p);
8498 pnt = isl_set_sample_point(set);
8499 v = isl_pw_aff_eval(pa, pnt);
8500 r = val_check_equal(v, aff_eval_tests[i].res);
8501 isl_val_free(v);
8502 if (r < 0)
8503 return -1;
8505 return 0;
8508 /* Perform basic evaluation tests.
8510 static int test_eval(isl_ctx *ctx)
8512 if (test_eval_1(ctx) < 0)
8513 return -1;
8514 if (test_eval_2(ctx) < 0)
8515 return -1;
8516 if (test_eval_3(ctx) < 0)
8517 return -1;
8518 if (test_eval_aff(ctx) < 0)
8519 return -1;
8520 return 0;
8523 /* Descriptions of sets that are tested for reparsing after printing.
8525 const char *output_tests[] = {
8526 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
8527 "{ [x] : 1 = 0 }",
8528 "{ [x] : false }",
8529 "{ [x] : x mod 2 = 0 }",
8530 "{ [x] : x mod 2 = 1 }",
8531 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
8532 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
8533 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8534 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8535 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
8536 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
8539 /* Check that printing a set and reparsing a set from the printed output
8540 * results in the same set.
8542 static int test_output_set(isl_ctx *ctx)
8544 int i;
8545 char *str;
8546 isl_set *set1, *set2;
8547 isl_bool equal;
8549 for (i = 0; i < ARRAY_SIZE(output_tests); ++i) {
8550 set1 = isl_set_read_from_str(ctx, output_tests[i]);
8551 str = isl_set_to_str(set1);
8552 set2 = isl_set_read_from_str(ctx, str);
8553 free(str);
8554 equal = isl_set_is_equal(set1, set2);
8555 isl_set_free(set1);
8556 isl_set_free(set2);
8557 if (equal < 0)
8558 return -1;
8559 if (!equal)
8560 isl_die(ctx, isl_error_unknown,
8561 "parsed output not the same", return -1);
8564 return 0;
8567 /* Check that an isl_multi_aff is printed using a consistent space.
8569 static isl_stat test_output_ma(isl_ctx *ctx)
8571 char *str;
8572 isl_bool equal;
8573 isl_aff *aff;
8574 isl_multi_aff *ma, *ma2;
8576 ma = isl_multi_aff_read_from_str(ctx, "{ [a, b] -> [a + b] }");
8577 aff = isl_aff_read_from_str(ctx, "{ [c, d] -> [c + d] }");
8578 ma = isl_multi_aff_set_aff(ma, 0, aff);
8579 str = isl_multi_aff_to_str(ma);
8580 ma2 = isl_multi_aff_read_from_str(ctx, str);
8581 free(str);
8582 equal = isl_multi_aff_plain_is_equal(ma, ma2);
8583 isl_multi_aff_free(ma2);
8584 isl_multi_aff_free(ma);
8586 if (equal < 0)
8587 return isl_stat_error;
8588 if (!equal)
8589 isl_die(ctx, isl_error_unknown, "bad conversion",
8590 return isl_stat_error);
8592 return isl_stat_ok;
8595 /* Check that an isl_multi_pw_aff is printed using a consistent space.
8597 static isl_stat test_output_mpa(isl_ctx *ctx)
8599 char *str;
8600 isl_bool equal;
8601 isl_pw_aff *pa;
8602 isl_multi_pw_aff *mpa, *mpa2;
8604 mpa = isl_multi_pw_aff_read_from_str(ctx, "{ [a, b] -> [a + b] }");
8605 pa = isl_pw_aff_read_from_str(ctx, "{ [c, d] -> [c + d] }");
8606 mpa = isl_multi_pw_aff_set_pw_aff(mpa, 0, pa);
8607 str = isl_multi_pw_aff_to_str(mpa);
8608 mpa2 = isl_multi_pw_aff_read_from_str(ctx, str);
8609 free(str);
8610 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2);
8611 isl_multi_pw_aff_free(mpa2);
8612 isl_multi_pw_aff_free(mpa);
8614 if (equal < 0)
8615 return isl_stat_error;
8616 if (!equal)
8617 isl_die(ctx, isl_error_unknown, "bad conversion",
8618 return isl_stat_error);
8620 return isl_stat_ok;
8623 int test_output(isl_ctx *ctx)
8625 char *s;
8626 const char *str;
8627 isl_pw_aff *pa;
8628 isl_printer *p;
8629 int equal;
8631 if (test_output_set(ctx) < 0)
8632 return -1;
8633 if (test_output_ma(ctx) < 0)
8634 return -1;
8635 if (test_output_mpa(ctx) < 0)
8636 return -1;
8638 str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
8639 pa = isl_pw_aff_read_from_str(ctx, str);
8641 p = isl_printer_to_str(ctx);
8642 p = isl_printer_set_output_format(p, ISL_FORMAT_C);
8643 p = isl_printer_print_pw_aff(p, pa);
8644 s = isl_printer_get_str(p);
8645 isl_printer_free(p);
8646 isl_pw_aff_free(pa);
8647 if (!s)
8648 equal = -1;
8649 else
8650 equal = !strcmp(s, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
8651 free(s);
8652 if (equal < 0)
8653 return -1;
8654 if (!equal)
8655 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
8657 return 0;
8660 int test_sample(isl_ctx *ctx)
8662 const char *str;
8663 isl_basic_set *bset1, *bset2;
8664 int empty, subset;
8666 str = "{ [a, b, c, d, e, f, g, h, i, j, k] : "
8667 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
8668 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
8669 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
8670 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
8671 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
8672 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
8673 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
8674 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
8675 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
8676 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
8677 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
8678 "d - 1073741821e and "
8679 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
8680 "3j >= 1 - a + b + 2e and "
8681 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
8682 "3i <= 4 - a + 4b - e and "
8683 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
8684 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
8685 "c <= -1 + a and 3i >= -2 - a + 3e and "
8686 "1073741822e <= 1073741823 - a + 1073741822b + c and "
8687 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
8688 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
8689 "1073741823e >= 1 + 1073741823b - d and "
8690 "3i >= 1073741823b + c - 1073741823e - f and "
8691 "3i >= 1 + 2b + e + 3g }";
8692 bset1 = isl_basic_set_read_from_str(ctx, str);
8693 bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1));
8694 empty = isl_basic_set_is_empty(bset2);
8695 subset = isl_basic_set_is_subset(bset2, bset1);
8696 isl_basic_set_free(bset1);
8697 isl_basic_set_free(bset2);
8698 if (empty < 0 || subset < 0)
8699 return -1;
8700 if (empty)
8701 isl_die(ctx, isl_error_unknown, "point not found", return -1);
8702 if (!subset)
8703 isl_die(ctx, isl_error_unknown, "bad point found", return -1);
8705 return 0;
8708 /* Perform a projection on a basic set that is known to be empty
8709 * but that has not been assigned a canonical representation.
8710 * Earlier versions of isl would run into a stack overflow
8711 * on this example.
8713 static int test_empty_projection(isl_ctx *ctx)
8715 const char *str;
8716 isl_bool empty;
8717 isl_basic_set *bset;
8719 str = "{ [a, b, c, d, e, f, g, h] : 5f = 1 + 4a - b + 5c - d - 2e and "
8720 "3h = 2 + b + c and 14c >= 9 - 3a + 25b and "
8721 "4c <= 50 - 3a + 23b and 6b <= -39 + a and "
8722 "9g >= -6 + 3a + b + c and e < a + b - 2d and "
8723 "7d >= -5 + 2a + 2b and 5g >= -14 + a - 4b + d + 2e and "
8724 "9g <= -28 - 5b - 2c + 3d + 6e }";
8725 bset = isl_basic_set_read_from_str(ctx, str);
8726 empty = isl_basic_set_is_empty(bset);
8727 bset = isl_basic_set_params(bset);
8728 isl_basic_set_free(bset);
8730 if (empty < 0)
8731 return -1;
8733 return 0;
8736 int test_slice(isl_ctx *ctx)
8738 const char *str;
8739 isl_map *map;
8740 int equal;
8742 str = "{ [i] -> [j] }";
8743 map = isl_map_read_from_str(ctx, str);
8744 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_out, 0);
8745 equal = map_check_equal(map, "{ [i] -> [i] }");
8746 isl_map_free(map);
8747 if (equal < 0)
8748 return -1;
8750 str = "{ [i] -> [j] }";
8751 map = isl_map_read_from_str(ctx, str);
8752 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_in, 0);
8753 equal = map_check_equal(map, "{ [i] -> [j] }");
8754 isl_map_free(map);
8755 if (equal < 0)
8756 return -1;
8758 str = "{ [i] -> [j] }";
8759 map = isl_map_read_from_str(ctx, str);
8760 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_out, 0);
8761 equal = map_check_equal(map, "{ [i] -> [-i] }");
8762 isl_map_free(map);
8763 if (equal < 0)
8764 return -1;
8766 str = "{ [i] -> [j] }";
8767 map = isl_map_read_from_str(ctx, str);
8768 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_in, 0);
8769 equal = map_check_equal(map, "{ [0] -> [j] }");
8770 isl_map_free(map);
8771 if (equal < 0)
8772 return -1;
8774 str = "{ [i] -> [j] }";
8775 map = isl_map_read_from_str(ctx, str);
8776 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_out, 0);
8777 equal = map_check_equal(map, "{ [i] -> [j] : i > j }");
8778 isl_map_free(map);
8779 if (equal < 0)
8780 return -1;
8782 str = "{ [i] -> [j] }";
8783 map = isl_map_read_from_str(ctx, str);
8784 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_in, 0);
8785 equal = map_check_equal(map, "{ [i] -> [j] : false }");
8786 isl_map_free(map);
8787 if (equal < 0)
8788 return -1;
8790 return 0;
8793 int test_eliminate(isl_ctx *ctx)
8795 const char *str;
8796 isl_map *map;
8797 int equal;
8799 str = "{ [i] -> [j] : i = 2j }";
8800 map = isl_map_read_from_str(ctx, str);
8801 map = isl_map_eliminate(map, isl_dim_out, 0, 1);
8802 equal = map_check_equal(map, "{ [i] -> [j] : exists a : i = 2a }");
8803 isl_map_free(map);
8804 if (equal < 0)
8805 return -1;
8807 return 0;
8810 /* Check basic functionality of isl_map_deltas_map.
8812 static int test_deltas_map(isl_ctx *ctx)
8814 const char *str;
8815 isl_map *map;
8816 int equal;
8818 str = "{ A[i] -> A[i + 1] }";
8819 map = isl_map_read_from_str(ctx, str);
8820 map = isl_map_deltas_map(map);
8821 equal = map_check_equal(map, "{ [A[i] -> A[i + 1]] -> A[1] }");
8822 isl_map_free(map);
8823 if (equal < 0)
8824 return -1;
8826 return 0;
8829 /* Check that isl_set_dim_residue_class detects that the values of j
8830 * in the set below are all odd and that it does not detect any spurious
8831 * strides.
8833 static int test_residue_class(isl_ctx *ctx)
8835 const char *str;
8836 isl_set *set;
8837 isl_int m, r;
8838 isl_stat res;
8840 str = "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
8841 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
8842 set = isl_set_read_from_str(ctx, str);
8843 isl_int_init(m);
8844 isl_int_init(r);
8845 res = isl_set_dim_residue_class(set, 1, &m, &r);
8846 if (res >= 0 &&
8847 (isl_int_cmp_si(m, 2) != 0 || isl_int_cmp_si(r, 1) != 0))
8848 isl_die(ctx, isl_error_unknown, "incorrect residue class",
8849 res = isl_stat_error);
8850 isl_int_clear(r);
8851 isl_int_clear(m);
8852 isl_set_free(set);
8854 return res;
8857 static int test_align_parameters_1(isl_ctx *ctx)
8859 const char *str;
8860 isl_space *space;
8861 isl_multi_aff *ma1, *ma2;
8862 int equal;
8864 str = "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
8865 ma1 = isl_multi_aff_read_from_str(ctx, str);
8867 space = isl_space_params_alloc(ctx, 1);
8868 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
8869 ma1 = isl_multi_aff_align_params(ma1, space);
8871 str = "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
8872 ma2 = isl_multi_aff_read_from_str(ctx, str);
8874 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
8876 isl_multi_aff_free(ma1);
8877 isl_multi_aff_free(ma2);
8879 if (equal < 0)
8880 return -1;
8881 if (!equal)
8882 isl_die(ctx, isl_error_unknown,
8883 "result not as expected", return -1);
8885 return 0;
8888 /* Check the isl_multi_*_from_*_list operation in case inputs
8889 * have unaligned parameters.
8890 * In particular, older versions of isl would simply fail
8891 * (without printing any error message).
8893 static isl_stat test_align_parameters_2(isl_ctx *ctx)
8895 isl_space *space;
8896 isl_map *map;
8897 isl_aff *aff;
8898 isl_multi_aff *ma;
8900 map = isl_map_read_from_str(ctx, "{ A[] -> M[x] }");
8901 space = isl_map_get_space(map);
8902 isl_map_free(map);
8904 aff = isl_aff_read_from_str(ctx, "[N] -> { A[] -> [N] }");
8905 ma = isl_multi_aff_from_aff_list(space, isl_aff_list_from_aff(aff));
8906 isl_multi_aff_free(ma);
8908 if (!ma)
8909 return isl_stat_error;
8910 return isl_stat_ok;
8913 /* Perform basic parameter alignment tests.
8915 static int test_align_parameters(isl_ctx *ctx)
8917 if (test_align_parameters_1(ctx) < 0)
8918 return -1;
8919 if (test_align_parameters_2(ctx) < 0)
8920 return -1;
8922 return 0;
8925 /* Check that isl_*_drop_unused_params actually drops the unused parameters
8926 * by comparing the result using isl_*_plain_is_equal.
8927 * Note that this assumes that isl_*_plain_is_equal does not consider
8928 * objects that only differ by unused parameters to be equal.
8930 int test_drop_unused_parameters(isl_ctx *ctx)
8932 const char *str_with, *str_without;
8933 isl_basic_set *bset1, *bset2;
8934 isl_set *set1, *set2;
8935 isl_pw_aff *pwa1, *pwa2;
8936 int equal;
8938 str_with = "[n, m, o] -> { [m] }";
8939 str_without = "[m] -> { [m] }";
8941 bset1 = isl_basic_set_read_from_str(ctx, str_with);
8942 bset2 = isl_basic_set_read_from_str(ctx, str_without);
8943 bset1 = isl_basic_set_drop_unused_params(bset1);
8944 equal = isl_basic_set_plain_is_equal(bset1, bset2);
8945 isl_basic_set_free(bset1);
8946 isl_basic_set_free(bset2);
8948 if (equal < 0)
8949 return -1;
8950 if (!equal)
8951 isl_die(ctx, isl_error_unknown,
8952 "result not as expected", return -1);
8954 set1 = isl_set_read_from_str(ctx, str_with);
8955 set2 = isl_set_read_from_str(ctx, str_without);
8956 set1 = isl_set_drop_unused_params(set1);
8957 equal = isl_set_plain_is_equal(set1, set2);
8958 isl_set_free(set1);
8959 isl_set_free(set2);
8961 if (equal < 0)
8962 return -1;
8963 if (!equal)
8964 isl_die(ctx, isl_error_unknown,
8965 "result not as expected", return -1);
8967 pwa1 = isl_pw_aff_read_from_str(ctx, str_with);
8968 pwa2 = isl_pw_aff_read_from_str(ctx, str_without);
8969 pwa1 = isl_pw_aff_drop_unused_params(pwa1);
8970 equal = isl_pw_aff_plain_is_equal(pwa1, pwa2);
8971 isl_pw_aff_free(pwa1);
8972 isl_pw_aff_free(pwa2);
8974 if (equal < 0)
8975 return -1;
8976 if (!equal)
8977 isl_die(ctx, isl_error_unknown,
8978 "result not as expected", return -1);
8980 return 0;
8983 static int test_list(isl_ctx *ctx)
8985 isl_id *a, *b, *c, *d, *id;
8986 isl_id_list *list;
8987 isl_size n;
8988 int ok;
8990 a = isl_id_alloc(ctx, "a", NULL);
8991 b = isl_id_alloc(ctx, "b", NULL);
8992 c = isl_id_alloc(ctx, "c", NULL);
8993 d = isl_id_alloc(ctx, "d", NULL);
8995 list = isl_id_list_alloc(ctx, 4);
8996 list = isl_id_list_add(list, b);
8997 list = isl_id_list_insert(list, 0, a);
8998 list = isl_id_list_add(list, c);
8999 list = isl_id_list_add(list, d);
9000 list = isl_id_list_drop(list, 1, 1);
9002 n = isl_id_list_n_id(list);
9003 if (n < 0)
9004 return -1;
9005 if (n != 3) {
9006 isl_id_list_free(list);
9007 isl_die(ctx, isl_error_unknown,
9008 "unexpected number of elements in list", return -1);
9011 id = isl_id_list_get_id(list, 0);
9012 ok = id == a;
9013 isl_id_free(id);
9014 id = isl_id_list_get_id(list, 1);
9015 ok = ok && id == c;
9016 isl_id_free(id);
9017 id = isl_id_list_get_id(list, 2);
9018 ok = ok && id == d;
9019 isl_id_free(id);
9021 isl_id_list_free(list);
9023 if (!ok)
9024 isl_die(ctx, isl_error_unknown,
9025 "unexpected elements in list", return -1);
9027 return 0;
9030 /* Check the conversion from an isl_multi_aff to an isl_basic_set.
9032 static isl_stat test_ma_conversion(isl_ctx *ctx)
9034 const char *str;
9035 isl_bool equal;
9036 isl_multi_aff *ma;
9037 isl_basic_set *bset1, *bset2;
9039 str = "[N] -> { A[0, N + 1] }";
9040 ma = isl_multi_aff_read_from_str(ctx, str);
9041 bset1 = isl_basic_set_read_from_str(ctx, str);
9042 bset2 = isl_basic_set_from_multi_aff(ma);
9043 equal = isl_basic_set_is_equal(bset1, bset2);
9044 isl_basic_set_free(bset1);
9045 isl_basic_set_free(bset2);
9046 if (equal < 0)
9047 return isl_stat_error;
9048 if (!equal)
9049 isl_die(ctx, isl_error_unknown, "bad conversion",
9050 return isl_stat_error);
9051 return isl_stat_ok;
9054 const char *set_conversion_tests[] = {
9055 "[N] -> { [i] : N - 1 <= 2 i <= N }",
9056 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
9057 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9058 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9059 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
9060 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
9061 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
9062 "-3 + c <= d <= 28 + c) }",
9065 /* Check that converting from isl_set to isl_pw_multi_aff and back
9066 * to isl_set produces the original isl_set.
9068 static int test_set_conversion(isl_ctx *ctx)
9070 int i;
9071 const char *str;
9072 isl_set *set1, *set2;
9073 isl_pw_multi_aff *pma;
9074 int equal;
9076 for (i = 0; i < ARRAY_SIZE(set_conversion_tests); ++i) {
9077 str = set_conversion_tests[i];
9078 set1 = isl_set_read_from_str(ctx, str);
9079 pma = isl_pw_multi_aff_from_set(isl_set_copy(set1));
9080 set2 = isl_set_from_pw_multi_aff(pma);
9081 equal = isl_set_is_equal(set1, set2);
9082 isl_set_free(set1);
9083 isl_set_free(set2);
9085 if (equal < 0)
9086 return -1;
9087 if (!equal)
9088 isl_die(ctx, isl_error_unknown, "bad conversion",
9089 return -1);
9092 return 0;
9095 const char *conversion_tests[] = {
9096 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9097 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9098 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9099 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9100 "9e <= -2 - 2a) }",
9101 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9102 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9103 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9106 /* Check that converting from isl_map to isl_pw_multi_aff and back
9107 * to isl_map produces the original isl_map.
9109 static int test_map_conversion(isl_ctx *ctx)
9111 int i;
9112 isl_map *map1, *map2;
9113 isl_pw_multi_aff *pma;
9114 int equal;
9116 for (i = 0; i < ARRAY_SIZE(conversion_tests); ++i) {
9117 map1 = isl_map_read_from_str(ctx, conversion_tests[i]);
9118 pma = isl_pw_multi_aff_from_map(isl_map_copy(map1));
9119 map2 = isl_map_from_pw_multi_aff(pma);
9120 equal = isl_map_is_equal(map1, map2);
9121 isl_map_free(map1);
9122 isl_map_free(map2);
9124 if (equal < 0)
9125 return -1;
9126 if (!equal)
9127 isl_die(ctx, isl_error_unknown, "bad conversion",
9128 return -1);
9131 return 0;
9134 /* Descriptions of isl_pw_multi_aff objects for testing conversion
9135 * to isl_multi_pw_aff and back.
9137 const char *mpa_conversion_tests[] = {
9138 "{ [x] -> A[x] }",
9139 "{ [x] -> A[x] : x >= 0 }",
9140 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
9141 "{ [x] -> A[x, x + 1] }",
9142 "{ [x] -> A[] }",
9143 "{ [x] -> A[] : x >= 0 }",
9146 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
9147 * back to isl_pw_multi_aff preserves the original meaning.
9149 static int test_mpa_conversion(isl_ctx *ctx)
9151 int i;
9152 isl_pw_multi_aff *pma1, *pma2;
9153 isl_multi_pw_aff *mpa;
9154 int equal;
9156 for (i = 0; i < ARRAY_SIZE(mpa_conversion_tests); ++i) {
9157 const char *str;
9158 str = mpa_conversion_tests[i];
9159 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
9160 pma2 = isl_pw_multi_aff_copy(pma1);
9161 mpa = isl_multi_pw_aff_from_pw_multi_aff(pma1);
9162 pma1 = isl_pw_multi_aff_from_multi_pw_aff(mpa);
9163 equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
9164 isl_pw_multi_aff_free(pma1);
9165 isl_pw_multi_aff_free(pma2);
9167 if (equal < 0)
9168 return -1;
9169 if (!equal)
9170 isl_die(ctx, isl_error_unknown, "bad conversion",
9171 return -1);
9174 return 0;
9177 /* Descriptions of union maps that should be convertible
9178 * to an isl_multi_union_pw_aff.
9180 const char *umap_mupa_conversion_tests[] = {
9181 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9182 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9183 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9184 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9185 "9e <= -2 - 2a) }",
9186 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9187 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9188 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9189 "{ A[] -> B[0]; C[] -> B[1] }",
9190 "{ A[] -> B[]; C[] -> B[] }",
9193 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
9194 * to isl_union_map produces the original isl_union_map.
9196 static int test_union_map_mupa_conversion(isl_ctx *ctx)
9198 int i;
9199 isl_union_map *umap1, *umap2;
9200 isl_multi_union_pw_aff *mupa;
9201 int equal;
9203 for (i = 0; i < ARRAY_SIZE(umap_mupa_conversion_tests); ++i) {
9204 const char *str;
9205 str = umap_mupa_conversion_tests[i];
9206 umap1 = isl_union_map_read_from_str(ctx, str);
9207 umap2 = isl_union_map_copy(umap1);
9208 mupa = isl_multi_union_pw_aff_from_union_map(umap2);
9209 umap2 = isl_union_map_from_multi_union_pw_aff(mupa);
9210 equal = isl_union_map_is_equal(umap1, umap2);
9211 isl_union_map_free(umap1);
9212 isl_union_map_free(umap2);
9214 if (equal < 0)
9215 return -1;
9216 if (!equal)
9217 isl_die(ctx, isl_error_unknown, "bad conversion",
9218 return -1);
9221 return 0;
9224 static int test_conversion(isl_ctx *ctx)
9226 if (test_ma_conversion(ctx) < 0)
9227 return -1;
9228 if (test_set_conversion(ctx) < 0)
9229 return -1;
9230 if (test_map_conversion(ctx) < 0)
9231 return -1;
9232 if (test_mpa_conversion(ctx) < 0)
9233 return -1;
9234 if (test_union_map_mupa_conversion(ctx) < 0)
9235 return -1;
9236 return 0;
9239 /* Check that isl_basic_map_curry does not modify input.
9241 static int test_curry(isl_ctx *ctx)
9243 const char *str;
9244 isl_basic_map *bmap1, *bmap2;
9245 int equal;
9247 str = "{ [A[] -> B[]] -> C[] }";
9248 bmap1 = isl_basic_map_read_from_str(ctx, str);
9249 bmap2 = isl_basic_map_curry(isl_basic_map_copy(bmap1));
9250 equal = isl_basic_map_is_equal(bmap1, bmap2);
9251 isl_basic_map_free(bmap1);
9252 isl_basic_map_free(bmap2);
9254 if (equal < 0)
9255 return -1;
9256 if (equal)
9257 isl_die(ctx, isl_error_unknown,
9258 "curried map should not be equal to original",
9259 return -1);
9261 return 0;
9264 struct {
9265 const char *ma1;
9266 const char *ma;
9267 const char *res;
9268 } pullback_tests[] = {
9269 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
9270 "{ A[a,b] -> C[b + 2a] }" },
9271 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
9272 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
9273 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
9274 "{ A[a] -> C[(a)/6] }" },
9275 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
9276 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
9277 "{ A[a] -> C[(2a)/3] }" },
9278 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
9279 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
9280 "{ A[i,j] -> C[i + j, i + j] }"},
9281 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
9282 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
9283 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
9284 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
9285 "{ [i, j] -> [floor((i)/3), j] }",
9286 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
9289 static int test_pullback(isl_ctx *ctx)
9291 int i;
9292 isl_multi_aff *ma1, *ma2;
9293 isl_multi_aff *ma;
9294 int equal;
9296 for (i = 0; i < ARRAY_SIZE(pullback_tests); ++i) {
9297 ma1 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma1);
9298 ma = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma);
9299 ma2 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].res);
9300 ma1 = isl_multi_aff_pullback_multi_aff(ma1, ma);
9301 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
9302 isl_multi_aff_free(ma1);
9303 isl_multi_aff_free(ma2);
9304 if (equal < 0)
9305 return -1;
9306 if (!equal)
9307 isl_die(ctx, isl_error_unknown, "bad pullback",
9308 return -1);
9311 return 0;
9314 /* Check that negation is printed correctly and that equal expressions
9315 * are correctly identified.
9317 static int test_ast(isl_ctx *ctx)
9319 isl_ast_expr *expr, *expr1, *expr2, *expr3;
9320 char *str;
9321 int ok, equal;
9323 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
9324 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
9325 expr = isl_ast_expr_add(expr1, expr2);
9326 expr2 = isl_ast_expr_copy(expr);
9327 expr = isl_ast_expr_neg(expr);
9328 expr2 = isl_ast_expr_neg(expr2);
9329 equal = isl_ast_expr_is_equal(expr, expr2);
9330 str = isl_ast_expr_to_C_str(expr);
9331 ok = str ? !strcmp(str, "-(A + B)") : -1;
9332 free(str);
9333 isl_ast_expr_free(expr);
9334 isl_ast_expr_free(expr2);
9336 if (ok < 0 || equal < 0)
9337 return -1;
9338 if (!equal)
9339 isl_die(ctx, isl_error_unknown,
9340 "equal expressions not considered equal", return -1);
9341 if (!ok)
9342 isl_die(ctx, isl_error_unknown,
9343 "isl_ast_expr printed incorrectly", return -1);
9345 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
9346 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
9347 expr = isl_ast_expr_add(expr1, expr2);
9348 expr3 = isl_ast_expr_from_id(isl_id_alloc(ctx, "C", NULL));
9349 expr = isl_ast_expr_sub(expr3, expr);
9350 str = isl_ast_expr_to_C_str(expr);
9351 ok = str ? !strcmp(str, "C - (A + B)") : -1;
9352 free(str);
9353 isl_ast_expr_free(expr);
9355 if (ok < 0)
9356 return -1;
9357 if (!ok)
9358 isl_die(ctx, isl_error_unknown,
9359 "isl_ast_expr printed incorrectly", return -1);
9361 return 0;
9364 /* Check that isl_ast_build_expr_from_set returns a valid expression
9365 * for an empty set. Note that isl_ast_build_expr_from_set getting
9366 * called on an empty set probably indicates a bug in the caller.
9368 static int test_ast_build(isl_ctx *ctx)
9370 isl_set *set;
9371 isl_ast_build *build;
9372 isl_ast_expr *expr;
9374 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9375 build = isl_ast_build_from_context(set);
9377 set = isl_set_empty(isl_space_params_alloc(ctx, 0));
9378 expr = isl_ast_build_expr_from_set(build, set);
9380 isl_ast_expr_free(expr);
9381 isl_ast_build_free(build);
9383 if (!expr)
9384 return -1;
9386 return 0;
9389 /* Internal data structure for before_for and after_for callbacks.
9391 * depth is the current depth
9392 * before is the number of times before_for has been called
9393 * after is the number of times after_for has been called
9395 struct isl_test_codegen_data {
9396 int depth;
9397 int before;
9398 int after;
9401 /* This function is called before each for loop in the AST generated
9402 * from test_ast_gen1.
9404 * Increment the number of calls and the depth.
9405 * Check that the space returned by isl_ast_build_get_schedule_space
9406 * matches the target space of the schedule returned by
9407 * isl_ast_build_get_schedule.
9408 * Return an isl_id that is checked by the corresponding call
9409 * to after_for.
9411 static __isl_give isl_id *before_for(__isl_keep isl_ast_build *build,
9412 void *user)
9414 struct isl_test_codegen_data *data = user;
9415 isl_ctx *ctx;
9416 isl_space *space;
9417 isl_union_map *schedule;
9418 isl_union_set *uset;
9419 isl_set *set;
9420 isl_bool empty;
9421 isl_size n;
9422 char name[] = "d0";
9424 ctx = isl_ast_build_get_ctx(build);
9426 if (data->before >= 3)
9427 isl_die(ctx, isl_error_unknown,
9428 "unexpected number of for nodes", return NULL);
9429 if (data->depth < 0 || data->depth >= 2)
9430 isl_die(ctx, isl_error_unknown,
9431 "unexpected depth", return NULL);
9433 snprintf(name, sizeof(name), "d%d", data->depth);
9434 data->before++;
9435 data->depth++;
9437 schedule = isl_ast_build_get_schedule(build);
9438 uset = isl_union_map_range(schedule);
9439 n = isl_union_set_n_set(uset);
9440 if (n != 1) {
9441 isl_union_set_free(uset);
9442 if (n < 0)
9443 return NULL;
9444 isl_die(ctx, isl_error_unknown,
9445 "expecting single range space", return NULL);
9448 space = isl_ast_build_get_schedule_space(build);
9449 set = isl_union_set_extract_set(uset, space);
9450 isl_union_set_free(uset);
9451 empty = isl_set_is_empty(set);
9452 isl_set_free(set);
9454 if (empty < 0)
9455 return NULL;
9456 if (empty)
9457 isl_die(ctx, isl_error_unknown,
9458 "spaces don't match", return NULL);
9460 return isl_id_alloc(ctx, name, NULL);
9463 /* This function is called after each for loop in the AST generated
9464 * from test_ast_gen1.
9466 * Increment the number of calls and decrement the depth.
9467 * Check that the annotation attached to the node matches
9468 * the isl_id returned by the corresponding call to before_for.
9470 static __isl_give isl_ast_node *after_for(__isl_take isl_ast_node *node,
9471 __isl_keep isl_ast_build *build, void *user)
9473 struct isl_test_codegen_data *data = user;
9474 isl_id *id;
9475 const char *name;
9476 int valid;
9478 data->after++;
9479 data->depth--;
9481 if (data->after > data->before)
9482 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
9483 "mismatch in number of for nodes",
9484 return isl_ast_node_free(node));
9486 id = isl_ast_node_get_annotation(node);
9487 if (!id)
9488 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
9489 "missing annotation", return isl_ast_node_free(node));
9491 name = isl_id_get_name(id);
9492 valid = name && atoi(name + 1) == data->depth;
9493 isl_id_free(id);
9495 if (!valid)
9496 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
9497 "wrong annotation", return isl_ast_node_free(node));
9499 return node;
9502 /* This function is called after node in the AST generated
9503 * from test_ast_gen1.
9505 * Increment the count in "user" if this is a for node and
9506 * return true to indicate that descendant should also be visited.
9508 static isl_bool count_for(__isl_keep isl_ast_node *node, void *user)
9510 int *count = user;
9512 if (isl_ast_node_get_type(node) == isl_ast_node_for)
9513 ++*count;
9515 return isl_bool_true;
9518 /* If "node" is a block node, then replace it by its first child.
9520 static __isl_give isl_ast_node *select_first(__isl_take isl_ast_node *node,
9521 void *user)
9523 isl_ast_node_list *children;
9524 isl_ast_node *child;
9526 if (isl_ast_node_get_type(node) != isl_ast_node_block)
9527 return node;
9529 children = isl_ast_node_block_get_children(node);
9530 child = isl_ast_node_list_get_at(children, 0);
9531 isl_ast_node_list_free(children);
9532 isl_ast_node_free(node);
9534 return child;
9537 /* Check that the before_each_for and after_each_for callbacks
9538 * are called for each for loop in the generated code,
9539 * that they are called in the right order and that the isl_id
9540 * returned from the before_each_for callback is attached to
9541 * the isl_ast_node passed to the corresponding after_each_for call.
9543 * Additionally, check the basic functionality of
9544 * isl_ast_node_foreach_descendant_top_down by counting the number
9545 * of for loops in the resulting AST,
9546 * as well as that of isl_ast_node_map_descendant_bottom_up
9547 * by replacing the block node by its first child and
9548 * counting the number of for loops again.
9550 static isl_stat test_ast_gen1(isl_ctx *ctx)
9552 int count = 0;
9553 int modified_count = 0;
9554 const char *str;
9555 isl_set *set;
9556 isl_union_map *schedule;
9557 isl_ast_build *build;
9558 isl_ast_node *tree;
9559 struct isl_test_codegen_data data;
9561 str = "[N] -> { : N >= 10 }";
9562 set = isl_set_read_from_str(ctx, str);
9563 str = "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
9564 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
9565 schedule = isl_union_map_read_from_str(ctx, str);
9567 data.before = 0;
9568 data.after = 0;
9569 data.depth = 0;
9570 build = isl_ast_build_from_context(set);
9571 build = isl_ast_build_set_before_each_for(build,
9572 &before_for, &data);
9573 build = isl_ast_build_set_after_each_for(build,
9574 &after_for, &data);
9575 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9576 isl_ast_build_free(build);
9578 if (isl_ast_node_foreach_descendant_top_down(tree,
9579 &count_for, &count) < 0)
9580 tree = isl_ast_node_free(tree);
9582 tree = isl_ast_node_map_descendant_bottom_up(tree, &select_first, NULL);
9584 if (isl_ast_node_foreach_descendant_top_down(tree, &count_for,
9585 &modified_count) < 0)
9586 tree = isl_ast_node_free(tree);
9588 if (!tree)
9589 return isl_stat_error;
9591 isl_ast_node_free(tree);
9593 if (data.before != 3 || data.after != 3 || count != 3)
9594 isl_die(ctx, isl_error_unknown,
9595 "unexpected number of for nodes",
9596 return isl_stat_error);
9598 if (modified_count != 2)
9599 isl_die(ctx, isl_error_unknown,
9600 "unexpected number of for nodes after changes",
9601 return isl_stat_error);
9603 return isl_stat_ok;
9606 /* Check that the AST generator handles domains that are integrally disjoint
9607 * but not rationally disjoint.
9609 static int test_ast_gen2(isl_ctx *ctx)
9611 const char *str;
9612 isl_set *set;
9613 isl_union_map *schedule;
9614 isl_union_map *options;
9615 isl_ast_build *build;
9616 isl_ast_node *tree;
9618 str = "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
9619 schedule = isl_union_map_read_from_str(ctx, str);
9620 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9621 build = isl_ast_build_from_context(set);
9623 str = "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
9624 options = isl_union_map_read_from_str(ctx, str);
9625 build = isl_ast_build_set_options(build, options);
9626 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9627 isl_ast_build_free(build);
9628 if (!tree)
9629 return -1;
9630 isl_ast_node_free(tree);
9632 return 0;
9635 /* Increment *user on each call.
9637 static __isl_give isl_ast_node *count_domains(__isl_take isl_ast_node *node,
9638 __isl_keep isl_ast_build *build, void *user)
9640 int *n = user;
9642 (*n)++;
9644 return node;
9647 /* Test that unrolling tries to minimize the number of instances.
9648 * In particular, for the schedule given below, make sure it generates
9649 * 3 nodes (rather than 101).
9651 static int test_ast_gen3(isl_ctx *ctx)
9653 const char *str;
9654 isl_set *set;
9655 isl_union_map *schedule;
9656 isl_union_map *options;
9657 isl_ast_build *build;
9658 isl_ast_node *tree;
9659 int n_domain = 0;
9661 str = "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
9662 schedule = isl_union_map_read_from_str(ctx, str);
9663 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9665 str = "{ [i] -> unroll[0] }";
9666 options = isl_union_map_read_from_str(ctx, str);
9668 build = isl_ast_build_from_context(set);
9669 build = isl_ast_build_set_options(build, options);
9670 build = isl_ast_build_set_at_each_domain(build,
9671 &count_domains, &n_domain);
9672 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9673 isl_ast_build_free(build);
9674 if (!tree)
9675 return -1;
9677 isl_ast_node_free(tree);
9679 if (n_domain != 3)
9680 isl_die(ctx, isl_error_unknown,
9681 "unexpected number of for nodes", return -1);
9683 return 0;
9686 /* Check that if the ast_build_exploit_nested_bounds options is set,
9687 * we do not get an outer if node in the generated AST,
9688 * while we do get such an outer if node if the options is not set.
9690 static int test_ast_gen4(isl_ctx *ctx)
9692 const char *str;
9693 isl_set *set;
9694 isl_union_map *schedule;
9695 isl_ast_build *build;
9696 isl_ast_node *tree;
9697 enum isl_ast_node_type type;
9698 int enb;
9700 enb = isl_options_get_ast_build_exploit_nested_bounds(ctx);
9701 str = "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
9703 isl_options_set_ast_build_exploit_nested_bounds(ctx, 1);
9705 schedule = isl_union_map_read_from_str(ctx, str);
9706 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9707 build = isl_ast_build_from_context(set);
9708 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9709 isl_ast_build_free(build);
9710 if (!tree)
9711 return -1;
9713 type = isl_ast_node_get_type(tree);
9714 isl_ast_node_free(tree);
9716 if (type == isl_ast_node_if)
9717 isl_die(ctx, isl_error_unknown,
9718 "not expecting if node", return -1);
9720 isl_options_set_ast_build_exploit_nested_bounds(ctx, 0);
9722 schedule = isl_union_map_read_from_str(ctx, str);
9723 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9724 build = isl_ast_build_from_context(set);
9725 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9726 isl_ast_build_free(build);
9727 if (!tree)
9728 return -1;
9730 type = isl_ast_node_get_type(tree);
9731 isl_ast_node_free(tree);
9733 if (type != isl_ast_node_if)
9734 isl_die(ctx, isl_error_unknown,
9735 "expecting if node", return -1);
9737 isl_options_set_ast_build_exploit_nested_bounds(ctx, enb);
9739 return 0;
9742 /* This function is called for each leaf in the AST generated
9743 * from test_ast_gen5.
9745 * We finalize the AST generation by extending the outer schedule
9746 * with a zero-dimensional schedule. If this results in any for loops,
9747 * then this means that we did not pass along enough information
9748 * about the outer schedule to the inner AST generation.
9750 static __isl_give isl_ast_node *create_leaf(__isl_take isl_ast_build *build,
9751 void *user)
9753 isl_union_map *schedule, *extra;
9754 isl_ast_node *tree;
9756 schedule = isl_ast_build_get_schedule(build);
9757 extra = isl_union_map_copy(schedule);
9758 extra = isl_union_map_from_domain(isl_union_map_domain(extra));
9759 schedule = isl_union_map_range_product(schedule, extra);
9760 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9761 isl_ast_build_free(build);
9763 if (!tree)
9764 return NULL;
9766 if (isl_ast_node_get_type(tree) == isl_ast_node_for)
9767 isl_die(isl_ast_node_get_ctx(tree), isl_error_unknown,
9768 "code should not contain any for loop",
9769 return isl_ast_node_free(tree));
9771 return tree;
9774 /* Check that we do not lose any information when going back and
9775 * forth between internal and external schedule.
9777 * In particular, we create an AST where we unroll the only
9778 * non-constant dimension in the schedule. We therefore do
9779 * not expect any for loops in the AST. However, older versions
9780 * of isl would not pass along enough information about the outer
9781 * schedule when performing an inner code generation from a create_leaf
9782 * callback, resulting in the inner code generation producing a for loop.
9784 static int test_ast_gen5(isl_ctx *ctx)
9786 const char *str;
9787 isl_set *set;
9788 isl_union_map *schedule, *options;
9789 isl_ast_build *build;
9790 isl_ast_node *tree;
9792 str = "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
9793 schedule = isl_union_map_read_from_str(ctx, str);
9795 str = "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
9796 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
9797 options = isl_union_map_read_from_str(ctx, str);
9799 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9800 build = isl_ast_build_from_context(set);
9801 build = isl_ast_build_set_options(build, options);
9802 build = isl_ast_build_set_create_leaf(build, &create_leaf, NULL);
9803 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9804 isl_ast_build_free(build);
9805 isl_ast_node_free(tree);
9806 if (!tree)
9807 return -1;
9809 return 0;
9812 /* Check that the expression
9814 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
9816 * is not combined into
9818 * min(n/2, 0)
9820 * as this would result in n/2 being evaluated in parts of
9821 * the definition domain where n is not a multiple of 2.
9823 static int test_ast_expr(isl_ctx *ctx)
9825 const char *str;
9826 isl_pw_aff *pa;
9827 isl_ast_build *build;
9828 isl_ast_expr *expr;
9829 int min_max;
9830 int is_min;
9832 min_max = isl_options_get_ast_build_detect_min_max(ctx);
9833 isl_options_set_ast_build_detect_min_max(ctx, 1);
9835 str = "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
9836 pa = isl_pw_aff_read_from_str(ctx, str);
9837 build = isl_ast_build_alloc(ctx);
9838 expr = isl_ast_build_expr_from_pw_aff(build, pa);
9839 is_min = isl_ast_expr_get_type(expr) == isl_ast_expr_op &&
9840 isl_ast_expr_get_op_type(expr) == isl_ast_expr_op_min;
9841 isl_ast_build_free(build);
9842 isl_ast_expr_free(expr);
9844 isl_options_set_ast_build_detect_min_max(ctx, min_max);
9846 if (!expr)
9847 return -1;
9848 if (is_min)
9849 isl_die(ctx, isl_error_unknown,
9850 "expressions should not be combined", return -1);
9852 return 0;
9855 static int test_ast_gen(isl_ctx *ctx)
9857 if (test_ast_gen1(ctx) < 0)
9858 return -1;
9859 if (test_ast_gen2(ctx) < 0)
9860 return -1;
9861 if (test_ast_gen3(ctx) < 0)
9862 return -1;
9863 if (test_ast_gen4(ctx) < 0)
9864 return -1;
9865 if (test_ast_gen5(ctx) < 0)
9866 return -1;
9867 if (test_ast_expr(ctx) < 0)
9868 return -1;
9869 return 0;
9872 /* Check if dropping output dimensions from an isl_pw_multi_aff
9873 * works properly.
9875 static int test_pw_multi_aff(isl_ctx *ctx)
9877 const char *str;
9878 isl_pw_multi_aff *pma1, *pma2;
9879 int equal;
9881 str = "{ [i,j] -> [i+j, 4i-j] }";
9882 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
9883 str = "{ [i,j] -> [4i-j] }";
9884 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
9886 pma1 = isl_pw_multi_aff_drop_dims(pma1, isl_dim_out, 0, 1);
9888 equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
9890 isl_pw_multi_aff_free(pma1);
9891 isl_pw_multi_aff_free(pma2);
9892 if (equal < 0)
9893 return -1;
9894 if (!equal)
9895 isl_die(ctx, isl_error_unknown,
9896 "expressions not equal", return -1);
9898 return 0;
9901 /* Check that we can properly parse multi piecewise affine expressions
9902 * where the piecewise affine expressions have different domains.
9904 static int test_multi_pw_aff_1(isl_ctx *ctx)
9906 const char *str;
9907 isl_set *dom, *dom2;
9908 isl_multi_pw_aff *mpa1, *mpa2;
9909 isl_pw_aff *pa;
9910 int equal;
9911 int equal_domain;
9913 mpa1 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [i] }");
9914 dom = isl_set_read_from_str(ctx, "{ [i] : i > 0 }");
9915 mpa1 = isl_multi_pw_aff_intersect_domain(mpa1, dom);
9916 mpa2 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [2i] }");
9917 mpa2 = isl_multi_pw_aff_flat_range_product(mpa1, mpa2);
9918 str = "{ [i] -> [(i : i > 0), 2i] }";
9919 mpa1 = isl_multi_pw_aff_read_from_str(ctx, str);
9921 equal = isl_multi_pw_aff_plain_is_equal(mpa1, mpa2);
9923 pa = isl_multi_pw_aff_get_pw_aff(mpa1, 0);
9924 dom = isl_pw_aff_domain(pa);
9925 pa = isl_multi_pw_aff_get_pw_aff(mpa1, 1);
9926 dom2 = isl_pw_aff_domain(pa);
9927 equal_domain = isl_set_is_equal(dom, dom2);
9929 isl_set_free(dom);
9930 isl_set_free(dom2);
9931 isl_multi_pw_aff_free(mpa1);
9932 isl_multi_pw_aff_free(mpa2);
9934 if (equal < 0)
9935 return -1;
9936 if (!equal)
9937 isl_die(ctx, isl_error_unknown,
9938 "expressions not equal", return -1);
9940 if (equal_domain < 0)
9941 return -1;
9942 if (equal_domain)
9943 isl_die(ctx, isl_error_unknown,
9944 "domains unexpectedly equal", return -1);
9946 return 0;
9949 /* Check that the dimensions in the explicit domain
9950 * of a multi piecewise affine expression are properly
9951 * taken into account.
9953 static int test_multi_pw_aff_2(isl_ctx *ctx)
9955 const char *str;
9956 isl_bool involves1, involves2, involves3, equal;
9957 isl_multi_pw_aff *mpa, *mpa1, *mpa2;
9959 str = "{ A[x,y] -> B[] : x >= y }";
9960 mpa = isl_multi_pw_aff_read_from_str(ctx, str);
9961 involves1 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 2);
9962 mpa1 = isl_multi_pw_aff_copy(mpa);
9964 mpa = isl_multi_pw_aff_insert_dims(mpa, isl_dim_in, 0, 1);
9965 involves2 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 1);
9966 involves3 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 1, 2);
9967 str = "{ [a,x,y] -> B[] : x >= y }";
9968 mpa2 = isl_multi_pw_aff_read_from_str(ctx, str);
9969 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2);
9970 isl_multi_pw_aff_free(mpa2);
9972 mpa = isl_multi_pw_aff_drop_dims(mpa, isl_dim_in, 0, 1);
9973 mpa = isl_multi_pw_aff_set_tuple_name(mpa, isl_dim_in, "A");
9974 if (equal >= 0 && equal)
9975 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa1);
9976 isl_multi_pw_aff_free(mpa1);
9977 isl_multi_pw_aff_free(mpa);
9979 if (involves1 < 0 || involves2 < 0 || involves3 < 0 || equal < 0)
9980 return -1;
9981 if (!equal)
9982 isl_die(ctx, isl_error_unknown,
9983 "incorrect result of dimension insertion/removal",
9984 return isl_stat_error);
9985 if (!involves1 || involves2 || !involves3)
9986 isl_die(ctx, isl_error_unknown,
9987 "incorrect characterization of involved dimensions",
9988 return isl_stat_error);
9990 return 0;
9993 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
9994 * sets the explicit domain of a zero-dimensional result,
9995 * such that it can be converted to an isl_union_map.
9997 static isl_stat test_multi_pw_aff_3(isl_ctx *ctx)
9999 isl_space *space;
10000 isl_union_set *dom;
10001 isl_multi_val *mv;
10002 isl_multi_union_pw_aff *mupa;
10003 isl_union_map *umap;
10005 dom = isl_union_set_read_from_str(ctx, "{ A[]; B[] }");
10006 space = isl_union_set_get_space(dom);
10007 mv = isl_multi_val_zero(isl_space_set_from_params(space));
10008 mupa = isl_multi_union_pw_aff_multi_val_on_domain(dom, mv);
10009 umap = isl_union_map_from_multi_union_pw_aff(mupa);
10010 isl_union_map_free(umap);
10011 if (!umap)
10012 return isl_stat_error;
10014 return isl_stat_ok;
10017 /* String descriptions of boxes that
10018 * are used for reconstructing box maps from their lower and upper bounds.
10020 static const char *multi_pw_aff_box_tests[] = {
10021 "{ A[x, y] -> [] : x + y >= 0 }",
10022 "[N] -> { A[x, y] -> [x] : x + y <= N }",
10023 "[N] -> { A[x, y] -> [x : y] : x + y <= N }",
10026 /* Check that map representations of boxes can be reconstructed
10027 * from their lower and upper bounds.
10029 static isl_stat test_multi_pw_aff_box(isl_ctx *ctx)
10031 int i;
10033 for (i = 0; i < ARRAY_SIZE(multi_pw_aff_box_tests); ++i) {
10034 const char *str;
10035 isl_bool equal;
10036 isl_map *map, *box;
10037 isl_multi_pw_aff *min, *max;
10039 str = multi_pw_aff_box_tests[i];
10040 map = isl_map_read_from_str(ctx, str);
10041 min = isl_map_min_multi_pw_aff(isl_map_copy(map));
10042 max = isl_map_max_multi_pw_aff(isl_map_copy(map));
10043 box = isl_map_universe(isl_map_get_space(map));
10044 box = isl_map_lower_bound_multi_pw_aff(box, min);
10045 box = isl_map_upper_bound_multi_pw_aff(box, max);
10046 equal = isl_map_is_equal(map, box);
10047 isl_map_free(map);
10048 isl_map_free(box);
10049 if (equal < 0)
10050 return isl_stat_error;
10051 if (!equal)
10052 isl_die(ctx, isl_error_unknown,
10053 "unexpected result", return isl_stat_error);
10056 return isl_stat_ok;
10059 /* Perform some tests on multi piecewise affine expressions.
10061 static int test_multi_pw_aff(isl_ctx *ctx)
10063 if (test_multi_pw_aff_1(ctx) < 0)
10064 return -1;
10065 if (test_multi_pw_aff_2(ctx) < 0)
10066 return -1;
10067 if (test_multi_pw_aff_3(ctx) < 0)
10068 return -1;
10069 if (test_multi_pw_aff_box(ctx) < 0)
10070 return -1;
10071 return 0;
10074 /* This is a regression test for a bug where isl_basic_map_simplify
10075 * would end up in an infinite loop. In particular, we construct
10076 * an empty basic set that is not obviously empty.
10077 * isl_basic_set_is_empty marks the basic set as empty.
10078 * After projecting out i3, the variable can be dropped completely,
10079 * but isl_basic_map_simplify refrains from doing so if the basic set
10080 * is empty and would end up in an infinite loop if it didn't test
10081 * explicitly for empty basic maps in the outer loop.
10083 static int test_simplify_1(isl_ctx *ctx)
10085 const char *str;
10086 isl_basic_set *bset;
10087 int empty;
10089 str = "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
10090 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
10091 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
10092 "i3 >= i2 }";
10093 bset = isl_basic_set_read_from_str(ctx, str);
10094 empty = isl_basic_set_is_empty(bset);
10095 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
10096 isl_basic_set_free(bset);
10097 if (!bset)
10098 return -1;
10099 if (!empty)
10100 isl_die(ctx, isl_error_unknown,
10101 "basic set should be empty", return -1);
10103 return 0;
10106 /* Check that the equality in the set description below
10107 * is simplified away.
10109 static int test_simplify_2(isl_ctx *ctx)
10111 const char *str;
10112 isl_basic_set *bset;
10113 isl_bool universe;
10115 str = "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
10116 bset = isl_basic_set_read_from_str(ctx, str);
10117 universe = isl_basic_set_plain_is_universe(bset);
10118 isl_basic_set_free(bset);
10120 if (universe < 0)
10121 return -1;
10122 if (!universe)
10123 isl_die(ctx, isl_error_unknown,
10124 "equality not simplified away", return -1);
10125 return 0;
10128 /* Some simplification tests.
10130 static int test_simplify(isl_ctx *ctx)
10132 if (test_simplify_1(ctx) < 0)
10133 return -1;
10134 if (test_simplify_2(ctx) < 0)
10135 return -1;
10136 return 0;
10139 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
10140 * with gbr context would fail to disable the use of the shifted tableau
10141 * when transferring equalities for the input to the context, resulting
10142 * in invalid sample values.
10144 static int test_partial_lexmin(isl_ctx *ctx)
10146 const char *str;
10147 isl_basic_set *bset;
10148 isl_basic_map *bmap;
10149 isl_map *map;
10151 str = "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
10152 bmap = isl_basic_map_read_from_str(ctx, str);
10153 str = "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
10154 bset = isl_basic_set_read_from_str(ctx, str);
10155 map = isl_basic_map_partial_lexmin(bmap, bset, NULL);
10156 isl_map_free(map);
10158 if (!map)
10159 return -1;
10161 return 0;
10164 /* Check that the variable compression performed on the existentially
10165 * quantified variables inside isl_basic_set_compute_divs is not confused
10166 * by the implicit equalities among the parameters.
10168 static int test_compute_divs(isl_ctx *ctx)
10170 const char *str;
10171 isl_basic_set *bset;
10172 isl_set *set;
10174 str = "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
10175 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
10176 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
10177 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
10178 bset = isl_basic_set_read_from_str(ctx, str);
10179 set = isl_basic_set_compute_divs(bset);
10180 isl_set_free(set);
10181 if (!set)
10182 return -1;
10184 return 0;
10187 /* Check that isl_schedule_get_map is not confused by a schedule tree
10188 * with divergent filter node parameters, as can result from a call
10189 * to isl_schedule_intersect_domain.
10191 static int test_schedule_tree(isl_ctx *ctx)
10193 const char *str;
10194 isl_union_set *uset;
10195 isl_schedule *sched1, *sched2;
10196 isl_union_map *umap;
10198 uset = isl_union_set_read_from_str(ctx, "{ A[i] }");
10199 sched1 = isl_schedule_from_domain(uset);
10200 uset = isl_union_set_read_from_str(ctx, "{ B[] }");
10201 sched2 = isl_schedule_from_domain(uset);
10203 sched1 = isl_schedule_sequence(sched1, sched2);
10204 str = "[n] -> { A[i] : 0 <= i < n; B[] }";
10205 uset = isl_union_set_read_from_str(ctx, str);
10206 sched1 = isl_schedule_intersect_domain(sched1, uset);
10207 umap = isl_schedule_get_map(sched1);
10208 isl_schedule_free(sched1);
10209 isl_union_map_free(umap);
10210 if (!umap)
10211 return -1;
10213 return 0;
10216 /* Check that a zero-dimensional prefix schedule keeps track
10217 * of the domain and outer filters.
10219 static int test_schedule_tree_prefix(isl_ctx *ctx)
10221 const char *str;
10222 isl_bool equal;
10223 isl_union_set *uset;
10224 isl_union_set_list *filters;
10225 isl_multi_union_pw_aff *mupa, *mupa2;
10226 isl_schedule_node *node;
10228 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10229 uset = isl_union_set_read_from_str(ctx, str);
10230 node = isl_schedule_node_from_domain(uset);
10231 node = isl_schedule_node_child(node, 0);
10233 str = "{ S1[i,j] : i > j }";
10234 uset = isl_union_set_read_from_str(ctx, str);
10235 filters = isl_union_set_list_from_union_set(uset);
10236 str = "{ S1[i,j] : i <= j; S2[i,j] }";
10237 uset = isl_union_set_read_from_str(ctx, str);
10238 filters = isl_union_set_list_add(filters, uset);
10239 node = isl_schedule_node_insert_sequence(node, filters);
10241 node = isl_schedule_node_grandchild(node, 0, 0);
10242 mupa = isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node);
10243 str = "([] : { S1[i,j] : i > j })";
10244 mupa2 = isl_multi_union_pw_aff_read_from_str(ctx, str);
10245 equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2);
10246 isl_multi_union_pw_aff_free(mupa2);
10247 isl_multi_union_pw_aff_free(mupa);
10248 isl_schedule_node_free(node);
10250 if (equal < 0)
10251 return -1;
10252 if (!equal)
10253 isl_die(ctx, isl_error_unknown, "unexpected prefix schedule",
10254 return -1);
10256 return 0;
10259 /* Check that the reaching domain elements and the prefix schedule
10260 * at a leaf node are the same before and after grouping.
10262 static int test_schedule_tree_group_1(isl_ctx *ctx)
10264 int equal;
10265 const char *str;
10266 isl_id *id;
10267 isl_union_set *uset;
10268 isl_multi_union_pw_aff *mupa;
10269 isl_union_pw_multi_aff *upma1, *upma2;
10270 isl_union_set *domain1, *domain2;
10271 isl_union_map *umap1, *umap2;
10272 isl_schedule_node *node;
10274 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10275 uset = isl_union_set_read_from_str(ctx, str);
10276 node = isl_schedule_node_from_domain(uset);
10277 node = isl_schedule_node_child(node, 0);
10278 str = "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
10279 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10280 node = isl_schedule_node_insert_partial_schedule(node, mupa);
10281 node = isl_schedule_node_child(node, 0);
10282 str = "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
10283 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10284 node = isl_schedule_node_insert_partial_schedule(node, mupa);
10285 node = isl_schedule_node_child(node, 0);
10286 umap1 = isl_schedule_node_get_prefix_schedule_union_map(node);
10287 upma1 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node);
10288 domain1 = isl_schedule_node_get_domain(node);
10289 id = isl_id_alloc(ctx, "group", NULL);
10290 node = isl_schedule_node_parent(node);
10291 node = isl_schedule_node_group(node, id);
10292 node = isl_schedule_node_child(node, 0);
10293 umap2 = isl_schedule_node_get_prefix_schedule_union_map(node);
10294 upma2 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node);
10295 domain2 = isl_schedule_node_get_domain(node);
10296 equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2);
10297 if (equal >= 0 && equal)
10298 equal = isl_union_set_is_equal(domain1, domain2);
10299 if (equal >= 0 && equal)
10300 equal = isl_union_map_is_equal(umap1, umap2);
10301 isl_union_map_free(umap1);
10302 isl_union_map_free(umap2);
10303 isl_union_set_free(domain1);
10304 isl_union_set_free(domain2);
10305 isl_union_pw_multi_aff_free(upma1);
10306 isl_union_pw_multi_aff_free(upma2);
10307 isl_schedule_node_free(node);
10309 if (equal < 0)
10310 return -1;
10311 if (!equal)
10312 isl_die(ctx, isl_error_unknown,
10313 "expressions not equal", return -1);
10315 return 0;
10318 /* Check that we can have nested groupings and that the union map
10319 * schedule representation is the same before and after the grouping.
10320 * Note that after the grouping, the union map representation contains
10321 * the domain constraints from the ranges of the expansion nodes,
10322 * while they are missing from the union map representation of
10323 * the tree without expansion nodes.
10325 * Also check that the global expansion is as expected.
10327 static int test_schedule_tree_group_2(isl_ctx *ctx)
10329 int equal, equal_expansion;
10330 const char *str;
10331 isl_id *id;
10332 isl_union_set *uset;
10333 isl_union_map *umap1, *umap2;
10334 isl_union_map *expansion1, *expansion2;
10335 isl_union_set_list *filters;
10336 isl_multi_union_pw_aff *mupa;
10337 isl_schedule *schedule;
10338 isl_schedule_node *node;
10340 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
10341 "S3[i,j] : 0 <= i,j < 10 }";
10342 uset = isl_union_set_read_from_str(ctx, str);
10343 node = isl_schedule_node_from_domain(uset);
10344 node = isl_schedule_node_child(node, 0);
10345 str = "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
10346 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10347 node = isl_schedule_node_insert_partial_schedule(node, mupa);
10348 node = isl_schedule_node_child(node, 0);
10349 str = "{ S1[i,j] }";
10350 uset = isl_union_set_read_from_str(ctx, str);
10351 filters = isl_union_set_list_from_union_set(uset);
10352 str = "{ S2[i,j]; S3[i,j] }";
10353 uset = isl_union_set_read_from_str(ctx, str);
10354 filters = isl_union_set_list_add(filters, uset);
10355 node = isl_schedule_node_insert_sequence(node, filters);
10356 node = isl_schedule_node_grandchild(node, 1, 0);
10357 str = "{ S2[i,j] }";
10358 uset = isl_union_set_read_from_str(ctx, str);
10359 filters = isl_union_set_list_from_union_set(uset);
10360 str = "{ S3[i,j] }";
10361 uset = isl_union_set_read_from_str(ctx, str);
10362 filters = isl_union_set_list_add(filters, uset);
10363 node = isl_schedule_node_insert_sequence(node, filters);
10365 schedule = isl_schedule_node_get_schedule(node);
10366 umap1 = isl_schedule_get_map(schedule);
10367 uset = isl_schedule_get_domain(schedule);
10368 umap1 = isl_union_map_intersect_domain(umap1, uset);
10369 isl_schedule_free(schedule);
10371 node = isl_schedule_node_grandparent(node);
10372 id = isl_id_alloc(ctx, "group1", NULL);
10373 node = isl_schedule_node_group(node, id);
10374 node = isl_schedule_node_grandchild(node, 1, 0);
10375 id = isl_id_alloc(ctx, "group2", NULL);
10376 node = isl_schedule_node_group(node, id);
10378 schedule = isl_schedule_node_get_schedule(node);
10379 umap2 = isl_schedule_get_map(schedule);
10380 isl_schedule_free(schedule);
10382 node = isl_schedule_node_root(node);
10383 node = isl_schedule_node_child(node, 0);
10384 expansion1 = isl_schedule_node_get_subtree_expansion(node);
10385 isl_schedule_node_free(node);
10387 str = "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
10388 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
10389 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
10391 expansion2 = isl_union_map_read_from_str(ctx, str);
10393 equal = isl_union_map_is_equal(umap1, umap2);
10394 equal_expansion = isl_union_map_is_equal(expansion1, expansion2);
10396 isl_union_map_free(umap1);
10397 isl_union_map_free(umap2);
10398 isl_union_map_free(expansion1);
10399 isl_union_map_free(expansion2);
10401 if (equal < 0 || equal_expansion < 0)
10402 return -1;
10403 if (!equal)
10404 isl_die(ctx, isl_error_unknown,
10405 "expressions not equal", return -1);
10406 if (!equal_expansion)
10407 isl_die(ctx, isl_error_unknown,
10408 "unexpected expansion", return -1);
10410 return 0;
10413 /* Some tests for the isl_schedule_node_group function.
10415 static int test_schedule_tree_group(isl_ctx *ctx)
10417 if (test_schedule_tree_group_1(ctx) < 0)
10418 return -1;
10419 if (test_schedule_tree_group_2(ctx) < 0)
10420 return -1;
10421 return 0;
10424 struct {
10425 const char *set;
10426 const char *dual;
10427 } coef_tests[] = {
10428 { "{ rat: [i] : 0 <= i <= 10 }",
10429 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
10430 { "{ rat: [i] : FALSE }",
10431 "{ rat: coefficients[[cst] -> [a]] }" },
10432 { "{ rat: [i] : }",
10433 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
10434 { "{ [0:,1,2:3] }",
10435 "{ rat: coefficients[[c_cst] -> [a, b, c]] : "
10436 "a >= 0 and 2c >= -c_cst - b and 3c >= -c_cst - b }" },
10437 { "[M, N] -> { [x = (1 - N):-1, -4x:(M - 4x)] }",
10438 "{ rat: coefficients[[c_cst, c_M = 0:, c_N = 0:] -> [a, b = -c_M:]] :"
10439 "4b >= -c_N + a and 4b >= -c_cst - 2c_N + a }" },
10440 { "{ rat : [x, y] : 1 <= 2x <= 9 and 2 <= 3y <= 16 }",
10441 "{ rat: coefficients[[c_cst] -> [c_x, c_y]] : "
10442 "4c_y >= -6c_cst - 3c_x and 4c_y >= -6c_cst - 27c_x and "
10443 "32c_y >= -6c_cst - 3c_x and 32c_y >= -6c_cst - 27c_x }" },
10444 { "{ [x, y, z] : 3y <= 2x - 2 and y >= -2 + 2x and 2y >= 2 - x }",
10445 "{ rat: coefficients[[cst] -> [a, b, c]] }" },
10448 struct {
10449 const char *set;
10450 const char *dual;
10451 } sol_tests[] = {
10452 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
10453 "{ rat: [i] : 0 <= i <= 10 }" },
10454 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
10455 "{ rat: [i] }" },
10456 { "{ rat: coefficients[[cst] -> [a]] }",
10457 "{ rat: [i] : FALSE }" },
10460 /* Test the basic functionality of isl_basic_set_coefficients and
10461 * isl_basic_set_solutions.
10463 static int test_dual(isl_ctx *ctx)
10465 int i;
10467 for (i = 0; i < ARRAY_SIZE(coef_tests); ++i) {
10468 int equal;
10469 isl_basic_set *bset1, *bset2;
10471 bset1 = isl_basic_set_read_from_str(ctx, coef_tests[i].set);
10472 bset2 = isl_basic_set_read_from_str(ctx, coef_tests[i].dual);
10473 bset1 = isl_basic_set_coefficients(bset1);
10474 equal = isl_basic_set_is_equal(bset1, bset2);
10475 isl_basic_set_free(bset1);
10476 isl_basic_set_free(bset2);
10477 if (equal < 0)
10478 return -1;
10479 if (!equal)
10480 isl_die(ctx, isl_error_unknown,
10481 "incorrect dual", return -1);
10484 for (i = 0; i < ARRAY_SIZE(sol_tests); ++i) {
10485 int equal;
10486 isl_basic_set *bset1, *bset2;
10488 bset1 = isl_basic_set_read_from_str(ctx, sol_tests[i].set);
10489 bset2 = isl_basic_set_read_from_str(ctx, sol_tests[i].dual);
10490 bset1 = isl_basic_set_solutions(bset1);
10491 equal = isl_basic_set_is_equal(bset1, bset2);
10492 isl_basic_set_free(bset1);
10493 isl_basic_set_free(bset2);
10494 if (equal < 0)
10495 return -1;
10496 if (!equal)
10497 isl_die(ctx, isl_error_unknown,
10498 "incorrect dual", return -1);
10501 return 0;
10504 struct {
10505 int scale_tile;
10506 int shift_point;
10507 const char *domain;
10508 const char *schedule;
10509 const char *sizes;
10510 const char *tile;
10511 const char *point;
10512 } tile_tests[] = {
10513 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10514 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10515 "{ [32,32] }",
10516 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10517 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10519 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10520 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10521 "{ [32,32] }",
10522 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10523 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10525 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10526 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10527 "{ [32,32] }",
10528 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10529 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10531 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10532 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10533 "{ [32,32] }",
10534 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10535 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10539 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
10540 * tile the band and then check if the tile and point bands have the
10541 * expected partial schedule.
10543 static int test_tile(isl_ctx *ctx)
10545 int i;
10546 int scale;
10547 int shift;
10549 scale = isl_options_get_tile_scale_tile_loops(ctx);
10550 shift = isl_options_get_tile_shift_point_loops(ctx);
10552 for (i = 0; i < ARRAY_SIZE(tile_tests); ++i) {
10553 int opt;
10554 int equal;
10555 const char *str;
10556 isl_union_set *domain;
10557 isl_multi_union_pw_aff *mupa, *mupa2;
10558 isl_schedule_node *node;
10559 isl_multi_val *sizes;
10561 opt = tile_tests[i].scale_tile;
10562 isl_options_set_tile_scale_tile_loops(ctx, opt);
10563 opt = tile_tests[i].shift_point;
10564 isl_options_set_tile_shift_point_loops(ctx, opt);
10566 str = tile_tests[i].domain;
10567 domain = isl_union_set_read_from_str(ctx, str);
10568 node = isl_schedule_node_from_domain(domain);
10569 node = isl_schedule_node_child(node, 0);
10570 str = tile_tests[i].schedule;
10571 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10572 node = isl_schedule_node_insert_partial_schedule(node, mupa);
10573 str = tile_tests[i].sizes;
10574 sizes = isl_multi_val_read_from_str(ctx, str);
10575 node = isl_schedule_node_band_tile(node, sizes);
10577 str = tile_tests[i].tile;
10578 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10579 mupa2 = isl_schedule_node_band_get_partial_schedule(node);
10580 equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2);
10581 isl_multi_union_pw_aff_free(mupa);
10582 isl_multi_union_pw_aff_free(mupa2);
10584 node = isl_schedule_node_child(node, 0);
10586 str = tile_tests[i].point;
10587 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10588 mupa2 = isl_schedule_node_band_get_partial_schedule(node);
10589 if (equal >= 0 && equal)
10590 equal = isl_multi_union_pw_aff_plain_is_equal(mupa,
10591 mupa2);
10592 isl_multi_union_pw_aff_free(mupa);
10593 isl_multi_union_pw_aff_free(mupa2);
10595 isl_schedule_node_free(node);
10597 if (equal < 0)
10598 return -1;
10599 if (!equal)
10600 isl_die(ctx, isl_error_unknown,
10601 "unexpected result", return -1);
10604 isl_options_set_tile_scale_tile_loops(ctx, scale);
10605 isl_options_set_tile_shift_point_loops(ctx, shift);
10607 return 0;
10610 /* Check that the domain hash of a space is equal to the hash
10611 * of the domain of the space, both ignoring parameters.
10613 static int test_domain_hash(isl_ctx *ctx)
10615 isl_map *map;
10616 isl_space *space;
10617 uint32_t hash1, hash2;
10619 map = isl_map_read_from_str(ctx, "[n] -> { A[B[x] -> C[]] -> D[] }");
10620 space = isl_map_get_space(map);
10621 isl_map_free(map);
10622 hash1 = isl_space_get_tuple_domain_hash(space);
10623 space = isl_space_domain(space);
10624 hash2 = isl_space_get_tuple_hash(space);
10625 isl_space_free(space);
10627 if (!space)
10628 return -1;
10629 if (hash1 != hash2)
10630 isl_die(ctx, isl_error_unknown,
10631 "domain hash not equal to hash of domain", return -1);
10633 return 0;
10636 /* Check that a universe basic set that is not obviously equal to the universe
10637 * is still recognized as being equal to the universe.
10639 static int test_universe(isl_ctx *ctx)
10641 const char *s;
10642 isl_basic_set *bset;
10643 isl_bool is_univ;
10645 s = "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
10646 bset = isl_basic_set_read_from_str(ctx, s);
10647 is_univ = isl_basic_set_is_universe(bset);
10648 isl_basic_set_free(bset);
10650 if (is_univ < 0)
10651 return -1;
10652 if (!is_univ)
10653 isl_die(ctx, isl_error_unknown,
10654 "not recognized as universe set", return -1);
10656 return 0;
10659 /* Sets for which chambers are computed and checked.
10661 const char *chambers_tests[] = {
10662 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
10663 "z >= 0 and z <= C - y and z <= B - x - y }",
10666 /* Add the domain of "cell" to "cells".
10668 static isl_stat add_cell(__isl_take isl_cell *cell, void *user)
10670 isl_basic_set_list **cells = user;
10671 isl_basic_set *dom;
10673 dom = isl_cell_get_domain(cell);
10674 isl_cell_free(cell);
10675 *cells = isl_basic_set_list_add(*cells, dom);
10677 return *cells ? isl_stat_ok : isl_stat_error;
10680 /* Check that the elements of "list" are pairwise disjoint.
10682 static isl_stat check_pairwise_disjoint(__isl_keep isl_basic_set_list *list)
10684 int i, j;
10685 isl_size n;
10687 n = isl_basic_set_list_n_basic_set(list);
10688 if (n < 0)
10689 return isl_stat_error;
10691 for (i = 0; i < n; ++i) {
10692 isl_basic_set *bset_i;
10694 bset_i = isl_basic_set_list_get_basic_set(list, i);
10695 for (j = i + 1; j < n; ++j) {
10696 isl_basic_set *bset_j;
10697 isl_bool disjoint;
10699 bset_j = isl_basic_set_list_get_basic_set(list, j);
10700 disjoint = isl_basic_set_is_disjoint(bset_i, bset_j);
10701 isl_basic_set_free(bset_j);
10702 if (!disjoint)
10703 isl_die(isl_basic_set_list_get_ctx(list),
10704 isl_error_unknown, "not disjoint",
10705 break);
10706 if (disjoint < 0 || !disjoint)
10707 break;
10709 isl_basic_set_free(bset_i);
10710 if (j < n)
10711 return isl_stat_error;
10714 return isl_stat_ok;
10717 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
10718 * are pairwise disjoint.
10720 static int test_chambers(isl_ctx *ctx)
10722 int i;
10724 for (i = 0; i < ARRAY_SIZE(chambers_tests); ++i) {
10725 isl_basic_set *bset;
10726 isl_vertices *vertices;
10727 isl_basic_set_list *cells;
10728 isl_stat ok;
10730 bset = isl_basic_set_read_from_str(ctx, chambers_tests[i]);
10731 vertices = isl_basic_set_compute_vertices(bset);
10732 cells = isl_basic_set_list_alloc(ctx, 0);
10733 if (isl_vertices_foreach_disjoint_cell(vertices, &add_cell,
10734 &cells) < 0)
10735 cells = isl_basic_set_list_free(cells);
10736 ok = check_pairwise_disjoint(cells);
10737 isl_basic_set_list_free(cells);
10738 isl_vertices_free(vertices);
10739 isl_basic_set_free(bset);
10741 if (ok < 0)
10742 return -1;
10745 return 0;
10748 struct {
10749 const char *name;
10750 int (*fn)(isl_ctx *ctx);
10751 } tests [] = {
10752 { "universe", &test_universe },
10753 { "domain hash", &test_domain_hash },
10754 { "dual", &test_dual },
10755 { "dependence analysis", &test_flow },
10756 { "val", &test_val },
10757 { "compute divs", &test_compute_divs },
10758 { "partial lexmin", &test_partial_lexmin },
10759 { "simplify", &test_simplify },
10760 { "curry", &test_curry },
10761 { "piecewise multi affine expressions", &test_pw_multi_aff },
10762 { "multi piecewise affine expressions", &test_multi_pw_aff },
10763 { "conversion", &test_conversion },
10764 { "list", &test_list },
10765 { "align parameters", &test_align_parameters },
10766 { "drop unused parameters", &test_drop_unused_parameters },
10767 { "pullback", &test_pullback },
10768 { "AST", &test_ast },
10769 { "AST build", &test_ast_build },
10770 { "AST generation", &test_ast_gen },
10771 { "eliminate", &test_eliminate },
10772 { "deltas_map", &test_deltas_map },
10773 { "residue class", &test_residue_class },
10774 { "div", &test_div },
10775 { "slice", &test_slice },
10776 { "sample", &test_sample },
10777 { "empty projection", &test_empty_projection },
10778 { "output", &test_output },
10779 { "vertices", &test_vertices },
10780 { "chambers", &test_chambers },
10781 { "fixed", &test_fixed },
10782 { "equal", &test_equal },
10783 { "disjoint", &test_disjoint },
10784 { "product", &test_product },
10785 { "dim_max", &test_dim_max },
10786 { "affine", &test_aff },
10787 { "injective", &test_injective },
10788 { "schedule (whole component)", &test_schedule_whole },
10789 { "schedule (incremental)", &test_schedule_incremental },
10790 { "schedule tree", &test_schedule_tree },
10791 { "schedule tree prefix", &test_schedule_tree_prefix },
10792 { "schedule tree grouping", &test_schedule_tree_group },
10793 { "tile", &test_tile },
10794 { "union map", &test_union_map },
10795 { "union_pw", &test_union_pw },
10796 { "locus", &test_locus },
10797 { "eval", &test_eval },
10798 { "parse", &test_parse },
10799 { "single-valued", &test_sv },
10800 { "recession cone", &test_recession_cone },
10801 { "affine hull", &test_affine_hull },
10802 { "simple_hull", &test_simple_hull },
10803 { "box hull", &test_box_hull },
10804 { "coalesce", &test_coalesce },
10805 { "factorize", &test_factorize },
10806 { "subset", &test_subset },
10807 { "subtract", &test_subtract },
10808 { "intersect", &test_intersect },
10809 { "lexmin", &test_lexmin },
10810 { "min", &test_min },
10811 { "set lower bounds", &test_min_mpa },
10812 { "gist", &test_gist },
10813 { "piecewise quasi-polynomials", &test_pwqp },
10814 { "lift", &test_lift },
10815 { "bind parameters", &test_bind },
10816 { "unbind parameters", &test_unbind },
10817 { "bound", &test_bound },
10818 { "get lists", &test_get_list },
10819 { "union", &test_union },
10820 { "split periods", &test_split_periods },
10821 { "lexicographic order", &test_lex },
10822 { "bijectivity", &test_bijective },
10823 { "dataflow analysis", &test_dep },
10824 { "reading", &test_read },
10825 { "bounded", &test_bounded },
10826 { "construction", &test_construction },
10827 { "dimension manipulation", &test_dim },
10828 { "map application", &test_application },
10829 { "convex hull", &test_convex_hull },
10830 { "transitive closure", &test_closure },
10831 { "isl_bool", &test_isl_bool},
10834 int main(int argc, char **argv)
10836 int i;
10837 struct isl_ctx *ctx;
10838 struct isl_options *options;
10840 options = isl_options_new_with_defaults();
10841 assert(options);
10842 argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL);
10844 ctx = isl_ctx_alloc_with_options(&isl_options_args, options);
10845 for (i = 0; i < ARRAY_SIZE(tests); ++i) {
10846 printf("%s\n", tests[i].name);
10847 if (tests[i].fn(ctx) < 0)
10848 goto error;
10850 isl_ctx_free(ctx);
10851 return 0;
10852 error:
10853 isl_ctx_free(ctx);
10854 return -1;