extract out shared isl_union_{map,set}_find_entry
[isl.git] / isl_test.c
blobe2b5bfa1ea1a9df8f2b57c69501f0d6ddf485007
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 /* Pairs of maps and the corresponding expected results of
1406 * isl_map_plain_unshifted_simple_hull.
1408 struct {
1409 const char *map;
1410 const char *hull;
1411 } plain_unshifted_simple_hull_tests[] = {
1412 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1413 "{ [i] -> [j] : i >= 1 }" },
1414 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1415 "(j mod 4 = 2 and k mod 6 = n) }",
1416 "{ [n] -> [i,j,k] : j mod 4 = 2 }" },
1419 /* Basic tests for isl_map_plain_unshifted_simple_hull.
1421 static int test_plain_unshifted_simple_hull(isl_ctx *ctx)
1423 int i;
1424 isl_map *map;
1425 isl_basic_map *hull, *expected;
1426 isl_bool equal;
1428 for (i = 0; i < ARRAY_SIZE(plain_unshifted_simple_hull_tests); ++i) {
1429 const char *str;
1430 str = plain_unshifted_simple_hull_tests[i].map;
1431 map = isl_map_read_from_str(ctx, str);
1432 str = plain_unshifted_simple_hull_tests[i].hull;
1433 expected = isl_basic_map_read_from_str(ctx, str);
1434 hull = isl_map_plain_unshifted_simple_hull(map);
1435 equal = isl_basic_map_is_equal(hull, expected);
1436 isl_basic_map_free(hull);
1437 isl_basic_map_free(expected);
1438 if (equal < 0)
1439 return -1;
1440 if (!equal)
1441 isl_die(ctx, isl_error_unknown, "unexpected hull",
1442 return -1);
1445 return 0;
1448 /* Pairs of sets and the corresponding expected results of
1449 * isl_set_unshifted_simple_hull.
1451 struct {
1452 const char *set;
1453 const char *hull;
1454 } unshifted_simple_hull_tests[] = {
1455 { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1456 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1459 /* Basic tests for isl_set_unshifted_simple_hull.
1461 static int test_unshifted_simple_hull(isl_ctx *ctx)
1463 int i;
1464 isl_set *set;
1465 isl_basic_set *hull, *expected;
1466 isl_bool equal;
1468 for (i = 0; i < ARRAY_SIZE(unshifted_simple_hull_tests); ++i) {
1469 const char *str;
1470 str = unshifted_simple_hull_tests[i].set;
1471 set = isl_set_read_from_str(ctx, str);
1472 str = unshifted_simple_hull_tests[i].hull;
1473 expected = isl_basic_set_read_from_str(ctx, str);
1474 hull = isl_set_unshifted_simple_hull(set);
1475 equal = isl_basic_set_is_equal(hull, expected);
1476 isl_basic_set_free(hull);
1477 isl_basic_set_free(expected);
1478 if (equal < 0)
1479 return -1;
1480 if (!equal)
1481 isl_die(ctx, isl_error_unknown, "unexpected hull",
1482 return -1);
1485 return 0;
1488 static int test_simple_hull(struct isl_ctx *ctx)
1490 const char *str;
1491 isl_set *set;
1492 isl_basic_set *bset;
1493 isl_bool is_empty;
1495 str = "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1496 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1497 set = isl_set_read_from_str(ctx, str);
1498 bset = isl_set_simple_hull(set);
1499 is_empty = isl_basic_set_is_empty(bset);
1500 isl_basic_set_free(bset);
1502 if (is_empty == isl_bool_error)
1503 return -1;
1505 if (is_empty == isl_bool_false)
1506 isl_die(ctx, isl_error_unknown, "Empty set should be detected",
1507 return -1);
1509 if (test_plain_unshifted_simple_hull_special(ctx) < 0)
1510 return -1;
1511 if (test_plain_unshifted_simple_hull(ctx) < 0)
1512 return -1;
1513 if (test_unshifted_simple_hull(ctx) < 0)
1514 return -1;
1516 return 0;
1519 /* Inputs for isl_set_get_simple_fixed_box_hull tests.
1520 * "set" is the input set.
1521 * "offset" is the expected box offset.
1522 * "size" is the expected box size.
1524 static struct {
1525 const char *set;
1526 const char *offset;
1527 const char *size;
1528 } box_hull_tests[] = {
1529 { "{ S[x, y] : 0 <= x, y < 10 }", "{ S[0, 0] }", "{ S[10, 10] }" },
1530 { "[N] -> { S[x, y] : N <= x, y < N + 10 }",
1531 "[N] -> { S[N, N] }", "{ S[10, 10] }" },
1532 { "{ S[x, y] : 0 <= x + y, x - y < 10 }",
1533 "{ S[0, -4] }", "{ S[10, 9] }" },
1534 { "{ [i=0:10] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1535 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1536 "{ [3] }", "{ [8] }" },
1537 { "[N] -> { [w = 0:17] : exists (e0: w < 2N and "
1538 "-1 + w <= e0 <= w and 2e0 >= N + w and w <= 2e0 <= 15 + w) }",
1539 "[N] -> { [N] }", "{ [9] }" },
1542 /* Perform basic isl_set_get_simple_fixed_box_hull tests.
1544 static int test_box_hull(struct isl_ctx *ctx)
1546 int i;
1548 for (i = 0; i < ARRAY_SIZE(box_hull_tests); ++i) {
1549 const char *str;
1550 isl_stat r;
1551 isl_set *set;
1552 isl_multi_aff *offset;
1553 isl_multi_val *size;
1554 isl_fixed_box *box;
1556 set = isl_set_read_from_str(ctx, box_hull_tests[i].set);
1557 box = isl_set_get_simple_fixed_box_hull(set);
1558 offset = isl_fixed_box_get_offset(box);
1559 size = isl_fixed_box_get_size(box);
1560 str = box_hull_tests[i].offset;
1561 r = multi_aff_check_plain_equal(offset, str);
1562 str = box_hull_tests[i].size;
1563 if (r >= 0)
1564 r = multi_val_check_plain_equal(size, str);
1565 isl_multi_aff_free(offset);
1566 isl_multi_val_free(size);
1567 isl_fixed_box_free(box);
1568 isl_set_free(set);
1569 if (r < 0)
1570 return -1;
1573 return 0;
1576 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
1578 char *filename;
1579 FILE *input;
1580 struct isl_basic_set *bset1, *bset2;
1581 struct isl_set *set;
1583 filename = get_filename(ctx, name, "polylib");
1584 assert(filename);
1585 input = fopen(filename, "r");
1586 assert(input);
1588 bset1 = isl_basic_set_read_from_file(ctx, input);
1589 bset2 = isl_basic_set_read_from_file(ctx, input);
1591 set = isl_basic_set_union(bset1, bset2);
1592 bset1 = isl_set_convex_hull(set);
1594 bset2 = isl_basic_set_read_from_file(ctx, input);
1596 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1598 isl_basic_set_free(bset1);
1599 isl_basic_set_free(bset2);
1600 free(filename);
1602 fclose(input);
1605 struct {
1606 const char *set;
1607 const char *hull;
1608 } convex_hull_tests[] = {
1609 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1610 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1611 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1612 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1613 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1614 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1615 "i2 <= 5 and i2 >= 4; "
1616 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1617 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1618 "i2 <= 5 + i0 and i2 >= i0 }" },
1619 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1620 "{ [x, y] : 1 = 0 }" },
1621 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1622 "[x, y, 0] : x >= 0 and y < 0 }",
1623 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1624 { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and "
1625 "c <= a; "
1626 "[0, 2, 0]; [3, 1, 0] }",
1627 "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and "
1628 "5c <= 6 - a - 3b }" },
1631 static int test_convex_hull_algo(isl_ctx *ctx, int convex)
1633 int i;
1634 int orig_convex = ctx->opt->convex;
1635 ctx->opt->convex = convex;
1637 test_convex_hull_case(ctx, "convex0");
1638 test_convex_hull_case(ctx, "convex1");
1639 test_convex_hull_case(ctx, "convex2");
1640 test_convex_hull_case(ctx, "convex3");
1641 test_convex_hull_case(ctx, "convex4");
1642 test_convex_hull_case(ctx, "convex5");
1643 test_convex_hull_case(ctx, "convex6");
1644 test_convex_hull_case(ctx, "convex7");
1645 test_convex_hull_case(ctx, "convex8");
1646 test_convex_hull_case(ctx, "convex9");
1647 test_convex_hull_case(ctx, "convex10");
1648 test_convex_hull_case(ctx, "convex11");
1649 test_convex_hull_case(ctx, "convex12");
1650 test_convex_hull_case(ctx, "convex13");
1651 test_convex_hull_case(ctx, "convex14");
1652 test_convex_hull_case(ctx, "convex15");
1654 for (i = 0; i < ARRAY_SIZE(convex_hull_tests); ++i) {
1655 isl_set *set1, *set2;
1656 int equal;
1658 set1 = isl_set_read_from_str(ctx, convex_hull_tests[i].set);
1659 set2 = isl_set_read_from_str(ctx, convex_hull_tests[i].hull);
1660 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
1661 equal = isl_set_is_equal(set1, set2);
1662 isl_set_free(set1);
1663 isl_set_free(set2);
1665 if (equal < 0)
1666 return -1;
1667 if (!equal)
1668 isl_die(ctx, isl_error_unknown,
1669 "unexpected convex hull", return -1);
1672 ctx->opt->convex = orig_convex;
1674 return 0;
1677 static int test_convex_hull(isl_ctx *ctx)
1679 if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM) < 0)
1680 return -1;
1681 if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP) < 0)
1682 return -1;
1683 return 0;
1686 void test_gist_case(struct isl_ctx *ctx, const char *name)
1688 char *filename;
1689 FILE *input;
1690 struct isl_basic_set *bset1, *bset2;
1692 filename = get_filename(ctx, name, "polylib");
1693 assert(filename);
1694 input = fopen(filename, "r");
1695 assert(input);
1697 bset1 = isl_basic_set_read_from_file(ctx, input);
1698 bset2 = isl_basic_set_read_from_file(ctx, input);
1700 bset1 = isl_basic_set_gist(bset1, bset2);
1702 bset2 = isl_basic_set_read_from_file(ctx, input);
1704 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1706 isl_basic_set_free(bset1);
1707 isl_basic_set_free(bset2);
1708 free(filename);
1710 fclose(input);
1713 /* Check that computing the gist of "map" with respect to "context"
1714 * does not make any copy of "map" get marked empty.
1715 * Earlier versions of isl would end up doing that.
1717 static isl_stat test_gist_empty_pair(isl_ctx *ctx, const char *map,
1718 const char *context)
1720 isl_map *m1, *m2, *m3;
1721 isl_bool empty_before, empty_after;
1723 m1 = isl_map_read_from_str(ctx, map);
1724 m2 = isl_map_read_from_str(ctx, context);
1725 m3 = isl_map_copy(m1);
1726 empty_before = isl_map_is_empty(m3);
1727 m1 = isl_map_gist(m1, m2);
1728 empty_after = isl_map_is_empty(m3);
1729 isl_map_free(m1);
1730 isl_map_free(m3);
1732 if (empty_before < 0 || empty_after < 0)
1733 return isl_stat_error;
1734 if (empty_before)
1735 isl_die(ctx, isl_error_unknown, "map should not be empty",
1736 return isl_stat_error);
1737 if (empty_after)
1738 isl_die(ctx, isl_error_unknown, "map should still not be empty",
1739 return isl_stat_error);
1741 return isl_stat_ok;
1744 /* Check that computing a gist does not make any copy of the input
1745 * get marked empty.
1746 * Earlier versions of isl would end up doing that on some pairs of inputs.
1748 static isl_stat test_gist_empty(isl_ctx *ctx)
1750 const char *map, *context;
1752 map = "{ [] -> [a, b, c] : 2b = 1 + a }";
1753 context = "{ [] -> [a, b, c] : 2c = 2 + a }";
1754 if (test_gist_empty_pair(ctx, map, context) < 0)
1755 return isl_stat_error;
1756 map = "{ [] -> [0, 0] }";
1757 context = "{ [] -> [a, b] : a > b }";
1758 if (test_gist_empty_pair(ctx, map, context) < 0)
1759 return isl_stat_error;
1761 return isl_stat_ok;
1764 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1766 struct {
1767 const char *map;
1768 const char *context;
1769 const char *gist;
1770 } plain_gist_tests[] = {
1771 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1772 "{ [i] -> [j] : i >= 1 }",
1773 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1774 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1775 "(j mod 4 = 2 and k mod 6 = n) }",
1776 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1777 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1778 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1779 "{ [i] -> [j] : i > j }",
1780 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1783 /* Basic tests for isl_map_plain_gist_basic_map.
1785 static int test_plain_gist(isl_ctx *ctx)
1787 int i;
1789 for (i = 0; i < ARRAY_SIZE(plain_gist_tests); ++i) {
1790 const char *str;
1791 int equal;
1792 isl_map *map, *gist;
1793 isl_basic_map *context;
1795 map = isl_map_read_from_str(ctx, plain_gist_tests[i].map);
1796 str = plain_gist_tests[i].context;
1797 context = isl_basic_map_read_from_str(ctx, str);
1798 map = isl_map_plain_gist_basic_map(map, context);
1799 gist = isl_map_read_from_str(ctx, plain_gist_tests[i].gist);
1800 equal = isl_map_is_equal(map, gist);
1801 isl_map_free(map);
1802 isl_map_free(gist);
1803 if (equal < 0)
1804 return -1;
1805 if (!equal)
1806 isl_die(ctx, isl_error_unknown,
1807 "incorrect gist result", return -1);
1810 return 0;
1813 /* Inputs for isl_basic_set_gist tests that are expected to fail.
1815 struct {
1816 const char *set;
1817 const char *context;
1818 } gist_fail_tests[] = {
1819 { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1820 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1821 "{ [i] : i >= 0 }" },
1824 /* Check that isl_basic_set_gist fails (gracefully) when expected.
1825 * In particular, the user should be able to recover from the failure.
1827 static isl_stat test_gist_fail(struct isl_ctx *ctx)
1829 int i, n;
1830 int on_error;
1832 on_error = isl_options_get_on_error(ctx);
1833 isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE);
1834 n = ARRAY_SIZE(gist_fail_tests);
1835 for (i = 0; i < n; ++i) {
1836 const char *str;
1837 isl_basic_set *bset, *context;
1839 bset = isl_basic_set_read_from_str(ctx, gist_fail_tests[i].set);
1840 str = gist_fail_tests[i].context;
1841 context = isl_basic_set_read_from_str(ctx, str);
1842 bset = isl_basic_set_gist(bset, context);
1843 isl_basic_set_free(bset);
1844 if (bset)
1845 break;
1847 isl_options_set_on_error(ctx, on_error);
1848 if (i < n)
1849 isl_die(ctx, isl_error_unknown,
1850 "operation not expected to succeed",
1851 return isl_stat_error);
1853 return isl_stat_ok;
1856 struct {
1857 const char *set;
1858 const char *context;
1859 const char *gist;
1860 } gist_tests[] = {
1861 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1862 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1863 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1864 "{ [a, b, c] : a <= 15 }" },
1865 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1866 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1867 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1868 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1869 { "{ [m, n, a, b] : a <= 2147 + n }",
1870 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1871 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1872 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1873 "b >= 0) }",
1874 "{ [m, n, ku, kl] }" },
1875 { "{ [a, a, b] : a >= 10 }",
1876 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1877 "{ [a, a, b] : a >= 10 }" },
1878 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1879 "{ [0, j] : j >= 0 }" },
1880 /* Check that no constraints on i6 are introduced in the gist */
1881 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1882 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1883 "5e0 <= 381 - t1 and i4 <= 1) }",
1884 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1885 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1886 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1887 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1888 "20e0 >= 1511 - 4t1 - 5i4) }" },
1889 /* Check that no constraints on i6 are introduced in the gist */
1890 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1891 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1892 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1893 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1894 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1895 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1896 "20e1 <= 1530 - 4t1 - 5i4 and "
1897 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1898 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1899 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1900 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1901 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1902 "10e0 <= -91 + 5i4 + 4i6 and "
1903 "10e0 >= -105 + 5i4 + 4i6) }",
1904 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1905 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1906 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1907 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1908 "{ [a, b, q, p] : b >= 1 + a }",
1909 "{ [a, b, q, p] : false }" },
1910 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1911 "[n] -> { [x] : x mod 32 = 0 }",
1912 "[n] -> { [x = n] }" },
1913 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1914 "{ [x] : x mod 2 = 0 }" },
1915 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1916 "{ [x] : x mod 128 = 0 }" },
1917 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1918 "{ [x] : x mod 3200 = 0 }" },
1919 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1920 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1921 "{ [a, b, c = a] }" },
1922 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1923 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1924 "{ [a, b, c = a] : a mod 3 = 0 }" },
1925 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1926 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1927 "{ [x] }" },
1928 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1929 "{ [x,y] : 1 <= y <= 3 }",
1930 "{ [x,y] }" },
1933 /* Check that isl_set_gist behaves as expected.
1935 * For the test cases in gist_tests, besides checking that the result
1936 * is as expected, also check that applying the gist operation does
1937 * not modify the input set (an earlier version of isl would do that) and
1938 * that the test case is consistent, i.e., that the gist has the same
1939 * intersection with the context as the input set.
1941 static int test_gist(struct isl_ctx *ctx)
1943 int i;
1944 const char *str;
1945 isl_basic_set *bset1, *bset2;
1946 isl_map *map1, *map2;
1947 isl_bool equal;
1948 isl_size n_div;
1950 for (i = 0; i < ARRAY_SIZE(gist_tests); ++i) {
1951 isl_bool equal_input, equal_intersection;
1952 isl_set *set1, *set2, *copy, *context;
1954 set1 = isl_set_read_from_str(ctx, gist_tests[i].set);
1955 context = isl_set_read_from_str(ctx, gist_tests[i].context);
1956 copy = isl_set_copy(set1);
1957 set1 = isl_set_gist(set1, isl_set_copy(context));
1958 set2 = isl_set_read_from_str(ctx, gist_tests[i].gist);
1959 equal = isl_set_is_equal(set1, set2);
1960 isl_set_free(set1);
1961 set1 = isl_set_read_from_str(ctx, gist_tests[i].set);
1962 equal_input = isl_set_is_equal(set1, copy);
1963 isl_set_free(copy);
1964 set1 = isl_set_intersect(set1, isl_set_copy(context));
1965 set2 = isl_set_intersect(set2, context);
1966 equal_intersection = isl_set_is_equal(set1, set2);
1967 isl_set_free(set2);
1968 isl_set_free(set1);
1969 if (equal < 0 || equal_input < 0 || equal_intersection < 0)
1970 return -1;
1971 if (!equal)
1972 isl_die(ctx, isl_error_unknown,
1973 "incorrect gist result", return -1);
1974 if (!equal_input)
1975 isl_die(ctx, isl_error_unknown,
1976 "gist modified input", return -1);
1977 if (!equal_input)
1978 isl_die(ctx, isl_error_unknown,
1979 "inconsistent gist test case", return -1);
1982 if (test_gist_fail(ctx) < 0)
1983 return -1;
1985 test_gist_case(ctx, "gist1");
1987 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
1988 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1989 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1990 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1991 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1992 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1993 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1994 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1995 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1996 bset1 = isl_basic_set_read_from_str(ctx, str);
1997 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1998 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1999 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
2000 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
2001 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
2002 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
2003 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
2004 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
2005 bset2 = isl_basic_set_read_from_str(ctx, str);
2006 bset1 = isl_basic_set_gist(bset1, bset2);
2007 assert(bset1 && bset1->n_div == 0);
2008 isl_basic_set_free(bset1);
2010 /* Check that the integer divisions of the second disjunct
2011 * do not spread to the first disjunct.
2013 str = "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
2014 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
2015 "(exists (e0 = [(-1 + t1)/16], "
2016 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
2017 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
2018 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
2019 "o0 <= 4294967295 and t1 <= -1)) }";
2020 map1 = isl_map_read_from_str(ctx, str);
2021 str = "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
2022 map2 = isl_map_read_from_str(ctx, str);
2023 map1 = isl_map_gist(map1, map2);
2024 if (!map1)
2025 return -1;
2026 if (map1->n != 1)
2027 isl_die(ctx, isl_error_unknown, "expecting single disjunct",
2028 isl_map_free(map1); return -1);
2029 n_div = isl_basic_map_dim(map1->p[0], isl_dim_div);
2030 isl_map_free(map1);
2031 if (n_div < 0)
2032 return -1;
2033 if (n_div != 1)
2034 isl_die(ctx, isl_error_unknown, "expecting single div",
2035 return -1);
2037 if (test_gist_empty(ctx) < 0)
2038 return -1;
2039 if (test_plain_gist(ctx) < 0)
2040 return -1;
2042 return 0;
2045 int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
2047 isl_set *set, *set2;
2048 int equal;
2049 int one;
2051 set = isl_set_read_from_str(ctx, str);
2052 set = isl_set_coalesce(set);
2053 set2 = isl_set_read_from_str(ctx, str);
2054 equal = isl_set_is_equal(set, set2);
2055 one = set && set->n == 1;
2056 isl_set_free(set);
2057 isl_set_free(set2);
2059 if (equal < 0)
2060 return -1;
2061 if (!equal)
2062 isl_die(ctx, isl_error_unknown,
2063 "coalesced set not equal to input", return -1);
2064 if (check_one && !one)
2065 isl_die(ctx, isl_error_unknown,
2066 "coalesced set should not be a union", return -1);
2068 return 0;
2071 /* Inputs for coalescing tests with unbounded wrapping.
2072 * "str" is a string representation of the input set.
2073 * "single_disjunct" is set if we expect the result to consist of
2074 * a single disjunct.
2076 struct {
2077 int single_disjunct;
2078 const char *str;
2079 } coalesce_unbounded_tests[] = {
2080 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
2081 "-x - y + 1 >= 0 and -3 <= z <= 3;"
2082 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
2083 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
2084 "-10 <= y <= 0}" },
2085 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
2086 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
2087 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
2088 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
2089 { 0, "{ [x, y, z] : 0 <= x,y,z <= 100 and 0 < z <= 2 + 2x + 2y; "
2090 "[x, y, 0] : x,y <= 100 and y <= 9 + 11x and x <= 9 + 11y }" },
2091 { 1, "{ [0:1, 0:1]; [0, 2:3] }" },
2092 { 1, "{ [0:1, 0:1]; [0, 2:3]; [1, -2:-1] }" },
2093 { 1, "{ [0:3, 0:1]; [1:2, 2:5] }" },
2094 { 1, "{ [0:3, 0:1]; [0:2, 2:5] }" },
2095 { 1, "{ [0:3, 0:1]; [1:3, 2:5] }" },
2096 { 0, "{ [0:3, 0:1]; [1:4, 2:5] }" },
2097 { 0, "{ [0:3, 0:1]; [1:5, 2:5] }" },
2100 /* Test the functionality of isl_set_coalesce with the bounded wrapping
2101 * option turned off.
2103 int test_coalesce_unbounded_wrapping(isl_ctx *ctx)
2105 int i;
2106 int r = 0;
2107 int bounded;
2109 bounded = isl_options_get_coalesce_bounded_wrapping(ctx);
2110 isl_options_set_coalesce_bounded_wrapping(ctx, 0);
2112 for (i = 0; i < ARRAY_SIZE(coalesce_unbounded_tests); ++i) {
2113 const char *str = coalesce_unbounded_tests[i].str;
2114 int check_one = coalesce_unbounded_tests[i].single_disjunct;
2115 if (test_coalesce_set(ctx, str, check_one) >= 0)
2116 continue;
2117 r = -1;
2118 break;
2121 isl_options_set_coalesce_bounded_wrapping(ctx, bounded);
2123 return r;
2126 /* Inputs for coalescing tests.
2127 * "str" is a string representation of the input set.
2128 * "single_disjunct" is set if we expect the result to consist of
2129 * a single disjunct.
2131 struct {
2132 int single_disjunct;
2133 const char *str;
2134 } coalesce_tests[] = {
2135 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
2136 "y >= x & x >= 2 & 5 >= y }" },
2137 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2138 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
2139 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
2140 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
2141 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2142 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
2143 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2144 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
2145 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
2146 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
2147 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
2148 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
2149 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
2150 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
2151 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
2152 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
2153 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
2154 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2155 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2156 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2157 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
2158 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
2159 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
2160 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
2161 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
2162 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
2163 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
2164 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
2165 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
2166 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
2167 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
2168 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
2169 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
2170 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
2171 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
2172 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
2173 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
2174 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
2175 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
2176 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
2177 "[o0, o1, o2, o3, o4, o5, o6]] : "
2178 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
2179 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
2180 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
2181 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
2182 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
2183 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
2184 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
2185 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
2186 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
2187 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
2188 "o6 >= i3 + i6 - o3 and M >= 0 and "
2189 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
2190 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
2191 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
2192 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
2193 "(o0 = 0 and M >= 2 and N >= 3) or "
2194 "(M = 0 and o0 = 0 and N >= 3) }" },
2195 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
2196 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
2197 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
2198 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
2199 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
2200 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
2201 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
2202 "(y = 3 and x = 1) }" },
2203 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
2204 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
2205 "i1 <= M and i3 <= M and i4 <= M) or "
2206 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
2207 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
2208 "i4 <= -1 + M) }" },
2209 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
2210 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
2211 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
2212 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
2213 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
2214 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
2215 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
2216 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
2217 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
2218 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
2219 { 0, "{ [a, b] : exists e : 2e = a and "
2220 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
2221 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
2222 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
2223 "j >= 1 and j' <= i + j - i' and i >= 1; "
2224 "[1, 1, 1, 1] }" },
2225 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
2226 "[i,j] : exists a : j = 3a }" },
2227 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
2228 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
2229 "a >= 3) or "
2230 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
2231 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
2232 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
2233 "c <= 6 + 8a and a >= 3; "
2234 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
2235 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
2236 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2237 "[x,0] : 3 <= x <= 4 }" },
2238 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
2239 "[x,0] : 4 <= x <= 5 }" },
2240 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2241 "[x,0] : 3 <= x <= 5 }" },
2242 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
2243 "[x,0] : 3 <= x <= 4 }" },
2244 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
2245 "i1 <= 0; "
2246 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
2247 { 1, "{ [0,0]; [1,1] }" },
2248 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
2249 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
2250 "ii <= k;"
2251 "[k, 0, k] : k <= 6 and k >= 1 }" },
2252 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
2253 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
2254 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
2255 { 1, "[n] -> { [1] : n >= 0;"
2256 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
2257 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
2258 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
2259 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
2260 "2e0 <= x and 2e0 <= n);"
2261 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
2262 "n >= 0) }" },
2263 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
2264 "128e0 >= -134 + 127t1 and t1 >= 2 and "
2265 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
2266 "t1 = 1 }" },
2267 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
2268 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
2269 "[0, 0] }" },
2270 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
2271 "t1 >= 13 and t1 <= 16);"
2272 "[t1] : t1 <= 15 and t1 >= 12 }" },
2273 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2274 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2275 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2276 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2277 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2278 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2279 "i <= 4j + 2 }" },
2280 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2281 "(exists (e0 : 3e0 = -2 + c0)) }" },
2282 { 0, "[n, b0, t0] -> "
2283 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2284 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2285 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2286 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2287 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2288 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2289 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2290 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2291 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2292 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2293 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2294 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2295 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2296 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2297 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2298 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2299 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2300 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2301 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2302 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2303 { 0, "{ [i0, i1, i2] : "
2304 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2305 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2306 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2307 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2308 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2309 "32e0 <= 31 + i0)) or "
2310 "i0 >= 0 }" },
2311 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2312 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2313 "2*floor((c)/2) = c and 0 <= a <= 192;"
2314 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2316 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2317 "(0 <= a <= b <= n) }" },
2318 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2319 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2320 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2321 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2322 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2323 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2324 "b = 3 and 9e0 <= -19 + 2c)) }" },
2325 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2326 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2327 "(a = 4 and b = 3 and "
2328 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2329 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2330 "(b = -1 + a and 0 < a <= 3 and "
2331 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2332 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2333 "b = 3 and 9e0 <= -19 + 2c)) }" },
2334 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2335 "[1, 0] }" },
2336 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2337 "[0, 1] }" },
2338 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2339 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2340 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2341 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2342 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2343 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2344 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2345 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2346 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2347 { 1, "{ [a] : a <= 8 and "
2348 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2349 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2350 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2351 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2352 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2353 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2354 "(a < 0 and 3*floor((a)/3) < a) }" },
2355 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2356 "(a < -1 and 3*floor((a)/3) < a) }" },
2357 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2358 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2359 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2360 "or (2 <= a <= 15 and b < a)) }" },
2361 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2362 "32*floor((a)/32) < a) or a <= 15) }" },
2363 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2364 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2365 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2366 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2367 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2368 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2369 "S_0[n] : n <= m <= 2 + n }" },
2370 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2371 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2372 "2e0 <= a + b); "
2373 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2374 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2375 "2e0 < -a + 2b) }" },
2376 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2377 "[i, 0, i] : 0 <= i <= 7 }" },
2378 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2379 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2380 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2381 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2382 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2383 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2384 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2385 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2386 "a > 0 and a <= 5) }" },
2387 { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" },
2388 { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and "
2389 "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; "
2390 "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" },
2391 { 0, "{ [0:1, 0:1]; [0, 2:3] }" },
2392 { 1, "{ [a] : (a = 0 or ((1 + a) mod 2 = 0 and 0 < a <= 15) or "
2393 "((a) mod 2 = 0 and 0 < a <= 15)) }" },
2396 /* A specialized coalescing test case that would result
2397 * in a segmentation fault or a failed assertion in earlier versions of isl.
2399 static int test_coalesce_special(struct isl_ctx *ctx)
2401 const char *str;
2402 isl_map *map1, *map2;
2404 str = "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2405 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2406 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2407 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2408 "o1 <= 239 and o1 >= 212)) or "
2409 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2410 "o1 <= 241 and o1 >= 240));"
2411 "[S_L220_OUT[] -> T7[]] -> "
2412 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2413 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2414 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2415 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2416 map1 = isl_map_read_from_str(ctx, str);
2417 map1 = isl_map_align_divs_internal(map1);
2418 map1 = isl_map_coalesce(map1);
2419 str = "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2420 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2421 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2422 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2423 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2424 map2 = isl_map_read_from_str(ctx, str);
2425 map2 = isl_map_union(map2, map1);
2426 map2 = isl_map_align_divs_internal(map2);
2427 map2 = isl_map_coalesce(map2);
2428 isl_map_free(map2);
2429 if (!map2)
2430 return -1;
2432 return 0;
2435 /* A specialized coalescing test case that would result in an assertion
2436 * in an earlier version of isl.
2437 * The explicit call to isl_basic_set_union prevents the implicit
2438 * equality constraints in the first basic map from being detected prior
2439 * to the call to isl_set_coalesce, at least at the point
2440 * where this test case was introduced.
2442 static int test_coalesce_special2(struct isl_ctx *ctx)
2444 const char *str;
2445 isl_basic_set *bset1, *bset2;
2446 isl_set *set;
2448 str = "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2449 bset1 = isl_basic_set_read_from_str(ctx, str);
2450 str = "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2451 bset2 = isl_basic_set_read_from_str(ctx, str);
2452 set = isl_basic_set_union(bset1, bset2);
2453 set = isl_set_coalesce(set);
2454 isl_set_free(set);
2456 if (!set)
2457 return -1;
2458 return 0;
2461 /* Check that calling isl_set_coalesce does not leave other sets
2462 * that may share some information with the input to isl_set_coalesce
2463 * in an inconsistent state.
2464 * In particular, older versions of isl would modify all copies
2465 * of the basic sets in the isl_set_coalesce input in a way
2466 * that could leave them in an inconsistent state.
2467 * The result of printing any other set containing one of these
2468 * basic sets would then result in an invalid set description.
2470 static int test_coalesce_special3(isl_ctx *ctx)
2472 const char *str;
2473 char *s;
2474 isl_set *set1, *set2;
2475 isl_printer *p;
2477 set1 = isl_set_read_from_str(ctx, "{ [0, 0, 0] }");
2478 str = "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2479 set2 = isl_set_read_from_str(ctx, str);
2480 set1 = isl_set_union(set1, isl_set_copy(set2));
2481 set1 = isl_set_coalesce(set1);
2482 isl_set_free(set1);
2484 p = isl_printer_to_str(ctx);
2485 p = isl_printer_print_set(p, set2);
2486 isl_set_free(set2);
2487 s = isl_printer_get_str(p);
2488 isl_printer_free(p);
2489 set1 = isl_set_read_from_str(ctx, s);
2490 free(s);
2491 isl_set_free(set1);
2493 if (!set1)
2494 return -1;
2496 return 0;
2499 /* Check that calling isl_set_coalesce on the intersection of
2500 * the sets described by "s1" and "s2" does not leave other sets
2501 * that may share some information with the input to isl_set_coalesce
2502 * in an inconsistent state.
2503 * In particular, when isl_set_coalesce detects equality constraints,
2504 * it does not immediately perform Gaussian elimination on them,
2505 * but then it needs to ensure that it is performed at some point.
2506 * The input set has implicit equality constraints in the first disjunct.
2507 * It is constructed as an intersection, because otherwise
2508 * those equality constraints would already be detected during parsing.
2510 static isl_stat test_coalesce_intersection(isl_ctx *ctx,
2511 const char *s1, const char *s2)
2513 isl_set *set1, *set2;
2515 set1 = isl_set_read_from_str(ctx, s1);
2516 set2 = isl_set_read_from_str(ctx, s2);
2517 set1 = isl_set_intersect(set1, set2);
2518 isl_set_free(isl_set_coalesce(isl_set_copy(set1)));
2519 set1 = isl_set_coalesce(set1);
2520 isl_set_free(set1);
2522 if (!set1)
2523 return isl_stat_error;
2525 return isl_stat_ok;
2528 /* Check that calling isl_set_coalesce does not leave other sets
2529 * that may share some information with the input to isl_set_coalesce
2530 * in an inconsistent state, for the case where one disjunct
2531 * is a subset of the other.
2533 static isl_stat test_coalesce_special4(isl_ctx *ctx)
2535 const char *s1, *s2;
2537 s1 = "{ [a, b] : b <= 0 or a <= 1 }";
2538 s2 = "{ [a, b] : -1 <= -a < b }";
2539 return test_coalesce_intersection(ctx, s1, s2);
2542 /* Check that calling isl_set_coalesce does not leave other sets
2543 * that may share some information with the input to isl_set_coalesce
2544 * in an inconsistent state, for the case where two disjuncts
2545 * can be fused.
2547 static isl_stat test_coalesce_special5(isl_ctx *ctx)
2549 const char *s1, *s2;
2551 s1 = "{ [a, b, c] : b <= 0 }";
2552 s2 = "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }";
2553 return test_coalesce_intersection(ctx, s1, s2);
2556 /* Check that calling isl_set_coalesce does not leave other sets
2557 * that may share some information with the input to isl_set_coalesce
2558 * in an inconsistent state, for the case where two disjuncts
2559 * can be fused and where both disjuncts have implicit equality constraints.
2561 static isl_stat test_coalesce_special6(isl_ctx *ctx)
2563 const char *s1, *s2;
2565 s1 = "{ [a, b, c] : c <= 0 }";
2566 s2 = "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }";
2567 return test_coalesce_intersection(ctx, s1, s2);
2570 /* Test the functionality of isl_set_coalesce.
2571 * That is, check that the output is always equal to the input
2572 * and in some cases that the result consists of a single disjunct.
2574 static int test_coalesce(struct isl_ctx *ctx)
2576 int i;
2578 for (i = 0; i < ARRAY_SIZE(coalesce_tests); ++i) {
2579 const char *str = coalesce_tests[i].str;
2580 int check_one = coalesce_tests[i].single_disjunct;
2581 if (test_coalesce_set(ctx, str, check_one) < 0)
2582 return -1;
2585 if (test_coalesce_unbounded_wrapping(ctx) < 0)
2586 return -1;
2587 if (test_coalesce_special(ctx) < 0)
2588 return -1;
2589 if (test_coalesce_special2(ctx) < 0)
2590 return -1;
2591 if (test_coalesce_special3(ctx) < 0)
2592 return -1;
2593 if (test_coalesce_special4(ctx) < 0)
2594 return -1;
2595 if (test_coalesce_special5(ctx) < 0)
2596 return -1;
2597 if (test_coalesce_special6(ctx) < 0)
2598 return -1;
2601 return 0;
2604 /* Construct a representation of the graph on the right of Figure 1
2605 * in "Computing the Transitive Closure of a Union of
2606 * Affine Integer Tuple Relations".
2608 static __isl_give isl_map *cocoa_fig_1_right_graph(isl_ctx *ctx)
2610 isl_set *dom;
2611 isl_map *up, *right;
2613 dom = isl_set_read_from_str(ctx,
2614 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2615 "2 x - 3 y + 3 >= 0 }");
2616 right = isl_map_read_from_str(ctx,
2617 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2618 up = isl_map_read_from_str(ctx,
2619 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2620 right = isl_map_intersect_domain(right, isl_set_copy(dom));
2621 right = isl_map_intersect_range(right, isl_set_copy(dom));
2622 up = isl_map_intersect_domain(up, isl_set_copy(dom));
2623 up = isl_map_intersect_range(up, dom);
2624 return isl_map_union(up, right);
2627 /* Construct a representation of the power of the graph
2628 * on the right of Figure 1 in "Computing the Transitive Closure of
2629 * a Union of Affine Integer Tuple Relations".
2631 static __isl_give isl_map *cocoa_fig_1_right_power(isl_ctx *ctx)
2633 return isl_map_read_from_str(ctx,
2634 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2635 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2636 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2639 /* Construct a representation of the transitive closure of the graph
2640 * on the right of Figure 1 in "Computing the Transitive Closure of
2641 * a Union of Affine Integer Tuple Relations".
2643 static __isl_give isl_map *cocoa_fig_1_right_tc(isl_ctx *ctx)
2645 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx)));
2648 static int test_closure(isl_ctx *ctx)
2650 const char *str;
2651 isl_map *map, *map2;
2652 isl_bool exact, equal;
2654 /* COCOA example 1 */
2655 map = isl_map_read_from_str(ctx,
2656 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2657 "1 <= i and i < n and 1 <= j and j < n or "
2658 "i2 = i + 1 and j2 = j - 1 and "
2659 "1 <= i and i < n and 2 <= j and j <= n }");
2660 map = isl_map_power(map, &exact);
2661 assert(exact);
2662 isl_map_free(map);
2664 /* COCOA example 1 */
2665 map = isl_map_read_from_str(ctx,
2666 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2667 "1 <= i and i < n and 1 <= j and j < n or "
2668 "i2 = i + 1 and j2 = j - 1 and "
2669 "1 <= i and i < n and 2 <= j and j <= n }");
2670 map = isl_map_transitive_closure(map, &exact);
2671 assert(exact);
2672 map2 = isl_map_read_from_str(ctx,
2673 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2674 "1 <= i and i < n and 1 <= j and j <= n and "
2675 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2676 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2677 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2678 assert(isl_map_is_equal(map, map2));
2679 isl_map_free(map2);
2680 isl_map_free(map);
2682 map = isl_map_read_from_str(ctx,
2683 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2684 " 0 <= y and y <= n }");
2685 map = isl_map_transitive_closure(map, &exact);
2686 map2 = isl_map_read_from_str(ctx,
2687 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2688 " 0 <= y and y <= n }");
2689 assert(isl_map_is_equal(map, map2));
2690 isl_map_free(map2);
2691 isl_map_free(map);
2693 /* COCOA example 2 */
2694 map = isl_map_read_from_str(ctx,
2695 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2696 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2697 "i2 = i + 2 and j2 = j - 2 and "
2698 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2699 map = isl_map_transitive_closure(map, &exact);
2700 assert(exact);
2701 map2 = isl_map_read_from_str(ctx,
2702 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2703 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2704 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2705 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2706 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2707 assert(isl_map_is_equal(map, map2));
2708 isl_map_free(map);
2709 isl_map_free(map2);
2711 /* COCOA Fig.2 left */
2712 map = isl_map_read_from_str(ctx,
2713 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2714 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2715 "j <= n or "
2716 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2717 "j <= 2 i - 3 and j <= n - 2 or "
2718 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2719 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2720 map = isl_map_transitive_closure(map, &exact);
2721 assert(exact);
2722 isl_map_free(map);
2724 /* COCOA Fig.2 right */
2725 map = isl_map_read_from_str(ctx,
2726 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2727 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2728 "j <= n or "
2729 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2730 "j <= 2 i - 4 and j <= n - 3 or "
2731 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2732 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2733 map = isl_map_power(map, &exact);
2734 assert(exact);
2735 isl_map_free(map);
2737 /* COCOA Fig.2 right */
2738 map = isl_map_read_from_str(ctx,
2739 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2740 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2741 "j <= n or "
2742 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2743 "j <= 2 i - 4 and j <= n - 3 or "
2744 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2745 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2746 map = isl_map_transitive_closure(map, &exact);
2747 assert(exact);
2748 map2 = isl_map_read_from_str(ctx,
2749 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2750 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2751 "j <= n and 3 + i + 2 j <= 3 n and "
2752 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2753 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2754 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2755 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2756 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2757 assert(isl_map_is_equal(map, map2));
2758 isl_map_free(map2);
2759 isl_map_free(map);
2761 map = cocoa_fig_1_right_graph(ctx);
2762 map = isl_map_transitive_closure(map, &exact);
2763 assert(exact);
2764 map2 = cocoa_fig_1_right_tc(ctx);
2765 assert(isl_map_is_equal(map, map2));
2766 isl_map_free(map2);
2767 isl_map_free(map);
2769 map = cocoa_fig_1_right_graph(ctx);
2770 map = isl_map_power(map, &exact);
2771 map2 = cocoa_fig_1_right_power(ctx);
2772 equal = isl_map_is_equal(map, map2);
2773 isl_map_free(map2);
2774 isl_map_free(map);
2775 if (equal < 0)
2776 return -1;
2777 if (!exact)
2778 isl_die(ctx, isl_error_unknown, "power not exact", return -1);
2779 if (!equal)
2780 isl_die(ctx, isl_error_unknown, "unexpected power", return -1);
2782 /* COCOA Theorem 1 counter example */
2783 map = isl_map_read_from_str(ctx,
2784 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2785 "i2 = 1 and j2 = j or "
2786 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2787 map = isl_map_transitive_closure(map, &exact);
2788 assert(exact);
2789 isl_map_free(map);
2791 map = isl_map_read_from_str(ctx,
2792 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2793 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2794 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2795 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2796 map = isl_map_transitive_closure(map, &exact);
2797 assert(exact);
2798 isl_map_free(map);
2800 /* Kelly et al 1996, fig 12 */
2801 map = isl_map_read_from_str(ctx,
2802 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2803 "1 <= i,j,j+1 <= n or "
2804 "j = n and j2 = 1 and i2 = i + 1 and "
2805 "1 <= i,i+1 <= n }");
2806 map = isl_map_transitive_closure(map, &exact);
2807 assert(exact);
2808 map2 = isl_map_read_from_str(ctx,
2809 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2810 "1 <= i <= n and i = i2 or "
2811 "1 <= i < i2 <= n and 1 <= j <= n and "
2812 "1 <= j2 <= n }");
2813 assert(isl_map_is_equal(map, map2));
2814 isl_map_free(map2);
2815 isl_map_free(map);
2817 /* Omega's closure4 */
2818 map = isl_map_read_from_str(ctx,
2819 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2820 "1 <= x,y <= 10 or "
2821 "x2 = x + 1 and y2 = y and "
2822 "1 <= x <= 20 && 5 <= y <= 15 }");
2823 map = isl_map_transitive_closure(map, &exact);
2824 assert(exact);
2825 isl_map_free(map);
2827 map = isl_map_read_from_str(ctx,
2828 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2829 map = isl_map_transitive_closure(map, &exact);
2830 assert(!exact);
2831 map2 = isl_map_read_from_str(ctx,
2832 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2833 assert(isl_map_is_equal(map, map2));
2834 isl_map_free(map);
2835 isl_map_free(map2);
2837 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2838 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2839 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2840 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2841 map = isl_map_read_from_str(ctx, str);
2842 map = isl_map_transitive_closure(map, &exact);
2843 assert(exact);
2844 map2 = isl_map_read_from_str(ctx, str);
2845 assert(isl_map_is_equal(map, map2));
2846 isl_map_free(map);
2847 isl_map_free(map2);
2849 str = "{[0] -> [1]; [2] -> [3]}";
2850 map = isl_map_read_from_str(ctx, str);
2851 map = isl_map_transitive_closure(map, &exact);
2852 assert(exact);
2853 map2 = isl_map_read_from_str(ctx, str);
2854 assert(isl_map_is_equal(map, map2));
2855 isl_map_free(map);
2856 isl_map_free(map2);
2858 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2859 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2860 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2861 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2862 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2863 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2864 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2865 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2866 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2867 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2868 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2869 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2870 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2871 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2872 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2873 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2874 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2875 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2876 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2877 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2878 map = isl_map_read_from_str(ctx, str);
2879 map = isl_map_transitive_closure(map, NULL);
2880 assert(map);
2881 isl_map_free(map);
2883 return 0;
2886 /* Check that the actual result of a boolean operation is equal
2887 * to the expected result.
2889 static isl_stat check_bool(isl_ctx *ctx, isl_bool actual, isl_bool expected)
2891 if (actual != expected)
2892 isl_die(ctx, isl_error_unknown,
2893 "incorrect boolean operation", return isl_stat_error);
2894 return isl_stat_ok;
2897 /* Test operations on isl_bool values.
2899 * This tests:
2901 * isl_bool_not
2902 * isl_bool_ok
2904 static int test_isl_bool(isl_ctx *ctx)
2906 if (check_bool(ctx, isl_bool_not(isl_bool_true), isl_bool_false) < 0)
2907 return -1;
2908 if (check_bool(ctx, isl_bool_not(isl_bool_false), isl_bool_true) < 0)
2909 return -1;
2910 if (check_bool(ctx, isl_bool_not(isl_bool_error), isl_bool_error) < 0)
2911 return -1;
2912 if (check_bool(ctx, isl_bool_ok(0), isl_bool_false) < 0)
2913 return -1;
2914 if (check_bool(ctx, isl_bool_ok(1), isl_bool_true) < 0)
2915 return -1;
2916 if (check_bool(ctx, isl_bool_ok(-1), isl_bool_true) < 0)
2917 return -1;
2918 if (check_bool(ctx, isl_bool_ok(2), isl_bool_true) < 0)
2919 return -1;
2920 if (check_bool(ctx, isl_bool_ok(-2), isl_bool_true) < 0)
2921 return -1;
2923 return 0;
2926 static int test_lex(struct isl_ctx *ctx)
2928 isl_space *space;
2929 isl_map *map;
2930 int empty;
2932 space = isl_space_set_alloc(ctx, 0, 0);
2933 map = isl_map_lex_le(space);
2934 empty = isl_map_is_empty(map);
2935 isl_map_free(map);
2937 if (empty < 0)
2938 return -1;
2939 if (empty)
2940 isl_die(ctx, isl_error_unknown,
2941 "expecting non-empty result", return -1);
2943 return 0;
2946 /* Inputs for isl_map_lexmin tests.
2947 * "map" is the input and "lexmin" is the expected result.
2949 struct {
2950 const char *map;
2951 const char *lexmin;
2952 } lexmin_tests [] = {
2953 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2954 "{ [x] -> [5] : 6 <= x <= 8; "
2955 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2956 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2957 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2958 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2959 "{ [x] -> [y] : (4y = x and x >= 0) or "
2960 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2961 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2962 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2963 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2964 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2965 /* Check that empty pieces are properly combined. */
2966 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2967 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2968 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2969 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2970 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2971 "x >= 4 }" },
2972 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2973 "a <= 255 and c <= 255 and d <= 255 - j and "
2974 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2975 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2976 "247d <= 247 + i and 248 - b <= 248d <= c and "
2977 "254d >= i - a + b and 254d >= -a + b and "
2978 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2979 "{ [i, k, j] -> "
2980 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2981 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2982 "247j >= 62738 - i and 509j <= 129795 + i and "
2983 "742j >= 188724 - i; "
2984 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2985 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2986 "16*floor((8 + b)/16) <= 7 + b; "
2987 "[a] -> [1] }",
2988 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2989 "[a] -> [b = 0] : 0 < a <= 509 }" },
2990 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2991 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2992 { "{ rat: [i] : 21 <= 2i <= 29 or i = 5 }", "{ rat: [5] }" },
2995 static int test_lexmin(struct isl_ctx *ctx)
2997 int i;
2998 int equal;
2999 const char *str;
3000 isl_basic_map *bmap;
3001 isl_map *map, *map2;
3002 isl_set *set;
3003 isl_set *set2;
3004 isl_pw_multi_aff *pma;
3006 str = "[p0, p1] -> { [] -> [] : "
3007 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
3008 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
3009 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
3010 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
3011 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
3012 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
3013 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
3014 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
3015 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
3016 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
3017 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
3018 map = isl_map_read_from_str(ctx, str);
3019 map = isl_map_lexmin(map);
3020 isl_map_free(map);
3021 if (!map)
3022 return -1;
3024 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
3025 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
3026 set = isl_set_read_from_str(ctx, str);
3027 set = isl_set_lexmax(set);
3028 str = "[C] -> { [obj,a,b,c] : C = 8 }";
3029 set2 = isl_set_read_from_str(ctx, str);
3030 set = isl_set_intersect(set, set2);
3031 assert(!isl_set_is_empty(set));
3032 isl_set_free(set);
3034 for (i = 0; i < ARRAY_SIZE(lexmin_tests); ++i) {
3035 map = isl_map_read_from_str(ctx, lexmin_tests[i].map);
3036 map = isl_map_lexmin(map);
3037 map2 = isl_map_read_from_str(ctx, lexmin_tests[i].lexmin);
3038 equal = isl_map_is_equal(map, map2);
3039 isl_map_free(map);
3040 isl_map_free(map2);
3042 if (equal < 0)
3043 return -1;
3044 if (!equal)
3045 isl_die(ctx, isl_error_unknown,
3046 "unexpected result", return -1);
3049 str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3050 " 8i' <= i and 8i' >= -7 + i }";
3051 bmap = isl_basic_map_read_from_str(ctx, str);
3052 pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap));
3053 map2 = isl_map_from_pw_multi_aff(pma);
3054 map = isl_map_from_basic_map(bmap);
3055 assert(isl_map_is_equal(map, map2));
3056 isl_map_free(map);
3057 isl_map_free(map2);
3059 str = "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
3060 " 8i' <= i and 8i' >= -7 + i }";
3061 set = isl_set_read_from_str(ctx, str);
3062 pma = isl_set_lexmin_pw_multi_aff(isl_set_copy(set));
3063 set2 = isl_set_from_pw_multi_aff(pma);
3064 equal = isl_set_is_equal(set, set2);
3065 isl_set_free(set);
3066 isl_set_free(set2);
3067 if (equal < 0)
3068 return -1;
3069 if (!equal)
3070 isl_die(ctx, isl_error_unknown,
3071 "unexpected difference between set and "
3072 "piecewise affine expression", return -1);
3074 return 0;
3077 /* Inputs for isl_pw_multi_aff_max_multi_val tests.
3078 * "pma" is the input.
3079 * "res" is the expected result.
3081 static struct {
3082 const char *pma;
3083 const char *res;
3084 } opt_pw_tests[] = {
3085 { "{ [-1] -> [-1]; [1] -> [1] }", "{ [1] }" },
3086 { "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] : "
3087 "0 <= a, b <= 100 and b mod 2 = 0}", "{ [30] }" },
3088 { "[N] -> { [i,j] -> A[i, -i, i + j] : 0 <= i,j <= N <= 10 }",
3089 "{ A[10, 0, 20] }" },
3090 { "[N] -> {A[N, -N, 2N] : 0 <= N }", "{ A[infty, 0, infty] }" },
3093 /* Perform basic isl_pw_multi_aff_max_multi_val tests.
3095 static isl_stat test_pw_max(struct isl_ctx *ctx)
3097 int i;
3098 isl_pw_multi_aff *pma;
3099 isl_multi_val *mv;
3100 isl_stat r;
3102 for (i = 0; i < ARRAY_SIZE(opt_pw_tests); ++i) {
3103 pma = isl_pw_multi_aff_read_from_str(ctx, opt_pw_tests[i].pma);
3104 mv = isl_pw_multi_aff_max_multi_val(pma);
3105 r = multi_val_check_plain_equal(mv, opt_pw_tests[i].res);
3106 isl_multi_val_free(mv);
3108 if (r < 0)
3109 return isl_stat_error;
3112 return isl_stat_ok;
3115 /* A specialized isl_set_min_val test case that would return the wrong result
3116 * in earlier versions of isl.
3117 * The explicit call to isl_basic_set_union prevents the second basic set
3118 * from being determined to be empty prior to the call to isl_set_min_val,
3119 * at least at the point where this test case was introduced.
3121 static int test_min_special(isl_ctx *ctx)
3123 const char *str;
3124 isl_basic_set *bset1, *bset2;
3125 isl_set *set;
3126 isl_aff *obj;
3127 isl_val *res;
3128 int ok;
3130 str = "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
3131 bset1 = isl_basic_set_read_from_str(ctx, str);
3132 str = "{ [a, b] : 1 <= a, b and a + b <= 1 }";
3133 bset2 = isl_basic_set_read_from_str(ctx, str);
3134 set = isl_basic_set_union(bset1, bset2);
3135 obj = isl_aff_read_from_str(ctx, "{ [a, b] -> [a] }");
3137 res = isl_set_min_val(set, obj);
3138 ok = isl_val_cmp_si(res, 5) == 0;
3140 isl_aff_free(obj);
3141 isl_set_free(set);
3142 isl_val_free(res);
3144 if (!res)
3145 return -1;
3146 if (!ok)
3147 isl_die(ctx, isl_error_unknown, "unexpected minimum",
3148 return -1);
3150 return 0;
3153 /* A specialized isl_set_min_val test case that would return an error
3154 * in earlier versions of isl.
3156 static int test_min_special2(isl_ctx *ctx)
3158 const char *str;
3159 isl_basic_set *bset;
3160 isl_aff *obj;
3161 isl_val *res;
3163 str = "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
3164 bset = isl_basic_set_read_from_str(ctx, str);
3166 obj = isl_aff_read_from_str(ctx, "{ [i, j, k] -> [i] }");
3168 res = isl_basic_set_max_val(bset, obj);
3170 isl_basic_set_free(bset);
3171 isl_aff_free(obj);
3172 isl_val_free(res);
3174 if (!res)
3175 return -1;
3177 return 0;
3180 struct {
3181 const char *set;
3182 const char *obj;
3183 __isl_give isl_val *(*fn)(__isl_keep isl_set *set,
3184 __isl_keep isl_aff *obj);
3185 const char *res;
3186 } opt_tests[] = {
3187 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val, "-1" },
3188 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val, "1" },
3189 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
3190 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
3191 &isl_set_max_val, "30" },
3195 /* Perform basic isl_set_min_val and isl_set_max_val tests.
3196 * In particular, check the results on non-convex inputs.
3198 static int test_min(struct isl_ctx *ctx)
3200 int i;
3201 isl_set *set;
3202 isl_aff *obj;
3203 isl_val *val, *res;
3204 isl_bool ok;
3206 for (i = 0; i < ARRAY_SIZE(opt_tests); ++i) {
3207 set = isl_set_read_from_str(ctx, opt_tests[i].set);
3208 obj = isl_aff_read_from_str(ctx, opt_tests[i].obj);
3209 res = isl_val_read_from_str(ctx, opt_tests[i].res);
3210 val = opt_tests[i].fn(set, obj);
3211 ok = isl_val_eq(res, val);
3212 isl_val_free(res);
3213 isl_val_free(val);
3214 isl_aff_free(obj);
3215 isl_set_free(set);
3217 if (ok < 0)
3218 return -1;
3219 if (!ok)
3220 isl_die(ctx, isl_error_unknown,
3221 "unexpected optimum", return -1);
3224 if (test_pw_max(ctx) < 0)
3225 return -1;
3226 if (test_min_special(ctx) < 0)
3227 return -1;
3228 if (test_min_special2(ctx) < 0)
3229 return -1;
3231 return 0;
3234 struct must_may {
3235 isl_map *must;
3236 isl_map *may;
3239 static isl_stat collect_must_may(__isl_take isl_map *dep, int must,
3240 void *dep_user, void *user)
3242 struct must_may *mm = (struct must_may *)user;
3244 if (must)
3245 mm->must = isl_map_union(mm->must, dep);
3246 else
3247 mm->may = isl_map_union(mm->may, dep);
3249 return isl_stat_ok;
3252 static int common_space(void *first, void *second)
3254 int depth = *(int *)first;
3255 return 2 * depth;
3258 static int map_is_equal(__isl_keep isl_map *map, const char *str)
3260 isl_map *map2;
3261 int equal;
3263 if (!map)
3264 return -1;
3266 map2 = isl_map_read_from_str(map->ctx, str);
3267 equal = isl_map_is_equal(map, map2);
3268 isl_map_free(map2);
3270 return equal;
3273 static int map_check_equal(__isl_keep isl_map *map, const char *str)
3275 int equal;
3277 equal = map_is_equal(map, str);
3278 if (equal < 0)
3279 return -1;
3280 if (!equal)
3281 isl_die(isl_map_get_ctx(map), isl_error_unknown,
3282 "result not as expected", return -1);
3283 return 0;
3286 /* Is "set" equal to the set described by "str"?
3288 static isl_bool set_is_equal(__isl_keep isl_set *set, const char *str)
3290 isl_set *set2;
3291 isl_bool equal;
3293 if (!set)
3294 return isl_bool_error;
3296 set2 = isl_set_read_from_str(isl_set_get_ctx(set), str);
3297 equal = isl_set_is_equal(set, set2);
3298 isl_set_free(set2);
3300 return equal;
3303 /* Check that "set" is equal to the set described by "str".
3305 static isl_stat set_check_equal(__isl_keep isl_set *set, const char *str)
3307 isl_bool equal;
3309 equal = set_is_equal(set, str);
3310 if (equal < 0)
3311 return isl_stat_error;
3312 if (!equal)
3313 isl_die(isl_set_get_ctx(set), isl_error_unknown,
3314 "result not as expected", return isl_stat_error);
3315 return isl_stat_ok;
3318 /* Is "uset" equal to the union set described by "str"?
3320 static isl_bool uset_is_equal(__isl_keep isl_union_set *uset, const char *str)
3322 isl_union_set *uset2;
3323 isl_bool equal;
3325 if (!uset)
3326 return isl_bool_error;
3328 uset2 = isl_union_set_read_from_str(isl_union_set_get_ctx(uset), str);
3329 equal = isl_union_set_is_equal(uset, uset2);
3330 isl_union_set_free(uset2);
3332 return equal;
3335 /* Check that "uset" is equal to the union set described by "str".
3337 static isl_stat uset_check_equal(__isl_keep isl_union_set *uset,
3338 const char *str)
3340 isl_bool equal;
3342 equal = uset_is_equal(uset, str);
3343 if (equal < 0)
3344 return isl_stat_error;
3345 if (!equal)
3346 isl_die(isl_union_set_get_ctx(uset), isl_error_unknown,
3347 "result not as expected", return isl_stat_error);
3348 return isl_stat_ok;
3351 static int test_dep(struct isl_ctx *ctx)
3353 const char *str;
3354 isl_space *space;
3355 isl_map *map;
3356 isl_access_info *ai;
3357 isl_flow *flow;
3358 int depth;
3359 struct must_may mm;
3361 depth = 3;
3363 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3364 map = isl_map_read_from_str(ctx, str);
3365 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3367 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3368 map = isl_map_read_from_str(ctx, str);
3369 ai = isl_access_info_add_source(ai, map, 1, &depth);
3371 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3372 map = isl_map_read_from_str(ctx, str);
3373 ai = isl_access_info_add_source(ai, map, 1, &depth);
3375 flow = isl_access_info_compute_flow(ai);
3376 space = isl_space_alloc(ctx, 0, 3, 3);
3377 mm.must = isl_map_empty(isl_space_copy(space));
3378 mm.may = isl_map_empty(space);
3380 isl_flow_foreach(flow, collect_must_may, &mm);
3382 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
3383 " [1,10,0] -> [2,5,0] }";
3384 assert(map_is_equal(mm.must, str));
3385 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3386 assert(map_is_equal(mm.may, str));
3388 isl_map_free(mm.must);
3389 isl_map_free(mm.may);
3390 isl_flow_free(flow);
3393 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3394 map = isl_map_read_from_str(ctx, str);
3395 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3397 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3398 map = isl_map_read_from_str(ctx, str);
3399 ai = isl_access_info_add_source(ai, map, 1, &depth);
3401 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3402 map = isl_map_read_from_str(ctx, str);
3403 ai = isl_access_info_add_source(ai, map, 0, &depth);
3405 flow = isl_access_info_compute_flow(ai);
3406 space = isl_space_alloc(ctx, 0, 3, 3);
3407 mm.must = isl_map_empty(isl_space_copy(space));
3408 mm.may = isl_map_empty(space);
3410 isl_flow_foreach(flow, collect_must_may, &mm);
3412 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
3413 assert(map_is_equal(mm.must, str));
3414 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3415 assert(map_is_equal(mm.may, str));
3417 isl_map_free(mm.must);
3418 isl_map_free(mm.may);
3419 isl_flow_free(flow);
3422 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3423 map = isl_map_read_from_str(ctx, str);
3424 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3426 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3427 map = isl_map_read_from_str(ctx, str);
3428 ai = isl_access_info_add_source(ai, map, 0, &depth);
3430 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3431 map = isl_map_read_from_str(ctx, str);
3432 ai = isl_access_info_add_source(ai, map, 0, &depth);
3434 flow = isl_access_info_compute_flow(ai);
3435 space = isl_space_alloc(ctx, 0, 3, 3);
3436 mm.must = isl_map_empty(isl_space_copy(space));
3437 mm.may = isl_map_empty(space);
3439 isl_flow_foreach(flow, collect_must_may, &mm);
3441 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
3442 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3443 assert(map_is_equal(mm.may, str));
3444 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3445 assert(map_is_equal(mm.must, str));
3447 isl_map_free(mm.must);
3448 isl_map_free(mm.may);
3449 isl_flow_free(flow);
3452 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
3453 map = isl_map_read_from_str(ctx, str);
3454 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3456 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3457 map = isl_map_read_from_str(ctx, str);
3458 ai = isl_access_info_add_source(ai, map, 0, &depth);
3460 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3461 map = isl_map_read_from_str(ctx, str);
3462 ai = isl_access_info_add_source(ai, map, 0, &depth);
3464 flow = isl_access_info_compute_flow(ai);
3465 space = isl_space_alloc(ctx, 0, 3, 3);
3466 mm.must = isl_map_empty(isl_space_copy(space));
3467 mm.may = isl_map_empty(space);
3469 isl_flow_foreach(flow, collect_must_may, &mm);
3471 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3472 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3473 assert(map_is_equal(mm.may, str));
3474 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3475 assert(map_is_equal(mm.must, str));
3477 isl_map_free(mm.must);
3478 isl_map_free(mm.may);
3479 isl_flow_free(flow);
3482 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3483 map = isl_map_read_from_str(ctx, str);
3484 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3486 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3487 map = isl_map_read_from_str(ctx, str);
3488 ai = isl_access_info_add_source(ai, map, 0, &depth);
3490 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3491 map = isl_map_read_from_str(ctx, str);
3492 ai = isl_access_info_add_source(ai, map, 0, &depth);
3494 flow = isl_access_info_compute_flow(ai);
3495 space = isl_space_alloc(ctx, 0, 3, 3);
3496 mm.must = isl_map_empty(isl_space_copy(space));
3497 mm.may = isl_map_empty(space);
3499 isl_flow_foreach(flow, collect_must_may, &mm);
3501 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3502 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3503 assert(map_is_equal(mm.may, str));
3504 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3505 assert(map_is_equal(mm.must, str));
3507 isl_map_free(mm.must);
3508 isl_map_free(mm.may);
3509 isl_flow_free(flow);
3512 depth = 5;
3514 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3515 map = isl_map_read_from_str(ctx, str);
3516 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
3518 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3519 map = isl_map_read_from_str(ctx, str);
3520 ai = isl_access_info_add_source(ai, map, 1, &depth);
3522 flow = isl_access_info_compute_flow(ai);
3523 space = isl_space_alloc(ctx, 0, 5, 5);
3524 mm.must = isl_map_empty(isl_space_copy(space));
3525 mm.may = isl_map_empty(space);
3527 isl_flow_foreach(flow, collect_must_may, &mm);
3529 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3530 assert(map_is_equal(mm.must, str));
3531 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3532 assert(map_is_equal(mm.may, str));
3534 isl_map_free(mm.must);
3535 isl_map_free(mm.may);
3536 isl_flow_free(flow);
3538 return 0;
3541 /* Check that the dependence analysis proceeds without errors.
3542 * Earlier versions of isl would break down during the analysis
3543 * due to the use of the wrong spaces.
3545 static int test_flow(isl_ctx *ctx)
3547 const char *str;
3548 isl_union_map *access, *schedule;
3549 isl_union_map *must_dep, *may_dep;
3550 int r;
3552 str = "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3553 access = isl_union_map_read_from_str(ctx, str);
3554 str = "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3555 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3556 "S2[] -> [1,0,0,0]; "
3557 "S3[] -> [-1,0,0,0] }";
3558 schedule = isl_union_map_read_from_str(ctx, str);
3559 r = isl_union_map_compute_flow(access, isl_union_map_copy(access),
3560 isl_union_map_copy(access), schedule,
3561 &must_dep, &may_dep, NULL, NULL);
3562 isl_union_map_free(may_dep);
3563 isl_union_map_free(must_dep);
3565 return r;
3568 struct {
3569 const char *map;
3570 int sv;
3571 } sv_tests[] = {
3572 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3573 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3574 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3575 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3576 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3577 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3578 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3579 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3580 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3583 int test_sv(isl_ctx *ctx)
3585 isl_union_map *umap;
3586 int i;
3587 int sv;
3589 for (i = 0; i < ARRAY_SIZE(sv_tests); ++i) {
3590 umap = isl_union_map_read_from_str(ctx, sv_tests[i].map);
3591 sv = isl_union_map_is_single_valued(umap);
3592 isl_union_map_free(umap);
3593 if (sv < 0)
3594 return -1;
3595 if (sv_tests[i].sv && !sv)
3596 isl_die(ctx, isl_error_internal,
3597 "map not detected as single valued", return -1);
3598 if (!sv_tests[i].sv && sv)
3599 isl_die(ctx, isl_error_internal,
3600 "map detected as single valued", return -1);
3603 return 0;
3606 struct {
3607 const char *str;
3608 int bijective;
3609 } bijective_tests[] = {
3610 { "[N,M]->{[i,j] -> [i]}", 0 },
3611 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3612 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3613 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3614 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3615 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3616 { "[N,M]->{[i,j] -> []}", 0 },
3617 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3618 { "[N,M]->{[i,j] -> [2i]}", 0 },
3619 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3620 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3621 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3622 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3625 static int test_bijective(struct isl_ctx *ctx)
3627 isl_map *map;
3628 int i;
3629 int bijective;
3631 for (i = 0; i < ARRAY_SIZE(bijective_tests); ++i) {
3632 map = isl_map_read_from_str(ctx, bijective_tests[i].str);
3633 bijective = isl_map_is_bijective(map);
3634 isl_map_free(map);
3635 if (bijective < 0)
3636 return -1;
3637 if (bijective_tests[i].bijective && !bijective)
3638 isl_die(ctx, isl_error_internal,
3639 "map not detected as bijective", return -1);
3640 if (!bijective_tests[i].bijective && bijective)
3641 isl_die(ctx, isl_error_internal,
3642 "map detected as bijective", return -1);
3645 return 0;
3648 /* Inputs for isl_pw_qpolynomial_gist tests.
3649 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3651 struct {
3652 const char *pwqp;
3653 const char *set;
3654 const char *gist;
3655 } pwqp_gist_tests[] = {
3656 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3657 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3658 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3659 "{ [i] -> -1/2 + 1/2 * i }" },
3660 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3663 /* Perform some basic isl_pw_qpolynomial_gist tests.
3665 static isl_stat test_pwqp_gist(isl_ctx *ctx)
3667 int i;
3668 const char *str;
3669 isl_set *set;
3670 isl_pw_qpolynomial *pwqp1, *pwqp2;
3671 isl_bool equal;
3673 for (i = 0; i < ARRAY_SIZE(pwqp_gist_tests); ++i) {
3674 str = pwqp_gist_tests[i].pwqp;
3675 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3676 str = pwqp_gist_tests[i].set;
3677 set = isl_set_read_from_str(ctx, str);
3678 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
3679 str = pwqp_gist_tests[i].gist;
3680 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3681 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3682 equal = isl_pw_qpolynomial_is_zero(pwqp1);
3683 isl_pw_qpolynomial_free(pwqp1);
3685 if (equal < 0)
3686 return isl_stat_error;
3687 if (!equal)
3688 isl_die(ctx, isl_error_unknown,
3689 "unexpected result", return isl_stat_error);
3692 return isl_stat_ok;
3695 /* Perform a basic isl_pw_qpolynomial_max test.
3697 static isl_stat test_pwqp_max(isl_ctx *ctx)
3699 const char *str;
3700 isl_pw_qpolynomial *pwqp;
3701 isl_val *v;
3702 int ok;
3704 str = "{ [x=2:9, y] -> floor((x + 1)/4)^3 - floor((2x)/3)^2 }";
3705 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3706 v = isl_pw_qpolynomial_max(pwqp);
3707 ok = isl_val_cmp_si(v, -1) == 0;
3708 isl_val_free(v);
3710 if (!v)
3711 return isl_stat_error;
3712 if (!ok)
3713 isl_die(ctx, isl_error_unknown, "unexpected maximum",
3714 return isl_stat_error);
3716 return isl_stat_ok;
3719 static int test_pwqp(struct isl_ctx *ctx)
3721 const char *str;
3722 isl_set *set;
3723 isl_pw_qpolynomial *pwqp1, *pwqp2;
3724 int equal;
3726 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3727 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3729 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
3730 isl_dim_in, 1, 1);
3732 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3733 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3735 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3737 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3739 isl_pw_qpolynomial_free(pwqp1);
3741 if (test_pwqp_gist(ctx) < 0)
3742 return -1;
3744 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
3745 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3746 str = "{ [i] -> ([(2 * [i/2])/5]) }";
3747 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3749 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3751 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3753 isl_pw_qpolynomial_free(pwqp1);
3755 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
3756 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3757 str = "{ [x] -> x }";
3758 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3760 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3762 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3764 isl_pw_qpolynomial_free(pwqp1);
3766 str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3767 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3768 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3769 pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
3770 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3771 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3772 isl_pw_qpolynomial_free(pwqp1);
3774 str = "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3775 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3776 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3777 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3778 set = isl_set_read_from_str(ctx, "{ [a,b,a] }");
3779 pwqp1 = isl_pw_qpolynomial_intersect_domain(pwqp1, set);
3780 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
3781 isl_pw_qpolynomial_free(pwqp1);
3782 isl_pw_qpolynomial_free(pwqp2);
3783 if (equal < 0)
3784 return -1;
3785 if (!equal)
3786 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3788 str = "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3789 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3790 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3791 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3792 pwqp1 = isl_pw_qpolynomial_fix_val(pwqp1, isl_dim_set, 1,
3793 isl_val_one(ctx));
3794 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
3795 isl_pw_qpolynomial_free(pwqp1);
3796 isl_pw_qpolynomial_free(pwqp2);
3797 if (equal < 0)
3798 return -1;
3799 if (!equal)
3800 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3802 if (test_pwqp_max(ctx) < 0)
3803 return -1;
3805 return 0;
3808 static int test_split_periods(isl_ctx *ctx)
3810 const char *str;
3811 isl_pw_qpolynomial *pwqp;
3813 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3814 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3815 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3816 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3818 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
3820 isl_pw_qpolynomial_free(pwqp);
3822 if (!pwqp)
3823 return -1;
3825 return 0;
3828 static int test_union(isl_ctx *ctx)
3830 const char *str;
3831 isl_union_set *uset1, *uset2;
3832 isl_union_map *umap1, *umap2;
3833 int equal;
3835 str = "{ [i] : 0 <= i <= 1 }";
3836 uset1 = isl_union_set_read_from_str(ctx, str);
3837 str = "{ [1] -> [0] }";
3838 umap1 = isl_union_map_read_from_str(ctx, str);
3840 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
3841 equal = isl_union_map_is_equal(umap1, umap2);
3843 isl_union_map_free(umap1);
3844 isl_union_map_free(umap2);
3846 if (equal < 0)
3847 return -1;
3848 if (!equal)
3849 isl_die(ctx, isl_error_unknown, "union maps not equal",
3850 return -1);
3852 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3853 umap1 = isl_union_map_read_from_str(ctx, str);
3854 str = "{ A[i]; B[i] }";
3855 uset1 = isl_union_set_read_from_str(ctx, str);
3857 uset2 = isl_union_map_domain(umap1);
3859 equal = isl_union_set_is_equal(uset1, uset2);
3861 isl_union_set_free(uset1);
3862 isl_union_set_free(uset2);
3864 if (equal < 0)
3865 return -1;
3866 if (!equal)
3867 isl_die(ctx, isl_error_unknown, "union sets not equal",
3868 return -1);
3870 return 0;
3873 /* Check that computing a bound of a non-zero polynomial over an unbounded
3874 * domain does not produce a rational value.
3875 * In particular, check that the upper bound is infinity.
3877 static int test_bound_unbounded_domain(isl_ctx *ctx)
3879 const char *str;
3880 isl_pw_qpolynomial *pwqp;
3881 isl_pw_qpolynomial_fold *pwf, *pwf2;
3882 isl_bool equal;
3884 str = "{ [m,n] -> -m * n }";
3885 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3886 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3887 str = "{ infty }";
3888 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3889 pwf2 = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3890 equal = isl_pw_qpolynomial_fold_plain_is_equal(pwf, pwf2);
3891 isl_pw_qpolynomial_fold_free(pwf);
3892 isl_pw_qpolynomial_fold_free(pwf2);
3894 if (equal < 0)
3895 return -1;
3896 if (!equal)
3897 isl_die(ctx, isl_error_unknown,
3898 "expecting infinite polynomial bound", return -1);
3900 return 0;
3903 static int test_bound(isl_ctx *ctx)
3905 const char *str;
3906 isl_size dim;
3907 isl_pw_qpolynomial *pwqp;
3908 isl_pw_qpolynomial_fold *pwf;
3910 if (test_bound_unbounded_domain(ctx) < 0)
3911 return -1;
3913 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
3914 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3915 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3916 dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in);
3917 isl_pw_qpolynomial_fold_free(pwf);
3918 if (dim < 0)
3919 return -1;
3920 if (dim != 4)
3921 isl_die(ctx, isl_error_unknown, "unexpected input dimension",
3922 return -1);
3924 str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3925 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3926 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3927 dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in);
3928 isl_pw_qpolynomial_fold_free(pwf);
3929 if (dim < 0)
3930 return -1;
3931 if (dim != 1)
3932 isl_die(ctx, isl_error_unknown, "unexpected input dimension",
3933 return -1);
3935 return 0;
3938 /* isl_set is defined to isl_map internally, so the corresponding elements
3939 * are isl_basic_map objects.
3941 #undef EL_BASE
3942 #undef SET_BASE
3943 #define EL_BASE basic_map
3944 #define SET_BASE set
3945 #include "isl_test_list_templ.c"
3947 #undef EL_BASE
3948 #undef SET_BASE
3949 #define EL_BASE basic_set
3950 #define SET_BASE union_set
3951 #include "isl_test_list_templ.c"
3953 #undef EL_BASE
3954 #undef SET_BASE
3955 #define EL_BASE set
3956 #define SET_BASE union_set
3957 #include "isl_test_list_templ.c"
3959 #undef EL_BASE
3960 #undef SET_BASE
3961 #define EL_BASE basic_map
3962 #define SET_BASE map
3963 #include "isl_test_list_templ.c"
3965 #undef EL_BASE
3966 #undef SET_BASE
3967 #define EL_BASE map
3968 #define SET_BASE union_map
3969 #include "isl_test_list_templ.c"
3971 /* Check that the conversion from isl objects to lists works as expected.
3973 static int test_get_list(isl_ctx *ctx)
3975 if (test_get_list_basic_map_from_set(ctx, "{ [0]; [2]; [3] }"))
3976 return -1;
3977 if (test_get_list_basic_set_from_union_set(ctx, "{ A[0]; B[2]; B[3] }"))
3978 return -1;
3979 if (test_get_list_set_from_union_set(ctx, "{ A[0]; A[2]; B[3] }"))
3980 return -1;
3981 if (test_get_list_basic_map_from_map(ctx,
3982 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"))
3983 return -1;
3984 if (test_get_list_map_from_union_map(ctx,
3985 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"))
3986 return -1;
3988 return 0;
3991 static int test_lift(isl_ctx *ctx)
3993 const char *str;
3994 isl_basic_map *bmap;
3995 isl_basic_set *bset;
3997 str = "{ [i0] : exists e0 : i0 = 4e0 }";
3998 bset = isl_basic_set_read_from_str(ctx, str);
3999 bset = isl_basic_set_lift(bset);
4000 bmap = isl_basic_map_from_range(bset);
4001 bset = isl_basic_map_domain(bmap);
4002 isl_basic_set_free(bset);
4004 return 0;
4007 /* Check that isl_set_is_subset is not confused by identical
4008 * integer divisions.
4009 * The call to isl_set_normalize ensures that the equality constraints
4010 * a = b = 0 are discovered, turning e0 and e1 into identical
4011 * integer divisions. Any further simplification would remove
4012 * the duplicate integer divisions.
4014 static isl_stat test_subset_duplicate_integer_divisions(isl_ctx *ctx)
4016 const char *str;
4017 isl_bool is_subset;
4018 isl_set *set1, *set2;
4020 str = "{ [a, b, c, d] : "
4021 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
4022 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
4023 "e3 = floor((-d + 4*floor((d)/4))/10): "
4024 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
4025 "b >= 0 and a <= 0 and b <= a) }";
4026 set1 = isl_set_read_from_str(ctx, str);
4027 set2 = isl_set_read_from_str(ctx, str);
4028 set2 = isl_set_normalize(set2);
4030 is_subset = isl_set_is_subset(set1, set2);
4032 isl_set_free(set1);
4033 isl_set_free(set2);
4035 if (is_subset < 0)
4036 return isl_stat_error;
4037 if (!is_subset)
4038 isl_die(ctx, isl_error_unknown,
4039 "set is not considered to be a subset of itself",
4040 return isl_stat_error);
4042 return isl_stat_ok;
4045 struct {
4046 const char *set1;
4047 const char *set2;
4048 int subset;
4049 } subset_tests[] = {
4050 { "{ [112, 0] }",
4051 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
4052 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
4053 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
4054 { "{ [65] }",
4055 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
4056 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
4057 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
4058 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
4059 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
4060 "256e0 <= 255i and 256e0 >= -255 + 255i and "
4061 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
4062 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
4063 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
4064 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
4065 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
4066 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
4067 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
4068 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
4069 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
4070 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
4071 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
4072 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
4073 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
4074 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
4075 "4e0 <= -57 + i0 + i1)) or "
4076 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
4077 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
4078 "4e0 >= -61 + i0 + i1)) or "
4079 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
4080 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
4083 static int test_subset(isl_ctx *ctx)
4085 int i;
4086 isl_set *set1, *set2;
4087 int subset;
4089 if (test_subset_duplicate_integer_divisions(ctx) < 0)
4090 return -1;
4092 for (i = 0; i < ARRAY_SIZE(subset_tests); ++i) {
4093 set1 = isl_set_read_from_str(ctx, subset_tests[i].set1);
4094 set2 = isl_set_read_from_str(ctx, subset_tests[i].set2);
4095 subset = isl_set_is_subset(set1, set2);
4096 isl_set_free(set1);
4097 isl_set_free(set2);
4098 if (subset < 0)
4099 return -1;
4100 if (subset != subset_tests[i].subset)
4101 isl_die(ctx, isl_error_unknown,
4102 "incorrect subset result", return -1);
4105 return 0;
4108 /* Perform a set subtraction with a set that has a non-obviously empty disjunct.
4109 * Older versions of isl would fail on such cases.
4111 static isl_stat test_subtract_empty(isl_ctx *ctx)
4113 const char *str;
4114 isl_set *s1, *s2;
4116 s1 = isl_set_read_from_str(ctx, "{ [0] }");
4117 str = "{ [a] : (exists (e0, e1, e2: 1056e1 <= 32 + a - 33e0 and "
4118 "1089e1 >= a - 33e0 and 1089e1 <= 1 + a - 33e0 and "
4119 "33e2 >= -a + 33e0 + 1056e1 and "
4120 "33e2 < -2a + 66e0 + 2112e1)) or a = 0 }";
4121 s2 = isl_set_read_from_str(ctx, str);
4122 s1 = isl_set_subtract(s1, s2);
4123 isl_set_free(s1);
4125 return isl_stat_non_null(s1);
4128 struct {
4129 const char *minuend;
4130 const char *subtrahend;
4131 const char *difference;
4132 } subtract_domain_tests[] = {
4133 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
4134 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
4135 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
4138 static int test_subtract(isl_ctx *ctx)
4140 int i;
4141 isl_union_map *umap1, *umap2;
4142 isl_union_pw_multi_aff *upma1, *upma2;
4143 isl_union_set *uset;
4144 int equal;
4146 if (test_subtract_empty(ctx) < 0)
4147 return -1;
4149 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests); ++i) {
4150 umap1 = isl_union_map_read_from_str(ctx,
4151 subtract_domain_tests[i].minuend);
4152 uset = isl_union_set_read_from_str(ctx,
4153 subtract_domain_tests[i].subtrahend);
4154 umap2 = isl_union_map_read_from_str(ctx,
4155 subtract_domain_tests[i].difference);
4156 umap1 = isl_union_map_subtract_domain(umap1, uset);
4157 equal = isl_union_map_is_equal(umap1, umap2);
4158 isl_union_map_free(umap1);
4159 isl_union_map_free(umap2);
4160 if (equal < 0)
4161 return -1;
4162 if (!equal)
4163 isl_die(ctx, isl_error_unknown,
4164 "incorrect subtract domain result", return -1);
4167 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests); ++i) {
4168 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
4169 subtract_domain_tests[i].minuend);
4170 uset = isl_union_set_read_from_str(ctx,
4171 subtract_domain_tests[i].subtrahend);
4172 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
4173 subtract_domain_tests[i].difference);
4174 upma1 = isl_union_pw_multi_aff_subtract_domain(upma1, uset);
4175 equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2);
4176 isl_union_pw_multi_aff_free(upma1);
4177 isl_union_pw_multi_aff_free(upma2);
4178 if (equal < 0)
4179 return -1;
4180 if (!equal)
4181 isl_die(ctx, isl_error_unknown,
4182 "incorrect subtract domain result", return -1);
4185 return 0;
4188 /* Check that intersecting the empty basic set with another basic set
4189 * does not increase the number of constraints. In particular,
4190 * the empty basic set should maintain its canonical representation.
4192 static int test_intersect_1(isl_ctx *ctx)
4194 isl_size n1, n2;
4195 isl_basic_set *bset1, *bset2;
4197 bset1 = isl_basic_set_read_from_str(ctx, "{ [a,b,c] : 1 = 0 }");
4198 bset2 = isl_basic_set_read_from_str(ctx, "{ [1,2,3] }");
4199 n1 = isl_basic_set_n_constraint(bset1);
4200 bset1 = isl_basic_set_intersect(bset1, bset2);
4201 n2 = isl_basic_set_n_constraint(bset1);
4202 isl_basic_set_free(bset1);
4203 if (n1 < 0 || n2 < 0)
4204 return -1;
4205 if (n1 != n2)
4206 isl_die(ctx, isl_error_unknown,
4207 "number of constraints of empty set changed",
4208 return -1);
4210 return 0;
4213 /* Check that intersecting a set with itself does not cause
4214 * an explosion in the number of disjuncts.
4216 static isl_stat test_intersect_2(isl_ctx *ctx)
4218 int i;
4219 isl_set *set;
4221 set = isl_set_read_from_str(ctx, "{ [x,y] : x >= 0 or y >= 0 }");
4222 for (i = 0; i < 100; ++i)
4223 set = isl_set_intersect(set, isl_set_copy(set));
4224 isl_set_free(set);
4225 if (!set)
4226 return isl_stat_error;
4227 return isl_stat_ok;
4230 /* Perform some intersection tests.
4232 static int test_intersect(isl_ctx *ctx)
4234 if (test_intersect_1(ctx) < 0)
4235 return -1;
4236 if (test_intersect_2(ctx) < 0)
4237 return -1;
4239 return 0;
4242 int test_factorize(isl_ctx *ctx)
4244 const char *str;
4245 isl_basic_set *bset;
4246 isl_factorizer *f;
4248 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
4249 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
4250 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
4251 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
4252 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
4253 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
4254 "3i5 >= -2i0 - i2 + 3i4 }";
4255 bset = isl_basic_set_read_from_str(ctx, str);
4256 f = isl_basic_set_factorizer(bset);
4257 isl_basic_set_free(bset);
4258 isl_factorizer_free(f);
4259 if (!f)
4260 isl_die(ctx, isl_error_unknown,
4261 "failed to construct factorizer", return -1);
4263 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
4264 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
4265 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
4266 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
4267 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
4268 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
4269 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
4270 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
4271 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
4272 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
4273 bset = isl_basic_set_read_from_str(ctx, str);
4274 f = isl_basic_set_factorizer(bset);
4275 isl_basic_set_free(bset);
4276 isl_factorizer_free(f);
4277 if (!f)
4278 isl_die(ctx, isl_error_unknown,
4279 "failed to construct factorizer", return -1);
4281 return 0;
4284 static isl_stat check_injective(__isl_take isl_map *map, void *user)
4286 int *injective = user;
4288 *injective = isl_map_is_injective(map);
4289 isl_map_free(map);
4291 if (*injective < 0 || !*injective)
4292 return isl_stat_error;
4294 return isl_stat_ok;
4297 int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
4298 const char *r, const char *s, int tilable, int parallel)
4300 int i;
4301 isl_union_set *D;
4302 isl_union_map *W, *R, *S;
4303 isl_union_map *empty;
4304 isl_union_map *dep_raw, *dep_war, *dep_waw, *dep;
4305 isl_union_map *validity, *proximity, *coincidence;
4306 isl_union_map *schedule;
4307 isl_union_map *test;
4308 isl_union_set *delta;
4309 isl_union_set *domain;
4310 isl_set *delta_set;
4311 isl_set *slice;
4312 isl_set *origin;
4313 isl_schedule_constraints *sc;
4314 isl_schedule *sched;
4315 int is_nonneg, is_parallel, is_tilable, is_injection, is_complete;
4316 isl_size n;
4318 D = isl_union_set_read_from_str(ctx, d);
4319 W = isl_union_map_read_from_str(ctx, w);
4320 R = isl_union_map_read_from_str(ctx, r);
4321 S = isl_union_map_read_from_str(ctx, s);
4323 W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
4324 R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
4326 empty = isl_union_map_empty(isl_union_map_get_space(S));
4327 isl_union_map_compute_flow(isl_union_map_copy(R),
4328 isl_union_map_copy(W), empty,
4329 isl_union_map_copy(S),
4330 &dep_raw, NULL, NULL, NULL);
4331 isl_union_map_compute_flow(isl_union_map_copy(W),
4332 isl_union_map_copy(W),
4333 isl_union_map_copy(R),
4334 isl_union_map_copy(S),
4335 &dep_waw, &dep_war, NULL, NULL);
4337 dep = isl_union_map_union(dep_waw, dep_war);
4338 dep = isl_union_map_union(dep, dep_raw);
4339 validity = isl_union_map_copy(dep);
4340 coincidence = isl_union_map_copy(dep);
4341 proximity = isl_union_map_copy(dep);
4343 sc = isl_schedule_constraints_on_domain(isl_union_set_copy(D));
4344 sc = isl_schedule_constraints_set_validity(sc, validity);
4345 sc = isl_schedule_constraints_set_coincidence(sc, coincidence);
4346 sc = isl_schedule_constraints_set_proximity(sc, proximity);
4347 sched = isl_schedule_constraints_compute_schedule(sc);
4348 schedule = isl_schedule_get_map(sched);
4349 isl_schedule_free(sched);
4350 isl_union_map_free(W);
4351 isl_union_map_free(R);
4352 isl_union_map_free(S);
4354 is_injection = 1;
4355 isl_union_map_foreach_map(schedule, &check_injective, &is_injection);
4357 domain = isl_union_map_domain(isl_union_map_copy(schedule));
4358 is_complete = isl_union_set_is_subset(D, domain);
4359 isl_union_set_free(D);
4360 isl_union_set_free(domain);
4362 test = isl_union_map_reverse(isl_union_map_copy(schedule));
4363 test = isl_union_map_apply_range(test, dep);
4364 test = isl_union_map_apply_range(test, schedule);
4366 delta = isl_union_map_deltas(test);
4367 n = isl_union_set_n_set(delta);
4368 if (n < 0) {
4369 isl_union_set_free(delta);
4370 return -1;
4372 if (n == 0) {
4373 is_tilable = 1;
4374 is_parallel = 1;
4375 is_nonneg = 1;
4376 isl_union_set_free(delta);
4377 } else {
4378 isl_size dim;
4380 delta_set = isl_set_from_union_set(delta);
4382 slice = isl_set_universe(isl_set_get_space(delta_set));
4383 for (i = 0; i < tilable; ++i)
4384 slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
4385 is_tilable = isl_set_is_subset(delta_set, slice);
4386 isl_set_free(slice);
4388 slice = isl_set_universe(isl_set_get_space(delta_set));
4389 for (i = 0; i < parallel; ++i)
4390 slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
4391 is_parallel = isl_set_is_subset(delta_set, slice);
4392 isl_set_free(slice);
4394 origin = isl_set_universe(isl_set_get_space(delta_set));
4395 dim = isl_set_dim(origin, isl_dim_set);
4396 if (dim < 0)
4397 origin = isl_set_free(origin);
4398 for (i = 0; i < dim; ++i)
4399 origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
4401 delta_set = isl_set_union(delta_set, isl_set_copy(origin));
4402 delta_set = isl_set_lexmin(delta_set);
4404 is_nonneg = isl_set_is_equal(delta_set, origin);
4406 isl_set_free(origin);
4407 isl_set_free(delta_set);
4410 if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
4411 is_injection < 0 || is_complete < 0)
4412 return -1;
4413 if (!is_complete)
4414 isl_die(ctx, isl_error_unknown,
4415 "generated schedule incomplete", return -1);
4416 if (!is_injection)
4417 isl_die(ctx, isl_error_unknown,
4418 "generated schedule not injective on each statement",
4419 return -1);
4420 if (!is_nonneg)
4421 isl_die(ctx, isl_error_unknown,
4422 "negative dependences in generated schedule",
4423 return -1);
4424 if (!is_tilable)
4425 isl_die(ctx, isl_error_unknown,
4426 "generated schedule not as tilable as expected",
4427 return -1);
4428 if (!is_parallel)
4429 isl_die(ctx, isl_error_unknown,
4430 "generated schedule not as parallel as expected",
4431 return -1);
4433 return 0;
4436 /* Compute a schedule for the given instance set, validity constraints,
4437 * proximity constraints and context and return a corresponding union map
4438 * representation.
4440 static __isl_give isl_union_map *compute_schedule_with_context(isl_ctx *ctx,
4441 const char *domain, const char *validity, const char *proximity,
4442 const char *context)
4444 isl_set *con;
4445 isl_union_set *dom;
4446 isl_union_map *dep;
4447 isl_union_map *prox;
4448 isl_schedule_constraints *sc;
4449 isl_schedule *schedule;
4450 isl_union_map *sched;
4452 con = isl_set_read_from_str(ctx, context);
4453 dom = isl_union_set_read_from_str(ctx, domain);
4454 dep = isl_union_map_read_from_str(ctx, validity);
4455 prox = isl_union_map_read_from_str(ctx, proximity);
4456 sc = isl_schedule_constraints_on_domain(dom);
4457 sc = isl_schedule_constraints_set_context(sc, con);
4458 sc = isl_schedule_constraints_set_validity(sc, dep);
4459 sc = isl_schedule_constraints_set_proximity(sc, prox);
4460 schedule = isl_schedule_constraints_compute_schedule(sc);
4461 sched = isl_schedule_get_map(schedule);
4462 isl_schedule_free(schedule);
4464 return sched;
4467 /* Compute a schedule for the given instance set, validity constraints and
4468 * proximity constraints and return a corresponding union map representation.
4470 static __isl_give isl_union_map *compute_schedule(isl_ctx *ctx,
4471 const char *domain, const char *validity, const char *proximity)
4473 return compute_schedule_with_context(ctx, domain, validity, proximity,
4474 "{ : }");
4477 /* Check that a schedule can be constructed on the given domain
4478 * with the given validity and proximity constraints.
4480 static int test_has_schedule(isl_ctx *ctx, const char *domain,
4481 const char *validity, const char *proximity)
4483 isl_union_map *sched;
4485 sched = compute_schedule(ctx, domain, validity, proximity);
4486 if (!sched)
4487 return -1;
4489 isl_union_map_free(sched);
4490 return 0;
4493 int test_special_schedule(isl_ctx *ctx, const char *domain,
4494 const char *validity, const char *proximity, const char *expected_sched)
4496 isl_union_map *sched1, *sched2;
4497 int equal;
4499 sched1 = compute_schedule(ctx, domain, validity, proximity);
4500 sched2 = isl_union_map_read_from_str(ctx, expected_sched);
4502 equal = isl_union_map_is_equal(sched1, sched2);
4503 isl_union_map_free(sched1);
4504 isl_union_map_free(sched2);
4506 if (equal < 0)
4507 return -1;
4508 if (!equal)
4509 isl_die(ctx, isl_error_unknown, "unexpected schedule",
4510 return -1);
4512 return 0;
4515 /* Check that the schedule map is properly padded, i.e., that the range
4516 * lives in a single space.
4518 static int test_padded_schedule(isl_ctx *ctx)
4520 const char *str;
4521 isl_union_set *D;
4522 isl_union_map *validity, *proximity;
4523 isl_schedule_constraints *sc;
4524 isl_schedule *sched;
4525 isl_union_map *umap;
4526 isl_union_set *range;
4527 isl_set *set;
4529 str = "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4530 D = isl_union_set_read_from_str(ctx, str);
4531 validity = isl_union_map_empty(isl_union_set_get_space(D));
4532 proximity = isl_union_map_copy(validity);
4533 sc = isl_schedule_constraints_on_domain(D);
4534 sc = isl_schedule_constraints_set_validity(sc, validity);
4535 sc = isl_schedule_constraints_set_proximity(sc, proximity);
4536 sched = isl_schedule_constraints_compute_schedule(sc);
4537 umap = isl_schedule_get_map(sched);
4538 isl_schedule_free(sched);
4539 range = isl_union_map_range(umap);
4540 set = isl_set_from_union_set(range);
4541 isl_set_free(set);
4543 if (!set)
4544 return -1;
4546 return 0;
4549 /* Check that conditional validity constraints are also taken into
4550 * account across bands.
4551 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4552 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4553 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4554 * is enforced by the rest of the schedule.
4556 static int test_special_conditional_schedule_constraints(isl_ctx *ctx)
4558 const char *str;
4559 isl_union_set *domain;
4560 isl_union_map *validity, *proximity, *condition;
4561 isl_union_map *sink, *source, *dep;
4562 isl_schedule_constraints *sc;
4563 isl_schedule *schedule;
4564 isl_union_access_info *access;
4565 isl_union_flow *flow;
4566 int empty;
4568 str = "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4569 "A[k] : k >= 1 and k <= -1 + n; "
4570 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4571 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4572 domain = isl_union_set_read_from_str(ctx, str);
4573 sc = isl_schedule_constraints_on_domain(domain);
4574 str = "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4575 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4576 "D[k, i] -> C[1 + k, i] : "
4577 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4578 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4579 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4580 validity = isl_union_map_read_from_str(ctx, str);
4581 sc = isl_schedule_constraints_set_validity(sc, validity);
4582 str = "[n] -> { C[k, i] -> D[k, i] : "
4583 "0 <= i <= -1 + k and k <= -1 + n }";
4584 proximity = isl_union_map_read_from_str(ctx, str);
4585 sc = isl_schedule_constraints_set_proximity(sc, proximity);
4586 str = "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4587 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4588 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4589 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4590 condition = isl_union_map_read_from_str(ctx, str);
4591 str = "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4592 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4593 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4594 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4595 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4596 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4597 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4598 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4599 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4600 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4601 validity = isl_union_map_read_from_str(ctx, str);
4602 sc = isl_schedule_constraints_set_conditional_validity(sc, condition,
4603 validity);
4604 schedule = isl_schedule_constraints_compute_schedule(sc);
4605 str = "{ D[2,0] -> [] }";
4606 sink = isl_union_map_read_from_str(ctx, str);
4607 access = isl_union_access_info_from_sink(sink);
4608 str = "{ C[2,1] -> [] }";
4609 source = isl_union_map_read_from_str(ctx, str);
4610 access = isl_union_access_info_set_must_source(access, source);
4611 access = isl_union_access_info_set_schedule(access, schedule);
4612 flow = isl_union_access_info_compute_flow(access);
4613 dep = isl_union_flow_get_must_dependence(flow);
4614 isl_union_flow_free(flow);
4615 empty = isl_union_map_is_empty(dep);
4616 isl_union_map_free(dep);
4618 if (empty < 0)
4619 return -1;
4620 if (empty)
4621 isl_die(ctx, isl_error_unknown,
4622 "conditional validity not respected", return -1);
4624 return 0;
4627 /* Check that the test for violated conditional validity constraints
4628 * is not confused by domain compression.
4629 * In particular, earlier versions of isl would apply
4630 * a schedule on the compressed domains to the original domains,
4631 * resulting in a failure to detect that the default schedule
4632 * violates the conditional validity constraints.
4634 static int test_special_conditional_schedule_constraints_2(isl_ctx *ctx)
4636 const char *str;
4637 isl_bool empty;
4638 isl_union_set *domain;
4639 isl_union_map *validity, *condition;
4640 isl_schedule_constraints *sc;
4641 isl_schedule *schedule;
4642 isl_union_map *umap;
4643 isl_map *map, *ge;
4645 str = "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4646 domain = isl_union_set_read_from_str(ctx, str);
4647 sc = isl_schedule_constraints_on_domain(domain);
4648 str = "{ B[1, i] -> A[0, i + 1] }";
4649 condition = isl_union_map_read_from_str(ctx, str);
4650 str = "{ A[0, i] -> B[1, i - 1] }";
4651 validity = isl_union_map_read_from_str(ctx, str);
4652 sc = isl_schedule_constraints_set_conditional_validity(sc, condition,
4653 isl_union_map_copy(validity));
4654 schedule = isl_schedule_constraints_compute_schedule(sc);
4655 umap = isl_schedule_get_map(schedule);
4656 isl_schedule_free(schedule);
4657 validity = isl_union_map_apply_domain(validity,
4658 isl_union_map_copy(umap));
4659 validity = isl_union_map_apply_range(validity, umap);
4660 map = isl_map_from_union_map(validity);
4661 ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map)));
4662 map = isl_map_intersect(map, ge);
4663 empty = isl_map_is_empty(map);
4664 isl_map_free(map);
4666 if (empty < 0)
4667 return -1;
4668 if (!empty)
4669 isl_die(ctx, isl_error_unknown,
4670 "conditional validity constraints not satisfied",
4671 return -1);
4673 return 0;
4676 /* Input for testing of schedule construction based on
4677 * conditional constraints.
4679 * domain is the iteration domain
4680 * flow are the flow dependences, which determine the validity and
4681 * proximity constraints
4682 * condition are the conditions on the conditional validity constraints
4683 * conditional_validity are the conditional validity constraints
4684 * outer_band_n is the expected number of members in the outer band
4686 struct {
4687 const char *domain;
4688 const char *flow;
4689 const char *condition;
4690 const char *conditional_validity;
4691 int outer_band_n;
4692 } live_range_tests[] = {
4693 /* Contrived example that illustrates that we need to keep
4694 * track of tagged condition dependences and
4695 * tagged conditional validity dependences
4696 * in isl_sched_edge separately.
4697 * In particular, the conditional validity constraints on A
4698 * cannot be satisfied,
4699 * but they can be ignored because there are no corresponding
4700 * condition constraints. However, we do have an additional
4701 * conditional validity constraint that maps to the same
4702 * dependence relation
4703 * as the condition constraint on B. If we did not make a distinction
4704 * between tagged condition and tagged conditional validity
4705 * dependences, then we
4706 * could end up treating this shared dependence as an condition
4707 * constraint on A, forcing a localization of the conditions,
4708 * which is impossible.
4710 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4711 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4712 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4713 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4714 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4715 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4718 /* TACO 2013 Fig. 7 */
4719 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4720 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4721 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4722 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4723 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4724 "0 <= i < n and 0 <= j < n - 1 }",
4725 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4726 "0 <= i < n and 0 <= j < j' < n;"
4727 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4728 "0 <= i < i' < n and 0 <= j,j' < n;"
4729 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4730 "0 <= i,j,j' < n and j < j' }",
4733 /* TACO 2013 Fig. 7, without tags */
4734 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4735 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4736 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4737 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4738 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4739 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4740 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4741 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4744 /* TACO 2013 Fig. 12 */
4745 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4746 "S3[i,3] : 0 <= i <= 1 }",
4747 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4748 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4749 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4750 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4751 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4752 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4753 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4754 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4755 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4756 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4757 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4762 /* Test schedule construction based on conditional constraints.
4763 * In particular, check the number of members in the outer band node
4764 * as an indication of whether tiling is possible or not.
4766 static int test_conditional_schedule_constraints(isl_ctx *ctx)
4768 int i;
4769 isl_union_set *domain;
4770 isl_union_map *condition;
4771 isl_union_map *flow;
4772 isl_union_map *validity;
4773 isl_schedule_constraints *sc;
4774 isl_schedule *schedule;
4775 isl_schedule_node *node;
4776 isl_size n_member;
4778 if (test_special_conditional_schedule_constraints(ctx) < 0)
4779 return -1;
4780 if (test_special_conditional_schedule_constraints_2(ctx) < 0)
4781 return -1;
4783 for (i = 0; i < ARRAY_SIZE(live_range_tests); ++i) {
4784 domain = isl_union_set_read_from_str(ctx,
4785 live_range_tests[i].domain);
4786 flow = isl_union_map_read_from_str(ctx,
4787 live_range_tests[i].flow);
4788 condition = isl_union_map_read_from_str(ctx,
4789 live_range_tests[i].condition);
4790 validity = isl_union_map_read_from_str(ctx,
4791 live_range_tests[i].conditional_validity);
4792 sc = isl_schedule_constraints_on_domain(domain);
4793 sc = isl_schedule_constraints_set_validity(sc,
4794 isl_union_map_copy(flow));
4795 sc = isl_schedule_constraints_set_proximity(sc, flow);
4796 sc = isl_schedule_constraints_set_conditional_validity(sc,
4797 condition, validity);
4798 schedule = isl_schedule_constraints_compute_schedule(sc);
4799 node = isl_schedule_get_root(schedule);
4800 while (node &&
4801 isl_schedule_node_get_type(node) != isl_schedule_node_band)
4802 node = isl_schedule_node_first_child(node);
4803 n_member = isl_schedule_node_band_n_member(node);
4804 isl_schedule_node_free(node);
4805 isl_schedule_free(schedule);
4807 if (!schedule || n_member < 0)
4808 return -1;
4809 if (n_member != live_range_tests[i].outer_band_n)
4810 isl_die(ctx, isl_error_unknown,
4811 "unexpected number of members in outer band",
4812 return -1);
4814 return 0;
4817 /* Check that the schedule computed for the given instance set and
4818 * dependence relation strongly satisfies the dependences.
4819 * In particular, check that no instance is scheduled before
4820 * or together with an instance on which it depends.
4821 * Earlier versions of isl would produce a schedule that
4822 * only weakly satisfies the dependences.
4824 static int test_strongly_satisfying_schedule(isl_ctx *ctx)
4826 const char *domain, *dep;
4827 isl_union_map *D, *schedule;
4828 isl_map *map, *ge;
4829 int empty;
4831 domain = "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4832 "A[i0] : 0 <= i0 <= 1 }";
4833 dep = "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4834 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4835 schedule = compute_schedule(ctx, domain, dep, dep);
4836 D = isl_union_map_read_from_str(ctx, dep);
4837 D = isl_union_map_apply_domain(D, isl_union_map_copy(schedule));
4838 D = isl_union_map_apply_range(D, schedule);
4839 map = isl_map_from_union_map(D);
4840 ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map)));
4841 map = isl_map_intersect(map, ge);
4842 empty = isl_map_is_empty(map);
4843 isl_map_free(map);
4845 if (empty < 0)
4846 return -1;
4847 if (!empty)
4848 isl_die(ctx, isl_error_unknown,
4849 "dependences not strongly satisfied", return -1);
4851 return 0;
4854 /* Compute a schedule for input where the instance set constraints
4855 * conflict with the context constraints.
4856 * Earlier versions of isl did not properly handle this situation.
4858 static int test_conflicting_context_schedule(isl_ctx *ctx)
4860 isl_union_map *schedule;
4861 const char *domain, *context;
4863 domain = "[n] -> { A[] : n >= 0 }";
4864 context = "[n] -> { : n < 0 }";
4865 schedule = compute_schedule_with_context(ctx,
4866 domain, "{}", "{}", context);
4867 isl_union_map_free(schedule);
4869 if (!schedule)
4870 return -1;
4872 return 0;
4875 /* Check that a set of schedule constraints that only allow for
4876 * a coalescing schedule still produces a schedule even if the user
4877 * request a non-coalescing schedule. Earlier versions of isl
4878 * would not handle this case correctly.
4880 static int test_coalescing_schedule(isl_ctx *ctx)
4882 const char *domain, *dep;
4883 isl_union_set *I;
4884 isl_union_map *D;
4885 isl_schedule_constraints *sc;
4886 isl_schedule *schedule;
4887 int treat_coalescing;
4889 domain = "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4890 dep = "{ S[a, b] -> S[a + b, 1 - b] }";
4891 I = isl_union_set_read_from_str(ctx, domain);
4892 D = isl_union_map_read_from_str(ctx, dep);
4893 sc = isl_schedule_constraints_on_domain(I);
4894 sc = isl_schedule_constraints_set_validity(sc, D);
4895 treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx);
4896 isl_options_set_schedule_treat_coalescing(ctx, 1);
4897 schedule = isl_schedule_constraints_compute_schedule(sc);
4898 isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing);
4899 isl_schedule_free(schedule);
4900 if (!schedule)
4901 return -1;
4902 return 0;
4905 /* Check that the scheduler does not perform any needless
4906 * compound skewing. Earlier versions of isl would compute
4907 * schedules in terms of transformed schedule coefficients and
4908 * would not accurately keep track of the sum of the original
4909 * schedule coefficients. It could then produce the schedule
4910 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4911 * for the input below instead of the schedule below.
4913 static int test_skewing_schedule(isl_ctx *ctx)
4915 const char *D, *V, *P, *S;
4917 D = "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4918 V = "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4919 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4920 "-1 <= a-i + b-j + c-k <= 1 }";
4921 P = "{ }";
4922 S = "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4924 return test_special_schedule(ctx, D, V, P, S);
4927 int test_schedule(isl_ctx *ctx)
4929 const char *D, *W, *R, *V, *P, *S;
4930 int max_coincidence;
4931 int treat_coalescing;
4933 /* Handle resulting schedule with zero bands. */
4934 if (test_one_schedule(ctx, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4935 return -1;
4937 /* Jacobi */
4938 D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4939 W = "{ S1[t,i] -> a[t,i] }";
4940 R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4941 "S1[t,i] -> a[t-1,i+1] }";
4942 S = "{ S1[t,i] -> [t,i] }";
4943 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4944 return -1;
4946 /* Fig. 5 of CC2008 */
4947 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4948 "j <= -1 + N }";
4949 W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4950 "j >= 2 and j <= -1 + N }";
4951 R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4952 "j >= 2 and j <= -1 + N; "
4953 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4954 "j >= 2 and j <= -1 + N }";
4955 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4956 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4957 return -1;
4959 D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4960 W = "{ S1[i] -> a[i] }";
4961 R = "{ S2[i] -> a[i+1] }";
4962 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4963 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4964 return -1;
4966 D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4967 W = "{ S1[i] -> a[i] }";
4968 R = "{ S2[i] -> a[9-i] }";
4969 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4970 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4971 return -1;
4973 D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4974 W = "{ S1[i] -> a[i] }";
4975 R = "[N] -> { S2[i] -> a[N-1-i] }";
4976 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4977 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4978 return -1;
4980 D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4981 W = "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4982 R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4983 S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4984 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4985 return -1;
4987 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4988 W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4989 R = "{ S2[i,j] -> a[i-1,j] }";
4990 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4991 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
4992 return -1;
4994 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4995 W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4996 R = "{ S2[i,j] -> a[i,j-1] }";
4997 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4998 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
4999 return -1;
5001 D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
5002 W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
5003 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
5004 R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
5005 S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
5006 "S_0[] -> [0, 0, 0] }";
5007 if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0)
5008 return -1;
5009 ctx->opt->schedule_parametric = 0;
5010 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5011 return -1;
5012 ctx->opt->schedule_parametric = 1;
5014 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
5015 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
5016 W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
5017 R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
5018 "S4[i] -> a[i,N] }";
5019 S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
5020 "S4[i] -> [4,i,0] }";
5021 max_coincidence = isl_options_get_schedule_maximize_coincidence(ctx);
5022 isl_options_set_schedule_maximize_coincidence(ctx, 0);
5023 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
5024 return -1;
5025 isl_options_set_schedule_maximize_coincidence(ctx, max_coincidence);
5027 D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
5028 W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5029 "j <= N }";
5030 R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
5031 "j <= N; "
5032 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
5033 "j <= N }";
5034 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
5035 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5036 return -1;
5038 D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
5039 " S_2[t] : t >= 0 and t <= -1 + N; "
5040 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
5041 "i <= -1 + N }";
5042 W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
5043 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
5044 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
5045 "i >= 0 and i <= -1 + N }";
5046 R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
5047 "i >= 0 and i <= -1 + N; "
5048 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
5049 S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
5050 " S_0[t] -> [0, t, 0] }";
5052 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
5053 return -1;
5054 ctx->opt->schedule_parametric = 0;
5055 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5056 return -1;
5057 ctx->opt->schedule_parametric = 1;
5059 D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
5060 S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
5061 if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0)
5062 return -1;
5064 D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
5065 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
5066 W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
5067 "j >= 0 and j <= -1 + N; "
5068 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5069 R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
5070 "j >= 0 and j <= -1 + N; "
5071 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
5072 S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
5073 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5074 return -1;
5076 D = "{ S_0[i] : i >= 0 }";
5077 W = "{ S_0[i] -> a[i] : i >= 0 }";
5078 R = "{ S_0[i] -> a[0] : i >= 0 }";
5079 S = "{ S_0[i] -> [0, i, 0] }";
5080 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5081 return -1;
5083 D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
5084 W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
5085 R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
5086 S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
5087 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5088 return -1;
5090 D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
5091 "k <= -1 + n and k >= 0 }";
5092 W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
5093 R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
5094 "k <= -1 + n and k >= 0; "
5095 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
5096 "k <= -1 + n and k >= 0; "
5097 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
5098 "k <= -1 + n and k >= 0 }";
5099 S = "[n] -> { S_0[j, k] -> [2, j, k] }";
5100 ctx->opt->schedule_outer_coincidence = 1;
5101 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
5102 return -1;
5103 ctx->opt->schedule_outer_coincidence = 0;
5105 D = "{Stmt_for_body24[i0, i1, i2, i3]:"
5106 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
5107 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
5108 "Stmt_for_body24[i0, i1, 1, 0]:"
5109 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
5110 "Stmt_for_body7[i0, i1, i2]:"
5111 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
5112 "i2 <= 7 }";
5114 V = "{Stmt_for_body24[0, i1, i2, i3] -> "
5115 "Stmt_for_body24[1, i1, i2, i3]:"
5116 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
5117 "i2 >= 1;"
5118 "Stmt_for_body24[0, i1, i2, i3] -> "
5119 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
5120 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
5121 "i3 >= 0;"
5122 "Stmt_for_body24[0, i1, i2, i3] ->"
5123 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
5124 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
5125 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
5126 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
5127 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
5128 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
5129 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
5130 "i1 <= 6 and i1 >= 0;"
5131 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
5132 "Stmt_for_body7[i0, i1, i2] -> "
5133 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
5134 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
5135 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
5136 "Stmt_for_body7[i0, i1, i2] -> "
5137 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
5138 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
5139 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
5140 P = V;
5142 treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx);
5143 isl_options_set_schedule_treat_coalescing(ctx, 0);
5144 if (test_has_schedule(ctx, D, V, P) < 0)
5145 return -1;
5146 isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing);
5148 D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
5149 V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
5150 "j >= 1 and j <= 7;"
5151 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
5152 "j >= 1 and j <= 8 }";
5153 P = "{ }";
5154 S = "{ S_0[i, j] -> [i + j, i] }";
5155 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5156 if (test_special_schedule(ctx, D, V, P, S) < 0)
5157 return -1;
5158 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5160 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
5161 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
5162 "j >= 0 and j <= -1 + i }";
5163 V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
5164 "i <= -1 + N and j >= 0;"
5165 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
5166 "i <= -2 + N }";
5167 P = "{ }";
5168 S = "{ S_0[i, j] -> [i, j] }";
5169 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5170 if (test_special_schedule(ctx, D, V, P, S) < 0)
5171 return -1;
5172 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5174 /* Test both algorithms on a case with only proximity dependences. */
5175 D = "{ S[i,j] : 0 <= i <= 10 }";
5176 V = "{ }";
5177 P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
5178 S = "{ S[i, j] -> [j, i] }";
5179 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5180 if (test_special_schedule(ctx, D, V, P, S) < 0)
5181 return -1;
5182 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5183 if (test_special_schedule(ctx, D, V, P, S) < 0)
5184 return -1;
5186 D = "{ A[a]; B[] }";
5187 V = "{}";
5188 P = "{ A[a] -> B[] }";
5189 if (test_has_schedule(ctx, D, V, P) < 0)
5190 return -1;
5192 if (test_padded_schedule(ctx) < 0)
5193 return -1;
5195 /* Check that check for progress is not confused by rational
5196 * solution.
5198 D = "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
5199 V = "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
5200 "i0 <= -2 + N; "
5201 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
5202 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
5203 P = "{}";
5204 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5205 if (test_has_schedule(ctx, D, V, P) < 0)
5206 return -1;
5207 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5209 /* Check that we allow schedule rows that are only non-trivial
5210 * on some full-dimensional domains.
5212 D = "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
5213 V = "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
5214 "S1[j] -> S2[1] : 0 <= j <= 1 }";
5215 P = "{}";
5216 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
5217 if (test_has_schedule(ctx, D, V, P) < 0)
5218 return -1;
5219 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
5221 if (test_conditional_schedule_constraints(ctx) < 0)
5222 return -1;
5224 if (test_strongly_satisfying_schedule(ctx) < 0)
5225 return -1;
5227 if (test_conflicting_context_schedule(ctx) < 0)
5228 return -1;
5230 if (test_coalescing_schedule(ctx) < 0)
5231 return -1;
5232 if (test_skewing_schedule(ctx) < 0)
5233 return -1;
5235 return 0;
5238 /* Perform scheduling tests using the whole component scheduler.
5240 static int test_schedule_whole(isl_ctx *ctx)
5242 int whole;
5243 int r;
5245 whole = isl_options_get_schedule_whole_component(ctx);
5246 isl_options_set_schedule_whole_component(ctx, 1);
5247 r = test_schedule(ctx);
5248 isl_options_set_schedule_whole_component(ctx, whole);
5250 return r;
5253 /* Perform scheduling tests using the incremental scheduler.
5255 static int test_schedule_incremental(isl_ctx *ctx)
5257 int whole;
5258 int r;
5260 whole = isl_options_get_schedule_whole_component(ctx);
5261 isl_options_set_schedule_whole_component(ctx, 0);
5262 r = test_schedule(ctx);
5263 isl_options_set_schedule_whole_component(ctx, whole);
5265 return r;
5268 int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
5270 isl_union_map *umap;
5271 int test;
5273 umap = isl_union_map_read_from_str(ctx, str);
5274 test = isl_union_map_plain_is_injective(umap);
5275 isl_union_map_free(umap);
5276 if (test < 0)
5277 return -1;
5278 if (test == injective)
5279 return 0;
5280 if (injective)
5281 isl_die(ctx, isl_error_unknown,
5282 "map not detected as injective", return -1);
5283 else
5284 isl_die(ctx, isl_error_unknown,
5285 "map detected as injective", return -1);
5288 int test_injective(isl_ctx *ctx)
5290 const char *str;
5292 if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
5293 return -1;
5294 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
5295 return -1;
5296 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
5297 return -1;
5298 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
5299 return -1;
5300 if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
5301 return -1;
5302 if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
5303 return -1;
5304 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
5305 return -1;
5306 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
5307 return -1;
5309 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
5310 if (test_plain_injective(ctx, str, 1))
5311 return -1;
5312 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
5313 if (test_plain_injective(ctx, str, 0))
5314 return -1;
5316 return 0;
5319 #undef BASE
5320 #define BASE aff
5321 #include "isl_test_plain_equal_templ.c"
5323 #undef BASE
5324 #define BASE pw_multi_aff
5325 #include "isl_test_plain_equal_templ.c"
5327 #undef BASE
5328 #define BASE union_pw_aff
5329 #include "isl_test_plain_equal_templ.c"
5331 /* Basic tests on isl_union_pw_aff.
5333 * In particular, check that isl_union_pw_aff_aff_on_domain
5334 * aligns the parameters of the input objects and
5335 * that isl_union_pw_aff_param_on_domain_id properly
5336 * introduces the parameter.
5338 static int test_upa(isl_ctx *ctx)
5340 const char *str;
5341 isl_id *id;
5342 isl_aff *aff;
5343 isl_union_set *domain;
5344 isl_union_pw_aff *upa;
5345 isl_stat ok;
5347 aff = isl_aff_read_from_str(ctx, "[N] -> { [N] }");
5348 str = "[M] -> { A[i] : 0 <= i < M; B[] }";
5349 domain = isl_union_set_read_from_str(ctx, str);
5350 upa = isl_union_pw_aff_aff_on_domain(domain, aff);
5351 str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5352 ok = union_pw_aff_check_plain_equal(upa, str);
5353 isl_union_pw_aff_free(upa);
5354 if (ok < 0)
5355 return -1;
5357 id = isl_id_alloc(ctx, "N", NULL);
5358 str = "[M] -> { A[i] : 0 <= i < M; B[] }";
5359 domain = isl_union_set_read_from_str(ctx, str);
5360 upa = isl_union_pw_aff_param_on_domain_id(domain, id);
5361 str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5362 ok = union_pw_aff_check_plain_equal(upa, str);
5363 isl_union_pw_aff_free(upa);
5364 if (ok < 0)
5365 return -1;
5367 return 0;
5370 struct {
5371 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
5372 __isl_take isl_aff *aff2);
5373 } aff_bin_op[] = {
5374 ['+'] = { &isl_aff_add },
5375 ['-'] = { &isl_aff_sub },
5376 ['*'] = { &isl_aff_mul },
5377 ['/'] = { &isl_aff_div },
5380 struct {
5381 const char *arg1;
5382 unsigned char op;
5383 const char *arg2;
5384 const char *res;
5385 } aff_bin_tests[] = {
5386 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5387 "{ [i] -> [2i] }" },
5388 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5389 "{ [i] -> [0] }" },
5390 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5391 "{ [i] -> [2i] }" },
5392 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5393 "{ [i] -> [2i] }" },
5394 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5395 "{ [i] -> [i/2] }" },
5396 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5397 "{ [i] -> [i] }" },
5398 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5399 "{ [i] -> [NaN] }" },
5400 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5401 "{ [i] -> [NaN] }" },
5402 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5403 "{ [i] -> [NaN] }" },
5404 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5405 "{ [i] -> [NaN] }" },
5406 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5407 "{ [i] -> [NaN] }" },
5408 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5409 "{ [i] -> [NaN] }" },
5410 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5411 "{ [i] -> [NaN] }" },
5412 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5413 "{ [i] -> [NaN] }" },
5414 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5415 "{ [i] -> [NaN] }" },
5416 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5417 "{ [i] -> [NaN] }" },
5418 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5419 "{ [i] -> [NaN] }" },
5420 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5421 "{ [i] -> [NaN] }" },
5422 { "{ [i] -> [i] }", '/', "{ [i] -> [0] }",
5423 "{ [i] -> [NaN] }" },
5426 /* Perform some basic tests of binary operations on isl_aff objects.
5428 static int test_bin_aff(isl_ctx *ctx)
5430 int i;
5431 isl_aff *aff1, *aff2, *res;
5432 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
5433 __isl_take isl_aff *aff2);
5434 int ok;
5436 for (i = 0; i < ARRAY_SIZE(aff_bin_tests); ++i) {
5437 aff1 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg1);
5438 aff2 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg2);
5439 res = isl_aff_read_from_str(ctx, aff_bin_tests[i].res);
5440 fn = aff_bin_op[aff_bin_tests[i].op].fn;
5441 aff1 = fn(aff1, aff2);
5442 if (isl_aff_is_nan(res))
5443 ok = isl_aff_is_nan(aff1);
5444 else
5445 ok = isl_aff_plain_is_equal(aff1, res);
5446 isl_aff_free(aff1);
5447 isl_aff_free(res);
5448 if (ok < 0)
5449 return -1;
5450 if (!ok)
5451 isl_die(ctx, isl_error_unknown,
5452 "unexpected result", return -1);
5455 return 0;
5458 struct {
5459 __isl_give isl_pw_aff *(*fn)(__isl_take isl_pw_aff *pa1,
5460 __isl_take isl_pw_aff *pa2);
5461 } pw_aff_bin_op[] = {
5462 ['m'] = { &isl_pw_aff_min },
5463 ['M'] = { &isl_pw_aff_max },
5466 /* Inputs for binary isl_pw_aff operation tests.
5467 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5468 * defined by pw_aff_bin_op, and "res" is the expected result.
5470 struct {
5471 const char *arg1;
5472 unsigned char op;
5473 const char *arg2;
5474 const char *res;
5475 } pw_aff_bin_tests[] = {
5476 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5477 "{ [i] -> [i] }" },
5478 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5479 "{ [i] -> [i] }" },
5480 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5481 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5482 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5483 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5484 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5485 "{ [i] -> [NaN] }" },
5486 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5487 "{ [i] -> [NaN] }" },
5490 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5492 static int test_bin_pw_aff(isl_ctx *ctx)
5494 int i;
5495 isl_bool ok;
5496 isl_pw_aff *pa1, *pa2, *res;
5498 for (i = 0; i < ARRAY_SIZE(pw_aff_bin_tests); ++i) {
5499 pa1 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg1);
5500 pa2 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg2);
5501 res = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].res);
5502 pa1 = pw_aff_bin_op[pw_aff_bin_tests[i].op].fn(pa1, pa2);
5503 if (isl_pw_aff_involves_nan(res))
5504 ok = isl_pw_aff_involves_nan(pa1);
5505 else
5506 ok = isl_pw_aff_plain_is_equal(pa1, res);
5507 isl_pw_aff_free(pa1);
5508 isl_pw_aff_free(res);
5509 if (ok < 0)
5510 return -1;
5511 if (!ok)
5512 isl_die(ctx, isl_error_unknown,
5513 "unexpected result", return -1);
5516 return 0;
5519 /* Inputs for basic tests of test operations on
5520 * isl_union_pw_multi_aff objects.
5521 * "fn" is the function that is being tested.
5522 * "arg" is a string description of the input.
5523 * "res" is the expected result.
5525 static struct {
5526 isl_bool (*fn)(__isl_keep isl_union_pw_multi_aff *upma1);
5527 const char *arg;
5528 isl_bool res;
5529 } upma_test_tests[] = {
5530 { &isl_union_pw_multi_aff_involves_nan, "{ A[] -> [0]; B[0] -> [1] }",
5531 isl_bool_false },
5532 { &isl_union_pw_multi_aff_involves_nan, "{ A[] -> [NaN]; B[0] -> [1] }",
5533 isl_bool_true },
5534 { &isl_union_pw_multi_aff_involves_nan, "{ A[] -> [0]; B[0] -> [NaN] }",
5535 isl_bool_true },
5536 { &isl_union_pw_multi_aff_involves_nan,
5537 "{ A[] -> [0]; B[0] -> [1, NaN, 5] }",
5538 isl_bool_true },
5539 { &isl_union_pw_multi_aff_involves_locals,
5540 "{ A[] -> [0]; B[0] -> [1] }",
5541 isl_bool_false },
5542 { &isl_union_pw_multi_aff_involves_locals,
5543 "{ A[] -> [0]; B[x] -> [1] : x mod 2 = 0 }",
5544 isl_bool_true },
5545 { &isl_union_pw_multi_aff_involves_locals,
5546 "{ A[] -> [0]; B[x] -> [x // 2] }",
5547 isl_bool_true },
5548 { &isl_union_pw_multi_aff_involves_locals,
5549 "{ A[i] -> [i // 2]; B[0] -> [1] }",
5550 isl_bool_true },
5553 /* Perform some basic tests of test operations on
5554 * isl_union_pw_multi_aff objects.
5556 static isl_stat test_upma_test(isl_ctx *ctx)
5558 int i;
5559 isl_union_pw_multi_aff *upma;
5560 isl_bool res;
5562 for (i = 0; i < ARRAY_SIZE(upma_test_tests); ++i) {
5563 const char *str;
5565 str = upma_test_tests[i].arg;
5566 upma = isl_union_pw_multi_aff_read_from_str(ctx, str);
5567 res = upma_test_tests[i].fn(upma);
5568 isl_union_pw_multi_aff_free(upma);
5569 if (res < 0)
5570 return isl_stat_error;
5571 if (res != upma_test_tests[i].res)
5572 isl_die(ctx, isl_error_unknown,
5573 "unexpected result", return isl_stat_error);
5576 return isl_stat_ok;
5579 struct {
5580 __isl_give isl_union_pw_multi_aff *(*fn)(
5581 __isl_take isl_union_pw_multi_aff *upma1,
5582 __isl_take isl_union_pw_multi_aff *upma2);
5583 const char *arg1;
5584 const char *arg2;
5585 const char *res;
5586 } upma_bin_tests[] = {
5587 { &isl_union_pw_multi_aff_add, "{ A[] -> [0]; B[0] -> [1] }",
5588 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5589 { &isl_union_pw_multi_aff_union_add, "{ A[] -> [0]; B[0] -> [1] }",
5590 "{ B[x] -> [2] : x >= 0 }",
5591 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5592 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff,
5593 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5594 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5595 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5596 "D[i] -> B[2] : i >= 5 }" },
5597 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5598 "{ B[x] -> C[2] : x > 0 }",
5599 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5600 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5601 "{ B[x] -> A[2] : x >= 0 }",
5602 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5605 /* Perform some basic tests of binary operations on
5606 * isl_union_pw_multi_aff objects.
5608 static int test_bin_upma(isl_ctx *ctx)
5610 int i;
5611 isl_union_pw_multi_aff *upma1, *upma2, *res;
5612 int ok;
5614 for (i = 0; i < ARRAY_SIZE(upma_bin_tests); ++i) {
5615 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
5616 upma_bin_tests[i].arg1);
5617 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
5618 upma_bin_tests[i].arg2);
5619 res = isl_union_pw_multi_aff_read_from_str(ctx,
5620 upma_bin_tests[i].res);
5621 upma1 = upma_bin_tests[i].fn(upma1, upma2);
5622 ok = isl_union_pw_multi_aff_plain_is_equal(upma1, res);
5623 isl_union_pw_multi_aff_free(upma1);
5624 isl_union_pw_multi_aff_free(res);
5625 if (ok < 0)
5626 return -1;
5627 if (!ok)
5628 isl_die(ctx, isl_error_unknown,
5629 "unexpected result", return -1);
5632 return 0;
5635 struct {
5636 __isl_give isl_union_pw_multi_aff *(*fn)(
5637 __isl_take isl_union_pw_multi_aff *upma1,
5638 __isl_take isl_union_pw_multi_aff *upma2);
5639 const char *arg1;
5640 const char *arg2;
5641 } upma_bin_fail_tests[] = {
5642 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5643 "{ B[x] -> C[2] : x >= 0 }" },
5646 /* Perform some basic tests of binary operations on
5647 * isl_union_pw_multi_aff objects that are expected to fail.
5649 static int test_bin_upma_fail(isl_ctx *ctx)
5651 int i, n;
5652 isl_union_pw_multi_aff *upma1, *upma2;
5653 int on_error;
5655 on_error = isl_options_get_on_error(ctx);
5656 isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE);
5657 n = ARRAY_SIZE(upma_bin_fail_tests);
5658 for (i = 0; i < n; ++i) {
5659 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
5660 upma_bin_fail_tests[i].arg1);
5661 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
5662 upma_bin_fail_tests[i].arg2);
5663 upma1 = upma_bin_fail_tests[i].fn(upma1, upma2);
5664 isl_union_pw_multi_aff_free(upma1);
5665 if (upma1)
5666 break;
5668 isl_options_set_on_error(ctx, on_error);
5669 if (i < n)
5670 isl_die(ctx, isl_error_unknown,
5671 "operation not expected to succeed", return -1);
5673 return 0;
5676 /* Inputs for basic tests of binary operations on
5677 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5678 * "fn" is the function that is being tested.
5679 * "arg1" and "arg2" are string descriptions of the inputs.
5680 * "res" is a string description of the expected result.
5682 struct {
5683 __isl_give isl_union_pw_multi_aff *(*fn)(
5684 __isl_take isl_union_pw_multi_aff *upma,
5685 __isl_take isl_union_set *uset);
5686 const char *arg1;
5687 const char *arg2;
5688 const char *res;
5689 } upma_uset_tests[] = {
5690 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5691 "{ A[i] -> B[i] }", "{ B[0] }",
5692 "{ }" },
5693 { &isl_union_pw_multi_aff_intersect_domain_wrapped_domain,
5694 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5695 "{ [A[1] -> B[1]] -> C[2] }" },
5696 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5697 "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }",
5698 "{ [A[0] -> B[0]] -> C[1] }" },
5699 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5700 "{ [A[i] -> B[i]] -> C[i + 1] }", "[N] -> { B[N] }",
5701 "[N] -> { [A[N] -> B[N]] -> C[N + 1] }" },
5702 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5703 "[M] -> { [A[M] -> B[M]] -> C[M + 1] }", "[N] -> { B[N] }",
5704 "[N, M] -> { [A[N] -> B[N]] -> C[N + 1] : N = M }" },
5705 { &isl_union_pw_multi_aff_intersect_domain_wrapped_range,
5706 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[]; [B[] -> A[]] -> E[] }",
5707 "{ B[] }",
5708 "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[] }" },
5711 /* Perform some basic tests of binary operations on
5712 * pairs of isl_union_pw_multi_aff and isl_union_set objects.
5714 static isl_stat test_upma_uset(isl_ctx *ctx)
5716 int i;
5717 isl_bool ok;
5718 isl_union_pw_multi_aff *upma, *res;
5719 isl_union_set *uset;
5721 for (i = 0; i < ARRAY_SIZE(upma_uset_tests); ++i) {
5722 upma = isl_union_pw_multi_aff_read_from_str(ctx,
5723 upma_uset_tests[i].arg1);
5724 uset = isl_union_set_read_from_str(ctx,
5725 upma_uset_tests[i].arg2);
5726 res = isl_union_pw_multi_aff_read_from_str(ctx,
5727 upma_uset_tests[i].res);
5728 upma = upma_uset_tests[i].fn(upma, uset);
5729 ok = isl_union_pw_multi_aff_plain_is_equal(upma, res);
5730 isl_union_pw_multi_aff_free(upma);
5731 isl_union_pw_multi_aff_free(res);
5732 if (ok < 0)
5733 return isl_stat_error;
5734 if (!ok)
5735 isl_die(ctx, isl_error_unknown,
5736 "unexpected result", return isl_stat_error);
5739 return isl_stat_ok;
5742 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5743 * "fn" is the function that is tested.
5744 * "arg" is a string description of the input.
5745 * "res" is a string description of the expected result.
5747 struct {
5748 __isl_give isl_multi_pw_aff *(*fn)(__isl_take isl_multi_pw_aff *mpa);
5749 const char *arg;
5750 const char *res;
5751 } mpa_un_tests[] = {
5752 { &isl_multi_pw_aff_range_factor_domain,
5753 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5754 "{ A[x] -> B[(1 : x >= 5)] }" },
5755 { &isl_multi_pw_aff_range_factor_range,
5756 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5757 "{ A[y] -> C[(2 : y <= 10)] }" },
5758 { &isl_multi_pw_aff_range_factor_domain,
5759 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5760 "{ A[x] -> B[(1 : x >= 5)] }" },
5761 { &isl_multi_pw_aff_range_factor_range,
5762 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5763 "{ A[y] -> C[] }" },
5764 { &isl_multi_pw_aff_range_factor_domain,
5765 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5766 "{ A[x] -> B[] }" },
5767 { &isl_multi_pw_aff_range_factor_range,
5768 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5769 "{ A[y] -> C[(2 : y <= 10)] }" },
5770 { &isl_multi_pw_aff_range_factor_domain,
5771 "{ A[x] -> [B[] -> C[]] }",
5772 "{ A[x] -> B[] }" },
5773 { &isl_multi_pw_aff_range_factor_range,
5774 "{ A[x] -> [B[] -> C[]] }",
5775 "{ A[y] -> C[] }" },
5776 { &isl_multi_pw_aff_factor_range,
5777 "{ [B[] -> C[]] }",
5778 "{ C[] }" },
5779 { &isl_multi_pw_aff_range_factor_domain,
5780 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5781 "{ A[x] -> B[] : x >= 0 }" },
5782 { &isl_multi_pw_aff_range_factor_range,
5783 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5784 "{ A[y] -> C[] : y >= 0 }" },
5785 { &isl_multi_pw_aff_factor_range,
5786 "[N] -> { [B[] -> C[]] : N >= 0 }",
5787 "[N] -> { C[] : N >= 0 }" },
5790 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5792 static int test_un_mpa(isl_ctx *ctx)
5794 int i;
5795 isl_bool ok;
5796 isl_multi_pw_aff *mpa, *res;
5798 for (i = 0; i < ARRAY_SIZE(mpa_un_tests); ++i) {
5799 mpa = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].arg);
5800 res = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].res);
5801 mpa = mpa_un_tests[i].fn(mpa);
5802 ok = isl_multi_pw_aff_plain_is_equal(mpa, res);
5803 isl_multi_pw_aff_free(mpa);
5804 isl_multi_pw_aff_free(res);
5805 if (ok < 0)
5806 return -1;
5807 if (!ok)
5808 isl_die(ctx, isl_error_unknown,
5809 "unexpected result", return -1);
5812 return 0;
5815 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5816 * "fn" is the function that is tested.
5817 * "arg1" and "arg2" are string descriptions of the inputs.
5818 * "res" is a string description of the expected result.
5820 struct {
5821 __isl_give isl_multi_pw_aff *(*fn)(
5822 __isl_take isl_multi_pw_aff *mpa1,
5823 __isl_take isl_multi_pw_aff *mpa2);
5824 const char *arg1;
5825 const char *arg2;
5826 const char *res;
5827 } mpa_bin_tests[] = {
5828 { &isl_multi_pw_aff_add, "{ A[] -> [1] }", "{ A[] -> [2] }",
5829 "{ A[] -> [3] }" },
5830 { &isl_multi_pw_aff_add, "{ A[x] -> [(1 : x >= 5)] }",
5831 "{ A[x] -> [(x : x <= 10)] }",
5832 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5833 { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }",
5834 "{ A[x] -> [] : x <= 10 }",
5835 "{ A[x] -> [] : 5 <= x <= 10 }" },
5836 { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }",
5837 "[N] -> { A[x] -> [] : x <= N }",
5838 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5839 { &isl_multi_pw_aff_add,
5840 "[N] -> { A[x] -> [] : x <= N }",
5841 "{ A[x] -> [] : x >= 5 }",
5842 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5843 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }",
5844 "{ A[y] -> C[(2 : y <= 10)] }",
5845 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5846 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }",
5847 "{ A[y] -> C[2] : y <= 10 }",
5848 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5849 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }",
5850 "[N] -> { A[y] -> C[2] : y <= N }",
5851 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5852 { &isl_multi_pw_aff_range_product, "[N] -> { A[x] -> B[1] : x >= N }",
5853 "{ A[y] -> C[2] : y <= 10 }",
5854 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5855 { &isl_multi_pw_aff_range_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5856 "{ A[] -> [B[1] -> C[2]] }" },
5857 { &isl_multi_pw_aff_range_product, "{ A[] -> B[] }", "{ A[] -> C[] }",
5858 "{ A[] -> [B[] -> C[]] }" },
5859 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }",
5860 "{ A[y] -> C[] : y <= 10 }",
5861 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5862 { &isl_multi_pw_aff_range_product, "{ A[y] -> C[] : y <= 10 }",
5863 "{ A[x] -> B[(1 : x >= 5)] }",
5864 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5865 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5866 "{ A[y] -> C[(2 : y <= 10)] }",
5867 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5868 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5869 "{ A[y] -> C[] : y <= 10 }",
5870 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5871 { &isl_multi_pw_aff_product, "{ A[y] -> C[] : y <= 10 }",
5872 "{ A[x] -> B[(1 : x >= 5)] }",
5873 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5874 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5875 "[N] -> { A[y] -> C[] : y <= N }",
5876 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5877 { &isl_multi_pw_aff_product, "[N] -> { A[y] -> C[] : y <= N }",
5878 "{ A[x] -> B[(1 : x >= 5)] }",
5879 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5880 { &isl_multi_pw_aff_product, "{ A[x] -> B[] : x >= 5 }",
5881 "{ A[y] -> C[] : y <= 10 }",
5882 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5883 { &isl_multi_pw_aff_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5884 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5885 { &isl_multi_pw_aff_product, "{ A[] -> B[] }", "{ A[] -> C[] }",
5886 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5887 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5888 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5889 "{ A[a,b] -> C[b + 2a] }" },
5890 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5891 "{ B[i,j] -> C[i + 2j] }",
5892 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5893 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5894 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5895 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5896 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5897 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5898 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5899 "{ B[i,j] -> C[] }",
5900 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5901 "{ A[a,b] -> C[] }" },
5902 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5903 "{ B[i,j] -> C[] : i > j }",
5904 "{ A[a,b] -> B[b,a] }",
5905 "{ A[a,b] -> C[] : b > a }" },
5906 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5907 "{ B[i,j] -> C[] : j > 5 }",
5908 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5909 "{ A[a,b] -> C[] : b > a > 5 }" },
5910 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5911 "[N] -> { B[i,j] -> C[] : j > N }",
5912 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5913 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5914 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5915 "[M,N] -> { B[] -> C[] : N > 5 }",
5916 "[M,N] -> { A[] -> B[] : M > N }",
5917 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5920 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5922 static int test_bin_mpa(isl_ctx *ctx)
5924 int i;
5925 isl_bool ok;
5926 isl_multi_pw_aff *mpa1, *mpa2, *res;
5928 for (i = 0; i < ARRAY_SIZE(mpa_bin_tests); ++i) {
5929 mpa1 = isl_multi_pw_aff_read_from_str(ctx,
5930 mpa_bin_tests[i].arg1);
5931 mpa2 = isl_multi_pw_aff_read_from_str(ctx,
5932 mpa_bin_tests[i].arg2);
5933 res = isl_multi_pw_aff_read_from_str(ctx,
5934 mpa_bin_tests[i].res);
5935 mpa1 = mpa_bin_tests[i].fn(mpa1, mpa2);
5936 ok = isl_multi_pw_aff_plain_is_equal(mpa1, res);
5937 isl_multi_pw_aff_free(mpa1);
5938 isl_multi_pw_aff_free(res);
5939 if (ok < 0)
5940 return -1;
5941 if (!ok)
5942 isl_die(ctx, isl_error_unknown,
5943 "unexpected result", return -1);
5946 return 0;
5949 /* Inputs for basic tests of unary operations on
5950 * isl_multi_union_pw_aff objects.
5951 * "fn" is the function that is tested.
5952 * "arg" is a string description of the input.
5953 * "res" is a string description of the expected result.
5955 struct {
5956 __isl_give isl_multi_union_pw_aff *(*fn)(
5957 __isl_take isl_multi_union_pw_aff *mupa);
5958 const char *arg;
5959 const char *res;
5960 } mupa_un_tests[] = {
5961 { &isl_multi_union_pw_aff_factor_range,
5962 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5963 "C[{ A[] -> [2] }]" },
5964 { &isl_multi_union_pw_aff_factor_range,
5965 "[B[] -> C[{ A[] -> [2] }]]",
5966 "C[{ A[] -> [2] }]" },
5967 { &isl_multi_union_pw_aff_factor_range,
5968 "[B[{ A[] -> [1] }] -> C[]]",
5969 "C[]" },
5970 { &isl_multi_union_pw_aff_factor_range,
5971 "[B[] -> C[]]",
5972 "C[]" },
5973 { &isl_multi_union_pw_aff_factor_range,
5974 "([B[] -> C[]] : { A[x] : x >= 0 })",
5975 "(C[] : { A[x] : x >= 0 })" },
5976 { &isl_multi_union_pw_aff_factor_range,
5977 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
5978 "[N] -> (C[] : { A[x] : x <= N })" },
5979 { &isl_multi_union_pw_aff_factor_range,
5980 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
5981 "[N] -> (C[] : { : N >= 0 })" },
5984 /* Perform some basic tests of unary operations on
5985 * isl_multi_union_pw_aff objects.
5987 static int test_un_mupa(isl_ctx *ctx)
5989 int i;
5990 isl_bool ok;
5991 isl_multi_union_pw_aff *mupa, *res;
5993 for (i = 0; i < ARRAY_SIZE(mupa_un_tests); ++i) {
5994 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5995 mupa_un_tests[i].arg);
5996 res = isl_multi_union_pw_aff_read_from_str(ctx,
5997 mupa_un_tests[i].res);
5998 mupa = mupa_un_tests[i].fn(mupa);
5999 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6000 isl_multi_union_pw_aff_free(mupa);
6001 isl_multi_union_pw_aff_free(res);
6002 if (ok < 0)
6003 return -1;
6004 if (!ok)
6005 isl_die(ctx, isl_error_unknown,
6006 "unexpected result", return -1);
6009 return 0;
6012 /* Inputs for basic tests of binary operations on
6013 * isl_multi_union_pw_aff objects.
6014 * "fn" is the function that is tested.
6015 * "arg1" and "arg2" are string descriptions of the inputs.
6016 * "res" is a string description of the expected result.
6018 struct {
6019 __isl_give isl_multi_union_pw_aff *(*fn)(
6020 __isl_take isl_multi_union_pw_aff *mupa1,
6021 __isl_take isl_multi_union_pw_aff *mupa2);
6022 const char *arg1;
6023 const char *arg2;
6024 const char *res;
6025 } mupa_bin_tests[] = {
6026 { &isl_multi_union_pw_aff_add, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6027 "[{ A[] -> [3] }]" },
6028 { &isl_multi_union_pw_aff_sub, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
6029 "[{ A[] -> [-1] }]" },
6030 { &isl_multi_union_pw_aff_add,
6031 "[{ A[] -> [1]; B[] -> [4] }]",
6032 "[{ A[] -> [2]; C[] -> [5] }]",
6033 "[{ A[] -> [3] }]" },
6034 { &isl_multi_union_pw_aff_union_add,
6035 "[{ A[] -> [1]; B[] -> [4] }]",
6036 "[{ A[] -> [2]; C[] -> [5] }]",
6037 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
6038 { &isl_multi_union_pw_aff_add, "[{ A[x] -> [(1)] : x >= 5 }]",
6039 "[{ A[x] -> [(x)] : x <= 10 }]",
6040 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
6041 { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })",
6042 "([] : { A[x] : x <= 10 })",
6043 "([] : { A[x] : 5 <= x <= 10 })" },
6044 { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })",
6045 "[N] -> ([] : { A[x] : x <= N })",
6046 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
6047 { &isl_multi_union_pw_aff_add, "[N] -> ([] : { A[x] : x >= N })",
6048 "([] : { A[x] : x <= 10 })",
6049 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
6050 { &isl_multi_union_pw_aff_union_add, "[{ A[x] -> [(1)] : x >= 5 }]",
6051 "[{ A[x] -> [(x)] : x <= 10 }]",
6052 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
6053 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
6054 { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 5 })",
6055 "([] : { A[x] : x <= 10 })",
6056 "([] : { A[x] })" },
6057 { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 0 })",
6058 "[N] -> ([] : { A[x] : x >= N })",
6059 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
6060 { &isl_multi_union_pw_aff_union_add,
6061 "[N] -> ([] : { A[] : N >= 0})",
6062 "[N] -> ([] : { A[] : N <= 0})",
6063 "[N] -> ([] : { A[] })" },
6064 { &isl_multi_union_pw_aff_union_add,
6065 "[N] -> ([] : { A[] })",
6066 "[N] -> ([] : { : })",
6067 "[N] -> ([] : { : })" },
6068 { &isl_multi_union_pw_aff_union_add,
6069 "[N] -> ([] : { : })",
6070 "[N] -> ([] : { A[] })",
6071 "[N] -> ([] : { : })" },
6072 { &isl_multi_union_pw_aff_union_add,
6073 "[N] -> ([] : { : N >= 0})",
6074 "[N] -> ([] : { : N <= 0})",
6075 "[N] -> ([] : { : })" },
6076 { &isl_multi_union_pw_aff_range_product,
6077 "B[{ A[] -> [1] }]",
6078 "C[{ A[] -> [2] }]",
6079 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
6080 { &isl_multi_union_pw_aff_range_product,
6081 "(B[] : { A[x] : x >= 5 })",
6082 "(C[] : { A[x] : x <= 10 })",
6083 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
6084 { &isl_multi_union_pw_aff_range_product,
6085 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6086 "(C[] : { A[x] : x <= 10 })",
6087 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
6088 { &isl_multi_union_pw_aff_range_product,
6089 "(C[] : { A[x] : x <= 10 })",
6090 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6091 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
6092 { &isl_multi_union_pw_aff_range_product,
6093 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6094 "[N] -> (C[] : { A[x] : x <= N })",
6095 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
6096 { &isl_multi_union_pw_aff_range_product,
6097 "[N] -> (C[] : { A[x] : x <= N })",
6098 "B[{ A[x] -> [x + 1] : x >= 5 }]",
6099 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
6100 { &isl_multi_union_pw_aff_range_product,
6101 "B[{ A[] -> [1]; D[] -> [3] }]",
6102 "C[{ A[] -> [2] }]",
6103 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
6104 { &isl_multi_union_pw_aff_range_product,
6105 "B[] }]",
6106 "(C[] : { A[x] })",
6107 "([B[] -> C[]] : { A[x] })" },
6108 { &isl_multi_union_pw_aff_range_product,
6109 "(B[] : { A[x] })",
6110 "C[] }]",
6111 "([B[] -> C[]] : { A[x] })" },
6114 /* Perform some basic tests of binary operations on
6115 * isl_multi_union_pw_aff objects.
6117 static int test_bin_mupa(isl_ctx *ctx)
6119 int i;
6120 isl_bool ok;
6121 isl_multi_union_pw_aff *mupa1, *mupa2, *res;
6123 for (i = 0; i < ARRAY_SIZE(mupa_bin_tests); ++i) {
6124 mupa1 = isl_multi_union_pw_aff_read_from_str(ctx,
6125 mupa_bin_tests[i].arg1);
6126 mupa2 = isl_multi_union_pw_aff_read_from_str(ctx,
6127 mupa_bin_tests[i].arg2);
6128 res = isl_multi_union_pw_aff_read_from_str(ctx,
6129 mupa_bin_tests[i].res);
6130 mupa1 = mupa_bin_tests[i].fn(mupa1, mupa2);
6131 ok = isl_multi_union_pw_aff_plain_is_equal(mupa1, res);
6132 isl_multi_union_pw_aff_free(mupa1);
6133 isl_multi_union_pw_aff_free(res);
6134 if (ok < 0)
6135 return -1;
6136 if (!ok)
6137 isl_die(ctx, isl_error_unknown,
6138 "unexpected result", return -1);
6141 return 0;
6144 /* Inputs for basic tests of binary operations on
6145 * pairs of isl_multi_union_pw_aff and isl_set objects.
6146 * "fn" is the function that is tested.
6147 * "arg1" and "arg2" are string descriptions of the inputs.
6148 * "res" is a string description of the expected result.
6150 struct {
6151 __isl_give isl_multi_union_pw_aff *(*fn)(
6152 __isl_take isl_multi_union_pw_aff *mupa,
6153 __isl_take isl_set *set);
6154 const char *arg1;
6155 const char *arg2;
6156 const char *res;
6157 } mupa_set_tests[] = {
6158 { &isl_multi_union_pw_aff_intersect_range,
6159 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
6160 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
6161 { &isl_multi_union_pw_aff_intersect_range,
6162 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
6163 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
6164 { &isl_multi_union_pw_aff_intersect_range,
6165 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
6166 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
6167 { &isl_multi_union_pw_aff_intersect_range,
6168 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
6169 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
6170 { &isl_multi_union_pw_aff_intersect_range,
6171 "C[]", "{ C[] }", "C[]" },
6172 { &isl_multi_union_pw_aff_intersect_range,
6173 "[N] -> (C[] : { : N >= 0 })",
6174 "{ C[] }",
6175 "[N] -> (C[] : { : N >= 0 })" },
6176 { &isl_multi_union_pw_aff_intersect_range,
6177 "(C[] : { A[a,b] })",
6178 "{ C[] }",
6179 "(C[] : { A[a,b] })" },
6180 { &isl_multi_union_pw_aff_intersect_range,
6181 "[N] -> (C[] : { A[a,b] : a,b <= N })",
6182 "{ C[] }",
6183 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
6184 { &isl_multi_union_pw_aff_intersect_range,
6185 "C[]",
6186 "[N] -> { C[] : N >= 0 }",
6187 "[N] -> (C[] : { : N >= 0 })" },
6188 { &isl_multi_union_pw_aff_intersect_range,
6189 "(C[] : { A[a,b] })",
6190 "[N] -> { C[] : N >= 0 }",
6191 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6192 { &isl_multi_union_pw_aff_intersect_range,
6193 "[N] -> (C[] : { : N >= 0 })",
6194 "[N] -> { C[] : N < 1024 }",
6195 "[N] -> (C[] : { : 0 <= N < 1024 })" },
6196 { &isl_multi_union_pw_aff_intersect_params,
6197 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
6198 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
6199 { &isl_multi_union_pw_aff_intersect_params,
6200 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
6201 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
6202 { &isl_multi_union_pw_aff_intersect_params,
6203 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
6204 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
6205 { &isl_multi_union_pw_aff_intersect_params,
6206 "C[]", "[N] -> { : N >= 0 }",
6207 "[N] -> (C[] : { : N >= 0 })" },
6208 { &isl_multi_union_pw_aff_intersect_params,
6209 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
6210 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
6211 { &isl_multi_union_pw_aff_intersect_params,
6212 "[N] -> (C[] : { A[a,N] })", "{ : }",
6213 "[N] -> (C[] : { A[a,N] })" },
6214 { &isl_multi_union_pw_aff_intersect_params,
6215 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
6216 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
6219 /* Perform some basic tests of binary operations on
6220 * pairs of isl_multi_union_pw_aff and isl_set objects.
6222 static int test_mupa_set(isl_ctx *ctx)
6224 int i;
6225 isl_bool ok;
6226 isl_multi_union_pw_aff *mupa, *res;
6227 isl_set *set;
6229 for (i = 0; i < ARRAY_SIZE(mupa_set_tests); ++i) {
6230 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6231 mupa_set_tests[i].arg1);
6232 set = isl_set_read_from_str(ctx, mupa_set_tests[i].arg2);
6233 res = isl_multi_union_pw_aff_read_from_str(ctx,
6234 mupa_set_tests[i].res);
6235 mupa = mupa_set_tests[i].fn(mupa, set);
6236 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6237 isl_multi_union_pw_aff_free(mupa);
6238 isl_multi_union_pw_aff_free(res);
6239 if (ok < 0)
6240 return -1;
6241 if (!ok)
6242 isl_die(ctx, isl_error_unknown,
6243 "unexpected result", return -1);
6246 return 0;
6249 /* Inputs for basic tests of binary operations on
6250 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6251 * "fn" is the function that is tested.
6252 * "arg1" and "arg2" are string descriptions of the inputs.
6253 * "res" is a string description of the expected result.
6255 struct {
6256 __isl_give isl_multi_union_pw_aff *(*fn)(
6257 __isl_take isl_multi_union_pw_aff *mupa,
6258 __isl_take isl_union_set *uset);
6259 const char *arg1;
6260 const char *arg2;
6261 const char *res;
6262 } mupa_uset_tests[] = {
6263 { &isl_multi_union_pw_aff_intersect_domain,
6264 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
6265 "C[{ B[i,i] -> [3i] }]" },
6266 { &isl_multi_union_pw_aff_intersect_domain,
6267 "(C[] : { B[i,j] })", "{ B[i,i] }",
6268 "(C[] : { B[i,i] })" },
6269 { &isl_multi_union_pw_aff_intersect_domain,
6270 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
6271 "[N] -> (C[] : { B[N,N] })" },
6272 { &isl_multi_union_pw_aff_intersect_domain,
6273 "C[]", "{ B[i,i] }",
6274 "(C[] : { B[i,i] })" },
6275 { &isl_multi_union_pw_aff_intersect_domain,
6276 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
6277 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
6280 /* Perform some basic tests of binary operations on
6281 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
6283 static int test_mupa_uset(isl_ctx *ctx)
6285 int i;
6286 isl_bool ok;
6287 isl_multi_union_pw_aff *mupa, *res;
6288 isl_union_set *uset;
6290 for (i = 0; i < ARRAY_SIZE(mupa_uset_tests); ++i) {
6291 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6292 mupa_uset_tests[i].arg1);
6293 uset = isl_union_set_read_from_str(ctx,
6294 mupa_uset_tests[i].arg2);
6295 res = isl_multi_union_pw_aff_read_from_str(ctx,
6296 mupa_uset_tests[i].res);
6297 mupa = mupa_uset_tests[i].fn(mupa, uset);
6298 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6299 isl_multi_union_pw_aff_free(mupa);
6300 isl_multi_union_pw_aff_free(res);
6301 if (ok < 0)
6302 return -1;
6303 if (!ok)
6304 isl_die(ctx, isl_error_unknown,
6305 "unexpected result", return -1);
6308 return 0;
6311 /* Inputs for basic tests of binary operations on
6312 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6313 * "fn" is the function that is tested.
6314 * "arg1" and "arg2" are string descriptions of the inputs.
6315 * "res" is a string description of the expected result.
6317 struct {
6318 __isl_give isl_multi_union_pw_aff *(*fn)(
6319 __isl_take isl_multi_union_pw_aff *mupa,
6320 __isl_take isl_multi_aff *ma);
6321 const char *arg1;
6322 const char *arg2;
6323 const char *res;
6324 } mupa_ma_tests[] = {
6325 { &isl_multi_union_pw_aff_apply_multi_aff,
6326 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6327 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6328 "{ C[a,b] -> D[b,a] }",
6329 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6330 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6331 { &isl_multi_union_pw_aff_apply_multi_aff,
6332 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6333 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6334 "{ C[a,b] -> D[b,a] }",
6335 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6336 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6337 { &isl_multi_union_pw_aff_apply_multi_aff,
6338 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6339 "[N] -> { C[a] -> D[a + N] }",
6340 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
6341 { &isl_multi_union_pw_aff_apply_multi_aff,
6342 "C[]",
6343 "{ C[] -> D[] }",
6344 "D[]" },
6345 { &isl_multi_union_pw_aff_apply_multi_aff,
6346 "[N] -> (C[] : { : N >= 0 })",
6347 "{ C[] -> D[] }",
6348 "[N] -> (D[] : { : N >= 0 })" },
6349 { &isl_multi_union_pw_aff_apply_multi_aff,
6350 "C[]",
6351 "[N] -> { C[] -> D[N] }",
6352 "[N] -> D[{ [N] }]" },
6353 { &isl_multi_union_pw_aff_apply_multi_aff,
6354 "(C[] : { A[i,j] : i >= j })",
6355 "{ C[] -> D[] }",
6356 "(D[] : { A[i,j] : i >= j })" },
6357 { &isl_multi_union_pw_aff_apply_multi_aff,
6358 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6359 "{ C[] -> D[] }",
6360 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6361 { &isl_multi_union_pw_aff_apply_multi_aff,
6362 "(C[] : { A[i,j] : i >= j })",
6363 "[N] -> { C[] -> D[N] }",
6364 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6367 /* Perform some basic tests of binary operations on
6368 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
6370 static int test_mupa_ma(isl_ctx *ctx)
6372 int i;
6373 isl_bool ok;
6374 isl_multi_union_pw_aff *mupa, *res;
6375 isl_multi_aff *ma;
6377 for (i = 0; i < ARRAY_SIZE(mupa_ma_tests); ++i) {
6378 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6379 mupa_ma_tests[i].arg1);
6380 ma = isl_multi_aff_read_from_str(ctx, mupa_ma_tests[i].arg2);
6381 res = isl_multi_union_pw_aff_read_from_str(ctx,
6382 mupa_ma_tests[i].res);
6383 mupa = mupa_ma_tests[i].fn(mupa, ma);
6384 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6385 isl_multi_union_pw_aff_free(mupa);
6386 isl_multi_union_pw_aff_free(res);
6387 if (ok < 0)
6388 return -1;
6389 if (!ok)
6390 isl_die(ctx, isl_error_unknown,
6391 "unexpected result", return -1);
6394 return 0;
6397 /* Inputs for basic tests of binary operations on
6398 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6399 * "fn" is the function that is tested.
6400 * "arg1" and "arg2" are string descriptions of the inputs.
6401 * "res" is a string description of the expected result.
6403 struct {
6404 __isl_give isl_union_pw_aff *(*fn)(
6405 __isl_take isl_multi_union_pw_aff *mupa,
6406 __isl_take isl_pw_aff *pa);
6407 const char *arg1;
6408 const char *arg2;
6409 const char *res;
6410 } mupa_pa_tests[] = {
6411 { &isl_multi_union_pw_aff_apply_pw_aff,
6412 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6413 "[N] -> { C[a] -> [a + N] }",
6414 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
6415 { &isl_multi_union_pw_aff_apply_pw_aff,
6416 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6417 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
6418 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6419 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
6420 { &isl_multi_union_pw_aff_apply_pw_aff,
6421 "C[]",
6422 "[N] -> { C[] -> [N] }",
6423 "[N] -> { [N] }" },
6424 { &isl_multi_union_pw_aff_apply_pw_aff,
6425 "C[]",
6426 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6427 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
6428 { &isl_multi_union_pw_aff_apply_pw_aff,
6429 "[N] -> (C[] : { : N >= 0 })",
6430 "[N] -> { C[] -> [N] }",
6431 "[N] -> { [N] : N >= 0 }" },
6432 { &isl_multi_union_pw_aff_apply_pw_aff,
6433 "[N] -> (C[] : { : N >= 0 })",
6434 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
6435 "[N] -> { [N] : N >= 0 }" },
6436 { &isl_multi_union_pw_aff_apply_pw_aff,
6437 "[N] -> (C[] : { : N >= 0 })",
6438 "{ C[] -> [0] }",
6439 "[N] -> { [0] : N >= 0 }" },
6440 { &isl_multi_union_pw_aff_apply_pw_aff,
6441 "(C[] : { A[i,j] : i >= j })",
6442 "[N] -> { C[] -> [N] }",
6443 "[N] -> { A[i,j] -> [N] : i >= j }" },
6444 { &isl_multi_union_pw_aff_apply_pw_aff,
6445 "(C[] : { A[i,j] : i >= j })",
6446 "[N] -> { C[] -> [N] : N >= 0 }",
6447 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6450 /* Perform some basic tests of binary operations on
6451 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6453 static int test_mupa_pa(isl_ctx *ctx)
6455 int i;
6456 isl_bool ok;
6457 isl_multi_union_pw_aff *mupa;
6458 isl_union_pw_aff *upa, *res;
6459 isl_pw_aff *pa;
6461 for (i = 0; i < ARRAY_SIZE(mupa_pa_tests); ++i) {
6462 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6463 mupa_pa_tests[i].arg1);
6464 pa = isl_pw_aff_read_from_str(ctx, mupa_pa_tests[i].arg2);
6465 res = isl_union_pw_aff_read_from_str(ctx,
6466 mupa_pa_tests[i].res);
6467 upa = mupa_pa_tests[i].fn(mupa, pa);
6468 ok = isl_union_pw_aff_plain_is_equal(upa, res);
6469 isl_union_pw_aff_free(upa);
6470 isl_union_pw_aff_free(res);
6471 if (ok < 0)
6472 return -1;
6473 if (!ok)
6474 isl_die(ctx, isl_error_unknown,
6475 "unexpected result", return -1);
6478 return 0;
6481 /* Inputs for basic tests of binary operations on
6482 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6483 * "fn" is the function that is tested.
6484 * "arg1" and "arg2" are string descriptions of the inputs.
6485 * "res" is a string description of the expected result.
6487 struct {
6488 __isl_give isl_multi_union_pw_aff *(*fn)(
6489 __isl_take isl_multi_union_pw_aff *mupa,
6490 __isl_take isl_pw_multi_aff *pma);
6491 const char *arg1;
6492 const char *arg2;
6493 const char *res;
6494 } mupa_pma_tests[] = {
6495 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6496 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6497 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6498 "{ C[a,b] -> D[b,a] }",
6499 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6500 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6501 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6502 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6503 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6504 "{ C[a,b] -> D[b,a] }",
6505 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6506 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6507 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6508 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6509 "[N] -> { C[a] -> D[a + N] }",
6510 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6511 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6512 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6513 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6514 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6515 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6516 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6517 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6518 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6519 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6520 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6521 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6522 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6523 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6524 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6525 "C[]",
6526 "{ C[] -> D[] }",
6527 "D[]" },
6528 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6529 "[N] -> (C[] : { : N >= 0 })",
6530 "{ C[] -> D[] }",
6531 "[N] -> (D[] : { : N >= 0 })" },
6532 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6533 "C[]",
6534 "[N] -> { C[] -> D[N] }",
6535 "[N] -> D[{ [N] }]" },
6536 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6537 "(C[] : { A[i,j] : i >= j })",
6538 "{ C[] -> D[] }",
6539 "(D[] : { A[i,j] : i >= j })" },
6540 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6541 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6542 "{ C[] -> D[] }",
6543 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6544 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6545 "(C[] : { A[i,j] : i >= j })",
6546 "[N] -> { C[] -> D[N] }",
6547 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6548 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6549 "C[]",
6550 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6551 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6552 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6553 "[N] -> (C[] : { : N >= 0 })",
6554 "[N] -> { C[] -> D[N] }",
6555 "[N] -> D[{ [N] : N >= 0 }]" },
6556 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6557 "[N] -> (C[] : { : N >= 0 })",
6558 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6559 "[N] -> D[{ [N] : N >= 0 }]" },
6560 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6561 "[N] -> (C[] : { : N >= 0 })",
6562 "{ C[] -> D[0] }",
6563 "[N] -> D[{ [0] : N >= 0 }]" },
6564 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6565 "(C[] : { A[i,j] : i >= j })",
6566 "[N] -> { C[] -> D[N] : N >= 0 }",
6567 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6570 /* Perform some basic tests of binary operations on
6571 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6573 static int test_mupa_pma(isl_ctx *ctx)
6575 int i;
6576 isl_bool ok;
6577 isl_multi_union_pw_aff *mupa, *res;
6578 isl_pw_multi_aff *pma;
6580 for (i = 0; i < ARRAY_SIZE(mupa_pma_tests); ++i) {
6581 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6582 mupa_pma_tests[i].arg1);
6583 pma = isl_pw_multi_aff_read_from_str(ctx,
6584 mupa_pma_tests[i].arg2);
6585 res = isl_multi_union_pw_aff_read_from_str(ctx,
6586 mupa_pma_tests[i].res);
6587 mupa = mupa_pma_tests[i].fn(mupa, pma);
6588 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6589 isl_multi_union_pw_aff_free(mupa);
6590 isl_multi_union_pw_aff_free(res);
6591 if (ok < 0)
6592 return -1;
6593 if (!ok)
6594 isl_die(ctx, isl_error_unknown,
6595 "unexpected result", return -1);
6598 return 0;
6601 /* Inputs for basic tests of binary operations on
6602 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6603 * "fn" is the function that is tested.
6604 * "arg1" and "arg2" are string descriptions of the inputs.
6605 * "res" is a string description of the expected result.
6607 struct {
6608 __isl_give isl_multi_union_pw_aff *(*fn)(
6609 __isl_take isl_multi_union_pw_aff *mupa,
6610 __isl_take isl_union_pw_multi_aff *upma);
6611 const char *arg1;
6612 const char *arg2;
6613 const char *res;
6614 } mupa_upma_tests[] = {
6615 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6616 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6617 "C[{ A[a,b] -> [b + 2a] }]" },
6618 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6619 "C[{ B[i,j] -> [i + 2j] }]",
6620 "{ A[a,b] -> B[b,a] : b > a }",
6621 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6622 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6623 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6624 "{ A[a,b] -> B[b,a] : b > a }",
6625 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6626 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6627 "C[{ B[i,j] -> [i + 2j] }]",
6628 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6629 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6630 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6631 "(C[] : { B[a,b] })",
6632 "{ A[a,b] -> B[b,a] }",
6633 "(C[] : { A[a,b] })" },
6634 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6635 "(C[] : { B[a,b] })",
6636 "{ B[a,b] -> A[b,a] }",
6637 "(C[] : { })" },
6638 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6639 "(C[] : { B[a,b] })",
6640 "{ A[a,b] -> B[b,a] : a > b }",
6641 "(C[] : { A[a,b] : a > b })" },
6642 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6643 "(C[] : { B[a,b] : a > b })",
6644 "{ A[a,b] -> B[b,a] }",
6645 "(C[] : { A[a,b] : b > a })" },
6646 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6647 "[N] -> (C[] : { B[a,b] : a > N })",
6648 "{ A[a,b] -> B[b,a] : a > b }",
6649 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6650 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6651 "(C[] : { B[a,b] : a > b })",
6652 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6653 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6654 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6655 "C[]",
6656 "{ A[a,b] -> B[b,a] }",
6657 "C[]" },
6658 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6659 "[N] -> (C[] : { : N >= 0 })",
6660 "{ A[a,b] -> B[b,a] }",
6661 "[N] -> (C[] : { : N >= 0 })" },
6662 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6663 "C[]",
6664 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6665 "[N] -> (C[] : { : N >= 0 })" },
6668 /* Perform some basic tests of binary operations on
6669 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6671 static int test_mupa_upma(isl_ctx *ctx)
6673 int i;
6674 isl_bool ok;
6675 isl_multi_union_pw_aff *mupa, *res;
6676 isl_union_pw_multi_aff *upma;
6678 for (i = 0; i < ARRAY_SIZE(mupa_upma_tests); ++i) {
6679 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6680 mupa_upma_tests[i].arg1);
6681 upma = isl_union_pw_multi_aff_read_from_str(ctx,
6682 mupa_upma_tests[i].arg2);
6683 res = isl_multi_union_pw_aff_read_from_str(ctx,
6684 mupa_upma_tests[i].res);
6685 mupa = mupa_upma_tests[i].fn(mupa, upma);
6686 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6687 isl_multi_union_pw_aff_free(mupa);
6688 isl_multi_union_pw_aff_free(res);
6689 if (ok < 0)
6690 return -1;
6691 if (!ok)
6692 isl_die(ctx, isl_error_unknown,
6693 "unexpected result", return -1);
6696 return 0;
6699 /* Check that the input tuple of an isl_aff can be set properly.
6701 static isl_stat test_aff_set_tuple_id(isl_ctx *ctx)
6703 isl_id *id;
6704 isl_aff *aff;
6705 isl_stat equal;
6707 aff = isl_aff_read_from_str(ctx, "{ [x] -> [x + 1] }");
6708 id = isl_id_alloc(ctx, "A", NULL);
6709 aff = isl_aff_set_tuple_id(aff, isl_dim_in, id);
6710 equal = aff_check_plain_equal(aff, "{ A[x] -> [x + 1] }");
6711 isl_aff_free(aff);
6712 if (equal < 0)
6713 return isl_stat_error;
6715 return isl_stat_ok;
6718 /* Check that affine expressions get normalized on addition/subtraction.
6719 * In particular, check that (final) unused integer divisions get removed
6720 * such that an expression derived from expressions with integer divisions
6721 * is found to be obviously equal to one that is created directly.
6723 static isl_stat test_aff_normalize(isl_ctx *ctx)
6725 isl_aff *aff, *aff2;
6726 isl_stat ok;
6728 aff = isl_aff_read_from_str(ctx, "{ [x] -> [x//2] }");
6729 aff2 = isl_aff_read_from_str(ctx, "{ [x] -> [1 + x//2] }");
6730 aff = isl_aff_sub(aff2, aff);
6731 ok = aff_check_plain_equal(aff, "{ [x] -> [1] }");
6732 isl_aff_free(aff);
6734 return ok;
6737 int test_aff(isl_ctx *ctx)
6739 const char *str;
6740 isl_set *set;
6741 isl_space *space;
6742 isl_local_space *ls;
6743 isl_aff *aff;
6744 int zero;
6745 isl_stat equal;
6747 if (test_upa(ctx) < 0)
6748 return -1;
6749 if (test_bin_aff(ctx) < 0)
6750 return -1;
6751 if (test_bin_pw_aff(ctx) < 0)
6752 return -1;
6753 if (test_upma_test(ctx) < 0)
6754 return -1;
6755 if (test_bin_upma(ctx) < 0)
6756 return -1;
6757 if (test_bin_upma_fail(ctx) < 0)
6758 return -1;
6759 if (test_upma_uset(ctx) < 0)
6760 return -1;
6761 if (test_un_mpa(ctx) < 0)
6762 return -1;
6763 if (test_bin_mpa(ctx) < 0)
6764 return -1;
6765 if (test_un_mupa(ctx) < 0)
6766 return -1;
6767 if (test_bin_mupa(ctx) < 0)
6768 return -1;
6769 if (test_mupa_set(ctx) < 0)
6770 return -1;
6771 if (test_mupa_uset(ctx) < 0)
6772 return -1;
6773 if (test_mupa_ma(ctx) < 0)
6774 return -1;
6775 if (test_mupa_pa(ctx) < 0)
6776 return -1;
6777 if (test_mupa_pma(ctx) < 0)
6778 return -1;
6779 if (test_mupa_upma(ctx) < 0)
6780 return -1;
6782 space = isl_space_set_alloc(ctx, 0, 1);
6783 ls = isl_local_space_from_space(space);
6784 aff = isl_aff_zero_on_domain(ls);
6786 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6787 aff = isl_aff_scale_down_ui(aff, 3);
6788 aff = isl_aff_floor(aff);
6789 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6790 aff = isl_aff_scale_down_ui(aff, 2);
6791 aff = isl_aff_floor(aff);
6792 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6794 str = "{ [10] }";
6795 set = isl_set_read_from_str(ctx, str);
6796 aff = isl_aff_gist(aff, set);
6798 aff = isl_aff_add_constant_si(aff, -16);
6799 zero = isl_aff_plain_is_zero(aff);
6800 isl_aff_free(aff);
6802 if (zero < 0)
6803 return -1;
6804 if (!zero)
6805 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6807 aff = isl_aff_read_from_str(ctx, "{ [-1] }");
6808 aff = isl_aff_scale_down_ui(aff, 64);
6809 aff = isl_aff_floor(aff);
6810 equal = aff_check_plain_equal(aff, "{ [-1] }");
6811 isl_aff_free(aff);
6812 if (equal < 0)
6813 return -1;
6815 if (test_aff_set_tuple_id(ctx) < 0)
6816 return -1;
6817 if (test_aff_normalize(ctx) < 0)
6818 return -1;
6820 return 0;
6823 /* Inputs for isl_set_bind tests.
6824 * "set" is the input set.
6825 * "tuple" is the binding tuple.
6826 * "res" is the expected result.
6828 static
6829 struct {
6830 const char *set;
6831 const char *tuple;
6832 const char *res;
6833 } bind_set_tests[] = {
6834 { "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6835 "{ A[M, N] }",
6836 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6837 { "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }",
6838 "{ B[N, M] }",
6839 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6840 { "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }",
6841 "{ C[N] }",
6842 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6843 { "[M] -> { D[x, N] : x mod 2 = 0 and N mod 8 = 3 and M >= 0 }",
6844 "{ D[M, N] }",
6845 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 and M >= 0 }" },
6848 /* Perform basic isl_set_bind tests.
6850 static isl_stat test_bind_set(isl_ctx *ctx)
6852 int i;
6854 for (i = 0; i < ARRAY_SIZE(bind_set_tests); ++i) {
6855 const char *str;
6856 isl_set *set;
6857 isl_multi_id *tuple;
6858 isl_stat r;
6860 set = isl_set_read_from_str(ctx, bind_set_tests[i].set);
6861 str = bind_set_tests[i].tuple;
6862 tuple = isl_multi_id_read_from_str(ctx, str);
6863 set = isl_set_bind(set, tuple);
6864 r = set_check_equal(set, bind_set_tests[i].res);
6865 isl_set_free(set);
6866 if (r < 0)
6867 return isl_stat_error;
6870 return isl_stat_ok;
6873 /* Inputs for isl_map_bind_domain tests.
6874 * "map" is the input map.
6875 * "tuple" is the binding tuple.
6876 * "res" is the expected result.
6878 struct {
6879 const char *map;
6880 const char *tuple;
6881 const char *res;
6882 } bind_map_domain_tests[] = {
6883 { "{ A[M, N] -> [M + floor(N/2)] }",
6884 "{ A[M, N] }",
6885 "[M, N] -> { [M + floor(N/2)] }" },
6886 { "{ B[N, M] -> [M + floor(N/2)] }",
6887 "{ B[N, M] }",
6888 "[N, M] -> { [M + floor(N/2)] }" },
6889 { "[M] -> { C[N] -> [M + floor(N/2)] }",
6890 "{ C[N] }",
6891 "[M, N] -> { [M + floor(N/2)] }" },
6892 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
6893 "{ C[M, N] }",
6894 "[M, N] -> { [M + floor(N/2)] }" },
6895 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
6896 "{ C[M, N] }",
6897 "[M, N] -> { [M + floor(N/2)] }" },
6898 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
6899 "{ C[N, M] }",
6900 "[A, N, M] -> { [M + floor(N/2)] }" },
6903 /* Perform basic isl_map_bind_domain tests.
6905 static isl_stat test_bind_map_domain(isl_ctx *ctx)
6907 int i;
6909 for (i = 0; i < ARRAY_SIZE(bind_map_domain_tests); ++i) {
6910 const char *str;
6911 isl_map *map;
6912 isl_set *set;
6913 isl_multi_id *tuple;
6914 isl_stat r;
6916 str = bind_map_domain_tests[i].map;
6917 map = isl_map_read_from_str(ctx, str);
6918 str = bind_map_domain_tests[i].tuple;
6919 tuple = isl_multi_id_read_from_str(ctx, str);
6920 set = isl_map_bind_domain(map, tuple);
6921 str = bind_map_domain_tests[i].res;
6922 r = set_check_equal(set, str);
6923 isl_set_free(set);
6924 if (r < 0)
6925 return isl_stat_error;
6928 return isl_stat_ok;
6931 /* Inputs for isl_union_map_bind_range tests.
6932 * "map" is the input union map.
6933 * "tuple" is the binding tuple.
6934 * "res" is the expected result.
6936 struct {
6937 const char *map;
6938 const char *tuple;
6939 const char *res;
6940 } bind_umap_range_tests[] = {
6941 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6942 "{ A[M, N] }",
6943 "[M, N] -> { B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
6944 { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6945 "{ B[M, N] }",
6946 "{ }" },
6947 { "{ A[] -> B[]; C[] -> D[]; E[] -> B[] }",
6948 "{ B[] }",
6949 "{ A[]; E[] }" },
6952 /* Perform basic isl_union_map_bind_range tests.
6954 static isl_stat test_bind_umap_range(isl_ctx *ctx)
6956 int i;
6958 for (i = 0; i < ARRAY_SIZE(bind_umap_range_tests); ++i) {
6959 const char *str;
6960 isl_union_map *umap;
6961 isl_union_set *uset;
6962 isl_multi_id *tuple;
6963 isl_stat r;
6965 str = bind_umap_range_tests[i].map;
6966 umap = isl_union_map_read_from_str(ctx, str);
6967 str = bind_umap_range_tests[i].tuple;
6968 tuple = isl_multi_id_read_from_str(ctx, str);
6969 uset = isl_union_map_bind_range(umap, tuple);
6970 str = bind_umap_range_tests[i].res;
6971 r = uset_check_equal(uset, str);
6972 isl_union_set_free(uset);
6973 if (r < 0)
6974 return isl_stat_error;
6977 return isl_stat_ok;
6980 /* Inputs for isl_pw_multi_aff_bind_domain tests.
6981 * "pma" is the input expression.
6982 * "tuple" is the binding tuple.
6983 * "res" is the expected result.
6985 struct {
6986 const char *pma;
6987 const char *tuple;
6988 const char *res;
6989 } bind_pma_domain_tests[] = {
6990 { "{ A[M, N] -> [M + floor(N/2)] }",
6991 "{ A[M, N] }",
6992 "[M, N] -> { [M + floor(N/2)] }" },
6993 { "{ B[N, M] -> [M + floor(N/2)] }",
6994 "{ B[N, M] }",
6995 "[N, M] -> { [M + floor(N/2)] }" },
6996 { "[M] -> { C[N] -> [M + floor(N/2)] }",
6997 "{ C[N] }",
6998 "[M, N] -> { [M + floor(N/2)] }" },
6999 { "[M] -> { C[x, N] -> [x + floor(N/2)] }",
7000 "{ C[M, N] }",
7001 "[M, N] -> { [M + floor(N/2)] }" },
7002 { "[M] -> { C[x, N] -> [M + floor(N/2)] }",
7003 "{ C[M, N] }",
7004 "[M, N] -> { [M + floor(N/2)] }" },
7005 { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }",
7006 "{ C[N, M] }",
7007 "[A, N, M] -> { [M + floor(N/2)] }" },
7010 /* Perform basic isl_pw_multi_aff_bind_domain tests.
7012 static isl_stat test_bind_pma_domain(isl_ctx *ctx)
7014 int i;
7016 for (i = 0; i < ARRAY_SIZE(bind_pma_domain_tests); ++i) {
7017 const char *str;
7018 isl_pw_multi_aff *pma;
7019 isl_multi_id *tuple;
7020 isl_stat r;
7022 str = bind_pma_domain_tests[i].pma;
7023 pma = isl_pw_multi_aff_read_from_str(ctx, str);
7024 str = bind_pma_domain_tests[i].tuple;
7025 tuple = isl_multi_id_read_from_str(ctx, str);
7026 pma = isl_pw_multi_aff_bind_domain(pma, tuple);
7027 str = bind_pma_domain_tests[i].res;
7028 r = pw_multi_aff_check_plain_equal(pma, str);
7029 isl_pw_multi_aff_free(pma);
7030 if (r < 0)
7031 return isl_stat_error;
7034 return isl_stat_ok;
7037 /* Inputs for isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7038 * "pma" is the input expression.
7039 * "tuple" is the binding tuple.
7040 * "res" is the expected result.
7042 struct {
7043 const char *pma;
7044 const char *tuple;
7045 const char *res;
7046 } bind_pma_domain_wrapped_tests[] = {
7047 { "{ [A[M, N] -> B[]] -> [M + floor(N/2)] }",
7048 "{ A[M, N] }",
7049 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7050 { "{ [B[N, M] -> D[]] -> [M + floor(N/2)] }",
7051 "{ B[N, M] }",
7052 "[N, M] -> { D[] -> [M + floor(N/2)] }" },
7053 { "[M] -> { [C[N] -> B[x]] -> [x + M + floor(N/2)] }",
7054 "{ C[N] }",
7055 "[M, N] -> { B[x] -> [x + M + floor(N/2)] }" },
7056 { "[M] -> { [C[x, N] -> B[]] -> [x + floor(N/2)] }",
7057 "{ C[M, N] }",
7058 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7059 { "[M] -> { [C[x, N] -> B[]] -> [M + floor(N/2)] }",
7060 "{ C[M, N] }",
7061 "[M, N] -> { B[] -> [M + floor(N/2)] }" },
7062 { "[A, M] -> { [C[N, x] -> B[]] -> [x + floor(N/2)] }",
7063 "{ C[N, M] }",
7064 "[A, N, M] -> { B[] -> [M + floor(N/2)] }" },
7067 /* Perform basic isl_pw_multi_aff_bind_domain_wrapped_domain tests.
7069 static isl_stat test_bind_pma_domain_wrapped(isl_ctx *ctx)
7071 int i;
7073 for (i = 0; i < ARRAY_SIZE(bind_pma_domain_wrapped_tests); ++i) {
7074 const char *str;
7075 isl_pw_multi_aff *pma;
7076 isl_multi_id *tuple;
7077 isl_stat r;
7079 str = bind_pma_domain_wrapped_tests[i].pma;
7080 pma = isl_pw_multi_aff_read_from_str(ctx, str);
7081 str = bind_pma_domain_wrapped_tests[i].tuple;
7082 tuple = isl_multi_id_read_from_str(ctx, str);
7083 pma = isl_pw_multi_aff_bind_domain_wrapped_domain(pma, tuple);
7084 str = bind_pma_domain_wrapped_tests[i].res;
7085 r = pw_multi_aff_check_plain_equal(pma, str);
7086 isl_pw_multi_aff_free(pma);
7087 if (r < 0)
7088 return isl_stat_error;
7091 return isl_stat_ok;
7094 /* Inputs for isl_aff_bind_id tests.
7095 * "aff" is the input expression.
7096 * "id" is the binding id.
7097 * "res" is the expected result.
7099 static
7100 struct {
7101 const char *aff;
7102 const char *id;
7103 const char *res;
7104 } bind_aff_tests[] = {
7105 { "{ [4] }", "M", "[M = 4] -> { : }" },
7106 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7107 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7108 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7109 { "{ [NaN] }", "M", "{ : false }" },
7110 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7113 /* Perform basic isl_aff_bind_id tests.
7115 static isl_stat test_bind_aff(isl_ctx *ctx)
7117 int i;
7119 for (i = 0; i < ARRAY_SIZE(bind_aff_tests); ++i) {
7120 isl_aff *aff;
7121 isl_set *res;
7122 isl_id *id;
7123 isl_stat r;
7125 aff = isl_aff_read_from_str(ctx, bind_aff_tests[i].aff);
7126 id = isl_id_read_from_str(ctx, bind_aff_tests[i].id);
7127 res = isl_set_from_basic_set(isl_aff_bind_id(aff, id));
7128 r = set_check_equal(res, bind_aff_tests[i].res);
7129 isl_set_free(res);
7130 if (r < 0)
7131 return isl_stat_error;
7134 return isl_stat_ok;
7137 /* Inputs for isl_pw_aff_bind_id tests.
7138 * "pa" is the input expression.
7139 * "id" is the binding id.
7140 * "res" is the expected result.
7142 static
7143 struct {
7144 const char *pa;
7145 const char *id;
7146 const char *res;
7147 } bind_pa_tests[] = {
7148 { "{ [4] }", "M", "[M = 4] -> { : }" },
7149 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
7150 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
7151 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
7152 { "[M] -> { [M] : M >= 0; [-M] : M < 0 }", "M", "[M] -> { : M >= 0 }" },
7153 { "{ [NaN] }", "M", "{ : false }" },
7154 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
7157 /* Perform basic isl_pw_aff_bind_id tests.
7159 static isl_stat test_bind_pa(isl_ctx *ctx)
7161 int i;
7163 for (i = 0; i < ARRAY_SIZE(bind_pa_tests); ++i) {
7164 isl_pw_aff *pa;
7165 isl_set *res;
7166 isl_id *id;
7167 isl_stat r;
7169 pa = isl_pw_aff_read_from_str(ctx, bind_pa_tests[i].pa);
7170 id = isl_id_read_from_str(ctx, bind_pa_tests[i].id);
7171 res = isl_pw_aff_bind_id(pa, id);
7172 r = set_check_equal(res, bind_pa_tests[i].res);
7173 isl_set_free(res);
7174 if (r < 0)
7175 return isl_stat_error;
7178 return isl_stat_ok;
7181 /* Inputs for isl_multi_union_pw_aff_bind tests.
7182 * "mupa" is the input expression.
7183 * "tuple" is the binding tuple.
7184 * "res" is the expected result.
7186 static
7187 struct {
7188 const char *mupa;
7189 const char *tuple;
7190 const char *res;
7191 } bind_mupa_tests[] = {
7192 { "A[{ [4] }, { [5] }]",
7193 "{ A[M, N] }",
7194 "[M = 4, N = 5] -> { : }" },
7195 { "A[{ B[x] -> [floor(x/2)] }, { B[y] -> [y + 5] }]",
7196 "{ A[M, N] }",
7197 "[M, N] -> { B[x] : M = floor(x/2) and N = x + 5 }" },
7198 { "[M] -> A[{ [4] }, { [M + 1] }]",
7199 "{ A[M, N] }",
7200 "[M = 4, N = 5] -> { : }" },
7203 /* Perform basic isl_multi_union_pw_aff_bind tests.
7205 static isl_stat test_bind_mupa(isl_ctx *ctx)
7207 int i;
7209 for (i = 0; i < ARRAY_SIZE(bind_mupa_tests); ++i) {
7210 const char *str;
7211 isl_multi_union_pw_aff *mupa;
7212 isl_union_set *res;
7213 isl_multi_id *tuple;
7214 isl_stat r;
7216 str = bind_mupa_tests[i].mupa;
7217 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
7218 str = bind_mupa_tests[i].tuple;
7219 tuple = isl_multi_id_read_from_str(ctx, str);
7220 res = isl_multi_union_pw_aff_bind(mupa, tuple);
7221 r = uset_check_equal(res, bind_mupa_tests[i].res);
7222 isl_union_set_free(res);
7223 if (r < 0)
7224 return isl_stat_error;
7227 return isl_stat_ok;
7230 /* Perform tests that reinterpret dimensions as parameters.
7232 static int test_bind(isl_ctx *ctx)
7234 if (test_bind_set(ctx) < 0)
7235 return -1;
7236 if (test_bind_map_domain(ctx) < 0)
7237 return -1;
7238 if (test_bind_umap_range(ctx) < 0)
7239 return -1;
7240 if (test_bind_pma_domain(ctx) < 0)
7241 return -1;
7242 if (test_bind_pma_domain_wrapped(ctx) < 0)
7243 return -1;
7244 if (test_bind_aff(ctx) < 0)
7245 return -1;
7246 if (test_bind_pa(ctx) < 0)
7247 return -1;
7248 if (test_bind_mupa(ctx) < 0)
7249 return -1;
7251 return 0;
7254 /* Inputs for isl_set_unbind_params tests.
7255 * "set" is the input parameter domain.
7256 * "tuple" is the tuple of the constructed set.
7257 * "res" is the expected result.
7259 struct {
7260 const char *set;
7261 const char *tuple;
7262 const char *res;
7263 } unbind_set_tests[] = {
7264 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7265 "{ A[M, N] }",
7266 "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7267 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7268 "{ B[N, M] }",
7269 "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
7270 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7271 "{ C[N] }",
7272 "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }" },
7273 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
7274 "{ D[T, N] }",
7275 "[M] -> { D[x, N] : M mod 2 = 0 and N mod 8 = 3 }" },
7278 /* Perform basic isl_set_unbind_params tests.
7280 static isl_stat test_unbind_set(isl_ctx *ctx)
7282 int i;
7284 for (i = 0; i < ARRAY_SIZE(unbind_set_tests); ++i) {
7285 const char *str;
7286 isl_set *set;
7287 isl_multi_id *tuple;
7288 isl_stat r;
7290 set = isl_set_read_from_str(ctx, unbind_set_tests[i].set);
7291 str = unbind_set_tests[i].tuple;
7292 tuple = isl_multi_id_read_from_str(ctx, str);
7293 set = isl_set_unbind_params(set, tuple);
7294 r = set_check_equal(set, unbind_set_tests[i].res);
7295 isl_set_free(set);
7296 if (r < 0)
7297 return isl_stat_error;
7300 return isl_stat_ok;
7303 /* Inputs for isl_aff_unbind_params_insert_domain tests.
7304 * "aff" is the input affine expression defined over a parameter domain.
7305 * "tuple" is the tuple of the domain that gets introduced.
7306 * "res" is the expected result.
7308 struct {
7309 const char *aff;
7310 const char *tuple;
7311 const char *res;
7312 } unbind_aff_tests[] = {
7313 { "[M, N] -> { [M + floor(N/2)] }",
7314 "{ A[M, N] }",
7315 "{ A[M, N] -> [M + floor(N/2)] }" },
7316 { "[M, N] -> { [M + floor(N/2)] }",
7317 "{ B[N, M] }",
7318 "{ B[N, M] -> [M + floor(N/2)] }" },
7319 { "[M, N] -> { [M + floor(N/2)] }",
7320 "{ C[N] }",
7321 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7322 { "[M, N] -> { [M + floor(N/2)] }",
7323 "{ D[A, B, C, N, Z] }",
7324 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7327 /* Perform basic isl_aff_unbind_params_insert_domain tests.
7329 static isl_stat test_unbind_aff(isl_ctx *ctx)
7331 int i;
7333 for (i = 0; i < ARRAY_SIZE(unbind_aff_tests); ++i) {
7334 const char *str;
7335 isl_aff *aff;
7336 isl_multi_id *tuple;
7337 isl_stat r;
7339 aff = isl_aff_read_from_str(ctx, unbind_aff_tests[i].aff);
7340 str = unbind_aff_tests[i].tuple;
7341 tuple = isl_multi_id_read_from_str(ctx, str);
7342 aff = isl_aff_unbind_params_insert_domain(aff, tuple);
7343 r = aff_check_plain_equal(aff, unbind_aff_tests[i].res);
7344 isl_aff_free(aff);
7345 if (r < 0)
7346 return isl_stat_error;
7349 return isl_stat_ok;
7352 /* Inputs for isl_multi_aff_unbind_params_insert_domain tests.
7353 * "ma" is the input multi affine expression defined over a parameter domain.
7354 * "tuple" is the tuple of the domain that gets introduced.
7355 * "res" is the expected result.
7357 static struct {
7358 const char *ma;
7359 const char *tuple;
7360 const char *res;
7361 } unbind_multi_aff_tests[] = {
7362 { "[M, N] -> { T[M + floor(N/2)] }",
7363 "{ A[M, N] }",
7364 "{ A[M, N] -> T[M + floor(N/2)] }" },
7365 { "[M, N] -> { [M + floor(N/2)] }",
7366 "{ B[N, M] }",
7367 "{ B[N, M] -> [M + floor(N/2)] }" },
7368 { "[M, N] -> { [M + floor(N/2)] }",
7369 "{ C[N] }",
7370 "[M] -> { C[N] -> [M + floor(N/2)] }" },
7371 { "[M, N] -> { [M + floor(N/2)] }",
7372 "{ D[A, B, C, N, Z] }",
7373 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
7374 { "[M, N] -> { T[M + floor(N/2), N + floor(M/3)] }",
7375 "{ A[M, N] }",
7376 "{ A[M, N] -> T[M + floor(N/2), N + floor(M/3)] }" },
7379 /* Perform basic isl_multi_aff_unbind_params_insert_domain tests.
7381 static isl_stat test_unbind_multi_aff(isl_ctx *ctx)
7383 int i;
7385 for (i = 0; i < ARRAY_SIZE(unbind_multi_aff_tests); ++i) {
7386 const char *str;
7387 isl_multi_aff *ma;
7388 isl_multi_id *tuple;
7389 isl_stat r;
7391 str = unbind_multi_aff_tests[i].ma;
7392 ma = isl_multi_aff_read_from_str(ctx, str);
7393 str = unbind_multi_aff_tests[i].tuple;
7394 tuple = isl_multi_id_read_from_str(ctx, str);
7395 ma = isl_multi_aff_unbind_params_insert_domain(ma, tuple);
7396 str = unbind_multi_aff_tests[i].res;
7397 r = multi_aff_check_plain_equal(ma, str);
7398 isl_multi_aff_free(ma);
7399 if (r < 0)
7400 return isl_stat_error;
7403 return isl_stat_ok;
7406 /* Perform tests that reinterpret parameters.
7408 static int test_unbind(isl_ctx *ctx)
7410 if (test_unbind_set(ctx) < 0)
7411 return -1;
7412 if (test_unbind_aff(ctx) < 0)
7413 return -1;
7414 if (test_unbind_multi_aff(ctx) < 0)
7415 return -1;
7417 return 0;
7420 /* Check that "pa" consists of a single expression.
7422 static int check_single_piece(isl_ctx *ctx, __isl_take isl_pw_aff *pa)
7424 isl_size n;
7426 n = isl_pw_aff_n_piece(pa);
7427 isl_pw_aff_free(pa);
7429 if (n < 0)
7430 return -1;
7431 if (n != 1)
7432 isl_die(ctx, isl_error_unknown, "expecting single expression",
7433 return -1);
7435 return 0;
7438 /* Check that the computation below results in a single expression.
7439 * One or two expressions may result depending on which constraint
7440 * ends up being considered as redundant with respect to the other
7441 * constraints after the projection that is performed internally
7442 * by isl_set_dim_min.
7444 static int test_dim_max_1(isl_ctx *ctx)
7446 const char *str;
7447 isl_set *set;
7448 isl_pw_aff *pa;
7450 str = "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
7451 "-4a <= b <= 3 and b < n - 4a }";
7452 set = isl_set_read_from_str(ctx, str);
7453 pa = isl_set_dim_min(set, 0);
7454 return check_single_piece(ctx, pa);
7457 /* Check that the computation below results in a single expression.
7458 * The PIP problem corresponding to these constraints has a row
7459 * that causes a split of the solution domain. The solver should
7460 * first pick rows that split off empty parts such that the actual
7461 * solution domain does not get split.
7462 * Note that the description contains some redundant constraints.
7463 * If these constraints get removed first, then the row mentioned
7464 * above does not appear in the PIP problem.
7466 static int test_dim_max_2(isl_ctx *ctx)
7468 const char *str;
7469 isl_set *set;
7470 isl_pw_aff *pa;
7472 str = "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
7473 "N > 0 and P >= 0 }";
7474 set = isl_set_read_from_str(ctx, str);
7475 pa = isl_set_dim_max(set, 0);
7476 return check_single_piece(ctx, pa);
7479 int test_dim_max(isl_ctx *ctx)
7481 int equal;
7482 const char *str;
7483 isl_set *set1, *set2;
7484 isl_set *set;
7485 isl_map *map;
7486 isl_pw_aff *pwaff;
7488 if (test_dim_max_1(ctx) < 0)
7489 return -1;
7490 if (test_dim_max_2(ctx) < 0)
7491 return -1;
7493 str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
7494 set = isl_set_read_from_str(ctx, str);
7495 pwaff = isl_set_dim_max(set, 0);
7496 set1 = isl_set_from_pw_aff(pwaff);
7497 str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
7498 set2 = isl_set_read_from_str(ctx, str);
7499 equal = isl_set_is_equal(set1, set2);
7500 isl_set_free(set1);
7501 isl_set_free(set2);
7502 if (equal < 0)
7503 return -1;
7504 if (!equal)
7505 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7507 str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
7508 set = isl_set_read_from_str(ctx, str);
7509 pwaff = isl_set_dim_max(set, 0);
7510 set1 = isl_set_from_pw_aff(pwaff);
7511 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7512 set2 = isl_set_read_from_str(ctx, str);
7513 equal = isl_set_is_equal(set1, set2);
7514 isl_set_free(set1);
7515 isl_set_free(set2);
7516 if (equal < 0)
7517 return -1;
7518 if (!equal)
7519 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7521 str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
7522 set = isl_set_read_from_str(ctx, str);
7523 pwaff = isl_set_dim_max(set, 0);
7524 set1 = isl_set_from_pw_aff(pwaff);
7525 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
7526 set2 = isl_set_read_from_str(ctx, str);
7527 equal = isl_set_is_equal(set1, set2);
7528 isl_set_free(set1);
7529 isl_set_free(set2);
7530 if (equal < 0)
7531 return -1;
7532 if (!equal)
7533 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7535 str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
7536 "0 <= i < N and 0 <= j < M }";
7537 map = isl_map_read_from_str(ctx, str);
7538 set = isl_map_range(map);
7540 pwaff = isl_set_dim_max(isl_set_copy(set), 0);
7541 set1 = isl_set_from_pw_aff(pwaff);
7542 str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
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);
7548 pwaff = isl_set_dim_max(isl_set_copy(set), 3);
7549 set1 = isl_set_from_pw_aff(pwaff);
7550 str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
7551 set2 = isl_set_read_from_str(ctx, str);
7552 if (equal >= 0 && equal)
7553 equal = isl_set_is_equal(set1, set2);
7554 isl_set_free(set1);
7555 isl_set_free(set2);
7557 isl_set_free(set);
7559 if (equal < 0)
7560 return -1;
7561 if (!equal)
7562 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7564 /* Check that solutions are properly merged. */
7565 str = "[n] -> { [a, b, c] : c >= -4a - 2b and "
7566 "c <= -1 + n - 4a - 2b and c >= -2b and "
7567 "4a >= -4 + n and c >= 0 }";
7568 set = isl_set_read_from_str(ctx, str);
7569 pwaff = isl_set_dim_min(set, 2);
7570 set1 = isl_set_from_pw_aff(pwaff);
7571 str = "[n] -> { [(0)] : n >= 1 }";
7572 set2 = isl_set_read_from_str(ctx, str);
7573 equal = isl_set_is_equal(set1, set2);
7574 isl_set_free(set1);
7575 isl_set_free(set2);
7577 if (equal < 0)
7578 return -1;
7579 if (!equal)
7580 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7582 /* Check that empty solution lie in the right space. */
7583 str = "[n] -> { [t,a] : 1 = 0 }";
7584 set = isl_set_read_from_str(ctx, str);
7585 pwaff = isl_set_dim_max(set, 0);
7586 set1 = isl_set_from_pw_aff(pwaff);
7587 str = "[n] -> { [t] : 1 = 0 }";
7588 set2 = isl_set_read_from_str(ctx, str);
7589 equal = isl_set_is_equal(set1, set2);
7590 isl_set_free(set1);
7591 isl_set_free(set2);
7593 if (equal < 0)
7594 return -1;
7595 if (!equal)
7596 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7598 return 0;
7601 /* Basic test for isl_pw_multi_aff_product.
7603 * Check that multiple pieces are properly handled.
7605 static int test_product_pma(isl_ctx *ctx)
7607 isl_stat equal;
7608 const char *str;
7609 isl_pw_multi_aff *pma1, *pma2;
7611 str = "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
7612 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
7613 str = "{ C[] -> D[] }";
7614 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
7615 pma1 = isl_pw_multi_aff_product(pma1, pma2);
7616 str = "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
7617 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
7618 equal = pw_multi_aff_check_plain_equal(pma1, str);
7619 isl_pw_multi_aff_free(pma1);
7620 if (equal < 0)
7621 return -1;
7623 return 0;
7626 int test_product(isl_ctx *ctx)
7628 const char *str;
7629 isl_set *set;
7630 isl_union_set *uset1, *uset2;
7631 int ok;
7633 str = "{ A[i] }";
7634 set = isl_set_read_from_str(ctx, str);
7635 set = isl_set_product(set, isl_set_copy(set));
7636 ok = isl_set_is_wrapping(set);
7637 isl_set_free(set);
7638 if (ok < 0)
7639 return -1;
7640 if (!ok)
7641 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7643 str = "{ [] }";
7644 uset1 = isl_union_set_read_from_str(ctx, str);
7645 uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1));
7646 str = "{ [[] -> []] }";
7647 uset2 = isl_union_set_read_from_str(ctx, str);
7648 ok = isl_union_set_is_equal(uset1, uset2);
7649 isl_union_set_free(uset1);
7650 isl_union_set_free(uset2);
7651 if (ok < 0)
7652 return -1;
7653 if (!ok)
7654 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7656 if (test_product_pma(ctx) < 0)
7657 return -1;
7659 return 0;
7662 /* Check that two sets are not considered disjoint just because
7663 * they have a different set of (named) parameters.
7665 static int test_disjoint(isl_ctx *ctx)
7667 const char *str;
7668 isl_set *set, *set2;
7669 int disjoint;
7671 str = "[n] -> { [[]->[]] }";
7672 set = isl_set_read_from_str(ctx, str);
7673 str = "{ [[]->[]] }";
7674 set2 = isl_set_read_from_str(ctx, str);
7675 disjoint = isl_set_is_disjoint(set, set2);
7676 isl_set_free(set);
7677 isl_set_free(set2);
7678 if (disjoint < 0)
7679 return -1;
7680 if (disjoint)
7681 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7683 return 0;
7686 /* Inputs for isl_pw_multi_aff_is_equal tests.
7687 * "f1" and "f2" are the two function that need to be compared.
7688 * "equal" is the expected result.
7690 struct {
7691 int equal;
7692 const char *f1;
7693 const char *f2;
7694 } pma_equal_tests[] = {
7695 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
7696 "[N] -> { [0] : 0 <= N <= 1 }" },
7697 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7698 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
7699 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
7700 "[N] -> { [0] : 0 <= N <= 1 }" },
7701 { 0, "{ [NaN] }", "{ [NaN] }" },
7704 int test_equal(isl_ctx *ctx)
7706 int i;
7707 const char *str;
7708 isl_set *set, *set2;
7709 int equal;
7711 str = "{ S_6[i] }";
7712 set = isl_set_read_from_str(ctx, str);
7713 str = "{ S_7[i] }";
7714 set2 = isl_set_read_from_str(ctx, str);
7715 equal = isl_set_is_equal(set, set2);
7716 isl_set_free(set);
7717 isl_set_free(set2);
7718 if (equal < 0)
7719 return -1;
7720 if (equal)
7721 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7723 for (i = 0; i < ARRAY_SIZE(pma_equal_tests); ++i) {
7724 int expected = pma_equal_tests[i].equal;
7725 isl_pw_multi_aff *f1, *f2;
7727 f1 = isl_pw_multi_aff_read_from_str(ctx, pma_equal_tests[i].f1);
7728 f2 = isl_pw_multi_aff_read_from_str(ctx, pma_equal_tests[i].f2);
7729 equal = isl_pw_multi_aff_is_equal(f1, f2);
7730 isl_pw_multi_aff_free(f1);
7731 isl_pw_multi_aff_free(f2);
7732 if (equal < 0)
7733 return -1;
7734 if (equal != expected)
7735 isl_die(ctx, isl_error_unknown,
7736 "unexpected equality result", return -1);
7739 return 0;
7742 static int test_plain_fixed(isl_ctx *ctx, __isl_take isl_map *map,
7743 enum isl_dim_type type, unsigned pos, int fixed)
7745 isl_bool test;
7747 test = isl_map_plain_is_fixed(map, type, pos, NULL);
7748 isl_map_free(map);
7749 if (test < 0)
7750 return -1;
7751 if (test == fixed)
7752 return 0;
7753 if (fixed)
7754 isl_die(ctx, isl_error_unknown,
7755 "map not detected as fixed", return -1);
7756 else
7757 isl_die(ctx, isl_error_unknown,
7758 "map detected as fixed", return -1);
7761 int test_fixed(isl_ctx *ctx)
7763 const char *str;
7764 isl_map *map;
7766 str = "{ [i] -> [i] }";
7767 map = isl_map_read_from_str(ctx, str);
7768 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 0))
7769 return -1;
7770 str = "{ [i] -> [1] }";
7771 map = isl_map_read_from_str(ctx, str);
7772 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
7773 return -1;
7774 str = "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
7775 map = isl_map_read_from_str(ctx, str);
7776 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
7777 return -1;
7778 map = isl_map_read_from_str(ctx, str);
7779 map = isl_map_neg(map);
7780 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
7781 return -1;
7783 return 0;
7786 struct isl_vertices_test_data {
7787 const char *set;
7788 int n;
7789 const char *vertex[6];
7790 } vertices_tests[] = {
7791 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
7792 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
7793 { "{ A[t, i] : t = 14 and i = 1 }",
7794 1, { "{ A[14, 1] }" } },
7795 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
7796 "c <= m and m <= n and m > 0 }",
7797 6, {
7798 "[n, m] -> { [n, m, m] : 0 < m <= n }",
7799 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
7800 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
7801 "[n, m] -> { [m, m, m] : 0 < m <= n }",
7802 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
7803 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
7804 } },
7807 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
7809 static isl_stat find_vertex(__isl_take isl_vertex *vertex, void *user)
7811 struct isl_vertices_test_data *data = user;
7812 isl_ctx *ctx;
7813 isl_multi_aff *ma;
7814 isl_basic_set *bset;
7815 isl_pw_multi_aff *pma;
7816 int i;
7817 isl_bool equal;
7819 ctx = isl_vertex_get_ctx(vertex);
7820 bset = isl_vertex_get_domain(vertex);
7821 ma = isl_vertex_get_expr(vertex);
7822 pma = isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset), ma);
7824 for (i = 0; i < data->n; ++i) {
7825 isl_pw_multi_aff *pma_i;
7827 pma_i = isl_pw_multi_aff_read_from_str(ctx, data->vertex[i]);
7828 equal = isl_pw_multi_aff_plain_is_equal(pma, pma_i);
7829 isl_pw_multi_aff_free(pma_i);
7831 if (equal < 0 || equal)
7832 break;
7835 isl_pw_multi_aff_free(pma);
7836 isl_vertex_free(vertex);
7838 if (equal < 0)
7839 return isl_stat_error;
7841 return equal ? isl_stat_ok : isl_stat_error;
7844 int test_vertices(isl_ctx *ctx)
7846 int i;
7848 for (i = 0; i < ARRAY_SIZE(vertices_tests); ++i) {
7849 isl_basic_set *bset;
7850 isl_vertices *vertices;
7851 int ok = 1;
7852 isl_size n;
7854 bset = isl_basic_set_read_from_str(ctx, vertices_tests[i].set);
7855 vertices = isl_basic_set_compute_vertices(bset);
7856 n = isl_vertices_get_n_vertices(vertices);
7857 if (vertices_tests[i].n != n)
7858 ok = 0;
7859 if (isl_vertices_foreach_vertex(vertices, &find_vertex,
7860 &vertices_tests[i]) < 0)
7861 ok = 0;
7862 isl_vertices_free(vertices);
7863 isl_basic_set_free(bset);
7865 if (n < 0)
7866 return -1;
7867 if (!ok)
7868 isl_die(ctx, isl_error_unknown, "unexpected vertices",
7869 return -1);
7872 return 0;
7875 /* Inputs for basic tests of unary operations on isl_union_map.
7876 * "fn" is the function that is being tested.
7877 * "arg" is a string description of the input.
7878 * "res" is a string description of the expected result.
7880 static struct {
7881 __isl_give isl_union_map *(*fn)(__isl_take isl_union_map *umap);
7882 const char *arg;
7883 const char *res;
7884 } umap_un_tests[] = {
7885 { &isl_union_map_range_reverse,
7886 "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }",
7887 "{ A[] -> [C[] -> B[]]; A[0] -> N[B[2] -> B[1]] }" },
7888 { &isl_union_map_range_reverse,
7889 "{ A[] -> N[B[] -> C[]] }",
7890 "{ A[] -> [C[] -> B[]] }" },
7891 { &isl_union_map_range_reverse,
7892 "{ A[] -> N[B[x] -> B[y]] }",
7893 "{ A[] -> N[B[*] -> B[*]] }" },
7896 /* Perform basic tests of unary operations on isl_union_map.
7898 static isl_stat test_un_union_map(isl_ctx *ctx)
7900 int i;
7902 for (i = 0; i < ARRAY_SIZE(umap_un_tests); ++i) {
7903 const char *str;
7904 isl_union_map *umap, *res;
7905 isl_bool equal;
7907 str = umap_un_tests[i].arg;
7908 umap = isl_union_map_read_from_str(ctx, str);
7909 str = umap_un_tests[i].res;
7910 res = isl_union_map_read_from_str(ctx, str);
7911 umap = umap_un_tests[i].fn(umap);
7912 equal = isl_union_map_is_equal(umap, res);
7913 isl_union_map_free(umap);
7914 isl_union_map_free(res);
7915 if (equal < 0)
7916 return isl_stat_error;
7917 if (!equal)
7918 isl_die(ctx, isl_error_unknown,
7919 "unexpected result", return isl_stat_error);
7922 return isl_stat_ok;
7925 /* Inputs for basic tests of binary operations on isl_union_map.
7926 * "fn" is the function that is being tested.
7927 * "arg1" and "arg2" are string descriptions of the inputs.
7928 * "res" is a string description of the expected result.
7930 static struct {
7931 __isl_give isl_union_map *(*fn)(__isl_take isl_union_map *umap1,
7932 __isl_take isl_union_map *umap2);
7933 const char *arg1;
7934 const char *arg2;
7935 const char *res;
7936 } umap_bin_tests[] = {
7937 { &isl_union_map_intersect,
7938 "[n] -> { A[i] -> [] : 0 <= i <= n; B[] -> [] }",
7939 "[m] -> { A[i] -> [] : 0 <= i <= m; C[] -> [] }",
7940 "[m, n] -> { A[i] -> [] : 0 <= i <= n and i <= m }" },
7941 { &isl_union_map_intersect_domain_factor_domain,
7942 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7943 "[N] -> { B[i] -> C[N] }",
7944 "{ }" },
7945 { &isl_union_map_intersect_domain_factor_domain,
7946 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7947 "[N] -> { A[i] -> C[N] }",
7948 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
7949 { &isl_union_map_intersect_domain_factor_domain,
7950 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
7951 "[N] -> { A[i] -> C[N] }",
7952 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
7953 { &isl_union_map_intersect_domain_factor_range,
7954 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7955 "[N] -> { B[i] -> C[N] }",
7956 "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" },
7957 { &isl_union_map_intersect_domain_factor_range,
7958 "{ T[A[i] -> B[i + 1]] -> C[i + 2] }",
7959 "[N] -> { B[i] -> C[N] }",
7960 "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" },
7961 { &isl_union_map_intersect_domain_factor_range,
7962 "{ [A[i] -> B[i + 1]] -> C[i + 2] }",
7963 "[N] -> { A[i] -> C[N] }",
7964 "{ }" },
7965 { &isl_union_map_intersect_range_factor_domain,
7966 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7967 "[N] -> { A[i] -> B[N] }",
7968 "[N] -> { A[N - 1] -> [B[N] -> C[N + 1]] }" },
7969 { &isl_union_map_intersect_range_factor_domain,
7970 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
7971 "[N] -> { A[i] -> B[N] }",
7972 "[N] -> { A[N - 1] -> T[B[N] -> C[N + 1]] }" },
7973 { &isl_union_map_intersect_range_factor_domain,
7974 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7975 "[N] -> { A[i] -> C[N] }",
7976 "{ }" },
7977 { &isl_union_map_intersect_range_factor_range,
7978 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7979 "[N] -> { A[i] -> C[N] }",
7980 "[N] -> { A[N - 2] -> [B[N - 1] -> C[N]] }" },
7981 { &isl_union_map_intersect_range_factor_range,
7982 "{ A[i] -> T[B[i + 1] -> C[i + 2]] }",
7983 "[N] -> { A[i] -> C[N] }",
7984 "[N] -> { A[N - 2] -> T[B[N - 1] -> C[N]] }" },
7985 { &isl_union_map_intersect_range_factor_range,
7986 "{ A[i] -> [B[i + 1] -> C[i + 2]] }",
7987 "[N] -> { A[i] -> B[N] }",
7988 "{ }" },
7991 /* Perform basic tests of binary operations on isl_union_map.
7993 static isl_stat test_bin_union_map(isl_ctx *ctx)
7995 int i;
7997 for (i = 0; i < ARRAY_SIZE(umap_bin_tests); ++i) {
7998 const char *str;
7999 isl_union_map *umap1, *umap2, *res;
8000 isl_bool equal;
8002 str = umap_bin_tests[i].arg1;
8003 umap1 = isl_union_map_read_from_str(ctx, str);
8004 str = umap_bin_tests[i].arg2;
8005 umap2 = isl_union_map_read_from_str(ctx, str);
8006 str = umap_bin_tests[i].res;
8007 res = isl_union_map_read_from_str(ctx, str);
8008 umap1 = umap_bin_tests[i].fn(umap1, umap2);
8009 equal = isl_union_map_is_equal(umap1, res);
8010 isl_union_map_free(umap1);
8011 isl_union_map_free(res);
8012 if (equal < 0)
8013 return isl_stat_error;
8014 if (!equal)
8015 isl_die(ctx, isl_error_unknown,
8016 "unexpected result", return isl_stat_error);
8019 return isl_stat_ok;
8022 /* Check that isl_union_set_contains finds space independently
8023 * of the parameters.
8025 static isl_stat test_union_set_contains(isl_ctx *ctx)
8027 const char *str;
8028 isl_bool ok;
8029 isl_space *space;
8030 isl_id *id;
8031 isl_union_set *uset;
8033 str = "[N] -> { A[0:N]; B[*,*] }";
8034 uset = isl_union_set_read_from_str(ctx, str);
8035 space = isl_space_unit(ctx);
8036 id = isl_id_alloc(ctx, "A", NULL);
8037 space = isl_space_add_named_tuple_id_ui(space, id, 1);
8038 ok = isl_union_set_contains(uset, space);
8039 isl_space_free(space);
8040 isl_union_set_free(uset);
8042 if (ok < 0)
8043 return isl_stat_error;
8044 if (!ok)
8045 isl_die(ctx, isl_error_unknown,
8046 "unexpected result", return isl_stat_error);
8048 return isl_stat_ok;
8051 /* Perform basic tests of operations on isl_union_map or isl_union_set.
8053 static int test_union_map(isl_ctx *ctx)
8055 if (test_un_union_map(ctx) < 0)
8056 return -1;
8057 if (test_bin_union_map(ctx) < 0)
8058 return -1;
8059 if (test_union_set_contains(ctx) < 0)
8060 return -1;
8061 return 0;
8064 int test_union_pw(isl_ctx *ctx)
8066 int equal;
8067 const char *str;
8068 isl_union_set *uset;
8069 isl_union_pw_qpolynomial *upwqp1, *upwqp2;
8071 str = "{ [x] -> x^2 }";
8072 upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str);
8073 upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1);
8074 uset = isl_union_pw_qpolynomial_domain(upwqp1);
8075 upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2);
8076 upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset);
8077 equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2);
8078 isl_union_pw_qpolynomial_free(upwqp1);
8079 isl_union_pw_qpolynomial_free(upwqp2);
8080 if (equal < 0)
8081 return -1;
8082 if (!equal)
8083 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
8085 return 0;
8088 /* Inputs for basic tests of functions that select
8089 * subparts of the domain of an isl_multi_union_pw_aff.
8090 * "fn" is the function that is tested.
8091 * "arg" is a string description of the input.
8092 * "res" is a string description of the expected result.
8094 struct {
8095 __isl_give isl_union_set *(*fn)(
8096 __isl_take isl_multi_union_pw_aff *mupa);
8097 const char *arg;
8098 const char *res;
8099 } un_locus_tests[] = {
8100 { &isl_multi_union_pw_aff_zero_union_set,
8101 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8102 "{ A[0,j]; B[0,j] }" },
8103 { &isl_multi_union_pw_aff_zero_union_set,
8104 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
8105 "{ A[i,i]; B[i,i] : i >= 0 }" },
8106 { &isl_multi_union_pw_aff_zero_union_set,
8107 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
8108 "{ A[i,j]; B[i,i] : i >= 0 }" },
8111 /* Perform some basic tests of functions that select
8112 * subparts of the domain of an isl_multi_union_pw_aff.
8114 static int test_un_locus(isl_ctx *ctx)
8116 int i;
8117 isl_bool ok;
8118 isl_union_set *uset, *res;
8119 isl_multi_union_pw_aff *mupa;
8121 for (i = 0; i < ARRAY_SIZE(un_locus_tests); ++i) {
8122 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
8123 un_locus_tests[i].arg);
8124 res = isl_union_set_read_from_str(ctx, un_locus_tests[i].res);
8125 uset = un_locus_tests[i].fn(mupa);
8126 ok = isl_union_set_is_equal(uset, res);
8127 isl_union_set_free(uset);
8128 isl_union_set_free(res);
8129 if (ok < 0)
8130 return -1;
8131 if (!ok)
8132 isl_die(ctx, isl_error_unknown,
8133 "unexpected result", return -1);
8136 return 0;
8139 /* Inputs for basic tests of functions that select
8140 * subparts of an isl_union_map based on a relation
8141 * specified by an isl_multi_union_pw_aff.
8142 * "fn" is the function that is tested.
8143 * "arg1" and "arg2" are string descriptions of the inputs.
8144 * "res" is a string description of the expected result.
8146 struct {
8147 __isl_give isl_union_map *(*fn)(
8148 __isl_take isl_union_map *umap,
8149 __isl_take isl_multi_union_pw_aff *mupa);
8150 const char *arg1;
8151 const char *arg2;
8152 const char *res;
8153 } bin_locus_tests[] = {
8154 { &isl_union_map_eq_at_multi_union_pw_aff,
8155 "{ A[i,j] -> B[i',j'] }",
8156 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8157 "{ A[i,j] -> B[i,j'] }" },
8158 { &isl_union_map_eq_at_multi_union_pw_aff,
8159 "{ A[i,j] -> B[i',j'] }",
8160 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8161 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8162 "{ A[i,j] -> B[i,j] }" },
8163 { &isl_union_map_eq_at_multi_union_pw_aff,
8164 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8165 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
8166 "{ A[i,j] -> B[i,j'] }" },
8167 { &isl_union_map_eq_at_multi_union_pw_aff,
8168 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8169 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
8170 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
8171 { &isl_union_map_eq_at_multi_union_pw_aff,
8172 "{ A[i,j] -> B[i',j'] }",
8173 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
8174 "{ A[i,j] -> B[i,j'] : i > j }" },
8175 { &isl_union_map_lex_lt_at_multi_union_pw_aff,
8176 "{ A[i,j] -> B[i',j'] }",
8177 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8178 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8179 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
8180 { &isl_union_map_lex_gt_at_multi_union_pw_aff,
8181 "{ A[i,j] -> B[i',j'] }",
8182 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
8183 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
8184 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
8185 { &isl_union_map_eq_at_multi_union_pw_aff,
8186 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
8187 "(F[] : { A[i,j]; B[i,j] })",
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 > j; B[i,j] : i < j })",
8192 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
8193 { &isl_union_map_eq_at_multi_union_pw_aff,
8194 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
8195 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
8196 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
8197 { &isl_union_map_eq_at_multi_union_pw_aff,
8198 "{ A[i,j] -> B[i',j'] }",
8199 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
8200 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
8201 { &isl_union_map_eq_at_multi_union_pw_aff,
8202 "{ A[i,j] -> B[i',j'] }",
8203 "[N] -> (F[] : { : N >= 0 })",
8204 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
8207 /* Perform some basic tests of functions that select
8208 * subparts of an isl_union_map based on a relation
8209 * specified by an isl_multi_union_pw_aff.
8211 static int test_bin_locus(isl_ctx *ctx)
8213 int i;
8214 isl_bool ok;
8215 isl_union_map *umap, *res;
8216 isl_multi_union_pw_aff *mupa;
8218 for (i = 0; i < ARRAY_SIZE(bin_locus_tests); ++i) {
8219 umap = isl_union_map_read_from_str(ctx,
8220 bin_locus_tests[i].arg1);
8221 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
8222 bin_locus_tests[i].arg2);
8223 res = isl_union_map_read_from_str(ctx, bin_locus_tests[i].res);
8224 umap = bin_locus_tests[i].fn(umap, mupa);
8225 ok = isl_union_map_is_equal(umap, res);
8226 isl_union_map_free(umap);
8227 isl_union_map_free(res);
8228 if (ok < 0)
8229 return -1;
8230 if (!ok)
8231 isl_die(ctx, isl_error_unknown,
8232 "unexpected result", return -1);
8235 return 0;
8238 /* Inputs for basic tests of functions that determine
8239 * the part of the domain where two isl_multi_aff objects
8240 * related to each other in a specific way.
8241 * "fn" is the function that is being tested.
8242 * "arg1" and "arg2" are string descriptions of the inputs.
8243 * "res" is a string description of the expected result.
8245 static struct {
8246 __isl_give isl_set *(*fn)(__isl_take isl_multi_aff *ma1,
8247 __isl_take isl_multi_aff *ma2);
8248 const char *arg1;
8249 const char *arg2;
8250 const char *res;
8251 } bin_locus_ma_tests[] = {
8252 { &isl_multi_aff_lex_le_set, "{ [] }", "{ [] }", "{ : }" },
8253 { &isl_multi_aff_lex_lt_set, "{ [] }", "{ [] }", "{ : false }" },
8254 { &isl_multi_aff_lex_le_set,
8255 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8256 "{ A[i] : i <= 0 }" },
8257 { &isl_multi_aff_lex_lt_set,
8258 "{ A[i] -> [i] }", "{ A[i] -> [0] }",
8259 "{ A[i] : i < 0 }" },
8260 { &isl_multi_aff_lex_le_set,
8261 "{ A[i] -> [i, i] }", "{ A[i] -> [0, 0] }",
8262 "{ A[i] : i <= 0 }" },
8263 { &isl_multi_aff_lex_le_set,
8264 "{ A[i] -> [i, 0] }", "{ A[i] -> [0, 0] }",
8265 "{ A[i] : i <= 0 }" },
8266 { &isl_multi_aff_lex_le_set,
8267 "{ A[i] -> [i, 1] }", "{ A[i] -> [0, 0] }",
8268 "{ A[i] : i < 0 }" },
8271 /* Perform some basic tests of functions that determine
8272 * the part of the domain where two isl_multi_aff objects
8273 * related to each other in a specific way.
8275 static isl_stat test_bin_locus_ma(isl_ctx *ctx)
8277 int i;
8279 for (i = 0; i < ARRAY_SIZE(bin_locus_ma_tests); ++i) {
8280 const char *str;
8281 isl_bool ok;
8282 isl_multi_aff *ma1, *ma2;
8283 isl_set *set, *res;
8285 str = bin_locus_ma_tests[i].arg1;
8286 ma1 = isl_multi_aff_read_from_str(ctx, str);
8287 str = bin_locus_ma_tests[i].arg2;
8288 ma2 = isl_multi_aff_read_from_str(ctx, str);
8289 res = isl_set_read_from_str(ctx, bin_locus_ma_tests[i].res);
8290 set = bin_locus_ma_tests[i].fn(ma1, ma2);
8291 ok = isl_set_is_equal(set, res);
8292 isl_set_free(set);
8293 isl_set_free(res);
8294 if (ok < 0)
8295 return isl_stat_error;
8296 if (!ok)
8297 isl_die(ctx, isl_error_unknown,
8298 "unexpected result", return isl_stat_error);
8301 return isl_stat_ok;
8304 /* Perform basic locus tests.
8306 static int test_locus(isl_ctx *ctx)
8308 if (test_un_locus(ctx) < 0)
8309 return -1;
8310 if (test_bin_locus(ctx) < 0)
8311 return -1;
8312 if (test_bin_locus_ma(ctx) < 0)
8313 return -1;
8314 return 0;
8317 /* Test that isl_union_pw_qpolynomial_eval picks up the function
8318 * defined over the correct domain space.
8320 static int test_eval_1(isl_ctx *ctx)
8322 const char *str;
8323 isl_point *pnt;
8324 isl_set *set;
8325 isl_union_pw_qpolynomial *upwqp;
8326 isl_val *v;
8327 int cmp;
8329 str = "{ A[x] -> x^2; B[x] -> -x^2 }";
8330 upwqp = isl_union_pw_qpolynomial_read_from_str(ctx, str);
8331 str = "{ A[6] }";
8332 set = isl_set_read_from_str(ctx, str);
8333 pnt = isl_set_sample_point(set);
8334 v = isl_union_pw_qpolynomial_eval(upwqp, pnt);
8335 cmp = isl_val_cmp_si(v, 36);
8336 isl_val_free(v);
8338 if (!v)
8339 return -1;
8340 if (cmp != 0)
8341 isl_die(ctx, isl_error_unknown, "unexpected value", return -1);
8343 return 0;
8346 /* Check that isl_qpolynomial_eval handles getting called on a void point.
8348 static int test_eval_2(isl_ctx *ctx)
8350 const char *str;
8351 isl_point *pnt;
8352 isl_set *set;
8353 isl_qpolynomial *qp;
8354 isl_val *v;
8355 isl_bool ok;
8357 str = "{ A[x] -> [x] }";
8358 qp = isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx, str));
8359 str = "{ A[x] : false }";
8360 set = isl_set_read_from_str(ctx, str);
8361 pnt = isl_set_sample_point(set);
8362 v = isl_qpolynomial_eval(qp, pnt);
8363 ok = isl_val_is_nan(v);
8364 isl_val_free(v);
8366 if (ok < 0)
8367 return -1;
8368 if (!ok)
8369 isl_die(ctx, isl_error_unknown, "expecting NaN", return -1);
8371 return 0;
8374 /* Check that a polynomial (without local variables) can be evaluated
8375 * in a rational point.
8377 static isl_stat test_eval_3(isl_ctx *ctx)
8379 isl_pw_qpolynomial *pwqp;
8380 isl_point *pnt;
8381 isl_val *v;
8382 isl_stat r;
8384 pwqp = isl_pw_qpolynomial_read_from_str(ctx, "{ [x] -> x^2 }");
8385 pnt = isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp));
8386 v = isl_val_read_from_str(ctx, "1/2");
8387 pnt = isl_point_set_coordinate_val(pnt, isl_dim_set, 0, v);
8388 v = isl_pw_qpolynomial_eval(pwqp, pnt);
8389 r = val_check_equal(v, "1/4");
8390 isl_val_free(v);
8392 return r;
8395 /* Inputs for isl_pw_aff_eval test.
8396 * "f" is the affine function.
8397 * "p" is the point where the function should be evaluated.
8398 * "res" is the expected result.
8400 struct {
8401 const char *f;
8402 const char *p;
8403 const char *res;
8404 } aff_eval_tests[] = {
8405 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
8406 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
8407 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
8408 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
8409 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
8410 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
8411 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
8412 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
8413 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
8414 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
8415 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
8416 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
8417 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
8418 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
8419 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
8420 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
8421 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
8422 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
8423 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
8424 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
8425 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
8426 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
8427 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
8430 /* Perform basic isl_pw_aff_eval tests.
8432 static int test_eval_aff(isl_ctx *ctx)
8434 int i;
8436 for (i = 0; i < ARRAY_SIZE(aff_eval_tests); ++i) {
8437 isl_stat r;
8438 isl_pw_aff *pa;
8439 isl_set *set;
8440 isl_point *pnt;
8441 isl_val *v;
8443 pa = isl_pw_aff_read_from_str(ctx, aff_eval_tests[i].f);
8444 set = isl_set_read_from_str(ctx, aff_eval_tests[i].p);
8445 pnt = isl_set_sample_point(set);
8446 v = isl_pw_aff_eval(pa, pnt);
8447 r = val_check_equal(v, aff_eval_tests[i].res);
8448 isl_val_free(v);
8449 if (r < 0)
8450 return -1;
8452 return 0;
8455 /* Perform basic evaluation tests.
8457 static int test_eval(isl_ctx *ctx)
8459 if (test_eval_1(ctx) < 0)
8460 return -1;
8461 if (test_eval_2(ctx) < 0)
8462 return -1;
8463 if (test_eval_3(ctx) < 0)
8464 return -1;
8465 if (test_eval_aff(ctx) < 0)
8466 return -1;
8467 return 0;
8470 /* Descriptions of sets that are tested for reparsing after printing.
8472 const char *output_tests[] = {
8473 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
8474 "{ [x] : 1 = 0 }",
8475 "{ [x] : false }",
8476 "{ [x] : x mod 2 = 0 }",
8477 "{ [x] : x mod 2 = 1 }",
8478 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
8479 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
8480 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8481 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
8482 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
8483 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
8486 /* Check that printing a set and reparsing a set from the printed output
8487 * results in the same set.
8489 static int test_output_set(isl_ctx *ctx)
8491 int i;
8492 char *str;
8493 isl_set *set1, *set2;
8494 isl_bool equal;
8496 for (i = 0; i < ARRAY_SIZE(output_tests); ++i) {
8497 set1 = isl_set_read_from_str(ctx, output_tests[i]);
8498 str = isl_set_to_str(set1);
8499 set2 = isl_set_read_from_str(ctx, str);
8500 free(str);
8501 equal = isl_set_is_equal(set1, set2);
8502 isl_set_free(set1);
8503 isl_set_free(set2);
8504 if (equal < 0)
8505 return -1;
8506 if (!equal)
8507 isl_die(ctx, isl_error_unknown,
8508 "parsed output not the same", return -1);
8511 return 0;
8514 /* Check that an isl_multi_aff is printed using a consistent space.
8516 static isl_stat test_output_ma(isl_ctx *ctx)
8518 char *str;
8519 isl_bool equal;
8520 isl_aff *aff;
8521 isl_multi_aff *ma, *ma2;
8523 ma = isl_multi_aff_read_from_str(ctx, "{ [a, b] -> [a + b] }");
8524 aff = isl_aff_read_from_str(ctx, "{ [c, d] -> [c + d] }");
8525 ma = isl_multi_aff_set_aff(ma, 0, aff);
8526 str = isl_multi_aff_to_str(ma);
8527 ma2 = isl_multi_aff_read_from_str(ctx, str);
8528 free(str);
8529 equal = isl_multi_aff_plain_is_equal(ma, ma2);
8530 isl_multi_aff_free(ma2);
8531 isl_multi_aff_free(ma);
8533 if (equal < 0)
8534 return isl_stat_error;
8535 if (!equal)
8536 isl_die(ctx, isl_error_unknown, "bad conversion",
8537 return isl_stat_error);
8539 return isl_stat_ok;
8542 /* Check that an isl_multi_pw_aff is printed using a consistent space.
8544 static isl_stat test_output_mpa(isl_ctx *ctx)
8546 char *str;
8547 isl_bool equal;
8548 isl_pw_aff *pa;
8549 isl_multi_pw_aff *mpa, *mpa2;
8551 mpa = isl_multi_pw_aff_read_from_str(ctx, "{ [a, b] -> [a + b] }");
8552 pa = isl_pw_aff_read_from_str(ctx, "{ [c, d] -> [c + d] }");
8553 mpa = isl_multi_pw_aff_set_pw_aff(mpa, 0, pa);
8554 str = isl_multi_pw_aff_to_str(mpa);
8555 mpa2 = isl_multi_pw_aff_read_from_str(ctx, str);
8556 free(str);
8557 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2);
8558 isl_multi_pw_aff_free(mpa2);
8559 isl_multi_pw_aff_free(mpa);
8561 if (equal < 0)
8562 return isl_stat_error;
8563 if (!equal)
8564 isl_die(ctx, isl_error_unknown, "bad conversion",
8565 return isl_stat_error);
8567 return isl_stat_ok;
8570 int test_output(isl_ctx *ctx)
8572 char *s;
8573 const char *str;
8574 isl_pw_aff *pa;
8575 isl_printer *p;
8576 int equal;
8578 if (test_output_set(ctx) < 0)
8579 return -1;
8580 if (test_output_ma(ctx) < 0)
8581 return -1;
8582 if (test_output_mpa(ctx) < 0)
8583 return -1;
8585 str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
8586 pa = isl_pw_aff_read_from_str(ctx, str);
8588 p = isl_printer_to_str(ctx);
8589 p = isl_printer_set_output_format(p, ISL_FORMAT_C);
8590 p = isl_printer_print_pw_aff(p, pa);
8591 s = isl_printer_get_str(p);
8592 isl_printer_free(p);
8593 isl_pw_aff_free(pa);
8594 if (!s)
8595 equal = -1;
8596 else
8597 equal = !strcmp(s, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
8598 free(s);
8599 if (equal < 0)
8600 return -1;
8601 if (!equal)
8602 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
8604 return 0;
8607 int test_sample(isl_ctx *ctx)
8609 const char *str;
8610 isl_basic_set *bset1, *bset2;
8611 int empty, subset;
8613 str = "{ [a, b, c, d, e, f, g, h, i, j, k] : "
8614 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
8615 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
8616 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
8617 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
8618 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
8619 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
8620 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
8621 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
8622 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
8623 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
8624 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
8625 "d - 1073741821e and "
8626 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
8627 "3j >= 1 - a + b + 2e and "
8628 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
8629 "3i <= 4 - a + 4b - e and "
8630 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
8631 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
8632 "c <= -1 + a and 3i >= -2 - a + 3e and "
8633 "1073741822e <= 1073741823 - a + 1073741822b + c and "
8634 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
8635 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
8636 "1073741823e >= 1 + 1073741823b - d and "
8637 "3i >= 1073741823b + c - 1073741823e - f and "
8638 "3i >= 1 + 2b + e + 3g }";
8639 bset1 = isl_basic_set_read_from_str(ctx, str);
8640 bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1));
8641 empty = isl_basic_set_is_empty(bset2);
8642 subset = isl_basic_set_is_subset(bset2, bset1);
8643 isl_basic_set_free(bset1);
8644 isl_basic_set_free(bset2);
8645 if (empty < 0 || subset < 0)
8646 return -1;
8647 if (empty)
8648 isl_die(ctx, isl_error_unknown, "point not found", return -1);
8649 if (!subset)
8650 isl_die(ctx, isl_error_unknown, "bad point found", return -1);
8652 return 0;
8655 int test_fixed_power(isl_ctx *ctx)
8657 const char *str;
8658 isl_map *map;
8659 isl_val *exp;
8660 int equal;
8662 str = "{ [i] -> [i + 1] }";
8663 map = isl_map_read_from_str(ctx, str);
8664 exp = isl_val_int_from_si(ctx, 23);
8665 map = isl_map_fixed_power_val(map, exp);
8666 equal = map_check_equal(map, "{ [i] -> [i + 23] }");
8667 isl_map_free(map);
8668 if (equal < 0)
8669 return -1;
8671 return 0;
8674 int test_slice(isl_ctx *ctx)
8676 const char *str;
8677 isl_map *map;
8678 int equal;
8680 str = "{ [i] -> [j] }";
8681 map = isl_map_read_from_str(ctx, str);
8682 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_out, 0);
8683 equal = map_check_equal(map, "{ [i] -> [i] }");
8684 isl_map_free(map);
8685 if (equal < 0)
8686 return -1;
8688 str = "{ [i] -> [j] }";
8689 map = isl_map_read_from_str(ctx, str);
8690 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_in, 0);
8691 equal = map_check_equal(map, "{ [i] -> [j] }");
8692 isl_map_free(map);
8693 if (equal < 0)
8694 return -1;
8696 str = "{ [i] -> [j] }";
8697 map = isl_map_read_from_str(ctx, str);
8698 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_out, 0);
8699 equal = map_check_equal(map, "{ [i] -> [-i] }");
8700 isl_map_free(map);
8701 if (equal < 0)
8702 return -1;
8704 str = "{ [i] -> [j] }";
8705 map = isl_map_read_from_str(ctx, str);
8706 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_in, 0);
8707 equal = map_check_equal(map, "{ [0] -> [j] }");
8708 isl_map_free(map);
8709 if (equal < 0)
8710 return -1;
8712 str = "{ [i] -> [j] }";
8713 map = isl_map_read_from_str(ctx, str);
8714 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_out, 0);
8715 equal = map_check_equal(map, "{ [i] -> [j] : i > j }");
8716 isl_map_free(map);
8717 if (equal < 0)
8718 return -1;
8720 str = "{ [i] -> [j] }";
8721 map = isl_map_read_from_str(ctx, str);
8722 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_in, 0);
8723 equal = map_check_equal(map, "{ [i] -> [j] : false }");
8724 isl_map_free(map);
8725 if (equal < 0)
8726 return -1;
8728 return 0;
8731 int test_eliminate(isl_ctx *ctx)
8733 const char *str;
8734 isl_map *map;
8735 int equal;
8737 str = "{ [i] -> [j] : i = 2j }";
8738 map = isl_map_read_from_str(ctx, str);
8739 map = isl_map_eliminate(map, isl_dim_out, 0, 1);
8740 equal = map_check_equal(map, "{ [i] -> [j] : exists a : i = 2a }");
8741 isl_map_free(map);
8742 if (equal < 0)
8743 return -1;
8745 return 0;
8748 /* Check basic functionality of isl_map_deltas_map.
8750 static int test_deltas_map(isl_ctx *ctx)
8752 const char *str;
8753 isl_map *map;
8754 int equal;
8756 str = "{ A[i] -> A[i + 1] }";
8757 map = isl_map_read_from_str(ctx, str);
8758 map = isl_map_deltas_map(map);
8759 equal = map_check_equal(map, "{ [A[i] -> A[i + 1]] -> A[1] }");
8760 isl_map_free(map);
8761 if (equal < 0)
8762 return -1;
8764 return 0;
8767 /* Check that isl_set_dim_residue_class detects that the values of j
8768 * in the set below are all odd and that it does not detect any spurious
8769 * strides.
8771 static int test_residue_class(isl_ctx *ctx)
8773 const char *str;
8774 isl_set *set;
8775 isl_int m, r;
8776 isl_stat res;
8778 str = "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
8779 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
8780 set = isl_set_read_from_str(ctx, str);
8781 isl_int_init(m);
8782 isl_int_init(r);
8783 res = isl_set_dim_residue_class(set, 1, &m, &r);
8784 if (res >= 0 &&
8785 (isl_int_cmp_si(m, 2) != 0 || isl_int_cmp_si(r, 1) != 0))
8786 isl_die(ctx, isl_error_unknown, "incorrect residue class",
8787 res = isl_stat_error);
8788 isl_int_clear(r);
8789 isl_int_clear(m);
8790 isl_set_free(set);
8792 return res;
8795 static int test_align_parameters_1(isl_ctx *ctx)
8797 const char *str;
8798 isl_space *space;
8799 isl_multi_aff *ma1, *ma2;
8800 int equal;
8802 str = "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
8803 ma1 = isl_multi_aff_read_from_str(ctx, str);
8805 space = isl_space_params_alloc(ctx, 1);
8806 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
8807 ma1 = isl_multi_aff_align_params(ma1, space);
8809 str = "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
8810 ma2 = isl_multi_aff_read_from_str(ctx, str);
8812 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
8814 isl_multi_aff_free(ma1);
8815 isl_multi_aff_free(ma2);
8817 if (equal < 0)
8818 return -1;
8819 if (!equal)
8820 isl_die(ctx, isl_error_unknown,
8821 "result not as expected", return -1);
8823 return 0;
8826 /* Check the isl_multi_*_from_*_list operation in case inputs
8827 * have unaligned parameters.
8828 * In particular, older versions of isl would simply fail
8829 * (without printing any error message).
8831 static isl_stat test_align_parameters_2(isl_ctx *ctx)
8833 isl_space *space;
8834 isl_map *map;
8835 isl_aff *aff;
8836 isl_multi_aff *ma;
8838 map = isl_map_read_from_str(ctx, "{ A[] -> M[x] }");
8839 space = isl_map_get_space(map);
8840 isl_map_free(map);
8842 aff = isl_aff_read_from_str(ctx, "[N] -> { A[] -> [N] }");
8843 ma = isl_multi_aff_from_aff_list(space, isl_aff_list_from_aff(aff));
8844 isl_multi_aff_free(ma);
8846 if (!ma)
8847 return isl_stat_error;
8848 return isl_stat_ok;
8851 /* Perform basic parameter alignment tests.
8853 static int test_align_parameters(isl_ctx *ctx)
8855 if (test_align_parameters_1(ctx) < 0)
8856 return -1;
8857 if (test_align_parameters_2(ctx) < 0)
8858 return -1;
8860 return 0;
8863 /* Check that isl_*_drop_unused_params actually drops the unused parameters
8864 * by comparing the result using isl_*_plain_is_equal.
8865 * Note that this assumes that isl_*_plain_is_equal does not consider
8866 * objects that only differ by unused parameters to be equal.
8868 int test_drop_unused_parameters(isl_ctx *ctx)
8870 const char *str_with, *str_without;
8871 isl_basic_set *bset1, *bset2;
8872 isl_set *set1, *set2;
8873 isl_pw_aff *pwa1, *pwa2;
8874 int equal;
8876 str_with = "[n, m, o] -> { [m] }";
8877 str_without = "[m] -> { [m] }";
8879 bset1 = isl_basic_set_read_from_str(ctx, str_with);
8880 bset2 = isl_basic_set_read_from_str(ctx, str_without);
8881 bset1 = isl_basic_set_drop_unused_params(bset1);
8882 equal = isl_basic_set_plain_is_equal(bset1, bset2);
8883 isl_basic_set_free(bset1);
8884 isl_basic_set_free(bset2);
8886 if (equal < 0)
8887 return -1;
8888 if (!equal)
8889 isl_die(ctx, isl_error_unknown,
8890 "result not as expected", return -1);
8892 set1 = isl_set_read_from_str(ctx, str_with);
8893 set2 = isl_set_read_from_str(ctx, str_without);
8894 set1 = isl_set_drop_unused_params(set1);
8895 equal = isl_set_plain_is_equal(set1, set2);
8896 isl_set_free(set1);
8897 isl_set_free(set2);
8899 if (equal < 0)
8900 return -1;
8901 if (!equal)
8902 isl_die(ctx, isl_error_unknown,
8903 "result not as expected", return -1);
8905 pwa1 = isl_pw_aff_read_from_str(ctx, str_with);
8906 pwa2 = isl_pw_aff_read_from_str(ctx, str_without);
8907 pwa1 = isl_pw_aff_drop_unused_params(pwa1);
8908 equal = isl_pw_aff_plain_is_equal(pwa1, pwa2);
8909 isl_pw_aff_free(pwa1);
8910 isl_pw_aff_free(pwa2);
8912 if (equal < 0)
8913 return -1;
8914 if (!equal)
8915 isl_die(ctx, isl_error_unknown,
8916 "result not as expected", return -1);
8918 return 0;
8921 static int test_list(isl_ctx *ctx)
8923 isl_id *a, *b, *c, *d, *id;
8924 isl_id_list *list;
8925 isl_size n;
8926 int ok;
8928 a = isl_id_alloc(ctx, "a", NULL);
8929 b = isl_id_alloc(ctx, "b", NULL);
8930 c = isl_id_alloc(ctx, "c", NULL);
8931 d = isl_id_alloc(ctx, "d", NULL);
8933 list = isl_id_list_alloc(ctx, 4);
8934 list = isl_id_list_add(list, b);
8935 list = isl_id_list_insert(list, 0, a);
8936 list = isl_id_list_add(list, c);
8937 list = isl_id_list_add(list, d);
8938 list = isl_id_list_drop(list, 1, 1);
8940 n = isl_id_list_n_id(list);
8941 if (n < 0)
8942 return -1;
8943 if (n != 3) {
8944 isl_id_list_free(list);
8945 isl_die(ctx, isl_error_unknown,
8946 "unexpected number of elements in list", return -1);
8949 id = isl_id_list_get_id(list, 0);
8950 ok = id == a;
8951 isl_id_free(id);
8952 id = isl_id_list_get_id(list, 1);
8953 ok = ok && id == c;
8954 isl_id_free(id);
8955 id = isl_id_list_get_id(list, 2);
8956 ok = ok && id == d;
8957 isl_id_free(id);
8959 isl_id_list_free(list);
8961 if (!ok)
8962 isl_die(ctx, isl_error_unknown,
8963 "unexpected elements in list", return -1);
8965 return 0;
8968 /* Check the conversion from an isl_multi_aff to an isl_basic_set.
8970 static isl_stat test_ma_conversion(isl_ctx *ctx)
8972 const char *str;
8973 isl_bool equal;
8974 isl_multi_aff *ma;
8975 isl_basic_set *bset1, *bset2;
8977 str = "[N] -> { A[0, N + 1] }";
8978 ma = isl_multi_aff_read_from_str(ctx, str);
8979 bset1 = isl_basic_set_read_from_str(ctx, str);
8980 bset2 = isl_basic_set_from_multi_aff(ma);
8981 equal = isl_basic_set_is_equal(bset1, bset2);
8982 isl_basic_set_free(bset1);
8983 isl_basic_set_free(bset2);
8984 if (equal < 0)
8985 return isl_stat_error;
8986 if (!equal)
8987 isl_die(ctx, isl_error_unknown, "bad conversion",
8988 return isl_stat_error);
8989 return isl_stat_ok;
8992 const char *set_conversion_tests[] = {
8993 "[N] -> { [i] : N - 1 <= 2 i <= N }",
8994 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
8995 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
8996 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
8997 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
8998 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
8999 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
9000 "-3 + c <= d <= 28 + c) }",
9003 /* Check that converting from isl_set to isl_pw_multi_aff and back
9004 * to isl_set produces the original isl_set.
9006 static int test_set_conversion(isl_ctx *ctx)
9008 int i;
9009 const char *str;
9010 isl_set *set1, *set2;
9011 isl_pw_multi_aff *pma;
9012 int equal;
9014 for (i = 0; i < ARRAY_SIZE(set_conversion_tests); ++i) {
9015 str = set_conversion_tests[i];
9016 set1 = isl_set_read_from_str(ctx, str);
9017 pma = isl_pw_multi_aff_from_set(isl_set_copy(set1));
9018 set2 = isl_set_from_pw_multi_aff(pma);
9019 equal = isl_set_is_equal(set1, set2);
9020 isl_set_free(set1);
9021 isl_set_free(set2);
9023 if (equal < 0)
9024 return -1;
9025 if (!equal)
9026 isl_die(ctx, isl_error_unknown, "bad conversion",
9027 return -1);
9030 return 0;
9033 const char *conversion_tests[] = {
9034 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9035 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9036 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9037 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9038 "9e <= -2 - 2a) }",
9039 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9040 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9041 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9044 /* Check that converting from isl_map to isl_pw_multi_aff and back
9045 * to isl_map produces the original isl_map.
9047 static int test_map_conversion(isl_ctx *ctx)
9049 int i;
9050 isl_map *map1, *map2;
9051 isl_pw_multi_aff *pma;
9052 int equal;
9054 for (i = 0; i < ARRAY_SIZE(conversion_tests); ++i) {
9055 map1 = isl_map_read_from_str(ctx, conversion_tests[i]);
9056 pma = isl_pw_multi_aff_from_map(isl_map_copy(map1));
9057 map2 = isl_map_from_pw_multi_aff(pma);
9058 equal = isl_map_is_equal(map1, map2);
9059 isl_map_free(map1);
9060 isl_map_free(map2);
9062 if (equal < 0)
9063 return -1;
9064 if (!equal)
9065 isl_die(ctx, isl_error_unknown, "bad conversion",
9066 return -1);
9069 return 0;
9072 /* Descriptions of isl_pw_multi_aff objects for testing conversion
9073 * to isl_multi_pw_aff and back.
9075 const char *mpa_conversion_tests[] = {
9076 "{ [x] -> A[x] }",
9077 "{ [x] -> A[x] : x >= 0 }",
9078 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
9079 "{ [x] -> A[x, x + 1] }",
9080 "{ [x] -> A[] }",
9081 "{ [x] -> A[] : x >= 0 }",
9084 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
9085 * back to isl_pw_multi_aff preserves the original meaning.
9087 static int test_mpa_conversion(isl_ctx *ctx)
9089 int i;
9090 isl_pw_multi_aff *pma1, *pma2;
9091 isl_multi_pw_aff *mpa;
9092 int equal;
9094 for (i = 0; i < ARRAY_SIZE(mpa_conversion_tests); ++i) {
9095 const char *str;
9096 str = mpa_conversion_tests[i];
9097 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
9098 pma2 = isl_pw_multi_aff_copy(pma1);
9099 mpa = isl_multi_pw_aff_from_pw_multi_aff(pma1);
9100 pma1 = isl_pw_multi_aff_from_multi_pw_aff(mpa);
9101 equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
9102 isl_pw_multi_aff_free(pma1);
9103 isl_pw_multi_aff_free(pma2);
9105 if (equal < 0)
9106 return -1;
9107 if (!equal)
9108 isl_die(ctx, isl_error_unknown, "bad conversion",
9109 return -1);
9112 return 0;
9115 /* Descriptions of union maps that should be convertible
9116 * to an isl_multi_union_pw_aff.
9118 const char *umap_mupa_conversion_tests[] = {
9119 "{ [a, b, c, d] -> s0[a, b, e, f] : "
9120 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
9121 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
9122 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
9123 "9e <= -2 - 2a) }",
9124 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
9125 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
9126 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
9127 "{ A[] -> B[0]; C[] -> B[1] }",
9128 "{ A[] -> B[]; C[] -> B[] }",
9131 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
9132 * to isl_union_map produces the original isl_union_map.
9134 static int test_union_map_mupa_conversion(isl_ctx *ctx)
9136 int i;
9137 isl_union_map *umap1, *umap2;
9138 isl_multi_union_pw_aff *mupa;
9139 int equal;
9141 for (i = 0; i < ARRAY_SIZE(umap_mupa_conversion_tests); ++i) {
9142 const char *str;
9143 str = umap_mupa_conversion_tests[i];
9144 umap1 = isl_union_map_read_from_str(ctx, str);
9145 umap2 = isl_union_map_copy(umap1);
9146 mupa = isl_multi_union_pw_aff_from_union_map(umap2);
9147 umap2 = isl_union_map_from_multi_union_pw_aff(mupa);
9148 equal = isl_union_map_is_equal(umap1, umap2);
9149 isl_union_map_free(umap1);
9150 isl_union_map_free(umap2);
9152 if (equal < 0)
9153 return -1;
9154 if (!equal)
9155 isl_die(ctx, isl_error_unknown, "bad conversion",
9156 return -1);
9159 return 0;
9162 static int test_conversion(isl_ctx *ctx)
9164 if (test_ma_conversion(ctx) < 0)
9165 return -1;
9166 if (test_set_conversion(ctx) < 0)
9167 return -1;
9168 if (test_map_conversion(ctx) < 0)
9169 return -1;
9170 if (test_mpa_conversion(ctx) < 0)
9171 return -1;
9172 if (test_union_map_mupa_conversion(ctx) < 0)
9173 return -1;
9174 return 0;
9177 /* Check that isl_basic_map_curry does not modify input.
9179 static int test_curry(isl_ctx *ctx)
9181 const char *str;
9182 isl_basic_map *bmap1, *bmap2;
9183 int equal;
9185 str = "{ [A[] -> B[]] -> C[] }";
9186 bmap1 = isl_basic_map_read_from_str(ctx, str);
9187 bmap2 = isl_basic_map_curry(isl_basic_map_copy(bmap1));
9188 equal = isl_basic_map_is_equal(bmap1, bmap2);
9189 isl_basic_map_free(bmap1);
9190 isl_basic_map_free(bmap2);
9192 if (equal < 0)
9193 return -1;
9194 if (equal)
9195 isl_die(ctx, isl_error_unknown,
9196 "curried map should not be equal to original",
9197 return -1);
9199 return 0;
9202 struct {
9203 const char *set;
9204 const char *ma;
9205 const char *res;
9206 } preimage_tests[] = {
9207 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
9208 "{ A[j,i] -> B[i,j] }",
9209 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
9210 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
9211 "{ A[a,b] -> B[a/2,b/6] }",
9212 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
9213 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
9214 "{ A[a,b] -> B[a/2,b/6] }",
9215 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
9216 "exists i,j : a = 2 i and b = 6 j }" },
9217 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
9218 "[n] -> { : 0 <= n <= 100 }" },
9219 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
9220 "{ A[a] -> B[2a] }",
9221 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
9222 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
9223 "{ A[a] -> B[([a/2])] }",
9224 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
9225 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
9226 "{ A[a] -> B[a,a,a/3] }",
9227 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
9228 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
9229 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
9232 static int test_preimage_basic_set(isl_ctx *ctx)
9234 int i;
9235 isl_basic_set *bset1, *bset2;
9236 isl_multi_aff *ma;
9237 int equal;
9239 for (i = 0; i < ARRAY_SIZE(preimage_tests); ++i) {
9240 bset1 = isl_basic_set_read_from_str(ctx, preimage_tests[i].set);
9241 ma = isl_multi_aff_read_from_str(ctx, preimage_tests[i].ma);
9242 bset2 = isl_basic_set_read_from_str(ctx, preimage_tests[i].res);
9243 bset1 = isl_basic_set_preimage_multi_aff(bset1, ma);
9244 equal = isl_basic_set_is_equal(bset1, bset2);
9245 isl_basic_set_free(bset1);
9246 isl_basic_set_free(bset2);
9247 if (equal < 0)
9248 return -1;
9249 if (!equal)
9250 isl_die(ctx, isl_error_unknown, "bad preimage",
9251 return -1);
9254 return 0;
9257 struct {
9258 const char *map;
9259 const char *ma;
9260 const char *res;
9261 } preimage_domain_tests[] = {
9262 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
9263 "{ A[j,i] -> B[i,j] }",
9264 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
9265 { "{ B[i] -> C[i]; D[i] -> E[i] }",
9266 "{ A[i] -> B[i + 1] }",
9267 "{ A[i] -> C[i + 1] }" },
9268 { "{ B[i] -> C[i]; B[i] -> E[i] }",
9269 "{ A[i] -> B[i + 1] }",
9270 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
9271 { "{ B[i] -> C[([i/2])] }",
9272 "{ A[i] -> B[2i] }",
9273 "{ A[i] -> C[i] }" },
9274 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
9275 "{ A[i] -> B[([i/5]), ([i/7])] }",
9276 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
9277 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
9278 "[N] -> { A[] -> B[([N/5])] }",
9279 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
9280 { "{ B[i] -> C[i] : exists a : i = 5 a }",
9281 "{ A[i] -> B[2i] }",
9282 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
9283 { "{ B[i] -> C[i] : exists a : i = 2 a; "
9284 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
9285 "{ A[i] -> B[2i] }",
9286 "{ A[i] -> C[2i] }" },
9287 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
9288 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
9291 static int test_preimage_union_map(isl_ctx *ctx)
9293 int i;
9294 isl_union_map *umap1, *umap2;
9295 isl_multi_aff *ma;
9296 int equal;
9298 for (i = 0; i < ARRAY_SIZE(preimage_domain_tests); ++i) {
9299 umap1 = isl_union_map_read_from_str(ctx,
9300 preimage_domain_tests[i].map);
9301 ma = isl_multi_aff_read_from_str(ctx,
9302 preimage_domain_tests[i].ma);
9303 umap2 = isl_union_map_read_from_str(ctx,
9304 preimage_domain_tests[i].res);
9305 umap1 = isl_union_map_preimage_domain_multi_aff(umap1, ma);
9306 equal = isl_union_map_is_equal(umap1, umap2);
9307 isl_union_map_free(umap1);
9308 isl_union_map_free(umap2);
9309 if (equal < 0)
9310 return -1;
9311 if (!equal)
9312 isl_die(ctx, isl_error_unknown, "bad preimage",
9313 return -1);
9316 return 0;
9319 static int test_preimage(isl_ctx *ctx)
9321 if (test_preimage_basic_set(ctx) < 0)
9322 return -1;
9323 if (test_preimage_union_map(ctx) < 0)
9324 return -1;
9326 return 0;
9329 struct {
9330 const char *ma1;
9331 const char *ma;
9332 const char *res;
9333 } pullback_tests[] = {
9334 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
9335 "{ A[a,b] -> C[b + 2a] }" },
9336 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
9337 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
9338 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
9339 "{ A[a] -> C[(a)/6] }" },
9340 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
9341 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
9342 "{ A[a] -> C[(2a)/3] }" },
9343 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
9344 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
9345 "{ A[i,j] -> C[i + j, i + j] }"},
9346 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
9347 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
9348 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
9349 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
9350 "{ [i, j] -> [floor((i)/3), j] }",
9351 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
9354 static int test_pullback(isl_ctx *ctx)
9356 int i;
9357 isl_multi_aff *ma1, *ma2;
9358 isl_multi_aff *ma;
9359 int equal;
9361 for (i = 0; i < ARRAY_SIZE(pullback_tests); ++i) {
9362 ma1 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma1);
9363 ma = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma);
9364 ma2 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].res);
9365 ma1 = isl_multi_aff_pullback_multi_aff(ma1, ma);
9366 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
9367 isl_multi_aff_free(ma1);
9368 isl_multi_aff_free(ma2);
9369 if (equal < 0)
9370 return -1;
9371 if (!equal)
9372 isl_die(ctx, isl_error_unknown, "bad pullback",
9373 return -1);
9376 return 0;
9379 /* Check that negation is printed correctly and that equal expressions
9380 * are correctly identified.
9382 static int test_ast(isl_ctx *ctx)
9384 isl_ast_expr *expr, *expr1, *expr2, *expr3;
9385 char *str;
9386 int ok, equal;
9388 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
9389 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
9390 expr = isl_ast_expr_add(expr1, expr2);
9391 expr2 = isl_ast_expr_copy(expr);
9392 expr = isl_ast_expr_neg(expr);
9393 expr2 = isl_ast_expr_neg(expr2);
9394 equal = isl_ast_expr_is_equal(expr, expr2);
9395 str = isl_ast_expr_to_C_str(expr);
9396 ok = str ? !strcmp(str, "-(A + B)") : -1;
9397 free(str);
9398 isl_ast_expr_free(expr);
9399 isl_ast_expr_free(expr2);
9401 if (ok < 0 || equal < 0)
9402 return -1;
9403 if (!equal)
9404 isl_die(ctx, isl_error_unknown,
9405 "equal expressions not considered equal", return -1);
9406 if (!ok)
9407 isl_die(ctx, isl_error_unknown,
9408 "isl_ast_expr printed incorrectly", return -1);
9410 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
9411 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
9412 expr = isl_ast_expr_add(expr1, expr2);
9413 expr3 = isl_ast_expr_from_id(isl_id_alloc(ctx, "C", NULL));
9414 expr = isl_ast_expr_sub(expr3, expr);
9415 str = isl_ast_expr_to_C_str(expr);
9416 ok = str ? !strcmp(str, "C - (A + B)") : -1;
9417 free(str);
9418 isl_ast_expr_free(expr);
9420 if (ok < 0)
9421 return -1;
9422 if (!ok)
9423 isl_die(ctx, isl_error_unknown,
9424 "isl_ast_expr printed incorrectly", return -1);
9426 return 0;
9429 /* Check that isl_ast_build_expr_from_set returns a valid expression
9430 * for an empty set. Note that isl_ast_build_expr_from_set getting
9431 * called on an empty set probably indicates a bug in the caller.
9433 static int test_ast_build(isl_ctx *ctx)
9435 isl_set *set;
9436 isl_ast_build *build;
9437 isl_ast_expr *expr;
9439 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9440 build = isl_ast_build_from_context(set);
9442 set = isl_set_empty(isl_space_params_alloc(ctx, 0));
9443 expr = isl_ast_build_expr_from_set(build, set);
9445 isl_ast_expr_free(expr);
9446 isl_ast_build_free(build);
9448 if (!expr)
9449 return -1;
9451 return 0;
9454 /* Internal data structure for before_for and after_for callbacks.
9456 * depth is the current depth
9457 * before is the number of times before_for has been called
9458 * after is the number of times after_for has been called
9460 struct isl_test_codegen_data {
9461 int depth;
9462 int before;
9463 int after;
9466 /* This function is called before each for loop in the AST generated
9467 * from test_ast_gen1.
9469 * Increment the number of calls and the depth.
9470 * Check that the space returned by isl_ast_build_get_schedule_space
9471 * matches the target space of the schedule returned by
9472 * isl_ast_build_get_schedule.
9473 * Return an isl_id that is checked by the corresponding call
9474 * to after_for.
9476 static __isl_give isl_id *before_for(__isl_keep isl_ast_build *build,
9477 void *user)
9479 struct isl_test_codegen_data *data = user;
9480 isl_ctx *ctx;
9481 isl_space *space;
9482 isl_union_map *schedule;
9483 isl_union_set *uset;
9484 isl_set *set;
9485 isl_bool empty;
9486 isl_size n;
9487 char name[] = "d0";
9489 ctx = isl_ast_build_get_ctx(build);
9491 if (data->before >= 3)
9492 isl_die(ctx, isl_error_unknown,
9493 "unexpected number of for nodes", return NULL);
9494 if (data->depth < 0 || data->depth >= 2)
9495 isl_die(ctx, isl_error_unknown,
9496 "unexpected depth", return NULL);
9498 snprintf(name, sizeof(name), "d%d", data->depth);
9499 data->before++;
9500 data->depth++;
9502 schedule = isl_ast_build_get_schedule(build);
9503 uset = isl_union_map_range(schedule);
9504 n = isl_union_set_n_set(uset);
9505 if (n != 1) {
9506 isl_union_set_free(uset);
9507 if (n < 0)
9508 return NULL;
9509 isl_die(ctx, isl_error_unknown,
9510 "expecting single range space", return NULL);
9513 space = isl_ast_build_get_schedule_space(build);
9514 set = isl_union_set_extract_set(uset, space);
9515 isl_union_set_free(uset);
9516 empty = isl_set_is_empty(set);
9517 isl_set_free(set);
9519 if (empty < 0)
9520 return NULL;
9521 if (empty)
9522 isl_die(ctx, isl_error_unknown,
9523 "spaces don't match", return NULL);
9525 return isl_id_alloc(ctx, name, NULL);
9528 /* This function is called after each for loop in the AST generated
9529 * from test_ast_gen1.
9531 * Increment the number of calls and decrement the depth.
9532 * Check that the annotation attached to the node matches
9533 * the isl_id returned by the corresponding call to before_for.
9535 static __isl_give isl_ast_node *after_for(__isl_take isl_ast_node *node,
9536 __isl_keep isl_ast_build *build, void *user)
9538 struct isl_test_codegen_data *data = user;
9539 isl_id *id;
9540 const char *name;
9541 int valid;
9543 data->after++;
9544 data->depth--;
9546 if (data->after > data->before)
9547 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
9548 "mismatch in number of for nodes",
9549 return isl_ast_node_free(node));
9551 id = isl_ast_node_get_annotation(node);
9552 if (!id)
9553 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
9554 "missing annotation", return isl_ast_node_free(node));
9556 name = isl_id_get_name(id);
9557 valid = name && atoi(name + 1) == data->depth;
9558 isl_id_free(id);
9560 if (!valid)
9561 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
9562 "wrong annotation", return isl_ast_node_free(node));
9564 return node;
9567 /* Check that the before_each_for and after_each_for callbacks
9568 * are called for each for loop in the generated code,
9569 * that they are called in the right order and that the isl_id
9570 * returned from the before_each_for callback is attached to
9571 * the isl_ast_node passed to the corresponding after_each_for call.
9573 static int test_ast_gen1(isl_ctx *ctx)
9575 const char *str;
9576 isl_set *set;
9577 isl_union_map *schedule;
9578 isl_ast_build *build;
9579 isl_ast_node *tree;
9580 struct isl_test_codegen_data data;
9582 str = "[N] -> { : N >= 10 }";
9583 set = isl_set_read_from_str(ctx, str);
9584 str = "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
9585 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
9586 schedule = isl_union_map_read_from_str(ctx, str);
9588 data.before = 0;
9589 data.after = 0;
9590 data.depth = 0;
9591 build = isl_ast_build_from_context(set);
9592 build = isl_ast_build_set_before_each_for(build,
9593 &before_for, &data);
9594 build = isl_ast_build_set_after_each_for(build,
9595 &after_for, &data);
9596 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9597 isl_ast_build_free(build);
9598 if (!tree)
9599 return -1;
9601 isl_ast_node_free(tree);
9603 if (data.before != 3 || data.after != 3)
9604 isl_die(ctx, isl_error_unknown,
9605 "unexpected number of for nodes", return -1);
9607 return 0;
9610 /* Check that the AST generator handles domains that are integrally disjoint
9611 * but not rationally disjoint.
9613 static int test_ast_gen2(isl_ctx *ctx)
9615 const char *str;
9616 isl_set *set;
9617 isl_union_map *schedule;
9618 isl_union_map *options;
9619 isl_ast_build *build;
9620 isl_ast_node *tree;
9622 str = "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
9623 schedule = isl_union_map_read_from_str(ctx, str);
9624 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9625 build = isl_ast_build_from_context(set);
9627 str = "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
9628 options = isl_union_map_read_from_str(ctx, str);
9629 build = isl_ast_build_set_options(build, options);
9630 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9631 isl_ast_build_free(build);
9632 if (!tree)
9633 return -1;
9634 isl_ast_node_free(tree);
9636 return 0;
9639 /* Increment *user on each call.
9641 static __isl_give isl_ast_node *count_domains(__isl_take isl_ast_node *node,
9642 __isl_keep isl_ast_build *build, void *user)
9644 int *n = user;
9646 (*n)++;
9648 return node;
9651 /* Test that unrolling tries to minimize the number of instances.
9652 * In particular, for the schedule given below, make sure it generates
9653 * 3 nodes (rather than 101).
9655 static int test_ast_gen3(isl_ctx *ctx)
9657 const char *str;
9658 isl_set *set;
9659 isl_union_map *schedule;
9660 isl_union_map *options;
9661 isl_ast_build *build;
9662 isl_ast_node *tree;
9663 int n_domain = 0;
9665 str = "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
9666 schedule = isl_union_map_read_from_str(ctx, str);
9667 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9669 str = "{ [i] -> unroll[0] }";
9670 options = isl_union_map_read_from_str(ctx, str);
9672 build = isl_ast_build_from_context(set);
9673 build = isl_ast_build_set_options(build, options);
9674 build = isl_ast_build_set_at_each_domain(build,
9675 &count_domains, &n_domain);
9676 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9677 isl_ast_build_free(build);
9678 if (!tree)
9679 return -1;
9681 isl_ast_node_free(tree);
9683 if (n_domain != 3)
9684 isl_die(ctx, isl_error_unknown,
9685 "unexpected number of for nodes", return -1);
9687 return 0;
9690 /* Check that if the ast_build_exploit_nested_bounds options is set,
9691 * we do not get an outer if node in the generated AST,
9692 * while we do get such an outer if node if the options is not set.
9694 static int test_ast_gen4(isl_ctx *ctx)
9696 const char *str;
9697 isl_set *set;
9698 isl_union_map *schedule;
9699 isl_ast_build *build;
9700 isl_ast_node *tree;
9701 enum isl_ast_node_type type;
9702 int enb;
9704 enb = isl_options_get_ast_build_exploit_nested_bounds(ctx);
9705 str = "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
9707 isl_options_set_ast_build_exploit_nested_bounds(ctx, 1);
9709 schedule = isl_union_map_read_from_str(ctx, str);
9710 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9711 build = isl_ast_build_from_context(set);
9712 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9713 isl_ast_build_free(build);
9714 if (!tree)
9715 return -1;
9717 type = isl_ast_node_get_type(tree);
9718 isl_ast_node_free(tree);
9720 if (type == isl_ast_node_if)
9721 isl_die(ctx, isl_error_unknown,
9722 "not expecting if node", return -1);
9724 isl_options_set_ast_build_exploit_nested_bounds(ctx, 0);
9726 schedule = isl_union_map_read_from_str(ctx, str);
9727 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9728 build = isl_ast_build_from_context(set);
9729 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9730 isl_ast_build_free(build);
9731 if (!tree)
9732 return -1;
9734 type = isl_ast_node_get_type(tree);
9735 isl_ast_node_free(tree);
9737 if (type != isl_ast_node_if)
9738 isl_die(ctx, isl_error_unknown,
9739 "expecting if node", return -1);
9741 isl_options_set_ast_build_exploit_nested_bounds(ctx, enb);
9743 return 0;
9746 /* This function is called for each leaf in the AST generated
9747 * from test_ast_gen5.
9749 * We finalize the AST generation by extending the outer schedule
9750 * with a zero-dimensional schedule. If this results in any for loops,
9751 * then this means that we did not pass along enough information
9752 * about the outer schedule to the inner AST generation.
9754 static __isl_give isl_ast_node *create_leaf(__isl_take isl_ast_build *build,
9755 void *user)
9757 isl_union_map *schedule, *extra;
9758 isl_ast_node *tree;
9760 schedule = isl_ast_build_get_schedule(build);
9761 extra = isl_union_map_copy(schedule);
9762 extra = isl_union_map_from_domain(isl_union_map_domain(extra));
9763 schedule = isl_union_map_range_product(schedule, extra);
9764 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9765 isl_ast_build_free(build);
9767 if (!tree)
9768 return NULL;
9770 if (isl_ast_node_get_type(tree) == isl_ast_node_for)
9771 isl_die(isl_ast_node_get_ctx(tree), isl_error_unknown,
9772 "code should not contain any for loop",
9773 return isl_ast_node_free(tree));
9775 return tree;
9778 /* Check that we do not lose any information when going back and
9779 * forth between internal and external schedule.
9781 * In particular, we create an AST where we unroll the only
9782 * non-constant dimension in the schedule. We therefore do
9783 * not expect any for loops in the AST. However, older versions
9784 * of isl would not pass along enough information about the outer
9785 * schedule when performing an inner code generation from a create_leaf
9786 * callback, resulting in the inner code generation producing a for loop.
9788 static int test_ast_gen5(isl_ctx *ctx)
9790 const char *str;
9791 isl_set *set;
9792 isl_union_map *schedule, *options;
9793 isl_ast_build *build;
9794 isl_ast_node *tree;
9796 str = "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
9797 schedule = isl_union_map_read_from_str(ctx, str);
9799 str = "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
9800 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
9801 options = isl_union_map_read_from_str(ctx, str);
9803 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
9804 build = isl_ast_build_from_context(set);
9805 build = isl_ast_build_set_options(build, options);
9806 build = isl_ast_build_set_create_leaf(build, &create_leaf, NULL);
9807 tree = isl_ast_build_node_from_schedule_map(build, schedule);
9808 isl_ast_build_free(build);
9809 isl_ast_node_free(tree);
9810 if (!tree)
9811 return -1;
9813 return 0;
9816 /* Check that the expression
9818 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
9820 * is not combined into
9822 * min(n/2, 0)
9824 * as this would result in n/2 being evaluated in parts of
9825 * the definition domain where n is not a multiple of 2.
9827 static int test_ast_expr(isl_ctx *ctx)
9829 const char *str;
9830 isl_pw_aff *pa;
9831 isl_ast_build *build;
9832 isl_ast_expr *expr;
9833 int min_max;
9834 int is_min;
9836 min_max = isl_options_get_ast_build_detect_min_max(ctx);
9837 isl_options_set_ast_build_detect_min_max(ctx, 1);
9839 str = "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
9840 pa = isl_pw_aff_read_from_str(ctx, str);
9841 build = isl_ast_build_alloc(ctx);
9842 expr = isl_ast_build_expr_from_pw_aff(build, pa);
9843 is_min = isl_ast_expr_get_type(expr) == isl_ast_expr_op &&
9844 isl_ast_expr_get_op_type(expr) == isl_ast_expr_op_min;
9845 isl_ast_build_free(build);
9846 isl_ast_expr_free(expr);
9848 isl_options_set_ast_build_detect_min_max(ctx, min_max);
9850 if (!expr)
9851 return -1;
9852 if (is_min)
9853 isl_die(ctx, isl_error_unknown,
9854 "expressions should not be combined", return -1);
9856 return 0;
9859 static int test_ast_gen(isl_ctx *ctx)
9861 if (test_ast_gen1(ctx) < 0)
9862 return -1;
9863 if (test_ast_gen2(ctx) < 0)
9864 return -1;
9865 if (test_ast_gen3(ctx) < 0)
9866 return -1;
9867 if (test_ast_gen4(ctx) < 0)
9868 return -1;
9869 if (test_ast_gen5(ctx) < 0)
9870 return -1;
9871 if (test_ast_expr(ctx) < 0)
9872 return -1;
9873 return 0;
9876 /* Check if dropping output dimensions from an isl_pw_multi_aff
9877 * works properly.
9879 static int test_pw_multi_aff(isl_ctx *ctx)
9881 const char *str;
9882 isl_pw_multi_aff *pma1, *pma2;
9883 int equal;
9885 str = "{ [i,j] -> [i+j, 4i-j] }";
9886 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
9887 str = "{ [i,j] -> [4i-j] }";
9888 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
9890 pma1 = isl_pw_multi_aff_drop_dims(pma1, isl_dim_out, 0, 1);
9892 equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
9894 isl_pw_multi_aff_free(pma1);
9895 isl_pw_multi_aff_free(pma2);
9896 if (equal < 0)
9897 return -1;
9898 if (!equal)
9899 isl_die(ctx, isl_error_unknown,
9900 "expressions not equal", return -1);
9902 return 0;
9905 /* Check that we can properly parse multi piecewise affine expressions
9906 * where the piecewise affine expressions have different domains.
9908 static int test_multi_pw_aff_1(isl_ctx *ctx)
9910 const char *str;
9911 isl_set *dom, *dom2;
9912 isl_multi_pw_aff *mpa1, *mpa2;
9913 isl_pw_aff *pa;
9914 int equal;
9915 int equal_domain;
9917 mpa1 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [i] }");
9918 dom = isl_set_read_from_str(ctx, "{ [i] : i > 0 }");
9919 mpa1 = isl_multi_pw_aff_intersect_domain(mpa1, dom);
9920 mpa2 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [2i] }");
9921 mpa2 = isl_multi_pw_aff_flat_range_product(mpa1, mpa2);
9922 str = "{ [i] -> [(i : i > 0), 2i] }";
9923 mpa1 = isl_multi_pw_aff_read_from_str(ctx, str);
9925 equal = isl_multi_pw_aff_plain_is_equal(mpa1, mpa2);
9927 pa = isl_multi_pw_aff_get_pw_aff(mpa1, 0);
9928 dom = isl_pw_aff_domain(pa);
9929 pa = isl_multi_pw_aff_get_pw_aff(mpa1, 1);
9930 dom2 = isl_pw_aff_domain(pa);
9931 equal_domain = isl_set_is_equal(dom, dom2);
9933 isl_set_free(dom);
9934 isl_set_free(dom2);
9935 isl_multi_pw_aff_free(mpa1);
9936 isl_multi_pw_aff_free(mpa2);
9938 if (equal < 0)
9939 return -1;
9940 if (!equal)
9941 isl_die(ctx, isl_error_unknown,
9942 "expressions not equal", return -1);
9944 if (equal_domain < 0)
9945 return -1;
9946 if (equal_domain)
9947 isl_die(ctx, isl_error_unknown,
9948 "domains unexpectedly equal", return -1);
9950 return 0;
9953 /* Check that the dimensions in the explicit domain
9954 * of a multi piecewise affine expression are properly
9955 * taken into account.
9957 static int test_multi_pw_aff_2(isl_ctx *ctx)
9959 const char *str;
9960 isl_bool involves1, involves2, involves3, equal;
9961 isl_multi_pw_aff *mpa, *mpa1, *mpa2;
9963 str = "{ A[x,y] -> B[] : x >= y }";
9964 mpa = isl_multi_pw_aff_read_from_str(ctx, str);
9965 involves1 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 2);
9966 mpa1 = isl_multi_pw_aff_copy(mpa);
9968 mpa = isl_multi_pw_aff_insert_dims(mpa, isl_dim_in, 0, 1);
9969 involves2 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 1);
9970 involves3 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 1, 2);
9971 str = "{ [a,x,y] -> B[] : x >= y }";
9972 mpa2 = isl_multi_pw_aff_read_from_str(ctx, str);
9973 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2);
9974 isl_multi_pw_aff_free(mpa2);
9976 mpa = isl_multi_pw_aff_drop_dims(mpa, isl_dim_in, 0, 1);
9977 mpa = isl_multi_pw_aff_set_tuple_name(mpa, isl_dim_in, "A");
9978 if (equal >= 0 && equal)
9979 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa1);
9980 isl_multi_pw_aff_free(mpa1);
9981 isl_multi_pw_aff_free(mpa);
9983 if (involves1 < 0 || involves2 < 0 || involves3 < 0 || equal < 0)
9984 return -1;
9985 if (!equal)
9986 isl_die(ctx, isl_error_unknown,
9987 "incorrect result of dimension insertion/removal",
9988 return isl_stat_error);
9989 if (!involves1 || involves2 || !involves3)
9990 isl_die(ctx, isl_error_unknown,
9991 "incorrect characterization of involved dimensions",
9992 return isl_stat_error);
9994 return 0;
9997 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
9998 * sets the explicit domain of a zero-dimensional result,
9999 * such that it can be converted to an isl_union_map.
10001 static isl_stat test_multi_pw_aff_3(isl_ctx *ctx)
10003 isl_space *space;
10004 isl_union_set *dom;
10005 isl_multi_val *mv;
10006 isl_multi_union_pw_aff *mupa;
10007 isl_union_map *umap;
10009 dom = isl_union_set_read_from_str(ctx, "{ A[]; B[] }");
10010 space = isl_union_set_get_space(dom);
10011 mv = isl_multi_val_zero(isl_space_set_from_params(space));
10012 mupa = isl_multi_union_pw_aff_multi_val_on_domain(dom, mv);
10013 umap = isl_union_map_from_multi_union_pw_aff(mupa);
10014 isl_union_map_free(umap);
10015 if (!umap)
10016 return isl_stat_error;
10018 return isl_stat_ok;
10021 /* Perform some tests on multi piecewise affine expressions.
10023 static int test_multi_pw_aff(isl_ctx *ctx)
10025 if (test_multi_pw_aff_1(ctx) < 0)
10026 return -1;
10027 if (test_multi_pw_aff_2(ctx) < 0)
10028 return -1;
10029 if (test_multi_pw_aff_3(ctx) < 0)
10030 return -1;
10031 return 0;
10034 /* This is a regression test for a bug where isl_basic_map_simplify
10035 * would end up in an infinite loop. In particular, we construct
10036 * an empty basic set that is not obviously empty.
10037 * isl_basic_set_is_empty marks the basic set as empty.
10038 * After projecting out i3, the variable can be dropped completely,
10039 * but isl_basic_map_simplify refrains from doing so if the basic set
10040 * is empty and would end up in an infinite loop if it didn't test
10041 * explicitly for empty basic maps in the outer loop.
10043 static int test_simplify_1(isl_ctx *ctx)
10045 const char *str;
10046 isl_basic_set *bset;
10047 int empty;
10049 str = "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
10050 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
10051 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
10052 "i3 >= i2 }";
10053 bset = isl_basic_set_read_from_str(ctx, str);
10054 empty = isl_basic_set_is_empty(bset);
10055 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
10056 isl_basic_set_free(bset);
10057 if (!bset)
10058 return -1;
10059 if (!empty)
10060 isl_die(ctx, isl_error_unknown,
10061 "basic set should be empty", return -1);
10063 return 0;
10066 /* Check that the equality in the set description below
10067 * is simplified away.
10069 static int test_simplify_2(isl_ctx *ctx)
10071 const char *str;
10072 isl_basic_set *bset;
10073 isl_bool universe;
10075 str = "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
10076 bset = isl_basic_set_read_from_str(ctx, str);
10077 universe = isl_basic_set_plain_is_universe(bset);
10078 isl_basic_set_free(bset);
10080 if (universe < 0)
10081 return -1;
10082 if (!universe)
10083 isl_die(ctx, isl_error_unknown,
10084 "equality not simplified away", return -1);
10085 return 0;
10088 /* Some simplification tests.
10090 static int test_simplify(isl_ctx *ctx)
10092 if (test_simplify_1(ctx) < 0)
10093 return -1;
10094 if (test_simplify_2(ctx) < 0)
10095 return -1;
10096 return 0;
10099 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
10100 * with gbr context would fail to disable the use of the shifted tableau
10101 * when transferring equalities for the input to the context, resulting
10102 * in invalid sample values.
10104 static int test_partial_lexmin(isl_ctx *ctx)
10106 const char *str;
10107 isl_basic_set *bset;
10108 isl_basic_map *bmap;
10109 isl_map *map;
10111 str = "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
10112 bmap = isl_basic_map_read_from_str(ctx, str);
10113 str = "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
10114 bset = isl_basic_set_read_from_str(ctx, str);
10115 map = isl_basic_map_partial_lexmin(bmap, bset, NULL);
10116 isl_map_free(map);
10118 if (!map)
10119 return -1;
10121 return 0;
10124 /* Check that the variable compression performed on the existentially
10125 * quantified variables inside isl_basic_set_compute_divs is not confused
10126 * by the implicit equalities among the parameters.
10128 static int test_compute_divs(isl_ctx *ctx)
10130 const char *str;
10131 isl_basic_set *bset;
10132 isl_set *set;
10134 str = "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
10135 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
10136 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
10137 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
10138 bset = isl_basic_set_read_from_str(ctx, str);
10139 set = isl_basic_set_compute_divs(bset);
10140 isl_set_free(set);
10141 if (!set)
10142 return -1;
10144 return 0;
10147 /* Check that isl_schedule_get_map is not confused by a schedule tree
10148 * with divergent filter node parameters, as can result from a call
10149 * to isl_schedule_intersect_domain.
10151 static int test_schedule_tree(isl_ctx *ctx)
10153 const char *str;
10154 isl_union_set *uset;
10155 isl_schedule *sched1, *sched2;
10156 isl_union_map *umap;
10158 uset = isl_union_set_read_from_str(ctx, "{ A[i] }");
10159 sched1 = isl_schedule_from_domain(uset);
10160 uset = isl_union_set_read_from_str(ctx, "{ B[] }");
10161 sched2 = isl_schedule_from_domain(uset);
10163 sched1 = isl_schedule_sequence(sched1, sched2);
10164 str = "[n] -> { A[i] : 0 <= i < n; B[] }";
10165 uset = isl_union_set_read_from_str(ctx, str);
10166 sched1 = isl_schedule_intersect_domain(sched1, uset);
10167 umap = isl_schedule_get_map(sched1);
10168 isl_schedule_free(sched1);
10169 isl_union_map_free(umap);
10170 if (!umap)
10171 return -1;
10173 return 0;
10176 /* Check that a zero-dimensional prefix schedule keeps track
10177 * of the domain and outer filters.
10179 static int test_schedule_tree_prefix(isl_ctx *ctx)
10181 const char *str;
10182 isl_bool equal;
10183 isl_union_set *uset;
10184 isl_union_set_list *filters;
10185 isl_multi_union_pw_aff *mupa, *mupa2;
10186 isl_schedule_node *node;
10188 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10189 uset = isl_union_set_read_from_str(ctx, str);
10190 node = isl_schedule_node_from_domain(uset);
10191 node = isl_schedule_node_child(node, 0);
10193 str = "{ S1[i,j] : i > j }";
10194 uset = isl_union_set_read_from_str(ctx, str);
10195 filters = isl_union_set_list_from_union_set(uset);
10196 str = "{ S1[i,j] : i <= j; S2[i,j] }";
10197 uset = isl_union_set_read_from_str(ctx, str);
10198 filters = isl_union_set_list_add(filters, uset);
10199 node = isl_schedule_node_insert_sequence(node, filters);
10201 node = isl_schedule_node_child(node, 0);
10202 node = isl_schedule_node_child(node, 0);
10203 mupa = isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node);
10204 str = "([] : { S1[i,j] : i > j })";
10205 mupa2 = isl_multi_union_pw_aff_read_from_str(ctx, str);
10206 equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2);
10207 isl_multi_union_pw_aff_free(mupa2);
10208 isl_multi_union_pw_aff_free(mupa);
10209 isl_schedule_node_free(node);
10211 if (equal < 0)
10212 return -1;
10213 if (!equal)
10214 isl_die(ctx, isl_error_unknown, "unexpected prefix schedule",
10215 return -1);
10217 return 0;
10220 /* Check that the reaching domain elements and the prefix schedule
10221 * at a leaf node are the same before and after grouping.
10223 static int test_schedule_tree_group_1(isl_ctx *ctx)
10225 int equal;
10226 const char *str;
10227 isl_id *id;
10228 isl_union_set *uset;
10229 isl_multi_union_pw_aff *mupa;
10230 isl_union_pw_multi_aff *upma1, *upma2;
10231 isl_union_set *domain1, *domain2;
10232 isl_union_map *umap1, *umap2;
10233 isl_schedule_node *node;
10235 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
10236 uset = isl_union_set_read_from_str(ctx, str);
10237 node = isl_schedule_node_from_domain(uset);
10238 node = isl_schedule_node_child(node, 0);
10239 str = "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
10240 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10241 node = isl_schedule_node_insert_partial_schedule(node, mupa);
10242 node = isl_schedule_node_child(node, 0);
10243 str = "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
10244 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10245 node = isl_schedule_node_insert_partial_schedule(node, mupa);
10246 node = isl_schedule_node_child(node, 0);
10247 umap1 = isl_schedule_node_get_prefix_schedule_union_map(node);
10248 upma1 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node);
10249 domain1 = isl_schedule_node_get_domain(node);
10250 id = isl_id_alloc(ctx, "group", NULL);
10251 node = isl_schedule_node_parent(node);
10252 node = isl_schedule_node_group(node, id);
10253 node = isl_schedule_node_child(node, 0);
10254 umap2 = isl_schedule_node_get_prefix_schedule_union_map(node);
10255 upma2 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node);
10256 domain2 = isl_schedule_node_get_domain(node);
10257 equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2);
10258 if (equal >= 0 && equal)
10259 equal = isl_union_set_is_equal(domain1, domain2);
10260 if (equal >= 0 && equal)
10261 equal = isl_union_map_is_equal(umap1, umap2);
10262 isl_union_map_free(umap1);
10263 isl_union_map_free(umap2);
10264 isl_union_set_free(domain1);
10265 isl_union_set_free(domain2);
10266 isl_union_pw_multi_aff_free(upma1);
10267 isl_union_pw_multi_aff_free(upma2);
10268 isl_schedule_node_free(node);
10270 if (equal < 0)
10271 return -1;
10272 if (!equal)
10273 isl_die(ctx, isl_error_unknown,
10274 "expressions not equal", return -1);
10276 return 0;
10279 /* Check that we can have nested groupings and that the union map
10280 * schedule representation is the same before and after the grouping.
10281 * Note that after the grouping, the union map representation contains
10282 * the domain constraints from the ranges of the expansion nodes,
10283 * while they are missing from the union map representation of
10284 * the tree without expansion nodes.
10286 * Also check that the global expansion is as expected.
10288 static int test_schedule_tree_group_2(isl_ctx *ctx)
10290 int equal, equal_expansion;
10291 const char *str;
10292 isl_id *id;
10293 isl_union_set *uset;
10294 isl_union_map *umap1, *umap2;
10295 isl_union_map *expansion1, *expansion2;
10296 isl_union_set_list *filters;
10297 isl_multi_union_pw_aff *mupa;
10298 isl_schedule *schedule;
10299 isl_schedule_node *node;
10301 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
10302 "S3[i,j] : 0 <= i,j < 10 }";
10303 uset = isl_union_set_read_from_str(ctx, str);
10304 node = isl_schedule_node_from_domain(uset);
10305 node = isl_schedule_node_child(node, 0);
10306 str = "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
10307 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10308 node = isl_schedule_node_insert_partial_schedule(node, mupa);
10309 node = isl_schedule_node_child(node, 0);
10310 str = "{ S1[i,j] }";
10311 uset = isl_union_set_read_from_str(ctx, str);
10312 filters = isl_union_set_list_from_union_set(uset);
10313 str = "{ S2[i,j]; S3[i,j] }";
10314 uset = isl_union_set_read_from_str(ctx, str);
10315 filters = isl_union_set_list_add(filters, uset);
10316 node = isl_schedule_node_insert_sequence(node, filters);
10317 node = isl_schedule_node_child(node, 1);
10318 node = isl_schedule_node_child(node, 0);
10319 str = "{ S2[i,j] }";
10320 uset = isl_union_set_read_from_str(ctx, str);
10321 filters = isl_union_set_list_from_union_set(uset);
10322 str = "{ S3[i,j] }";
10323 uset = isl_union_set_read_from_str(ctx, str);
10324 filters = isl_union_set_list_add(filters, uset);
10325 node = isl_schedule_node_insert_sequence(node, filters);
10327 schedule = isl_schedule_node_get_schedule(node);
10328 umap1 = isl_schedule_get_map(schedule);
10329 uset = isl_schedule_get_domain(schedule);
10330 umap1 = isl_union_map_intersect_domain(umap1, uset);
10331 isl_schedule_free(schedule);
10333 node = isl_schedule_node_parent(node);
10334 node = isl_schedule_node_parent(node);
10335 id = isl_id_alloc(ctx, "group1", NULL);
10336 node = isl_schedule_node_group(node, id);
10337 node = isl_schedule_node_child(node, 1);
10338 node = isl_schedule_node_child(node, 0);
10339 id = isl_id_alloc(ctx, "group2", NULL);
10340 node = isl_schedule_node_group(node, id);
10342 schedule = isl_schedule_node_get_schedule(node);
10343 umap2 = isl_schedule_get_map(schedule);
10344 isl_schedule_free(schedule);
10346 node = isl_schedule_node_root(node);
10347 node = isl_schedule_node_child(node, 0);
10348 expansion1 = isl_schedule_node_get_subtree_expansion(node);
10349 isl_schedule_node_free(node);
10351 str = "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
10352 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
10353 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
10355 expansion2 = isl_union_map_read_from_str(ctx, str);
10357 equal = isl_union_map_is_equal(umap1, umap2);
10358 equal_expansion = isl_union_map_is_equal(expansion1, expansion2);
10360 isl_union_map_free(umap1);
10361 isl_union_map_free(umap2);
10362 isl_union_map_free(expansion1);
10363 isl_union_map_free(expansion2);
10365 if (equal < 0 || equal_expansion < 0)
10366 return -1;
10367 if (!equal)
10368 isl_die(ctx, isl_error_unknown,
10369 "expressions not equal", return -1);
10370 if (!equal_expansion)
10371 isl_die(ctx, isl_error_unknown,
10372 "unexpected expansion", return -1);
10374 return 0;
10377 /* Some tests for the isl_schedule_node_group function.
10379 static int test_schedule_tree_group(isl_ctx *ctx)
10381 if (test_schedule_tree_group_1(ctx) < 0)
10382 return -1;
10383 if (test_schedule_tree_group_2(ctx) < 0)
10384 return -1;
10385 return 0;
10388 struct {
10389 const char *set;
10390 const char *dual;
10391 } coef_tests[] = {
10392 { "{ rat: [i] : 0 <= i <= 10 }",
10393 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
10394 { "{ rat: [i] : FALSE }",
10395 "{ rat: coefficients[[cst] -> [a]] }" },
10396 { "{ rat: [i] : }",
10397 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
10398 { "{ [0:,1,2:3] }",
10399 "{ rat: coefficients[[c_cst] -> [a, b, c]] : "
10400 "a >= 0 and 2c >= -c_cst - b and 3c >= -c_cst - b }" },
10401 { "[M, N] -> { [x = (1 - N):-1, -4x:(M - 4x)] }",
10402 "{ rat: coefficients[[c_cst, c_M = 0:, c_N = 0:] -> [a, b = -c_M:]] :"
10403 "4b >= -c_N + a and 4b >= -c_cst - 2c_N + a }" },
10404 { "{ rat : [x, y] : 1 <= 2x <= 9 and 2 <= 3y <= 16 }",
10405 "{ rat: coefficients[[c_cst] -> [c_x, c_y]] : "
10406 "4c_y >= -6c_cst - 3c_x and 4c_y >= -6c_cst - 27c_x and "
10407 "32c_y >= -6c_cst - 3c_x and 32c_y >= -6c_cst - 27c_x }" },
10408 { "{ [x, y, z] : 3y <= 2x - 2 and y >= -2 + 2x and 2y >= 2 - x }",
10409 "{ rat: coefficients[[cst] -> [a, b, c]] }" },
10412 struct {
10413 const char *set;
10414 const char *dual;
10415 } sol_tests[] = {
10416 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
10417 "{ rat: [i] : 0 <= i <= 10 }" },
10418 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
10419 "{ rat: [i] }" },
10420 { "{ rat: coefficients[[cst] -> [a]] }",
10421 "{ rat: [i] : FALSE }" },
10424 /* Test the basic functionality of isl_basic_set_coefficients and
10425 * isl_basic_set_solutions.
10427 static int test_dual(isl_ctx *ctx)
10429 int i;
10431 for (i = 0; i < ARRAY_SIZE(coef_tests); ++i) {
10432 int equal;
10433 isl_basic_set *bset1, *bset2;
10435 bset1 = isl_basic_set_read_from_str(ctx, coef_tests[i].set);
10436 bset2 = isl_basic_set_read_from_str(ctx, coef_tests[i].dual);
10437 bset1 = isl_basic_set_coefficients(bset1);
10438 equal = isl_basic_set_is_equal(bset1, bset2);
10439 isl_basic_set_free(bset1);
10440 isl_basic_set_free(bset2);
10441 if (equal < 0)
10442 return -1;
10443 if (!equal)
10444 isl_die(ctx, isl_error_unknown,
10445 "incorrect dual", return -1);
10448 for (i = 0; i < ARRAY_SIZE(sol_tests); ++i) {
10449 int equal;
10450 isl_basic_set *bset1, *bset2;
10452 bset1 = isl_basic_set_read_from_str(ctx, sol_tests[i].set);
10453 bset2 = isl_basic_set_read_from_str(ctx, sol_tests[i].dual);
10454 bset1 = isl_basic_set_solutions(bset1);
10455 equal = isl_basic_set_is_equal(bset1, bset2);
10456 isl_basic_set_free(bset1);
10457 isl_basic_set_free(bset2);
10458 if (equal < 0)
10459 return -1;
10460 if (!equal)
10461 isl_die(ctx, isl_error_unknown,
10462 "incorrect dual", return -1);
10465 return 0;
10468 struct {
10469 int scale_tile;
10470 int shift_point;
10471 const char *domain;
10472 const char *schedule;
10473 const char *sizes;
10474 const char *tile;
10475 const char *point;
10476 } tile_tests[] = {
10477 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10478 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10479 "{ [32,32] }",
10480 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10481 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10483 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
10484 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10485 "{ [32,32] }",
10486 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10487 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10489 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10490 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10491 "{ [32,32] }",
10492 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
10493 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10495 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
10496 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
10497 "{ [32,32] }",
10498 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
10499 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
10503 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
10504 * tile the band and then check if the tile and point bands have the
10505 * expected partial schedule.
10507 static int test_tile(isl_ctx *ctx)
10509 int i;
10510 int scale;
10511 int shift;
10513 scale = isl_options_get_tile_scale_tile_loops(ctx);
10514 shift = isl_options_get_tile_shift_point_loops(ctx);
10516 for (i = 0; i < ARRAY_SIZE(tile_tests); ++i) {
10517 int opt;
10518 int equal;
10519 const char *str;
10520 isl_union_set *domain;
10521 isl_multi_union_pw_aff *mupa, *mupa2;
10522 isl_schedule_node *node;
10523 isl_multi_val *sizes;
10525 opt = tile_tests[i].scale_tile;
10526 isl_options_set_tile_scale_tile_loops(ctx, opt);
10527 opt = tile_tests[i].shift_point;
10528 isl_options_set_tile_shift_point_loops(ctx, opt);
10530 str = tile_tests[i].domain;
10531 domain = isl_union_set_read_from_str(ctx, str);
10532 node = isl_schedule_node_from_domain(domain);
10533 node = isl_schedule_node_child(node, 0);
10534 str = tile_tests[i].schedule;
10535 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10536 node = isl_schedule_node_insert_partial_schedule(node, mupa);
10537 str = tile_tests[i].sizes;
10538 sizes = isl_multi_val_read_from_str(ctx, str);
10539 node = isl_schedule_node_band_tile(node, sizes);
10541 str = tile_tests[i].tile;
10542 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10543 mupa2 = isl_schedule_node_band_get_partial_schedule(node);
10544 equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2);
10545 isl_multi_union_pw_aff_free(mupa);
10546 isl_multi_union_pw_aff_free(mupa2);
10548 node = isl_schedule_node_child(node, 0);
10550 str = tile_tests[i].point;
10551 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
10552 mupa2 = isl_schedule_node_band_get_partial_schedule(node);
10553 if (equal >= 0 && equal)
10554 equal = isl_multi_union_pw_aff_plain_is_equal(mupa,
10555 mupa2);
10556 isl_multi_union_pw_aff_free(mupa);
10557 isl_multi_union_pw_aff_free(mupa2);
10559 isl_schedule_node_free(node);
10561 if (equal < 0)
10562 return -1;
10563 if (!equal)
10564 isl_die(ctx, isl_error_unknown,
10565 "unexpected result", return -1);
10568 isl_options_set_tile_scale_tile_loops(ctx, scale);
10569 isl_options_set_tile_shift_point_loops(ctx, shift);
10571 return 0;
10574 /* Check that the domain hash of a space is equal to the hash
10575 * of the domain of the space.
10577 static int test_domain_hash(isl_ctx *ctx)
10579 isl_map *map;
10580 isl_space *space;
10581 uint32_t hash1, hash2;
10583 map = isl_map_read_from_str(ctx, "[n] -> { A[B[x] -> C[]] -> D[] }");
10584 space = isl_map_get_space(map);
10585 isl_map_free(map);
10586 hash1 = isl_space_get_full_domain_hash(space);
10587 space = isl_space_domain(space);
10588 hash2 = isl_space_get_full_hash(space);
10589 isl_space_free(space);
10591 if (!space)
10592 return -1;
10593 if (hash1 != hash2)
10594 isl_die(ctx, isl_error_unknown,
10595 "domain hash not equal to hash of domain", return -1);
10597 return 0;
10600 /* Check that a universe basic set that is not obviously equal to the universe
10601 * is still recognized as being equal to the universe.
10603 static int test_universe(isl_ctx *ctx)
10605 const char *s;
10606 isl_basic_set *bset;
10607 isl_bool is_univ;
10609 s = "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
10610 bset = isl_basic_set_read_from_str(ctx, s);
10611 is_univ = isl_basic_set_is_universe(bset);
10612 isl_basic_set_free(bset);
10614 if (is_univ < 0)
10615 return -1;
10616 if (!is_univ)
10617 isl_die(ctx, isl_error_unknown,
10618 "not recognized as universe set", return -1);
10620 return 0;
10623 /* Sets for which chambers are computed and checked.
10625 const char *chambers_tests[] = {
10626 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
10627 "z >= 0 and z <= C - y and z <= B - x - y }",
10630 /* Add the domain of "cell" to "cells".
10632 static isl_stat add_cell(__isl_take isl_cell *cell, void *user)
10634 isl_basic_set_list **cells = user;
10635 isl_basic_set *dom;
10637 dom = isl_cell_get_domain(cell);
10638 isl_cell_free(cell);
10639 *cells = isl_basic_set_list_add(*cells, dom);
10641 return *cells ? isl_stat_ok : isl_stat_error;
10644 /* Check that the elements of "list" are pairwise disjoint.
10646 static isl_stat check_pairwise_disjoint(__isl_keep isl_basic_set_list *list)
10648 int i, j;
10649 isl_size n;
10651 n = isl_basic_set_list_n_basic_set(list);
10652 if (n < 0)
10653 return isl_stat_error;
10655 for (i = 0; i < n; ++i) {
10656 isl_basic_set *bset_i;
10658 bset_i = isl_basic_set_list_get_basic_set(list, i);
10659 for (j = i + 1; j < n; ++j) {
10660 isl_basic_set *bset_j;
10661 isl_bool disjoint;
10663 bset_j = isl_basic_set_list_get_basic_set(list, j);
10664 disjoint = isl_basic_set_is_disjoint(bset_i, bset_j);
10665 isl_basic_set_free(bset_j);
10666 if (!disjoint)
10667 isl_die(isl_basic_set_list_get_ctx(list),
10668 isl_error_unknown, "not disjoint",
10669 break);
10670 if (disjoint < 0 || !disjoint)
10671 break;
10673 isl_basic_set_free(bset_i);
10674 if (j < n)
10675 return isl_stat_error;
10678 return isl_stat_ok;
10681 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
10682 * are pairwise disjoint.
10684 static int test_chambers(isl_ctx *ctx)
10686 int i;
10688 for (i = 0; i < ARRAY_SIZE(chambers_tests); ++i) {
10689 isl_basic_set *bset;
10690 isl_vertices *vertices;
10691 isl_basic_set_list *cells;
10692 isl_stat ok;
10694 bset = isl_basic_set_read_from_str(ctx, chambers_tests[i]);
10695 vertices = isl_basic_set_compute_vertices(bset);
10696 cells = isl_basic_set_list_alloc(ctx, 0);
10697 if (isl_vertices_foreach_disjoint_cell(vertices, &add_cell,
10698 &cells) < 0)
10699 cells = isl_basic_set_list_free(cells);
10700 ok = check_pairwise_disjoint(cells);
10701 isl_basic_set_list_free(cells);
10702 isl_vertices_free(vertices);
10703 isl_basic_set_free(bset);
10705 if (ok < 0)
10706 return -1;
10709 return 0;
10712 struct {
10713 const char *name;
10714 int (*fn)(isl_ctx *ctx);
10715 } tests [] = {
10716 { "universe", &test_universe },
10717 { "domain hash", &test_domain_hash },
10718 { "dual", &test_dual },
10719 { "dependence analysis", &test_flow },
10720 { "val", &test_val },
10721 { "compute divs", &test_compute_divs },
10722 { "partial lexmin", &test_partial_lexmin },
10723 { "simplify", &test_simplify },
10724 { "curry", &test_curry },
10725 { "piecewise multi affine expressions", &test_pw_multi_aff },
10726 { "multi piecewise affine expressions", &test_multi_pw_aff },
10727 { "conversion", &test_conversion },
10728 { "list", &test_list },
10729 { "align parameters", &test_align_parameters },
10730 { "drop unused parameters", &test_drop_unused_parameters },
10731 { "preimage", &test_preimage },
10732 { "pullback", &test_pullback },
10733 { "AST", &test_ast },
10734 { "AST build", &test_ast_build },
10735 { "AST generation", &test_ast_gen },
10736 { "eliminate", &test_eliminate },
10737 { "deltas_map", &test_deltas_map },
10738 { "residue class", &test_residue_class },
10739 { "div", &test_div },
10740 { "slice", &test_slice },
10741 { "fixed power", &test_fixed_power },
10742 { "sample", &test_sample },
10743 { "output", &test_output },
10744 { "vertices", &test_vertices },
10745 { "chambers", &test_chambers },
10746 { "fixed", &test_fixed },
10747 { "equal", &test_equal },
10748 { "disjoint", &test_disjoint },
10749 { "product", &test_product },
10750 { "dim_max", &test_dim_max },
10751 { "affine", &test_aff },
10752 { "injective", &test_injective },
10753 { "schedule (whole component)", &test_schedule_whole },
10754 { "schedule (incremental)", &test_schedule_incremental },
10755 { "schedule tree", &test_schedule_tree },
10756 { "schedule tree prefix", &test_schedule_tree_prefix },
10757 { "schedule tree grouping", &test_schedule_tree_group },
10758 { "tile", &test_tile },
10759 { "union map", &test_union_map },
10760 { "union_pw", &test_union_pw },
10761 { "locus", &test_locus },
10762 { "eval", &test_eval },
10763 { "parse", &test_parse },
10764 { "single-valued", &test_sv },
10765 { "recession cone", &test_recession_cone },
10766 { "affine hull", &test_affine_hull },
10767 { "simple_hull", &test_simple_hull },
10768 { "box hull", &test_box_hull },
10769 { "coalesce", &test_coalesce },
10770 { "factorize", &test_factorize },
10771 { "subset", &test_subset },
10772 { "subtract", &test_subtract },
10773 { "intersect", &test_intersect },
10774 { "lexmin", &test_lexmin },
10775 { "min", &test_min },
10776 { "gist", &test_gist },
10777 { "piecewise quasi-polynomials", &test_pwqp },
10778 { "lift", &test_lift },
10779 { "bind parameters", &test_bind },
10780 { "unbind parameters", &test_unbind },
10781 { "bound", &test_bound },
10782 { "get lists", &test_get_list },
10783 { "union", &test_union },
10784 { "split periods", &test_split_periods },
10785 { "lexicographic order", &test_lex },
10786 { "bijectivity", &test_bijective },
10787 { "dataflow analysis", &test_dep },
10788 { "reading", &test_read },
10789 { "bounded", &test_bounded },
10790 { "construction", &test_construction },
10791 { "dimension manipulation", &test_dim },
10792 { "map application", &test_application },
10793 { "convex hull", &test_convex_hull },
10794 { "transitive closure", &test_closure },
10795 { "isl_bool", &test_isl_bool},
10798 int main(int argc, char **argv)
10800 int i;
10801 struct isl_ctx *ctx;
10802 struct isl_options *options;
10804 options = isl_options_new_with_defaults();
10805 assert(options);
10806 argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL);
10808 ctx = isl_ctx_alloc_with_options(&isl_options_args, options);
10809 for (i = 0; i < ARRAY_SIZE(tests); ++i) {
10810 printf("%s\n", tests[i].name);
10811 if (tests[i].fn(ctx) < 0)
10812 goto error;
10814 isl_ctx_free(ctx);
10815 return 0;
10816 error:
10817 isl_ctx_free(ctx);
10818 return -1;