Merge branch 'maint'
[isl.git] / isl_test.c
blobd609442c213f12aa7e86c5113bf9aafb8b48cab2
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
7 * Use of this software is governed by the MIT license
9 * Written by Sven Verdoolaege, K.U.Leuven, Departement
10 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
11 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
12 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
14 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
15 * B.P. 105 - 78153 Le Chesnay, France
18 #include <assert.h>
19 #include <stdio.h>
20 #include <limits.h>
21 #include <isl_ctx_private.h>
22 #include <isl_map_private.h>
23 #include <isl_aff_private.h>
24 #include <isl_space_private.h>
25 #include <isl/id.h>
26 #include <isl/set.h>
27 #include <isl/flow.h>
28 #include <isl_constraint_private.h>
29 #include <isl/polynomial.h>
30 #include <isl/union_set.h>
31 #include <isl/union_map.h>
32 #include <isl_factorization.h>
33 #include <isl/schedule.h>
34 #include <isl/schedule_node.h>
35 #include <isl_options_private.h>
36 #include <isl_vertices_private.h>
37 #include <isl/ast_build.h>
38 #include <isl/val.h>
39 #include <isl/ilp.h>
40 #include <isl_ast_build_expr.h>
41 #include <isl/options.h>
43 #include "isl_srcdir.c"
45 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
47 static char *get_filename(isl_ctx *ctx, const char *name, const char *suffix) {
48 char *filename;
49 int length;
50 char *pattern = "%s/test_inputs/%s.%s";
52 length = strlen(pattern) - 6 + strlen(srcdir) + strlen(name)
53 + strlen(suffix) + 1;
54 filename = isl_alloc_array(ctx, char, length);
56 if (!filename)
57 return NULL;
59 sprintf(filename, pattern, srcdir, name, suffix);
61 return filename;
64 void test_parse_map(isl_ctx *ctx, const char *str)
66 isl_map *map;
68 map = isl_map_read_from_str(ctx, str);
69 assert(map);
70 isl_map_free(map);
73 int test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
75 isl_map *map, *map2;
76 int equal;
78 map = isl_map_read_from_str(ctx, str);
79 map2 = isl_map_read_from_str(ctx, str2);
80 equal = isl_map_is_equal(map, map2);
81 isl_map_free(map);
82 isl_map_free(map2);
84 if (equal < 0)
85 return -1;
86 if (!equal)
87 isl_die(ctx, isl_error_unknown, "maps not equal",
88 return -1);
90 return 0;
93 void test_parse_pwqp(isl_ctx *ctx, const char *str)
95 isl_pw_qpolynomial *pwqp;
97 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
98 assert(pwqp);
99 isl_pw_qpolynomial_free(pwqp);
102 static void test_parse_pwaff(isl_ctx *ctx, const char *str)
104 isl_pw_aff *pwaff;
106 pwaff = isl_pw_aff_read_from_str(ctx, str);
107 assert(pwaff);
108 isl_pw_aff_free(pwaff);
111 /* Check that we can read an isl_multi_val from "str" without errors.
113 static int test_parse_multi_val(isl_ctx *ctx, const char *str)
115 isl_multi_val *mv;
117 mv = isl_multi_val_read_from_str(ctx, str);
118 isl_multi_val_free(mv);
120 return mv ? 0 : -1;
123 /* String descriptions of multi piecewise affine expressions
124 * that are used for testing printing and parsing.
126 static const char *reparse_multi_pw_aff_tests[] = {
127 "{ A[x, y] -> [] : x + y >= 0 }",
128 "{ A[x, y] -> B[] : x + y >= 0 }",
129 "{ A[x, y] -> [x] : x + y >= 0 }",
130 "[N] -> { A[x, y] -> [x] : x + y <= N }",
131 "{ A[x, y] -> [x, y] : x + y >= 0 }",
132 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
133 "[N] -> { [] : N >= 0 }",
134 "[N] -> { [] : N >= 0 }",
135 "[N] -> { [N] : N >= 0 }",
136 "[N] -> { [N, N + 1] : N >= 0 }",
137 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
140 #undef BASE
141 #define BASE multi_pw_aff
143 #include "check_reparse_templ.c"
144 #include "check_reparse_test_templ.c"
146 /* String descriptions of piecewise multi affine expressions
147 * that are used for testing printing and parsing.
149 static const char *reparse_pw_multi_aff_tests[] = {
150 "{ [x] -> [x] }",
151 "{ [x] -> [x % 4] }",
152 "{ [x] -> [x % 4] : x mod 3 = 1 }",
153 "{ [x, x] -> [x % 4] }",
154 "{ [x, x + 1] -> [x % 4] : x mod 3 = 1 }",
155 "{ [x, x mod 2] -> [x % 4] }",
158 #undef BASE
159 #define BASE pw_multi_aff
161 #include "check_reparse_templ.c"
162 #include "check_reparse_test_templ.c"
164 /* Test parsing of piecewise multi affine expressions by printing
165 * the expressions and checking that parsing the output results
166 * in the same expression.
167 * Do this for an expression converted from a map with an output
168 * dimension name that is equal to an automatically generated name, and
169 * a set of expressions parsed from strings.
171 static isl_stat test_parse_pma(isl_ctx *ctx)
173 isl_map *map;
174 isl_pw_multi_aff *pma;
176 map = isl_map_read_from_str(ctx, "{ [a, a] -> [i1 = a + 1] }");
177 pma = isl_pw_multi_aff_from_map(map);
178 if (check_reparse_pw_multi_aff(ctx, pma) < 0)
179 return isl_stat_error;
181 if (check_reparse_pw_multi_aff_tests(ctx) < 0)
182 return isl_stat_error;
184 return isl_stat_ok;
187 /* Test parsing of multi piecewise affine expressions by printing
188 * the expressions and checking that parsing the output results
189 * in the same expression.
190 * Do this for a couple of manually constructed expressions,
191 * an expression converted from a map with an output dimension name
192 * that is equal to an automatically generated name, and
193 * a set of expressions parsed from strings.
195 static int test_parse_mpa(isl_ctx *ctx)
197 isl_space *space;
198 isl_set *dom;
199 isl_map *map;
200 isl_pw_multi_aff *pma;
201 isl_multi_pw_aff *mpa;
202 isl_stat r;
204 space = isl_space_set_alloc(ctx, 0, 0);
205 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
206 mpa = isl_multi_pw_aff_zero(space);
207 r = check_reparse_multi_pw_aff(ctx, mpa);
208 if (r < 0)
209 return -1;
211 space = isl_space_set_alloc(ctx, 1, 0);
212 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
213 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
214 dom = isl_set_universe(isl_space_params(isl_space_copy(space)));
215 dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5);
216 mpa = isl_multi_pw_aff_zero(space);
217 mpa = isl_multi_pw_aff_intersect_domain(mpa, dom);
218 r = check_reparse_multi_pw_aff(ctx, mpa);
219 if (r < 0)
220 return -1;
222 map = isl_map_read_from_str(ctx, "{ [a, a] -> [i1 = a + 1] }");
223 pma = isl_pw_multi_aff_from_map(map);
224 mpa = isl_multi_pw_aff_from_pw_multi_aff(pma);
225 if (check_reparse_multi_pw_aff(ctx, mpa) < 0)
226 return -1;
228 if (check_reparse_multi_pw_aff_tests(ctx) < 0)
229 return -1;
231 return 0;
234 /* String descriptions of multi union piecewise affine expressions
235 * that are used for testing printing and parsing.
237 static const char *reparse_multi_union_pw_aff_tests[] = {
238 "[]",
239 "A[]",
240 "A[B[] -> C[]]",
241 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
242 "(A[] : { })",
243 "[N] -> (A[] : { })",
244 "[N] -> (A[] : { : N >= 0 })",
245 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
246 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
247 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
248 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
249 "{ S[x] : x > 0; T[y] : y >= 0 })",
252 #undef BASE
253 #define BASE multi_union_pw_aff
255 #include "check_reparse_templ.c"
256 #include "check_reparse_test_templ.c"
258 /* Test parsing of multi union piecewise affine expressions by printing
259 * the expressions and checking that parsing the output results
260 * in the same expression.
261 * Do this for a couple of manually constructed expressions and
262 * a set of expressions parsed from strings.
264 static int test_parse_mupa(isl_ctx *ctx)
266 isl_space *space;
267 isl_multi_union_pw_aff *mupa;
268 isl_set *dom;
269 isl_union_set *uset;
270 isl_stat r;
272 space = isl_space_set_alloc(ctx, 0, 0);
273 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
274 mupa = isl_multi_union_pw_aff_zero(space);
275 r = check_reparse_multi_union_pw_aff(ctx, mupa);
276 if (r < 0)
277 return -1;
279 space = isl_space_set_alloc(ctx, 1, 0);
280 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
281 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
282 dom = isl_set_universe(space);
283 dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5);
284 uset = isl_union_set_from_set(dom);
285 space = isl_space_set_alloc(ctx, 1, 0);
286 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
287 space = isl_space_set_tuple_name(space, isl_dim_set, "B");
288 mupa = isl_multi_union_pw_aff_zero(space);
289 mupa = isl_multi_union_pw_aff_intersect_domain(mupa, uset);
290 r = check_reparse_multi_union_pw_aff(ctx, mupa);
291 if (r < 0)
292 return -1;
294 if (check_reparse_multi_union_pw_aff_tests(ctx) < 0)
295 return -1;
297 return 0;
300 /* Test parsing of multi expressions.
302 static int test_parse_multi(isl_ctx *ctx)
304 if (test_parse_mpa(ctx) < 0)
305 return -1;
306 if (test_parse_mupa(ctx) < 0)
307 return -1;
309 return 0;
312 /* Pairs of binary relation representations that should represent
313 * the same binary relations.
315 struct {
316 const char *map1;
317 const char *map2;
318 } parse_map_equal_tests[] = {
319 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
320 "{ [x, y] : 2y >= 6 - x }" },
321 { "{ [x,y] : x <= min(y, 2*y+3) }",
322 "{ [x,y] : x <= y, 2*y + 3 }" },
323 { "{ [x,y] : x >= min(y, 2*y+3) }",
324 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
325 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
326 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
327 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
328 "{ [i,j] -> [min(i,j)] }" },
329 { "{ [i,j] : i != j }",
330 "{ [i,j] : i < j or i > j }" },
331 { "{ [i,j] : (i+1)*2 >= j }",
332 "{ [i, j] : j <= 2 + 2i }" },
333 { "{ [i] -> [i > 0 ? 4 : 5] }",
334 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
335 { "[N=2,M] -> { [i=[(M+N)/4]] }",
336 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
337 { "{ [x] : x >= 0 }",
338 "{ [x] : x-0 >= 0 }" },
339 { "{ [i] : ((i > 10)) }",
340 "{ [i] : i >= 11 }" },
341 { "{ [i] -> [0] }",
342 "{ [i] -> [0 * i] }" },
343 { "{ [a] -> [b] : (not false) }",
344 "{ [a] -> [b] : true }" },
345 { "{ [i] : i/2 <= 5 }",
346 "{ [i] : i <= 10 }" },
347 { "{Sym=[n] [i] : i <= n }",
348 "[n] -> { [i] : i <= n }" },
349 { "{ [*] }",
350 "{ [a] }" },
351 { "{ [i] : 2*floor(i/2) = i }",
352 "{ [i] : exists a : i = 2 a }" },
353 { "{ [a] -> [b] : a = 5 implies b = 5 }",
354 "{ [a] -> [b] : a != 5 or b = 5 }" },
355 { "{ [a] -> [a - 1 : a > 0] }",
356 "{ [a] -> [a - 1] : a > 0 }" },
357 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
358 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
359 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
360 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
361 { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
362 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
363 { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
364 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
365 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
366 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
367 { "{ [a,b] -> [i,j] : a,b << i,j }",
368 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
369 { "{ [a,b] -> [i,j] : a,b <<= i,j }",
370 "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" },
371 { "{ [a,b] -> [i,j] : a,b >> i,j }",
372 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
373 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
374 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
375 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
376 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
377 "8c < n - 32a and i < n and c >= 0 and "
378 "c <= 3 and c >= -4a) }",
379 "{ [n] -> [i] : 0 <= i < n }" },
380 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
381 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
382 "{ [x] -> [] : 0 <= x <= 15 }" },
383 { "{ [x] -> [x] : }",
384 "{ [x] -> [x] }" },
385 { "{ [x=4:5] -> [x + 1] }",
386 "{ [x] -> [x + 1] : 4 <= x <= 5 }" },
387 { "{ [x=4:5] -> [x + 1 : x + 1] }",
388 "{ [x=4:5] -> [x + 1] }" },
389 { "{ [x] -> [x - 1 : x + 1] }",
390 "{ [x] -> [y] : x - 1 <= y <= x + 1 }" },
391 { "{ [x=4:] -> [x + 1] }",
392 "{ [x] -> [x + 1] : 4 <= x }" },
393 { "{ [x=:5] -> [x + 1] }",
394 "{ [x] -> [x + 1] : x <= 5 }" },
395 { "{ [x=:] -> [x + 1] }",
396 "{ [x] -> [x + 1] }" },
397 { "{ [:] -> [:] }",
398 "{ [x] -> [y] }" },
399 { "{ [x, x//4] }",
400 "{ [x, floor(x/4)] }" },
401 { "{ [10//4] }",
402 "{ [2] }" },
405 int test_parse(struct isl_ctx *ctx)
407 int i;
408 isl_map *map, *map2;
409 const char *str, *str2;
411 if (test_parse_multi_val(ctx, "{ A[B[2] -> C[5, 7]] }") < 0)
412 return -1;
413 if (test_parse_multi_val(ctx, "[n] -> { [2] }") < 0)
414 return -1;
415 if (test_parse_multi_val(ctx, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
416 return -1;
417 if (test_parse_multi(ctx) < 0)
418 return -1;
419 if (test_parse_pma(ctx) < 0)
420 return -1;
422 str = "{ [i] -> [-i] }";
423 map = isl_map_read_from_str(ctx, str);
424 assert(map);
425 isl_map_free(map);
427 str = "{ A[i] -> L[([i/3])] }";
428 map = isl_map_read_from_str(ctx, str);
429 assert(map);
430 isl_map_free(map);
432 test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
433 test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : "
434 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
436 for (i = 0; i < ARRAY_SIZE(parse_map_equal_tests); ++i) {
437 str = parse_map_equal_tests[i].map1;
438 str2 = parse_map_equal_tests[i].map2;
439 if (test_parse_map_equal(ctx, str, str2) < 0)
440 return -1;
443 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
444 map = isl_map_read_from_str(ctx, str);
445 str = "{ [new, old] -> [o0, o1] : "
446 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
447 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
448 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
449 map2 = isl_map_read_from_str(ctx, str);
450 assert(isl_map_is_equal(map, map2));
451 isl_map_free(map);
452 isl_map_free(map2);
454 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
455 map = isl_map_read_from_str(ctx, str);
456 str = "{[new,old] -> [(new+1)%2,(old+1)%2]}";
457 map2 = isl_map_read_from_str(ctx, str);
458 assert(isl_map_is_equal(map, map2));
459 isl_map_free(map);
460 isl_map_free(map2);
462 test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
463 test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
464 test_parse_pwaff(ctx, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
465 test_parse_pwqp(ctx, "{ [x] -> ([(x)/2] * [(x)/3]) }");
466 test_parse_pwaff(ctx, "{ [] -> [(100)] }");
468 return 0;
471 static int test_read(isl_ctx *ctx)
473 char *filename;
474 FILE *input;
475 isl_basic_set *bset1, *bset2;
476 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
477 int equal;
479 filename = get_filename(ctx, "set", "omega");
480 assert(filename);
481 input = fopen(filename, "r");
482 assert(input);
484 bset1 = isl_basic_set_read_from_file(ctx, input);
485 bset2 = isl_basic_set_read_from_str(ctx, str);
487 equal = isl_basic_set_is_equal(bset1, bset2);
489 isl_basic_set_free(bset1);
490 isl_basic_set_free(bset2);
491 free(filename);
493 fclose(input);
495 if (equal < 0)
496 return -1;
497 if (!equal)
498 isl_die(ctx, isl_error_unknown,
499 "read sets not equal", return -1);
501 return 0;
504 static int test_bounded(isl_ctx *ctx)
506 isl_set *set;
507 isl_bool bounded;
509 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }");
510 bounded = isl_set_is_bounded(set);
511 isl_set_free(set);
513 if (bounded < 0)
514 return -1;
515 if (!bounded)
516 isl_die(ctx, isl_error_unknown,
517 "set not considered bounded", return -1);
519 set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }");
520 bounded = isl_set_is_bounded(set);
521 assert(!bounded);
522 isl_set_free(set);
524 if (bounded < 0)
525 return -1;
526 if (bounded)
527 isl_die(ctx, isl_error_unknown,
528 "set considered bounded", return -1);
530 set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }");
531 bounded = isl_set_is_bounded(set);
532 isl_set_free(set);
534 if (bounded < 0)
535 return -1;
536 if (bounded)
537 isl_die(ctx, isl_error_unknown,
538 "set considered bounded", return -1);
540 return 0;
543 /* Construct the basic set { [i] : 5 <= i <= N } */
544 static int test_construction_1(isl_ctx *ctx)
546 isl_space *space;
547 isl_local_space *ls;
548 isl_basic_set *bset;
549 isl_constraint *c;
551 space = isl_space_set_alloc(ctx, 1, 1);
552 bset = isl_basic_set_universe(isl_space_copy(space));
553 ls = isl_local_space_from_space(space);
555 c = isl_constraint_alloc_inequality(isl_local_space_copy(ls));
556 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
557 c = isl_constraint_set_coefficient_si(c, isl_dim_param, 0, 1);
558 bset = isl_basic_set_add_constraint(bset, c);
560 c = isl_constraint_alloc_inequality(isl_local_space_copy(ls));
561 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
562 c = isl_constraint_set_constant_si(c, -5);
563 bset = isl_basic_set_add_constraint(bset, c);
565 isl_local_space_free(ls);
566 isl_basic_set_free(bset);
568 return 0;
571 /* Construct the basic set { [x] : -100 <= x <= 100 }
572 * using isl_basic_set_{lower,upper}_bound_val and
573 * check that it is equal the same basic set parsed from a string.
575 static int test_construction_2(isl_ctx *ctx)
577 isl_bool equal;
578 isl_val *v;
579 isl_space *space;
580 isl_basic_set *bset1, *bset2;
582 v = isl_val_int_from_si(ctx, 100);
583 space = isl_space_set_alloc(ctx, 0, 1);
584 bset1 = isl_basic_set_universe(space);
585 bset1 = isl_basic_set_upper_bound_val(bset1, isl_dim_set, 0,
586 isl_val_copy(v));
587 bset1 = isl_basic_set_lower_bound_val(bset1, isl_dim_set, 0,
588 isl_val_neg(v));
589 bset2 = isl_basic_set_read_from_str(ctx, "{ [x] : -100 <= x <= 100 }");
590 equal = isl_basic_set_is_equal(bset1, bset2);
591 isl_basic_set_free(bset1);
592 isl_basic_set_free(bset2);
594 if (equal < 0)
595 return -1;
596 if (!equal)
597 isl_die(ctx, isl_error_unknown,
598 "failed construction", return -1);
600 return 0;
603 /* Basic tests for constructing basic sets.
605 static int test_construction(isl_ctx *ctx)
607 if (test_construction_1(ctx) < 0)
608 return -1;
609 if (test_construction_2(ctx) < 0)
610 return -1;
611 return 0;
614 static int test_dim(isl_ctx *ctx)
616 const char *str;
617 isl_map *map1, *map2;
618 int equal;
620 map1 = isl_map_read_from_str(ctx,
621 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
622 map1 = isl_map_add_dims(map1, isl_dim_in, 1);
623 map2 = isl_map_read_from_str(ctx,
624 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
625 equal = isl_map_is_equal(map1, map2);
626 isl_map_free(map2);
628 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
629 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }");
630 if (equal >= 0 && equal)
631 equal = isl_map_is_equal(map1, map2);
633 isl_map_free(map1);
634 isl_map_free(map2);
636 if (equal < 0)
637 return -1;
638 if (!equal)
639 isl_die(ctx, isl_error_unknown,
640 "unexpected result", return -1);
642 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
643 map1 = isl_map_read_from_str(ctx, str);
644 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
645 map2 = isl_map_read_from_str(ctx, str);
646 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
647 equal = isl_map_is_equal(map1, map2);
648 isl_map_free(map1);
649 isl_map_free(map2);
651 if (equal < 0)
652 return -1;
653 if (!equal)
654 isl_die(ctx, isl_error_unknown,
655 "unexpected result", return -1);
657 return 0;
660 #undef BASE
661 #define BASE multi_val
662 #include "isl_test_plain_equal_templ.c"
664 #undef BASE
665 #define BASE multi_aff
666 #include "isl_test_plain_equal_templ.c"
668 /* Check that "val" is equal to the value described by "str".
669 * If "str" is "NaN", then check for a NaN value explicitly.
671 static isl_stat val_check_equal(__isl_keep isl_val *val, const char *str)
673 isl_bool ok, is_nan;
674 isl_ctx *ctx;
675 isl_val *res;
677 if (!val)
678 return isl_stat_error;
680 ctx = isl_val_get_ctx(val);
681 res = isl_val_read_from_str(ctx, str);
682 is_nan = isl_val_is_nan(res);
683 if (is_nan < 0)
684 ok = isl_bool_error;
685 else if (is_nan)
686 ok = isl_val_is_nan(val);
687 else
688 ok = isl_val_eq(val, res);
689 isl_val_free(res);
690 if (ok < 0)
691 return isl_stat_error;
692 if (!ok)
693 isl_die(ctx, isl_error_unknown,
694 "unexpected result", return isl_stat_error);
695 return isl_stat_ok;
698 struct {
699 __isl_give isl_val *(*op)(__isl_take isl_val *v);
700 const char *arg;
701 const char *res;
702 } val_un_tests[] = {
703 { &isl_val_neg, "0", "0" },
704 { &isl_val_abs, "0", "0" },
705 { &isl_val_pow2, "0", "1" },
706 { &isl_val_floor, "0", "0" },
707 { &isl_val_ceil, "0", "0" },
708 { &isl_val_neg, "1", "-1" },
709 { &isl_val_neg, "-1", "1" },
710 { &isl_val_neg, "1/2", "-1/2" },
711 { &isl_val_neg, "-1/2", "1/2" },
712 { &isl_val_neg, "infty", "-infty" },
713 { &isl_val_neg, "-infty", "infty" },
714 { &isl_val_neg, "NaN", "NaN" },
715 { &isl_val_abs, "1", "1" },
716 { &isl_val_abs, "-1", "1" },
717 { &isl_val_abs, "1/2", "1/2" },
718 { &isl_val_abs, "-1/2", "1/2" },
719 { &isl_val_abs, "infty", "infty" },
720 { &isl_val_abs, "-infty", "infty" },
721 { &isl_val_abs, "NaN", "NaN" },
722 { &isl_val_floor, "1", "1" },
723 { &isl_val_floor, "-1", "-1" },
724 { &isl_val_floor, "1/2", "0" },
725 { &isl_val_floor, "-1/2", "-1" },
726 { &isl_val_floor, "infty", "infty" },
727 { &isl_val_floor, "-infty", "-infty" },
728 { &isl_val_floor, "NaN", "NaN" },
729 { &isl_val_ceil, "1", "1" },
730 { &isl_val_ceil, "-1", "-1" },
731 { &isl_val_ceil, "1/2", "1" },
732 { &isl_val_ceil, "-1/2", "0" },
733 { &isl_val_ceil, "infty", "infty" },
734 { &isl_val_ceil, "-infty", "-infty" },
735 { &isl_val_ceil, "NaN", "NaN" },
736 { &isl_val_pow2, "-3", "1/8" },
737 { &isl_val_pow2, "-1", "1/2" },
738 { &isl_val_pow2, "1", "2" },
739 { &isl_val_pow2, "2", "4" },
740 { &isl_val_pow2, "3", "8" },
741 { &isl_val_inv, "1", "1" },
742 { &isl_val_inv, "2", "1/2" },
743 { &isl_val_inv, "1/2", "2" },
744 { &isl_val_inv, "-2", "-1/2" },
745 { &isl_val_inv, "-1/2", "-2" },
746 { &isl_val_inv, "0", "NaN" },
747 { &isl_val_inv, "NaN", "NaN" },
748 { &isl_val_inv, "infty", "0" },
749 { &isl_val_inv, "-infty", "0" },
752 /* Perform some basic tests of unary operations on isl_val objects.
754 static int test_un_val(isl_ctx *ctx)
756 int i;
757 isl_val *v;
758 __isl_give isl_val *(*fn)(__isl_take isl_val *v);
760 for (i = 0; i < ARRAY_SIZE(val_un_tests); ++i) {
761 isl_stat r;
763 v = isl_val_read_from_str(ctx, val_un_tests[i].arg);
764 fn = val_un_tests[i].op;
765 v = fn(v);
766 r = val_check_equal(v, val_un_tests[i].res);
767 isl_val_free(v);
768 if (r < 0)
769 return -1;
772 return 0;
775 struct {
776 __isl_give isl_val *(*fn)(__isl_take isl_val *v1,
777 __isl_take isl_val *v2);
778 } val_bin_op[] = {
779 ['+'] = { &isl_val_add },
780 ['-'] = { &isl_val_sub },
781 ['*'] = { &isl_val_mul },
782 ['/'] = { &isl_val_div },
783 ['g'] = { &isl_val_gcd },
784 ['m'] = { &isl_val_min },
785 ['M'] = { &isl_val_max },
788 struct {
789 const char *arg1;
790 unsigned char op;
791 const char *arg2;
792 const char *res;
793 } val_bin_tests[] = {
794 { "0", '+', "0", "0" },
795 { "1", '+', "0", "1" },
796 { "1", '+', "1", "2" },
797 { "1", '-', "1", "0" },
798 { "1", '*', "1", "1" },
799 { "1", '/', "1", "1" },
800 { "2", '*', "3", "6" },
801 { "2", '*', "1/2", "1" },
802 { "2", '*', "1/3", "2/3" },
803 { "2/3", '*', "3/5", "2/5" },
804 { "2/3", '*', "7/5", "14/15" },
805 { "2", '/', "1/2", "4" },
806 { "-2", '/', "-1/2", "4" },
807 { "-2", '/', "1/2", "-4" },
808 { "2", '/', "-1/2", "-4" },
809 { "2", '/', "2", "1" },
810 { "2", '/', "3", "2/3" },
811 { "2/3", '/', "5/3", "2/5" },
812 { "2/3", '/', "5/7", "14/15" },
813 { "0", '/', "0", "NaN" },
814 { "42", '/', "0", "NaN" },
815 { "-42", '/', "0", "NaN" },
816 { "infty", '/', "0", "NaN" },
817 { "-infty", '/', "0", "NaN" },
818 { "NaN", '/', "0", "NaN" },
819 { "0", '/', "NaN", "NaN" },
820 { "42", '/', "NaN", "NaN" },
821 { "-42", '/', "NaN", "NaN" },
822 { "infty", '/', "NaN", "NaN" },
823 { "-infty", '/', "NaN", "NaN" },
824 { "NaN", '/', "NaN", "NaN" },
825 { "0", '/', "infty", "0" },
826 { "42", '/', "infty", "0" },
827 { "-42", '/', "infty", "0" },
828 { "infty", '/', "infty", "NaN" },
829 { "-infty", '/', "infty", "NaN" },
830 { "NaN", '/', "infty", "NaN" },
831 { "0", '/', "-infty", "0" },
832 { "42", '/', "-infty", "0" },
833 { "-42", '/', "-infty", "0" },
834 { "infty", '/', "-infty", "NaN" },
835 { "-infty", '/', "-infty", "NaN" },
836 { "NaN", '/', "-infty", "NaN" },
837 { "1", '-', "1/3", "2/3" },
838 { "1/3", '+', "1/2", "5/6" },
839 { "1/2", '+', "1/2", "1" },
840 { "3/4", '-', "1/4", "1/2" },
841 { "1/2", '-', "1/3", "1/6" },
842 { "infty", '+', "42", "infty" },
843 { "infty", '+', "infty", "infty" },
844 { "42", '+', "infty", "infty" },
845 { "infty", '-', "infty", "NaN" },
846 { "infty", '*', "infty", "infty" },
847 { "infty", '*', "-infty", "-infty" },
848 { "-infty", '*', "infty", "-infty" },
849 { "-infty", '*', "-infty", "infty" },
850 { "0", '*', "infty", "NaN" },
851 { "1", '*', "infty", "infty" },
852 { "infty", '*', "0", "NaN" },
853 { "infty", '*', "42", "infty" },
854 { "42", '-', "infty", "-infty" },
855 { "infty", '+', "-infty", "NaN" },
856 { "4", 'g', "6", "2" },
857 { "5", 'g', "6", "1" },
858 { "42", 'm', "3", "3" },
859 { "42", 'M', "3", "42" },
860 { "3", 'm', "42", "3" },
861 { "3", 'M', "42", "42" },
862 { "42", 'm', "infty", "42" },
863 { "42", 'M', "infty", "infty" },
864 { "42", 'm', "-infty", "-infty" },
865 { "42", 'M', "-infty", "42" },
866 { "42", 'm', "NaN", "NaN" },
867 { "42", 'M', "NaN", "NaN" },
868 { "infty", 'm', "-infty", "-infty" },
869 { "infty", 'M', "-infty", "infty" },
872 /* Perform some basic tests of binary operations on isl_val objects.
874 static int test_bin_val(isl_ctx *ctx)
876 int i;
877 isl_val *v1, *v2, *res;
878 __isl_give isl_val *(*fn)(__isl_take isl_val *v1,
879 __isl_take isl_val *v2);
880 int ok;
882 for (i = 0; i < ARRAY_SIZE(val_bin_tests); ++i) {
883 v1 = isl_val_read_from_str(ctx, val_bin_tests[i].arg1);
884 v2 = isl_val_read_from_str(ctx, val_bin_tests[i].arg2);
885 res = isl_val_read_from_str(ctx, val_bin_tests[i].res);
886 fn = val_bin_op[val_bin_tests[i].op].fn;
887 v1 = fn(v1, v2);
888 if (isl_val_is_nan(res))
889 ok = isl_val_is_nan(v1);
890 else
891 ok = isl_val_eq(v1, res);
892 isl_val_free(v1);
893 isl_val_free(res);
894 if (ok < 0)
895 return -1;
896 if (!ok)
897 isl_die(ctx, isl_error_unknown,
898 "unexpected result", return -1);
901 return 0;
904 /* Perform some basic tests on isl_val objects.
906 static int test_val(isl_ctx *ctx)
908 if (test_un_val(ctx) < 0)
909 return -1;
910 if (test_bin_val(ctx) < 0)
911 return -1;
912 return 0;
915 /* Sets described using existentially quantified variables that
916 * can also be described without.
918 static const char *elimination_tests[] = {
919 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
920 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
921 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
924 /* Check that redundant existentially quantified variables are
925 * getting removed.
927 static int test_elimination(isl_ctx *ctx)
929 int i;
930 isl_size n;
931 isl_basic_set *bset;
933 for (i = 0; i < ARRAY_SIZE(elimination_tests); ++i) {
934 bset = isl_basic_set_read_from_str(ctx, elimination_tests[i]);
935 n = isl_basic_set_dim(bset, isl_dim_div);
936 isl_basic_set_free(bset);
937 if (n < 0)
938 return -1;
939 if (n != 0)
940 isl_die(ctx, isl_error_unknown,
941 "expecting no existentials", return -1);
944 return 0;
947 static int test_div(isl_ctx *ctx)
949 const char *str;
950 int empty;
951 isl_space *space;
952 isl_set *set;
953 isl_local_space *ls;
954 struct isl_basic_set *bset;
955 struct isl_constraint *c;
957 /* test 1 */
958 space = isl_space_set_alloc(ctx, 0, 3);
959 bset = isl_basic_set_universe(isl_space_copy(space));
960 ls = isl_local_space_from_space(space);
962 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
963 c = isl_constraint_set_constant_si(c, -1);
964 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
965 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
966 bset = isl_basic_set_add_constraint(bset, c);
968 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
969 c = isl_constraint_set_constant_si(c, 1);
970 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
971 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3);
972 bset = isl_basic_set_add_constraint(bset, c);
974 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
976 assert(bset && bset->n_div == 1);
977 isl_local_space_free(ls);
978 isl_basic_set_free(bset);
980 /* test 2 */
981 space = isl_space_set_alloc(ctx, 0, 3);
982 bset = isl_basic_set_universe(isl_space_copy(space));
983 ls = isl_local_space_from_space(space);
985 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
986 c = isl_constraint_set_constant_si(c, 1);
987 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
988 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
989 bset = isl_basic_set_add_constraint(bset, c);
991 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
992 c = isl_constraint_set_constant_si(c, -1);
993 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
994 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3);
995 bset = isl_basic_set_add_constraint(bset, c);
997 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
999 assert(bset && bset->n_div == 1);
1000 isl_local_space_free(ls);
1001 isl_basic_set_free(bset);
1003 /* test 3 */
1004 space = isl_space_set_alloc(ctx, 0, 3);
1005 bset = isl_basic_set_universe(isl_space_copy(space));
1006 ls = isl_local_space_from_space(space);
1008 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1009 c = isl_constraint_set_constant_si(c, 1);
1010 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1011 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
1012 bset = isl_basic_set_add_constraint(bset, c);
1014 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1015 c = isl_constraint_set_constant_si(c, -3);
1016 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1017 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 4);
1018 bset = isl_basic_set_add_constraint(bset, c);
1020 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
1022 assert(bset && bset->n_div == 1);
1023 isl_local_space_free(ls);
1024 isl_basic_set_free(bset);
1026 /* test 4 */
1027 space = isl_space_set_alloc(ctx, 0, 3);
1028 bset = isl_basic_set_universe(isl_space_copy(space));
1029 ls = isl_local_space_from_space(space);
1031 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1032 c = isl_constraint_set_constant_si(c, 2);
1033 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1034 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
1035 bset = isl_basic_set_add_constraint(bset, c);
1037 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1038 c = isl_constraint_set_constant_si(c, -1);
1039 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1040 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 6);
1041 bset = isl_basic_set_add_constraint(bset, c);
1043 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
1045 assert(isl_basic_set_is_empty(bset));
1046 isl_local_space_free(ls);
1047 isl_basic_set_free(bset);
1049 /* test 5 */
1050 space = isl_space_set_alloc(ctx, 0, 3);
1051 bset = isl_basic_set_universe(isl_space_copy(space));
1052 ls = isl_local_space_from_space(space);
1054 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1055 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1056 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3);
1057 bset = isl_basic_set_add_constraint(bset, c);
1059 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1060 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1061 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1062 bset = isl_basic_set_add_constraint(bset, c);
1064 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
1066 assert(bset && bset->n_div == 0);
1067 isl_basic_set_free(bset);
1068 isl_local_space_free(ls);
1070 /* test 6 */
1071 space = isl_space_set_alloc(ctx, 0, 3);
1072 bset = isl_basic_set_universe(isl_space_copy(space));
1073 ls = isl_local_space_from_space(space);
1075 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1076 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1077 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 6);
1078 bset = isl_basic_set_add_constraint(bset, c);
1080 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1081 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1082 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1083 bset = isl_basic_set_add_constraint(bset, c);
1085 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
1087 assert(bset && bset->n_div == 1);
1088 isl_basic_set_free(bset);
1089 isl_local_space_free(ls);
1091 /* test 7 */
1092 /* This test is a bit tricky. We set up an equality
1093 * a + 3b + 3c = 6 e0
1094 * Normalization of divs creates _two_ divs
1095 * a = 3 e0
1096 * c - b - e0 = 2 e1
1097 * Afterwards e0 is removed again because it has coefficient -1
1098 * and we end up with the original equality and div again.
1099 * Perhaps we can avoid the introduction of this temporary div.
1101 space = isl_space_set_alloc(ctx, 0, 4);
1102 bset = isl_basic_set_universe(isl_space_copy(space));
1103 ls = isl_local_space_from_space(space);
1105 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1106 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1107 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1108 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -3);
1109 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, 6);
1110 bset = isl_basic_set_add_constraint(bset, c);
1112 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
1114 /* Test disabled for now */
1116 assert(bset && bset->n_div == 1);
1118 isl_local_space_free(ls);
1119 isl_basic_set_free(bset);
1121 /* test 8 */
1122 space = isl_space_set_alloc(ctx, 0, 5);
1123 bset = isl_basic_set_universe(isl_space_copy(space));
1124 ls = isl_local_space_from_space(space);
1126 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1127 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1128 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1129 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, -3);
1130 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 4, 6);
1131 bset = isl_basic_set_add_constraint(bset, c);
1133 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1134 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1135 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 1);
1136 c = isl_constraint_set_constant_si(c, 1);
1137 bset = isl_basic_set_add_constraint(bset, c);
1139 bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1);
1141 /* Test disabled for now */
1143 assert(bset && bset->n_div == 1);
1145 isl_local_space_free(ls);
1146 isl_basic_set_free(bset);
1148 /* test 9 */
1149 space = isl_space_set_alloc(ctx, 0, 4);
1150 bset = isl_basic_set_universe(isl_space_copy(space));
1151 ls = isl_local_space_from_space(space);
1153 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1154 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1155 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -1);
1156 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -2);
1157 bset = isl_basic_set_add_constraint(bset, c);
1159 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1160 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1161 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, 3);
1162 c = isl_constraint_set_constant_si(c, 2);
1163 bset = isl_basic_set_add_constraint(bset, c);
1165 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2);
1167 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
1169 assert(!isl_basic_set_is_empty(bset));
1171 isl_local_space_free(ls);
1172 isl_basic_set_free(bset);
1174 /* test 10 */
1175 space = isl_space_set_alloc(ctx, 0, 3);
1176 bset = isl_basic_set_universe(isl_space_copy(space));
1177 ls = isl_local_space_from_space(space);
1179 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1180 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1181 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -2);
1182 bset = isl_basic_set_add_constraint(bset, c);
1184 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
1186 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
1188 isl_local_space_free(ls);
1189 isl_basic_set_free(bset);
1191 str = "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1192 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1193 set = isl_set_read_from_str(ctx, str);
1194 set = isl_set_compute_divs(set);
1195 isl_set_free(set);
1196 if (!set)
1197 return -1;
1199 if (test_elimination(ctx) < 0)
1200 return -1;
1202 str = "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1203 set = isl_set_read_from_str(ctx, str);
1204 set = isl_set_remove_divs_involving_dims(set, isl_dim_set, 0, 2);
1205 set = isl_set_fix_si(set, isl_dim_set, 2, -3);
1206 empty = isl_set_is_empty(set);
1207 isl_set_free(set);
1208 if (empty < 0)
1209 return -1;
1210 if (!empty)
1211 isl_die(ctx, isl_error_unknown,
1212 "result not as accurate as expected", return -1);
1214 return 0;
1217 void test_application_case(struct isl_ctx *ctx, const char *name)
1219 char *filename;
1220 FILE *input;
1221 struct isl_basic_set *bset1, *bset2;
1222 struct isl_basic_map *bmap;
1224 filename = get_filename(ctx, name, "omega");
1225 assert(filename);
1226 input = fopen(filename, "r");
1227 assert(input);
1229 bset1 = isl_basic_set_read_from_file(ctx, input);
1230 bmap = isl_basic_map_read_from_file(ctx, input);
1232 bset1 = isl_basic_set_apply(bset1, bmap);
1234 bset2 = isl_basic_set_read_from_file(ctx, input);
1236 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1238 isl_basic_set_free(bset1);
1239 isl_basic_set_free(bset2);
1240 free(filename);
1242 fclose(input);
1245 static int test_application(isl_ctx *ctx)
1247 test_application_case(ctx, "application");
1248 test_application_case(ctx, "application2");
1250 return 0;
1253 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
1255 char *filename;
1256 FILE *input;
1257 struct isl_basic_set *bset1, *bset2;
1259 filename = get_filename(ctx, name, "polylib");
1260 assert(filename);
1261 input = fopen(filename, "r");
1262 assert(input);
1264 bset1 = isl_basic_set_read_from_file(ctx, input);
1265 bset2 = isl_basic_set_read_from_file(ctx, input);
1267 bset1 = isl_basic_set_affine_hull(bset1);
1269 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1271 isl_basic_set_free(bset1);
1272 isl_basic_set_free(bset2);
1273 free(filename);
1275 fclose(input);
1278 /* Pairs of sets and the corresponding expected results of
1279 * isl_basic_set_recession_cone.
1281 struct {
1282 const char *set;
1283 const char *cone;
1284 } recession_cone_tests[] = {
1285 { "{ [i] : 0 <= i <= 10 }", "{ [0] }" },
1286 { "{ [i] : 0 <= i }", "{ [i] : 0 <= i }" },
1287 { "{ [i] : i <= 10 }", "{ [i] : i <= 0 }" },
1288 { "{ [i] : false }", "{ [i] : false }" },
1291 /* Perform some basic isl_basic_set_recession_cone tests.
1293 static int test_recession_cone(struct isl_ctx *ctx)
1295 int i;
1297 for (i = 0; i < ARRAY_SIZE(recession_cone_tests); ++i) {
1298 const char *str;
1299 isl_basic_set *bset;
1300 isl_basic_set *cone, *expected;
1301 isl_bool equal;
1303 str = recession_cone_tests[i].set;
1304 bset = isl_basic_set_read_from_str(ctx, str);
1305 str = recession_cone_tests[i].cone;
1306 expected = isl_basic_set_read_from_str(ctx, str);
1307 cone = isl_basic_set_recession_cone(bset);
1308 equal = isl_basic_set_is_equal(cone, expected);
1309 isl_basic_set_free(cone);
1310 isl_basic_set_free(expected);
1311 if (equal < 0)
1312 return -1;
1313 if (!equal)
1314 isl_die(ctx, isl_error_unknown, "unexpected cone",
1315 return -1);
1318 return 0;
1321 int test_affine_hull(struct isl_ctx *ctx)
1323 const char *str;
1324 isl_set *set;
1325 isl_basic_set *bset, *bset2;
1326 isl_size n;
1327 isl_bool subset;
1329 test_affine_hull_case(ctx, "affine2");
1330 test_affine_hull_case(ctx, "affine");
1331 test_affine_hull_case(ctx, "affine3");
1333 str = "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1334 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1335 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1336 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1337 set = isl_set_read_from_str(ctx, str);
1338 bset = isl_set_affine_hull(set);
1339 n = isl_basic_set_dim(bset, isl_dim_div);
1340 isl_basic_set_free(bset);
1341 if (n < 0)
1342 return -1;
1343 if (n != 0)
1344 isl_die(ctx, isl_error_unknown, "not expecting any divs",
1345 return -1);
1347 /* Check that isl_map_affine_hull is not confused by
1348 * the reordering of divs in isl_map_align_divs.
1350 str = "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1351 "32e0 = b and 32e1 = c); "
1352 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1353 set = isl_set_read_from_str(ctx, str);
1354 bset = isl_set_affine_hull(set);
1355 isl_basic_set_free(bset);
1356 if (!bset)
1357 return -1;
1359 str = "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1360 "32e2 = 31 + 31e0 }";
1361 set = isl_set_read_from_str(ctx, str);
1362 bset = isl_set_affine_hull(set);
1363 str = "{ [a] : exists e : a = 32 e }";
1364 bset2 = isl_basic_set_read_from_str(ctx, str);
1365 subset = isl_basic_set_is_subset(bset, bset2);
1366 isl_basic_set_free(bset);
1367 isl_basic_set_free(bset2);
1368 if (subset < 0)
1369 return -1;
1370 if (!subset)
1371 isl_die(ctx, isl_error_unknown, "not as accurate as expected",
1372 return -1);
1374 return 0;
1377 /* Test a special case of isl_set_plain_unshifted_simple_hull
1378 * where older versions of isl would include a redundant constraint
1379 * in the result.
1380 * Check that the result does not have any constraints.
1382 static isl_stat test_plain_unshifted_simple_hull_special(isl_ctx *ctx)
1384 const char *str;
1385 isl_bool is_universe;
1386 isl_set *set;
1387 isl_basic_set *bset;
1389 str = "{[x, y] : x = 0 or 2*((x+y)//2) <= y + 2 }";
1390 set = isl_set_read_from_str(ctx, str);
1391 bset = isl_set_plain_unshifted_simple_hull(set);
1392 is_universe = isl_basic_set_plain_is_universe(bset);
1393 isl_basic_set_free(bset);
1395 if (is_universe < 0)
1396 return isl_stat_error;
1397 if (!is_universe)
1398 isl_die(ctx, isl_error_unknown,
1399 "hull should not have any constraints",
1400 return isl_stat_error);
1402 return isl_stat_ok;
1405 /* Inputs for simple hull tests, consisting of
1406 * the specific simple hull function, the input set and the expected result.
1408 struct {
1409 __isl_give isl_basic_set *(*fn)(__isl_take isl_set *set);
1410 const char *set;
1411 const char *hull;
1412 } simple_hull_tests[] = {
1413 { &isl_set_plain_unshifted_simple_hull,
1414 "{ [i,j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1415 "{ [i,j] : i >= 1 }" },
1416 { &isl_set_plain_unshifted_simple_hull,
1417 "{ [n,i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1418 "(j mod 4 = 2 and k mod 6 = n) }",
1419 "{ [n,i,j,k] : j mod 4 = 2 }" },
1420 { &isl_set_unshifted_simple_hull,
1421 "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1422 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1423 { &isl_set_simple_hull,
1424 "{ [a, b] : b <= 0 and "
1425 "2*floor((-2*floor((b)/2))/5) >= a - floor((b)/2); "
1426 "[a, b] : a mod 2 = 0 }",
1427 "{ [a, b] }" },
1430 /* Basic tests for various simple hull functions.
1432 static int test_various_simple_hull(isl_ctx *ctx)
1434 int i;
1435 isl_set *set;
1436 isl_basic_set *hull, *expected;
1437 isl_bool equal;
1439 for (i = 0; i < ARRAY_SIZE(simple_hull_tests); ++i) {
1440 const char *str;
1441 str = simple_hull_tests[i].set;
1442 set = isl_set_read_from_str(ctx, str);
1443 str = simple_hull_tests[i].hull;
1444 expected = isl_basic_set_read_from_str(ctx, str);
1445 hull = simple_hull_tests[i].fn(set);
1446 equal = isl_basic_set_is_equal(hull, expected);
1447 isl_basic_set_free(hull);
1448 isl_basic_set_free(expected);
1449 if (equal < 0)
1450 return -1;
1451 if (!equal)
1452 isl_die(ctx, isl_error_unknown, "unexpected hull",
1453 return -1);
1456 return 0;
1459 static int test_simple_hull(struct isl_ctx *ctx)
1461 const char *str;
1462 isl_set *set;
1463 isl_basic_set *bset;
1464 isl_bool is_empty;
1466 str = "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1467 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1468 set = isl_set_read_from_str(ctx, str);
1469 bset = isl_set_simple_hull(set);
1470 is_empty = isl_basic_set_is_empty(bset);
1471 isl_basic_set_free(bset);
1473 if (is_empty == isl_bool_error)
1474 return -1;
1476 if (is_empty == isl_bool_false)
1477 isl_die(ctx, isl_error_unknown, "Empty set should be detected",
1478 return -1);
1480 if (test_plain_unshifted_simple_hull_special(ctx) < 0)
1481 return -1;
1482 if (test_various_simple_hull(ctx) < 0)
1483 return -1;
1485 return 0;
1488 /* Inputs for isl_set_get_simple_fixed_box_hull tests.
1489 * "set" is the input set.
1490 * "offset" is the expected box offset.
1491 * "size" is the expected box size.
1493 static struct {
1494 const char *set;
1495 const char *offset;
1496 const char *size;
1497 } box_hull_tests[] = {
1498 { "{ S[x, y] : 0 <= x, y < 10 }", "{ S[0, 0] }", "{ S[10, 10] }" },
1499 { "[N] -> { S[x, y] : N <= x, y < N + 10 }",
1500 "[N] -> { S[N, N] }", "{ S[10, 10] }" },
1501 { "{ S[x, y] : 0 <= x + y, x - y < 10 }",
1502 "{ S[0, -4] }", "{ S[10, 9] }" },
1503 { "{ [i=0:10] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1504 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1505 "{ [3] }", "{ [8] }" },
1506 { "[N] -> { [w = 0:17] : exists (e0: w < 2N and "
1507 "-1 + w <= e0 <= w and 2e0 >= N + w and w <= 2e0 <= 15 + w) }",
1508 "[N] -> { [N] }", "{ [9] }" },
1511 /* Perform basic isl_set_get_simple_fixed_box_hull tests.
1513 static int test_box_hull(struct isl_ctx *ctx)
1515 int i;
1517 for (i = 0; i < ARRAY_SIZE(box_hull_tests); ++i) {
1518 const char *str;
1519 isl_stat r;
1520 isl_set *set;
1521 isl_multi_aff *offset;
1522 isl_multi_val *size;
1523 isl_fixed_box *box;
1525 set = isl_set_read_from_str(ctx, box_hull_tests[i].set);
1526 box = isl_set_get_simple_fixed_box_hull(set);
1527 offset = isl_fixed_box_get_offset(box);
1528 size = isl_fixed_box_get_size(box);
1529 str = box_hull_tests[i].offset;
1530 r = multi_aff_check_plain_equal(offset, str);
1531 str = box_hull_tests[i].size;
1532 if (r >= 0)
1533 r = multi_val_check_plain_equal(size, str);
1534 isl_multi_aff_free(offset);
1535 isl_multi_val_free(size);
1536 isl_fixed_box_free(box);
1537 isl_set_free(set);
1538 if (r < 0)
1539 return -1;
1542 return 0;
1545 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
1547 char *filename;
1548 FILE *input;
1549 struct isl_basic_set *bset1, *bset2;
1550 struct isl_set *set;
1552 filename = get_filename(ctx, name, "polylib");
1553 assert(filename);
1554 input = fopen(filename, "r");
1555 assert(input);
1557 bset1 = isl_basic_set_read_from_file(ctx, input);
1558 bset2 = isl_basic_set_read_from_file(ctx, input);
1560 set = isl_basic_set_union(bset1, bset2);
1561 bset1 = isl_set_convex_hull(set);
1563 bset2 = isl_basic_set_read_from_file(ctx, input);
1565 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1567 isl_basic_set_free(bset1);
1568 isl_basic_set_free(bset2);
1569 free(filename);
1571 fclose(input);
1574 struct {
1575 const char *set;
1576 const char *hull;
1577 } convex_hull_tests[] = {
1578 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1579 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1580 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1581 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1582 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1583 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1584 "i2 <= 5 and i2 >= 4; "
1585 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1586 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1587 "i2 <= 5 + i0 and i2 >= i0 }" },
1588 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1589 "{ [x, y] : 1 = 0 }" },
1590 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1591 "[x, y, 0] : x >= 0 and y < 0 }",
1592 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1593 { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and "
1594 "c <= a; "
1595 "[0, 2, 0]; [3, 1, 0] }",
1596 "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and "
1597 "5c <= 6 - a - 3b }" },
1600 static int test_convex_hull_algo(isl_ctx *ctx, int convex)
1602 int i;
1603 int orig_convex = ctx->opt->convex;
1604 ctx->opt->convex = convex;
1606 test_convex_hull_case(ctx, "convex0");
1607 test_convex_hull_case(ctx, "convex1");
1608 test_convex_hull_case(ctx, "convex2");
1609 test_convex_hull_case(ctx, "convex3");
1610 test_convex_hull_case(ctx, "convex4");
1611 test_convex_hull_case(ctx, "convex5");
1612 test_convex_hull_case(ctx, "convex6");
1613 test_convex_hull_case(ctx, "convex7");
1614 test_convex_hull_case(ctx, "convex8");
1615 test_convex_hull_case(ctx, "convex9");
1616 test_convex_hull_case(ctx, "convex10");
1617 test_convex_hull_case(ctx, "convex11");
1618 test_convex_hull_case(ctx, "convex12");
1619 test_convex_hull_case(ctx, "convex13");
1620 test_convex_hull_case(ctx, "convex14");
1621 test_convex_hull_case(ctx, "convex15");
1623 for (i = 0; i < ARRAY_SIZE(convex_hull_tests); ++i) {
1624 isl_set *set1, *set2;
1625 int equal;
1627 set1 = isl_set_read_from_str(ctx, convex_hull_tests[i].set);
1628 set2 = isl_set_read_from_str(ctx, convex_hull_tests[i].hull);
1629 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
1630 equal = isl_set_is_equal(set1, set2);
1631 isl_set_free(set1);
1632 isl_set_free(set2);
1634 if (equal < 0)
1635 return -1;
1636 if (!equal)
1637 isl_die(ctx, isl_error_unknown,
1638 "unexpected convex hull", return -1);
1641 ctx->opt->convex = orig_convex;
1643 return 0;
1646 static int test_convex_hull(isl_ctx *ctx)
1648 if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM) < 0)
1649 return -1;
1650 if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP) < 0)
1651 return -1;
1652 return 0;
1655 /* Check that computing the gist of "map" with respect to "context"
1656 * does not make any copy of "map" get marked empty.
1657 * Earlier versions of isl would end up doing that.
1659 static isl_stat test_gist_empty_pair(isl_ctx *ctx, const char *map,
1660 const char *context)
1662 isl_map *m1, *m2, *m3;
1663 isl_bool empty_before, empty_after;
1665 m1 = isl_map_read_from_str(ctx, map);
1666 m2 = isl_map_read_from_str(ctx, context);
1667 m3 = isl_map_copy(m1);
1668 empty_before = isl_map_is_empty(m3);
1669 m1 = isl_map_gist(m1, m2);
1670 empty_after = isl_map_is_empty(m3);
1671 isl_map_free(m1);
1672 isl_map_free(m3);
1674 if (empty_before < 0 || empty_after < 0)
1675 return isl_stat_error;
1676 if (empty_before)
1677 isl_die(ctx, isl_error_unknown, "map should not be empty",
1678 return isl_stat_error);
1679 if (empty_after)
1680 isl_die(ctx, isl_error_unknown, "map should still not be empty",
1681 return isl_stat_error);
1683 return isl_stat_ok;
1686 /* Check that computing a gist does not make any copy of the input
1687 * get marked empty.
1688 * Earlier versions of isl would end up doing that on some pairs of inputs.
1690 static isl_stat test_gist_empty(isl_ctx *ctx)
1692 const char *map, *context;
1694 map = "{ [] -> [a, b, c] : 2b = 1 + a }";
1695 context = "{ [] -> [a, b, c] : 2c = 2 + a }";
1696 if (test_gist_empty_pair(ctx, map, context) < 0)
1697 return isl_stat_error;
1698 map = "{ [] -> [0, 0] }";
1699 context = "{ [] -> [a, b] : a > b }";
1700 if (test_gist_empty_pair(ctx, map, context) < 0)
1701 return isl_stat_error;
1703 return isl_stat_ok;
1706 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1708 struct {
1709 const char *map;
1710 const char *context;
1711 const char *gist;
1712 } plain_gist_tests[] = {
1713 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1714 "{ [i] -> [j] : i >= 1 }",
1715 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1716 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1717 "(j mod 4 = 2 and k mod 6 = n) }",
1718 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1719 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1720 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1721 "{ [i] -> [j] : i > j }",
1722 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1725 /* Basic tests for isl_map_plain_gist_basic_map.
1727 static int test_plain_gist(isl_ctx *ctx)
1729 int i;
1731 for (i = 0; i < ARRAY_SIZE(plain_gist_tests); ++i) {
1732 const char *str;
1733 int equal;
1734 isl_map *map, *gist;
1735 isl_basic_map *context;
1737 map = isl_map_read_from_str(ctx, plain_gist_tests[i].map);
1738 str = plain_gist_tests[i].context;
1739 context = isl_basic_map_read_from_str(ctx, str);
1740 map = isl_map_plain_gist_basic_map(map, context);
1741 gist = isl_map_read_from_str(ctx, plain_gist_tests[i].gist);
1742 equal = isl_map_is_equal(map, gist);
1743 isl_map_free(map);
1744 isl_map_free(gist);
1745 if (equal < 0)
1746 return -1;
1747 if (!equal)
1748 isl_die(ctx, isl_error_unknown,
1749 "incorrect gist result", return -1);
1752 return 0;
1755 /* Inputs for isl_basic_set_gist tests that are expected to fail.
1757 struct {
1758 const char *set;
1759 const char *context;
1760 } gist_fail_tests[] = {
1761 { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1762 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1763 "{ [i] : i >= 0 }" },
1766 /* Check that isl_basic_set_gist fails (gracefully) when expected.
1767 * In particular, the user should be able to recover from the failure.
1769 static isl_stat test_gist_fail(struct isl_ctx *ctx)
1771 int i, n;
1772 int on_error;
1774 on_error = isl_options_get_on_error(ctx);
1775 isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE);
1776 n = ARRAY_SIZE(gist_fail_tests);
1777 for (i = 0; i < n; ++i) {
1778 const char *str;
1779 isl_basic_set *bset, *context;
1781 bset = isl_basic_set_read_from_str(ctx, gist_fail_tests[i].set);
1782 str = gist_fail_tests[i].context;
1783 context = isl_basic_set_read_from_str(ctx, str);
1784 bset = isl_basic_set_gist(bset, context);
1785 isl_basic_set_free(bset);
1786 if (bset)
1787 break;
1789 isl_options_set_on_error(ctx, on_error);
1790 if (i < n)
1791 isl_die(ctx, isl_error_unknown,
1792 "operation not expected to succeed",
1793 return isl_stat_error);
1795 return isl_stat_ok;
1798 struct {
1799 const char *set;
1800 const char *context;
1801 const char *gist;
1802 } gist_tests[] = {
1803 { "{ [1, -1, 3] }",
1804 "{ [1, b, 2 - b] : -1 <= b <= 2 }",
1805 "{ [a, -1, c] }" },
1806 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1807 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1808 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1809 "{ [a, b, c] : a <= 15 }" },
1810 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1811 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1812 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1813 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1814 { "{ [m, n, a, b] : a <= 2147 + n }",
1815 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1816 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1817 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1818 "b >= 0) }",
1819 "{ [m, n, ku, kl] }" },
1820 { "{ [a, a, b] : a >= 10 }",
1821 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1822 "{ [a, a, b] : a >= 10 }" },
1823 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1824 "{ [0, j] : j >= 0 }" },
1825 /* Check that no constraints on i6 are introduced in the gist */
1826 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1827 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1828 "5e0 <= 381 - t1 and i4 <= 1) }",
1829 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1830 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1831 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1832 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1833 "20e0 >= 1511 - 4t1 - 5i4) }" },
1834 /* Check that no constraints on i6 are introduced in the gist */
1835 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1836 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1837 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1838 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1839 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1840 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1841 "20e1 <= 1530 - 4t1 - 5i4 and "
1842 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1843 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1844 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1845 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1846 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1847 "10e0 <= -91 + 5i4 + 4i6 and "
1848 "10e0 >= -105 + 5i4 + 4i6) }",
1849 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1850 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1851 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1852 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1853 "{ [a, b, q, p] : b >= 1 + a }",
1854 "{ [a, b, q, p] : false }" },
1855 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1856 "[n] -> { [x] : x mod 32 = 0 }",
1857 "[n] -> { [x = n] }" },
1858 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1859 "{ [x] : x mod 2 = 0 }" },
1860 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1861 "{ [x] : x mod 128 = 0 }" },
1862 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1863 "{ [x] : x mod 3200 = 0 }" },
1864 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1865 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1866 "{ [a, b, c = a] }" },
1867 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1868 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1869 "{ [a, b, c = a] : a mod 3 = 0 }" },
1870 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1871 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1872 "{ [x] }" },
1873 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1874 "{ [x,y] : 1 <= y <= 3 }",
1875 "{ [x,y] }" },
1878 /* Check that isl_set_gist behaves as expected.
1880 * For the test cases in gist_tests, besides checking that the result
1881 * is as expected, also check that applying the gist operation does
1882 * not modify the input set (an earlier version of isl would do that) and
1883 * that the test case is consistent, i.e., that the gist has the same
1884 * intersection with the context as the input set.
1886 static int test_gist(struct isl_ctx *ctx)
1888 int i;
1889 const char *str;
1890 isl_basic_set *bset1, *bset2;
1891 isl_map *map1, *map2;
1892 isl_bool equal;
1893 isl_size n_div;
1895 for (i = 0; i < ARRAY_SIZE(gist_tests); ++i) {
1896 isl_bool equal_input, equal_intersection;
1897 isl_set *set1, *set2, *copy, *context;
1899 set1 = isl_set_read_from_str(ctx, gist_tests[i].set);
1900 context = isl_set_read_from_str(ctx, gist_tests[i].context);
1901 copy = isl_set_copy(set1);
1902 set1 = isl_set_gist(set1, isl_set_copy(context));
1903 set2 = isl_set_read_from_str(ctx, gist_tests[i].gist);
1904 equal = isl_set_is_equal(set1, set2);
1905 isl_set_free(set1);
1906 set1 = isl_set_read_from_str(ctx, gist_tests[i].set);
1907 equal_input = isl_set_is_equal(set1, copy);
1908 isl_set_free(copy);
1909 set1 = isl_set_intersect(set1, isl_set_copy(context));
1910 set2 = isl_set_intersect(set2, context);
1911 equal_intersection = isl_set_is_equal(set1, set2);
1912 isl_set_free(set2);
1913 isl_set_free(set1);
1914 if (equal < 0 || equal_input < 0 || equal_intersection < 0)
1915 return -1;
1916 if (!equal)
1917 isl_die(ctx, isl_error_unknown,
1918 "incorrect gist result", return -1);
1919 if (!equal_input)
1920 isl_die(ctx, isl_error_unknown,
1921 "gist modified input", return -1);
1922 if (!equal_input)
1923 isl_die(ctx, isl_error_unknown,
1924 "inconsistent gist test case", return -1);
1927 if (test_gist_fail(ctx) < 0)
1928 return -1;
1930 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
1931 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1932 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1933 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1934 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1935 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1936 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1937 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1938 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1939 bset1 = isl_basic_set_read_from_str(ctx, str);
1940 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1941 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1942 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1943 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1944 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1945 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1946 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1947 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1948 bset2 = isl_basic_set_read_from_str(ctx, str);
1949 bset1 = isl_basic_set_gist(bset1, bset2);
1950 assert(bset1 && bset1->n_div == 0);
1951 isl_basic_set_free(bset1);
1953 /* Check that the integer divisions of the second disjunct
1954 * do not spread to the first disjunct.
1956 str = "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1957 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1958 "(exists (e0 = [(-1 + t1)/16], "
1959 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1960 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1961 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1962 "o0 <= 4294967295 and t1 <= -1)) }";
1963 map1 = isl_map_read_from_str(ctx, str);
1964 str = "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1965 map2 = isl_map_read_from_str(ctx, str);
1966 map1 = isl_map_gist(map1, map2);
1967 if (!map1)
1968 return -1;
1969 if (map1->n != 1)
1970 isl_die(ctx, isl_error_unknown, "expecting single disjunct",
1971 isl_map_free(map1); return -1);
1972 n_div = isl_basic_map_dim(map1->p[0], isl_dim_div);
1973 isl_map_free(map1);
1974 if (n_div < 0)
1975 return -1;
1976 if (n_div != 1)
1977 isl_die(ctx, isl_error_unknown, "expecting single div",
1978 return -1);
1980 if (test_gist_empty(ctx) < 0)
1981 return -1;
1982 if (test_plain_gist(ctx) < 0)
1983 return -1;
1985 return 0;
1988 int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
1990 isl_set *set, *set2;
1991 int equal;
1992 int one;
1994 set = isl_set_read_from_str(ctx, str);
1995 set = isl_set_coalesce(set);
1996 set2 = isl_set_read_from_str(ctx, str);
1997 equal = isl_set_is_equal(set, set2);
1998 one = set && set->n == 1;
1999 isl_set_free(set);
2000 isl_set_free(set2);
2002 if (equal < 0)
2003 return -1;
2004 if (!equal)
2005 isl_die(ctx, isl_error_unknown,
2006 "coalesced set not equal to input", return -1);
2007 if (check_one && !one)
2008 isl_die(ctx, isl_error_unknown,
2009 "coalesced set should not be a union", return -1);
2011 return 0;
2014 /* Inputs for coalescing tests with unbounded wrapping.
2015 * "str" is a string representation of the input set.
2016 * "single_disjunct" is set if we expect the result to consist of
2017 * a single disjunct.
2019 struct {
2020 int single_disjunct;
2021 const char *str;
2022 } coalesce_unbounded_tests[] = {
2023 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
2024 "-x - y + 1 >= 0 and -3 <= z <= 3;"
2025 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
2026 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
2027 "-10 <= y <= 0}" },
2028 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
2029 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
2030 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
2031 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
2032 { 0, "{ [x, y, z] : 0 <= x,y,z <= 100 and 0 < z <= 2 + 2x + 2y; "
2033 "[x, y, 0] : x,y <= 100 and y <= 9 + 11x and x <= 9 + 11y }" },
2034 { 1, "{ [0:1, 0:1]; [0, 2:3] }" },
2035 { 1, "{ [0:1, 0:1]; [0, 2:3]; [1, -2:-1] }" },
2036 { 1, "{ [0:3, 0:1]; [1:2, 2:5] }" },
2037 { 1, "{ [0:3, 0:1]; [0:2, 2:5] }" },
2038 { 1, "{ [0:3, 0:1]; [1:3, 2:5] }" },
2039 { 0, "{ [0:3, 0:1]; [1:4, 2:5] }" },
2040 { 0, "{ [0:3, 0:1]; [1:5, 2:5] }" },
2043 /* Test the functionality of isl_set_coalesce with the bounded wrapping
2044 * option turned off.
2046 int test_coalesce_unbounded_wrapping(isl_ctx *ctx)
2048 int i;
2049 int r = 0;
2050 int bounded;
2052 bounded = isl_options_get_coalesce_bounded_wrapping(ctx);
2053 isl_options_set_coalesce_bounded_wrapping(ctx, 0);
2055 for (i = 0; i < ARRAY_SIZE(coalesce_unbounded_tests); ++i) {
2056 const char *str = coalesce_unbounded_tests[i].str;
2057 int check_one = coalesce_unbounded_tests[i].single_disjunct;
2058 if (test_coalesce_set(ctx, str, check_one) >= 0)
2059 continue;
2060 r = -1;
2061 break;
2064 isl_options_set_coalesce_bounded_wrapping(ctx, bounded);
2066 return r;
2069 /* Inputs for coalescing tests.
2070 * "str" is a string representation of the input set.
2071 * "single_disjunct" is set if we expect the result to consist of
2072 * a single disjunct.
2074 struct {
2075 int single_disjunct;
2076 const char *str;
2077 } coalesce_tests[] = {
2078 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
2079 "y >= x & x >= 2 & 5 >= y }" },
2080 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2081 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
2082 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2083 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
2084 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2085 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
2086 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2087 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
2088 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2089 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
2090 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
2091 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
2092 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
2093 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
2094 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
2095 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
2096 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
2097 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2098 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2099 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2100 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
2101 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
2102 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
2103 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
2104 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
2105 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2106 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2107 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2108 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
2109 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
2110 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
2111 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
2112 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
2113 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
2114 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
2115 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
2116 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
2117 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
2118 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
2119 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
2120 "[o0, o1, o2, o3, o4, o5, o6]] : "
2121 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
2122 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
2123 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
2124 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
2125 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
2126 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
2127 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
2128 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
2129 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
2130 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
2131 "o6 >= i3 + i6 - o3 and M >= 0 and "
2132 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
2133 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
2134 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
2135 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
2136 "(o0 = 0 and M >= 2 and N >= 3) or "
2137 "(M = 0 and o0 = 0 and N >= 3) }" },
2138 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
2139 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
2140 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
2141 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
2142 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
2143 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
2144 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
2145 "(y = 3 and x = 1) }" },
2146 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
2147 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
2148 "i1 <= M and i3 <= M and i4 <= M) or "
2149 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
2150 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
2151 "i4 <= -1 + M) }" },
2152 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
2153 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
2154 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
2155 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
2156 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
2157 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
2158 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
2159 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
2160 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
2161 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
2162 { 0, "{ [a, b] : exists e : 2e = a and "
2163 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
2164 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
2165 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
2166 "j >= 1 and j' <= i + j - i' and i >= 1; "
2167 "[1, 1, 1, 1] }" },
2168 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
2169 "[i,j] : exists a : j = 3a }" },
2170 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
2171 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
2172 "a >= 3) or "
2173 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
2174 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
2175 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
2176 "c <= 6 + 8a and a >= 3; "
2177 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
2178 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
2179 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2180 "[x,0] : 3 <= x <= 4 }" },
2181 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
2182 "[x,0] : 4 <= x <= 5 }" },
2183 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2184 "[x,0] : 3 <= x <= 5 }" },
2185 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
2186 "[x,0] : 3 <= x <= 4 }" },
2187 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
2188 "i1 <= 0; "
2189 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
2190 { 1, "{ [0,0]; [1,1] }" },
2191 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
2192 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
2193 "ii <= k;"
2194 "[k, 0, k] : k <= 6 and k >= 1 }" },
2195 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
2196 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
2197 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
2198 { 1, "[n] -> { [1] : n >= 0;"
2199 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
2200 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
2201 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
2202 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
2203 "2e0 <= x and 2e0 <= n);"
2204 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
2205 "n >= 0) }" },
2206 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
2207 "128e0 >= -134 + 127t1 and t1 >= 2 and "
2208 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
2209 "t1 = 1 }" },
2210 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
2211 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
2212 "[0, 0] }" },
2213 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
2214 "t1 >= 13 and t1 <= 16);"
2215 "[t1] : t1 <= 15 and t1 >= 12 }" },
2216 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2217 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2218 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2219 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2220 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2221 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2222 "i <= 4j + 2 }" },
2223 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2224 "(exists (e0 : 3e0 = -2 + c0)) }" },
2225 { 0, "[n, b0, t0] -> "
2226 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2227 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2228 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2229 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2230 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2231 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2232 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2233 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2234 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2235 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2236 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2237 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2238 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2239 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2240 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2241 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2242 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2243 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2244 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2245 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2246 { 0, "{ [i0, i1, i2] : "
2247 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2248 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2249 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2250 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2251 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2252 "32e0 <= 31 + i0)) or "
2253 "i0 >= 0 }" },
2254 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2255 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2256 "2*floor((c)/2) = c and 0 <= a <= 192;"
2257 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2259 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2260 "(0 <= a <= b <= n) }" },
2261 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2262 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2263 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2264 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2265 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2266 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2267 "b = 3 and 9e0 <= -19 + 2c)) }" },
2268 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2269 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2270 "(a = 4 and b = 3 and "
2271 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2272 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2273 "(b = -1 + a and 0 < a <= 3 and "
2274 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2275 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2276 "b = 3 and 9e0 <= -19 + 2c)) }" },
2277 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2278 "[1, 0] }" },
2279 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2280 "[0, 1] }" },
2281 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2282 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2283 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2284 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2285 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2286 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2287 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2288 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2289 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2290 { 1, "{ [a] : a <= 8 and "
2291 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2292 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2293 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2294 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2295 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2296 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2297 "(a < 0 and 3*floor((a)/3) < a) }" },
2298 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2299 "(a < -1 and 3*floor((a)/3) < a) }" },
2300 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2301 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2302 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2303 "or (2 <= a <= 15 and b < a)) }" },
2304 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2305 "32*floor((a)/32) < a) or a <= 15) }" },
2306 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2307 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2308 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2309 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2310 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2311 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2312 "S_0[n] : n <= m <= 2 + n }" },
2313 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2314 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2315 "2e0 <= a + b); "
2316 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2317 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2318 "2e0 < -a + 2b) }" },
2319 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2320 "[i, 0, i] : 0 <= i <= 7 }" },
2321 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2322 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2323 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2324 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2325 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2326 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2327 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2328 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2329 "a > 0 and a <= 5) }" },
2330 { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" },
2331 { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and "
2332 "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; "
2333 "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" },
2334 { 0, "{ [0:1, 0:1]; [0, 2:3] }" },
2335 { 1, "{ [a] : (a = 0 or ((1 + a) mod 2 = 0 and 0 < a <= 15) or "
2336 "((a) mod 2 = 0 and 0 < a <= 15)) }" },
2339 /* A specialized coalescing test case that would result
2340 * in a segmentation fault or a failed assertion in earlier versions of isl.
2342 static int test_coalesce_special(struct isl_ctx *ctx)
2344 const char *str;
2345 isl_map *map1, *map2;
2347 str = "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2348 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2349 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2350 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2351 "o1 <= 239 and o1 >= 212)) or "
2352 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2353 "o1 <= 241 and o1 >= 240));"
2354 "[S_L220_OUT[] -> T7[]] -> "
2355 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2356 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2357 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2358 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2359 map1 = isl_map_read_from_str(ctx, str);
2360 map1 = isl_map_align_divs_internal(map1);
2361 map1 = isl_map_coalesce(map1);
2362 str = "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2363 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2364 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2365 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2366 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2367 map2 = isl_map_read_from_str(ctx, str);
2368 map2 = isl_map_union(map2, map1);
2369 map2 = isl_map_align_divs_internal(map2);
2370 map2 = isl_map_coalesce(map2);
2371 isl_map_free(map2);
2372 if (!map2)
2373 return -1;
2375 return 0;
2378 /* A specialized coalescing test case that would result in an assertion
2379 * in an earlier version of isl.
2380 * The explicit call to isl_basic_set_union prevents the implicit
2381 * equality constraints in the first basic map from being detected prior
2382 * to the call to isl_set_coalesce, at least at the point
2383 * where this test case was introduced.
2385 static int test_coalesce_special2(struct isl_ctx *ctx)
2387 const char *str;
2388 isl_basic_set *bset1, *bset2;
2389 isl_set *set;
2391 str = "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2392 bset1 = isl_basic_set_read_from_str(ctx, str);
2393 str = "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2394 bset2 = isl_basic_set_read_from_str(ctx, str);
2395 set = isl_basic_set_union(bset1, bset2);
2396 set = isl_set_coalesce(set);
2397 isl_set_free(set);
2399 if (!set)
2400 return -1;
2401 return 0;
2404 /* Check that calling isl_set_coalesce does not leave other sets
2405 * that may share some information with the input to isl_set_coalesce
2406 * in an inconsistent state.
2407 * In particular, older versions of isl would modify all copies
2408 * of the basic sets in the isl_set_coalesce input in a way
2409 * that could leave them in an inconsistent state.
2410 * The result of printing any other set containing one of these
2411 * basic sets would then result in an invalid set description.
2413 static int test_coalesce_special3(isl_ctx *ctx)
2415 const char *str;
2416 char *s;
2417 isl_set *set1, *set2;
2418 isl_printer *p;
2420 set1 = isl_set_read_from_str(ctx, "{ [0, 0, 0] }");
2421 str = "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2422 set2 = isl_set_read_from_str(ctx, str);
2423 set1 = isl_set_union(set1, isl_set_copy(set2));
2424 set1 = isl_set_coalesce(set1);
2425 isl_set_free(set1);
2427 p = isl_printer_to_str(ctx);
2428 p = isl_printer_print_set(p, set2);
2429 isl_set_free(set2);
2430 s = isl_printer_get_str(p);
2431 isl_printer_free(p);
2432 set1 = isl_set_read_from_str(ctx, s);
2433 free(s);
2434 isl_set_free(set1);
2436 if (!set1)
2437 return -1;
2439 return 0;
2442 /* Check that calling isl_set_coalesce on the intersection of
2443 * the sets described by "s1" and "s2" does not leave other sets
2444 * that may share some information with the input to isl_set_coalesce
2445 * in an inconsistent state.
2446 * In particular, when isl_set_coalesce detects equality constraints,
2447 * it does not immediately perform Gaussian elimination on them,
2448 * but then it needs to ensure that it is performed at some point.
2449 * The input set has implicit equality constraints in the first disjunct.
2450 * It is constructed as an intersection, because otherwise
2451 * those equality constraints would already be detected during parsing.
2453 static isl_stat test_coalesce_intersection(isl_ctx *ctx,
2454 const char *s1, const char *s2)
2456 isl_set *set1, *set2;
2458 set1 = isl_set_read_from_str(ctx, s1);
2459 set2 = isl_set_read_from_str(ctx, s2);
2460 set1 = isl_set_intersect(set1, set2);
2461 isl_set_free(isl_set_coalesce(isl_set_copy(set1)));
2462 set1 = isl_set_coalesce(set1);
2463 isl_set_free(set1);
2465 if (!set1)
2466 return isl_stat_error;
2468 return isl_stat_ok;
2471 /* Check that calling isl_set_coalesce does not leave other sets
2472 * that may share some information with the input to isl_set_coalesce
2473 * in an inconsistent state, for the case where one disjunct
2474 * is a subset of the other.
2476 static isl_stat test_coalesce_special4(isl_ctx *ctx)
2478 const char *s1, *s2;
2480 s1 = "{ [a, b] : b <= 0 or a <= 1 }";
2481 s2 = "{ [a, b] : -1 <= -a < b }";
2482 return test_coalesce_intersection(ctx, s1, s2);
2485 /* Check that calling isl_set_coalesce does not leave other sets
2486 * that may share some information with the input to isl_set_coalesce
2487 * in an inconsistent state, for the case where two disjuncts
2488 * can be fused.
2490 static isl_stat test_coalesce_special5(isl_ctx *ctx)
2492 const char *s1, *s2;
2494 s1 = "{ [a, b, c] : b <= 0 }";
2495 s2 = "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }";
2496 return test_coalesce_intersection(ctx, s1, s2);
2499 /* Check that calling isl_set_coalesce does not leave other sets
2500 * that may share some information with the input to isl_set_coalesce
2501 * in an inconsistent state, for the case where two disjuncts
2502 * can be fused and where both disjuncts have implicit equality constraints.
2504 static isl_stat test_coalesce_special6(isl_ctx *ctx)
2506 const char *s1, *s2;
2508 s1 = "{ [a, b, c] : c <= 0 }";
2509 s2 = "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }";
2510 return test_coalesce_intersection(ctx, s1, s2);
2513 /* Test the functionality of isl_set_coalesce.
2514 * That is, check that the output is always equal to the input
2515 * and in some cases that the result consists of a single disjunct.
2517 static int test_coalesce(struct isl_ctx *ctx)
2519 int i;
2521 for (i = 0; i < ARRAY_SIZE(coalesce_tests); ++i) {
2522 const char *str = coalesce_tests[i].str;
2523 int check_one = coalesce_tests[i].single_disjunct;
2524 if (test_coalesce_set(ctx, str, check_one) < 0)
2525 return -1;
2528 if (test_coalesce_unbounded_wrapping(ctx) < 0)
2529 return -1;
2530 if (test_coalesce_special(ctx) < 0)
2531 return -1;
2532 if (test_coalesce_special2(ctx) < 0)
2533 return -1;
2534 if (test_coalesce_special3(ctx) < 0)
2535 return -1;
2536 if (test_coalesce_special4(ctx) < 0)
2537 return -1;
2538 if (test_coalesce_special5(ctx) < 0)
2539 return -1;
2540 if (test_coalesce_special6(ctx) < 0)
2541 return -1;
2544 return 0;
2547 /* Construct a representation of the graph on the right of Figure 1
2548 * in "Computing the Transitive Closure of a Union of
2549 * Affine Integer Tuple Relations".
2551 static __isl_give isl_map *cocoa_fig_1_right_graph(isl_ctx *ctx)
2553 isl_set *dom;
2554 isl_map *up, *right;
2556 dom = isl_set_read_from_str(ctx,
2557 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2558 "2 x - 3 y + 3 >= 0 }");
2559 right = isl_map_read_from_str(ctx,
2560 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2561 up = isl_map_read_from_str(ctx,
2562 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2563 right = isl_map_intersect_domain(right, isl_set_copy(dom));
2564 right = isl_map_intersect_range(right, isl_set_copy(dom));
2565 up = isl_map_intersect_domain(up, isl_set_copy(dom));
2566 up = isl_map_intersect_range(up, dom);
2567 return isl_map_union(up, right);
2570 /* Construct a representation of the power of the graph
2571 * on the right of Figure 1 in "Computing the Transitive Closure of
2572 * a Union of Affine Integer Tuple Relations".
2574 static __isl_give isl_map *cocoa_fig_1_right_power(isl_ctx *ctx)
2576 return isl_map_read_from_str(ctx,
2577 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2578 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2579 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2582 /* Construct a representation of the transitive closure of the graph
2583 * on the right of Figure 1 in "Computing the Transitive Closure of
2584 * a Union of Affine Integer Tuple Relations".
2586 static __isl_give isl_map *cocoa_fig_1_right_tc(isl_ctx *ctx)
2588 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx)));
2591 static int test_closure(isl_ctx *ctx)
2593 const char *str;
2594 isl_map *map, *map2;
2595 isl_bool exact, equal;
2597 /* COCOA example 1 */
2598 map = isl_map_read_from_str(ctx,
2599 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2600 "1 <= i and i < n and 1 <= j and j < n or "
2601 "i2 = i + 1 and j2 = j - 1 and "
2602 "1 <= i and i < n and 2 <= j and j <= n }");
2603 map = isl_map_power(map, &exact);
2604 assert(exact);
2605 isl_map_free(map);
2607 /* COCOA example 1 */
2608 map = isl_map_read_from_str(ctx,
2609 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2610 "1 <= i and i < n and 1 <= j and j < n or "
2611 "i2 = i + 1 and j2 = j - 1 and "
2612 "1 <= i and i < n and 2 <= j and j <= n }");
2613 map = isl_map_transitive_closure(map, &exact);
2614 assert(exact);
2615 map2 = isl_map_read_from_str(ctx,
2616 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2617 "1 <= i and i < n and 1 <= j and j <= n and "
2618 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2619 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2620 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2621 assert(isl_map_is_equal(map, map2));
2622 isl_map_free(map2);
2623 isl_map_free(map);
2625 map = isl_map_read_from_str(ctx,
2626 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2627 " 0 <= y and y <= n }");
2628 map = isl_map_transitive_closure(map, &exact);
2629 map2 = isl_map_read_from_str(ctx,
2630 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2631 " 0 <= y and y <= n }");
2632 assert(isl_map_is_equal(map, map2));
2633 isl_map_free(map2);
2634 isl_map_free(map);
2636 /* COCOA example 2 */
2637 map = isl_map_read_from_str(ctx,
2638 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2639 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2640 "i2 = i + 2 and j2 = j - 2 and "
2641 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2642 map = isl_map_transitive_closure(map, &exact);
2643 assert(exact);
2644 map2 = isl_map_read_from_str(ctx,
2645 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2646 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2647 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2648 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2649 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2650 assert(isl_map_is_equal(map, map2));
2651 isl_map_free(map);
2652 isl_map_free(map2);
2654 /* COCOA Fig.2 left */
2655 map = isl_map_read_from_str(ctx,
2656 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2657 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2658 "j <= n or "
2659 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2660 "j <= 2 i - 3 and j <= n - 2 or "
2661 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2662 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2663 map = isl_map_transitive_closure(map, &exact);
2664 assert(exact);
2665 isl_map_free(map);
2667 /* COCOA Fig.2 right */
2668 map = isl_map_read_from_str(ctx,
2669 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2670 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2671 "j <= n or "
2672 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2673 "j <= 2 i - 4 and j <= n - 3 or "
2674 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2675 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2676 map = isl_map_power(map, &exact);
2677 assert(exact);
2678 isl_map_free(map);
2680 /* COCOA Fig.2 right */
2681 map = isl_map_read_from_str(ctx,
2682 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2683 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2684 "j <= n or "
2685 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2686 "j <= 2 i - 4 and j <= n - 3 or "
2687 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2688 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2689 map = isl_map_transitive_closure(map, &exact);
2690 assert(exact);
2691 map2 = isl_map_read_from_str(ctx,
2692 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2693 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2694 "j <= n and 3 + i + 2 j <= 3 n and "
2695 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2696 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2697 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2698 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2699 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2700 assert(isl_map_is_equal(map, map2));
2701 isl_map_free(map2);
2702 isl_map_free(map);
2704 map = cocoa_fig_1_right_graph(ctx);
2705 map = isl_map_transitive_closure(map, &exact);
2706 assert(exact);
2707 map2 = cocoa_fig_1_right_tc(ctx);
2708 assert(isl_map_is_equal(map, map2));
2709 isl_map_free(map2);
2710 isl_map_free(map);
2712 map = cocoa_fig_1_right_graph(ctx);
2713 map = isl_map_power(map, &exact);
2714 map2 = cocoa_fig_1_right_power(ctx);
2715 equal = isl_map_is_equal(map, map2);
2716 isl_map_free(map2);
2717 isl_map_free(map);
2718 if (equal < 0)
2719 return -1;
2720 if (!exact)
2721 isl_die(ctx, isl_error_unknown, "power not exact", return -1);
2722 if (!equal)
2723 isl_die(ctx, isl_error_unknown, "unexpected power", return -1);
2725 /* COCOA Theorem 1 counter example */
2726 map = isl_map_read_from_str(ctx,
2727 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2728 "i2 = 1 and j2 = j or "
2729 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2730 map = isl_map_transitive_closure(map, &exact);
2731 assert(exact);
2732 isl_map_free(map);
2734 map = isl_map_read_from_str(ctx,
2735 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2736 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2737 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2738 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2739 map = isl_map_transitive_closure(map, &exact);
2740 assert(exact);
2741 isl_map_free(map);
2743 /* Kelly et al 1996, fig 12 */
2744 map = isl_map_read_from_str(ctx,
2745 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2746 "1 <= i,j,j+1 <= n or "
2747 "j = n and j2 = 1 and i2 = i + 1 and "
2748 "1 <= i,i+1 <= n }");
2749 map = isl_map_transitive_closure(map, &exact);
2750 assert(exact);
2751 map2 = isl_map_read_from_str(ctx,
2752 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2753 "1 <= i <= n and i = i2 or "
2754 "1 <= i < i2 <= n and 1 <= j <= n and "
2755 "1 <= j2 <= n }");
2756 assert(isl_map_is_equal(map, map2));
2757 isl_map_free(map2);
2758 isl_map_free(map);
2760 /* Omega's closure4 */
2761 map = isl_map_read_from_str(ctx,
2762 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2763 "1 <= x,y <= 10 or "
2764 "x2 = x + 1 and y2 = y and "
2765 "1 <= x <= 20 && 5 <= y <= 15 }");
2766 map = isl_map_transitive_closure(map, &exact);
2767 assert(exact);
2768 isl_map_free(map);
2770 map = isl_map_read_from_str(ctx,
2771 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2772 map = isl_map_transitive_closure(map, &exact);
2773 assert(!exact);
2774 map2 = isl_map_read_from_str(ctx,
2775 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2776 assert(isl_map_is_equal(map, map2));
2777 isl_map_free(map);
2778 isl_map_free(map2);
2780 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2781 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2782 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2783 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2784 map = isl_map_read_from_str(ctx, str);
2785 map = isl_map_transitive_closure(map, &exact);
2786 assert(exact);
2787 map2 = isl_map_read_from_str(ctx, str);
2788 assert(isl_map_is_equal(map, map2));
2789 isl_map_free(map);
2790 isl_map_free(map2);
2792 str = "{[0] -> [1]; [2] -> [3]}";
2793 map = isl_map_read_from_str(ctx, str);
2794 map = isl_map_transitive_closure(map, &exact);
2795 assert(exact);
2796 map2 = isl_map_read_from_str(ctx, str);
2797 assert(isl_map_is_equal(map, map2));
2798 isl_map_free(map);
2799 isl_map_free(map2);
2801 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2802 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2803 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2804 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2805 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2806 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2807 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2808 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2809 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2810 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2811 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2812 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2813 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2814 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2815 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2816 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2817 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2818 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2819 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2820 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2821 map = isl_map_read_from_str(ctx, str);
2822 map = isl_map_transitive_closure(map, NULL);
2823 assert(map);
2824 isl_map_free(map);
2826 return 0;
2829 /* Check that the actual result of a boolean operation is equal
2830 * to the expected result.
2832 static isl_stat check_bool(isl_ctx *ctx, isl_bool actual, isl_bool expected)
2834 if (actual != expected)
2835 isl_die(ctx, isl_error_unknown,
2836 "incorrect boolean operation", return isl_stat_error);
2837 return isl_stat_ok;
2840 /* Test operations on isl_bool values.
2842 * This tests:
2844 * isl_bool_not
2845 * isl_bool_ok
2847 static int test_isl_bool(isl_ctx *ctx)
2849 if (check_bool(ctx, isl_bool_not(isl_bool_true), isl_bool_false) < 0)
2850 return -1;
2851 if (check_bool(ctx, isl_bool_not(isl_bool_false), isl_bool_true) < 0)
2852 return -1;
2853 if (check_bool(ctx, isl_bool_not(isl_bool_error), isl_bool_error) < 0)
2854 return -1;
2855 if (check_bool(ctx, isl_bool_ok(0), isl_bool_false) < 0)
2856 return -1;
2857 if (check_bool(ctx, isl_bool_ok(1), isl_bool_true) < 0)
2858 return -1;
2859 if (check_bool(ctx, isl_bool_ok(-1), isl_bool_true) < 0)
2860 return -1;
2861 if (check_bool(ctx, isl_bool_ok(2), isl_bool_true) < 0)
2862 return -1;
2863 if (check_bool(ctx, isl_bool_ok(-2), isl_bool_true) < 0)
2864 return -1;
2866 return 0;
2869 static int test_lex(struct isl_ctx *ctx)
2871 isl_space *space;
2872 isl_map *map;
2873 int empty;
2875 space = isl_space_set_alloc(ctx, 0, 0);
2876 map = isl_map_lex_le(space);
2877 empty = isl_map_is_empty(map);
2878 isl_map_free(map);
2880 if (empty < 0)
2881 return -1;
2882 if (empty)
2883 isl_die(ctx, isl_error_unknown,
2884 "expecting non-empty result", return -1);
2886 return 0;
2889 /* Inputs for isl_map_lexmin tests.
2890 * "map" is the input and "lexmin" is the expected result.
2892 struct {
2893 const char *map;
2894 const char *lexmin;
2895 } lexmin_tests [] = {
2896 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2897 "{ [x] -> [5] : 6 <= x <= 8; "
2898 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2899 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2900 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2901 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2902 "{ [x] -> [y] : (4y = x and x >= 0) or "
2903 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2904 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2905 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2906 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2907 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2908 /* Check that empty pieces are properly combined. */
2909 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2910 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2911 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2912 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2913 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2914 "x >= 4 }" },
2915 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2916 "a <= 255 and c <= 255 and d <= 255 - j and "
2917 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2918 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2919 "247d <= 247 + i and 248 - b <= 248d <= c and "
2920 "254d >= i - a + b and 254d >= -a + b and "
2921 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2922 "{ [i, k, j] -> "
2923 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2924 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2925 "247j >= 62738 - i and 509j <= 129795 + i and "
2926 "742j >= 188724 - i; "
2927 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2928 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2929 "16*floor((8 + b)/16) <= 7 + b; "
2930 "[a] -> [1] }",
2931 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2932 "[a] -> [b = 0] : 0 < a <= 509 }" },
2933 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2934 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2935 { "{ rat: [i] : 21 <= 2i <= 29 or i = 5 }", "{ rat: [5] }" },
2938 static int test_lexmin(struct isl_ctx *ctx)
2940 int i;
2941 int equal;
2942 const char *str;
2943 isl_basic_map *bmap;
2944 isl_map *map, *map2;
2945 isl_set *set;
2946 isl_set *set2;
2947 isl_pw_multi_aff *pma;
2949 str = "[p0, p1] -> { [] -> [] : "
2950 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2951 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2952 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2953 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2954 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2955 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2956 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2957 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2958 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2959 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2960 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2961 map = isl_map_read_from_str(ctx, str);
2962 map = isl_map_lexmin(map);
2963 isl_map_free(map);
2964 if (!map)
2965 return -1;
2967 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2968 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2969 set = isl_set_read_from_str(ctx, str);
2970 set = isl_set_lexmax(set);
2971 str = "[C] -> { [obj,a,b,c] : C = 8 }";
2972 set2 = isl_set_read_from_str(ctx, str);
2973 set = isl_set_intersect(set, set2);
2974 assert(!isl_set_is_empty(set));
2975 isl_set_free(set);
2977 for (i = 0; i < ARRAY_SIZE(lexmin_tests); ++i) {
2978 map = isl_map_read_from_str(ctx, lexmin_tests[i].map);
2979 map = isl_map_lexmin(map);
2980 map2 = isl_map_read_from_str(ctx, lexmin_tests[i].lexmin);
2981 equal = isl_map_is_equal(map, map2);
2982 isl_map_free(map);
2983 isl_map_free(map2);
2985 if (equal < 0)
2986 return -1;
2987 if (!equal)
2988 isl_die(ctx, isl_error_unknown,
2989 "unexpected result", return -1);
2992 str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2993 " 8i' <= i and 8i' >= -7 + i }";
2994 bmap = isl_basic_map_read_from_str(ctx, str);
2995 pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap));
2996 map2 = isl_map_from_pw_multi_aff(pma);
2997 map = isl_map_from_basic_map(bmap);
2998 assert(isl_map_is_equal(map, map2));
2999 isl_map_free(map);
3000 isl_map_free(map2);
3002 str = "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3003 " 8i' <= i and 8i' >= -7 + i }";
3004 set = isl_set_read_from_str(ctx, str);
3005 pma = isl_set_lexmin_pw_multi_aff(isl_set_copy(set));
3006 set2 = isl_set_from_pw_multi_aff(pma);
3007 equal = isl_set_is_equal(set, set2);
3008 isl_set_free(set);
3009 isl_set_free(set2);
3010 if (equal < 0)
3011 return -1;
3012 if (!equal)
3013 isl_die(ctx, isl_error_unknown,
3014 "unexpected difference between set and "
3015 "piecewise affine expression", return -1);
3017 return 0;
3020 /* Inputs for isl_pw_multi_aff_max_multi_val tests.
3021 * "pma" is the input.
3022 * "res" is the expected result.
3024 static struct {
3025 const char *pma;
3026 const char *res;
3027 } opt_pw_tests[] = {
3028 { "{ [-1] -> [-1]; [1] -> [1] }", "{ [1] }" },
3029 { "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] : "
3030 "0 <= a, b <= 100 and b mod 2 = 0}", "{ [30] }" },
3031 { "[N] -> { [i,j] -> A[i, -i, i + j] : 0 <= i,j <= N <= 10 }",
3032 "{ A[10, 0, 20] }" },
3033 { "[N] -> {A[N, -N, 2N] : 0 <= N }", "{ A[infty, 0, infty] }" },
3036 /* Perform basic isl_pw_multi_aff_max_multi_val tests.
3038 static isl_stat test_pw_max(struct isl_ctx *ctx)
3040 int i;
3041 isl_pw_multi_aff *pma;
3042 isl_multi_val *mv;
3043 isl_stat r;
3045 for (i = 0; i < ARRAY_SIZE(opt_pw_tests); ++i) {
3046 pma = isl_pw_multi_aff_read_from_str(ctx, opt_pw_tests[i].pma);
3047 mv = isl_pw_multi_aff_max_multi_val(pma);
3048 r = multi_val_check_plain_equal(mv, opt_pw_tests[i].res);
3049 isl_multi_val_free(mv);
3051 if (r < 0)
3052 return isl_stat_error;
3055 return isl_stat_ok;
3058 /* A specialized isl_set_min_val test case that would return the wrong result
3059 * in earlier versions of isl.
3060 * The explicit call to isl_basic_set_union prevents the second basic set
3061 * from being determined to be empty prior to the call to isl_set_min_val,
3062 * at least at the point where this test case was introduced.
3064 static int test_min_special(isl_ctx *ctx)
3066 const char *str;
3067 isl_basic_set *bset1, *bset2;
3068 isl_set *set;
3069 isl_aff *obj;
3070 isl_val *res;
3071 int ok;
3073 str = "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
3074 bset1 = isl_basic_set_read_from_str(ctx, str);
3075 str = "{ [a, b] : 1 <= a, b and a + b <= 1 }";
3076 bset2 = isl_basic_set_read_from_str(ctx, str);
3077 set = isl_basic_set_union(bset1, bset2);
3078 obj = isl_aff_read_from_str(ctx, "{ [a, b] -> [a] }");
3080 res = isl_set_min_val(set, obj);
3081 ok = isl_val_cmp_si(res, 5) == 0;
3083 isl_aff_free(obj);
3084 isl_set_free(set);
3085 isl_val_free(res);
3087 if (!res)
3088 return -1;
3089 if (!ok)
3090 isl_die(ctx, isl_error_unknown, "unexpected minimum",
3091 return -1);
3093 return 0;
3096 /* A specialized isl_set_min_val test case that would return an error
3097 * in earlier versions of isl.
3099 static int test_min_special2(isl_ctx *ctx)
3101 const char *str;
3102 isl_basic_set *bset;
3103 isl_aff *obj;
3104 isl_val *res;
3106 str = "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
3107 bset = isl_basic_set_read_from_str(ctx, str);
3109 obj = isl_aff_read_from_str(ctx, "{ [i, j, k] -> [i] }");
3111 res = isl_basic_set_max_val(bset, obj);
3113 isl_basic_set_free(bset);
3114 isl_aff_free(obj);
3115 isl_val_free(res);
3117 if (!res)
3118 return -1;
3120 return 0;
3123 /* Check that the result of isl_set_min_multi_pw_aff
3124 * on the union of the sets with string descriptions "s1" and "s2"
3125 * consists of a single expression (on a single cell).
3127 static isl_stat check_single_expr_min(isl_ctx *ctx, const char *s1,
3128 const char *s2)
3130 isl_size n;
3131 isl_set *set1, *set2;
3132 isl_multi_pw_aff *mpa;
3133 isl_pw_multi_aff *pma;
3135 set1 = isl_set_read_from_str(ctx, s1);
3136 set2 = isl_set_read_from_str(ctx, s2);
3137 set1 = isl_set_union(set1, set2);
3138 mpa = isl_set_min_multi_pw_aff(set1);
3139 pma = isl_pw_multi_aff_from_multi_pw_aff(mpa);
3140 n = isl_pw_multi_aff_n_piece(pma);
3141 isl_pw_multi_aff_free(pma);
3143 if (n < 0)
3144 return isl_stat_error;
3145 if (n != 1)
3146 isl_die(ctx, isl_error_unknown, "expecting single expression",
3147 return isl_stat_error);
3148 return isl_stat_ok;
3151 /* A specialized isl_set_min_multi_pw_aff test that checks
3152 * that the minimum of 2N and 3N for N >= 0 is represented
3153 * by a single expression, without splitting off the special case N = 0.
3154 * Do this for both orderings.
3156 static int test_min_mpa(isl_ctx *ctx)
3158 const char *s1, *s2;
3160 s1 = "[N=0:] -> { [1, 3N:] }";
3161 s2 = "[N=0:] -> { [10, 2N:] }";
3162 if (check_single_expr_min(ctx, s1, s2) < 0)
3163 return -1;
3164 if (check_single_expr_min(ctx, s2, s1) < 0)
3165 return -1;
3167 return 0;
3170 struct {
3171 const char *set;
3172 const char *obj;
3173 __isl_give isl_val *(*fn)(__isl_keep isl_set *set,
3174 __isl_keep isl_aff *obj);
3175 const char *res;
3176 } opt_tests[] = {
3177 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val, "-1" },
3178 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val, "1" },
3179 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
3180 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
3181 &isl_set_max_val, "30" },
3185 /* Perform basic isl_set_min_val and isl_set_max_val tests.
3186 * In particular, check the results on non-convex inputs.
3188 static int test_min(struct isl_ctx *ctx)
3190 int i;
3191 isl_set *set;
3192 isl_aff *obj;
3193 isl_val *val, *res;
3194 isl_bool ok;
3196 for (i = 0; i < ARRAY_SIZE(opt_tests); ++i) {
3197 set = isl_set_read_from_str(ctx, opt_tests[i].set);
3198 obj = isl_aff_read_from_str(ctx, opt_tests[i].obj);
3199 res = isl_val_read_from_str(ctx, opt_tests[i].res);
3200 val = opt_tests[i].fn(set, obj);
3201 ok = isl_val_eq(res, val);
3202 isl_val_free(res);
3203 isl_val_free(val);
3204 isl_aff_free(obj);
3205 isl_set_free(set);
3207 if (ok < 0)
3208 return -1;
3209 if (!ok)
3210 isl_die(ctx, isl_error_unknown,
3211 "unexpected optimum", return -1);
3214 if (test_pw_max(ctx) < 0)
3215 return -1;
3216 if (test_min_special(ctx) < 0)
3217 return -1;
3218 if (test_min_special2(ctx) < 0)
3219 return -1;
3221 return 0;
3224 struct must_may {
3225 isl_map *must;
3226 isl_map *may;
3229 static isl_stat collect_must_may(__isl_take isl_map *dep, int must,
3230 void *dep_user, void *user)
3232 struct must_may *mm = (struct must_may *)user;
3234 if (must)
3235 mm->must = isl_map_union(mm->must, dep);
3236 else
3237 mm->may = isl_map_union(mm->may, dep);
3239 return isl_stat_ok;
3242 static int common_space(void *first, void *second)
3244 int depth = *(int *)first;
3245 return 2 * depth;
3248 static int map_is_equal(__isl_keep isl_map *map, const char *str)
3250 isl_map *map2;
3251 int equal;
3253 if (!map)
3254 return -1;
3256 map2 = isl_map_read_from_str(map->ctx, str);
3257 equal = isl_map_is_equal(map, map2);
3258 isl_map_free(map2);
3260 return equal;
3263 static int map_check_equal(__isl_keep isl_map *map, const char *str)
3265 int equal;
3267 equal = map_is_equal(map, str);
3268 if (equal < 0)
3269 return -1;
3270 if (!equal)
3271 isl_die(isl_map_get_ctx(map), isl_error_unknown,
3272 "result not as expected", return -1);
3273 return 0;
3276 /* Is "set" equal to the set described by "str"?
3278 static isl_bool set_is_equal(__isl_keep isl_set *set, const char *str)
3280 isl_set *set2;
3281 isl_bool equal;
3283 if (!set)
3284 return isl_bool_error;
3286 set2 = isl_set_read_from_str(isl_set_get_ctx(set), str);
3287 equal = isl_set_is_equal(set, set2);
3288 isl_set_free(set2);
3290 return equal;
3293 /* Check that "set" is equal to the set described by "str".
3295 static isl_stat set_check_equal(__isl_keep isl_set *set, const char *str)
3297 isl_bool equal;
3299 equal = set_is_equal(set, str);
3300 if (equal < 0)
3301 return isl_stat_error;
3302 if (!equal)
3303 isl_die(isl_set_get_ctx(set), isl_error_unknown,
3304 "result not as expected", return isl_stat_error);
3305 return isl_stat_ok;
3308 /* Is "uset" equal to the union set described by "str"?
3310 static isl_bool uset_is_equal(__isl_keep isl_union_set *uset, const char *str)
3312 isl_union_set *uset2;
3313 isl_bool equal;
3315 if (!uset)
3316 return isl_bool_error;
3318 uset2 = isl_union_set_read_from_str(isl_union_set_get_ctx(uset), str);
3319 equal = isl_union_set_is_equal(uset, uset2);
3320 isl_union_set_free(uset2);
3322 return equal;
3325 /* Check that "uset" is equal to the union set described by "str".
3327 static isl_stat uset_check_equal(__isl_keep isl_union_set *uset,
3328 const char *str)
3330 isl_bool equal;
3332 equal = uset_is_equal(uset, str);
3333 if (equal < 0)
3334 return isl_stat_error;
3335 if (!equal)
3336 isl_die(isl_union_set_get_ctx(uset), isl_error_unknown,
3337 "result not as expected", return isl_stat_error);
3338 return isl_stat_ok;
3341 static int test_dep(struct isl_ctx *ctx)
3343 const char *str;
3344 isl_space *space;
3345 isl_map *map;
3346 isl_access_info *ai;
3347 isl_flow *flow;
3348 int depth;
3349 struct must_may mm;
3351 depth = 3;
3353 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3354 map = isl_map_read_from_str(ctx, str);
3355 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3357 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3358 map = isl_map_read_from_str(ctx, str);
3359 ai = isl_access_info_add_source(ai, map, 1, &depth);
3361 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3362 map = isl_map_read_from_str(ctx, str);
3363 ai = isl_access_info_add_source(ai, map, 1, &depth);
3365 flow = isl_access_info_compute_flow(ai);
3366 space = isl_space_alloc(ctx, 0, 3, 3);
3367 mm.must = isl_map_empty(isl_space_copy(space));
3368 mm.may = isl_map_empty(space);
3370 isl_flow_foreach(flow, collect_must_may, &mm);
3372 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
3373 " [1,10,0] -> [2,5,0] }";
3374 assert(map_is_equal(mm.must, str));
3375 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3376 assert(map_is_equal(mm.may, str));
3378 isl_map_free(mm.must);
3379 isl_map_free(mm.may);
3380 isl_flow_free(flow);
3383 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3384 map = isl_map_read_from_str(ctx, str);
3385 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3387 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3388 map = isl_map_read_from_str(ctx, str);
3389 ai = isl_access_info_add_source(ai, map, 1, &depth);
3391 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3392 map = isl_map_read_from_str(ctx, str);
3393 ai = isl_access_info_add_source(ai, map, 0, &depth);
3395 flow = isl_access_info_compute_flow(ai);
3396 space = isl_space_alloc(ctx, 0, 3, 3);
3397 mm.must = isl_map_empty(isl_space_copy(space));
3398 mm.may = isl_map_empty(space);
3400 isl_flow_foreach(flow, collect_must_may, &mm);
3402 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
3403 assert(map_is_equal(mm.must, str));
3404 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3405 assert(map_is_equal(mm.may, str));
3407 isl_map_free(mm.must);
3408 isl_map_free(mm.may);
3409 isl_flow_free(flow);
3412 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3413 map = isl_map_read_from_str(ctx, str);
3414 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3416 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3417 map = isl_map_read_from_str(ctx, str);
3418 ai = isl_access_info_add_source(ai, map, 0, &depth);
3420 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3421 map = isl_map_read_from_str(ctx, str);
3422 ai = isl_access_info_add_source(ai, map, 0, &depth);
3424 flow = isl_access_info_compute_flow(ai);
3425 space = isl_space_alloc(ctx, 0, 3, 3);
3426 mm.must = isl_map_empty(isl_space_copy(space));
3427 mm.may = isl_map_empty(space);
3429 isl_flow_foreach(flow, collect_must_may, &mm);
3431 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
3432 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3433 assert(map_is_equal(mm.may, str));
3434 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3435 assert(map_is_equal(mm.must, str));
3437 isl_map_free(mm.must);
3438 isl_map_free(mm.may);
3439 isl_flow_free(flow);
3442 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
3443 map = isl_map_read_from_str(ctx, str);
3444 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3446 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3447 map = isl_map_read_from_str(ctx, str);
3448 ai = isl_access_info_add_source(ai, map, 0, &depth);
3450 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3451 map = isl_map_read_from_str(ctx, str);
3452 ai = isl_access_info_add_source(ai, map, 0, &depth);
3454 flow = isl_access_info_compute_flow(ai);
3455 space = isl_space_alloc(ctx, 0, 3, 3);
3456 mm.must = isl_map_empty(isl_space_copy(space));
3457 mm.may = isl_map_empty(space);
3459 isl_flow_foreach(flow, collect_must_may, &mm);
3461 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3462 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3463 assert(map_is_equal(mm.may, str));
3464 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3465 assert(map_is_equal(mm.must, str));
3467 isl_map_free(mm.must);
3468 isl_map_free(mm.may);
3469 isl_flow_free(flow);
3472 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3473 map = isl_map_read_from_str(ctx, str);
3474 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3476 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3477 map = isl_map_read_from_str(ctx, str);
3478 ai = isl_access_info_add_source(ai, map, 0, &depth);
3480 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3481 map = isl_map_read_from_str(ctx, str);
3482 ai = isl_access_info_add_source(ai, map, 0, &depth);
3484 flow = isl_access_info_compute_flow(ai);
3485 space = isl_space_alloc(ctx, 0, 3, 3);
3486 mm.must = isl_map_empty(isl_space_copy(space));
3487 mm.may = isl_map_empty(space);
3489 isl_flow_foreach(flow, collect_must_may, &mm);
3491 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3492 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3493 assert(map_is_equal(mm.may, str));
3494 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3495 assert(map_is_equal(mm.must, str));
3497 isl_map_free(mm.must);
3498 isl_map_free(mm.may);
3499 isl_flow_free(flow);
3502 depth = 5;
3504 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3505 map = isl_map_read_from_str(ctx, str);
3506 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
3508 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3509 map = isl_map_read_from_str(ctx, str);
3510 ai = isl_access_info_add_source(ai, map, 1, &depth);
3512 flow = isl_access_info_compute_flow(ai);
3513 space = isl_space_alloc(ctx, 0, 5, 5);
3514 mm.must = isl_map_empty(isl_space_copy(space));
3515 mm.may = isl_map_empty(space);
3517 isl_flow_foreach(flow, collect_must_may, &mm);
3519 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3520 assert(map_is_equal(mm.must, str));
3521 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3522 assert(map_is_equal(mm.may, str));
3524 isl_map_free(mm.must);
3525 isl_map_free(mm.may);
3526 isl_flow_free(flow);
3528 return 0;
3531 /* Check that the dependence analysis proceeds without errors.
3532 * Earlier versions of isl would break down during the analysis
3533 * due to the use of the wrong spaces.
3535 static int test_flow(isl_ctx *ctx)
3537 const char *str;
3538 isl_union_map *access, *schedule;
3539 isl_union_map *must_dep, *may_dep;
3540 int r;
3542 str = "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3543 access = isl_union_map_read_from_str(ctx, str);
3544 str = "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3545 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3546 "S2[] -> [1,0,0,0]; "
3547 "S3[] -> [-1,0,0,0] }";
3548 schedule = isl_union_map_read_from_str(ctx, str);
3549 r = isl_union_map_compute_flow(access, isl_union_map_copy(access),
3550 isl_union_map_copy(access), schedule,
3551 &must_dep, &may_dep, NULL, NULL);
3552 isl_union_map_free(may_dep);
3553 isl_union_map_free(must_dep);
3555 return r;
3558 struct {
3559 const char *map;
3560 int sv;
3561 } sv_tests[] = {
3562 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3563 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3564 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3565 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3566 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3567 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3568 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3569 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3570 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3573 int test_sv(isl_ctx *ctx)
3575 isl_union_map *umap;
3576 int i;
3577 int sv;
3579 for (i = 0; i < ARRAY_SIZE(sv_tests); ++i) {
3580 umap = isl_union_map_read_from_str(ctx, sv_tests[i].map);
3581 sv = isl_union_map_is_single_valued(umap);
3582 isl_union_map_free(umap);
3583 if (sv < 0)
3584 return -1;
3585 if (sv_tests[i].sv && !sv)
3586 isl_die(ctx, isl_error_internal,
3587 "map not detected as single valued", return -1);
3588 if (!sv_tests[i].sv && sv)
3589 isl_die(ctx, isl_error_internal,
3590 "map detected as single valued", return -1);
3593 return 0;
3596 struct {
3597 const char *str;
3598 int bijective;
3599 } bijective_tests[] = {
3600 { "[N,M]->{[i,j] -> [i]}", 0 },
3601 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3602 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3603 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3604 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3605 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3606 { "[N,M]->{[i,j] -> []}", 0 },
3607 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3608 { "[N,M]->{[i,j] -> [2i]}", 0 },
3609 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3610 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3611 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3612 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3615 static int test_bijective(struct isl_ctx *ctx)
3617 isl_map *map;
3618 int i;
3619 int bijective;
3621 for (i = 0; i < ARRAY_SIZE(bijective_tests); ++i) {
3622 map = isl_map_read_from_str(ctx, bijective_tests[i].str);
3623 bijective = isl_map_is_bijective(map);
3624 isl_map_free(map);
3625 if (bijective < 0)
3626 return -1;
3627 if (bijective_tests[i].bijective && !bijective)
3628 isl_die(ctx, isl_error_internal,
3629 "map not detected as bijective", return -1);
3630 if (!bijective_tests[i].bijective && bijective)
3631 isl_die(ctx, isl_error_internal,
3632 "map detected as bijective", return -1);
3635 return 0;
3638 /* Inputs for isl_pw_qpolynomial_gist tests.
3639 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3641 struct {
3642 const char *pwqp;
3643 const char *set;
3644 const char *gist;
3645 } pwqp_gist_tests[] = {
3646 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3647 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3648 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3649 "{ [i] -> -1/2 + 1/2 * i }" },
3650 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3653 /* Perform some basic isl_pw_qpolynomial_gist tests.
3655 static isl_stat test_pwqp_gist(isl_ctx *ctx)
3657 int i;
3658 const char *str;
3659 isl_set *set;
3660 isl_pw_qpolynomial *pwqp1, *pwqp2;
3661 isl_bool equal;
3663 for (i = 0; i < ARRAY_SIZE(pwqp_gist_tests); ++i) {
3664 str = pwqp_gist_tests[i].pwqp;
3665 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3666 str = pwqp_gist_tests[i].set;
3667 set = isl_set_read_from_str(ctx, str);
3668 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
3669 str = pwqp_gist_tests[i].gist;
3670 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3671 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3672 equal = isl_pw_qpolynomial_is_zero(pwqp1);
3673 isl_pw_qpolynomial_free(pwqp1);
3675 if (equal < 0)
3676 return isl_stat_error;
3677 if (!equal)
3678 isl_die(ctx, isl_error_unknown,
3679 "unexpected result", return isl_stat_error);
3682 return isl_stat_ok;
3685 /* Perform a basic isl_pw_qpolynomial_max test.
3687 static isl_stat test_pwqp_max(isl_ctx *ctx)
3689 const char *str;
3690 isl_pw_qpolynomial *pwqp;
3691 isl_val *v;
3692 int ok;
3694 str = "{ [x=2:9, y] -> floor((x + 1)/4)^3 - floor((2x)/3)^2 }";
3695 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3696 v = isl_pw_qpolynomial_max(pwqp);
3697 ok = isl_val_cmp_si(v, -1) == 0;
3698 isl_val_free(v);
3700 if (!v)
3701 return isl_stat_error;
3702 if (!ok)
3703 isl_die(ctx, isl_error_unknown, "unexpected maximum",
3704 return isl_stat_error);
3706 return isl_stat_ok;
3709 static int test_pwqp(struct isl_ctx *ctx)
3711 const char *str;
3712 isl_set *set;
3713 isl_pw_qpolynomial *pwqp1, *pwqp2;
3714 int equal;
3716 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3717 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3719 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
3720 isl_dim_in, 1, 1);
3722 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3723 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3725 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3727 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3729 isl_pw_qpolynomial_free(pwqp1);
3731 if (test_pwqp_gist(ctx) < 0)
3732 return -1;
3734 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
3735 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3736 str = "{ [i] -> ([(2 * [i/2])/5]) }";
3737 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3739 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3741 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3743 isl_pw_qpolynomial_free(pwqp1);
3745 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
3746 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3747 str = "{ [x] -> x }";
3748 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3750 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3752 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3754 isl_pw_qpolynomial_free(pwqp1);
3756 str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3757 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3758 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3759 pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
3760 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3761 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3762 isl_pw_qpolynomial_free(pwqp1);
3764 str = "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3765 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3766 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3767 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3768 set = isl_set_read_from_str(ctx, "{ [a,b,a] }");
3769 pwqp1 = isl_pw_qpolynomial_intersect_domain(pwqp1, set);
3770 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
3771 isl_pw_qpolynomial_free(pwqp1);
3772 isl_pw_qpolynomial_free(pwqp2);
3773 if (equal < 0)
3774 return -1;
3775 if (!equal)
3776 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3778 str = "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3779 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3780 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3781 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3782 pwqp1 = isl_pw_qpolynomial_fix_val(pwqp1, isl_dim_set, 1,
3783 isl_val_one(ctx));
3784 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
3785 isl_pw_qpolynomial_free(pwqp1);
3786 isl_pw_qpolynomial_free(pwqp2);
3787 if (equal < 0)
3788 return -1;
3789 if (!equal)
3790 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3792 if (test_pwqp_max(ctx) < 0)
3793 return -1;
3795 return 0;
3798 static int test_split_periods(isl_ctx *ctx)
3800 const char *str;
3801 isl_pw_qpolynomial *pwqp;
3803 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3804 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3805 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3806 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3808 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
3810 isl_pw_qpolynomial_free(pwqp);
3812 if (!pwqp)
3813 return -1;
3815 return 0;
3818 static int test_union(isl_ctx *ctx)
3820 const char *str;
3821 isl_union_set *uset1, *uset2;
3822 isl_union_map *umap1, *umap2;
3823 int equal;
3825 str = "{ [i] : 0 <= i <= 1 }";
3826 uset1 = isl_union_set_read_from_str(ctx, str);
3827 str = "{ [1] -> [0] }";
3828 umap1 = isl_union_map_read_from_str(ctx, str);
3830 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
3831 equal = isl_union_map_is_equal(umap1, umap2);
3833 isl_union_map_free(umap1);
3834 isl_union_map_free(umap2);
3836 if (equal < 0)
3837 return -1;
3838 if (!equal)
3839 isl_die(ctx, isl_error_unknown, "union maps not equal",
3840 return -1);
3842 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3843 umap1 = isl_union_map_read_from_str(ctx, str);
3844 str = "{ A[i]; B[i] }";
3845 uset1 = isl_union_set_read_from_str(ctx, str);
3847 uset2 = isl_union_map_domain(umap1);
3849 equal = isl_union_set_is_equal(uset1, uset2);
3851 isl_union_set_free(uset1);
3852 isl_union_set_free(uset2);
3854 if (equal < 0)
3855 return -1;
3856 if (!equal)
3857 isl_die(ctx, isl_error_unknown, "union sets not equal",
3858 return -1);
3860 return 0;
3863 /* Inputs for basic isl_pw_qpolynomial_bound tests.
3864 * "type" is the type of bound that should be computed.
3865 * "poly" is a string representation of the input.
3866 * "bound" is a string representation of the expected result.
3867 * "tight" is set if the result is expected to be tight.
3869 static struct {
3870 int tight;
3871 enum isl_fold type;
3872 const char *poly;
3873 const char *bound;
3874 } bound_tests[] = {
3875 /* Check that computing a bound of a non-zero polynomial
3876 * over an unbounded domain does not produce a rational value.
3877 * In particular, check that the upper bound is infinity.
3879 { 0, isl_fold_max, "{ [m, n] -> -m * n }", "{ max(infty) }" },
3880 { 1, isl_fold_max, "{ [[a, b, c, d] -> [e]] -> 0 }",
3881 "{ [a, b, c, d] -> max(0) }" },
3882 { 1, isl_fold_max, "{ [[x] -> [x]] -> 1 : exists a : x = 2 a }",
3883 "{ [x] -> max(1) : x mod 2 = 0 }" },
3884 { 1, isl_fold_min, "{ [x=5:10] -> (x + 2)^2 }", "{ min(49) }" },
3885 { 1, isl_fold_max, "{ [0:10] -> 1 }", "{ max(1) }" },
3886 { 1, isl_fold_max, "{ [[m] -> [0:m]] -> m^2 }",
3887 "{ [m] -> max(m^2) : m >= 0 }" },
3890 /* Check that the bound computation can handle differences
3891 * in domain dimension names of the input polynomial and its domain.
3893 static isl_stat test_bound_space(isl_ctx *ctx)
3895 const char *str;
3896 isl_set *set;
3897 isl_pw_qpolynomial *pwqp;
3898 isl_pw_qpolynomial_fold *pwf;
3900 str = "{ [[c] -> [c]] }";
3901 set = isl_set_read_from_str(ctx, str);
3902 str = "{ [[a] -> [b]] -> 1 }";
3903 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3904 pwqp = isl_pw_qpolynomial_intersect_domain(pwqp, set);
3905 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3906 isl_pw_qpolynomial_fold_free(pwf);
3908 return isl_stat_non_null(pwf);
3911 /* Perform basic isl_pw_qpolynomial_bound tests.
3913 static int test_bound(isl_ctx *ctx)
3915 int i;
3917 if (test_bound_space(ctx) < 0)
3918 return -1;
3920 for (i = 0; i < ARRAY_SIZE(bound_tests); ++i) {
3921 const char *str;
3922 enum isl_fold type;
3923 isl_bool equal, tight;
3924 isl_pw_qpolynomial *pwqp;
3925 isl_pw_qpolynomial_fold *pwf1, *pwf2;
3927 str = bound_tests[i].poly;
3928 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3929 type = bound_tests[i].type;
3930 pwf1 = isl_pw_qpolynomial_bound(pwqp, type, &tight);
3931 str = bound_tests[i].bound;
3932 pwf2 = isl_pw_qpolynomial_fold_read_from_str(ctx, str);
3933 equal = isl_pw_qpolynomial_fold_plain_is_equal(pwf1, pwf2);
3934 isl_pw_qpolynomial_fold_free(pwf2);
3935 isl_pw_qpolynomial_fold_free(pwf1);
3936 if (equal < 0)
3937 return -1;
3938 if (!equal)
3939 isl_die(ctx, isl_error_unknown,
3940 "incorrect bound result", return -1);
3941 if (bound_tests[i].tight && !tight)
3942 isl_die(ctx, isl_error_unknown,
3943 "bound unexpectedly not tight", return -1);
3946 return 0;
3949 /* isl_set is defined to isl_map internally, so the corresponding elements
3950 * are isl_basic_map objects.
3952 #undef EL_BASE
3953 #undef SET_BASE
3954 #define EL_BASE basic_map
3955 #define SET_BASE set
3956 #include "isl_test_list_templ.c"
3958 #undef EL_BASE
3959 #undef SET_BASE
3960 #define EL_BASE basic_set
3961 #define SET_BASE union_set
3962 #include "isl_test_list_templ.c"
3964 #undef EL_BASE
3965 #undef SET_BASE
3966 #define EL_BASE set
3967 #define SET_BASE union_set
3968 #include "isl_test_list_templ.c"
3970 #undef EL_BASE
3971 #undef SET_BASE
3972 #define EL_BASE basic_map
3973 #define SET_BASE map
3974 #include "isl_test_list_templ.c"
3976 #undef EL_BASE
3977 #undef SET_BASE
3978 #define EL_BASE map
3979 #define SET_BASE union_map
3980 #include "isl_test_list_templ.c"
3982 /* Check that the conversion from isl objects to lists works as expected.
3984 static int test_get_list(isl_ctx *ctx)
3986 if (test_get_list_basic_map_from_set(ctx, "{ [0]; [2]; [3] }"))
3987 return -1;
3988 if (test_get_list_basic_set_from_union_set(ctx, "{ A[0]; B[2]; B[3] }"))
3989 return -1;
3990 if (test_get_list_set_from_union_set(ctx, "{ A[0]; A[2]; B[3] }"))
3991 return -1;
3992 if (test_get_list_basic_map_from_map(ctx,
3993 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"))
3994 return -1;
3995 if (test_get_list_map_from_union_map(ctx,
3996 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"))
3997 return -1;
3999 return 0;
4002 static int test_lift(isl_ctx *ctx)
4004 const char *str;
4005 isl_basic_map *bmap;
4006 isl_basic_set *bset;
4008 str = "{ [i0] : exists e0 : i0 = 4e0 }";
4009 bset = isl_basic_set_read_from_str(ctx, str);
4010 bset = isl_basic_set_lift(bset);
4011 bmap = isl_basic_map_from_range(bset);
4012 bset = isl_basic_map_domain(bmap);
4013 isl_basic_set_free(bset);
4015 return 0;
4018 /* Check that isl_set_is_subset is not confused by identical
4019 * integer divisions.
4020 * The call to isl_set_normalize ensures that the equality constraints
4021 * a = b = 0 are discovered, turning e0 and e1 into identical
4022 * integer divisions. Any further simplification would remove
4023 * the duplicate integer divisions.
4025 static isl_stat test_subset_duplicate_integer_divisions(isl_ctx *ctx)
4027 const char *str;
4028 isl_bool is_subset;
4029 isl_set *set1, *set2;
4031 str = "{ [a, b, c, d] : "
4032 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
4033 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
4034 "e3 = floor((-d + 4*floor((d)/4))/10): "
4035 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
4036 "b >= 0 and a <= 0 and b <= a) }";
4037 set1 = isl_set_read_from_str(ctx, str);
4038 set2 = isl_set_read_from_str(ctx, str);
4039 set2 = isl_set_normalize(set2);
4041 is_subset = isl_set_is_subset(set1, set2);
4043 isl_set_free(set1);
4044 isl_set_free(set2);
4046 if (is_subset < 0)
4047 return isl_stat_error;
4048 if (!is_subset)
4049 isl_die(ctx, isl_error_unknown,
4050 "set is not considered to be a subset of itself",
4051 return isl_stat_error);
4053 return isl_stat_ok;
4056 struct {
4057 const char *set1;
4058 const char *set2;
4059 int subset;
4060 } subset_tests[] = {
4061 { "{ [112, 0] }",
4062 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
4063 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
4064 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
4065 { "{ [65] }",
4066 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
4067 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
4068 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
4069 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
4070 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
4071 "256e0 <= 255i and 256e0 >= -255 + 255i and "
4072 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
4073 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
4074 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
4075 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
4076 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
4077 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
4078 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
4079 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
4080 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
4081 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
4082 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
4083 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
4084 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
4085 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
4086 "4e0 <= -57 + i0 + i1)) or "
4087 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
4088 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
4089 "4e0 >= -61 + i0 + i1)) or "
4090 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
4091 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
4094 static int test_subset(isl_ctx *ctx)
4096 int i;
4097 isl_set *set1, *set2;
4098 int subset;
4100 if (test_subset_duplicate_integer_divisions(ctx) < 0)
4101 return -1;
4103 for (i = 0; i < ARRAY_SIZE(subset_tests); ++i) {
4104 set1 = isl_set_read_from_str(ctx, subset_tests[i].set1);
4105 set2 = isl_set_read_from_str(ctx, subset_tests[i].set2);
4106 subset = isl_set_is_subset(set1, set2);
4107 isl_set_free(set1);
4108 isl_set_free(set2);
4109 if (subset < 0)
4110 return -1;
4111 if (subset != subset_tests[i].subset)
4112 isl_die(ctx, isl_error_unknown,
4113 "incorrect subset result", return -1);
4116 return 0;
4119 /* Perform a set subtraction with a set that has a non-obviously empty disjunct.
4120 * Older versions of isl would fail on such cases.
4122 static isl_stat test_subtract_empty(isl_ctx *ctx)
4124 const char *str;
4125 isl_set *s1, *s2;
4127 s1 = isl_set_read_from_str(ctx, "{ [0] }");
4128 str = "{ [a] : (exists (e0, e1, e2: 1056e1 <= 32 + a - 33e0 and "
4129 "1089e1 >= a - 33e0 and 1089e1 <= 1 + a - 33e0 and "
4130 "33e2 >= -a + 33e0 + 1056e1 and "
4131 "33e2 < -2a + 66e0 + 2112e1)) or a = 0 }";
4132 s2 = isl_set_read_from_str(ctx, str);
4133 s1 = isl_set_subtract(s1, s2);
4134 isl_set_free(s1);
4136 return isl_stat_non_null(s1);
4139 struct {
4140 const char *minuend;
4141 const char *subtrahend;
4142 const char *difference;
4143 } subtract_domain_tests[] = {
4144 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
4145 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
4146 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
4149 static int test_subtract(isl_ctx *ctx)
4151 int i;
4152 isl_union_map *umap1, *umap2;
4153 isl_union_pw_multi_aff *upma1, *upma2;
4154 isl_union_set *uset;
4155 int equal;
4157 if (test_subtract_empty(ctx) < 0)
4158 return -1;
4160 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests); ++i) {
4161 umap1 = isl_union_map_read_from_str(ctx,
4162 subtract_domain_tests[i].minuend);
4163 uset = isl_union_set_read_from_str(ctx,
4164 subtract_domain_tests[i].subtrahend);
4165 umap2 = isl_union_map_read_from_str(ctx,
4166 subtract_domain_tests[i].difference);
4167 umap1 = isl_union_map_subtract_domain(umap1, uset);
4168 equal = isl_union_map_is_equal(umap1, umap2);
4169 isl_union_map_free(umap1);
4170 isl_union_map_free(umap2);
4171 if (equal < 0)
4172 return -1;
4173 if (!equal)
4174 isl_die(ctx, isl_error_unknown,
4175 "incorrect subtract domain result", return -1);
4178 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests); ++i) {
4179 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
4180 subtract_domain_tests[i].minuend);
4181 uset = isl_union_set_read_from_str(ctx,
4182 subtract_domain_tests[i].subtrahend);
4183 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
4184 subtract_domain_tests[i].difference);
4185 upma1 = isl_union_pw_multi_aff_subtract_domain(upma1, uset);
4186 equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2);
4187 isl_union_pw_multi_aff_free(upma1);
4188 isl_union_pw_multi_aff_free(upma2);
4189 if (equal < 0)
4190 return -1;
4191 if (!equal)
4192 isl_die(ctx, isl_error_unknown,
4193 "incorrect subtract domain result", return -1);
4196 return 0;
4199 /* Check that intersecting the empty basic set with another basic set
4200 * does not increase the number of constraints. In particular,
4201 * the empty basic set should maintain its canonical representation.
4203 static int test_intersect_1(isl_ctx *ctx)
4205 isl_size n1, n2;
4206 isl_basic_set *bset1, *bset2;
4208 bset1 = isl_basic_set_read_from_str(ctx, "{ [a,b,c] : 1 = 0 }");
4209 bset2 = isl_basic_set_read_from_str(ctx, "{ [1,2,3] }");
4210 n1 = isl_basic_set_n_constraint(bset1);
4211 bset1 = isl_basic_set_intersect(bset1, bset2);
4212 n2 = isl_basic_set_n_constraint(bset1);
4213 isl_basic_set_free(bset1);
4214 if (n1 < 0 || n2 < 0)
4215 return -1;
4216 if (n1 != n2)
4217 isl_die(ctx, isl_error_unknown,
4218 "number of constraints of empty set changed",
4219 return -1);
4221 return 0;
4224 /* Check that intersecting a set with itself does not cause
4225 * an explosion in the number of disjuncts.
4227 static isl_stat test_intersect_2(isl_ctx *ctx)
4229 int i;
4230 isl_set *set;
4232 set = isl_set_read_from_str(ctx, "{ [x,y] : x >= 0 or y >= 0 }");
4233 for (i = 0; i < 100; ++i)
4234 set = isl_set_intersect(set, isl_set_copy(set));
4235 isl_set_free(set);
4236 if (!set)
4237 return isl_stat_error;
4238 return isl_stat_ok;
4241 /* Perform some intersection tests.
4243 static int test_intersect(isl_ctx *ctx)
4245 if (test_intersect_1(ctx) < 0)
4246 return -1;
4247 if (test_intersect_2(ctx) < 0)
4248 return -1;
4250 return 0;
4253 int test_factorize(isl_ctx *ctx)
4255 const char *str;
4256 isl_basic_set *bset;
4257 isl_factorizer *f;
4259 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
4260 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
4261 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
4262 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
4263 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
4264 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
4265 "3i5 >= -2i0 - i2 + 3i4 }";
4266 bset = isl_basic_set_read_from_str(ctx, str);
4267 f = isl_basic_set_factorizer(bset);
4268 isl_basic_set_free(bset);
4269 isl_factorizer_free(f);
4270 if (!f)
4271 isl_die(ctx, isl_error_unknown,
4272 "failed to construct factorizer", return -1);
4274 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
4275 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
4276 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
4277 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
4278 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
4279 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
4280 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
4281 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
4282 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
4283 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
4284 bset = isl_basic_set_read_from_str(ctx, str);
4285 f = isl_basic_set_factorizer(bset);
4286 isl_basic_set_free(bset);
4287 isl_factorizer_free(f);
4288 if (!f)
4289 isl_die(ctx, isl_error_unknown,
4290 "failed to construct factorizer", return -1);
4292 return 0;
4295 static isl_stat check_injective(__isl_take isl_map *map, void *user)
4297 int *injective = user;
4299 *injective = isl_map_is_injective(map);
4300 isl_map_free(map);
4302 if (*injective < 0 || !*injective)
4303 return isl_stat_error;
4305 return isl_stat_ok;
4308 int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
4309 const char *r, const char *s, int tilable, int parallel)
4311 int i;
4312 isl_union_set *D;
4313 isl_union_map *W, *R, *S;
4314 isl_union_map *empty;
4315 isl_union_map *dep_raw, *dep_war, *dep_waw, *dep;
4316 isl_union_map *validity, *proximity, *coincidence;
4317 isl_union_map *schedule;
4318 isl_union_map *test;
4319 isl_union_set *delta;
4320 isl_union_set *domain;
4321 isl_set *delta_set;
4322 isl_set *slice;
4323 isl_set *origin;
4324 isl_schedule_constraints *sc;
4325 isl_schedule *sched;
4326 int is_nonneg, is_parallel, is_tilable, is_injection, is_complete;
4327 isl_size n;
4329 D = isl_union_set_read_from_str(ctx, d);
4330 W = isl_union_map_read_from_str(ctx, w);
4331 R = isl_union_map_read_from_str(ctx, r);
4332 S = isl_union_map_read_from_str(ctx, s);
4334 W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
4335 R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
4337 empty = isl_union_map_empty(isl_union_map_get_space(S));
4338 isl_union_map_compute_flow(isl_union_map_copy(R),
4339 isl_union_map_copy(W), empty,
4340 isl_union_map_copy(S),
4341 &dep_raw, NULL, NULL, NULL);
4342 isl_union_map_compute_flow(isl_union_map_copy(W),
4343 isl_union_map_copy(W),
4344 isl_union_map_copy(R),
4345 isl_union_map_copy(S),
4346 &dep_waw, &dep_war, NULL, NULL);
4348 dep = isl_union_map_union(dep_waw, dep_war);
4349 dep = isl_union_map_union(dep, dep_raw);
4350 validity = isl_union_map_copy(dep);
4351 coincidence = isl_union_map_copy(dep);
4352 proximity = isl_union_map_copy(dep);
4354 sc = isl_schedule_constraints_on_domain(isl_union_set_copy(D));
4355 sc = isl_schedule_constraints_set_validity(sc, validity);
4356 sc = isl_schedule_constraints_set_coincidence(sc, coincidence);
4357 sc = isl_schedule_constraints_set_proximity(sc, proximity);
4358 sched = isl_schedule_constraints_compute_schedule(sc);
4359 schedule = isl_schedule_get_map(sched);
4360 isl_schedule_free(sched);
4361 isl_union_map_free(W);
4362 isl_union_map_free(R);
4363 isl_union_map_free(S);
4365 is_injection = 1;
4366 isl_union_map_foreach_map(schedule, &check_injective, &is_injection);
4368 domain = isl_union_map_domain(isl_union_map_copy(schedule));
4369 is_complete = isl_union_set_is_subset(D, domain);
4370 isl_union_set_free(D);
4371 isl_union_set_free(domain);
4373 test = isl_union_map_reverse(isl_union_map_copy(schedule));
4374 test = isl_union_map_apply_range(test, dep);
4375 test = isl_union_map_apply_range(test, schedule);
4377 delta = isl_union_map_deltas(test);
4378 n = isl_union_set_n_set(delta);
4379 if (n < 0) {
4380 isl_union_set_free(delta);
4381 return -1;
4383 if (n == 0) {
4384 is_tilable = 1;
4385 is_parallel = 1;
4386 is_nonneg = 1;
4387 isl_union_set_free(delta);
4388 } else {
4389 isl_size dim;
4391 delta_set = isl_set_from_union_set(delta);
4393 slice = isl_set_universe(isl_set_get_space(delta_set));
4394 for (i = 0; i < tilable; ++i)
4395 slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
4396 is_tilable = isl_set_is_subset(delta_set, slice);
4397 isl_set_free(slice);
4399 slice = isl_set_universe(isl_set_get_space(delta_set));
4400 for (i = 0; i < parallel; ++i)
4401 slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
4402 is_parallel = isl_set_is_subset(delta_set, slice);
4403 isl_set_free(slice);
4405 origin = isl_set_universe(isl_set_get_space(delta_set));
4406 dim = isl_set_dim(origin, isl_dim_set);
4407 if (dim < 0)
4408 origin = isl_set_free(origin);
4409 for (i = 0; i < dim; ++i)
4410 origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
4412 delta_set = isl_set_union(delta_set, isl_set_copy(origin));
4413 delta_set = isl_set_lexmin(delta_set);
4415 is_nonneg = isl_set_is_equal(delta_set, origin);
4417 isl_set_free(origin);
4418 isl_set_free(delta_set);
4421 if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
4422 is_injection < 0 || is_complete < 0)
4423 return -1;
4424 if (!is_complete)
4425 isl_die(ctx, isl_error_unknown,
4426 "generated schedule incomplete", return -1);
4427 if (!is_injection)
4428 isl_die(ctx, isl_error_unknown,
4429 "generated schedule not injective on each statement",
4430 return -1);
4431 if (!is_nonneg)
4432 isl_die(ctx, isl_error_unknown,
4433 "negative dependences in generated schedule",
4434 return -1);
4435 if (!is_tilable)
4436 isl_die(ctx, isl_error_unknown,
4437 "generated schedule not as tilable as expected",
4438 return -1);
4439 if (!is_parallel)
4440 isl_die(ctx, isl_error_unknown,
4441 "generated schedule not as parallel as expected",
4442 return -1);
4444 return 0;
4447 /* Compute a schedule for the given instance set, validity constraints,
4448 * proximity constraints and context and return a corresponding union map
4449 * representation.
4451 static __isl_give isl_union_map *compute_schedule_with_context(isl_ctx *ctx,
4452 const char *domain, const char *validity, const char *proximity,
4453 const char *context)
4455 isl_set *con;
4456 isl_union_set *dom;
4457 isl_union_map *dep;
4458 isl_union_map *prox;
4459 isl_schedule_constraints *sc;
4460 isl_schedule *schedule;
4461 isl_union_map *sched;
4463 con = isl_set_read_from_str(ctx, context);
4464 dom = isl_union_set_read_from_str(ctx, domain);
4465 dep = isl_union_map_read_from_str(ctx, validity);
4466 prox = isl_union_map_read_from_str(ctx, proximity);
4467 sc = isl_schedule_constraints_on_domain(dom);
4468 sc = isl_schedule_constraints_set_context(sc, con);
4469 sc = isl_schedule_constraints_set_validity(sc, dep);
4470 sc = isl_schedule_constraints_set_proximity(sc, prox);
4471 schedule = isl_schedule_constraints_compute_schedule(sc);
4472 sched = isl_schedule_get_map(schedule);
4473 isl_schedule_free(schedule);
4475 return sched;
4478 /* Compute a schedule for the given instance set, validity constraints and
4479 * proximity constraints and return a corresponding union map representation.
4481 static __isl_give isl_union_map *compute_schedule(isl_ctx *ctx,
4482 const char *domain, const char *validity, const char *proximity)
4484 return compute_schedule_with_context(ctx, domain, validity, proximity,
4485 "{ : }");
4488 /* Check that a schedule can be constructed on the given domain
4489 * with the given validity and proximity constraints.
4491 static int test_has_schedule(isl_ctx *ctx, const char *domain,
4492 const char *validity, const char *proximity)
4494 isl_union_map *sched;
4496 sched = compute_schedule(ctx, domain, validity, proximity);
4497 if (!sched)
4498 return -1;
4500 isl_union_map_free(sched);
4501 return 0;
4504 int test_special_schedule(isl_ctx *ctx, const char *domain,
4505 const char *validity, const char *proximity, const char *expected_sched)
4507 isl_union_map *sched1, *sched2;
4508 int equal;
4510 sched1 = compute_schedule(ctx, domain, validity, proximity);
4511 sched2 = isl_union_map_read_from_str(ctx, expected_sched);
4513 equal = isl_union_map_is_equal(sched1, sched2);
4514 isl_union_map_free(sched1);
4515 isl_union_map_free(sched2);
4517 if (equal < 0)
4518 return -1;
4519 if (!equal)
4520 isl_die(ctx, isl_error_unknown, "unexpected schedule",
4521 return -1);
4523 return 0;
4526 /* Check that the schedule map is properly padded, i.e., that the range
4527 * lives in a single space.
4529 static int test_padded_schedule(isl_ctx *ctx)
4531 const char *str;
4532 isl_union_set *D;
4533 isl_union_map *validity, *proximity;
4534 isl_schedule_constraints *sc;
4535 isl_schedule *sched;
4536 isl_union_map *umap;
4537 isl_union_set *range;
4538 isl_set *set;
4540 str = "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4541 D = isl_union_set_read_from_str(ctx, str);
4542 validity = isl_union_map_empty(isl_union_set_get_space(D));
4543 proximity = isl_union_map_copy(validity);
4544 sc = isl_schedule_constraints_on_domain(D);
4545 sc = isl_schedule_constraints_set_validity(sc, validity);
4546 sc = isl_schedule_constraints_set_proximity(sc, proximity);
4547 sched = isl_schedule_constraints_compute_schedule(sc);
4548 umap = isl_schedule_get_map(sched);
4549 isl_schedule_free(sched);
4550 range = isl_union_map_range(umap);
4551 set = isl_set_from_union_set(range);
4552 isl_set_free(set);
4554 if (!set)
4555 return -1;
4557 return 0;
4560 /* Check that conditional validity constraints are also taken into
4561 * account across bands.
4562 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4563 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4564 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4565 * is enforced by the rest of the schedule.
4567 static int test_special_conditional_schedule_constraints(isl_ctx *ctx)
4569 const char *str;
4570 isl_union_set *domain;
4571 isl_union_map *validity, *proximity, *condition;
4572 isl_union_map *sink, *source, *dep;
4573 isl_schedule_constraints *sc;
4574 isl_schedule *schedule;
4575 isl_union_access_info *access;
4576 isl_union_flow *flow;
4577 int empty;
4579 str = "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4580 "A[k] : k >= 1 and k <= -1 + n; "
4581 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4582 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4583 domain = isl_union_set_read_from_str(ctx, str);
4584 sc = isl_schedule_constraints_on_domain(domain);
4585 str = "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4586 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4587 "D[k, i] -> C[1 + k, i] : "
4588 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4589 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4590 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4591 validity = isl_union_map_read_from_str(ctx, str);
4592 sc = isl_schedule_constraints_set_validity(sc, validity);
4593 str = "[n] -> { C[k, i] -> D[k, i] : "
4594 "0 <= i <= -1 + k and k <= -1 + n }";
4595 proximity = isl_union_map_read_from_str(ctx, str);
4596 sc = isl_schedule_constraints_set_proximity(sc, proximity);
4597 str = "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4598 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4599 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4600 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4601 condition = isl_union_map_read_from_str(ctx, str);
4602 str = "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4603 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4604 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4605 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4606 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4607 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4608 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4609 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4610 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4611 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4612 validity = isl_union_map_read_from_str(ctx, str);
4613 sc = isl_schedule_constraints_set_conditional_validity(sc, condition,
4614 validity);
4615 schedule = isl_schedule_constraints_compute_schedule(sc);
4616 str = "{ D[2,0] -> [] }";
4617 sink = isl_union_map_read_from_str(ctx, str);
4618 access = isl_union_access_info_from_sink(sink);
4619 str = "{ C[2,1] -> [] }";
4620 source = isl_union_map_read_from_str(ctx, str);
4621 access = isl_union_access_info_set_must_source(access, source);
4622 access = isl_union_access_info_set_schedule(access, schedule);
4623 flow = isl_union_access_info_compute_flow(access);
4624 dep = isl_union_flow_get_must_dependence(flow);
4625 isl_union_flow_free(flow);
4626 empty = isl_union_map_is_empty(dep);
4627 isl_union_map_free(dep);
4629 if (empty < 0)
4630 return -1;
4631 if (empty)
4632 isl_die(ctx, isl_error_unknown,
4633 "conditional validity not respected", return -1);
4635 return 0;
4638 /* Check that the test for violated conditional validity constraints
4639 * is not confused by domain compression.
4640 * In particular, earlier versions of isl would apply
4641 * a schedule on the compressed domains to the original domains,
4642 * resulting in a failure to detect that the default schedule
4643 * violates the conditional validity constraints.
4645 static int test_special_conditional_schedule_constraints_2(isl_ctx *ctx)
4647 const char *str;
4648 isl_bool empty;
4649 isl_union_set *domain;
4650 isl_union_map *validity, *condition;
4651 isl_schedule_constraints *sc;
4652 isl_schedule *schedule;
4653 isl_union_map *umap;
4654 isl_map *map, *ge;
4656 str = "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4657 domain = isl_union_set_read_from_str(ctx, str);
4658 sc = isl_schedule_constraints_on_domain(domain);
4659 str = "{ B[1, i] -> A[0, i + 1] }";
4660 condition = isl_union_map_read_from_str(ctx, str);
4661 str = "{ A[0, i] -> B[1, i - 1] }";
4662 validity = isl_union_map_read_from_str(ctx, str);
4663 sc = isl_schedule_constraints_set_conditional_validity(sc, condition,
4664 isl_union_map_copy(validity));
4665 schedule = isl_schedule_constraints_compute_schedule(sc);
4666 umap = isl_schedule_get_map(schedule);
4667 isl_schedule_free(schedule);
4668 validity = isl_union_map_apply_domain(validity,
4669 isl_union_map_copy(umap));
4670 validity = isl_union_map_apply_range(validity, umap);
4671 map = isl_map_from_union_map(validity);
4672 ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map)));
4673 map = isl_map_intersect(map, ge);
4674 empty = isl_map_is_empty(map);
4675 isl_map_free(map);
4677 if (empty < 0)
4678 return -1;
4679 if (!empty)
4680 isl_die(ctx, isl_error_unknown,
4681 "conditional validity constraints not satisfied",
4682 return -1);
4684 return 0;
4687 /* Input for testing of schedule construction based on
4688 * conditional constraints.
4690 * domain is the iteration domain
4691 * flow are the flow dependences, which determine the validity and
4692 * proximity constraints
4693 * condition are the conditions on the conditional validity constraints
4694 * conditional_validity are the conditional validity constraints
4695 * outer_band_n is the expected number of members in the outer band
4697 struct {
4698 const char *domain;
4699 const char *flow;
4700 const char *condition;
4701 const char *conditional_validity;
4702 int outer_band_n;
4703 } live_range_tests[] = {
4704 /* Contrived example that illustrates that we need to keep
4705 * track of tagged condition dependences and
4706 * tagged conditional validity dependences
4707 * in isl_sched_edge separately.
4708 * In particular, the conditional validity constraints on A
4709 * cannot be satisfied,
4710 * but they can be ignored because there are no corresponding
4711 * condition constraints. However, we do have an additional
4712 * conditional validity constraint that maps to the same
4713 * dependence relation
4714 * as the condition constraint on B. If we did not make a distinction
4715 * between tagged condition and tagged conditional validity
4716 * dependences, then we
4717 * could end up treating this shared dependence as an condition
4718 * constraint on A, forcing a localization of the conditions,
4719 * which is impossible.
4721 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4722 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4723 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4724 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4725 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4726 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4729 /* TACO 2013 Fig. 7 */
4730 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4731 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4732 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4733 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4734 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4735 "0 <= i < n and 0 <= j < n - 1 }",
4736 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4737 "0 <= i < n and 0 <= j < j' < n;"
4738 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4739 "0 <= i < i' < n and 0 <= j,j' < n;"
4740 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4741 "0 <= i,j,j' < n and j < j' }",
4744 /* TACO 2013 Fig. 7, without tags */
4745 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
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] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4749 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4750 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4751 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4752 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4755 /* TACO 2013 Fig. 12 */
4756 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4757 "S3[i,3] : 0 <= i <= 1 }",
4758 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4759 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4760 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4761 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4762 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4763 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4764 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4765 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4766 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4767 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4768 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4773 /* Test schedule construction based on conditional constraints.
4774 * In particular, check the number of members in the outer band node
4775 * as an indication of whether tiling is possible or not.
4777 static int test_conditional_schedule_constraints(isl_ctx *ctx)
4779 int i;
4780 isl_union_set *domain;
4781 isl_union_map *condition;
4782 isl_union_map *flow;
4783 isl_union_map *validity;
4784 isl_schedule_constraints *sc;
4785 isl_schedule *schedule;
4786 isl_schedule_node *node;
4787 isl_size n_member;
4789 if (test_special_conditional_schedule_constraints(ctx) < 0)
4790 return -1;
4791 if (test_special_conditional_schedule_constraints_2(ctx) < 0)
4792 return -1;
4794 for (i = 0; i < ARRAY_SIZE(live_range_tests); ++i) {
4795 domain = isl_union_set_read_from_str(ctx,
4796 live_range_tests[i].domain);
4797 flow = isl_union_map_read_from_str(ctx,
4798 live_range_tests[i].flow);
4799 condition = isl_union_map_read_from_str(ctx,
4800 live_range_tests[i].condition);
4801 validity = isl_union_map_read_from_str(ctx,
4802 live_range_tests[i].conditional_validity);
4803 sc = isl_schedule_constraints_on_domain(domain);
4804 sc = isl_schedule_constraints_set_validity(sc,
4805 isl_union_map_copy(flow));
4806 sc = isl_schedule_constraints_set_proximity(sc, flow);
4807 sc = isl_schedule_constraints_set_conditional_validity(sc,
4808 condition, validity);
4809 schedule = isl_schedule_constraints_compute_schedule(sc);
4810 node = isl_schedule_get_root(schedule);
4811 while (node &&
4812 isl_schedule_node_get_type(node) != isl_schedule_node_band)
4813 node = isl_schedule_node_first_child(node);
4814 n_member = isl_schedule_node_band_n_member(node);
4815 isl_schedule_node_free(node);
4816 isl_schedule_free(schedule);
4818 if (!schedule || n_member < 0)
4819 return -1;
4820 if (n_member != live_range_tests[i].outer_band_n)
4821 isl_die(ctx, isl_error_unknown,
4822 "unexpected number of members in outer band",
4823 return -1);
4825 return 0;
4828 /* Check that the schedule computed for the given instance set and
4829 * dependence relation strongly satisfies the dependences.
4830 * In particular, check that no instance is scheduled before
4831 * or together with an instance on which it depends.
4832 * Earlier versions of isl would produce a schedule that
4833 * only weakly satisfies the dependences.
4835 static int test_strongly_satisfying_schedule(isl_ctx *ctx)
4837 const char *domain, *dep;
4838 isl_union_map *D, *schedule;
4839 isl_map *map, *ge;
4840 int empty;
4842 domain = "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4843 "A[i0] : 0 <= i0 <= 1 }";
4844 dep = "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4845 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4846 schedule = compute_schedule(ctx, domain, dep, dep);
4847 D = isl_union_map_read_from_str(ctx, dep);
4848 D = isl_union_map_apply_domain(D, isl_union_map_copy(schedule));
4849 D = isl_union_map_apply_range(D, schedule);
4850 map = isl_map_from_union_map(D);
4851 ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map)));
4852 map = isl_map_intersect(map, ge);
4853 empty = isl_map_is_empty(map);
4854 isl_map_free(map);
4856 if (empty < 0)
4857 return -1;
4858 if (!empty)
4859 isl_die(ctx, isl_error_unknown,
4860 "dependences not strongly satisfied", return -1);
4862 return 0;
4865 /* Compute a schedule for input where the instance set constraints
4866 * conflict with the context constraints.
4867 * Earlier versions of isl did not properly handle this situation.
4869 static int test_conflicting_context_schedule(isl_ctx *ctx)
4871 isl_union_map *schedule;
4872 const char *domain, *context;
4874 domain = "[n] -> { A[] : n >= 0 }";
4875 context = "[n] -> { : n < 0 }";
4876 schedule = compute_schedule_with_context(ctx,
4877 domain, "{}", "{}", context);
4878 isl_union_map_free(schedule);
4880 if (!schedule)
4881 return -1;
4883 return 0;
4886 /* Check that a set of schedule constraints that only allow for
4887 * a coalescing schedule still produces a schedule even if the user
4888 * request a non-coalescing schedule. Earlier versions of isl
4889 * would not handle this case correctly.
4891 static int test_coalescing_schedule(isl_ctx *ctx)
4893 const char *domain, *dep;
4894 isl_union_set *I;
4895 isl_union_map *D;
4896 isl_schedule_constraints *sc;
4897 isl_schedule *schedule;
4898 int treat_coalescing;
4900 domain = "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4901 dep = "{ S[a, b] -> S[a + b, 1 - b] }";
4902 I = isl_union_set_read_from_str(ctx, domain);
4903 D = isl_union_map_read_from_str(ctx, dep);
4904 sc = isl_schedule_constraints_on_domain(I);
4905 sc = isl_schedule_constraints_set_validity(sc, D);
4906 treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx);
4907 isl_options_set_schedule_treat_coalescing(ctx, 1);
4908 schedule = isl_schedule_constraints_compute_schedule(sc);
4909 isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing);
4910 isl_schedule_free(schedule);
4911 if (!schedule)
4912 return -1;
4913 return 0;
4916 /* Check that the scheduler does not perform any needless
4917 * compound skewing. Earlier versions of isl would compute
4918 * schedules in terms of transformed schedule coefficients and
4919 * would not accurately keep track of the sum of the original
4920 * schedule coefficients. It could then produce the schedule
4921 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4922 * for the input below instead of the schedule below.
4924 static int test_skewing_schedule(isl_ctx *ctx)
4926 const char *D, *V, *P, *S;
4928 D = "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4929 V = "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4930 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4931 "-1 <= a-i + b-j + c-k <= 1 }";
4932 P = "{ }";
4933 S = "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4935 return test_special_schedule(ctx, D, V, P, S);
4938 int test_schedule(isl_ctx *ctx)
4940 const char *D, *W, *R, *V, *P, *S;
4941 int max_coincidence;
4942 int treat_coalescing;
4944 /* Handle resulting schedule with zero bands. */
4945 if (test_one_schedule(ctx, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4946 return -1;
4948 /* Jacobi */
4949 D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4950 W = "{ S1[t,i] -> a[t,i] }";
4951 R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4952 "S1[t,i] -> a[t-1,i+1] }";
4953 S = "{ S1[t,i] -> [t,i] }";
4954 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4955 return -1;
4957 /* Fig. 5 of CC2008 */
4958 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4959 "j <= -1 + N }";
4960 W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4961 "j >= 2 and j <= -1 + N }";
4962 R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4963 "j >= 2 and j <= -1 + N; "
4964 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4965 "j >= 2 and j <= -1 + N }";
4966 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4967 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4968 return -1;
4970 D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4971 W = "{ S1[i] -> a[i] }";
4972 R = "{ S2[i] -> a[i+1] }";
4973 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4974 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4975 return -1;
4977 D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4978 W = "{ S1[i] -> a[i] }";
4979 R = "{ S2[i] -> a[9-i] }";
4980 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4981 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4982 return -1;
4984 D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4985 W = "{ S1[i] -> a[i] }";
4986 R = "[N] -> { S2[i] -> a[N-1-i] }";
4987 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4988 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4989 return -1;
4991 D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4992 W = "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4993 R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4994 S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4995 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4996 return -1;
4998 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4999 W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
5000 R = "{ S2[i,j] -> a[i-1,j] }";
5001 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5002 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
5003 return -1;
5005 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
5006 W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
5007 R = "{ S2[i,j] -> a[i,j-1] }";
5008 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
5009 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
5010 return -1;
5012 D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
5013 W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
5014 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
5015 R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
5016 S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
5017 "S_0[] -> [0, 0, 0] }";
5018 if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0)
5019 return -1;
5020 ctx->opt->schedule_parametric = 0;
5021 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5022 return -1;
5023 ctx->opt->schedule_parametric = 1;
5025 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
5026 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
5027 W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
5028 R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
5029 "S4[i] -> a[i,N] }";
5030 S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
5031 "S4[i] -> [4,i,0] }";
5032 max_coincidence = isl_options_get_schedule_maximize_coincidence(ctx);
5033 isl_options_set_schedule_maximize_coincidence(ctx, 0);
5034 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
5035 return -1;
5036 isl_options_set_schedule_maximize_coincidence(ctx, max_coincidence);
5038 D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
5039 W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5040 "j <= N }";
5041 R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5042 "j <= N; "
5043 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
5044 "j <= N }";
5045 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
5046 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5047 return -1;
5049 D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
5050 " S_2[t] : t >= 0 and t <= -1 + N; "
5051 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
5052 "i <= -1 + N }";
5053 W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
5054 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
5055 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
5056 "i >= 0 and i <= -1 + N }";
5057 R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
5058 "i >= 0 and i <= -1 + N; "
5059 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
5060 S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
5061 " S_0[t] -> [0, t, 0] }";
5063 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
5064 return -1;
5065 ctx->opt->schedule_parametric = 0;
5066 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5067 return -1;
5068 ctx->opt->schedule_parametric = 1;
5070 D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
5071 S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
5072 if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0)
5073 return -1;
5075 D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
5076 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
5077 W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
5078 "j >= 0 and j <= -1 + N; "
5079 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5080 R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
5081 "j >= 0 and j <= -1 + N; "
5082 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5083 S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
5084 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5085 return -1;
5087 D = "{ S_0[i] : i >= 0 }";
5088 W = "{ S_0[i] -> a[i] : i >= 0 }";
5089 R = "{ S_0[i] -> a[0] : i >= 0 }";
5090 S = "{ S_0[i] -> [0, i, 0] }";
5091 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5092 return -1;
5094 D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
5095 W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
5096 R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
5097 S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
5098 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5099 return -1;
5101 D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
5102 "k <= -1 + n and k >= 0 }";
5103 W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
5104 R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
5105 "k <= -1 + n and k >= 0; "
5106 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
5107 "k <= -1 + n and k >= 0; "
5108 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
5109 "k <= -1 + n and k >= 0 }";
5110 S = "[n] -> { S_0[j, k] -> [2, j, k] }";
5111 ctx->opt->schedule_outer_coincidence = 1;
5112 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5113 return -1;
5114 ctx->opt->schedule_outer_coincidence = 0;
5116 D = "{Stmt_for_body24[i0, i1, i2, i3]:"
5117 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
5118 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
5119 "Stmt_for_body24[i0, i1, 1, 0]:"
5120 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
5121 "Stmt_for_body7[i0, i1, i2]:"
5122 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
5123 "i2 <= 7 }";
5125 V = "{Stmt_for_body24[0, i1, i2, i3] -> "
5126 "Stmt_for_body24[1, i1, i2, i3]:"
5127 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
5128 "i2 >= 1;"
5129 "Stmt_for_body24[0, i1, i2, i3] -> "
5130 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
5131 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
5132 "i3 >= 0;"
5133 "Stmt_for_body24[0, i1, i2, i3] ->"
5134 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
5135 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
5136 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
5137 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
5138 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
5139 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
5140 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
5141 "i1 <= 6 and i1 >= 0;"
5142 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
5143 "Stmt_for_body7[i0, i1, i2] -> "
5144 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
5145 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
5146 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
5147 "Stmt_for_body7[i0, i1, i2] -> "
5148 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
5149 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
5150 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
5151 P = V;
5153 treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx);
5154 isl_options_set_schedule_treat_coalescing(ctx, 0);
5155 if (test_has_schedule(ctx, D, V, P) < 0)
5156 return -1;
5157 isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing);
5159 D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
5160 V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
5161 "j >= 1 and j <= 7;"
5162 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
5163 "j >= 1 and j <= 8 }";
5164 P = "{ }";
5165 S = "{ S_0[i, j] -> [i + j, i] }";
5166 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5167 if (test_special_schedule(ctx, D, V, P, S) < 0)
5168 return -1;
5169 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5171 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
5172 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
5173 "j >= 0 and j <= -1 + i }";
5174 V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
5175 "i <= -1 + N and j >= 0;"
5176 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
5177 "i <= -2 + N }";
5178 P = "{ }";
5179 S = "{ S_0[i, j] -> [i, j] }";
5180 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5181 if (test_special_schedule(ctx, D, V, P, S) < 0)
5182 return -1;
5183 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5185 /* Test both algorithms on a case with only proximity dependences. */
5186 D = "{ S[i,j] : 0 <= i <= 10 }";
5187 V = "{ }";
5188 P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
5189 S = "{ S[i, j] -> [j, i] }";
5190 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5191 if (test_special_schedule(ctx, D, V, P, S) < 0)
5192 return -1;
5193 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5194 if (test_special_schedule(ctx, D, V, P, S) < 0)
5195 return -1;
5197 D = "{ A[a]; B[] }";
5198 V = "{}";
5199 P = "{ A[a] -> B[] }";
5200 if (test_has_schedule(ctx, D, V, P) < 0)
5201 return -1;
5203 if (test_padded_schedule(ctx) < 0)
5204 return -1;
5206 /* Check that check for progress is not confused by rational
5207 * solution.
5209 D = "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
5210 V = "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
5211 "i0 <= -2 + N; "
5212 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
5213 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
5214 P = "{}";
5215 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5216 if (test_has_schedule(ctx, D, V, P) < 0)
5217 return -1;
5218 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5220 /* Check that we allow schedule rows that are only non-trivial
5221 * on some full-dimensional domains.
5223 D = "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
5224 V = "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
5225 "S1[j] -> S2[1] : 0 <= j <= 1 }";
5226 P = "{}";
5227 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5228 if (test_has_schedule(ctx, D, V, P) < 0)
5229 return -1;
5230 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5232 if (test_conditional_schedule_constraints(ctx) < 0)
5233 return -1;
5235 if (test_strongly_satisfying_schedule(ctx) < 0)
5236 return -1;
5238 if (test_conflicting_context_schedule(ctx) < 0)
5239 return -1;
5241 if (test_coalescing_schedule(ctx) < 0)
5242 return -1;
5243 if (test_skewing_schedule(ctx) < 0)
5244 return -1;
5246 return 0;
5249 /* Perform scheduling tests using the whole component scheduler.
5251 static int test_schedule_whole(isl_ctx *ctx)
5253 int whole;
5254 int r;
5256 whole = isl_options_get_schedule_whole_component(ctx);
5257 isl_options_set_schedule_whole_component(ctx, 1);
5258 r = test_schedule(ctx);
5259 isl_options_set_schedule_whole_component(ctx, whole);
5261 return r;
5264 /* Perform scheduling tests using the incremental scheduler.
5266 static int test_schedule_incremental(isl_ctx *ctx)
5268 int whole;
5269 int r;
5271 whole = isl_options_get_schedule_whole_component(ctx);
5272 isl_options_set_schedule_whole_component(ctx, 0);
5273 r = test_schedule(ctx);
5274 isl_options_set_schedule_whole_component(ctx, whole);
5276 return r;
5279 int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
5281 isl_union_map *umap;
5282 int test;
5284 umap = isl_union_map_read_from_str(ctx, str);
5285 test = isl_union_map_plain_is_injective(umap);
5286 isl_union_map_free(umap);
5287 if (test < 0)
5288 return -1;
5289 if (test == injective)
5290 return 0;
5291 if (injective)
5292 isl_die(ctx, isl_error_unknown,
5293 "map not detected as injective", return -1);
5294 else
5295 isl_die(ctx, isl_error_unknown,
5296 "map detected as injective", return -1);
5299 int test_injective(isl_ctx *ctx)
5301 const char *str;
5303 if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
5304 return -1;
5305 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
5306 return -1;
5307 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
5308 return -1;
5309 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
5310 return -1;
5311 if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
5312 return -1;
5313 if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
5314 return -1;
5315 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
5316 return -1;
5317 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
5318 return -1;
5320 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
5321 if (test_plain_injective(ctx, str, 1))
5322 return -1;
5323 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
5324 if (test_plain_injective(ctx, str, 0))
5325 return -1;
5327 return 0;
5330 #undef BASE
5331 #define BASE aff
5332 #include "isl_test_plain_equal_templ.c"
5334 #undef BASE
5335 #define BASE pw_multi_aff
5336 #include "isl_test_plain_equal_templ.c"
5338 #undef BASE
5339 #define BASE union_pw_aff
5340 #include "isl_test_plain_equal_templ.c"
5342 /* Basic tests on isl_union_pw_aff.
5344 * In particular, check that isl_union_pw_aff_aff_on_domain
5345 * aligns the parameters of the input objects and
5346 * that isl_union_pw_aff_param_on_domain_id properly
5347 * introduces the parameter.
5349 static int test_upa(isl_ctx *ctx)
5351 const char *str;
5352 isl_id *id;
5353 isl_aff *aff;
5354 isl_union_set *domain;
5355 isl_union_pw_aff *upa;
5356 isl_stat ok;
5358 aff = isl_aff_read_from_str(ctx, "[N] -> { [N] }");
5359 str = "[M] -> { A[i] : 0 <= i < M; B[] }";
5360 domain = isl_union_set_read_from_str(ctx, str);
5361 upa = isl_union_pw_aff_aff_on_domain(domain, aff);
5362 str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5363 ok = union_pw_aff_check_plain_equal(upa, str);
5364 isl_union_pw_aff_free(upa);
5365 if (ok < 0)
5366 return -1;
5368 id = isl_id_alloc(ctx, "N", NULL);
5369 str = "[M] -> { A[i] : 0 <= i < M; B[] }";
5370 domain = isl_union_set_read_from_str(ctx, str);
5371 upa = isl_union_pw_aff_param_on_domain_id(domain, id);
5372 str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5373 ok = union_pw_aff_check_plain_equal(upa, str);
5374 isl_union_pw_aff_free(upa);
5375 if (ok < 0)
5376 return -1;
5378 return 0;
5381 struct {
5382 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
5383 __isl_take isl_aff *aff2);
5384 } aff_bin_op[] = {
5385 ['+'] = { &isl_aff_add },
5386 ['-'] = { &isl_aff_sub },
5387 ['*'] = { &isl_aff_mul },
5388 ['/'] = { &isl_aff_div },
5391 struct {
5392 const char *arg1;
5393 unsigned char op;
5394 const char *arg2;
5395 const char *res;
5396 } aff_bin_tests[] = {
5397 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5398 "{ [i] -> [2i] }" },
5399 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5400 "{ [i] -> [0] }" },
5401 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5402 "{ [i] -> [2i] }" },
5403 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5404 "{ [i] -> [2i] }" },
5405 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5406 "{ [i] -> [i/2] }" },
5407 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5408 "{ [i] -> [i] }" },
5409 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5410 "{ [i] -> [NaN] }" },
5411 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5412 "{ [i] -> [NaN] }" },
5413 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5414 "{ [i] -> [NaN] }" },
5415 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5416 "{ [i] -> [NaN] }" },
5417 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5418 "{ [i] -> [NaN] }" },
5419 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5420 "{ [i] -> [NaN] }" },
5421 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5422 "{ [i] -> [NaN] }" },
5423 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5424 "{ [i] -> [NaN] }" },
5425 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5426 "{ [i] -> [NaN] }" },
5427 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5428 "{ [i] -> [NaN] }" },
5429 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5430 "{ [i] -> [NaN] }" },
5431 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5432 "{ [i] -> [NaN] }" },
5433 { "{ [i] -> [i] }", '/', "{ [i] -> [0] }",
5434 "{ [i] -> [NaN] }" },
5437 /* Perform some basic tests of binary operations on isl_aff objects.
5439 static int test_bin_aff(isl_ctx *ctx)
5441 int i;
5442 isl_aff *aff1, *aff2, *res;
5443 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
5444 __isl_take isl_aff *aff2);
5445 int ok;
5447 for (i = 0; i < ARRAY_SIZE(aff_bin_tests); ++i) {
5448 aff1 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg1);
5449 aff2 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg2);
5450 res = isl_aff_read_from_str(ctx, aff_bin_tests[i].res);
5451 fn = aff_bin_op[aff_bin_tests[i].op].fn;
5452 aff1 = fn(aff1, aff2);
5453 if (isl_aff_is_nan(res))
5454 ok = isl_aff_is_nan(aff1);
5455 else
5456 ok = isl_aff_plain_is_equal(aff1, res);
5457 isl_aff_free(aff1);
5458 isl_aff_free(res);
5459 if (ok < 0)
5460 return -1;
5461 if (!ok)
5462 isl_die(ctx, isl_error_unknown,
5463 "unexpected result", return -1);
5466 return 0;
5469 struct {
5470 __isl_give isl_pw_aff *(*fn)(__isl_take isl_pw_aff *pa1,
5471 __isl_take isl_pw_aff *pa2);
5472 } pw_aff_bin_op[] = {
5473 ['m'] = { &isl_pw_aff_min },
5474 ['M'] = { &isl_pw_aff_max },
5477 /* Inputs for binary isl_pw_aff operation tests.
5478 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5479 * defined by pw_aff_bin_op, and "res" is the expected result.
5481 struct {
5482 const char *arg1;
5483 unsigned char op;
5484 const char *arg2;
5485 const char *res;
5486 } pw_aff_bin_tests[] = {
5487 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5488 "{ [i] -> [i] }" },
5489 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5490 "{ [i] -> [i] }" },
5491 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5492 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5493 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5494 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5495 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5496 "{ [i] -> [NaN] }" },
5497 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5498 "{ [i] -> [NaN] }" },
5501 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5503 static int test_bin_pw_aff(isl_ctx *ctx)
5505 int i;
5506 isl_bool ok;
5507 isl_pw_aff *pa1, *pa2, *res;
5509 for (i = 0; i < ARRAY_SIZE(pw_aff_bin_tests); ++i) {
5510 pa1 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg1);
5511 pa2 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg2);
5512 res = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].res);
5513 pa1 = pw_aff_bin_op[pw_aff_bin_tests[i].op].fn(pa1, pa2);
5514 if (isl_pw_aff_involves_nan(res))
5515 ok = isl_pw_aff_involves_nan(pa1);
5516 else
5517 ok = isl_pw_aff_plain_is_equal(pa1, res);
5518 isl_pw_aff_free(pa1);
5519 isl_pw_aff_free(res);
5520 if (ok < 0)
5521 return -1;
5522 if (!ok)
5523 isl_die(ctx, isl_error_unknown,
5524 "unexpected result", return -1);
5527 return 0;
5530 /* Inputs for basic tests of test operations on
5531 * isl_union_pw_multi_aff objects.
5532 * "fn" is the function that is being tested.
5533 * "arg" is a string description of the input.
5534 * "res" is the expected result.
5536 static struct {
5537 isl_bool (*fn)(__isl_keep isl_union_pw_multi_aff *upma1);
5538 const char *arg;
5539 isl_bool res;
5540 } upma_test_tests[] = {
5541 { &isl_union_pw_multi_aff_involves_nan, "{ A[] -> [0]; B[0] -> [1] }",
5542 isl_bool_false },
5543 { &isl_union_pw_multi_aff_involves_nan, "{ A[] -> [NaN]; B[0] -> [1] }",
5544 isl_bool_true },
5545 { &isl_union_pw_multi_aff_involves_nan, "{ A[] -> [0]; B[0] -> [NaN] }",
5546 isl_bool_true },
5547 { &isl_union_pw_multi_aff_involves_nan,
5548 "{ A[] -> [0]; B[0] -> [1, NaN, 5] }",
5549 isl_bool_true },
5550 { &isl_union_pw_multi_aff_involves_locals,
5551 "{ A[] -> [0]; B[0] -> [1] }",
5552 isl_bool_false },
5553 { &isl_union_pw_multi_aff_involves_locals,
5554 "{ A[] -> [0]; B[x] -> [1] : x mod 2 = 0 }",
5555 isl_bool_true },
5556 { &isl_union_pw_multi_aff_involves_locals,
5557 "{ A[] -> [0]; B[x] -> [x // 2] }",
5558 isl_bool_true },
5559 { &isl_union_pw_multi_aff_involves_locals,
5560 "{ A[i] -> [i // 2]; B[0] -> [1] }",
5561 isl_bool_true },
5564 /* Perform some basic tests of test operations on
5565 * isl_union_pw_multi_aff objects.
5567 static isl_stat test_upma_test(isl_ctx *ctx)
5569 int i;
5570 isl_union_pw_multi_aff *upma;
5571 isl_bool res;
5573 for (i = 0; i < ARRAY_SIZE(upma_test_tests); ++i) {
5574 const char *str;
5576 str = upma_test_tests[i].arg;
5577 upma = isl_union_pw_multi_aff_read_from_str(ctx, str);
5578 res = upma_test_tests[i].fn(upma);
5579 isl_union_pw_multi_aff_free(upma);
5580 if (res < 0)
5581 return isl_stat_error;
5582 if (res != upma_test_tests[i].res)
5583 isl_die(ctx, isl_error_unknown,
5584 "unexpected result", return isl_stat_error);
5587 return isl_stat_ok;
5590 struct {
5591 __isl_give isl_union_pw_multi_aff *(*fn)(
5592 __isl_take isl_union_pw_multi_aff *upma1,
5593 __isl_take isl_union_pw_multi_aff *upma2);
5594 const char *arg1;
5595 const char *arg2;
5596 const char *res;
5597 } upma_bin_tests[] = {
5598 { &isl_union_pw_multi_aff_add, "{ A[] -> [0]; B[0] -> [1] }",
5599 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5600 { &isl_union_pw_multi_aff_union_add, "{ A[] -> [0]; B[0] -> [1] }",
5601 "{ B[x] -> [2] : x >= 0 }",
5602 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5603 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff,
5604 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5605 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5606 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5607 "D[i] -> B[2] : i >= 5 }" },
5608 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5609 "{ B[x] -> C[2] : x > 0 }",
5610 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5611 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5612 "{ B[x] -> A[2] : x >= 0 }",
5613 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5615 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff,
5616 "{ B[x] -> C[x + 2] }",
5617 "{ D[y] -> B[2y] }",
5618 "{ }" },
5620 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff,
5621 "{ [A[x] -> B[x + 1]] -> C[x + 2] }",
5622 "{ D[y] -> B[2y] }",
5623 "{ }" },
5625 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff,
5626 "{ [A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5627 "{ D[y] -> A[2y] }",
5628 "{ [D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5630 &isl_union_pw_multi_aff_preimage_domain_wrapped_domain_union_pw_multi_aff,
5631 "{ T[A[x] -> B[x + 1]] -> C[x + 2]; B[x] -> C[x + 2] }",
5632 "{ D[y] -> A[2y] }",
5633 "{ T[D[y] -> B[2y + 1]] -> C[2y + 2] }" },
5636 /* Perform some basic tests of binary operations on
5637 * isl_union_pw_multi_aff objects.
5639 static int test_bin_upma(isl_ctx *ctx)
5641 int i;
5642 isl_union_pw_multi_aff *upma1, *upma2, *res;
5643 int ok;
5645 for (i = 0; i < ARRAY_SIZE(upma_bin_tests); ++i) {
5646 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
5647 upma_bin_tests[i].arg1);
5648 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
5649 upma_bin_tests[i].arg2);
5650 res = isl_union_pw_multi_aff_read_from_str(ctx,
5651 upma_bin_tests[i].res);
5652 upma1 = upma_bin_tests[i].fn(upma1, upma2);
5653 ok = isl_union_pw_multi_aff_plain_is_equal(upma1, res);
5654 isl_union_pw_multi_aff_free(upma1);
5655 isl_union_pw_multi_aff_free(res);
5656 if (ok < 0)
5657 return -1;
5658 if (!ok)
5659 isl_die(ctx, isl_error_unknown,
5660 "unexpected result", return -1);
5663 return 0;
5666 struct {
5667 __isl_give isl_union_pw_multi_aff *(*fn)(
5668 __isl_take isl_union_pw_multi_aff *upma1,
5669 __isl_take isl_union_pw_multi_aff *upma2);
5670 const char *arg1;
5671 const char *arg2;
5672 } upma_bin_fail_tests[] = {
5673 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5674 "{ B[x] -> C[2] : x >= 0 }" },
5677 /* Perform some basic tests of binary operations on
5678 * isl_union_pw_multi_aff objects that are expected to fail.
5680 static int test_bin_upma_fail(isl_ctx *ctx)
5682 int i, n;
5683 isl_union_pw_multi_aff *upma1, *upma2;
5684 int on_error;
5686 on_error = isl_options_get_on_error(ctx);
5687 isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE);
5688 n = ARRAY_SIZE(upma_bin_fail_tests);
5689 for (i = 0; i < n; ++i) {
5690 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
5691 upma_bin_fail_tests[i].arg1);
5692 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
5693 upma_bin_fail_tests[i].arg2);
5694 upma1 = upma_bin_fail_tests[i].fn(upma1, upma2);
5695 isl_union_pw_multi_aff_free(upma1);
5696 if (upma1)
5697 break;
5699 isl_options_set_on_error(ctx, on_error);
5700 if (i < n)
5701 isl_die(ctx, isl_error_unknown,
5702 "operation not expected to succeed", return -1);
5704 return 0;
5707 /* Inputs for basic tests of binary operations on
5708 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5709 * "fn" is the function that is being tested.
5710 * "arg1" and "arg2" are string descriptions of the inputs.
5711 * "res" is a string description of the expected result.
5713 struct {
5714 __isl_give isl_union_pw_multi_aff *(*fn)(
5715 __isl_take isl_union_pw_multi_aff *upma,
5716 __isl_take isl_union_set *uset);
5717 const char *arg1;
5718 const char *arg2;
5719 const char *res;
5720 } upma_uset_tests[] = {
5721 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5722 "{ A[i] -> B[i] }", "{ B[0] }",
5723 "{ }" },
5724 { &isl_union_pw_multi_aff_intersect_domain_wrapped_domain,
5725 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5726 "{ [A[1] -> B[1]] -> C[2] }" },
5727 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5728 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5729 "{ [A[0] -> B[0]] -> C[1] }" },
5730 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5731 "{ [A[i] -> B[i]] -> C[i + 1] }", "[N] -> { B[N] }",
5732 "[N] -> { [A[N] -> B[N]] -> C[N + 1] }" },
5733 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5734 "[M] -> { [A[M] -> B[M]] -> C[M + 1] }", "[N] -> { B[N] }",
5735 "[N, M] -> { [A[N] -> B[N]] -> C[N + 1] : N = M }" },
5736 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5737 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[]; [B[] -> A[]] -> E[] }",
5738 "{ B[] }",
5739 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[] }" },
5742 /* Perform some basic tests of binary operations on
5743 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5745 static isl_stat test_upma_uset(isl_ctx *ctx)
5747 int i;
5748 isl_bool ok;
5749 isl_union_pw_multi_aff *upma, *res;
5750 isl_union_set *uset;
5752 for (i = 0; i < ARRAY_SIZE(upma_uset_tests); ++i) {
5753 upma = isl_union_pw_multi_aff_read_from_str(ctx,
5754 upma_uset_tests[i].arg1);
5755 uset = isl_union_set_read_from_str(ctx,
5756 upma_uset_tests[i].arg2);
5757 res = isl_union_pw_multi_aff_read_from_str(ctx,
5758 upma_uset_tests[i].res);
5759 upma = upma_uset_tests[i].fn(upma, uset);
5760 ok = isl_union_pw_multi_aff_plain_is_equal(upma, res);
5761 isl_union_pw_multi_aff_free(upma);
5762 isl_union_pw_multi_aff_free(res);
5763 if (ok < 0)
5764 return isl_stat_error;
5765 if (!ok)
5766 isl_die(ctx, isl_error_unknown,
5767 "unexpected result", return isl_stat_error);
5770 return isl_stat_ok;
5773 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5774 * "fn" is the function that is tested.
5775 * "arg" is a string description of the input.
5776 * "res" is a string description of the expected result.
5778 struct {
5779 __isl_give isl_multi_pw_aff *(*fn)(__isl_take isl_multi_pw_aff *mpa);
5780 const char *arg;
5781 const char *res;
5782 } mpa_un_tests[] = {
5783 { &isl_multi_pw_aff_range_factor_domain,
5784 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5785 "{ A[x] -> B[(1 : x >= 5)] }" },
5786 { &isl_multi_pw_aff_range_factor_range,
5787 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5788 "{ A[y] -> C[(2 : y <= 10)] }" },
5789 { &isl_multi_pw_aff_range_factor_domain,
5790 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5791 "{ A[x] -> B[(1 : x >= 5)] }" },
5792 { &isl_multi_pw_aff_range_factor_range,
5793 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5794 "{ A[y] -> C[] }" },
5795 { &isl_multi_pw_aff_range_factor_domain,
5796 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5797 "{ A[x] -> B[] }" },
5798 { &isl_multi_pw_aff_range_factor_range,
5799 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5800 "{ A[y] -> C[(2 : y <= 10)] }" },
5801 { &isl_multi_pw_aff_range_factor_domain,
5802 "{ A[x] -> [B[] -> C[]] }",
5803 "{ A[x] -> B[] }" },
5804 { &isl_multi_pw_aff_range_factor_range,
5805 "{ A[x] -> [B[] -> C[]] }",
5806 "{ A[y] -> C[] }" },
5807 { &isl_multi_pw_aff_factor_range,
5808 "{ [B[] -> C[]] }",
5809 "{ C[] }" },
5810 { &isl_multi_pw_aff_range_factor_domain,
5811 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5812 "{ A[x] -> B[] : x >= 0 }" },
5813 { &isl_multi_pw_aff_range_factor_range,
5814 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5815 "{ A[y] -> C[] : y >= 0 }" },
5816 { &isl_multi_pw_aff_factor_range,
5817 "[N] -> { [B[] -> C[]] : N >= 0 }",
5818 "[N] -> { C[] : N >= 0 }" },
5821 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5823 static int test_un_mpa(isl_ctx *ctx)
5825 int i;
5826 isl_bool ok;
5827 isl_multi_pw_aff *mpa, *res;
5829 for (i = 0; i < ARRAY_SIZE(mpa_un_tests); ++i) {
5830 mpa = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].arg);
5831 res = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].res);
5832 mpa = mpa_un_tests[i].fn(mpa);
5833 ok = isl_multi_pw_aff_plain_is_equal(mpa, res);
5834 isl_multi_pw_aff_free(mpa);
5835 isl_multi_pw_aff_free(res);
5836 if (ok < 0)
5837 return -1;
5838 if (!ok)
5839 isl_die(ctx, isl_error_unknown,
5840 "unexpected result", return -1);
5843 return 0;
5846 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5847 * "fn" is the function that is tested.
5848 * "arg1" and "arg2" are string descriptions of the inputs.
5849 * "res" is a string description of the expected result.
5851 struct {
5852 __isl_give isl_multi_pw_aff *(*fn)(
5853 __isl_take isl_multi_pw_aff *mpa1,
5854 __isl_take isl_multi_pw_aff *mpa2);
5855 const char *arg1;
5856 const char *arg2;
5857 const char *res;
5858 } mpa_bin_tests[] = {
5859 { &isl_multi_pw_aff_add, "{ A[] -> [1] }", "{ A[] -> [2] }",
5860 "{ A[] -> [3] }" },
5861 { &isl_multi_pw_aff_add, "{ A[x] -> [(1 : x >= 5)] }",
5862 "{ A[x] -> [(x : x <= 10)] }",
5863 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5864 { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }",
5865 "{ A[x] -> [] : x <= 10 }",
5866 "{ A[x] -> [] : 5 <= x <= 10 }" },
5867 { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }",
5868 "[N] -> { A[x] -> [] : x <= N }",
5869 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5870 { &isl_multi_pw_aff_add,
5871 "[N] -> { A[x] -> [] : x <= N }",
5872 "{ A[x] -> [] : x >= 5 }",
5873 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5874 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }",
5875 "{ A[y] -> C[(2 : y <= 10)] }",
5876 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5877 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }",
5878 "{ A[y] -> C[2] : y <= 10 }",
5879 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5880 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }",
5881 "[N] -> { A[y] -> C[2] : y <= N }",
5882 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5883 { &isl_multi_pw_aff_range_product, "[N] -> { A[x] -> B[1] : x >= N }",
5884 "{ A[y] -> C[2] : y <= 10 }",
5885 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5886 { &isl_multi_pw_aff_range_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5887 "{ A[] -> [B[1] -> C[2]] }" },
5888 { &isl_multi_pw_aff_range_product, "{ A[] -> B[] }", "{ A[] -> C[] }",
5889 "{ A[] -> [B[] -> C[]] }" },
5890 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }",
5891 "{ A[y] -> C[] : y <= 10 }",
5892 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5893 { &isl_multi_pw_aff_range_product, "{ A[y] -> C[] : y <= 10 }",
5894 "{ A[x] -> B[(1 : x >= 5)] }",
5895 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5896 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5897 "{ A[y] -> C[(2 : y <= 10)] }",
5898 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5899 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5900 "{ A[y] -> C[] : y <= 10 }",
5901 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5902 { &isl_multi_pw_aff_product, "{ A[y] -> C[] : y <= 10 }",
5903 "{ A[x] -> B[(1 : x >= 5)] }",
5904 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5905 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5906 "[N] -> { A[y] -> C[] : y <= N }",
5907 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5908 { &isl_multi_pw_aff_product, "[N] -> { A[y] -> C[] : y <= N }",
5909 "{ A[x] -> B[(1 : x >= 5)] }",
5910 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5911 { &isl_multi_pw_aff_product, "{ A[x] -> B[] : x >= 5 }",
5912 "{ A[y] -> C[] : y <= 10 }",
5913 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5914 { &isl_multi_pw_aff_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5915 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5916 { &isl_multi_pw_aff_product, "{ A[] -> B[] }", "{ A[] -> C[] }",
5917 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5918 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5919 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5920 "{ A[a,b] -> C[b + 2a] }" },
5921 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5922 "{ B[i,j] -> C[i + 2j] }",
5923 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5924 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5925 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5926 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5927 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5928 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5929 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5930 "{ B[i,j] -> C[] }",
5931 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5932 "{ A[a,b] -> C[] }" },
5933 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5934 "{ B[i,j] -> C[] : i > j }",
5935 "{ A[a,b] -> B[b,a] }",
5936 "{ A[a,b] -> C[] : b > a }" },
5937 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5938 "{ B[i,j] -> C[] : j > 5 }",
5939 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5940 "{ A[a,b] -> C[] : b > a > 5 }" },
5941 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5942 "[N] -> { B[i,j] -> C[] : j > N }",
5943 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5944 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5945 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5946 "[M,N] -> { B[] -> C[] : N > 5 }",
5947 "[M,N] -> { A[] -> B[] : M > N }",
5948 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5951 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5953 static int test_bin_mpa(isl_ctx *ctx)
5955 int i;
5956 isl_bool ok;
5957 isl_multi_pw_aff *mpa1, *mpa2, *res;
5959 for (i = 0; i < ARRAY_SIZE(mpa_bin_tests); ++i) {
5960 mpa1 = isl_multi_pw_aff_read_from_str(ctx,
5961 mpa_bin_tests[i].arg1);
5962 mpa2 = isl_multi_pw_aff_read_from_str(ctx,
5963 mpa_bin_tests[i].arg2);
5964 res = isl_multi_pw_aff_read_from_str(ctx,
5965 mpa_bin_tests[i].res);
5966 mpa1 = mpa_bin_tests[i].fn(mpa1, mpa2);
5967 ok = isl_multi_pw_aff_plain_is_equal(mpa1, res);
5968 isl_multi_pw_aff_free(mpa1);
5969 isl_multi_pw_aff_free(res);
5970 if (ok < 0)
5971 return -1;
5972 if (!ok)
5973 isl_die(ctx, isl_error_unknown,
5974 "unexpected result", return -1);
5977 return 0;
5980 /* Inputs for basic tests of unary operations on
5981 * isl_multi_union_pw_aff objects.
5982 * "fn" is the function that is tested.
5983 * "arg" is a string description of the input.
5984 * "res" is a string description of the expected result.
5986 struct {
5987 __isl_give isl_multi_union_pw_aff *(*fn)(
5988 __isl_take isl_multi_union_pw_aff *mupa);
5989 const char *arg;
5990 const char *res;
5991 } mupa_un_tests[] = {
5992 { &isl_multi_union_pw_aff_factor_range,
5993 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5994 "C[{ A[] -> [2] }]" },
5995 { &isl_multi_union_pw_aff_factor_range,
5996 "[B[] -> C[{ A[] -> [2] }]]",
5997 "C[{ A[] -> [2] }]" },
5998 { &isl_multi_union_pw_aff_factor_range,
5999 "[B[{ A[] -> [1] }] -> C[]]",
6000 "C[]" },
6001 { &isl_multi_union_pw_aff_factor_range,
6002 "[B[] -> C[]]",
6003 "C[]" },
6004 { &isl_multi_union_pw_aff_factor_range,
6005 "([B[] -> C[]] : { A[x] : x >= 0 })",
6006 "(C[] : { A[x] : x >= 0 })" },
6007 { &isl_multi_union_pw_aff_factor_range,
6008 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
6009 "[N] -> (C[] : { A[x] : x <= N })" },
6010 { &isl_multi_union_pw_aff_factor_range,
6011 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
6012 "[N] -> (C[] : { : N >= 0 })" },
6015 /* Perform some basic tests of unary operations on
6016 * isl_multi_union_pw_aff objects.
6018 static int test_un_mupa(isl_ctx *ctx)
6020 int i;
6021 isl_bool ok;
6022 isl_multi_union_pw_aff *mupa, *res;
6024 for (i = 0; i < ARRAY_SIZE(mupa_un_tests); ++i) {
6025 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6026 mupa_un_tests[i].arg);
6027 res = isl_multi_union_pw_aff_read_from_str(ctx,
6028 mupa_un_tests[i].res);
6029 mupa = mupa_un_tests[i].fn(mupa);
6030 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6031 isl_multi_union_pw_aff_free(mupa);
6032 isl_multi_union_pw_aff_free(res);
6033 if (ok < 0)
6034 return -1;
6035 if (!ok)
6036 isl_die(ctx, isl_error_unknown,
6037 "unexpected result", return -1);
6040 return 0;
6043 /* Inputs for basic tests of binary operations on
6044 * isl_multi_union_pw_aff objects.
6045 * "fn" is the function that is tested.
6046 * "arg1" and "arg2" are string descriptions of the inputs.
6047 * "res" is a string description of the expected result.
6049 struct {
6050 __isl_give isl_multi_union_pw_aff *(*fn)(
6051 __isl_take isl_multi_union_pw_aff *mupa1,
6052 __isl_take isl_multi_union_pw_aff *mupa2);
6053 const char *arg1;
6054 const char *arg2;
6055 const char *res;
6056 } mupa_bin_tests[] = {
6057 { &isl_multi_union_pw_aff_add, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6058 "[{ A[] -> [3] }]" },
6059 { &isl_multi_union_pw_aff_sub, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6060 "[{ A[] -> [-1] }]" },
6061 { &isl_multi_union_pw_aff_add,
6062 "[{ A[] -> [1]; B[] -> [4] }]",
6063 "[{ A[] -> [2]; C[] -> [5] }]",
6064 "[{ A[] -> [3] }]" },
6065 { &isl_multi_union_pw_aff_union_add,
6066 "[{ A[] -> [1]; B[] -> [4] }]",
6067 "[{ A[] -> [2]; C[] -> [5] }]",
6068 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
6069 { &isl_multi_union_pw_aff_add, "[{ A[x] -> [(1)] : x >= 5 }]",
6070 "[{ A[x] -> [(x)] : x <= 10 }]",
6071 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
6072 { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })",
6073 "([] : { A[x] : x <= 10 })",
6074 "([] : { A[x] : 5 <= x <= 10 })" },
6075 { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })",
6076 "[N] -> ([] : { A[x] : x <= N })",
6077 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
6078 { &isl_multi_union_pw_aff_add, "[N] -> ([] : { A[x] : x >= N })",
6079 "([] : { A[x] : x <= 10 })",
6080 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
6081 { &isl_multi_union_pw_aff_union_add, "[{ A[x] -> [(1)] : x >= 5 }]",
6082 "[{ A[x] -> [(x)] : x <= 10 }]",
6083 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
6084 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
6085 { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 5 })",
6086 "([] : { A[x] : x <= 10 })",
6087 "([] : { A[x] })" },
6088 { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 0 })",
6089 "[N] -> ([] : { A[x] : x >= N })",
6090 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
6091 { &isl_multi_union_pw_aff_union_add,
6092 "[N] -> ([] : { A[] : N >= 0})",
6093 "[N] -> ([] : { A[] : N <= 0})",
6094 "[N] -> ([] : { A[] })" },
6095 { &isl_multi_union_pw_aff_union_add,
6096 "[N] -> ([] : { A[] })",
6097 "[N] -> ([] : { : })",
6098 "[N] -> ([] : { : })" },
6099 { &isl_multi_union_pw_aff_union_add,
6100 "[N] -> ([] : { : })",
6101 "[N] -> ([] : { A[] })",
6102 "[N] -> ([] : { : })" },
6103 { &isl_multi_union_pw_aff_union_add,
6104 "[N] -> ([] : { : N >= 0})",
6105 "[N] -> ([] : { : N <= 0})",
6106 "[N] -> ([] : { : })" },
6107 { &isl_multi_union_pw_aff_range_product,
6108 "B[{ A[] -> [1] }]",
6109 "C[{ A[] -> [2] }]",
6110 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
6111 { &isl_multi_union_pw_aff_range_product,
6112 "(B[] : { A[x] : x >= 5 })",
6113 "(C[] : { A[x] : x <= 10 })",
6114 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
6115 { &isl_multi_union_pw_aff_range_product,
6116 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6117 "(C[] : { A[x] : x <= 10 })",
6118 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
6119 { &isl_multi_union_pw_aff_range_product,
6120 "(C[] : { A[x] : x <= 10 })",
6121 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6122 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
6123 { &isl_multi_union_pw_aff_range_product,
6124 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6125 "[N] -> (C[] : { A[x] : x <= N })",
6126 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
6127 { &isl_multi_union_pw_aff_range_product,
6128 "[N] -> (C[] : { A[x] : x <= N })",
6129 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6130 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
6131 { &isl_multi_union_pw_aff_range_product,
6132 "B[{ A[] -> [1]; D[] -> [3] }]",
6133 "C[{ A[] -> [2] }]",
6134 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
6135 { &isl_multi_union_pw_aff_range_product,
6136 "B[] }]",
6137 "(C[] : { A[x] })",
6138 "([B[] -> C[]] : { A[x] })" },
6139 { &isl_multi_union_pw_aff_range_product,
6140 "(B[] : { A[x] })",
6141 "C[] }]",
6142 "([B[] -> C[]] : { A[x] })" },
6145 /* Perform some basic tests of binary operations on
6146 * isl_multi_union_pw_aff objects.
6148 static int test_bin_mupa(isl_ctx *ctx)
6150 int i;
6151 isl_bool ok;
6152 isl_multi_union_pw_aff *mupa1, *mupa2, *res;
6154 for (i = 0; i < ARRAY_SIZE(mupa_bin_tests); ++i) {
6155 mupa1 = isl_multi_union_pw_aff_read_from_str(ctx,
6156 mupa_bin_tests[i].arg1);
6157 mupa2 = isl_multi_union_pw_aff_read_from_str(ctx,
6158 mupa_bin_tests[i].arg2);
6159 res = isl_multi_union_pw_aff_read_from_str(ctx,
6160 mupa_bin_tests[i].res);
6161 mupa1 = mupa_bin_tests[i].fn(mupa1, mupa2);
6162 ok = isl_multi_union_pw_aff_plain_is_equal(mupa1, res);
6163 isl_multi_union_pw_aff_free(mupa1);
6164 isl_multi_union_pw_aff_free(res);
6165 if (ok < 0)
6166 return -1;
6167 if (!ok)
6168 isl_die(ctx, isl_error_unknown,
6169 "unexpected result", return -1);
6172 return 0;
6175 /* Inputs for basic tests of binary operations on
6176 * pairs of isl_multi_union_pw_aff and isl_set objects.
6177 * "fn" is the function that is tested.
6178 * "arg1" and "arg2" are string descriptions of the inputs.
6179 * "res" is a string description of the expected result.
6181 struct {
6182 __isl_give isl_multi_union_pw_aff *(*fn)(
6183 __isl_take isl_multi_union_pw_aff *mupa,
6184 __isl_take isl_set *set);
6185 const char *arg1;
6186 const char *arg2;
6187 const char *res;
6188 } mupa_set_tests[] = {
6189 { &isl_multi_union_pw_aff_intersect_range,
6190 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
6191 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
6192 { &isl_multi_union_pw_aff_intersect_range,
6193 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
6194 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
6195 { &isl_multi_union_pw_aff_intersect_range,
6196 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
6197 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
6198 { &isl_multi_union_pw_aff_intersect_range,
6199 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
6200 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
6201 { &isl_multi_union_pw_aff_intersect_range,
6202 "C[]", "{ C[] }", "C[]" },
6203 { &isl_multi_union_pw_aff_intersect_range,
6204 "[N] -> (C[] : { : N >= 0 })",
6205 "{ C[] }",
6206 "[N] -> (C[] : { : N >= 0 })" },
6207 { &isl_multi_union_pw_aff_intersect_range,
6208 "(C[] : { A[a,b] })",
6209 "{ C[] }",
6210 "(C[] : { A[a,b] })" },
6211 { &isl_multi_union_pw_aff_intersect_range,
6212 "[N] -> (C[] : { A[a,b] : a,b <= N })",
6213 "{ C[] }",
6214 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
6215 { &isl_multi_union_pw_aff_intersect_range,
6216 "C[]",
6217 "[N] -> { C[] : N >= 0 }",
6218 "[N] -> (C[] : { : N >= 0 })" },
6219 { &isl_multi_union_pw_aff_intersect_range,
6220 "(C[] : { A[a,b] })",
6221 "[N] -> { C[] : N >= 0 }",
6222 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6223 { &isl_multi_union_pw_aff_intersect_range,
6224 "[N] -> (C[] : { : N >= 0 })",
6225 "[N] -> { C[] : N < 1024 }",
6226 "[N] -> (C[] : { : 0 <= N < 1024 })" },
6227 { &isl_multi_union_pw_aff_intersect_params,
6228 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
6229 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
6230 { &isl_multi_union_pw_aff_intersect_params,
6231 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
6232 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
6233 { &isl_multi_union_pw_aff_intersect_params,
6234 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
6235 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
6236 { &isl_multi_union_pw_aff_intersect_params,
6237 "C[]", "[N] -> { : N >= 0 }",
6238 "[N] -> (C[] : { : N >= 0 })" },
6239 { &isl_multi_union_pw_aff_intersect_params,
6240 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
6241 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6242 { &isl_multi_union_pw_aff_intersect_params,
6243 "[N] -> (C[] : { A[a,N] })", "{ : }",
6244 "[N] -> (C[] : { A[a,N] })" },
6245 { &isl_multi_union_pw_aff_intersect_params,
6246 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
6247 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
6250 /* Perform some basic tests of binary operations on
6251 * pairs of isl_multi_union_pw_aff and isl_set objects.
6253 static int test_mupa_set(isl_ctx *ctx)
6255 int i;
6256 isl_bool ok;
6257 isl_multi_union_pw_aff *mupa, *res;
6258 isl_set *set;
6260 for (i = 0; i < ARRAY_SIZE(mupa_set_tests); ++i) {
6261 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6262 mupa_set_tests[i].arg1);
6263 set = isl_set_read_from_str(ctx, mupa_set_tests[i].arg2);
6264 res = isl_multi_union_pw_aff_read_from_str(ctx,
6265 mupa_set_tests[i].res);
6266 mupa = mupa_set_tests[i].fn(mupa, set);
6267 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6268 isl_multi_union_pw_aff_free(mupa);
6269 isl_multi_union_pw_aff_free(res);
6270 if (ok < 0)
6271 return -1;
6272 if (!ok)
6273 isl_die(ctx, isl_error_unknown,
6274 "unexpected result", return -1);
6277 return 0;
6280 /* Inputs for basic tests of binary operations on
6281 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6282 * "fn" is the function that is tested.
6283 * "arg1" and "arg2" are string descriptions of the inputs.
6284 * "res" is a string description of the expected result.
6286 struct {
6287 __isl_give isl_multi_union_pw_aff *(*fn)(
6288 __isl_take isl_multi_union_pw_aff *mupa,
6289 __isl_take isl_union_set *uset);
6290 const char *arg1;
6291 const char *arg2;
6292 const char *res;
6293 } mupa_uset_tests[] = {
6294 { &isl_multi_union_pw_aff_intersect_domain,
6295 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
6296 "C[{ B[i,i] -> [3i] }]" },
6297 { &isl_multi_union_pw_aff_intersect_domain,
6298 "(C[] : { B[i,j] })", "{ B[i,i] }",
6299 "(C[] : { B[i,i] })" },
6300 { &isl_multi_union_pw_aff_intersect_domain,
6301 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
6302 "[N] -> (C[] : { B[N,N] })" },
6303 { &isl_multi_union_pw_aff_intersect_domain,
6304 "C[]", "{ B[i,i] }",
6305 "(C[] : { B[i,i] })" },
6306 { &isl_multi_union_pw_aff_intersect_domain,
6307 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
6308 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
6311 /* Perform some basic tests of binary operations on
6312 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6314 static int test_mupa_uset(isl_ctx *ctx)
6316 int i;
6317 isl_bool ok;
6318 isl_multi_union_pw_aff *mupa, *res;
6319 isl_union_set *uset;
6321 for (i = 0; i < ARRAY_SIZE(mupa_uset_tests); ++i) {
6322 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6323 mupa_uset_tests[i].arg1);
6324 uset = isl_union_set_read_from_str(ctx,
6325 mupa_uset_tests[i].arg2);
6326 res = isl_multi_union_pw_aff_read_from_str(ctx,
6327 mupa_uset_tests[i].res);
6328 mupa = mupa_uset_tests[i].fn(mupa, uset);
6329 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6330 isl_multi_union_pw_aff_free(mupa);
6331 isl_multi_union_pw_aff_free(res);
6332 if (ok < 0)
6333 return -1;
6334 if (!ok)
6335 isl_die(ctx, isl_error_unknown,
6336 "unexpected result", return -1);
6339 return 0;
6342 /* Inputs for basic tests of binary operations on
6343 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6344 * "fn" is the function that is tested.
6345 * "arg1" and "arg2" are string descriptions of the inputs.
6346 * "res" is a string description of the expected result.
6348 struct {
6349 __isl_give isl_multi_union_pw_aff *(*fn)(
6350 __isl_take isl_multi_union_pw_aff *mupa,
6351 __isl_take isl_multi_aff *ma);
6352 const char *arg1;
6353 const char *arg2;
6354 const char *res;
6355 } mupa_ma_tests[] = {
6356 { &isl_multi_union_pw_aff_apply_multi_aff,
6357 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6358 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6359 "{ C[a,b] -> D[b,a] }",
6360 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6361 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6362 { &isl_multi_union_pw_aff_apply_multi_aff,
6363 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6364 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6365 "{ C[a,b] -> D[b,a] }",
6366 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6367 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6368 { &isl_multi_union_pw_aff_apply_multi_aff,
6369 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6370 "[N] -> { C[a] -> D[a + N] }",
6371 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
6372 { &isl_multi_union_pw_aff_apply_multi_aff,
6373 "C[]",
6374 "{ C[] -> D[] }",
6375 "D[]" },
6376 { &isl_multi_union_pw_aff_apply_multi_aff,
6377 "[N] -> (C[] : { : N >= 0 })",
6378 "{ C[] -> D[] }",
6379 "[N] -> (D[] : { : N >= 0 })" },
6380 { &isl_multi_union_pw_aff_apply_multi_aff,
6381 "C[]",
6382 "[N] -> { C[] -> D[N] }",
6383 "[N] -> D[{ [N] }]" },
6384 { &isl_multi_union_pw_aff_apply_multi_aff,
6385 "(C[] : { A[i,j] : i >= j })",
6386 "{ C[] -> D[] }",
6387 "(D[] : { A[i,j] : i >= j })" },
6388 { &isl_multi_union_pw_aff_apply_multi_aff,
6389 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6390 "{ C[] -> D[] }",
6391 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6392 { &isl_multi_union_pw_aff_apply_multi_aff,
6393 "(C[] : { A[i,j] : i >= j })",
6394 "[N] -> { C[] -> D[N] }",
6395 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6398 /* Perform some basic tests of binary operations on
6399 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6401 static int test_mupa_ma(isl_ctx *ctx)
6403 int i;
6404 isl_bool ok;
6405 isl_multi_union_pw_aff *mupa, *res;
6406 isl_multi_aff *ma;
6408 for (i = 0; i < ARRAY_SIZE(mupa_ma_tests); ++i) {
6409 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6410 mupa_ma_tests[i].arg1);
6411 ma = isl_multi_aff_read_from_str(ctx, mupa_ma_tests[i].arg2);
6412 res = isl_multi_union_pw_aff_read_from_str(ctx,
6413 mupa_ma_tests[i].res);
6414 mupa = mupa_ma_tests[i].fn(mupa, ma);
6415 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6416 isl_multi_union_pw_aff_free(mupa);
6417 isl_multi_union_pw_aff_free(res);
6418 if (ok < 0)
6419 return -1;
6420 if (!ok)
6421 isl_die(ctx, isl_error_unknown,
6422 "unexpected result", return -1);
6425 return 0;
6428 /* Inputs for basic tests of binary operations on
6429 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6430 * "fn" is the function that is tested.
6431 * "arg1" and "arg2" are string descriptions of the inputs.
6432 * "res" is a string description of the expected result.
6434 struct {
6435 __isl_give isl_union_pw_aff *(*fn)(
6436 __isl_take isl_multi_union_pw_aff *mupa,
6437 __isl_take isl_pw_aff *pa);
6438 const char *arg1;
6439 const char *arg2;
6440 const char *res;
6441 } mupa_pa_tests[] = {
6442 { &isl_multi_union_pw_aff_apply_pw_aff,
6443 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6444 "[N] -> { C[a] -> [a + N] }",
6445 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
6446 { &isl_multi_union_pw_aff_apply_pw_aff,
6447 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6448 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
6449 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6450 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
6451 { &isl_multi_union_pw_aff_apply_pw_aff,
6452 "C[]",
6453 "[N] -> { C[] -> [N] }",
6454 "[N] -> { [N] }" },
6455 { &isl_multi_union_pw_aff_apply_pw_aff,
6456 "C[]",
6457 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6458 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
6459 { &isl_multi_union_pw_aff_apply_pw_aff,
6460 "[N] -> (C[] : { : N >= 0 })",
6461 "[N] -> { C[] -> [N] }",
6462 "[N] -> { [N] : N >= 0 }" },
6463 { &isl_multi_union_pw_aff_apply_pw_aff,
6464 "[N] -> (C[] : { : N >= 0 })",
6465 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6466 "[N] -> { [N] : N >= 0 }" },
6467 { &isl_multi_union_pw_aff_apply_pw_aff,
6468 "[N] -> (C[] : { : N >= 0 })",
6469 "{ C[] -> [0] }",
6470 "[N] -> { [0] : N >= 0 }" },
6471 { &isl_multi_union_pw_aff_apply_pw_aff,
6472 "(C[] : { A[i,j] : i >= j })",
6473 "[N] -> { C[] -> [N] }",
6474 "[N] -> { A[i,j] -> [N] : i >= j }" },
6475 { &isl_multi_union_pw_aff_apply_pw_aff,
6476 "(C[] : { A[i,j] : i >= j })",
6477 "[N] -> { C[] -> [N] : N >= 0 }",
6478 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6481 /* Perform some basic tests of binary operations on
6482 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6484 static int test_mupa_pa(isl_ctx *ctx)
6486 int i;
6487 isl_bool ok;
6488 isl_multi_union_pw_aff *mupa;
6489 isl_union_pw_aff *upa, *res;
6490 isl_pw_aff *pa;
6492 for (i = 0; i < ARRAY_SIZE(mupa_pa_tests); ++i) {
6493 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6494 mupa_pa_tests[i].arg1);
6495 pa = isl_pw_aff_read_from_str(ctx, mupa_pa_tests[i].arg2);
6496 res = isl_union_pw_aff_read_from_str(ctx,
6497 mupa_pa_tests[i].res);
6498 upa = mupa_pa_tests[i].fn(mupa, pa);
6499 ok = isl_union_pw_aff_plain_is_equal(upa, res);
6500 isl_union_pw_aff_free(upa);
6501 isl_union_pw_aff_free(res);
6502 if (ok < 0)
6503 return -1;
6504 if (!ok)
6505 isl_die(ctx, isl_error_unknown,
6506 "unexpected result", return -1);
6509 return 0;
6512 /* Inputs for basic tests of binary operations on
6513 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6514 * "fn" is the function that is tested.
6515 * "arg1" and "arg2" are string descriptions of the inputs.
6516 * "res" is a string description of the expected result.
6518 struct {
6519 __isl_give isl_multi_union_pw_aff *(*fn)(
6520 __isl_take isl_multi_union_pw_aff *mupa,
6521 __isl_take isl_pw_multi_aff *pma);
6522 const char *arg1;
6523 const char *arg2;
6524 const char *res;
6525 } mupa_pma_tests[] = {
6526 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6527 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6528 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6529 "{ C[a,b] -> D[b,a] }",
6530 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6531 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6532 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6533 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6534 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6535 "{ C[a,b] -> D[b,a] }",
6536 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6537 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6538 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6539 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6540 "[N] -> { C[a] -> D[a + N] }",
6541 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6542 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6543 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6544 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6545 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6546 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6547 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6548 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6549 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6550 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6551 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6552 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6553 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6554 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6555 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6556 "C[]",
6557 "{ C[] -> D[] }",
6558 "D[]" },
6559 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6560 "[N] -> (C[] : { : N >= 0 })",
6561 "{ C[] -> D[] }",
6562 "[N] -> (D[] : { : N >= 0 })" },
6563 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6564 "C[]",
6565 "[N] -> { C[] -> D[N] }",
6566 "[N] -> D[{ [N] }]" },
6567 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6568 "(C[] : { A[i,j] : i >= j })",
6569 "{ C[] -> D[] }",
6570 "(D[] : { A[i,j] : i >= j })" },
6571 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6572 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6573 "{ C[] -> D[] }",
6574 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6575 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6576 "(C[] : { A[i,j] : i >= j })",
6577 "[N] -> { C[] -> D[N] }",
6578 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6579 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6580 "C[]",
6581 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6582 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6583 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6584 "[N] -> (C[] : { : N >= 0 })",
6585 "[N] -> { C[] -> D[N] }",
6586 "[N] -> D[{ [N] : N >= 0 }]" },
6587 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6588 "[N] -> (C[] : { : N >= 0 })",
6589 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6590 "[N] -> D[{ [N] : N >= 0 }]" },
6591 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6592 "[N] -> (C[] : { : N >= 0 })",
6593 "{ C[] -> D[0] }",
6594 "[N] -> D[{ [0] : N >= 0 }]" },
6595 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6596 "(C[] : { A[i,j] : i >= j })",
6597 "[N] -> { C[] -> D[N] : N >= 0 }",
6598 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6601 /* Perform some basic tests of binary operations on
6602 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6604 static int test_mupa_pma(isl_ctx *ctx)
6606 int i;
6607 isl_bool ok;
6608 isl_multi_union_pw_aff *mupa, *res;
6609 isl_pw_multi_aff *pma;
6611 for (i = 0; i < ARRAY_SIZE(mupa_pma_tests); ++i) {
6612 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6613 mupa_pma_tests[i].arg1);
6614 pma = isl_pw_multi_aff_read_from_str(ctx,
6615 mupa_pma_tests[i].arg2);
6616 res = isl_multi_union_pw_aff_read_from_str(ctx,
6617 mupa_pma_tests[i].res);
6618 mupa = mupa_pma_tests[i].fn(mupa, pma);
6619 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6620 isl_multi_union_pw_aff_free(mupa);
6621 isl_multi_union_pw_aff_free(res);
6622 if (ok < 0)
6623 return -1;
6624 if (!ok)
6625 isl_die(ctx, isl_error_unknown,
6626 "unexpected result", return -1);
6629 return 0;
6632 /* Inputs for basic tests of binary operations on
6633 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6634 * "fn" is the function that is tested.
6635 * "arg1" and "arg2" are string descriptions of the inputs.
6636 * "res" is a string description of the expected result.
6638 struct {
6639 __isl_give isl_multi_union_pw_aff *(*fn)(
6640 __isl_take isl_multi_union_pw_aff *mupa,
6641 __isl_take isl_union_pw_multi_aff *upma);
6642 const char *arg1;
6643 const char *arg2;
6644 const char *res;
6645 } mupa_upma_tests[] = {
6646 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6647 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6648 "C[{ A[a,b] -> [b + 2a] }]" },
6649 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6650 "C[{ B[i,j] -> [i + 2j] }]",
6651 "{ A[a,b] -> B[b,a] : b > a }",
6652 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6653 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6654 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6655 "{ A[a,b] -> B[b,a] : b > a }",
6656 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6657 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6658 "C[{ B[i,j] -> [i + 2j] }]",
6659 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6660 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6661 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6662 "(C[] : { B[a,b] })",
6663 "{ A[a,b] -> B[b,a] }",
6664 "(C[] : { A[a,b] })" },
6665 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6666 "(C[] : { B[a,b] })",
6667 "{ B[a,b] -> A[b,a] }",
6668 "(C[] : { })" },
6669 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6670 "(C[] : { B[a,b] })",
6671 "{ A[a,b] -> B[b,a] : a > b }",
6672 "(C[] : { A[a,b] : a > b })" },
6673 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6674 "(C[] : { B[a,b] : a > b })",
6675 "{ A[a,b] -> B[b,a] }",
6676 "(C[] : { A[a,b] : b > a })" },
6677 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6678 "[N] -> (C[] : { B[a,b] : a > N })",
6679 "{ A[a,b] -> B[b,a] : a > b }",
6680 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6681 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6682 "(C[] : { B[a,b] : a > b })",
6683 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6684 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6685 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6686 "C[]",
6687 "{ A[a,b] -> B[b,a] }",
6688 "C[]" },
6689 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6690 "[N] -> (C[] : { : N >= 0 })",
6691 "{ A[a,b] -> B[b,a] }",
6692 "[N] -> (C[] : { : N >= 0 })" },
6693 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6694 "C[]",
6695 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6696 "[N] -> (C[] : { : N >= 0 })" },
6699 /* Perform some basic tests of binary operations on
6700 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6702 static int test_mupa_upma(isl_ctx *ctx)
6704 int i;
6705 isl_bool ok;
6706 isl_multi_union_pw_aff *mupa, *res;
6707 isl_union_pw_multi_aff *upma;
6709 for (i = 0; i < ARRAY_SIZE(mupa_upma_tests); ++i) {
6710 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6711 mupa_upma_tests[i].arg1);
6712 upma = isl_union_pw_multi_aff_read_from_str(ctx,
6713 mupa_upma_tests[i].arg2);
6714 res = isl_multi_union_pw_aff_read_from_str(ctx,
6715 mupa_upma_tests[i].res);
6716 mupa = mupa_upma_tests[i].fn(mupa, upma);
6717 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6718 isl_multi_union_pw_aff_free(mupa);
6719 isl_multi_union_pw_aff_free(res);
6720 if (ok < 0)
6721 return -1;
6722 if (!ok)
6723 isl_die(ctx, isl_error_unknown,
6724 "unexpected result", return -1);
6727 return 0;
6730 /* Check that the input tuple of an isl_aff can be set properly.
6732 static isl_stat test_aff_set_tuple_id(isl_ctx *ctx)
6734 isl_id *id;
6735 isl_aff *aff;
6736 isl_stat equal;
6738 aff = isl_aff_read_from_str(ctx, "{ [x] -> [x + 1] }");
6739 id = isl_id_alloc(ctx, "A", NULL);
6740 aff = isl_aff_set_tuple_id(aff, isl_dim_in, id);
6741 equal = aff_check_plain_equal(aff, "{ A[x] -> [x + 1] }");
6742 isl_aff_free(aff);
6743 if (equal < 0)
6744 return isl_stat_error;
6746 return isl_stat_ok;
6749 /* Check that affine expressions get normalized on addition/subtraction.
6750 * In particular, check that (final) unused integer divisions get removed
6751 * such that an expression derived from expressions with integer divisions
6752 * is found to be obviously equal to one that is created directly.
6754 static isl_stat test_aff_normalize(isl_ctx *ctx)
6756 isl_aff *aff, *aff2;
6757 isl_stat ok;
6759 aff = isl_aff_read_from_str(ctx, "{ [x] -> [x//2] }");
6760 aff2 = isl_aff_read_from_str(ctx, "{ [x] -> [1 + x//2] }");
6761 aff = isl_aff_sub(aff2, aff);
6762 ok = aff_check_plain_equal(aff, "{ [x] -> [1] }");
6763 isl_aff_free(aff);
6765 return ok;
6768 int test_aff(isl_ctx *ctx)
6770 const char *str;
6771 isl_set *set;
6772 isl_space *space;
6773 isl_local_space *ls;
6774 isl_aff *aff;
6775 int zero;
6776 isl_stat equal;
6778 if (test_upa(ctx) < 0)
6779 return -1;
6780 if (test_bin_aff(ctx) < 0)
6781 return -1;
6782 if (test_bin_pw_aff(ctx) < 0)
6783 return -1;
6784 if (test_upma_test(ctx) < 0)
6785 return -1;
6786 if (test_bin_upma(ctx) < 0)
6787 return -1;
6788 if (test_bin_upma_fail(ctx) < 0)
6789 return -1;
6790 if (test_upma_uset(ctx) < 0)
6791 return -1;
6792 if (test_un_mpa(ctx) < 0)
6793 return -1;
6794 if (test_bin_mpa(ctx) < 0)
6795 return -1;
6796 if (test_un_mupa(ctx) < 0)
6797 return -1;
6798 if (test_bin_mupa(ctx) < 0)
6799 return -1;
6800 if (test_mupa_set(ctx) < 0)
6801 return -1;
6802 if (test_mupa_uset(ctx) < 0)
6803 return -1;
6804 if (test_mupa_ma(ctx) < 0)
6805 return -1;
6806 if (test_mupa_pa(ctx) < 0)
6807 return -1;
6808 if (test_mupa_pma(ctx) < 0)
6809 return -1;
6810 if (test_mupa_upma(ctx) < 0)
6811 return -1;
6813 space = isl_space_set_alloc(ctx, 0, 1);
6814 ls = isl_local_space_from_space(space);
6815 aff = isl_aff_zero_on_domain(ls);
6817 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6818 aff = isl_aff_scale_down_ui(aff, 3);
6819 aff = isl_aff_floor(aff);
6820 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6821 aff = isl_aff_scale_down_ui(aff, 2);
6822 aff = isl_aff_floor(aff);
6823 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6825 str = "{ [10] }";
6826 set = isl_set_read_from_str(ctx, str);
6827 aff = isl_aff_gist(aff, set);
6829 aff = isl_aff_add_constant_si(aff, -16);
6830 zero = isl_aff_plain_is_zero(aff);
6831 isl_aff_free(aff);
6833 if (zero < 0)
6834 return -1;
6835 if (!zero)
6836 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6838 aff = isl_aff_read_from_str(ctx, "{ [-1] }");
6839 aff = isl_aff_scale_down_ui(aff, 64);
6840 aff = isl_aff_floor(aff);
6841 equal = aff_check_plain_equal(aff, "{ [-1] }");
6842 isl_aff_free(aff);
6843 if (equal < 0)
6844 return -1;
6846 if (test_aff_set_tuple_id(ctx) < 0)
6847 return -1;
6848 if (test_aff_normalize(ctx) < 0)
6849 return -1;
6851 return 0;
6854 /* Inputs for isl_set_bind tests.
6855 * "set" is the input set.
6856 * "tuple" is the binding tuple.
6857 * "res" is the expected result.
6859 static
6860 struct {
6861 const char *set;
6862 const char *tuple;
6863 const char *res;
6864 } bind_set_tests[] = {
6865 { "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6866 "{ A[M, N] }",
6867 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6868 { "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }",
6869 "{ B[N, M] }",
6870 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6871 { "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }",
6872 "{ C[N] }",
6873 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6874 { "[M] -> { D[x, N] : x mod 2 = 0 and N mod 8 = 3 and M >= 0 }",
6875 "{ D[M, N] }",
6876 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 and M >= 0 }" },
6879 /* Perform basic isl_set_bind tests.
6881 static isl_stat test_bind_set(isl_ctx *ctx)
6883 int i;
6885 for (i = 0; i < ARRAY_SIZE(bind_set_tests); ++i) {
6886 const char *str;
6887 isl_set *set;
6888 isl_multi_id *tuple;
6889 isl_stat r;
6891 set = isl_set_read_from_str(ctx, bind_set_tests[i].set);
6892 str = bind_set_tests[i].tuple;
6893 tuple = isl_multi_id_read_from_str(ctx, str);
6894 set = isl_set_bind(set, tuple);
6895 r = set_check_equal(set, bind_set_tests[i].res);
6896 isl_set_free(set);
6897 if (r < 0)
6898 return isl_stat_error;
6901 return isl_stat_ok;
6904 /* Inputs for isl_map_bind_domain tests.
6905 * "map" is the input map.
6906 * "tuple" is the binding tuple.
6907 * "res" is the expected result.
6909 struct {
6910 const char *map;
6911 const char *tuple;
6912 const char *res;
6913 } bind_map_domain_tests[] = {
6914 { "{ A[M, N] -> [M + floor(N/2)] }",
6915 "{ A[M, N] }",
6916 "[M, N] -> { [M + floor(N/2)] }" },
6917 { "{ B[N, M] -> [M + floor(N/2)] }",
6918 "{ B[N, M] }",
6919 "[N, M] -> { [M + floor(N/2)] }" },
6920 { "[M] -> { C[N] -> [M + floor(N/2)] }",
6921 "{ C[N] }",
6922 "[M, N] -> { [M + floor(N/2)] }" },
6923 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
6924 "{ C[M, N] }",
6925 "[M, N] -> { [M + floor(N/2)] }" },
6926 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
6927 "{ C[M, N] }",
6928 "[M, N] -> { [M + floor(N/2)] }" },
6929 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
6930 "{ C[N, M] }",
6931 "[A, N, M] -> { [M + floor(N/2)] }" },
6934 /* Perform basic isl_map_bind_domain tests.
6936 static isl_stat test_bind_map_domain(isl_ctx *ctx)
6938 int i;
6940 for (i = 0; i < ARRAY_SIZE(bind_map_domain_tests); ++i) {
6941 const char *str;
6942 isl_map *map;
6943 isl_set *set;
6944 isl_multi_id *tuple;
6945 isl_stat r;
6947 str = bind_map_domain_tests[i].map;
6948 map = isl_map_read_from_str(ctx, str);
6949 str = bind_map_domain_tests[i].tuple;
6950 tuple = isl_multi_id_read_from_str(ctx, str);
6951 set = isl_map_bind_domain(map, tuple);
6952 str = bind_map_domain_tests[i].res;
6953 r = set_check_equal(set, str);
6954 isl_set_free(set);
6955 if (r < 0)
6956 return isl_stat_error;
6959 return isl_stat_ok;
6962 /* Inputs for isl_union_map_bind_range tests.
6963 * "map" is the input union map.
6964 * "tuple" is the binding tuple.
6965 * "res" is the expected result.
6967 struct {
6968 const char *map;
6969 const char *tuple;
6970 const char *res;
6971 } bind_umap_range_tests[] = {
6972 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6973 "{ A[M, N] }",
6974 "[M, N] -> { B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
6975 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6976 "{ B[M, N] }",
6977 "{ }" },
6978 { "{ A[] -> B[]; C[] -> D[]; E[] -> B[] }",
6979 "{ B[] }",
6980 "{ A[]; E[] }" },
6983 /* Perform basic isl_union_map_bind_range tests.
6985 static isl_stat test_bind_umap_range(isl_ctx *ctx)
6987 int i;
6989 for (i = 0; i < ARRAY_SIZE(bind_umap_range_tests); ++i) {
6990 const char *str;
6991 isl_union_map *umap;
6992 isl_union_set *uset;
6993 isl_multi_id *tuple;
6994 isl_stat r;
6996 str = bind_umap_range_tests[i].map;
6997 umap = isl_union_map_read_from_str(ctx, str);
6998 str = bind_umap_range_tests[i].tuple;
6999 tuple = isl_multi_id_read_from_str(ctx, str);
7000 uset = isl_union_map_bind_range(umap, tuple);
7001 str = bind_umap_range_tests[i].res;
7002 r = uset_check_equal(uset, str);
7003 isl_union_set_free(uset);
7004 if (r < 0)
7005 return isl_stat_error;
7008 return isl_stat_ok;
7011 /* Inputs for isl_pw_multi_aff_bind_domain tests.
7012 * "pma" is the input expression.
7013 * "tuple" is the binding tuple.
7014 * "res" is the expected result.
7016 struct {
7017 const char *pma;
7018 const char *tuple;
7019 const char *res;
7020 } bind_pma_domain_tests[] = {
7021 { "{ A[M, N] -> [M + floor(N/2)] }",
7022 "{ A[M, N] }",
7023 "[M, N] -> { [M + floor(N/2)] }" },
7024 { "{ B[N, M] -> [M + floor(N/2)] }",
7025 "{ B[N, M] }",
7026 "[N, M] -> { [M + floor(N/2)] }" },
7027 { "[M] -> { C[N] -> [M + floor(N/2)] }",
7028 "{ C[N] }",
7029 "[M, N] -> { [M + floor(N/2)] }" },
7030 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
7031 "{ C[M, N] }",
7032 "[M, N] -> { [M + floor(N/2)] }" },
7033 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
7034 "{ C[M, N] }",
7035 "[M, N] -> { [M + floor(N/2)] }" },
7036 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
7037 "{ C[N, M] }",
7038 "[A, N, M] -> { [M + floor(N/2)] }" },
7041 /* Perform basic isl_pw_multi_aff_bind_domain tests.
7043 static isl_stat test_bind_pma_domain(isl_ctx *ctx)
7045 int i;
7047 for (i = 0; i < ARRAY_SIZE(bind_pma_domain_tests); ++i) {
7048 const char *str;
7049 isl_pw_multi_aff *pma;
7050 isl_multi_id *tuple;
7051 isl_stat r;
7053 str = bind_pma_domain_tests[i].pma;
7054 pma = isl_pw_multi_aff_read_from_str(ctx, str);
7055 str = bind_pma_domain_tests[i].tuple;
7056 tuple = isl_multi_id_read_from_str(ctx, str);
7057 pma = isl_pw_multi_aff_bind_domain(pma, tuple);
7058 str = bind_pma_domain_tests[i].res;
7059 r = pw_multi_aff_check_plain_equal(pma, str);
7060 isl_pw_multi_aff_free(pma);
7061 if (r < 0)
7062 return isl_stat_error;
7065 return isl_stat_ok;
7068 /* Inputs for isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7069 * "pma" is the input expression.
7070 * "tuple" is the binding tuple.
7071 * "res" is the expected result.
7073 struct {
7074 const char *pma;
7075 const char *tuple;
7076 const char *res;
7077 } bind_pma_domain_wrapped_tests[] = {
7078 { "{ [A[M, N] -> B[]] -> [M + floor(N/2)] }",
7079 "{ A[M, N] }",
7080 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7081 { "{ [B[N, M] -> D[]] -> [M + floor(N/2)] }",
7082 "{ B[N, M] }",
7083 "[N, M] -> { D[] -> [M + floor(N/2)] }" },
7084 { "[M] -> { [C[N] -> B[x]] -> [x + M + floor(N/2)] }",
7085 "{ C[N] }",
7086 "[M, N] -> { B[x] -> [x + M + floor(N/2)] }" },
7087 { "[M] -> { [C[x, N] -> B[]] -> [x + floor(N/2)] }",
7088 "{ C[M, N] }",
7089 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7090 { "[M] -> { [C[x, N] -> B[]] -> [M + floor(N/2)] }",
7091 "{ C[M, N] }",
7092 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7093 { "[A, M] -> { [C[N, x] -> B[]] -> [x + floor(N/2)] }",
7094 "{ C[N, M] }",
7095 "[A, N, M] -> { B[] -> [M + floor(N/2)] }" },
7098 /* Perform basic isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7100 static isl_stat test_bind_pma_domain_wrapped(isl_ctx *ctx)
7102 int i;
7104 for (i = 0; i < ARRAY_SIZE(bind_pma_domain_wrapped_tests); ++i) {
7105 const char *str;
7106 isl_pw_multi_aff *pma;
7107 isl_multi_id *tuple;
7108 isl_stat r;
7110 str = bind_pma_domain_wrapped_tests[i].pma;
7111 pma = isl_pw_multi_aff_read_from_str(ctx, str);
7112 str = bind_pma_domain_wrapped_tests[i].tuple;
7113 tuple = isl_multi_id_read_from_str(ctx, str);
7114 pma = isl_pw_multi_aff_bind_domain_wrapped_domain(pma, tuple);
7115 str = bind_pma_domain_wrapped_tests[i].res;
7116 r = pw_multi_aff_check_plain_equal(pma, str);
7117 isl_pw_multi_aff_free(pma);
7118 if (r < 0)
7119 return isl_stat_error;
7122 return isl_stat_ok;
7125 /* Inputs for isl_aff_bind_id tests.
7126 * "aff" is the input expression.
7127 * "id" is the binding id.
7128 * "res" is the expected result.
7130 static
7131 struct {
7132 const char *aff;
7133 const char *id;
7134 const char *res;
7135 } bind_aff_tests[] = {
7136 { "{ [4] }", "M", "[M = 4] -> { : }" },
7137 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7138 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7139 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7140 { "{ [NaN] }", "M", "{ : false }" },
7141 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7144 /* Perform basic isl_aff_bind_id tests.
7146 static isl_stat test_bind_aff(isl_ctx *ctx)
7148 int i;
7150 for (i = 0; i < ARRAY_SIZE(bind_aff_tests); ++i) {
7151 isl_aff *aff;
7152 isl_set *res;
7153 isl_id *id;
7154 isl_stat r;
7156 aff = isl_aff_read_from_str(ctx, bind_aff_tests[i].aff);
7157 id = isl_id_read_from_str(ctx, bind_aff_tests[i].id);
7158 res = isl_set_from_basic_set(isl_aff_bind_id(aff, id));
7159 r = set_check_equal(res, bind_aff_tests[i].res);
7160 isl_set_free(res);
7161 if (r < 0)
7162 return isl_stat_error;
7165 return isl_stat_ok;
7168 /* Inputs for isl_pw_aff_bind_id tests.
7169 * "pa" is the input expression.
7170 * "id" is the binding id.
7171 * "res" is the expected result.
7173 static
7174 struct {
7175 const char *pa;
7176 const char *id;
7177 const char *res;
7178 } bind_pa_tests[] = {
7179 { "{ [4] }", "M", "[M = 4] -> { : }" },
7180 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7181 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7182 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7183 { "[M] -> { [M] : M >= 0; [-M] : M < 0 }", "M", "[M] -> { : M >= 0 }" },
7184 { "{ [NaN] }", "M", "{ : false }" },
7185 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7188 /* Perform basic isl_pw_aff_bind_id tests.
7190 static isl_stat test_bind_pa(isl_ctx *ctx)
7192 int i;
7194 for (i = 0; i < ARRAY_SIZE(bind_pa_tests); ++i) {
7195 isl_pw_aff *pa;
7196 isl_set *res;
7197 isl_id *id;
7198 isl_stat r;
7200 pa = isl_pw_aff_read_from_str(ctx, bind_pa_tests[i].pa);
7201 id = isl_id_read_from_str(ctx, bind_pa_tests[i].id);
7202 res = isl_pw_aff_bind_id(pa, id);
7203 r = set_check_equal(res, bind_pa_tests[i].res);
7204 isl_set_free(res);
7205 if (r < 0)
7206 return isl_stat_error;
7209 return isl_stat_ok;
7212 /* Inputs for isl_multi_union_pw_aff_bind tests.
7213 * "mupa" is the input expression.
7214 * "tuple" is the binding tuple.
7215 * "res" is the expected result.
7217 static
7218 struct {
7219 const char *mupa;
7220 const char *tuple;
7221 const char *res;
7222 } bind_mupa_tests[] = {
7223 { "A[{ [4] }, { [5] }]",
7224 "{ A[M, N] }",
7225 "[M = 4, N = 5] -> { : }" },
7226 { "A[{ B[x] -> [floor(x/2)] }, { B[y] -> [y + 5] }]",
7227 "{ A[M, N] }",
7228 "[M, N] -> { B[x] : M = floor(x/2) and N = x + 5 }" },
7229 { "[M] -> A[{ [4] }, { [M + 1] }]",
7230 "{ A[M, N] }",
7231 "[M = 4, N = 5] -> { : }" },
7234 /* Perform basic isl_multi_union_pw_aff_bind tests.
7236 static isl_stat test_bind_mupa(isl_ctx *ctx)
7238 int i;
7240 for (i = 0; i < ARRAY_SIZE(bind_mupa_tests); ++i) {
7241 const char *str;
7242 isl_multi_union_pw_aff *mupa;
7243 isl_union_set *res;
7244 isl_multi_id *tuple;
7245 isl_stat r;
7247 str = bind_mupa_tests[i].mupa;
7248 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
7249 str = bind_mupa_tests[i].tuple;
7250 tuple = isl_multi_id_read_from_str(ctx, str);
7251 res = isl_multi_union_pw_aff_bind(mupa, tuple);
7252 r = uset_check_equal(res, bind_mupa_tests[i].res);
7253 isl_union_set_free(res);
7254 if (r < 0)
7255 return isl_stat_error;
7258 return isl_stat_ok;
7261 /* Perform tests that reinterpret dimensions as parameters.
7263 static int test_bind(isl_ctx *ctx)
7265 if (test_bind_set(ctx) < 0)
7266 return -1;
7267 if (test_bind_map_domain(ctx) < 0)
7268 return -1;
7269 if (test_bind_umap_range(ctx) < 0)
7270 return -1;
7271 if (test_bind_pma_domain(ctx) < 0)
7272 return -1;
7273 if (test_bind_pma_domain_wrapped(ctx) < 0)
7274 return -1;
7275 if (test_bind_aff(ctx) < 0)
7276 return -1;
7277 if (test_bind_pa(ctx) < 0)
7278 return -1;
7279 if (test_bind_mupa(ctx) < 0)
7280 return -1;
7282 return 0;
7285 /* Inputs for isl_set_unbind_params tests.
7286 * "set" is the input parameter domain.
7287 * "tuple" is the tuple of the constructed set.
7288 * "res" is the expected result.
7290 struct {
7291 const char *set;
7292 const char *tuple;
7293 const char *res;
7294 } unbind_set_tests[] = {
7295 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7296 "{ A[M, N] }",
7297 "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7298 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7299 "{ B[N, M] }",
7300 "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7301 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7302 "{ C[N] }",
7303 "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }" },
7304 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7305 "{ D[T, N] }",
7306 "[M] -> { D[x, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7309 /* Perform basic isl_set_unbind_params tests.
7311 static isl_stat test_unbind_set(isl_ctx *ctx)
7313 int i;
7315 for (i = 0; i < ARRAY_SIZE(unbind_set_tests); ++i) {
7316 const char *str;
7317 isl_set *set;
7318 isl_multi_id *tuple;
7319 isl_stat r;
7321 set = isl_set_read_from_str(ctx, unbind_set_tests[i].set);
7322 str = unbind_set_tests[i].tuple;
7323 tuple = isl_multi_id_read_from_str(ctx, str);
7324 set = isl_set_unbind_params(set, tuple);
7325 r = set_check_equal(set, unbind_set_tests[i].res);
7326 isl_set_free(set);
7327 if (r < 0)
7328 return isl_stat_error;
7331 return isl_stat_ok;
7334 /* Inputs for isl_aff_unbind_params_insert_domain tests.
7335 * "aff" is the input affine expression defined over a parameter domain.
7336 * "tuple" is the tuple of the domain that gets introduced.
7337 * "res" is the expected result.
7339 struct {
7340 const char *aff;
7341 const char *tuple;
7342 const char *res;
7343 } unbind_aff_tests[] = {
7344 { "[M, N] -> { [M + floor(N/2)] }",
7345 "{ A[M, N] }",
7346 "{ A[M, N] -> [M + floor(N/2)] }" },
7347 { "[M, N] -> { [M + floor(N/2)] }",
7348 "{ B[N, M] }",
7349 "{ B[N, M] -> [M + floor(N/2)] }" },
7350 { "[M, N] -> { [M + floor(N/2)] }",
7351 "{ C[N] }",
7352 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7353 { "[M, N] -> { [M + floor(N/2)] }",
7354 "{ D[A, B, C, N, Z] }",
7355 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7358 /* Perform basic isl_aff_unbind_params_insert_domain tests.
7360 static isl_stat test_unbind_aff(isl_ctx *ctx)
7362 int i;
7364 for (i = 0; i < ARRAY_SIZE(unbind_aff_tests); ++i) {
7365 const char *str;
7366 isl_aff *aff;
7367 isl_multi_id *tuple;
7368 isl_stat r;
7370 aff = isl_aff_read_from_str(ctx, unbind_aff_tests[i].aff);
7371 str = unbind_aff_tests[i].tuple;
7372 tuple = isl_multi_id_read_from_str(ctx, str);
7373 aff = isl_aff_unbind_params_insert_domain(aff, tuple);
7374 r = aff_check_plain_equal(aff, unbind_aff_tests[i].res);
7375 isl_aff_free(aff);
7376 if (r < 0)
7377 return isl_stat_error;
7380 return isl_stat_ok;
7383 /* Inputs for isl_multi_aff_unbind_params_insert_domain tests.
7384 * "ma" is the input multi affine expression defined over a parameter domain.
7385 * "tuple" is the tuple of the domain that gets introduced.
7386 * "res" is the expected result.
7388 static struct {
7389 const char *ma;
7390 const char *tuple;
7391 const char *res;
7392 } unbind_multi_aff_tests[] = {
7393 { "[M, N] -> { T[M + floor(N/2)] }",
7394 "{ A[M, N] }",
7395 "{ A[M, N] -> T[M + floor(N/2)] }" },
7396 { "[M, N] -> { [M + floor(N/2)] }",
7397 "{ B[N, M] }",
7398 "{ B[N, M] -> [M + floor(N/2)] }" },
7399 { "[M, N] -> { [M + floor(N/2)] }",
7400 "{ C[N] }",
7401 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7402 { "[M, N] -> { [M + floor(N/2)] }",
7403 "{ D[A, B, C, N, Z] }",
7404 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7405 { "[M, N] -> { T[M + floor(N/2), N + floor(M/3)] }",
7406 "{ A[M, N] }",
7407 "{ A[M, N] -> T[M + floor(N/2), N + floor(M/3)] }" },
7410 /* Perform basic isl_multi_aff_unbind_params_insert_domain tests.
7412 static isl_stat test_unbind_multi_aff(isl_ctx *ctx)
7414 int i;
7416 for (i = 0; i < ARRAY_SIZE(unbind_multi_aff_tests); ++i) {
7417 const char *str;
7418 isl_multi_aff *ma;
7419 isl_multi_id *tuple;
7420 isl_stat r;
7422 str = unbind_multi_aff_tests[i].ma;
7423 ma = isl_multi_aff_read_from_str(ctx, str);
7424 str = unbind_multi_aff_tests[i].tuple;
7425 tuple = isl_multi_id_read_from_str(ctx, str);
7426 ma = isl_multi_aff_unbind_params_insert_domain(ma, tuple);
7427 str = unbind_multi_aff_tests[i].res;
7428 r = multi_aff_check_plain_equal(ma, str);
7429 isl_multi_aff_free(ma);
7430 if (r < 0)
7431 return isl_stat_error;
7434 return isl_stat_ok;
7437 /* Perform tests that reinterpret parameters.
7439 static int test_unbind(isl_ctx *ctx)
7441 if (test_unbind_set(ctx) < 0)
7442 return -1;
7443 if (test_unbind_aff(ctx) < 0)
7444 return -1;
7445 if (test_unbind_multi_aff(ctx) < 0)
7446 return -1;
7448 return 0;
7451 /* Check that "pa" consists of a single expression.
7453 static int check_single_piece(isl_ctx *ctx, __isl_take isl_pw_aff *pa)
7455 isl_size n;
7457 n = isl_pw_aff_n_piece(pa);
7458 isl_pw_aff_free(pa);
7460 if (n < 0)
7461 return -1;
7462 if (n != 1)
7463 isl_die(ctx, isl_error_unknown, "expecting single expression",
7464 return -1);
7466 return 0;
7469 /* Check that the computation below results in a single expression.
7470 * One or two expressions may result depending on which constraint
7471 * ends up being considered as redundant with respect to the other
7472 * constraints after the projection that is performed internally
7473 * by isl_set_dim_min.
7475 static int test_dim_max_1(isl_ctx *ctx)
7477 const char *str;
7478 isl_set *set;
7479 isl_pw_aff *pa;
7481 str = "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
7482 "-4a <= b <= 3 and b < n - 4a }";
7483 set = isl_set_read_from_str(ctx, str);
7484 pa = isl_set_dim_min(set, 0);
7485 return check_single_piece(ctx, pa);
7488 /* Check that the computation below results in a single expression.
7489 * The PIP problem corresponding to these constraints has a row
7490 * that causes a split of the solution domain. The solver should
7491 * first pick rows that split off empty parts such that the actual
7492 * solution domain does not get split.
7493 * Note that the description contains some redundant constraints.
7494 * If these constraints get removed first, then the row mentioned
7495 * above does not appear in the PIP problem.
7497 static int test_dim_max_2(isl_ctx *ctx)
7499 const char *str;
7500 isl_set *set;
7501 isl_pw_aff *pa;
7503 str = "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
7504 "N > 0 and P >= 0 }";
7505 set = isl_set_read_from_str(ctx, str);
7506 pa = isl_set_dim_max(set, 0);
7507 return check_single_piece(ctx, pa);
7510 int test_dim_max(isl_ctx *ctx)
7512 int equal;
7513 const char *str;
7514 isl_set *set1, *set2;
7515 isl_set *set;
7516 isl_map *map;
7517 isl_pw_aff *pwaff;
7519 if (test_dim_max_1(ctx) < 0)
7520 return -1;
7521 if (test_dim_max_2(ctx) < 0)
7522 return -1;
7524 str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
7525 set = isl_set_read_from_str(ctx, str);
7526 pwaff = isl_set_dim_max(set, 0);
7527 set1 = isl_set_from_pw_aff(pwaff);
7528 str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
7529 set2 = isl_set_read_from_str(ctx, str);
7530 equal = isl_set_is_equal(set1, set2);
7531 isl_set_free(set1);
7532 isl_set_free(set2);
7533 if (equal < 0)
7534 return -1;
7535 if (!equal)
7536 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7538 str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
7539 set = isl_set_read_from_str(ctx, str);
7540 pwaff = isl_set_dim_max(set, 0);
7541 set1 = isl_set_from_pw_aff(pwaff);
7542 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7543 set2 = isl_set_read_from_str(ctx, str);
7544 equal = isl_set_is_equal(set1, set2);
7545 isl_set_free(set1);
7546 isl_set_free(set2);
7547 if (equal < 0)
7548 return -1;
7549 if (!equal)
7550 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7552 str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
7553 set = isl_set_read_from_str(ctx, str);
7554 pwaff = isl_set_dim_max(set, 0);
7555 set1 = isl_set_from_pw_aff(pwaff);
7556 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7557 set2 = isl_set_read_from_str(ctx, str);
7558 equal = isl_set_is_equal(set1, set2);
7559 isl_set_free(set1);
7560 isl_set_free(set2);
7561 if (equal < 0)
7562 return -1;
7563 if (!equal)
7564 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7566 str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
7567 "0 <= i < N and 0 <= j < M }";
7568 map = isl_map_read_from_str(ctx, str);
7569 set = isl_map_range(map);
7571 pwaff = isl_set_dim_max(isl_set_copy(set), 0);
7572 set1 = isl_set_from_pw_aff(pwaff);
7573 str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
7574 set2 = isl_set_read_from_str(ctx, str);
7575 equal = isl_set_is_equal(set1, set2);
7576 isl_set_free(set1);
7577 isl_set_free(set2);
7579 pwaff = isl_set_dim_max(isl_set_copy(set), 3);
7580 set1 = isl_set_from_pw_aff(pwaff);
7581 str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
7582 set2 = isl_set_read_from_str(ctx, str);
7583 if (equal >= 0 && equal)
7584 equal = isl_set_is_equal(set1, set2);
7585 isl_set_free(set1);
7586 isl_set_free(set2);
7588 isl_set_free(set);
7590 if (equal < 0)
7591 return -1;
7592 if (!equal)
7593 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7595 /* Check that solutions are properly merged. */
7596 str = "[n] -> { [a, b, c] : c >= -4a - 2b and "
7597 "c <= -1 + n - 4a - 2b and c >= -2b and "
7598 "4a >= -4 + n and c >= 0 }";
7599 set = isl_set_read_from_str(ctx, str);
7600 pwaff = isl_set_dim_min(set, 2);
7601 set1 = isl_set_from_pw_aff(pwaff);
7602 str = "[n] -> { [(0)] : n >= 1 }";
7603 set2 = isl_set_read_from_str(ctx, str);
7604 equal = isl_set_is_equal(set1, set2);
7605 isl_set_free(set1);
7606 isl_set_free(set2);
7608 if (equal < 0)
7609 return -1;
7610 if (!equal)
7611 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7613 /* Check that empty solution lie in the right space. */
7614 str = "[n] -> { [t,a] : 1 = 0 }";
7615 set = isl_set_read_from_str(ctx, str);
7616 pwaff = isl_set_dim_max(set, 0);
7617 set1 = isl_set_from_pw_aff(pwaff);
7618 str = "[n] -> { [t] : 1 = 0 }";
7619 set2 = isl_set_read_from_str(ctx, str);
7620 equal = isl_set_is_equal(set1, set2);
7621 isl_set_free(set1);
7622 isl_set_free(set2);
7624 if (equal < 0)
7625 return -1;
7626 if (!equal)
7627 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7629 return 0;
7632 /* Basic test for isl_pw_multi_aff_product.
7634 * Check that multiple pieces are properly handled.
7636 static int test_product_pma(isl_ctx *ctx)
7638 isl_stat equal;
7639 const char *str;
7640 isl_pw_multi_aff *pma1, *pma2;
7642 str = "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
7643 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
7644 str = "{ C[] -> D[] }";
7645 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
7646 pma1 = isl_pw_multi_aff_product(pma1, pma2);
7647 str = "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
7648 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
7649 equal = pw_multi_aff_check_plain_equal(pma1, str);
7650 isl_pw_multi_aff_free(pma1);
7651 if (equal < 0)
7652 return -1;
7654 return 0;
7657 int test_product(isl_ctx *ctx)
7659 const char *str;
7660 isl_set *set;
7661 isl_union_set *uset1, *uset2;
7662 int ok;
7664 str = "{ A[i] }";
7665 set = isl_set_read_from_str(ctx, str);
7666 set = isl_set_product(set, isl_set_copy(set));
7667 ok = isl_set_is_wrapping(set);
7668 isl_set_free(set);
7669 if (ok < 0)
7670 return -1;
7671 if (!ok)
7672 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7674 str = "{ [] }";
7675 uset1 = isl_union_set_read_from_str(ctx, str);
7676 uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1));
7677 str = "{ [[] -> []] }";
7678 uset2 = isl_union_set_read_from_str(ctx, str);
7679 ok = isl_union_set_is_equal(uset1, uset2);
7680 isl_union_set_free(uset1);
7681 isl_union_set_free(uset2);
7682 if (ok < 0)
7683 return -1;
7684 if (!ok)
7685 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7687 if (test_product_pma(ctx) < 0)
7688 return -1;
7690 return 0;
7693 /* Check that two sets are not considered disjoint just because
7694 * they have a different set of (named) parameters.
7696 static int test_disjoint(isl_ctx *ctx)
7698 const char *str;
7699 isl_set *set, *set2;
7700 int disjoint;
7702 str = "[n] -> { [[]->[]] }";
7703 set = isl_set_read_from_str(ctx, str);
7704 str = "{ [[]->[]] }";
7705 set2 = isl_set_read_from_str(ctx, str);
7706 disjoint = isl_set_is_disjoint(set, set2);
7707 isl_set_free(set);
7708 isl_set_free(set2);
7709 if (disjoint < 0)
7710 return -1;
7711 if (disjoint)
7712 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7714 return 0;
7717 /* Inputs for isl_pw_multi_aff_is_equal tests.
7718 * "f1" and "f2" are the two function that need to be compared.
7719 * "equal" is the expected result.
7721 struct {
7722 int equal;
7723 const char *f1;
7724 const char *f2;
7725 } pma_equal_tests[] = {
7726 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
7727 "[N] -> { [0] : 0 <= N <= 1 }" },
7728 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7729 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
7730 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7731 "[N] -> { [0] : 0 <= N <= 1 }" },
7732 { 0, "{ [NaN] }", "{ [NaN] }" },
7735 int test_equal(isl_ctx *ctx)
7737 int i;
7738 const char *str;
7739 isl_set *set, *set2;
7740 int equal;
7742 str = "{ S_6[i] }";
7743 set = isl_set_read_from_str(ctx, str);
7744 str = "{ S_7[i] }";
7745 set2 = isl_set_read_from_str(ctx, str);
7746 equal = isl_set_is_equal(set, set2);
7747 isl_set_free(set);
7748 isl_set_free(set2);
7749 if (equal < 0)
7750 return -1;
7751 if (equal)
7752 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7754 for (i = 0; i < ARRAY_SIZE(pma_equal_tests); ++i) {
7755 int expected = pma_equal_tests[i].equal;
7756 isl_pw_multi_aff *f1, *f2;
7758 f1 = isl_pw_multi_aff_read_from_str(ctx, pma_equal_tests[i].f1);
7759 f2 = isl_pw_multi_aff_read_from_str(ctx, pma_equal_tests[i].f2);
7760 equal = isl_pw_multi_aff_is_equal(f1, f2);
7761 isl_pw_multi_aff_free(f1);
7762 isl_pw_multi_aff_free(f2);
7763 if (equal < 0)
7764 return -1;
7765 if (equal != expected)
7766 isl_die(ctx, isl_error_unknown,
7767 "unexpected equality result", return -1);
7770 return 0;
7773 static int test_plain_fixed(isl_ctx *ctx, __isl_take isl_map *map,
7774 enum isl_dim_type type, unsigned pos, int fixed)
7776 isl_bool test;
7778 test = isl_map_plain_is_fixed(map, type, pos, NULL);
7779 isl_map_free(map);
7780 if (test < 0)
7781 return -1;
7782 if (test == fixed)
7783 return 0;
7784 if (fixed)
7785 isl_die(ctx, isl_error_unknown,
7786 "map not detected as fixed", return -1);
7787 else
7788 isl_die(ctx, isl_error_unknown,
7789 "map detected as fixed", return -1);
7792 int test_fixed(isl_ctx *ctx)
7794 const char *str;
7795 isl_map *map;
7797 str = "{ [i] -> [i] }";
7798 map = isl_map_read_from_str(ctx, str);
7799 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 0))
7800 return -1;
7801 str = "{ [i] -> [1] }";
7802 map = isl_map_read_from_str(ctx, str);
7803 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
7804 return -1;
7805 str = "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
7806 map = isl_map_read_from_str(ctx, str);
7807 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
7808 return -1;
7809 map = isl_map_read_from_str(ctx, str);
7810 map = isl_map_neg(map);
7811 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
7812 return -1;
7814 return 0;
7817 struct isl_vertices_test_data {
7818 const char *set;
7819 int n;
7820 const char *vertex[6];
7821 } vertices_tests[] = {
7822 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
7823 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
7824 { "{ A[t, i] : t = 14 and i = 1 }",
7825 1, { "{ A[14, 1] }" } },
7826 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
7827 "c <= m and m <= n and m > 0 }",
7828 6, {
7829 "[n, m] -> { [n, m, m] : 0 < m <= n }",
7830 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
7831 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
7832 "[n, m] -> { [m, m, m] : 0 < m <= n }",
7833 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
7834 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
7835 } },
7838 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
7840 static isl_stat find_vertex(__isl_take isl_vertex *vertex, void *user)
7842 struct isl_vertices_test_data *data = user;
7843 isl_ctx *ctx;
7844 isl_multi_aff *ma;
7845 isl_basic_set *bset;
7846 isl_pw_multi_aff *pma;
7847 int i;
7848 isl_bool equal;
7850 ctx = isl_vertex_get_ctx(vertex);
7851 bset = isl_vertex_get_domain(vertex);
7852 ma = isl_vertex_get_expr(vertex);
7853 pma = isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset), ma);
7855 for (i = 0; i < data->n; ++i) {
7856 isl_pw_multi_aff *pma_i;
7858 pma_i = isl_pw_multi_aff_read_from_str(ctx, data->vertex[i]);
7859 equal = isl_pw_multi_aff_plain_is_equal(pma, pma_i);
7860 isl_pw_multi_aff_free(pma_i);
7862 if (equal < 0 || equal)
7863 break;
7866 isl_pw_multi_aff_free(pma);
7867 isl_vertex_free(vertex);
7869 if (equal < 0)
7870 return isl_stat_error;
7872 return equal ? isl_stat_ok : isl_stat_error;
7875 int test_vertices(isl_ctx *ctx)
7877 int i;
7879 for (i = 0; i < ARRAY_SIZE(vertices_tests); ++i) {
7880 isl_basic_set *bset;
7881 isl_vertices *vertices;
7882 int ok = 1;
7883 isl_size n;
7885 bset = isl_basic_set_read_from_str(ctx, vertices_tests[i].set);
7886 vertices = isl_basic_set_compute_vertices(bset);
7887 n = isl_vertices_get_n_vertices(vertices);
7888 if (vertices_tests[i].n != n)
7889 ok = 0;
7890 if (isl_vertices_foreach_vertex(vertices, &find_vertex,
7891 &vertices_tests[i]) < 0)
7892 ok = 0;
7893 isl_vertices_free(vertices);
7894 isl_basic_set_free(bset);
7896 if (n < 0)
7897 return -1;
7898 if (!ok)
7899 isl_die(ctx, isl_error_unknown, "unexpected vertices",
7900 return -1);
7903 return 0;
7906 /* Inputs for basic tests of unary operations on isl_union_map.
7907 * "fn" is the function that is being tested.
7908 * "arg" is a string description of the input.
7909 * "res" is a string description of the expected result.
7911 static struct {
7912 __isl_give isl_union_map *(*fn)(__isl_take isl_union_map *umap);
7913 const char *arg;
7914 const char *res;
7915 } umap_un_tests[] = {
7916 { &isl_union_map_range_reverse,
7917 "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
7918 "{ A[] -> [C[] -> B[]]; A[0] -> N[B[2] -> B[1]] }" },
7919 { &isl_union_map_range_reverse,
7920 "{ A[] -> N[B[] -> C[]] }",
7921 "{ A[] -> [C[] -> B[]] }" },
7922 { &isl_union_map_range_reverse,
7923 "{ A[] -> N[B[x] -> B[y]] }",
7924 "{ A[] -> N[B[*] -> B[*]] }" },
7927 /* Perform basic tests of unary operations on isl_union_map.
7929 static isl_stat test_un_union_map(isl_ctx *ctx)
7931 int i;
7933 for (i = 0; i < ARRAY_SIZE(umap_un_tests); ++i) {
7934 const char *str;
7935 isl_union_map *umap, *res;
7936 isl_bool equal;
7938 str = umap_un_tests[i].arg;
7939 umap = isl_union_map_read_from_str(ctx, str);
7940 str = umap_un_tests[i].res;
7941 res = isl_union_map_read_from_str(ctx, str);
7942 umap = umap_un_tests[i].fn(umap);
7943 equal = isl_union_map_is_equal(umap, res);
7944 isl_union_map_free(umap);
7945 isl_union_map_free(res);
7946 if (equal < 0)
7947 return isl_stat_error;
7948 if (!equal)
7949 isl_die(ctx, isl_error_unknown,
7950 "unexpected result", return isl_stat_error);
7953 return isl_stat_ok;
7956 /* Inputs for basic tests of binary operations on isl_union_map.
7957 * "fn" is the function that is being tested.
7958 * "arg1" and "arg2" are string descriptions of the inputs.
7959 * "res" is a string description of the expected result.
7961 static struct {
7962 __isl_give isl_union_map *(*fn)(__isl_take isl_union_map *umap1,
7963 __isl_take isl_union_map *umap2);
7964 const char *arg1;
7965 const char *arg2;
7966 const char *res;
7967 } umap_bin_tests[] = {
7968 { &isl_union_map_intersect,
7969 "[n] -> { A[i] -> [] : 0 <= i <= n; B[] -> [] }",
7970 "[m] -> { A[i] -> [] : 0 <= i <= m; C[] -> [] }",
7971 "[m, n] -> { A[i] -> [] : 0 <= i <= n and i <= m }" },
7972 { &isl_union_map_intersect_domain_factor_domain,
7973 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7974 "[N] -> { B[i] -> C[N] }",
7975 "{ }" },
7976 { &isl_union_map_intersect_domain_factor_domain,
7977 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7978 "[N] -> { A[i] -> C[N] }",
7979 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
7980 { &isl_union_map_intersect_domain_factor_domain,
7981 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
7982 "[N] -> { A[i] -> C[N] }",
7983 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
7984 { &isl_union_map_intersect_domain_factor_range,
7985 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7986 "[N] -> { B[i] -> C[N] }",
7987 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
7988 { &isl_union_map_intersect_domain_factor_range,
7989 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
7990 "[N] -> { B[i] -> C[N] }",
7991 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
7992 { &isl_union_map_intersect_domain_factor_range,
7993 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7994 "[N] -> { A[i] -> C[N] }",
7995 "{ }" },
7996 { &isl_union_map_intersect_range_factor_domain,
7997 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7998 "[N] -> { A[i] -> B[N] }",
7999 "[N] -> { A[N - 1] -> [B[N] -> C[N + 1]] }" },
8000 { &isl_union_map_intersect_range_factor_domain,
8001 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
8002 "[N] -> { A[i] -> B[N] }",
8003 "[N] -> { A[N - 1] -> T[B[N] -> C[N + 1]] }" },
8004 { &isl_union_map_intersect_range_factor_domain,
8005 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8006 "[N] -> { A[i] -> C[N] }",
8007 "{ }" },
8008 { &isl_union_map_intersect_range_factor_range,
8009 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8010 "[N] -> { A[i] -> C[N] }",
8011 "[N] -> { A[N - 2] -> [B[N - 1] -> C[N]] }" },
8012 { &isl_union_map_intersect_range_factor_range,
8013 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
8014 "[N] -> { A[i] -> C[N] }",
8015 "[N] -> { A[N - 2] -> T[B[N - 1] -> C[N]] }" },
8016 { &isl_union_map_intersect_range_factor_range,
8017 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
8018 "[N] -> { A[i] -> B[N] }",
8019 "{ }" },
8022 /* Perform basic tests of binary operations on isl_union_map.
8024 static isl_stat test_bin_union_map(isl_ctx *ctx)
8026 int i;
8028 for (i = 0; i < ARRAY_SIZE(umap_bin_tests); ++i) {
8029 const char *str;
8030 isl_union_map *umap1, *umap2, *res;
8031 isl_bool equal;
8033 str = umap_bin_tests[i].arg1;
8034 umap1 = isl_union_map_read_from_str(ctx, str);
8035 str = umap_bin_tests[i].arg2;
8036 umap2 = isl_union_map_read_from_str(ctx, str);
8037 str = umap_bin_tests[i].res;
8038 res = isl_union_map_read_from_str(ctx, str);
8039 umap1 = umap_bin_tests[i].fn(umap1, umap2);
8040 equal = isl_union_map_is_equal(umap1, res);
8041 isl_union_map_free(umap1);
8042 isl_union_map_free(res);
8043 if (equal < 0)
8044 return isl_stat_error;
8045 if (!equal)
8046 isl_die(ctx, isl_error_unknown,
8047 "unexpected result", return isl_stat_error);
8050 return isl_stat_ok;
8053 /* Check that isl_union_set_contains finds space independently
8054 * of the parameters.
8056 static isl_stat test_union_set_contains(isl_ctx *ctx)
8058 const char *str;
8059 isl_bool ok;
8060 isl_space *space;
8061 isl_id *id;
8062 isl_union_set *uset;
8064 str = "[N] -> { A[0:N]; B[*,*] }";
8065 uset = isl_union_set_read_from_str(ctx, str);
8066 space = isl_space_unit(ctx);
8067 id = isl_id_alloc(ctx, "A", NULL);
8068 space = isl_space_add_named_tuple_id_ui(space, id, 1);
8069 ok = isl_union_set_contains(uset, space);
8070 isl_space_free(space);
8071 isl_union_set_free(uset);
8073 if (ok < 0)
8074 return isl_stat_error;
8075 if (!ok)
8076 isl_die(ctx, isl_error_unknown,
8077 "unexpected result", return isl_stat_error);
8079 return isl_stat_ok;
8082 /* Perform basic tests of operations on isl_union_map or isl_union_set.
8084 static int test_union_map(isl_ctx *ctx)
8086 if (test_un_union_map(ctx) < 0)
8087 return -1;
8088 if (test_bin_union_map(ctx) < 0)
8089 return -1;
8090 if (test_union_set_contains(ctx) < 0)
8091 return -1;
8092 return 0;
8095 int test_union_pw(isl_ctx *ctx)
8097 int equal;
8098 const char *str;
8099 isl_union_set *uset;
8100 isl_union_pw_qpolynomial *upwqp1, *upwqp2;
8102 str = "{ [x] -> x^2 }";
8103 upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str);
8104 upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1);
8105 uset = isl_union_pw_qpolynomial_domain(upwqp1);
8106 upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2);
8107 upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset);
8108 equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2);
8109 isl_union_pw_qpolynomial_free(upwqp1);
8110 isl_union_pw_qpolynomial_free(upwqp2);
8111 if (equal < 0)
8112 return -1;
8113 if (!equal)
8114 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
8116 return 0;
8119 /* Inputs for basic tests of functions that select
8120 * subparts of the domain of an isl_multi_union_pw_aff.
8121 * "fn" is the function that is tested.
8122 * "arg" is a string description of the input.
8123 * "res" is a string description of the expected result.
8125 struct {
8126 __isl_give isl_union_set *(*fn)(
8127 __isl_take isl_multi_union_pw_aff *mupa);
8128 const char *arg;
8129 const char *res;
8130 } un_locus_tests[] = {
8131 { &isl_multi_union_pw_aff_zero_union_set,
8132 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8133 "{ A[0,j]; B[0,j] }" },
8134 { &isl_multi_union_pw_aff_zero_union_set,
8135 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
8136 "{ A[i,i]; B[i,i] : i >= 0 }" },
8137 { &isl_multi_union_pw_aff_zero_union_set,
8138 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
8139 "{ A[i,j]; B[i,i] : i >= 0 }" },
8142 /* Perform some basic tests of functions that select
8143 * subparts of the domain of an isl_multi_union_pw_aff.
8145 static int test_un_locus(isl_ctx *ctx)
8147 int i;
8148 isl_bool ok;
8149 isl_union_set *uset, *res;
8150 isl_multi_union_pw_aff *mupa;
8152 for (i = 0; i < ARRAY_SIZE(un_locus_tests); ++i) {
8153 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
8154 un_locus_tests[i].arg);
8155 res = isl_union_set_read_from_str(ctx, un_locus_tests[i].res);
8156 uset = un_locus_tests[i].fn(mupa);
8157 ok = isl_union_set_is_equal(uset, res);
8158 isl_union_set_free(uset);
8159 isl_union_set_free(res);
8160 if (ok < 0)
8161 return -1;
8162 if (!ok)
8163 isl_die(ctx, isl_error_unknown,
8164 "unexpected result", return -1);
8167 return 0;
8170 /* Inputs for basic tests of functions that select
8171 * subparts of an isl_union_map based on a relation
8172 * specified by an isl_multi_union_pw_aff.
8173 * "fn" is the function that is tested.
8174 * "arg1" and "arg2" are string descriptions of the inputs.
8175 * "res" is a string description of the expected result.
8177 struct {
8178 __isl_give isl_union_map *(*fn)(
8179 __isl_take isl_union_map *umap,
8180 __isl_take isl_multi_union_pw_aff *mupa);
8181 const char *arg1;
8182 const char *arg2;
8183 const char *res;
8184 } bin_locus_tests[] = {
8185 { &isl_union_map_eq_at_multi_union_pw_aff,
8186 "{ A[i,j] -> B[i',j'] }",
8187 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8188 "{ A[i,j] -> B[i,j'] }" },
8189 { &isl_union_map_eq_at_multi_union_pw_aff,
8190 "{ A[i,j] -> B[i',j'] }",
8191 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8192 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8193 "{ A[i,j] -> B[i,j] }" },
8194 { &isl_union_map_eq_at_multi_union_pw_aff,
8195 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8196 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8197 "{ A[i,j] -> B[i,j'] }" },
8198 { &isl_union_map_eq_at_multi_union_pw_aff,
8199 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8200 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
8201 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
8202 { &isl_union_map_eq_at_multi_union_pw_aff,
8203 "{ A[i,j] -> B[i',j'] }",
8204 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
8205 "{ A[i,j] -> B[i,j'] : i > j }" },
8206 { &isl_union_map_lex_le_at_multi_union_pw_aff,
8207 "{ A[i,j] -> B[i',j'] }",
8208 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8209 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8210 "{ A[i,j] -> B[i',j'] : i,j <<= i',j' }" },
8211 { &isl_union_map_lex_lt_at_multi_union_pw_aff,
8212 "{ A[i,j] -> B[i',j'] }",
8213 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8214 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8215 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
8216 { &isl_union_map_lex_ge_at_multi_union_pw_aff,
8217 "{ A[i,j] -> B[i',j'] }",
8218 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8219 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8220 "{ A[i,j] -> B[i',j'] : i,j >>= i',j' }" },
8221 { &isl_union_map_lex_gt_at_multi_union_pw_aff,
8222 "{ A[i,j] -> B[i',j'] }",
8223 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8224 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8225 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
8226 { &isl_union_map_eq_at_multi_union_pw_aff,
8227 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8228 "(F[] : { A[i,j]; B[i,j] })",
8229 "{ A[i,j] -> B[i',j'] }" },
8230 { &isl_union_map_eq_at_multi_union_pw_aff,
8231 "{ A[i,j] -> B[i',j'] }",
8232 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8233 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
8234 { &isl_union_map_eq_at_multi_union_pw_aff,
8235 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
8236 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8237 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
8238 { &isl_union_map_eq_at_multi_union_pw_aff,
8239 "{ A[i,j] -> B[i',j'] }",
8240 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
8241 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
8242 { &isl_union_map_eq_at_multi_union_pw_aff,
8243 "{ A[i,j] -> B[i',j'] }",
8244 "[N] -> (F[] : { : N >= 0 })",
8245 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
8248 /* Perform some basic tests of functions that select
8249 * subparts of an isl_union_map based on a relation
8250 * specified by an isl_multi_union_pw_aff.
8252 static int test_bin_locus(isl_ctx *ctx)
8254 int i;
8255 isl_bool ok;
8256 isl_union_map *umap, *res;
8257 isl_multi_union_pw_aff *mupa;
8259 for (i = 0; i < ARRAY_SIZE(bin_locus_tests); ++i) {
8260 umap = isl_union_map_read_from_str(ctx,
8261 bin_locus_tests[i].arg1);
8262 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
8263 bin_locus_tests[i].arg2);
8264 res = isl_union_map_read_from_str(ctx, bin_locus_tests[i].res);
8265 umap = bin_locus_tests[i].fn(umap, mupa);
8266 ok = isl_union_map_is_equal(umap, res);
8267 isl_union_map_free(umap);
8268 isl_union_map_free(res);
8269 if (ok < 0)
8270 return -1;
8271 if (!ok)
8272 isl_die(ctx, isl_error_unknown,
8273 "unexpected result", return -1);
8276 return 0;
8279 /* Inputs for basic tests of functions that determine
8280 * the part of the domain where two isl_multi_aff objects
8281 * related to each other in a specific way.
8282 * "fn" is the function that is being tested.
8283 * "arg1" and "arg2" are string descriptions of the inputs.
8284 * "res" is a string description of the expected result.
8286 static struct {
8287 __isl_give isl_set *(*fn)(__isl_take isl_multi_aff *ma1,
8288 __isl_take isl_multi_aff *ma2);
8289 const char *arg1;
8290 const char *arg2;
8291 const char *res;
8292 } bin_locus_ma_tests[] = {
8293 { &isl_multi_aff_lex_le_set, "{ [] }", "{ [] }", "{ : }" },
8294 { &isl_multi_aff_lex_lt_set, "{ [] }", "{ [] }", "{ : false }" },
8295 { &isl_multi_aff_lex_le_set,
8296 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8297 "{ A[i] : i <= 0 }" },
8298 { &isl_multi_aff_lex_lt_set,
8299 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8300 "{ A[i] : i < 0 }" },
8301 { &isl_multi_aff_lex_le_set,
8302 "{ A[i] -> [i, i] }", "{ A[i] -> [0, 0] }",
8303 "{ A[i] : i <= 0 }" },
8304 { &isl_multi_aff_lex_le_set,
8305 "{ A[i] -> [i, 0] }", "{ A[i] -> [0, 0] }",
8306 "{ A[i] : i <= 0 }" },
8307 { &isl_multi_aff_lex_le_set,
8308 "{ A[i] -> [i, 1] }", "{ A[i] -> [0, 0] }",
8309 "{ A[i] : i < 0 }" },
8312 /* Perform some basic tests of functions that determine
8313 * the part of the domain where two isl_multi_aff objects
8314 * related to each other in a specific way.
8316 static isl_stat test_bin_locus_ma(isl_ctx *ctx)
8318 int i;
8320 for (i = 0; i < ARRAY_SIZE(bin_locus_ma_tests); ++i) {
8321 const char *str;
8322 isl_bool ok;
8323 isl_multi_aff *ma1, *ma2;
8324 isl_set *set, *res;
8326 str = bin_locus_ma_tests[i].arg1;
8327 ma1 = isl_multi_aff_read_from_str(ctx, str);
8328 str = bin_locus_ma_tests[i].arg2;
8329 ma2 = isl_multi_aff_read_from_str(ctx, str);
8330 res = isl_set_read_from_str(ctx, bin_locus_ma_tests[i].res);
8331 set = bin_locus_ma_tests[i].fn(ma1, ma2);
8332 ok = isl_set_is_equal(set, res);
8333 isl_set_free(set);
8334 isl_set_free(res);
8335 if (ok < 0)
8336 return isl_stat_error;
8337 if (!ok)
8338 isl_die(ctx, isl_error_unknown,
8339 "unexpected result", return isl_stat_error);
8342 return isl_stat_ok;
8345 /* Perform basic locus tests.
8347 static int test_locus(isl_ctx *ctx)
8349 if (test_un_locus(ctx) < 0)
8350 return -1;
8351 if (test_bin_locus(ctx) < 0)
8352 return -1;
8353 if (test_bin_locus_ma(ctx) < 0)
8354 return -1;
8355 return 0;
8358 /* Test that isl_union_pw_qpolynomial_eval picks up the function
8359 * defined over the correct domain space.
8361 static int test_eval_1(isl_ctx *ctx)
8363 const char *str;
8364 isl_point *pnt;
8365 isl_set *set;
8366 isl_union_pw_qpolynomial *upwqp;
8367 isl_val *v;
8368 int cmp;
8370 str = "{ A[x] -> x^2; B[x] -> -x^2 }";
8371 upwqp = isl_union_pw_qpolynomial_read_from_str(ctx, str);
8372 str = "{ A[6] }";
8373 set = isl_set_read_from_str(ctx, str);
8374 pnt = isl_set_sample_point(set);
8375 v = isl_union_pw_qpolynomial_eval(upwqp, pnt);
8376 cmp = isl_val_cmp_si(v, 36);
8377 isl_val_free(v);
8379 if (!v)
8380 return -1;
8381 if (cmp != 0)
8382 isl_die(ctx, isl_error_unknown, "unexpected value", return -1);
8384 return 0;
8387 /* Check that isl_qpolynomial_eval handles getting called on a void point.
8389 static int test_eval_2(isl_ctx *ctx)
8391 const char *str;
8392 isl_point *pnt;
8393 isl_set *set;
8394 isl_qpolynomial *qp;
8395 isl_val *v;
8396 isl_bool ok;
8398 str = "{ A[x] -> [x] }";
8399 qp = isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx, str));
8400 str = "{ A[x] : false }";
8401 set = isl_set_read_from_str(ctx, str);
8402 pnt = isl_set_sample_point(set);
8403 v = isl_qpolynomial_eval(qp, pnt);
8404 ok = isl_val_is_nan(v);
8405 isl_val_free(v);
8407 if (ok < 0)
8408 return -1;
8409 if (!ok)
8410 isl_die(ctx, isl_error_unknown, "expecting NaN", return -1);
8412 return 0;
8415 /* Check that a polynomial (without local variables) can be evaluated
8416 * in a rational point.
8418 static isl_stat test_eval_3(isl_ctx *ctx)
8420 isl_pw_qpolynomial *pwqp;
8421 isl_point *pnt;
8422 isl_val *v;
8423 isl_stat r;
8425 pwqp = isl_pw_qpolynomial_read_from_str(ctx, "{ [x] -> x^2 }");
8426 pnt = isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp));
8427 v = isl_val_read_from_str(ctx, "1/2");
8428 pnt = isl_point_set_coordinate_val(pnt, isl_dim_set, 0, v);
8429 v = isl_pw_qpolynomial_eval(pwqp, pnt);
8430 r = val_check_equal(v, "1/4");
8431 isl_val_free(v);
8433 return r;
8436 /* Inputs for isl_pw_aff_eval test.
8437 * "f" is the affine function.
8438 * "p" is the point where the function should be evaluated.
8439 * "res" is the expected result.
8441 struct {
8442 const char *f;
8443 const char *p;
8444 const char *res;
8445 } aff_eval_tests[] = {
8446 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
8447 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
8448 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
8449 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
8450 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
8451 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
8452 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
8453 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
8454 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
8455 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
8456 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
8457 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
8458 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
8459 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
8460 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
8461 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
8462 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
8463 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
8464 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
8465 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
8466 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
8467 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
8468 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
8471 /* Perform basic isl_pw_aff_eval tests.
8473 static int test_eval_aff(isl_ctx *ctx)
8475 int i;
8477 for (i = 0; i < ARRAY_SIZE(aff_eval_tests); ++i) {
8478 isl_stat r;
8479 isl_pw_aff *pa;
8480 isl_set *set;
8481 isl_point *pnt;
8482 isl_val *v;
8484 pa = isl_pw_aff_read_from_str(ctx, aff_eval_tests[i].f);
8485 set = isl_set_read_from_str(ctx, aff_eval_tests[i].p);
8486 pnt = isl_set_sample_point(set);
8487 v = isl_pw_aff_eval(pa, pnt);
8488 r = val_check_equal(v, aff_eval_tests[i].res);
8489 isl_val_free(v);
8490 if (r < 0)
8491 return -1;
8493 return 0;
8496 /* Perform basic evaluation tests.
8498 static int test_eval(isl_ctx *ctx)
8500 if (test_eval_1(ctx) < 0)
8501 return -1;
8502 if (test_eval_2(ctx) < 0)
8503 return -1;
8504 if (test_eval_3(ctx) < 0)
8505 return -1;
8506 if (test_eval_aff(ctx) < 0)
8507 return -1;
8508 return 0;
8511 /* Descriptions of sets that are tested for reparsing after printing.
8513 const char *output_tests[] = {
8514 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
8515 "{ [x] : 1 = 0 }",
8516 "{ [x] : false }",
8517 "{ [x] : x mod 2 = 0 }",
8518 "{ [x] : x mod 2 = 1 }",
8519 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
8520 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
8521 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8522 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8523 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
8524 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
8527 /* Check that printing a set and reparsing a set from the printed output
8528 * results in the same set.
8530 static int test_output_set(isl_ctx *ctx)
8532 int i;
8533 char *str;
8534 isl_set *set1, *set2;
8535 isl_bool equal;
8537 for (i = 0; i < ARRAY_SIZE(output_tests); ++i) {
8538 set1 = isl_set_read_from_str(ctx, output_tests[i]);
8539 str = isl_set_to_str(set1);
8540 set2 = isl_set_read_from_str(ctx, str);
8541 free(str);
8542 equal = isl_set_is_equal(set1, set2);
8543 isl_set_free(set1);
8544 isl_set_free(set2);
8545 if (equal < 0)
8546 return -1;
8547 if (!equal)
8548 isl_die(ctx, isl_error_unknown,
8549 "parsed output not the same", return -1);
8552 return 0;
8555 /* Check that an isl_multi_aff is printed using a consistent space.
8557 static isl_stat test_output_ma(isl_ctx *ctx)
8559 char *str;
8560 isl_bool equal;
8561 isl_aff *aff;
8562 isl_multi_aff *ma, *ma2;
8564 ma = isl_multi_aff_read_from_str(ctx, "{ [a, b] -> [a + b] }");
8565 aff = isl_aff_read_from_str(ctx, "{ [c, d] -> [c + d] }");
8566 ma = isl_multi_aff_set_aff(ma, 0, aff);
8567 str = isl_multi_aff_to_str(ma);
8568 ma2 = isl_multi_aff_read_from_str(ctx, str);
8569 free(str);
8570 equal = isl_multi_aff_plain_is_equal(ma, ma2);
8571 isl_multi_aff_free(ma2);
8572 isl_multi_aff_free(ma);
8574 if (equal < 0)
8575 return isl_stat_error;
8576 if (!equal)
8577 isl_die(ctx, isl_error_unknown, "bad conversion",
8578 return isl_stat_error);
8580 return isl_stat_ok;
8583 /* Check that an isl_multi_pw_aff is printed using a consistent space.
8585 static isl_stat test_output_mpa(isl_ctx *ctx)
8587 char *str;
8588 isl_bool equal;
8589 isl_pw_aff *pa;
8590 isl_multi_pw_aff *mpa, *mpa2;
8592 mpa = isl_multi_pw_aff_read_from_str(ctx, "{ [a, b] -> [a + b] }");
8593 pa = isl_pw_aff_read_from_str(ctx, "{ [c, d] -> [c + d] }");
8594 mpa = isl_multi_pw_aff_set_pw_aff(mpa, 0, pa);
8595 str = isl_multi_pw_aff_to_str(mpa);
8596 mpa2 = isl_multi_pw_aff_read_from_str(ctx, str);
8597 free(str);
8598 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2);
8599 isl_multi_pw_aff_free(mpa2);
8600 isl_multi_pw_aff_free(mpa);
8602 if (equal < 0)
8603 return isl_stat_error;
8604 if (!equal)
8605 isl_die(ctx, isl_error_unknown, "bad conversion",
8606 return isl_stat_error);
8608 return isl_stat_ok;
8611 int test_output(isl_ctx *ctx)
8613 char *s;
8614 const char *str;
8615 isl_pw_aff *pa;
8616 isl_printer *p;
8617 int equal;
8619 if (test_output_set(ctx) < 0)
8620 return -1;
8621 if (test_output_ma(ctx) < 0)
8622 return -1;
8623 if (test_output_mpa(ctx) < 0)
8624 return -1;
8626 str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
8627 pa = isl_pw_aff_read_from_str(ctx, str);
8629 p = isl_printer_to_str(ctx);
8630 p = isl_printer_set_output_format(p, ISL_FORMAT_C);
8631 p = isl_printer_print_pw_aff(p, pa);
8632 s = isl_printer_get_str(p);
8633 isl_printer_free(p);
8634 isl_pw_aff_free(pa);
8635 if (!s)
8636 equal = -1;
8637 else
8638 equal = !strcmp(s, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
8639 free(s);
8640 if (equal < 0)
8641 return -1;
8642 if (!equal)
8643 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
8645 return 0;
8648 int test_sample(isl_ctx *ctx)
8650 const char *str;
8651 isl_basic_set *bset1, *bset2;
8652 int empty, subset;
8654 str = "{ [a, b, c, d, e, f, g, h, i, j, k] : "
8655 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
8656 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
8657 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
8658 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
8659 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
8660 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
8661 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
8662 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
8663 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
8664 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
8665 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
8666 "d - 1073741821e and "
8667 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
8668 "3j >= 1 - a + b + 2e and "
8669 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
8670 "3i <= 4 - a + 4b - e and "
8671 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
8672 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
8673 "c <= -1 + a and 3i >= -2 - a + 3e and "
8674 "1073741822e <= 1073741823 - a + 1073741822b + c and "
8675 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
8676 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
8677 "1073741823e >= 1 + 1073741823b - d and "
8678 "3i >= 1073741823b + c - 1073741823e - f and "
8679 "3i >= 1 + 2b + e + 3g }";
8680 bset1 = isl_basic_set_read_from_str(ctx, str);
8681 bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1));
8682 empty = isl_basic_set_is_empty(bset2);
8683 subset = isl_basic_set_is_subset(bset2, bset1);
8684 isl_basic_set_free(bset1);
8685 isl_basic_set_free(bset2);
8686 if (empty < 0 || subset < 0)
8687 return -1;
8688 if (empty)
8689 isl_die(ctx, isl_error_unknown, "point not found", return -1);
8690 if (!subset)
8691 isl_die(ctx, isl_error_unknown, "bad point found", return -1);
8693 return 0;
8696 int test_fixed_power(isl_ctx *ctx)
8698 const char *str;
8699 isl_map *map;
8700 isl_val *exp;
8701 int equal;
8703 str = "{ [i] -> [i + 1] }";
8704 map = isl_map_read_from_str(ctx, str);
8705 exp = isl_val_int_from_si(ctx, 23);
8706 map = isl_map_fixed_power_val(map, exp);
8707 equal = map_check_equal(map, "{ [i] -> [i + 23] }");
8708 isl_map_free(map);
8709 if (equal < 0)
8710 return -1;
8712 return 0;
8715 int test_slice(isl_ctx *ctx)
8717 const char *str;
8718 isl_map *map;
8719 int equal;
8721 str = "{ [i] -> [j] }";
8722 map = isl_map_read_from_str(ctx, str);
8723 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_out, 0);
8724 equal = map_check_equal(map, "{ [i] -> [i] }");
8725 isl_map_free(map);
8726 if (equal < 0)
8727 return -1;
8729 str = "{ [i] -> [j] }";
8730 map = isl_map_read_from_str(ctx, str);
8731 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_in, 0);
8732 equal = map_check_equal(map, "{ [i] -> [j] }");
8733 isl_map_free(map);
8734 if (equal < 0)
8735 return -1;
8737 str = "{ [i] -> [j] }";
8738 map = isl_map_read_from_str(ctx, str);
8739 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_out, 0);
8740 equal = map_check_equal(map, "{ [i] -> [-i] }");
8741 isl_map_free(map);
8742 if (equal < 0)
8743 return -1;
8745 str = "{ [i] -> [j] }";
8746 map = isl_map_read_from_str(ctx, str);
8747 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_in, 0);
8748 equal = map_check_equal(map, "{ [0] -> [j] }");
8749 isl_map_free(map);
8750 if (equal < 0)
8751 return -1;
8753 str = "{ [i] -> [j] }";
8754 map = isl_map_read_from_str(ctx, str);
8755 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_out, 0);
8756 equal = map_check_equal(map, "{ [i] -> [j] : i > j }");
8757 isl_map_free(map);
8758 if (equal < 0)
8759 return -1;
8761 str = "{ [i] -> [j] }";
8762 map = isl_map_read_from_str(ctx, str);
8763 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_in, 0);
8764 equal = map_check_equal(map, "{ [i] -> [j] : false }");
8765 isl_map_free(map);
8766 if (equal < 0)
8767 return -1;
8769 return 0;
8772 int test_eliminate(isl_ctx *ctx)
8774 const char *str;
8775 isl_map *map;
8776 int equal;
8778 str = "{ [i] -> [j] : i = 2j }";
8779 map = isl_map_read_from_str(ctx, str);
8780 map = isl_map_eliminate(map, isl_dim_out, 0, 1);
8781 equal = map_check_equal(map, "{ [i] -> [j] : exists a : i = 2a }");
8782 isl_map_free(map);
8783 if (equal < 0)
8784 return -1;
8786 return 0;
8789 /* Check basic functionality of isl_map_deltas_map.
8791 static int test_deltas_map(isl_ctx *ctx)
8793 const char *str;
8794 isl_map *map;
8795 int equal;
8797 str = "{ A[i] -> A[i + 1] }";
8798 map = isl_map_read_from_str(ctx, str);
8799 map = isl_map_deltas_map(map);
8800 equal = map_check_equal(map, "{ [A[i] -> A[i + 1]] -> A[1] }");
8801 isl_map_free(map);
8802 if (equal < 0)
8803 return -1;
8805 return 0;
8808 /* Check that isl_set_dim_residue_class detects that the values of j
8809 * in the set below are all odd and that it does not detect any spurious
8810 * strides.
8812 static int test_residue_class(isl_ctx *ctx)
8814 const char *str;
8815 isl_set *set;
8816 isl_int m, r;
8817 isl_stat res;
8819 str = "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
8820 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
8821 set = isl_set_read_from_str(ctx, str);
8822 isl_int_init(m);
8823 isl_int_init(r);
8824 res = isl_set_dim_residue_class(set, 1, &m, &r);
8825 if (res >= 0 &&
8826 (isl_int_cmp_si(m, 2) != 0 || isl_int_cmp_si(r, 1) != 0))
8827 isl_die(ctx, isl_error_unknown, "incorrect residue class",
8828 res = isl_stat_error);
8829 isl_int_clear(r);
8830 isl_int_clear(m);
8831 isl_set_free(set);
8833 return res;
8836 static int test_align_parameters_1(isl_ctx *ctx)
8838 const char *str;
8839 isl_space *space;
8840 isl_multi_aff *ma1, *ma2;
8841 int equal;
8843 str = "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
8844 ma1 = isl_multi_aff_read_from_str(ctx, str);
8846 space = isl_space_params_alloc(ctx, 1);
8847 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
8848 ma1 = isl_multi_aff_align_params(ma1, space);
8850 str = "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
8851 ma2 = isl_multi_aff_read_from_str(ctx, str);
8853 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
8855 isl_multi_aff_free(ma1);
8856 isl_multi_aff_free(ma2);
8858 if (equal < 0)
8859 return -1;
8860 if (!equal)
8861 isl_die(ctx, isl_error_unknown,
8862 "result not as expected", return -1);
8864 return 0;
8867 /* Check the isl_multi_*_from_*_list operation in case inputs
8868 * have unaligned parameters.
8869 * In particular, older versions of isl would simply fail
8870 * (without printing any error message).
8872 static isl_stat test_align_parameters_2(isl_ctx *ctx)
8874 isl_space *space;
8875 isl_map *map;
8876 isl_aff *aff;
8877 isl_multi_aff *ma;
8879 map = isl_map_read_from_str(ctx, "{ A[] -> M[x] }");
8880 space = isl_map_get_space(map);
8881 isl_map_free(map);
8883 aff = isl_aff_read_from_str(ctx, "[N] -> { A[] -> [N] }");
8884 ma = isl_multi_aff_from_aff_list(space, isl_aff_list_from_aff(aff));
8885 isl_multi_aff_free(ma);
8887 if (!ma)
8888 return isl_stat_error;
8889 return isl_stat_ok;
8892 /* Perform basic parameter alignment tests.
8894 static int test_align_parameters(isl_ctx *ctx)
8896 if (test_align_parameters_1(ctx) < 0)
8897 return -1;
8898 if (test_align_parameters_2(ctx) < 0)
8899 return -1;
8901 return 0;
8904 /* Check that isl_*_drop_unused_params actually drops the unused parameters
8905 * by comparing the result using isl_*_plain_is_equal.
8906 * Note that this assumes that isl_*_plain_is_equal does not consider
8907 * objects that only differ by unused parameters to be equal.
8909 int test_drop_unused_parameters(isl_ctx *ctx)
8911 const char *str_with, *str_without;
8912 isl_basic_set *bset1, *bset2;
8913 isl_set *set1, *set2;
8914 isl_pw_aff *pwa1, *pwa2;
8915 int equal;
8917 str_with = "[n, m, o] -> { [m] }";
8918 str_without = "[m] -> { [m] }";
8920 bset1 = isl_basic_set_read_from_str(ctx, str_with);
8921 bset2 = isl_basic_set_read_from_str(ctx, str_without);
8922 bset1 = isl_basic_set_drop_unused_params(bset1);
8923 equal = isl_basic_set_plain_is_equal(bset1, bset2);
8924 isl_basic_set_free(bset1);
8925 isl_basic_set_free(bset2);
8927 if (equal < 0)
8928 return -1;
8929 if (!equal)
8930 isl_die(ctx, isl_error_unknown,
8931 "result not as expected", return -1);
8933 set1 = isl_set_read_from_str(ctx, str_with);
8934 set2 = isl_set_read_from_str(ctx, str_without);
8935 set1 = isl_set_drop_unused_params(set1);
8936 equal = isl_set_plain_is_equal(set1, set2);
8937 isl_set_free(set1);
8938 isl_set_free(set2);
8940 if (equal < 0)
8941 return -1;
8942 if (!equal)
8943 isl_die(ctx, isl_error_unknown,
8944 "result not as expected", return -1);
8946 pwa1 = isl_pw_aff_read_from_str(ctx, str_with);
8947 pwa2 = isl_pw_aff_read_from_str(ctx, str_without);
8948 pwa1 = isl_pw_aff_drop_unused_params(pwa1);
8949 equal = isl_pw_aff_plain_is_equal(pwa1, pwa2);
8950 isl_pw_aff_free(pwa1);
8951 isl_pw_aff_free(pwa2);
8953 if (equal < 0)
8954 return -1;
8955 if (!equal)
8956 isl_die(ctx, isl_error_unknown,
8957 "result not as expected", return -1);
8959 return 0;
8962 static int test_list(isl_ctx *ctx)
8964 isl_id *a, *b, *c, *d, *id;
8965 isl_id_list *list;
8966 isl_size n;
8967 int ok;
8969 a = isl_id_alloc(ctx, "a", NULL);
8970 b = isl_id_alloc(ctx, "b", NULL);
8971 c = isl_id_alloc(ctx, "c", NULL);
8972 d = isl_id_alloc(ctx, "d", NULL);
8974 list = isl_id_list_alloc(ctx, 4);
8975 list = isl_id_list_add(list, b);
8976 list = isl_id_list_insert(list, 0, a);
8977 list = isl_id_list_add(list, c);
8978 list = isl_id_list_add(list, d);
8979 list = isl_id_list_drop(list, 1, 1);
8981 n = isl_id_list_n_id(list);
8982 if (n < 0)
8983 return -1;
8984 if (n != 3) {
8985 isl_id_list_free(list);
8986 isl_die(ctx, isl_error_unknown,
8987 "unexpected number of elements in list", return -1);
8990 id = isl_id_list_get_id(list, 0);
8991 ok = id == a;
8992 isl_id_free(id);
8993 id = isl_id_list_get_id(list, 1);
8994 ok = ok && id == c;
8995 isl_id_free(id);
8996 id = isl_id_list_get_id(list, 2);
8997 ok = ok && id == d;
8998 isl_id_free(id);
9000 isl_id_list_free(list);
9002 if (!ok)
9003 isl_die(ctx, isl_error_unknown,
9004 "unexpected elements in list", return -1);
9006 return 0;
9009 /* Check the conversion from an isl_multi_aff to an isl_basic_set.
9011 static isl_stat test_ma_conversion(isl_ctx *ctx)
9013 const char *str;
9014 isl_bool equal;
9015 isl_multi_aff *ma;
9016 isl_basic_set *bset1, *bset2;
9018 str = "[N] -> { A[0, N + 1] }";
9019 ma = isl_multi_aff_read_from_str(ctx, str);
9020 bset1 = isl_basic_set_read_from_str(ctx, str);
9021 bset2 = isl_basic_set_from_multi_aff(ma);
9022 equal = isl_basic_set_is_equal(bset1, bset2);
9023 isl_basic_set_free(bset1);
9024 isl_basic_set_free(bset2);
9025 if (equal < 0)
9026 return isl_stat_error;
9027 if (!equal)
9028 isl_die(ctx, isl_error_unknown, "bad conversion",
9029 return isl_stat_error);
9030 return isl_stat_ok;
9033 const char *set_conversion_tests[] = {
9034 "[N] -> { [i] : N - 1 <= 2 i <= N }",
9035 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
9036 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9037 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
9038 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
9039 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
9040 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
9041 "-3 + c <= d <= 28 + c) }",
9044 /* Check that converting from isl_set to isl_pw_multi_aff and back
9045 * to isl_set produces the original isl_set.
9047 static int test_set_conversion(isl_ctx *ctx)
9049 int i;
9050 const char *str;
9051 isl_set *set1, *set2;
9052 isl_pw_multi_aff *pma;
9053 int equal;
9055 for (i = 0; i < ARRAY_SIZE(set_conversion_tests); ++i) {
9056 str = set_conversion_tests[i];
9057 set1 = isl_set_read_from_str(ctx, str);
9058 pma = isl_pw_multi_aff_from_set(isl_set_copy(set1));
9059 set2 = isl_set_from_pw_multi_aff(pma);
9060 equal = isl_set_is_equal(set1, set2);
9061 isl_set_free(set1);
9062 isl_set_free(set2);
9064 if (equal < 0)
9065 return -1;
9066 if (!equal)
9067 isl_die(ctx, isl_error_unknown, "bad conversion",
9068 return -1);
9071 return 0;
9074 const char *conversion_tests[] = {
9075 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9076 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9077 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9078 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9079 "9e <= -2 - 2a) }",
9080 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9081 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9082 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9085 /* Check that converting from isl_map to isl_pw_multi_aff and back
9086 * to isl_map produces the original isl_map.
9088 static int test_map_conversion(isl_ctx *ctx)
9090 int i;
9091 isl_map *map1, *map2;
9092 isl_pw_multi_aff *pma;
9093 int equal;
9095 for (i = 0; i < ARRAY_SIZE(conversion_tests); ++i) {
9096 map1 = isl_map_read_from_str(ctx, conversion_tests[i]);
9097 pma = isl_pw_multi_aff_from_map(isl_map_copy(map1));
9098 map2 = isl_map_from_pw_multi_aff(pma);
9099 equal = isl_map_is_equal(map1, map2);
9100 isl_map_free(map1);
9101 isl_map_free(map2);
9103 if (equal < 0)
9104 return -1;
9105 if (!equal)
9106 isl_die(ctx, isl_error_unknown, "bad conversion",
9107 return -1);
9110 return 0;
9113 /* Descriptions of isl_pw_multi_aff objects for testing conversion
9114 * to isl_multi_pw_aff and back.
9116 const char *mpa_conversion_tests[] = {
9117 "{ [x] -> A[x] }",
9118 "{ [x] -> A[x] : x >= 0 }",
9119 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
9120 "{ [x] -> A[x, x + 1] }",
9121 "{ [x] -> A[] }",
9122 "{ [x] -> A[] : x >= 0 }",
9125 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
9126 * back to isl_pw_multi_aff preserves the original meaning.
9128 static int test_mpa_conversion(isl_ctx *ctx)
9130 int i;
9131 isl_pw_multi_aff *pma1, *pma2;
9132 isl_multi_pw_aff *mpa;
9133 int equal;
9135 for (i = 0; i < ARRAY_SIZE(mpa_conversion_tests); ++i) {
9136 const char *str;
9137 str = mpa_conversion_tests[i];
9138 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
9139 pma2 = isl_pw_multi_aff_copy(pma1);
9140 mpa = isl_multi_pw_aff_from_pw_multi_aff(pma1);
9141 pma1 = isl_pw_multi_aff_from_multi_pw_aff(mpa);
9142 equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
9143 isl_pw_multi_aff_free(pma1);
9144 isl_pw_multi_aff_free(pma2);
9146 if (equal < 0)
9147 return -1;
9148 if (!equal)
9149 isl_die(ctx, isl_error_unknown, "bad conversion",
9150 return -1);
9153 return 0;
9156 /* Descriptions of union maps that should be convertible
9157 * to an isl_multi_union_pw_aff.
9159 const char *umap_mupa_conversion_tests[] = {
9160 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9161 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9162 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9163 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9164 "9e <= -2 - 2a) }",
9165 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9166 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9167 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9168 "{ A[] -> B[0]; C[] -> B[1] }",
9169 "{ A[] -> B[]; C[] -> B[] }",
9172 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
9173 * to isl_union_map produces the original isl_union_map.
9175 static int test_union_map_mupa_conversion(isl_ctx *ctx)
9177 int i;
9178 isl_union_map *umap1, *umap2;
9179 isl_multi_union_pw_aff *mupa;
9180 int equal;
9182 for (i = 0; i < ARRAY_SIZE(umap_mupa_conversion_tests); ++i) {
9183 const char *str;
9184 str = umap_mupa_conversion_tests[i];
9185 umap1 = isl_union_map_read_from_str(ctx, str);
9186 umap2 = isl_union_map_copy(umap1);
9187 mupa = isl_multi_union_pw_aff_from_union_map(umap2);
9188 umap2 = isl_union_map_from_multi_union_pw_aff(mupa);
9189 equal = isl_union_map_is_equal(umap1, umap2);
9190 isl_union_map_free(umap1);
9191 isl_union_map_free(umap2);
9193 if (equal < 0)
9194 return -1;
9195 if (!equal)
9196 isl_die(ctx, isl_error_unknown, "bad conversion",
9197 return -1);
9200 return 0;
9203 static int test_conversion(isl_ctx *ctx)
9205 if (test_ma_conversion(ctx) < 0)
9206 return -1;
9207 if (test_set_conversion(ctx) < 0)
9208 return -1;
9209 if (test_map_conversion(ctx) < 0)
9210 return -1;
9211 if (test_mpa_conversion(ctx) < 0)
9212 return -1;
9213 if (test_union_map_mupa_conversion(ctx) < 0)
9214 return -1;
9215 return 0;
9218 /* Check that isl_basic_map_curry does not modify input.
9220 static int test_curry(isl_ctx *ctx)
9222 const char *str;
9223 isl_basic_map *bmap1, *bmap2;
9224 int equal;
9226 str = "{ [A[] -> B[]] -> C[] }";
9227 bmap1 = isl_basic_map_read_from_str(ctx, str);
9228 bmap2 = isl_basic_map_curry(isl_basic_map_copy(bmap1));
9229 equal = isl_basic_map_is_equal(bmap1, bmap2);
9230 isl_basic_map_free(bmap1);
9231 isl_basic_map_free(bmap2);
9233 if (equal < 0)
9234 return -1;
9235 if (equal)
9236 isl_die(ctx, isl_error_unknown,
9237 "curried map should not be equal to original",
9238 return -1);
9240 return 0;
9243 struct {
9244 const char *set;
9245 const char *ma;
9246 const char *res;
9247 } preimage_tests[] = {
9248 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
9249 "{ A[j,i] -> B[i,j] }",
9250 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
9251 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
9252 "{ A[a,b] -> B[a/2,b/6] }",
9253 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
9254 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
9255 "{ A[a,b] -> B[a/2,b/6] }",
9256 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
9257 "exists i,j : a = 2 i and b = 6 j }" },
9258 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
9259 "[n] -> { : 0 <= n <= 100 }" },
9260 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
9261 "{ A[a] -> B[2a] }",
9262 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
9263 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
9264 "{ A[a] -> B[([a/2])] }",
9265 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
9266 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
9267 "{ A[a] -> B[a,a,a/3] }",
9268 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
9269 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
9270 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
9273 static int test_preimage_basic_set(isl_ctx *ctx)
9275 int i;
9276 isl_basic_set *bset1, *bset2;
9277 isl_multi_aff *ma;
9278 int equal;
9280 for (i = 0; i < ARRAY_SIZE(preimage_tests); ++i) {
9281 bset1 = isl_basic_set_read_from_str(ctx, preimage_tests[i].set);
9282 ma = isl_multi_aff_read_from_str(ctx, preimage_tests[i].ma);
9283 bset2 = isl_basic_set_read_from_str(ctx, preimage_tests[i].res);
9284 bset1 = isl_basic_set_preimage_multi_aff(bset1, ma);
9285 equal = isl_basic_set_is_equal(bset1, bset2);
9286 isl_basic_set_free(bset1);
9287 isl_basic_set_free(bset2);
9288 if (equal < 0)
9289 return -1;
9290 if (!equal)
9291 isl_die(ctx, isl_error_unknown, "bad preimage",
9292 return -1);
9295 return 0;
9298 struct {
9299 const char *map;
9300 const char *ma;
9301 const char *res;
9302 } preimage_domain_tests[] = {
9303 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
9304 "{ A[j,i] -> B[i,j] }",
9305 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
9306 { "{ B[i] -> C[i]; D[i] -> E[i] }",
9307 "{ A[i] -> B[i + 1] }",
9308 "{ A[i] -> C[i + 1] }" },
9309 { "{ B[i] -> C[i]; B[i] -> E[i] }",
9310 "{ A[i] -> B[i + 1] }",
9311 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
9312 { "{ B[i] -> C[([i/2])] }",
9313 "{ A[i] -> B[2i] }",
9314 "{ A[i] -> C[i] }" },
9315 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
9316 "{ A[i] -> B[([i/5]), ([i/7])] }",
9317 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
9318 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
9319 "[N] -> { A[] -> B[([N/5])] }",
9320 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
9321 { "{ B[i] -> C[i] : exists a : i = 5 a }",
9322 "{ A[i] -> B[2i] }",
9323 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
9324 { "{ B[i] -> C[i] : exists a : i = 2 a; "
9325 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
9326 "{ A[i] -> B[2i] }",
9327 "{ A[i] -> C[2i] }" },
9328 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
9329 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
9332 static int test_preimage_union_map(isl_ctx *ctx)
9334 int i;
9335 isl_union_map *umap1, *umap2;
9336 isl_multi_aff *ma;
9337 int equal;
9339 for (i = 0; i < ARRAY_SIZE(preimage_domain_tests); ++i) {
9340 umap1 = isl_union_map_read_from_str(ctx,
9341 preimage_domain_tests[i].map);
9342 ma = isl_multi_aff_read_from_str(ctx,
9343 preimage_domain_tests[i].ma);
9344 umap2 = isl_union_map_read_from_str(ctx,
9345 preimage_domain_tests[i].res);
9346 umap1 = isl_union_map_preimage_domain_multi_aff(umap1, ma);
9347 equal = isl_union_map_is_equal(umap1, umap2);
9348 isl_union_map_free(umap1);
9349 isl_union_map_free(umap2);
9350 if (equal < 0)
9351 return -1;
9352 if (!equal)
9353 isl_die(ctx, isl_error_unknown, "bad preimage",
9354 return -1);
9357 return 0;
9360 static int test_preimage(isl_ctx *ctx)
9362 if (test_preimage_basic_set(ctx) < 0)
9363 return -1;
9364 if (test_preimage_union_map(ctx) < 0)
9365 return -1;
9367 return 0;
9370 struct {
9371 const char *ma1;
9372 const char *ma;
9373 const char *res;
9374 } pullback_tests[] = {
9375 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
9376 "{ A[a,b] -> C[b + 2a] }" },
9377 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
9378 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
9379 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
9380 "{ A[a] -> C[(a)/6] }" },
9381 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
9382 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
9383 "{ A[a] -> C[(2a)/3] }" },
9384 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
9385 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
9386 "{ A[i,j] -> C[i + j, i + j] }"},
9387 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
9388 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
9389 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
9390 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
9391 "{ [i, j] -> [floor((i)/3), j] }",
9392 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
9395 static int test_pullback(isl_ctx *ctx)
9397 int i;
9398 isl_multi_aff *ma1, *ma2;
9399 isl_multi_aff *ma;
9400 int equal;
9402 for (i = 0; i < ARRAY_SIZE(pullback_tests); ++i) {
9403 ma1 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma1);
9404 ma = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma);
9405 ma2 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].res);
9406 ma1 = isl_multi_aff_pullback_multi_aff(ma1, ma);
9407 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
9408 isl_multi_aff_free(ma1);
9409 isl_multi_aff_free(ma2);
9410 if (equal < 0)
9411 return -1;
9412 if (!equal)
9413 isl_die(ctx, isl_error_unknown, "bad pullback",
9414 return -1);
9417 return 0;
9420 /* Check that negation is printed correctly and that equal expressions
9421 * are correctly identified.
9423 static int test_ast(isl_ctx *ctx)
9425 isl_ast_expr *expr, *expr1, *expr2, *expr3;
9426 char *str;
9427 int ok, equal;
9429 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
9430 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
9431 expr = isl_ast_expr_add(expr1, expr2);
9432 expr2 = isl_ast_expr_copy(expr);
9433 expr = isl_ast_expr_neg(expr);
9434 expr2 = isl_ast_expr_neg(expr2);
9435 equal = isl_ast_expr_is_equal(expr, expr2);
9436 str = isl_ast_expr_to_C_str(expr);
9437 ok = str ? !strcmp(str, "-(A + B)") : -1;
9438 free(str);
9439 isl_ast_expr_free(expr);
9440 isl_ast_expr_free(expr2);
9442 if (ok < 0 || equal < 0)
9443 return -1;
9444 if (!equal)
9445 isl_die(ctx, isl_error_unknown,
9446 "equal expressions not considered equal", return -1);
9447 if (!ok)
9448 isl_die(ctx, isl_error_unknown,
9449 "isl_ast_expr printed incorrectly", return -1);
9451 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
9452 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
9453 expr = isl_ast_expr_add(expr1, expr2);
9454 expr3 = isl_ast_expr_from_id(isl_id_alloc(ctx, "C", NULL));
9455 expr = isl_ast_expr_sub(expr3, expr);
9456 str = isl_ast_expr_to_C_str(expr);
9457 ok = str ? !strcmp(str, "C - (A + B)") : -1;
9458 free(str);
9459 isl_ast_expr_free(expr);
9461 if (ok < 0)
9462 return -1;
9463 if (!ok)
9464 isl_die(ctx, isl_error_unknown,
9465 "isl_ast_expr printed incorrectly", return -1);
9467 return 0;
9470 /* Check that isl_ast_build_expr_from_set returns a valid expression
9471 * for an empty set. Note that isl_ast_build_expr_from_set getting
9472 * called on an empty set probably indicates a bug in the caller.
9474 static int test_ast_build(isl_ctx *ctx)
9476 isl_set *set;
9477 isl_ast_build *build;
9478 isl_ast_expr *expr;
9480 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9481 build = isl_ast_build_from_context(set);
9483 set = isl_set_empty(isl_space_params_alloc(ctx, 0));
9484 expr = isl_ast_build_expr_from_set(build, set);
9486 isl_ast_expr_free(expr);
9487 isl_ast_build_free(build);
9489 if (!expr)
9490 return -1;
9492 return 0;
9495 /* Internal data structure for before_for and after_for callbacks.
9497 * depth is the current depth
9498 * before is the number of times before_for has been called
9499 * after is the number of times after_for has been called
9501 struct isl_test_codegen_data {
9502 int depth;
9503 int before;
9504 int after;
9507 /* This function is called before each for loop in the AST generated
9508 * from test_ast_gen1.
9510 * Increment the number of calls and the depth.
9511 * Check that the space returned by isl_ast_build_get_schedule_space
9512 * matches the target space of the schedule returned by
9513 * isl_ast_build_get_schedule.
9514 * Return an isl_id that is checked by the corresponding call
9515 * to after_for.
9517 static __isl_give isl_id *before_for(__isl_keep isl_ast_build *build,
9518 void *user)
9520 struct isl_test_codegen_data *data = user;
9521 isl_ctx *ctx;
9522 isl_space *space;
9523 isl_union_map *schedule;
9524 isl_union_set *uset;
9525 isl_set *set;
9526 isl_bool empty;
9527 isl_size n;
9528 char name[] = "d0";
9530 ctx = isl_ast_build_get_ctx(build);
9532 if (data->before >= 3)
9533 isl_die(ctx, isl_error_unknown,
9534 "unexpected number of for nodes", return NULL);
9535 if (data->depth < 0 || data->depth >= 2)
9536 isl_die(ctx, isl_error_unknown,
9537 "unexpected depth", return NULL);
9539 snprintf(name, sizeof(name), "d%d", data->depth);
9540 data->before++;
9541 data->depth++;
9543 schedule = isl_ast_build_get_schedule(build);
9544 uset = isl_union_map_range(schedule);
9545 n = isl_union_set_n_set(uset);
9546 if (n != 1) {
9547 isl_union_set_free(uset);
9548 if (n < 0)
9549 return NULL;
9550 isl_die(ctx, isl_error_unknown,
9551 "expecting single range space", return NULL);
9554 space = isl_ast_build_get_schedule_space(build);
9555 set = isl_union_set_extract_set(uset, space);
9556 isl_union_set_free(uset);
9557 empty = isl_set_is_empty(set);
9558 isl_set_free(set);
9560 if (empty < 0)
9561 return NULL;
9562 if (empty)
9563 isl_die(ctx, isl_error_unknown,
9564 "spaces don't match", return NULL);
9566 return isl_id_alloc(ctx, name, NULL);
9569 /* This function is called after each for loop in the AST generated
9570 * from test_ast_gen1.
9572 * Increment the number of calls and decrement the depth.
9573 * Check that the annotation attached to the node matches
9574 * the isl_id returned by the corresponding call to before_for.
9576 static __isl_give isl_ast_node *after_for(__isl_take isl_ast_node *node,
9577 __isl_keep isl_ast_build *build, void *user)
9579 struct isl_test_codegen_data *data = user;
9580 isl_id *id;
9581 const char *name;
9582 int valid;
9584 data->after++;
9585 data->depth--;
9587 if (data->after > data->before)
9588 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
9589 "mismatch in number of for nodes",
9590 return isl_ast_node_free(node));
9592 id = isl_ast_node_get_annotation(node);
9593 if (!id)
9594 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
9595 "missing annotation", return isl_ast_node_free(node));
9597 name = isl_id_get_name(id);
9598 valid = name && atoi(name + 1) == data->depth;
9599 isl_id_free(id);
9601 if (!valid)
9602 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
9603 "wrong annotation", return isl_ast_node_free(node));
9605 return node;
9608 /* Check that the before_each_for and after_each_for callbacks
9609 * are called for each for loop in the generated code,
9610 * that they are called in the right order and that the isl_id
9611 * returned from the before_each_for callback is attached to
9612 * the isl_ast_node passed to the corresponding after_each_for call.
9614 static int test_ast_gen1(isl_ctx *ctx)
9616 const char *str;
9617 isl_set *set;
9618 isl_union_map *schedule;
9619 isl_ast_build *build;
9620 isl_ast_node *tree;
9621 struct isl_test_codegen_data data;
9623 str = "[N] -> { : N >= 10 }";
9624 set = isl_set_read_from_str(ctx, str);
9625 str = "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
9626 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
9627 schedule = isl_union_map_read_from_str(ctx, str);
9629 data.before = 0;
9630 data.after = 0;
9631 data.depth = 0;
9632 build = isl_ast_build_from_context(set);
9633 build = isl_ast_build_set_before_each_for(build,
9634 &before_for, &data);
9635 build = isl_ast_build_set_after_each_for(build,
9636 &after_for, &data);
9637 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9638 isl_ast_build_free(build);
9639 if (!tree)
9640 return -1;
9642 isl_ast_node_free(tree);
9644 if (data.before != 3 || data.after != 3)
9645 isl_die(ctx, isl_error_unknown,
9646 "unexpected number of for nodes", return -1);
9648 return 0;
9651 /* Check that the AST generator handles domains that are integrally disjoint
9652 * but not rationally disjoint.
9654 static int test_ast_gen2(isl_ctx *ctx)
9656 const char *str;
9657 isl_set *set;
9658 isl_union_map *schedule;
9659 isl_union_map *options;
9660 isl_ast_build *build;
9661 isl_ast_node *tree;
9663 str = "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
9664 schedule = isl_union_map_read_from_str(ctx, str);
9665 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9666 build = isl_ast_build_from_context(set);
9668 str = "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
9669 options = isl_union_map_read_from_str(ctx, str);
9670 build = isl_ast_build_set_options(build, options);
9671 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9672 isl_ast_build_free(build);
9673 if (!tree)
9674 return -1;
9675 isl_ast_node_free(tree);
9677 return 0;
9680 /* Increment *user on each call.
9682 static __isl_give isl_ast_node *count_domains(__isl_take isl_ast_node *node,
9683 __isl_keep isl_ast_build *build, void *user)
9685 int *n = user;
9687 (*n)++;
9689 return node;
9692 /* Test that unrolling tries to minimize the number of instances.
9693 * In particular, for the schedule given below, make sure it generates
9694 * 3 nodes (rather than 101).
9696 static int test_ast_gen3(isl_ctx *ctx)
9698 const char *str;
9699 isl_set *set;
9700 isl_union_map *schedule;
9701 isl_union_map *options;
9702 isl_ast_build *build;
9703 isl_ast_node *tree;
9704 int n_domain = 0;
9706 str = "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
9707 schedule = isl_union_map_read_from_str(ctx, str);
9708 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9710 str = "{ [i] -> unroll[0] }";
9711 options = isl_union_map_read_from_str(ctx, str);
9713 build = isl_ast_build_from_context(set);
9714 build = isl_ast_build_set_options(build, options);
9715 build = isl_ast_build_set_at_each_domain(build,
9716 &count_domains, &n_domain);
9717 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9718 isl_ast_build_free(build);
9719 if (!tree)
9720 return -1;
9722 isl_ast_node_free(tree);
9724 if (n_domain != 3)
9725 isl_die(ctx, isl_error_unknown,
9726 "unexpected number of for nodes", return -1);
9728 return 0;
9731 /* Check that if the ast_build_exploit_nested_bounds options is set,
9732 * we do not get an outer if node in the generated AST,
9733 * while we do get such an outer if node if the options is not set.
9735 static int test_ast_gen4(isl_ctx *ctx)
9737 const char *str;
9738 isl_set *set;
9739 isl_union_map *schedule;
9740 isl_ast_build *build;
9741 isl_ast_node *tree;
9742 enum isl_ast_node_type type;
9743 int enb;
9745 enb = isl_options_get_ast_build_exploit_nested_bounds(ctx);
9746 str = "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
9748 isl_options_set_ast_build_exploit_nested_bounds(ctx, 1);
9750 schedule = isl_union_map_read_from_str(ctx, str);
9751 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9752 build = isl_ast_build_from_context(set);
9753 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9754 isl_ast_build_free(build);
9755 if (!tree)
9756 return -1;
9758 type = isl_ast_node_get_type(tree);
9759 isl_ast_node_free(tree);
9761 if (type == isl_ast_node_if)
9762 isl_die(ctx, isl_error_unknown,
9763 "not expecting if node", return -1);
9765 isl_options_set_ast_build_exploit_nested_bounds(ctx, 0);
9767 schedule = isl_union_map_read_from_str(ctx, str);
9768 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9769 build = isl_ast_build_from_context(set);
9770 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9771 isl_ast_build_free(build);
9772 if (!tree)
9773 return -1;
9775 type = isl_ast_node_get_type(tree);
9776 isl_ast_node_free(tree);
9778 if (type != isl_ast_node_if)
9779 isl_die(ctx, isl_error_unknown,
9780 "expecting if node", return -1);
9782 isl_options_set_ast_build_exploit_nested_bounds(ctx, enb);
9784 return 0;
9787 /* This function is called for each leaf in the AST generated
9788 * from test_ast_gen5.
9790 * We finalize the AST generation by extending the outer schedule
9791 * with a zero-dimensional schedule. If this results in any for loops,
9792 * then this means that we did not pass along enough information
9793 * about the outer schedule to the inner AST generation.
9795 static __isl_give isl_ast_node *create_leaf(__isl_take isl_ast_build *build,
9796 void *user)
9798 isl_union_map *schedule, *extra;
9799 isl_ast_node *tree;
9801 schedule = isl_ast_build_get_schedule(build);
9802 extra = isl_union_map_copy(schedule);
9803 extra = isl_union_map_from_domain(isl_union_map_domain(extra));
9804 schedule = isl_union_map_range_product(schedule, extra);
9805 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9806 isl_ast_build_free(build);
9808 if (!tree)
9809 return NULL;
9811 if (isl_ast_node_get_type(tree) == isl_ast_node_for)
9812 isl_die(isl_ast_node_get_ctx(tree), isl_error_unknown,
9813 "code should not contain any for loop",
9814 return isl_ast_node_free(tree));
9816 return tree;
9819 /* Check that we do not lose any information when going back and
9820 * forth between internal and external schedule.
9822 * In particular, we create an AST where we unroll the only
9823 * non-constant dimension in the schedule. We therefore do
9824 * not expect any for loops in the AST. However, older versions
9825 * of isl would not pass along enough information about the outer
9826 * schedule when performing an inner code generation from a create_leaf
9827 * callback, resulting in the inner code generation producing a for loop.
9829 static int test_ast_gen5(isl_ctx *ctx)
9831 const char *str;
9832 isl_set *set;
9833 isl_union_map *schedule, *options;
9834 isl_ast_build *build;
9835 isl_ast_node *tree;
9837 str = "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
9838 schedule = isl_union_map_read_from_str(ctx, str);
9840 str = "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
9841 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
9842 options = isl_union_map_read_from_str(ctx, str);
9844 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9845 build = isl_ast_build_from_context(set);
9846 build = isl_ast_build_set_options(build, options);
9847 build = isl_ast_build_set_create_leaf(build, &create_leaf, NULL);
9848 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9849 isl_ast_build_free(build);
9850 isl_ast_node_free(tree);
9851 if (!tree)
9852 return -1;
9854 return 0;
9857 /* Check that the expression
9859 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
9861 * is not combined into
9863 * min(n/2, 0)
9865 * as this would result in n/2 being evaluated in parts of
9866 * the definition domain where n is not a multiple of 2.
9868 static int test_ast_expr(isl_ctx *ctx)
9870 const char *str;
9871 isl_pw_aff *pa;
9872 isl_ast_build *build;
9873 isl_ast_expr *expr;
9874 int min_max;
9875 int is_min;
9877 min_max = isl_options_get_ast_build_detect_min_max(ctx);
9878 isl_options_set_ast_build_detect_min_max(ctx, 1);
9880 str = "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
9881 pa = isl_pw_aff_read_from_str(ctx, str);
9882 build = isl_ast_build_alloc(ctx);
9883 expr = isl_ast_build_expr_from_pw_aff(build, pa);
9884 is_min = isl_ast_expr_get_type(expr) == isl_ast_expr_op &&
9885 isl_ast_expr_get_op_type(expr) == isl_ast_expr_op_min;
9886 isl_ast_build_free(build);
9887 isl_ast_expr_free(expr);
9889 isl_options_set_ast_build_detect_min_max(ctx, min_max);
9891 if (!expr)
9892 return -1;
9893 if (is_min)
9894 isl_die(ctx, isl_error_unknown,
9895 "expressions should not be combined", return -1);
9897 return 0;
9900 static int test_ast_gen(isl_ctx *ctx)
9902 if (test_ast_gen1(ctx) < 0)
9903 return -1;
9904 if (test_ast_gen2(ctx) < 0)
9905 return -1;
9906 if (test_ast_gen3(ctx) < 0)
9907 return -1;
9908 if (test_ast_gen4(ctx) < 0)
9909 return -1;
9910 if (test_ast_gen5(ctx) < 0)
9911 return -1;
9912 if (test_ast_expr(ctx) < 0)
9913 return -1;
9914 return 0;
9917 /* Check if dropping output dimensions from an isl_pw_multi_aff
9918 * works properly.
9920 static int test_pw_multi_aff(isl_ctx *ctx)
9922 const char *str;
9923 isl_pw_multi_aff *pma1, *pma2;
9924 int equal;
9926 str = "{ [i,j] -> [i+j, 4i-j] }";
9927 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
9928 str = "{ [i,j] -> [4i-j] }";
9929 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
9931 pma1 = isl_pw_multi_aff_drop_dims(pma1, isl_dim_out, 0, 1);
9933 equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
9935 isl_pw_multi_aff_free(pma1);
9936 isl_pw_multi_aff_free(pma2);
9937 if (equal < 0)
9938 return -1;
9939 if (!equal)
9940 isl_die(ctx, isl_error_unknown,
9941 "expressions not equal", return -1);
9943 return 0;
9946 /* Check that we can properly parse multi piecewise affine expressions
9947 * where the piecewise affine expressions have different domains.
9949 static int test_multi_pw_aff_1(isl_ctx *ctx)
9951 const char *str;
9952 isl_set *dom, *dom2;
9953 isl_multi_pw_aff *mpa1, *mpa2;
9954 isl_pw_aff *pa;
9955 int equal;
9956 int equal_domain;
9958 mpa1 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [i] }");
9959 dom = isl_set_read_from_str(ctx, "{ [i] : i > 0 }");
9960 mpa1 = isl_multi_pw_aff_intersect_domain(mpa1, dom);
9961 mpa2 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [2i] }");
9962 mpa2 = isl_multi_pw_aff_flat_range_product(mpa1, mpa2);
9963 str = "{ [i] -> [(i : i > 0), 2i] }";
9964 mpa1 = isl_multi_pw_aff_read_from_str(ctx, str);
9966 equal = isl_multi_pw_aff_plain_is_equal(mpa1, mpa2);
9968 pa = isl_multi_pw_aff_get_pw_aff(mpa1, 0);
9969 dom = isl_pw_aff_domain(pa);
9970 pa = isl_multi_pw_aff_get_pw_aff(mpa1, 1);
9971 dom2 = isl_pw_aff_domain(pa);
9972 equal_domain = isl_set_is_equal(dom, dom2);
9974 isl_set_free(dom);
9975 isl_set_free(dom2);
9976 isl_multi_pw_aff_free(mpa1);
9977 isl_multi_pw_aff_free(mpa2);
9979 if (equal < 0)
9980 return -1;
9981 if (!equal)
9982 isl_die(ctx, isl_error_unknown,
9983 "expressions not equal", return -1);
9985 if (equal_domain < 0)
9986 return -1;
9987 if (equal_domain)
9988 isl_die(ctx, isl_error_unknown,
9989 "domains unexpectedly equal", return -1);
9991 return 0;
9994 /* Check that the dimensions in the explicit domain
9995 * of a multi piecewise affine expression are properly
9996 * taken into account.
9998 static int test_multi_pw_aff_2(isl_ctx *ctx)
10000 const char *str;
10001 isl_bool involves1, involves2, involves3, equal;
10002 isl_multi_pw_aff *mpa, *mpa1, *mpa2;
10004 str = "{ A[x,y] -> B[] : x >= y }";
10005 mpa = isl_multi_pw_aff_read_from_str(ctx, str);
10006 involves1 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 2);
10007 mpa1 = isl_multi_pw_aff_copy(mpa);
10009 mpa = isl_multi_pw_aff_insert_dims(mpa, isl_dim_in, 0, 1);
10010 involves2 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 1);
10011 involves3 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 1, 2);
10012 str = "{ [a,x,y] -> B[] : x >= y }";
10013 mpa2 = isl_multi_pw_aff_read_from_str(ctx, str);
10014 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2);
10015 isl_multi_pw_aff_free(mpa2);
10017 mpa = isl_multi_pw_aff_drop_dims(mpa, isl_dim_in, 0, 1);
10018 mpa = isl_multi_pw_aff_set_tuple_name(mpa, isl_dim_in, "A");
10019 if (equal >= 0 && equal)
10020 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa1);
10021 isl_multi_pw_aff_free(mpa1);
10022 isl_multi_pw_aff_free(mpa);
10024 if (involves1 < 0 || involves2 < 0 || involves3 < 0 || equal < 0)
10025 return -1;
10026 if (!equal)
10027 isl_die(ctx, isl_error_unknown,
10028 "incorrect result of dimension insertion/removal",
10029 return isl_stat_error);
10030 if (!involves1 || involves2 || !involves3)
10031 isl_die(ctx, isl_error_unknown,
10032 "incorrect characterization of involved dimensions",
10033 return isl_stat_error);
10035 return 0;
10038 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
10039 * sets the explicit domain of a zero-dimensional result,
10040 * such that it can be converted to an isl_union_map.
10042 static isl_stat test_multi_pw_aff_3(isl_ctx *ctx)
10044 isl_space *space;
10045 isl_union_set *dom;
10046 isl_multi_val *mv;
10047 isl_multi_union_pw_aff *mupa;
10048 isl_union_map *umap;
10050 dom = isl_union_set_read_from_str(ctx, "{ A[]; B[] }");
10051 space = isl_union_set_get_space(dom);
10052 mv = isl_multi_val_zero(isl_space_set_from_params(space));
10053 mupa = isl_multi_union_pw_aff_multi_val_on_domain(dom, mv);
10054 umap = isl_union_map_from_multi_union_pw_aff(mupa);
10055 isl_union_map_free(umap);
10056 if (!umap)
10057 return isl_stat_error;
10059 return isl_stat_ok;
10062 /* String descriptions of boxes that
10063 * are used for reconstructing box maps from their lower and upper bounds.
10065 static const char *multi_pw_aff_box_tests[] = {
10066 "{ A[x, y] -> [] : x + y >= 0 }",
10067 "[N] -> { A[x, y] -> [x] : x + y <= N }",
10068 "[N] -> { A[x, y] -> [x : y] : x + y <= N }",
10071 /* Check that map representations of boxes can be reconstructed
10072 * from their lower and upper bounds.
10074 static isl_stat test_multi_pw_aff_box(isl_ctx *ctx)
10076 int i;
10078 for (i = 0; i < ARRAY_SIZE(multi_pw_aff_box_tests); ++i) {
10079 const char *str;
10080 isl_bool equal;
10081 isl_map *map, *box;
10082 isl_multi_pw_aff *min, *max;
10084 str = multi_pw_aff_box_tests[i];
10085 map = isl_map_read_from_str(ctx, str);
10086 min = isl_map_min_multi_pw_aff(isl_map_copy(map));
10087 max = isl_map_max_multi_pw_aff(isl_map_copy(map));
10088 box = isl_map_universe(isl_map_get_space(map));
10089 box = isl_map_lower_bound_multi_pw_aff(box, min);
10090 box = isl_map_upper_bound_multi_pw_aff(box, max);
10091 equal = isl_map_is_equal(map, box);
10092 isl_map_free(map);
10093 isl_map_free(box);
10094 if (equal < 0)
10095 return isl_stat_error;
10096 if (!equal)
10097 isl_die(ctx, isl_error_unknown,
10098 "unexpected result", return isl_stat_error);
10101 return isl_stat_ok;
10104 /* Perform some tests on multi piecewise affine expressions.
10106 static int test_multi_pw_aff(isl_ctx *ctx)
10108 if (test_multi_pw_aff_1(ctx) < 0)
10109 return -1;
10110 if (test_multi_pw_aff_2(ctx) < 0)
10111 return -1;
10112 if (test_multi_pw_aff_3(ctx) < 0)
10113 return -1;
10114 if (test_multi_pw_aff_box(ctx) < 0)
10115 return -1;
10116 return 0;
10119 /* This is a regression test for a bug where isl_basic_map_simplify
10120 * would end up in an infinite loop. In particular, we construct
10121 * an empty basic set that is not obviously empty.
10122 * isl_basic_set_is_empty marks the basic set as empty.
10123 * After projecting out i3, the variable can be dropped completely,
10124 * but isl_basic_map_simplify refrains from doing so if the basic set
10125 * is empty and would end up in an infinite loop if it didn't test
10126 * explicitly for empty basic maps in the outer loop.
10128 static int test_simplify_1(isl_ctx *ctx)
10130 const char *str;
10131 isl_basic_set *bset;
10132 int empty;
10134 str = "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
10135 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
10136 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
10137 "i3 >= i2 }";
10138 bset = isl_basic_set_read_from_str(ctx, str);
10139 empty = isl_basic_set_is_empty(bset);
10140 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
10141 isl_basic_set_free(bset);
10142 if (!bset)
10143 return -1;
10144 if (!empty)
10145 isl_die(ctx, isl_error_unknown,
10146 "basic set should be empty", return -1);
10148 return 0;
10151 /* Check that the equality in the set description below
10152 * is simplified away.
10154 static int test_simplify_2(isl_ctx *ctx)
10156 const char *str;
10157 isl_basic_set *bset;
10158 isl_bool universe;
10160 str = "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
10161 bset = isl_basic_set_read_from_str(ctx, str);
10162 universe = isl_basic_set_plain_is_universe(bset);
10163 isl_basic_set_free(bset);
10165 if (universe < 0)
10166 return -1;
10167 if (!universe)
10168 isl_die(ctx, isl_error_unknown,
10169 "equality not simplified away", return -1);
10170 return 0;
10173 /* Some simplification tests.
10175 static int test_simplify(isl_ctx *ctx)
10177 if (test_simplify_1(ctx) < 0)
10178 return -1;
10179 if (test_simplify_2(ctx) < 0)
10180 return -1;
10181 return 0;
10184 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
10185 * with gbr context would fail to disable the use of the shifted tableau
10186 * when transferring equalities for the input to the context, resulting
10187 * in invalid sample values.
10189 static int test_partial_lexmin(isl_ctx *ctx)
10191 const char *str;
10192 isl_basic_set *bset;
10193 isl_basic_map *bmap;
10194 isl_map *map;
10196 str = "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
10197 bmap = isl_basic_map_read_from_str(ctx, str);
10198 str = "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
10199 bset = isl_basic_set_read_from_str(ctx, str);
10200 map = isl_basic_map_partial_lexmin(bmap, bset, NULL);
10201 isl_map_free(map);
10203 if (!map)
10204 return -1;
10206 return 0;
10209 /* Check that the variable compression performed on the existentially
10210 * quantified variables inside isl_basic_set_compute_divs is not confused
10211 * by the implicit equalities among the parameters.
10213 static int test_compute_divs(isl_ctx *ctx)
10215 const char *str;
10216 isl_basic_set *bset;
10217 isl_set *set;
10219 str = "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
10220 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
10221 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
10222 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
10223 bset = isl_basic_set_read_from_str(ctx, str);
10224 set = isl_basic_set_compute_divs(bset);
10225 isl_set_free(set);
10226 if (!set)
10227 return -1;
10229 return 0;
10232 /* Check that isl_schedule_get_map is not confused by a schedule tree
10233 * with divergent filter node parameters, as can result from a call
10234 * to isl_schedule_intersect_domain.
10236 static int test_schedule_tree(isl_ctx *ctx)
10238 const char *str;
10239 isl_union_set *uset;
10240 isl_schedule *sched1, *sched2;
10241 isl_union_map *umap;
10243 uset = isl_union_set_read_from_str(ctx, "{ A[i] }");
10244 sched1 = isl_schedule_from_domain(uset);
10245 uset = isl_union_set_read_from_str(ctx, "{ B[] }");
10246 sched2 = isl_schedule_from_domain(uset);
10248 sched1 = isl_schedule_sequence(sched1, sched2);
10249 str = "[n] -> { A[i] : 0 <= i < n; B[] }";
10250 uset = isl_union_set_read_from_str(ctx, str);
10251 sched1 = isl_schedule_intersect_domain(sched1, uset);
10252 umap = isl_schedule_get_map(sched1);
10253 isl_schedule_free(sched1);
10254 isl_union_map_free(umap);
10255 if (!umap)
10256 return -1;
10258 return 0;
10261 /* Check that a zero-dimensional prefix schedule keeps track
10262 * of the domain and outer filters.
10264 static int test_schedule_tree_prefix(isl_ctx *ctx)
10266 const char *str;
10267 isl_bool equal;
10268 isl_union_set *uset;
10269 isl_union_set_list *filters;
10270 isl_multi_union_pw_aff *mupa, *mupa2;
10271 isl_schedule_node *node;
10273 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10274 uset = isl_union_set_read_from_str(ctx, str);
10275 node = isl_schedule_node_from_domain(uset);
10276 node = isl_schedule_node_child(node, 0);
10278 str = "{ S1[i,j] : i > j }";
10279 uset = isl_union_set_read_from_str(ctx, str);
10280 filters = isl_union_set_list_from_union_set(uset);
10281 str = "{ S1[i,j] : i <= j; S2[i,j] }";
10282 uset = isl_union_set_read_from_str(ctx, str);
10283 filters = isl_union_set_list_add(filters, uset);
10284 node = isl_schedule_node_insert_sequence(node, filters);
10286 node = isl_schedule_node_child(node, 0);
10287 node = isl_schedule_node_child(node, 0);
10288 mupa = isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node);
10289 str = "([] : { S1[i,j] : i > j })";
10290 mupa2 = isl_multi_union_pw_aff_read_from_str(ctx, str);
10291 equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2);
10292 isl_multi_union_pw_aff_free(mupa2);
10293 isl_multi_union_pw_aff_free(mupa);
10294 isl_schedule_node_free(node);
10296 if (equal < 0)
10297 return -1;
10298 if (!equal)
10299 isl_die(ctx, isl_error_unknown, "unexpected prefix schedule",
10300 return -1);
10302 return 0;
10305 /* Check that the reaching domain elements and the prefix schedule
10306 * at a leaf node are the same before and after grouping.
10308 static int test_schedule_tree_group_1(isl_ctx *ctx)
10310 int equal;
10311 const char *str;
10312 isl_id *id;
10313 isl_union_set *uset;
10314 isl_multi_union_pw_aff *mupa;
10315 isl_union_pw_multi_aff *upma1, *upma2;
10316 isl_union_set *domain1, *domain2;
10317 isl_union_map *umap1, *umap2;
10318 isl_schedule_node *node;
10320 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10321 uset = isl_union_set_read_from_str(ctx, str);
10322 node = isl_schedule_node_from_domain(uset);
10323 node = isl_schedule_node_child(node, 0);
10324 str = "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
10325 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10326 node = isl_schedule_node_insert_partial_schedule(node, mupa);
10327 node = isl_schedule_node_child(node, 0);
10328 str = "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
10329 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10330 node = isl_schedule_node_insert_partial_schedule(node, mupa);
10331 node = isl_schedule_node_child(node, 0);
10332 umap1 = isl_schedule_node_get_prefix_schedule_union_map(node);
10333 upma1 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node);
10334 domain1 = isl_schedule_node_get_domain(node);
10335 id = isl_id_alloc(ctx, "group", NULL);
10336 node = isl_schedule_node_parent(node);
10337 node = isl_schedule_node_group(node, id);
10338 node = isl_schedule_node_child(node, 0);
10339 umap2 = isl_schedule_node_get_prefix_schedule_union_map(node);
10340 upma2 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node);
10341 domain2 = isl_schedule_node_get_domain(node);
10342 equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2);
10343 if (equal >= 0 && equal)
10344 equal = isl_union_set_is_equal(domain1, domain2);
10345 if (equal >= 0 && equal)
10346 equal = isl_union_map_is_equal(umap1, umap2);
10347 isl_union_map_free(umap1);
10348 isl_union_map_free(umap2);
10349 isl_union_set_free(domain1);
10350 isl_union_set_free(domain2);
10351 isl_union_pw_multi_aff_free(upma1);
10352 isl_union_pw_multi_aff_free(upma2);
10353 isl_schedule_node_free(node);
10355 if (equal < 0)
10356 return -1;
10357 if (!equal)
10358 isl_die(ctx, isl_error_unknown,
10359 "expressions not equal", return -1);
10361 return 0;
10364 /* Check that we can have nested groupings and that the union map
10365 * schedule representation is the same before and after the grouping.
10366 * Note that after the grouping, the union map representation contains
10367 * the domain constraints from the ranges of the expansion nodes,
10368 * while they are missing from the union map representation of
10369 * the tree without expansion nodes.
10371 * Also check that the global expansion is as expected.
10373 static int test_schedule_tree_group_2(isl_ctx *ctx)
10375 int equal, equal_expansion;
10376 const char *str;
10377 isl_id *id;
10378 isl_union_set *uset;
10379 isl_union_map *umap1, *umap2;
10380 isl_union_map *expansion1, *expansion2;
10381 isl_union_set_list *filters;
10382 isl_multi_union_pw_aff *mupa;
10383 isl_schedule *schedule;
10384 isl_schedule_node *node;
10386 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
10387 "S3[i,j] : 0 <= i,j < 10 }";
10388 uset = isl_union_set_read_from_str(ctx, str);
10389 node = isl_schedule_node_from_domain(uset);
10390 node = isl_schedule_node_child(node, 0);
10391 str = "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
10392 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10393 node = isl_schedule_node_insert_partial_schedule(node, mupa);
10394 node = isl_schedule_node_child(node, 0);
10395 str = "{ S1[i,j] }";
10396 uset = isl_union_set_read_from_str(ctx, str);
10397 filters = isl_union_set_list_from_union_set(uset);
10398 str = "{ S2[i,j]; S3[i,j] }";
10399 uset = isl_union_set_read_from_str(ctx, str);
10400 filters = isl_union_set_list_add(filters, uset);
10401 node = isl_schedule_node_insert_sequence(node, filters);
10402 node = isl_schedule_node_child(node, 1);
10403 node = isl_schedule_node_child(node, 0);
10404 str = "{ S2[i,j] }";
10405 uset = isl_union_set_read_from_str(ctx, str);
10406 filters = isl_union_set_list_from_union_set(uset);
10407 str = "{ S3[i,j] }";
10408 uset = isl_union_set_read_from_str(ctx, str);
10409 filters = isl_union_set_list_add(filters, uset);
10410 node = isl_schedule_node_insert_sequence(node, filters);
10412 schedule = isl_schedule_node_get_schedule(node);
10413 umap1 = isl_schedule_get_map(schedule);
10414 uset = isl_schedule_get_domain(schedule);
10415 umap1 = isl_union_map_intersect_domain(umap1, uset);
10416 isl_schedule_free(schedule);
10418 node = isl_schedule_node_parent(node);
10419 node = isl_schedule_node_parent(node);
10420 id = isl_id_alloc(ctx, "group1", NULL);
10421 node = isl_schedule_node_group(node, id);
10422 node = isl_schedule_node_child(node, 1);
10423 node = isl_schedule_node_child(node, 0);
10424 id = isl_id_alloc(ctx, "group2", NULL);
10425 node = isl_schedule_node_group(node, id);
10427 schedule = isl_schedule_node_get_schedule(node);
10428 umap2 = isl_schedule_get_map(schedule);
10429 isl_schedule_free(schedule);
10431 node = isl_schedule_node_root(node);
10432 node = isl_schedule_node_child(node, 0);
10433 expansion1 = isl_schedule_node_get_subtree_expansion(node);
10434 isl_schedule_node_free(node);
10436 str = "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
10437 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
10438 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
10440 expansion2 = isl_union_map_read_from_str(ctx, str);
10442 equal = isl_union_map_is_equal(umap1, umap2);
10443 equal_expansion = isl_union_map_is_equal(expansion1, expansion2);
10445 isl_union_map_free(umap1);
10446 isl_union_map_free(umap2);
10447 isl_union_map_free(expansion1);
10448 isl_union_map_free(expansion2);
10450 if (equal < 0 || equal_expansion < 0)
10451 return -1;
10452 if (!equal)
10453 isl_die(ctx, isl_error_unknown,
10454 "expressions not equal", return -1);
10455 if (!equal_expansion)
10456 isl_die(ctx, isl_error_unknown,
10457 "unexpected expansion", return -1);
10459 return 0;
10462 /* Some tests for the isl_schedule_node_group function.
10464 static int test_schedule_tree_group(isl_ctx *ctx)
10466 if (test_schedule_tree_group_1(ctx) < 0)
10467 return -1;
10468 if (test_schedule_tree_group_2(ctx) < 0)
10469 return -1;
10470 return 0;
10473 struct {
10474 const char *set;
10475 const char *dual;
10476 } coef_tests[] = {
10477 { "{ rat: [i] : 0 <= i <= 10 }",
10478 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
10479 { "{ rat: [i] : FALSE }",
10480 "{ rat: coefficients[[cst] -> [a]] }" },
10481 { "{ rat: [i] : }",
10482 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
10483 { "{ [0:,1,2:3] }",
10484 "{ rat: coefficients[[c_cst] -> [a, b, c]] : "
10485 "a >= 0 and 2c >= -c_cst - b and 3c >= -c_cst - b }" },
10486 { "[M, N] -> { [x = (1 - N):-1, -4x:(M - 4x)] }",
10487 "{ rat: coefficients[[c_cst, c_M = 0:, c_N = 0:] -> [a, b = -c_M:]] :"
10488 "4b >= -c_N + a and 4b >= -c_cst - 2c_N + a }" },
10489 { "{ rat : [x, y] : 1 <= 2x <= 9 and 2 <= 3y <= 16 }",
10490 "{ rat: coefficients[[c_cst] -> [c_x, c_y]] : "
10491 "4c_y >= -6c_cst - 3c_x and 4c_y >= -6c_cst - 27c_x and "
10492 "32c_y >= -6c_cst - 3c_x and 32c_y >= -6c_cst - 27c_x }" },
10493 { "{ [x, y, z] : 3y <= 2x - 2 and y >= -2 + 2x and 2y >= 2 - x }",
10494 "{ rat: coefficients[[cst] -> [a, b, c]] }" },
10497 struct {
10498 const char *set;
10499 const char *dual;
10500 } sol_tests[] = {
10501 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
10502 "{ rat: [i] : 0 <= i <= 10 }" },
10503 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
10504 "{ rat: [i] }" },
10505 { "{ rat: coefficients[[cst] -> [a]] }",
10506 "{ rat: [i] : FALSE }" },
10509 /* Test the basic functionality of isl_basic_set_coefficients and
10510 * isl_basic_set_solutions.
10512 static int test_dual(isl_ctx *ctx)
10514 int i;
10516 for (i = 0; i < ARRAY_SIZE(coef_tests); ++i) {
10517 int equal;
10518 isl_basic_set *bset1, *bset2;
10520 bset1 = isl_basic_set_read_from_str(ctx, coef_tests[i].set);
10521 bset2 = isl_basic_set_read_from_str(ctx, coef_tests[i].dual);
10522 bset1 = isl_basic_set_coefficients(bset1);
10523 equal = isl_basic_set_is_equal(bset1, bset2);
10524 isl_basic_set_free(bset1);
10525 isl_basic_set_free(bset2);
10526 if (equal < 0)
10527 return -1;
10528 if (!equal)
10529 isl_die(ctx, isl_error_unknown,
10530 "incorrect dual", return -1);
10533 for (i = 0; i < ARRAY_SIZE(sol_tests); ++i) {
10534 int equal;
10535 isl_basic_set *bset1, *bset2;
10537 bset1 = isl_basic_set_read_from_str(ctx, sol_tests[i].set);
10538 bset2 = isl_basic_set_read_from_str(ctx, sol_tests[i].dual);
10539 bset1 = isl_basic_set_solutions(bset1);
10540 equal = isl_basic_set_is_equal(bset1, bset2);
10541 isl_basic_set_free(bset1);
10542 isl_basic_set_free(bset2);
10543 if (equal < 0)
10544 return -1;
10545 if (!equal)
10546 isl_die(ctx, isl_error_unknown,
10547 "incorrect dual", return -1);
10550 return 0;
10553 struct {
10554 int scale_tile;
10555 int shift_point;
10556 const char *domain;
10557 const char *schedule;
10558 const char *sizes;
10559 const char *tile;
10560 const char *point;
10561 } tile_tests[] = {
10562 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10563 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10564 "{ [32,32] }",
10565 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10566 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10568 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10569 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10570 "{ [32,32] }",
10571 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10572 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10574 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10575 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10576 "{ [32,32] }",
10577 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10578 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10580 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10581 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10582 "{ [32,32] }",
10583 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10584 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10588 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
10589 * tile the band and then check if the tile and point bands have the
10590 * expected partial schedule.
10592 static int test_tile(isl_ctx *ctx)
10594 int i;
10595 int scale;
10596 int shift;
10598 scale = isl_options_get_tile_scale_tile_loops(ctx);
10599 shift = isl_options_get_tile_shift_point_loops(ctx);
10601 for (i = 0; i < ARRAY_SIZE(tile_tests); ++i) {
10602 int opt;
10603 int equal;
10604 const char *str;
10605 isl_union_set *domain;
10606 isl_multi_union_pw_aff *mupa, *mupa2;
10607 isl_schedule_node *node;
10608 isl_multi_val *sizes;
10610 opt = tile_tests[i].scale_tile;
10611 isl_options_set_tile_scale_tile_loops(ctx, opt);
10612 opt = tile_tests[i].shift_point;
10613 isl_options_set_tile_shift_point_loops(ctx, opt);
10615 str = tile_tests[i].domain;
10616 domain = isl_union_set_read_from_str(ctx, str);
10617 node = isl_schedule_node_from_domain(domain);
10618 node = isl_schedule_node_child(node, 0);
10619 str = tile_tests[i].schedule;
10620 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10621 node = isl_schedule_node_insert_partial_schedule(node, mupa);
10622 str = tile_tests[i].sizes;
10623 sizes = isl_multi_val_read_from_str(ctx, str);
10624 node = isl_schedule_node_band_tile(node, sizes);
10626 str = tile_tests[i].tile;
10627 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10628 mupa2 = isl_schedule_node_band_get_partial_schedule(node);
10629 equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2);
10630 isl_multi_union_pw_aff_free(mupa);
10631 isl_multi_union_pw_aff_free(mupa2);
10633 node = isl_schedule_node_child(node, 0);
10635 str = tile_tests[i].point;
10636 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10637 mupa2 = isl_schedule_node_band_get_partial_schedule(node);
10638 if (equal >= 0 && equal)
10639 equal = isl_multi_union_pw_aff_plain_is_equal(mupa,
10640 mupa2);
10641 isl_multi_union_pw_aff_free(mupa);
10642 isl_multi_union_pw_aff_free(mupa2);
10644 isl_schedule_node_free(node);
10646 if (equal < 0)
10647 return -1;
10648 if (!equal)
10649 isl_die(ctx, isl_error_unknown,
10650 "unexpected result", return -1);
10653 isl_options_set_tile_scale_tile_loops(ctx, scale);
10654 isl_options_set_tile_shift_point_loops(ctx, shift);
10656 return 0;
10659 /* Check that the domain hash of a space is equal to the hash
10660 * of the domain of the space, both ignoring parameters.
10662 static int test_domain_hash(isl_ctx *ctx)
10664 isl_map *map;
10665 isl_space *space;
10666 uint32_t hash1, hash2;
10668 map = isl_map_read_from_str(ctx, "[n] -> { A[B[x] -> C[]] -> D[] }");
10669 space = isl_map_get_space(map);
10670 isl_map_free(map);
10671 hash1 = isl_space_get_tuple_domain_hash(space);
10672 space = isl_space_domain(space);
10673 hash2 = isl_space_get_tuple_hash(space);
10674 isl_space_free(space);
10676 if (!space)
10677 return -1;
10678 if (hash1 != hash2)
10679 isl_die(ctx, isl_error_unknown,
10680 "domain hash not equal to hash of domain", return -1);
10682 return 0;
10685 /* Check that a universe basic set that is not obviously equal to the universe
10686 * is still recognized as being equal to the universe.
10688 static int test_universe(isl_ctx *ctx)
10690 const char *s;
10691 isl_basic_set *bset;
10692 isl_bool is_univ;
10694 s = "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
10695 bset = isl_basic_set_read_from_str(ctx, s);
10696 is_univ = isl_basic_set_is_universe(bset);
10697 isl_basic_set_free(bset);
10699 if (is_univ < 0)
10700 return -1;
10701 if (!is_univ)
10702 isl_die(ctx, isl_error_unknown,
10703 "not recognized as universe set", return -1);
10705 return 0;
10708 /* Sets for which chambers are computed and checked.
10710 const char *chambers_tests[] = {
10711 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
10712 "z >= 0 and z <= C - y and z <= B - x - y }",
10715 /* Add the domain of "cell" to "cells".
10717 static isl_stat add_cell(__isl_take isl_cell *cell, void *user)
10719 isl_basic_set_list **cells = user;
10720 isl_basic_set *dom;
10722 dom = isl_cell_get_domain(cell);
10723 isl_cell_free(cell);
10724 *cells = isl_basic_set_list_add(*cells, dom);
10726 return *cells ? isl_stat_ok : isl_stat_error;
10729 /* Check that the elements of "list" are pairwise disjoint.
10731 static isl_stat check_pairwise_disjoint(__isl_keep isl_basic_set_list *list)
10733 int i, j;
10734 isl_size n;
10736 n = isl_basic_set_list_n_basic_set(list);
10737 if (n < 0)
10738 return isl_stat_error;
10740 for (i = 0; i < n; ++i) {
10741 isl_basic_set *bset_i;
10743 bset_i = isl_basic_set_list_get_basic_set(list, i);
10744 for (j = i + 1; j < n; ++j) {
10745 isl_basic_set *bset_j;
10746 isl_bool disjoint;
10748 bset_j = isl_basic_set_list_get_basic_set(list, j);
10749 disjoint = isl_basic_set_is_disjoint(bset_i, bset_j);
10750 isl_basic_set_free(bset_j);
10751 if (!disjoint)
10752 isl_die(isl_basic_set_list_get_ctx(list),
10753 isl_error_unknown, "not disjoint",
10754 break);
10755 if (disjoint < 0 || !disjoint)
10756 break;
10758 isl_basic_set_free(bset_i);
10759 if (j < n)
10760 return isl_stat_error;
10763 return isl_stat_ok;
10766 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
10767 * are pairwise disjoint.
10769 static int test_chambers(isl_ctx *ctx)
10771 int i;
10773 for (i = 0; i < ARRAY_SIZE(chambers_tests); ++i) {
10774 isl_basic_set *bset;
10775 isl_vertices *vertices;
10776 isl_basic_set_list *cells;
10777 isl_stat ok;
10779 bset = isl_basic_set_read_from_str(ctx, chambers_tests[i]);
10780 vertices = isl_basic_set_compute_vertices(bset);
10781 cells = isl_basic_set_list_alloc(ctx, 0);
10782 if (isl_vertices_foreach_disjoint_cell(vertices, &add_cell,
10783 &cells) < 0)
10784 cells = isl_basic_set_list_free(cells);
10785 ok = check_pairwise_disjoint(cells);
10786 isl_basic_set_list_free(cells);
10787 isl_vertices_free(vertices);
10788 isl_basic_set_free(bset);
10790 if (ok < 0)
10791 return -1;
10794 return 0;
10797 struct {
10798 const char *name;
10799 int (*fn)(isl_ctx *ctx);
10800 } tests [] = {
10801 { "universe", &test_universe },
10802 { "domain hash", &test_domain_hash },
10803 { "dual", &test_dual },
10804 { "dependence analysis", &test_flow },
10805 { "val", &test_val },
10806 { "compute divs", &test_compute_divs },
10807 { "partial lexmin", &test_partial_lexmin },
10808 { "simplify", &test_simplify },
10809 { "curry", &test_curry },
10810 { "piecewise multi affine expressions", &test_pw_multi_aff },
10811 { "multi piecewise affine expressions", &test_multi_pw_aff },
10812 { "conversion", &test_conversion },
10813 { "list", &test_list },
10814 { "align parameters", &test_align_parameters },
10815 { "drop unused parameters", &test_drop_unused_parameters },
10816 { "preimage", &test_preimage },
10817 { "pullback", &test_pullback },
10818 { "AST", &test_ast },
10819 { "AST build", &test_ast_build },
10820 { "AST generation", &test_ast_gen },
10821 { "eliminate", &test_eliminate },
10822 { "deltas_map", &test_deltas_map },
10823 { "residue class", &test_residue_class },
10824 { "div", &test_div },
10825 { "slice", &test_slice },
10826 { "fixed power", &test_fixed_power },
10827 { "sample", &test_sample },
10828 { "output", &test_output },
10829 { "vertices", &test_vertices },
10830 { "chambers", &test_chambers },
10831 { "fixed", &test_fixed },
10832 { "equal", &test_equal },
10833 { "disjoint", &test_disjoint },
10834 { "product", &test_product },
10835 { "dim_max", &test_dim_max },
10836 { "affine", &test_aff },
10837 { "injective", &test_injective },
10838 { "schedule (whole component)", &test_schedule_whole },
10839 { "schedule (incremental)", &test_schedule_incremental },
10840 { "schedule tree", &test_schedule_tree },
10841 { "schedule tree prefix", &test_schedule_tree_prefix },
10842 { "schedule tree grouping", &test_schedule_tree_group },
10843 { "tile", &test_tile },
10844 { "union map", &test_union_map },
10845 { "union_pw", &test_union_pw },
10846 { "locus", &test_locus },
10847 { "eval", &test_eval },
10848 { "parse", &test_parse },
10849 { "single-valued", &test_sv },
10850 { "recession cone", &test_recession_cone },
10851 { "affine hull", &test_affine_hull },
10852 { "simple_hull", &test_simple_hull },
10853 { "box hull", &test_box_hull },
10854 { "coalesce", &test_coalesce },
10855 { "factorize", &test_factorize },
10856 { "subset", &test_subset },
10857 { "subtract", &test_subtract },
10858 { "intersect", &test_intersect },
10859 { "lexmin", &test_lexmin },
10860 { "min", &test_min },
10861 { "set lower bounds", &test_min_mpa },
10862 { "gist", &test_gist },
10863 { "piecewise quasi-polynomials", &test_pwqp },
10864 { "lift", &test_lift },
10865 { "bind parameters", &test_bind },
10866 { "unbind parameters", &test_unbind },
10867 { "bound", &test_bound },
10868 { "get lists", &test_get_list },
10869 { "union", &test_union },
10870 { "split periods", &test_split_periods },
10871 { "lexicographic order", &test_lex },
10872 { "bijectivity", &test_bijective },
10873 { "dataflow analysis", &test_dep },
10874 { "reading", &test_read },
10875 { "bounded", &test_bounded },
10876 { "construction", &test_construction },
10877 { "dimension manipulation", &test_dim },
10878 { "map application", &test_application },
10879 { "convex hull", &test_convex_hull },
10880 { "transitive closure", &test_closure },
10881 { "isl_bool", &test_isl_bool},
10884 int main(int argc, char **argv)
10886 int i;
10887 struct isl_ctx *ctx;
10888 struct isl_options *options;
10890 options = isl_options_new_with_defaults();
10891 assert(options);
10892 argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL);
10894 ctx = isl_ctx_alloc_with_options(&isl_options_args, options);
10895 for (i = 0; i < ARRAY_SIZE(tests); ++i) {
10896 printf("%s\n", tests[i].name);
10897 if (tests[i].fn(ctx) < 0)
10898 goto error;
10900 isl_ctx_free(ctx);
10901 return 0;
10902 error:
10903 isl_ctx_free(ctx);
10904 return -1;