isl_aff.c: isolate include defining isl_multi_aff_gist
[isl.git] / isl_test.c
blob53cc2efd5a196639f3962c02b1339993ae1f9ce8
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 #undef BASE
124 #define BASE multi_pw_aff
126 #include "check_reparse_templ.c"
128 #undef BASE
129 #define BASE pw_multi_aff
131 #include "check_reparse_templ.c"
133 /* Test parsing of piecewise multi affine expressions by printing
134 * the expressions and checking that parsing the output results
135 * in the same expression.
136 * Do this for an expression converted from a map with an output
137 * dimension name that is equal to an automatically generated name.
139 static isl_stat test_parse_pma(isl_ctx *ctx)
141 isl_map *map;
142 isl_pw_multi_aff *pma;
144 map = isl_map_read_from_str(ctx, "{ [a, a] -> [i1 = a + 1] }");
145 pma = isl_pw_multi_aff_from_map(map);
146 if (check_reparse_pw_multi_aff(ctx, pma) < 0)
147 return isl_stat_error;
149 return isl_stat_ok;
152 /* String descriptions of multi piecewise affine expressions
153 * that are used for testing printing and parsing.
155 const char *parse_multi_mpa_tests[] = {
156 "{ A[x, y] -> [] : x + y >= 0 }",
157 "{ A[x, y] -> B[] : x + y >= 0 }",
158 "{ A[x, y] -> [x] : x + y >= 0 }",
159 "[N] -> { A[x, y] -> [x] : x + y <= N }",
160 "{ A[x, y] -> [x, y] : x + y >= 0 }",
161 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
162 "[N] -> { [] : N >= 0 }",
163 "[N] -> { [] : N >= 0 }",
164 "[N] -> { [N] : N >= 0 }",
165 "[N] -> { [N, N + 1] : N >= 0 }",
166 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
169 /* Test parsing of multi piecewise affine expressions by printing
170 * the expressions and checking that parsing the output results
171 * in the same expression.
172 * Do this for a couple of manually constructed expressions,
173 * an expression converted from a map with an output dimension name
174 * that is equal to an automatically generated name, and
175 * a set of expressions parsed from strings.
177 static int test_parse_mpa(isl_ctx *ctx)
179 int i;
180 isl_space *space;
181 isl_set *dom;
182 isl_map *map;
183 isl_pw_multi_aff *pma;
184 isl_multi_pw_aff *mpa;
185 isl_stat r;
187 space = isl_space_set_alloc(ctx, 0, 0);
188 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
189 mpa = isl_multi_pw_aff_zero(space);
190 r = check_reparse_multi_pw_aff(ctx, mpa);
191 if (r < 0)
192 return -1;
194 space = isl_space_set_alloc(ctx, 1, 0);
195 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
196 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
197 dom = isl_set_universe(isl_space_params(isl_space_copy(space)));
198 dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5);
199 mpa = isl_multi_pw_aff_zero(space);
200 mpa = isl_multi_pw_aff_intersect_domain(mpa, dom);
201 r = check_reparse_multi_pw_aff(ctx, mpa);
202 if (r < 0)
203 return -1;
205 map = isl_map_read_from_str(ctx, "{ [a, a] -> [i1 = a + 1] }");
206 pma = isl_pw_multi_aff_from_map(map);
207 mpa = isl_multi_pw_aff_from_pw_multi_aff(pma);
208 if (check_reparse_multi_pw_aff(ctx, mpa) < 0)
209 return -1;
211 for (i = 0; i < ARRAY_SIZE(parse_multi_mpa_tests); ++i) {
212 const char *str;
214 str = parse_multi_mpa_tests[i];
215 mpa = isl_multi_pw_aff_read_from_str(ctx, str);
216 r = check_reparse_multi_pw_aff(ctx, mpa);
217 if (r < 0)
218 return -1;
221 return 0;
225 #undef BASE
226 #define BASE multi_union_pw_aff
228 #include "check_reparse_templ.c"
230 /* String descriptions of multi union piecewise affine expressions
231 * that are used for testing printing and parsing.
233 const char *parse_multi_mupa_tests[] = {
234 "[]",
235 "A[]",
236 "A[B[] -> C[]]",
237 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
238 "(A[] : { })",
239 "[N] -> (A[] : { })",
240 "[N] -> (A[] : { : N >= 0 })",
241 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
242 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
243 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
244 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
245 "{ S[x] : x > 0; T[y] : y >= 0 })",
248 /* Test parsing of multi union piecewise affine expressions by printing
249 * the expressions and checking that parsing the output results
250 * in the same expression.
251 * Do this for a couple of manually constructed expressions and
252 * a set of expressions parsed from strings.
254 static int test_parse_mupa(isl_ctx *ctx)
256 int i;
257 isl_space *space;
258 isl_multi_union_pw_aff *mupa;
259 isl_set *dom;
260 isl_union_set *uset;
261 isl_stat r;
263 space = isl_space_set_alloc(ctx, 0, 0);
264 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
265 mupa = isl_multi_union_pw_aff_zero(space);
266 r = check_reparse_multi_union_pw_aff(ctx, mupa);
267 if (r < 0)
268 return -1;
270 space = isl_space_set_alloc(ctx, 1, 0);
271 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
272 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
273 dom = isl_set_universe(space);
274 dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5);
275 uset = isl_union_set_from_set(dom);
276 space = isl_space_set_alloc(ctx, 1, 0);
277 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
278 space = isl_space_set_tuple_name(space, isl_dim_set, "B");
279 mupa = isl_multi_union_pw_aff_zero(space);
280 mupa = isl_multi_union_pw_aff_intersect_domain(mupa, uset);
281 r = check_reparse_multi_union_pw_aff(ctx, mupa);
282 if (r < 0)
283 return -1;
285 for (i = 0; i < ARRAY_SIZE(parse_multi_mupa_tests); ++i) {
286 const char *str;
288 str = parse_multi_mupa_tests[i];
289 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
290 r = check_reparse_multi_union_pw_aff(ctx, mupa);
291 if (r < 0)
292 return -1;
295 return 0;
298 /* Test parsing of multi expressions.
300 static int test_parse_multi(isl_ctx *ctx)
302 if (test_parse_mpa(ctx) < 0)
303 return -1;
304 if (test_parse_mupa(ctx) < 0)
305 return -1;
307 return 0;
310 /* Pairs of binary relation representations that should represent
311 * the same binary relations.
313 struct {
314 const char *map1;
315 const char *map2;
316 } parse_map_equal_tests[] = {
317 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
318 "{ [x, y] : 2y >= 6 - x }" },
319 { "{ [x,y] : x <= min(y, 2*y+3) }",
320 "{ [x,y] : x <= y, 2*y + 3 }" },
321 { "{ [x,y] : x >= min(y, 2*y+3) }",
322 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
323 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
324 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
325 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
326 "{ [i,j] -> [min(i,j)] }" },
327 { "{ [i,j] : i != j }",
328 "{ [i,j] : i < j or i > j }" },
329 { "{ [i,j] : (i+1)*2 >= j }",
330 "{ [i, j] : j <= 2 + 2i }" },
331 { "{ [i] -> [i > 0 ? 4 : 5] }",
332 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
333 { "[N=2,M] -> { [i=[(M+N)/4]] }",
334 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
335 { "{ [x] : x >= 0 }",
336 "{ [x] : x-0 >= 0 }" },
337 { "{ [i] : ((i > 10)) }",
338 "{ [i] : i >= 11 }" },
339 { "{ [i] -> [0] }",
340 "{ [i] -> [0 * i] }" },
341 { "{ [a] -> [b] : (not false) }",
342 "{ [a] -> [b] : true }" },
343 { "{ [i] : i/2 <= 5 }",
344 "{ [i] : i <= 10 }" },
345 { "{Sym=[n] [i] : i <= n }",
346 "[n] -> { [i] : i <= n }" },
347 { "{ [*] }",
348 "{ [a] }" },
349 { "{ [i] : 2*floor(i/2) = i }",
350 "{ [i] : exists a : i = 2 a }" },
351 { "{ [a] -> [b] : a = 5 implies b = 5 }",
352 "{ [a] -> [b] : a != 5 or b = 5 }" },
353 { "{ [a] -> [a - 1 : a > 0] }",
354 "{ [a] -> [a - 1] : a > 0 }" },
355 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
356 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
357 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
358 "{ [a] -> [2a] : a >= 0; [a] -> [0] : 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,b] -> [i,j] : a,b << i,j }",
366 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
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 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
374 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
375 "8c < n - 32a and i < n and c >= 0 and "
376 "c <= 3 and c >= -4a) }",
377 "{ [n] -> [i] : 0 <= i < n }" },
378 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
379 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
380 "{ [x] -> [] : 0 <= x <= 15 }" },
381 { "{ [x] -> [x] : }",
382 "{ [x] -> [x] }" },
385 int test_parse(struct isl_ctx *ctx)
387 int i;
388 isl_map *map, *map2;
389 const char *str, *str2;
391 if (test_parse_multi_val(ctx, "{ A[B[2] -> C[5, 7]] }") < 0)
392 return -1;
393 if (test_parse_multi_val(ctx, "[n] -> { [2] }") < 0)
394 return -1;
395 if (test_parse_multi_val(ctx, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
396 return -1;
397 if (test_parse_multi(ctx) < 0)
398 return -1;
399 if (test_parse_pma(ctx) < 0)
400 return -1;
402 str = "{ [i] -> [-i] }";
403 map = isl_map_read_from_str(ctx, str);
404 assert(map);
405 isl_map_free(map);
407 str = "{ A[i] -> L[([i/3])] }";
408 map = isl_map_read_from_str(ctx, str);
409 assert(map);
410 isl_map_free(map);
412 test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
413 test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : "
414 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
416 for (i = 0; i < ARRAY_SIZE(parse_map_equal_tests); ++i) {
417 str = parse_map_equal_tests[i].map1;
418 str2 = parse_map_equal_tests[i].map2;
419 if (test_parse_map_equal(ctx, str, str2) < 0)
420 return -1;
423 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
424 map = isl_map_read_from_str(ctx, str);
425 str = "{ [new, old] -> [o0, o1] : "
426 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
427 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
428 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
429 map2 = isl_map_read_from_str(ctx, str);
430 assert(isl_map_is_equal(map, map2));
431 isl_map_free(map);
432 isl_map_free(map2);
434 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
435 map = isl_map_read_from_str(ctx, str);
436 str = "{[new,old] -> [(new+1)%2,(old+1)%2]}";
437 map2 = isl_map_read_from_str(ctx, str);
438 assert(isl_map_is_equal(map, map2));
439 isl_map_free(map);
440 isl_map_free(map2);
442 test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
443 test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
444 test_parse_pwaff(ctx, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
445 test_parse_pwqp(ctx, "{ [x] -> ([(x)/2] * [(x)/3]) }");
446 test_parse_pwaff(ctx, "{ [] -> [(100)] }");
448 return 0;
451 static int test_read(isl_ctx *ctx)
453 char *filename;
454 FILE *input;
455 isl_basic_set *bset1, *bset2;
456 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
457 int equal;
459 filename = get_filename(ctx, "set", "omega");
460 assert(filename);
461 input = fopen(filename, "r");
462 assert(input);
464 bset1 = isl_basic_set_read_from_file(ctx, input);
465 bset2 = isl_basic_set_read_from_str(ctx, str);
467 equal = isl_basic_set_is_equal(bset1, bset2);
469 isl_basic_set_free(bset1);
470 isl_basic_set_free(bset2);
471 free(filename);
473 fclose(input);
475 if (equal < 0)
476 return -1;
477 if (!equal)
478 isl_die(ctx, isl_error_unknown,
479 "read sets not equal", return -1);
481 return 0;
484 static int test_bounded(isl_ctx *ctx)
486 isl_set *set;
487 isl_bool bounded;
489 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }");
490 bounded = isl_set_is_bounded(set);
491 isl_set_free(set);
493 if (bounded < 0)
494 return -1;
495 if (!bounded)
496 isl_die(ctx, isl_error_unknown,
497 "set not considered bounded", return -1);
499 set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }");
500 bounded = isl_set_is_bounded(set);
501 assert(!bounded);
502 isl_set_free(set);
504 if (bounded < 0)
505 return -1;
506 if (bounded)
507 isl_die(ctx, isl_error_unknown,
508 "set considered bounded", return -1);
510 set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }");
511 bounded = isl_set_is_bounded(set);
512 isl_set_free(set);
514 if (bounded < 0)
515 return -1;
516 if (bounded)
517 isl_die(ctx, isl_error_unknown,
518 "set considered bounded", return -1);
520 return 0;
523 /* Construct the basic set { [i] : 5 <= i <= N } */
524 static int test_construction_1(isl_ctx *ctx)
526 isl_space *dim;
527 isl_local_space *ls;
528 isl_basic_set *bset;
529 isl_constraint *c;
531 dim = isl_space_set_alloc(ctx, 1, 1);
532 bset = isl_basic_set_universe(isl_space_copy(dim));
533 ls = isl_local_space_from_space(dim);
535 c = isl_constraint_alloc_inequality(isl_local_space_copy(ls));
536 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
537 c = isl_constraint_set_coefficient_si(c, isl_dim_param, 0, 1);
538 bset = isl_basic_set_add_constraint(bset, c);
540 c = isl_constraint_alloc_inequality(isl_local_space_copy(ls));
541 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
542 c = isl_constraint_set_constant_si(c, -5);
543 bset = isl_basic_set_add_constraint(bset, c);
545 isl_local_space_free(ls);
546 isl_basic_set_free(bset);
548 return 0;
551 /* Construct the basic set { [x] : -100 <= x <= 100 }
552 * using isl_basic_set_{lower,upper}_bound_val and
553 * check that it is equal the same basic set parsed from a string.
555 static int test_construction_2(isl_ctx *ctx)
557 isl_bool equal;
558 isl_val *v;
559 isl_space *space;
560 isl_basic_set *bset1, *bset2;
562 v = isl_val_int_from_si(ctx, 100);
563 space = isl_space_set_alloc(ctx, 0, 1);
564 bset1 = isl_basic_set_universe(space);
565 bset1 = isl_basic_set_upper_bound_val(bset1, isl_dim_set, 0,
566 isl_val_copy(v));
567 bset1 = isl_basic_set_lower_bound_val(bset1, isl_dim_set, 0,
568 isl_val_neg(v));
569 bset2 = isl_basic_set_read_from_str(ctx, "{ [x] : -100 <= x <= 100 }");
570 equal = isl_basic_set_is_equal(bset1, bset2);
571 isl_basic_set_free(bset1);
572 isl_basic_set_free(bset2);
574 if (equal < 0)
575 return -1;
576 if (!equal)
577 isl_die(ctx, isl_error_unknown,
578 "failed construction", return -1);
580 return 0;
583 /* Basic tests for constructing basic sets.
585 static int test_construction(isl_ctx *ctx)
587 if (test_construction_1(ctx) < 0)
588 return -1;
589 if (test_construction_2(ctx) < 0)
590 return -1;
591 return 0;
594 static int test_dim(isl_ctx *ctx)
596 const char *str;
597 isl_map *map1, *map2;
598 int equal;
600 map1 = isl_map_read_from_str(ctx,
601 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
602 map1 = isl_map_add_dims(map1, isl_dim_in, 1);
603 map2 = isl_map_read_from_str(ctx,
604 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
605 equal = isl_map_is_equal(map1, map2);
606 isl_map_free(map2);
608 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
609 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }");
610 if (equal >= 0 && equal)
611 equal = isl_map_is_equal(map1, map2);
613 isl_map_free(map1);
614 isl_map_free(map2);
616 if (equal < 0)
617 return -1;
618 if (!equal)
619 isl_die(ctx, isl_error_unknown,
620 "unexpected result", return -1);
622 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
623 map1 = isl_map_read_from_str(ctx, str);
624 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
625 map2 = isl_map_read_from_str(ctx, str);
626 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
627 equal = isl_map_is_equal(map1, map2);
628 isl_map_free(map1);
629 isl_map_free(map2);
631 if (equal < 0)
632 return -1;
633 if (!equal)
634 isl_die(ctx, isl_error_unknown,
635 "unexpected result", return -1);
637 return 0;
640 /* Check that "val" is equal to the value described by "str".
641 * If "str" is "NaN", then check for a NaN value explicitly.
643 static isl_stat val_check_equal(__isl_keep isl_val *val, const char *str)
645 isl_bool ok, is_nan;
646 isl_ctx *ctx;
647 isl_val *res;
649 if (!val)
650 return isl_stat_error;
652 ctx = isl_val_get_ctx(val);
653 res = isl_val_read_from_str(ctx, str);
654 is_nan = isl_val_is_nan(res);
655 if (is_nan < 0)
656 ok = isl_bool_error;
657 else if (is_nan)
658 ok = isl_val_is_nan(val);
659 else
660 ok = isl_val_eq(val, res);
661 isl_val_free(res);
662 if (ok < 0)
663 return isl_stat_error;
664 if (!ok)
665 isl_die(ctx, isl_error_unknown,
666 "unexpected result", return isl_stat_error);
667 return isl_stat_ok;
670 struct {
671 __isl_give isl_val *(*op)(__isl_take isl_val *v);
672 const char *arg;
673 const char *res;
674 } val_un_tests[] = {
675 { &isl_val_neg, "0", "0" },
676 { &isl_val_abs, "0", "0" },
677 { &isl_val_pow2, "0", "1" },
678 { &isl_val_floor, "0", "0" },
679 { &isl_val_ceil, "0", "0" },
680 { &isl_val_neg, "1", "-1" },
681 { &isl_val_neg, "-1", "1" },
682 { &isl_val_neg, "1/2", "-1/2" },
683 { &isl_val_neg, "-1/2", "1/2" },
684 { &isl_val_neg, "infty", "-infty" },
685 { &isl_val_neg, "-infty", "infty" },
686 { &isl_val_neg, "NaN", "NaN" },
687 { &isl_val_abs, "1", "1" },
688 { &isl_val_abs, "-1", "1" },
689 { &isl_val_abs, "1/2", "1/2" },
690 { &isl_val_abs, "-1/2", "1/2" },
691 { &isl_val_abs, "infty", "infty" },
692 { &isl_val_abs, "-infty", "infty" },
693 { &isl_val_abs, "NaN", "NaN" },
694 { &isl_val_floor, "1", "1" },
695 { &isl_val_floor, "-1", "-1" },
696 { &isl_val_floor, "1/2", "0" },
697 { &isl_val_floor, "-1/2", "-1" },
698 { &isl_val_floor, "infty", "infty" },
699 { &isl_val_floor, "-infty", "-infty" },
700 { &isl_val_floor, "NaN", "NaN" },
701 { &isl_val_ceil, "1", "1" },
702 { &isl_val_ceil, "-1", "-1" },
703 { &isl_val_ceil, "1/2", "1" },
704 { &isl_val_ceil, "-1/2", "0" },
705 { &isl_val_ceil, "infty", "infty" },
706 { &isl_val_ceil, "-infty", "-infty" },
707 { &isl_val_ceil, "NaN", "NaN" },
708 { &isl_val_pow2, "-3", "1/8" },
709 { &isl_val_pow2, "-1", "1/2" },
710 { &isl_val_pow2, "1", "2" },
711 { &isl_val_pow2, "2", "4" },
712 { &isl_val_pow2, "3", "8" },
713 { &isl_val_inv, "1", "1" },
714 { &isl_val_inv, "2", "1/2" },
715 { &isl_val_inv, "1/2", "2" },
716 { &isl_val_inv, "-2", "-1/2" },
717 { &isl_val_inv, "-1/2", "-2" },
718 { &isl_val_inv, "0", "NaN" },
719 { &isl_val_inv, "NaN", "NaN" },
720 { &isl_val_inv, "infty", "0" },
721 { &isl_val_inv, "-infty", "0" },
724 /* Perform some basic tests of unary operations on isl_val objects.
726 static int test_un_val(isl_ctx *ctx)
728 int i;
729 isl_val *v;
730 __isl_give isl_val *(*fn)(__isl_take isl_val *v);
732 for (i = 0; i < ARRAY_SIZE(val_un_tests); ++i) {
733 isl_stat r;
735 v = isl_val_read_from_str(ctx, val_un_tests[i].arg);
736 fn = val_un_tests[i].op;
737 v = fn(v);
738 r = val_check_equal(v, val_un_tests[i].res);
739 isl_val_free(v);
740 if (r < 0)
741 return -1;
744 return 0;
747 struct {
748 __isl_give isl_val *(*fn)(__isl_take isl_val *v1,
749 __isl_take isl_val *v2);
750 } val_bin_op[] = {
751 ['+'] = { &isl_val_add },
752 ['-'] = { &isl_val_sub },
753 ['*'] = { &isl_val_mul },
754 ['/'] = { &isl_val_div },
755 ['g'] = { &isl_val_gcd },
756 ['m'] = { &isl_val_min },
757 ['M'] = { &isl_val_max },
760 struct {
761 const char *arg1;
762 unsigned char op;
763 const char *arg2;
764 const char *res;
765 } val_bin_tests[] = {
766 { "0", '+', "0", "0" },
767 { "1", '+', "0", "1" },
768 { "1", '+', "1", "2" },
769 { "1", '-', "1", "0" },
770 { "1", '*', "1", "1" },
771 { "1", '/', "1", "1" },
772 { "2", '*', "3", "6" },
773 { "2", '*', "1/2", "1" },
774 { "2", '*', "1/3", "2/3" },
775 { "2/3", '*', "3/5", "2/5" },
776 { "2/3", '*', "7/5", "14/15" },
777 { "2", '/', "1/2", "4" },
778 { "-2", '/', "-1/2", "4" },
779 { "-2", '/', "1/2", "-4" },
780 { "2", '/', "-1/2", "-4" },
781 { "2", '/', "2", "1" },
782 { "2", '/', "3", "2/3" },
783 { "2/3", '/', "5/3", "2/5" },
784 { "2/3", '/', "5/7", "14/15" },
785 { "0", '/', "0", "NaN" },
786 { "42", '/', "0", "NaN" },
787 { "-42", '/', "0", "NaN" },
788 { "infty", '/', "0", "NaN" },
789 { "-infty", '/', "0", "NaN" },
790 { "NaN", '/', "0", "NaN" },
791 { "0", '/', "NaN", "NaN" },
792 { "42", '/', "NaN", "NaN" },
793 { "-42", '/', "NaN", "NaN" },
794 { "infty", '/', "NaN", "NaN" },
795 { "-infty", '/', "NaN", "NaN" },
796 { "NaN", '/', "NaN", "NaN" },
797 { "0", '/', "infty", "0" },
798 { "42", '/', "infty", "0" },
799 { "-42", '/', "infty", "0" },
800 { "infty", '/', "infty", "NaN" },
801 { "-infty", '/', "infty", "NaN" },
802 { "NaN", '/', "infty", "NaN" },
803 { "0", '/', "-infty", "0" },
804 { "42", '/', "-infty", "0" },
805 { "-42", '/', "-infty", "0" },
806 { "infty", '/', "-infty", "NaN" },
807 { "-infty", '/', "-infty", "NaN" },
808 { "NaN", '/', "-infty", "NaN" },
809 { "1", '-', "1/3", "2/3" },
810 { "1/3", '+', "1/2", "5/6" },
811 { "1/2", '+', "1/2", "1" },
812 { "3/4", '-', "1/4", "1/2" },
813 { "1/2", '-', "1/3", "1/6" },
814 { "infty", '+', "42", "infty" },
815 { "infty", '+', "infty", "infty" },
816 { "42", '+', "infty", "infty" },
817 { "infty", '-', "infty", "NaN" },
818 { "infty", '*', "infty", "infty" },
819 { "infty", '*', "-infty", "-infty" },
820 { "-infty", '*', "infty", "-infty" },
821 { "-infty", '*', "-infty", "infty" },
822 { "0", '*', "infty", "NaN" },
823 { "1", '*', "infty", "infty" },
824 { "infty", '*', "0", "NaN" },
825 { "infty", '*', "42", "infty" },
826 { "42", '-', "infty", "-infty" },
827 { "infty", '+', "-infty", "NaN" },
828 { "4", 'g', "6", "2" },
829 { "5", 'g', "6", "1" },
830 { "42", 'm', "3", "3" },
831 { "42", 'M', "3", "42" },
832 { "3", 'm', "42", "3" },
833 { "3", 'M', "42", "42" },
834 { "42", 'm', "infty", "42" },
835 { "42", 'M', "infty", "infty" },
836 { "42", 'm', "-infty", "-infty" },
837 { "42", 'M', "-infty", "42" },
838 { "42", 'm', "NaN", "NaN" },
839 { "42", 'M', "NaN", "NaN" },
840 { "infty", 'm', "-infty", "-infty" },
841 { "infty", 'M', "-infty", "infty" },
844 /* Perform some basic tests of binary operations on isl_val objects.
846 static int test_bin_val(isl_ctx *ctx)
848 int i;
849 isl_val *v1, *v2, *res;
850 __isl_give isl_val *(*fn)(__isl_take isl_val *v1,
851 __isl_take isl_val *v2);
852 int ok;
854 for (i = 0; i < ARRAY_SIZE(val_bin_tests); ++i) {
855 v1 = isl_val_read_from_str(ctx, val_bin_tests[i].arg1);
856 v2 = isl_val_read_from_str(ctx, val_bin_tests[i].arg2);
857 res = isl_val_read_from_str(ctx, val_bin_tests[i].res);
858 fn = val_bin_op[val_bin_tests[i].op].fn;
859 v1 = fn(v1, v2);
860 if (isl_val_is_nan(res))
861 ok = isl_val_is_nan(v1);
862 else
863 ok = isl_val_eq(v1, res);
864 isl_val_free(v1);
865 isl_val_free(res);
866 if (ok < 0)
867 return -1;
868 if (!ok)
869 isl_die(ctx, isl_error_unknown,
870 "unexpected result", return -1);
873 return 0;
876 /* Perform some basic tests on isl_val objects.
878 static int test_val(isl_ctx *ctx)
880 if (test_un_val(ctx) < 0)
881 return -1;
882 if (test_bin_val(ctx) < 0)
883 return -1;
884 return 0;
887 /* Sets described using existentially quantified variables that
888 * can also be described without.
890 static const char *elimination_tests[] = {
891 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
892 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
893 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
896 /* Check that redundant existentially quantified variables are
897 * getting removed.
899 static int test_elimination(isl_ctx *ctx)
901 int i;
902 isl_size n;
903 isl_basic_set *bset;
905 for (i = 0; i < ARRAY_SIZE(elimination_tests); ++i) {
906 bset = isl_basic_set_read_from_str(ctx, elimination_tests[i]);
907 n = isl_basic_set_dim(bset, isl_dim_div);
908 isl_basic_set_free(bset);
909 if (n < 0)
910 return -1;
911 if (n != 0)
912 isl_die(ctx, isl_error_unknown,
913 "expecting no existentials", return -1);
916 return 0;
919 static int test_div(isl_ctx *ctx)
921 const char *str;
922 int empty;
923 isl_space *dim;
924 isl_set *set;
925 isl_local_space *ls;
926 struct isl_basic_set *bset;
927 struct isl_constraint *c;
929 /* test 1 */
930 dim = isl_space_set_alloc(ctx, 0, 3);
931 bset = isl_basic_set_universe(isl_space_copy(dim));
932 ls = isl_local_space_from_space(dim);
934 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
935 c = isl_constraint_set_constant_si(c, -1);
936 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
937 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
938 bset = isl_basic_set_add_constraint(bset, c);
940 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
941 c = isl_constraint_set_constant_si(c, 1);
942 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
943 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3);
944 bset = isl_basic_set_add_constraint(bset, c);
946 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
948 assert(bset && bset->n_div == 1);
949 isl_local_space_free(ls);
950 isl_basic_set_free(bset);
952 /* test 2 */
953 dim = isl_space_set_alloc(ctx, 0, 3);
954 bset = isl_basic_set_universe(isl_space_copy(dim));
955 ls = isl_local_space_from_space(dim);
957 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
958 c = isl_constraint_set_constant_si(c, 1);
959 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
960 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
961 bset = isl_basic_set_add_constraint(bset, c);
963 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
964 c = isl_constraint_set_constant_si(c, -1);
965 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
966 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3);
967 bset = isl_basic_set_add_constraint(bset, c);
969 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
971 assert(bset && bset->n_div == 1);
972 isl_local_space_free(ls);
973 isl_basic_set_free(bset);
975 /* test 3 */
976 dim = isl_space_set_alloc(ctx, 0, 3);
977 bset = isl_basic_set_universe(isl_space_copy(dim));
978 ls = isl_local_space_from_space(dim);
980 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
981 c = isl_constraint_set_constant_si(c, 1);
982 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
983 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
984 bset = isl_basic_set_add_constraint(bset, c);
986 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
987 c = isl_constraint_set_constant_si(c, -3);
988 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
989 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 4);
990 bset = isl_basic_set_add_constraint(bset, c);
992 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
994 assert(bset && bset->n_div == 1);
995 isl_local_space_free(ls);
996 isl_basic_set_free(bset);
998 /* test 4 */
999 dim = isl_space_set_alloc(ctx, 0, 3);
1000 bset = isl_basic_set_universe(isl_space_copy(dim));
1001 ls = isl_local_space_from_space(dim);
1003 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1004 c = isl_constraint_set_constant_si(c, 2);
1005 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1006 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
1007 bset = isl_basic_set_add_constraint(bset, c);
1009 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1010 c = isl_constraint_set_constant_si(c, -1);
1011 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1012 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 6);
1013 bset = isl_basic_set_add_constraint(bset, c);
1015 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
1017 assert(isl_basic_set_is_empty(bset));
1018 isl_local_space_free(ls);
1019 isl_basic_set_free(bset);
1021 /* test 5 */
1022 dim = isl_space_set_alloc(ctx, 0, 3);
1023 bset = isl_basic_set_universe(isl_space_copy(dim));
1024 ls = isl_local_space_from_space(dim);
1026 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1027 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1028 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3);
1029 bset = isl_basic_set_add_constraint(bset, c);
1031 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1032 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1033 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1034 bset = isl_basic_set_add_constraint(bset, c);
1036 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
1038 assert(bset && bset->n_div == 0);
1039 isl_basic_set_free(bset);
1040 isl_local_space_free(ls);
1042 /* test 6 */
1043 dim = isl_space_set_alloc(ctx, 0, 3);
1044 bset = isl_basic_set_universe(isl_space_copy(dim));
1045 ls = isl_local_space_from_space(dim);
1047 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1048 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1049 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 6);
1050 bset = isl_basic_set_add_constraint(bset, c);
1052 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1053 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1054 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1055 bset = isl_basic_set_add_constraint(bset, c);
1057 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
1059 assert(bset && bset->n_div == 1);
1060 isl_basic_set_free(bset);
1061 isl_local_space_free(ls);
1063 /* test 7 */
1064 /* This test is a bit tricky. We set up an equality
1065 * a + 3b + 3c = 6 e0
1066 * Normalization of divs creates _two_ divs
1067 * a = 3 e0
1068 * c - b - e0 = 2 e1
1069 * Afterwards e0 is removed again because it has coefficient -1
1070 * and we end up with the original equality and div again.
1071 * Perhaps we can avoid the introduction of this temporary div.
1073 dim = isl_space_set_alloc(ctx, 0, 4);
1074 bset = isl_basic_set_universe(isl_space_copy(dim));
1075 ls = isl_local_space_from_space(dim);
1077 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1078 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1079 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1080 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -3);
1081 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, 6);
1082 bset = isl_basic_set_add_constraint(bset, c);
1084 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
1086 /* Test disabled for now */
1088 assert(bset && bset->n_div == 1);
1090 isl_local_space_free(ls);
1091 isl_basic_set_free(bset);
1093 /* test 8 */
1094 dim = isl_space_set_alloc(ctx, 0, 5);
1095 bset = isl_basic_set_universe(isl_space_copy(dim));
1096 ls = isl_local_space_from_space(dim);
1098 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1099 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1100 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1101 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, -3);
1102 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 4, 6);
1103 bset = isl_basic_set_add_constraint(bset, c);
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, 2, 1);
1108 c = isl_constraint_set_constant_si(c, 1);
1109 bset = isl_basic_set_add_constraint(bset, c);
1111 bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1);
1113 /* Test disabled for now */
1115 assert(bset && bset->n_div == 1);
1117 isl_local_space_free(ls);
1118 isl_basic_set_free(bset);
1120 /* test 9 */
1121 dim = isl_space_set_alloc(ctx, 0, 4);
1122 bset = isl_basic_set_universe(isl_space_copy(dim));
1123 ls = isl_local_space_from_space(dim);
1125 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1126 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1127 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -1);
1128 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -2);
1129 bset = isl_basic_set_add_constraint(bset, c);
1131 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1132 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1133 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, 3);
1134 c = isl_constraint_set_constant_si(c, 2);
1135 bset = isl_basic_set_add_constraint(bset, c);
1137 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2);
1139 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
1141 assert(!isl_basic_set_is_empty(bset));
1143 isl_local_space_free(ls);
1144 isl_basic_set_free(bset);
1146 /* test 10 */
1147 dim = isl_space_set_alloc(ctx, 0, 3);
1148 bset = isl_basic_set_universe(isl_space_copy(dim));
1149 ls = isl_local_space_from_space(dim);
1151 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1152 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1153 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -2);
1154 bset = isl_basic_set_add_constraint(bset, c);
1156 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
1158 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
1160 isl_local_space_free(ls);
1161 isl_basic_set_free(bset);
1163 str = "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1164 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1165 set = isl_set_read_from_str(ctx, str);
1166 set = isl_set_compute_divs(set);
1167 isl_set_free(set);
1168 if (!set)
1169 return -1;
1171 if (test_elimination(ctx) < 0)
1172 return -1;
1174 str = "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1175 set = isl_set_read_from_str(ctx, str);
1176 set = isl_set_remove_divs_involving_dims(set, isl_dim_set, 0, 2);
1177 set = isl_set_fix_si(set, isl_dim_set, 2, -3);
1178 empty = isl_set_is_empty(set);
1179 isl_set_free(set);
1180 if (empty < 0)
1181 return -1;
1182 if (!empty)
1183 isl_die(ctx, isl_error_unknown,
1184 "result not as accurate as expected", return -1);
1186 return 0;
1189 void test_application_case(struct isl_ctx *ctx, const char *name)
1191 char *filename;
1192 FILE *input;
1193 struct isl_basic_set *bset1, *bset2;
1194 struct isl_basic_map *bmap;
1196 filename = get_filename(ctx, name, "omega");
1197 assert(filename);
1198 input = fopen(filename, "r");
1199 assert(input);
1201 bset1 = isl_basic_set_read_from_file(ctx, input);
1202 bmap = isl_basic_map_read_from_file(ctx, input);
1204 bset1 = isl_basic_set_apply(bset1, bmap);
1206 bset2 = isl_basic_set_read_from_file(ctx, input);
1208 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1210 isl_basic_set_free(bset1);
1211 isl_basic_set_free(bset2);
1212 free(filename);
1214 fclose(input);
1217 static int test_application(isl_ctx *ctx)
1219 test_application_case(ctx, "application");
1220 test_application_case(ctx, "application2");
1222 return 0;
1225 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
1227 char *filename;
1228 FILE *input;
1229 struct isl_basic_set *bset1, *bset2;
1231 filename = get_filename(ctx, name, "polylib");
1232 assert(filename);
1233 input = fopen(filename, "r");
1234 assert(input);
1236 bset1 = isl_basic_set_read_from_file(ctx, input);
1237 bset2 = isl_basic_set_read_from_file(ctx, input);
1239 bset1 = isl_basic_set_affine_hull(bset1);
1241 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1243 isl_basic_set_free(bset1);
1244 isl_basic_set_free(bset2);
1245 free(filename);
1247 fclose(input);
1250 int test_affine_hull(struct isl_ctx *ctx)
1252 const char *str;
1253 isl_set *set;
1254 isl_basic_set *bset, *bset2;
1255 isl_size n;
1256 isl_bool subset;
1258 test_affine_hull_case(ctx, "affine2");
1259 test_affine_hull_case(ctx, "affine");
1260 test_affine_hull_case(ctx, "affine3");
1262 str = "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1263 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1264 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1265 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1266 set = isl_set_read_from_str(ctx, str);
1267 bset = isl_set_affine_hull(set);
1268 n = isl_basic_set_dim(bset, isl_dim_div);
1269 isl_basic_set_free(bset);
1270 if (n < 0)
1271 return -1;
1272 if (n != 0)
1273 isl_die(ctx, isl_error_unknown, "not expecting any divs",
1274 return -1);
1276 /* Check that isl_map_affine_hull is not confused by
1277 * the reordering of divs in isl_map_align_divs.
1279 str = "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1280 "32e0 = b and 32e1 = c); "
1281 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1282 set = isl_set_read_from_str(ctx, str);
1283 bset = isl_set_affine_hull(set);
1284 isl_basic_set_free(bset);
1285 if (!bset)
1286 return -1;
1288 str = "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1289 "32e2 = 31 + 31e0 }";
1290 set = isl_set_read_from_str(ctx, str);
1291 bset = isl_set_affine_hull(set);
1292 str = "{ [a] : exists e : a = 32 e }";
1293 bset2 = isl_basic_set_read_from_str(ctx, str);
1294 subset = isl_basic_set_is_subset(bset, bset2);
1295 isl_basic_set_free(bset);
1296 isl_basic_set_free(bset2);
1297 if (subset < 0)
1298 return -1;
1299 if (!subset)
1300 isl_die(ctx, isl_error_unknown, "not as accurate as expected",
1301 return -1);
1303 return 0;
1306 /* Pairs of maps and the corresponding expected results of
1307 * isl_map_plain_unshifted_simple_hull.
1309 struct {
1310 const char *map;
1311 const char *hull;
1312 } plain_unshifted_simple_hull_tests[] = {
1313 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1314 "{ [i] -> [j] : i >= 1 }" },
1315 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1316 "(j mod 4 = 2 and k mod 6 = n) }",
1317 "{ [n] -> [i,j,k] : j mod 4 = 2 }" },
1320 /* Basic tests for isl_map_plain_unshifted_simple_hull.
1322 static int test_plain_unshifted_simple_hull(isl_ctx *ctx)
1324 int i;
1325 isl_map *map;
1326 isl_basic_map *hull, *expected;
1327 isl_bool equal;
1329 for (i = 0; i < ARRAY_SIZE(plain_unshifted_simple_hull_tests); ++i) {
1330 const char *str;
1331 str = plain_unshifted_simple_hull_tests[i].map;
1332 map = isl_map_read_from_str(ctx, str);
1333 str = plain_unshifted_simple_hull_tests[i].hull;
1334 expected = isl_basic_map_read_from_str(ctx, str);
1335 hull = isl_map_plain_unshifted_simple_hull(map);
1336 equal = isl_basic_map_is_equal(hull, expected);
1337 isl_basic_map_free(hull);
1338 isl_basic_map_free(expected);
1339 if (equal < 0)
1340 return -1;
1341 if (!equal)
1342 isl_die(ctx, isl_error_unknown, "unexpected hull",
1343 return -1);
1346 return 0;
1349 /* Pairs of sets and the corresponding expected results of
1350 * isl_set_unshifted_simple_hull.
1352 struct {
1353 const char *set;
1354 const char *hull;
1355 } unshifted_simple_hull_tests[] = {
1356 { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1357 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1360 /* Basic tests for isl_set_unshifted_simple_hull.
1362 static int test_unshifted_simple_hull(isl_ctx *ctx)
1364 int i;
1365 isl_set *set;
1366 isl_basic_set *hull, *expected;
1367 isl_bool equal;
1369 for (i = 0; i < ARRAY_SIZE(unshifted_simple_hull_tests); ++i) {
1370 const char *str;
1371 str = unshifted_simple_hull_tests[i].set;
1372 set = isl_set_read_from_str(ctx, str);
1373 str = unshifted_simple_hull_tests[i].hull;
1374 expected = isl_basic_set_read_from_str(ctx, str);
1375 hull = isl_set_unshifted_simple_hull(set);
1376 equal = isl_basic_set_is_equal(hull, expected);
1377 isl_basic_set_free(hull);
1378 isl_basic_set_free(expected);
1379 if (equal < 0)
1380 return -1;
1381 if (!equal)
1382 isl_die(ctx, isl_error_unknown, "unexpected hull",
1383 return -1);
1386 return 0;
1389 static int test_simple_hull(struct isl_ctx *ctx)
1391 const char *str;
1392 isl_set *set;
1393 isl_basic_set *bset;
1394 isl_bool is_empty;
1396 str = "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1397 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1398 set = isl_set_read_from_str(ctx, str);
1399 bset = isl_set_simple_hull(set);
1400 is_empty = isl_basic_set_is_empty(bset);
1401 isl_basic_set_free(bset);
1403 if (is_empty == isl_bool_error)
1404 return -1;
1406 if (is_empty == isl_bool_false)
1407 isl_die(ctx, isl_error_unknown, "Empty set should be detected",
1408 return -1);
1410 if (test_plain_unshifted_simple_hull(ctx) < 0)
1411 return -1;
1412 if (test_unshifted_simple_hull(ctx) < 0)
1413 return -1;
1415 return 0;
1418 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
1420 char *filename;
1421 FILE *input;
1422 struct isl_basic_set *bset1, *bset2;
1423 struct isl_set *set;
1425 filename = get_filename(ctx, name, "polylib");
1426 assert(filename);
1427 input = fopen(filename, "r");
1428 assert(input);
1430 bset1 = isl_basic_set_read_from_file(ctx, input);
1431 bset2 = isl_basic_set_read_from_file(ctx, input);
1433 set = isl_basic_set_union(bset1, bset2);
1434 bset1 = isl_set_convex_hull(set);
1436 bset2 = isl_basic_set_read_from_file(ctx, input);
1438 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1440 isl_basic_set_free(bset1);
1441 isl_basic_set_free(bset2);
1442 free(filename);
1444 fclose(input);
1447 struct {
1448 const char *set;
1449 const char *hull;
1450 } convex_hull_tests[] = {
1451 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1452 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1453 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1454 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1455 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1456 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1457 "i2 <= 5 and i2 >= 4; "
1458 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1459 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1460 "i2 <= 5 + i0 and i2 >= i0 }" },
1461 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1462 "{ [x, y] : 1 = 0 }" },
1463 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1464 "[x, y, 0] : x >= 0 and y < 0 }",
1465 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1466 { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and "
1467 "c <= a; "
1468 "[0, 2, 0]; [3, 1, 0] }",
1469 "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and "
1470 "5c <= 6 - a - 3b }" },
1473 static int test_convex_hull_algo(isl_ctx *ctx, int convex)
1475 int i;
1476 int orig_convex = ctx->opt->convex;
1477 ctx->opt->convex = convex;
1479 test_convex_hull_case(ctx, "convex0");
1480 test_convex_hull_case(ctx, "convex1");
1481 test_convex_hull_case(ctx, "convex2");
1482 test_convex_hull_case(ctx, "convex3");
1483 test_convex_hull_case(ctx, "convex4");
1484 test_convex_hull_case(ctx, "convex5");
1485 test_convex_hull_case(ctx, "convex6");
1486 test_convex_hull_case(ctx, "convex7");
1487 test_convex_hull_case(ctx, "convex8");
1488 test_convex_hull_case(ctx, "convex9");
1489 test_convex_hull_case(ctx, "convex10");
1490 test_convex_hull_case(ctx, "convex11");
1491 test_convex_hull_case(ctx, "convex12");
1492 test_convex_hull_case(ctx, "convex13");
1493 test_convex_hull_case(ctx, "convex14");
1494 test_convex_hull_case(ctx, "convex15");
1496 for (i = 0; i < ARRAY_SIZE(convex_hull_tests); ++i) {
1497 isl_set *set1, *set2;
1498 int equal;
1500 set1 = isl_set_read_from_str(ctx, convex_hull_tests[i].set);
1501 set2 = isl_set_read_from_str(ctx, convex_hull_tests[i].hull);
1502 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
1503 equal = isl_set_is_equal(set1, set2);
1504 isl_set_free(set1);
1505 isl_set_free(set2);
1507 if (equal < 0)
1508 return -1;
1509 if (!equal)
1510 isl_die(ctx, isl_error_unknown,
1511 "unexpected convex hull", return -1);
1514 ctx->opt->convex = orig_convex;
1516 return 0;
1519 static int test_convex_hull(isl_ctx *ctx)
1521 if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM) < 0)
1522 return -1;
1523 if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP) < 0)
1524 return -1;
1525 return 0;
1528 void test_gist_case(struct isl_ctx *ctx, const char *name)
1530 char *filename;
1531 FILE *input;
1532 struct isl_basic_set *bset1, *bset2;
1534 filename = get_filename(ctx, name, "polylib");
1535 assert(filename);
1536 input = fopen(filename, "r");
1537 assert(input);
1539 bset1 = isl_basic_set_read_from_file(ctx, input);
1540 bset2 = isl_basic_set_read_from_file(ctx, input);
1542 bset1 = isl_basic_set_gist(bset1, bset2);
1544 bset2 = isl_basic_set_read_from_file(ctx, input);
1546 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1548 isl_basic_set_free(bset1);
1549 isl_basic_set_free(bset2);
1550 free(filename);
1552 fclose(input);
1555 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1557 struct {
1558 const char *map;
1559 const char *context;
1560 const char *gist;
1561 } plain_gist_tests[] = {
1562 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1563 "{ [i] -> [j] : i >= 1 }",
1564 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1565 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1566 "(j mod 4 = 2 and k mod 6 = n) }",
1567 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1568 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1569 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1570 "{ [i] -> [j] : i > j }",
1571 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1574 /* Basic tests for isl_map_plain_gist_basic_map.
1576 static int test_plain_gist(isl_ctx *ctx)
1578 int i;
1580 for (i = 0; i < ARRAY_SIZE(plain_gist_tests); ++i) {
1581 const char *str;
1582 int equal;
1583 isl_map *map, *gist;
1584 isl_basic_map *context;
1586 map = isl_map_read_from_str(ctx, plain_gist_tests[i].map);
1587 str = plain_gist_tests[i].context;
1588 context = isl_basic_map_read_from_str(ctx, str);
1589 map = isl_map_plain_gist_basic_map(map, context);
1590 gist = isl_map_read_from_str(ctx, plain_gist_tests[i].gist);
1591 equal = isl_map_is_equal(map, gist);
1592 isl_map_free(map);
1593 isl_map_free(gist);
1594 if (equal < 0)
1595 return -1;
1596 if (!equal)
1597 isl_die(ctx, isl_error_unknown,
1598 "incorrect gist result", return -1);
1601 return 0;
1604 /* Inputs for isl_basic_set_gist tests that are expected to fail.
1606 struct {
1607 const char *set;
1608 const char *context;
1609 } gist_fail_tests[] = {
1610 { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1611 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }",
1612 "{ [i] : i >= 0 }" },
1615 /* Check that isl_basic_set_gist fails (gracefully) when expected.
1616 * In particular, the user should be able to recover from the failure.
1618 static isl_stat test_gist_fail(struct isl_ctx *ctx)
1620 int i, n;
1621 int on_error;
1623 on_error = isl_options_get_on_error(ctx);
1624 isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE);
1625 n = ARRAY_SIZE(gist_fail_tests);
1626 for (i = 0; i < n; ++i) {
1627 const char *str;
1628 isl_basic_set *bset, *context;
1630 bset = isl_basic_set_read_from_str(ctx, gist_fail_tests[i].set);
1631 str = gist_fail_tests[i].context;
1632 context = isl_basic_set_read_from_str(ctx, str);
1633 bset = isl_basic_set_gist(bset, context);
1634 isl_basic_set_free(bset);
1635 if (bset)
1636 break;
1638 isl_options_set_on_error(ctx, on_error);
1639 if (i < n)
1640 isl_die(ctx, isl_error_unknown,
1641 "operation not expected to succeed",
1642 return isl_stat_error);
1644 return isl_stat_ok;
1647 struct {
1648 const char *set;
1649 const char *context;
1650 const char *gist;
1651 } gist_tests[] = {
1652 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1653 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1654 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1655 "{ [a, b, c] : a <= 15 }" },
1656 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1657 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1658 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1659 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1660 { "{ [m, n, a, b] : a <= 2147 + n }",
1661 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1662 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1663 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1664 "b >= 0) }",
1665 "{ [m, n, ku, kl] }" },
1666 { "{ [a, a, b] : a >= 10 }",
1667 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1668 "{ [a, a, b] : a >= 10 }" },
1669 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1670 "{ [0, j] : j >= 0 }" },
1671 /* Check that no constraints on i6 are introduced in the gist */
1672 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1673 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1674 "5e0 <= 381 - t1 and i4 <= 1) }",
1675 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1676 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1677 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1678 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1679 "20e0 >= 1511 - 4t1 - 5i4) }" },
1680 /* Check that no constraints on i6 are introduced in the gist */
1681 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1682 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1683 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1684 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1685 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1686 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1687 "20e1 <= 1530 - 4t1 - 5i4 and "
1688 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1689 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1690 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1691 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1692 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1693 "10e0 <= -91 + 5i4 + 4i6 and "
1694 "10e0 >= -105 + 5i4 + 4i6) }",
1695 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1696 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1697 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1698 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1699 "{ [a, b, q, p] : b >= 1 + a }",
1700 "{ [a, b, q, p] : false }" },
1701 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1702 "[n] -> { [x] : x mod 32 = 0 }",
1703 "[n] -> { [x = n] }" },
1704 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1705 "{ [x] : x mod 2 = 0 }" },
1706 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1707 "{ [x] : x mod 128 = 0 }" },
1708 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1709 "{ [x] : x mod 3200 = 0 }" },
1710 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1711 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1712 "{ [a, b, c = a] }" },
1713 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1714 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1715 "{ [a, b, c = a] : a mod 3 = 0 }" },
1716 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1717 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1718 "{ [x] }" },
1719 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1720 "{ [x,y] : 1 <= y <= 3 }",
1721 "{ [x,y] }" },
1724 /* Check that isl_set_gist behaves as expected.
1726 * For the test cases in gist_tests, besides checking that the result
1727 * is as expected, also check that applying the gist operation does
1728 * not modify the input set (an earlier version of isl would do that) and
1729 * that the test case is consistent, i.e., that the gist has the same
1730 * intersection with the context as the input set.
1732 static int test_gist(struct isl_ctx *ctx)
1734 int i;
1735 const char *str;
1736 isl_basic_set *bset1, *bset2;
1737 isl_map *map1, *map2;
1738 isl_bool equal;
1739 isl_size n_div;
1741 for (i = 0; i < ARRAY_SIZE(gist_tests); ++i) {
1742 isl_bool equal_input, equal_intersection;
1743 isl_set *set1, *set2, *copy, *context;
1745 set1 = isl_set_read_from_str(ctx, gist_tests[i].set);
1746 context = isl_set_read_from_str(ctx, gist_tests[i].context);
1747 copy = isl_set_copy(set1);
1748 set1 = isl_set_gist(set1, isl_set_copy(context));
1749 set2 = isl_set_read_from_str(ctx, gist_tests[i].gist);
1750 equal = isl_set_is_equal(set1, set2);
1751 isl_set_free(set1);
1752 set1 = isl_set_read_from_str(ctx, gist_tests[i].set);
1753 equal_input = isl_set_is_equal(set1, copy);
1754 isl_set_free(copy);
1755 set1 = isl_set_intersect(set1, isl_set_copy(context));
1756 set2 = isl_set_intersect(set2, context);
1757 equal_intersection = isl_set_is_equal(set1, set2);
1758 isl_set_free(set2);
1759 isl_set_free(set1);
1760 if (equal < 0 || equal_input < 0 || equal_intersection < 0)
1761 return -1;
1762 if (!equal)
1763 isl_die(ctx, isl_error_unknown,
1764 "incorrect gist result", return -1);
1765 if (!equal_input)
1766 isl_die(ctx, isl_error_unknown,
1767 "gist modified input", return -1);
1768 if (!equal_input)
1769 isl_die(ctx, isl_error_unknown,
1770 "inconsistent gist test case", return -1);
1773 if (test_gist_fail(ctx) < 0)
1774 return -1;
1776 test_gist_case(ctx, "gist1");
1778 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
1779 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1780 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1781 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1782 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1783 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1784 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1785 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1786 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1787 bset1 = isl_basic_set_read_from_str(ctx, str);
1788 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1789 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1790 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1791 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1792 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1793 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1794 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1795 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1796 bset2 = isl_basic_set_read_from_str(ctx, str);
1797 bset1 = isl_basic_set_gist(bset1, bset2);
1798 assert(bset1 && bset1->n_div == 0);
1799 isl_basic_set_free(bset1);
1801 /* Check that the integer divisions of the second disjunct
1802 * do not spread to the first disjunct.
1804 str = "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1805 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1806 "(exists (e0 = [(-1 + t1)/16], "
1807 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1808 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1809 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1810 "o0 <= 4294967295 and t1 <= -1)) }";
1811 map1 = isl_map_read_from_str(ctx, str);
1812 str = "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1813 map2 = isl_map_read_from_str(ctx, str);
1814 map1 = isl_map_gist(map1, map2);
1815 if (!map1)
1816 return -1;
1817 if (map1->n != 1)
1818 isl_die(ctx, isl_error_unknown, "expecting single disjunct",
1819 isl_map_free(map1); return -1);
1820 n_div = isl_basic_map_dim(map1->p[0], isl_dim_div);
1821 isl_map_free(map1);
1822 if (n_div < 0)
1823 return -1;
1824 if (n_div != 1)
1825 isl_die(ctx, isl_error_unknown, "expecting single div",
1826 return -1);
1828 if (test_plain_gist(ctx) < 0)
1829 return -1;
1831 return 0;
1834 int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
1836 isl_set *set, *set2;
1837 int equal;
1838 int one;
1840 set = isl_set_read_from_str(ctx, str);
1841 set = isl_set_coalesce(set);
1842 set2 = isl_set_read_from_str(ctx, str);
1843 equal = isl_set_is_equal(set, set2);
1844 one = set && set->n == 1;
1845 isl_set_free(set);
1846 isl_set_free(set2);
1848 if (equal < 0)
1849 return -1;
1850 if (!equal)
1851 isl_die(ctx, isl_error_unknown,
1852 "coalesced set not equal to input", return -1);
1853 if (check_one && !one)
1854 isl_die(ctx, isl_error_unknown,
1855 "coalesced set should not be a union", return -1);
1857 return 0;
1860 /* Inputs for coalescing tests with unbounded wrapping.
1861 * "str" is a string representation of the input set.
1862 * "single_disjunct" is set if we expect the result to consist of
1863 * a single disjunct.
1865 struct {
1866 int single_disjunct;
1867 const char *str;
1868 } coalesce_unbounded_tests[] = {
1869 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1870 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1871 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1872 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1873 "-10 <= y <= 0}" },
1874 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1875 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1876 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1877 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1878 { 0, "{ [x, y, z] : 0 <= x,y,z <= 100 and 0 < z <= 2 + 2x + 2y; "
1879 "[x, y, 0] : x,y <= 100 and y <= 9 + 11x and x <= 9 + 11y }" },
1882 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1883 * option turned off.
1885 int test_coalesce_unbounded_wrapping(isl_ctx *ctx)
1887 int i;
1888 int r = 0;
1889 int bounded;
1891 bounded = isl_options_get_coalesce_bounded_wrapping(ctx);
1892 isl_options_set_coalesce_bounded_wrapping(ctx, 0);
1894 for (i = 0; i < ARRAY_SIZE(coalesce_unbounded_tests); ++i) {
1895 const char *str = coalesce_unbounded_tests[i].str;
1896 int check_one = coalesce_unbounded_tests[i].single_disjunct;
1897 if (test_coalesce_set(ctx, str, check_one) >= 0)
1898 continue;
1899 r = -1;
1900 break;
1903 isl_options_set_coalesce_bounded_wrapping(ctx, bounded);
1905 return r;
1908 /* Inputs for coalescing tests.
1909 * "str" is a string representation of the input set.
1910 * "single_disjunct" is set if we expect the result to consist of
1911 * a single disjunct.
1913 struct {
1914 int single_disjunct;
1915 const char *str;
1916 } coalesce_tests[] = {
1917 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1918 "y >= x & x >= 2 & 5 >= y }" },
1919 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1920 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1921 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1922 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1923 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1924 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1925 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1926 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1927 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1928 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1929 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1930 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1931 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1932 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1933 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1934 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1935 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1936 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1937 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1938 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1939 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1940 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1941 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1942 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1943 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1944 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1945 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1946 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1947 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1948 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1949 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1950 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1951 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1952 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1953 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1954 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1955 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1956 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1957 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1958 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1959 "[o0, o1, o2, o3, o4, o5, o6]] : "
1960 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1961 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1962 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1963 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1964 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1965 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1966 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1967 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1968 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1969 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1970 "o6 >= i3 + i6 - o3 and M >= 0 and "
1971 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1972 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1973 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1974 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1975 "(o0 = 0 and M >= 2 and N >= 3) or "
1976 "(M = 0 and o0 = 0 and N >= 3) }" },
1977 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1978 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1979 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1980 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1981 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1982 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1983 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1984 "(y = 3 and x = 1) }" },
1985 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1986 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1987 "i1 <= M and i3 <= M and i4 <= M) or "
1988 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1989 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1990 "i4 <= -1 + M) }" },
1991 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1992 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1993 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1994 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1995 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1996 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1997 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1998 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1999 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
2000 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
2001 { 0, "{ [a, b] : exists e : 2e = a and "
2002 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
2003 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
2004 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
2005 "j >= 1 and j' <= i + j - i' and i >= 1; "
2006 "[1, 1, 1, 1] }" },
2007 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
2008 "[i,j] : exists a : j = 3a }" },
2009 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
2010 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
2011 "a >= 3) or "
2012 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
2013 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
2014 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
2015 "c <= 6 + 8a and a >= 3; "
2016 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
2017 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
2018 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2019 "[x,0] : 3 <= x <= 4 }" },
2020 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
2021 "[x,0] : 4 <= x <= 5 }" },
2022 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
2023 "[x,0] : 3 <= x <= 5 }" },
2024 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
2025 "[x,0] : 3 <= x <= 4 }" },
2026 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
2027 "i1 <= 0; "
2028 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
2029 { 1, "{ [0,0]; [1,1] }" },
2030 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
2031 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
2032 "ii <= k;"
2033 "[k, 0, k] : k <= 6 and k >= 1 }" },
2034 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
2035 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
2036 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
2037 { 1, "[n] -> { [1] : n >= 0;"
2038 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
2039 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
2040 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
2041 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
2042 "2e0 <= x and 2e0 <= n);"
2043 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
2044 "n >= 0) }" },
2045 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
2046 "128e0 >= -134 + 127t1 and t1 >= 2 and "
2047 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
2048 "t1 = 1 }" },
2049 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
2050 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
2051 "[0, 0] }" },
2052 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
2053 "t1 >= 13 and t1 <= 16);"
2054 "[t1] : t1 <= 15 and t1 >= 12 }" },
2055 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2056 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2057 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2058 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2059 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2060 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2061 "i <= 4j + 2 }" },
2062 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2063 "(exists (e0 : 3e0 = -2 + c0)) }" },
2064 { 0, "[n, b0, t0] -> "
2065 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2066 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2067 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2068 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2069 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2070 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2071 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2072 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2073 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2074 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2075 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2076 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2077 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2078 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2079 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2080 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2081 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2082 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2083 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2084 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2085 { 0, "{ [i0, i1, i2] : "
2086 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2087 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2088 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2089 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2090 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2091 "32e0 <= 31 + i0)) or "
2092 "i0 >= 0 }" },
2093 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2094 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2095 "2*floor((c)/2) = c and 0 <= a <= 192;"
2096 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2098 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2099 "(0 <= a <= b <= n) }" },
2100 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2101 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2102 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2103 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2104 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2105 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2106 "b = 3 and 9e0 <= -19 + 2c)) }" },
2107 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2108 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2109 "(a = 4 and b = 3 and "
2110 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2111 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2112 "(b = -1 + a and 0 < a <= 3 and "
2113 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2114 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2115 "b = 3 and 9e0 <= -19 + 2c)) }" },
2116 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2117 "[1, 0] }" },
2118 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2119 "[0, 1] }" },
2120 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2121 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2122 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2123 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2124 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2125 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2126 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2127 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2128 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2129 { 1, "{ [a] : a <= 8 and "
2130 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2131 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2132 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2133 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2134 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2135 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2136 "(a < 0 and 3*floor((a)/3) < a) }" },
2137 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2138 "(a < -1 and 3*floor((a)/3) < a) }" },
2139 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2140 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2141 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2142 "or (2 <= a <= 15 and b < a)) }" },
2143 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2144 "32*floor((a)/32) < a) or a <= 15) }" },
2145 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2146 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2147 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2148 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2149 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2150 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2151 "S_0[n] : n <= m <= 2 + n }" },
2152 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2153 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2154 "2e0 <= a + b); "
2155 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2156 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2157 "2e0 < -a + 2b) }" },
2158 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2159 "[i, 0, i] : 0 <= i <= 7 }" },
2160 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2161 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2162 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2163 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2164 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2165 { 0, "{ [a, c] : (2 + a) mod 4 = 0 or "
2166 "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or "
2167 "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and "
2168 "a > 0 and a <= 5) }" },
2169 { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" },
2170 { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and "
2171 "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; "
2172 "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" },
2175 /* A specialized coalescing test case that would result
2176 * in a segmentation fault or a failed assertion in earlier versions of isl.
2178 static int test_coalesce_special(struct isl_ctx *ctx)
2180 const char *str;
2181 isl_map *map1, *map2;
2183 str = "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2184 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2185 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2186 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2187 "o1 <= 239 and o1 >= 212)) or "
2188 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2189 "o1 <= 241 and o1 >= 240));"
2190 "[S_L220_OUT[] -> T7[]] -> "
2191 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2192 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2193 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2194 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2195 map1 = isl_map_read_from_str(ctx, str);
2196 map1 = isl_map_align_divs_internal(map1);
2197 map1 = isl_map_coalesce(map1);
2198 str = "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2199 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2200 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2201 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2202 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2203 map2 = isl_map_read_from_str(ctx, str);
2204 map2 = isl_map_union(map2, map1);
2205 map2 = isl_map_align_divs_internal(map2);
2206 map2 = isl_map_coalesce(map2);
2207 isl_map_free(map2);
2208 if (!map2)
2209 return -1;
2211 return 0;
2214 /* A specialized coalescing test case that would result in an assertion
2215 * in an earlier version of isl.
2216 * The explicit call to isl_basic_set_union prevents the implicit
2217 * equality constraints in the first basic map from being detected prior
2218 * to the call to isl_set_coalesce, at least at the point
2219 * where this test case was introduced.
2221 static int test_coalesce_special2(struct isl_ctx *ctx)
2223 const char *str;
2224 isl_basic_set *bset1, *bset2;
2225 isl_set *set;
2227 str = "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2228 bset1 = isl_basic_set_read_from_str(ctx, str);
2229 str = "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2230 bset2 = isl_basic_set_read_from_str(ctx, str);
2231 set = isl_basic_set_union(bset1, bset2);
2232 set = isl_set_coalesce(set);
2233 isl_set_free(set);
2235 if (!set)
2236 return -1;
2237 return 0;
2240 /* Check that calling isl_set_coalesce does not leave other sets
2241 * that may share some information with the input to isl_set_coalesce
2242 * in an inconsistent state.
2243 * In particular, older versions of isl would modify all copies
2244 * of the basic sets in the isl_set_coalesce input in a way
2245 * that could leave them in an inconsistent state.
2246 * The result of printing any other set containing one of these
2247 * basic sets would then result in an invalid set description.
2249 static int test_coalesce_special3(isl_ctx *ctx)
2251 const char *str;
2252 char *s;
2253 isl_set *set1, *set2;
2254 isl_printer *p;
2256 set1 = isl_set_read_from_str(ctx, "{ [0, 0, 0] }");
2257 str = "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2258 set2 = isl_set_read_from_str(ctx, str);
2259 set1 = isl_set_union(set1, isl_set_copy(set2));
2260 set1 = isl_set_coalesce(set1);
2261 isl_set_free(set1);
2263 p = isl_printer_to_str(ctx);
2264 p = isl_printer_print_set(p, set2);
2265 isl_set_free(set2);
2266 s = isl_printer_get_str(p);
2267 isl_printer_free(p);
2268 set1 = isl_set_read_from_str(ctx, s);
2269 free(s);
2270 isl_set_free(set1);
2272 if (!set1)
2273 return -1;
2275 return 0;
2278 /* Check that calling isl_set_coalesce on the intersection of
2279 * the sets described by "s1" and "s2" does not leave other sets
2280 * that may share some information with the input to isl_set_coalesce
2281 * in an inconsistent state.
2282 * In particular, when isl_set_coalesce detects equality constraints,
2283 * it does not immediately perform Gaussian elimination on them,
2284 * but then it needs to ensure that it is performed at some point.
2285 * The input set has implicit equality constraints in the first disjunct.
2286 * It is constructed as an intersection, because otherwise
2287 * those equality constraints would already be detected during parsing.
2289 static isl_stat test_coalesce_intersection(isl_ctx *ctx,
2290 const char *s1, const char *s2)
2292 isl_set *set1, *set2;
2294 set1 = isl_set_read_from_str(ctx, s1);
2295 set2 = isl_set_read_from_str(ctx, s2);
2296 set1 = isl_set_intersect(set1, set2);
2297 isl_set_free(isl_set_coalesce(isl_set_copy(set1)));
2298 set1 = isl_set_coalesce(set1);
2299 isl_set_free(set1);
2301 if (!set1)
2302 return isl_stat_error;
2304 return isl_stat_ok;
2307 /* Check that calling isl_set_coalesce does not leave other sets
2308 * that may share some information with the input to isl_set_coalesce
2309 * in an inconsistent state, for the case where one disjunct
2310 * is a subset of the other.
2312 static isl_stat test_coalesce_special4(isl_ctx *ctx)
2314 const char *s1, *s2;
2316 s1 = "{ [a, b] : b <= 0 or a <= 1 }";
2317 s2 = "{ [a, b] : -1 <= -a < b }";
2318 return test_coalesce_intersection(ctx, s1, s2);
2321 /* Check that calling isl_set_coalesce does not leave other sets
2322 * that may share some information with the input to isl_set_coalesce
2323 * in an inconsistent state, for the case where two disjuncts
2324 * can be fused.
2326 static isl_stat test_coalesce_special5(isl_ctx *ctx)
2328 const char *s1, *s2;
2330 s1 = "{ [a, b, c] : b <= 0 }";
2331 s2 = "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }";
2332 return test_coalesce_intersection(ctx, s1, s2);
2335 /* Check that calling isl_set_coalesce does not leave other sets
2336 * that may share some information with the input to isl_set_coalesce
2337 * in an inconsistent state, for the case where two disjuncts
2338 * can be fused and where both disjuncts have implicit equality constraints.
2340 static isl_stat test_coalesce_special6(isl_ctx *ctx)
2342 const char *s1, *s2;
2344 s1 = "{ [a, b, c] : c <= 0 }";
2345 s2 = "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }";
2346 return test_coalesce_intersection(ctx, s1, s2);
2349 /* Test the functionality of isl_set_coalesce.
2350 * That is, check that the output is always equal to the input
2351 * and in some cases that the result consists of a single disjunct.
2353 static int test_coalesce(struct isl_ctx *ctx)
2355 int i;
2357 for (i = 0; i < ARRAY_SIZE(coalesce_tests); ++i) {
2358 const char *str = coalesce_tests[i].str;
2359 int check_one = coalesce_tests[i].single_disjunct;
2360 if (test_coalesce_set(ctx, str, check_one) < 0)
2361 return -1;
2364 if (test_coalesce_unbounded_wrapping(ctx) < 0)
2365 return -1;
2366 if (test_coalesce_special(ctx) < 0)
2367 return -1;
2368 if (test_coalesce_special2(ctx) < 0)
2369 return -1;
2370 if (test_coalesce_special3(ctx) < 0)
2371 return -1;
2372 if (test_coalesce_special4(ctx) < 0)
2373 return -1;
2374 if (test_coalesce_special5(ctx) < 0)
2375 return -1;
2376 if (test_coalesce_special6(ctx) < 0)
2377 return -1;
2380 return 0;
2383 /* Construct a representation of the graph on the right of Figure 1
2384 * in "Computing the Transitive Closure of a Union of
2385 * Affine Integer Tuple Relations".
2387 static __isl_give isl_map *cocoa_fig_1_right_graph(isl_ctx *ctx)
2389 isl_set *dom;
2390 isl_map *up, *right;
2392 dom = isl_set_read_from_str(ctx,
2393 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2394 "2 x - 3 y + 3 >= 0 }");
2395 right = isl_map_read_from_str(ctx,
2396 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2397 up = isl_map_read_from_str(ctx,
2398 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2399 right = isl_map_intersect_domain(right, isl_set_copy(dom));
2400 right = isl_map_intersect_range(right, isl_set_copy(dom));
2401 up = isl_map_intersect_domain(up, isl_set_copy(dom));
2402 up = isl_map_intersect_range(up, dom);
2403 return isl_map_union(up, right);
2406 /* Construct a representation of the power of the graph
2407 * on the right of Figure 1 in "Computing the Transitive Closure of
2408 * a Union of Affine Integer Tuple Relations".
2410 static __isl_give isl_map *cocoa_fig_1_right_power(isl_ctx *ctx)
2412 return isl_map_read_from_str(ctx,
2413 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2414 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2415 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2418 /* Construct a representation of the transitive closure of the graph
2419 * on the right of Figure 1 in "Computing the Transitive Closure of
2420 * a Union of Affine Integer Tuple Relations".
2422 static __isl_give isl_map *cocoa_fig_1_right_tc(isl_ctx *ctx)
2424 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx)));
2427 static int test_closure(isl_ctx *ctx)
2429 const char *str;
2430 isl_map *map, *map2;
2431 isl_bool exact, equal;
2433 /* COCOA example 1 */
2434 map = isl_map_read_from_str(ctx,
2435 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2436 "1 <= i and i < n and 1 <= j and j < n or "
2437 "i2 = i + 1 and j2 = j - 1 and "
2438 "1 <= i and i < n and 2 <= j and j <= n }");
2439 map = isl_map_power(map, &exact);
2440 assert(exact);
2441 isl_map_free(map);
2443 /* COCOA example 1 */
2444 map = isl_map_read_from_str(ctx,
2445 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2446 "1 <= i and i < n and 1 <= j and j < n or "
2447 "i2 = i + 1 and j2 = j - 1 and "
2448 "1 <= i and i < n and 2 <= j and j <= n }");
2449 map = isl_map_transitive_closure(map, &exact);
2450 assert(exact);
2451 map2 = isl_map_read_from_str(ctx,
2452 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2453 "1 <= i and i < n and 1 <= j and j <= n and "
2454 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2455 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2456 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2457 assert(isl_map_is_equal(map, map2));
2458 isl_map_free(map2);
2459 isl_map_free(map);
2461 map = isl_map_read_from_str(ctx,
2462 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2463 " 0 <= y and y <= n }");
2464 map = isl_map_transitive_closure(map, &exact);
2465 map2 = isl_map_read_from_str(ctx,
2466 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2467 " 0 <= y and y <= n }");
2468 assert(isl_map_is_equal(map, map2));
2469 isl_map_free(map2);
2470 isl_map_free(map);
2472 /* COCOA example 2 */
2473 map = isl_map_read_from_str(ctx,
2474 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2475 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2476 "i2 = i + 2 and j2 = j - 2 and "
2477 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2478 map = isl_map_transitive_closure(map, &exact);
2479 assert(exact);
2480 map2 = isl_map_read_from_str(ctx,
2481 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2482 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2483 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2484 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2485 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2486 assert(isl_map_is_equal(map, map2));
2487 isl_map_free(map);
2488 isl_map_free(map2);
2490 /* COCOA Fig.2 left */
2491 map = isl_map_read_from_str(ctx,
2492 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2493 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2494 "j <= n or "
2495 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2496 "j <= 2 i - 3 and j <= n - 2 or "
2497 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2498 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2499 map = isl_map_transitive_closure(map, &exact);
2500 assert(exact);
2501 isl_map_free(map);
2503 /* COCOA Fig.2 right */
2504 map = isl_map_read_from_str(ctx,
2505 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2506 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2507 "j <= n or "
2508 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2509 "j <= 2 i - 4 and j <= n - 3 or "
2510 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2511 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2512 map = isl_map_power(map, &exact);
2513 assert(exact);
2514 isl_map_free(map);
2516 /* COCOA Fig.2 right */
2517 map = isl_map_read_from_str(ctx,
2518 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2519 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2520 "j <= n or "
2521 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2522 "j <= 2 i - 4 and j <= n - 3 or "
2523 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2524 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2525 map = isl_map_transitive_closure(map, &exact);
2526 assert(exact);
2527 map2 = isl_map_read_from_str(ctx,
2528 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2529 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2530 "j <= n and 3 + i + 2 j <= 3 n and "
2531 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2532 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2533 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2534 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2535 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2536 assert(isl_map_is_equal(map, map2));
2537 isl_map_free(map2);
2538 isl_map_free(map);
2540 map = cocoa_fig_1_right_graph(ctx);
2541 map = isl_map_transitive_closure(map, &exact);
2542 assert(exact);
2543 map2 = cocoa_fig_1_right_tc(ctx);
2544 assert(isl_map_is_equal(map, map2));
2545 isl_map_free(map2);
2546 isl_map_free(map);
2548 map = cocoa_fig_1_right_graph(ctx);
2549 map = isl_map_power(map, &exact);
2550 map2 = cocoa_fig_1_right_power(ctx);
2551 equal = isl_map_is_equal(map, map2);
2552 isl_map_free(map2);
2553 isl_map_free(map);
2554 if (equal < 0)
2555 return -1;
2556 if (!exact)
2557 isl_die(ctx, isl_error_unknown, "power not exact", return -1);
2558 if (!equal)
2559 isl_die(ctx, isl_error_unknown, "unexpected power", return -1);
2561 /* COCOA Theorem 1 counter example */
2562 map = isl_map_read_from_str(ctx,
2563 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2564 "i2 = 1 and j2 = j or "
2565 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2566 map = isl_map_transitive_closure(map, &exact);
2567 assert(exact);
2568 isl_map_free(map);
2570 map = isl_map_read_from_str(ctx,
2571 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2572 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2573 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2574 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2575 map = isl_map_transitive_closure(map, &exact);
2576 assert(exact);
2577 isl_map_free(map);
2579 /* Kelly et al 1996, fig 12 */
2580 map = isl_map_read_from_str(ctx,
2581 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2582 "1 <= i,j,j+1 <= n or "
2583 "j = n and j2 = 1 and i2 = i + 1 and "
2584 "1 <= i,i+1 <= n }");
2585 map = isl_map_transitive_closure(map, &exact);
2586 assert(exact);
2587 map2 = isl_map_read_from_str(ctx,
2588 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2589 "1 <= i <= n and i = i2 or "
2590 "1 <= i < i2 <= n and 1 <= j <= n and "
2591 "1 <= j2 <= n }");
2592 assert(isl_map_is_equal(map, map2));
2593 isl_map_free(map2);
2594 isl_map_free(map);
2596 /* Omega's closure4 */
2597 map = isl_map_read_from_str(ctx,
2598 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2599 "1 <= x,y <= 10 or "
2600 "x2 = x + 1 and y2 = y and "
2601 "1 <= x <= 20 && 5 <= y <= 15 }");
2602 map = isl_map_transitive_closure(map, &exact);
2603 assert(exact);
2604 isl_map_free(map);
2606 map = isl_map_read_from_str(ctx,
2607 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2608 map = isl_map_transitive_closure(map, &exact);
2609 assert(!exact);
2610 map2 = isl_map_read_from_str(ctx,
2611 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2612 assert(isl_map_is_equal(map, map2));
2613 isl_map_free(map);
2614 isl_map_free(map2);
2616 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2617 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2618 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2619 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2620 map = isl_map_read_from_str(ctx, str);
2621 map = isl_map_transitive_closure(map, &exact);
2622 assert(exact);
2623 map2 = isl_map_read_from_str(ctx, str);
2624 assert(isl_map_is_equal(map, map2));
2625 isl_map_free(map);
2626 isl_map_free(map2);
2628 str = "{[0] -> [1]; [2] -> [3]}";
2629 map = isl_map_read_from_str(ctx, str);
2630 map = isl_map_transitive_closure(map, &exact);
2631 assert(exact);
2632 map2 = isl_map_read_from_str(ctx, str);
2633 assert(isl_map_is_equal(map, map2));
2634 isl_map_free(map);
2635 isl_map_free(map2);
2637 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2638 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2639 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2640 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2641 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2642 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2643 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2644 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2645 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2646 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2647 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2648 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2649 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2650 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2651 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2652 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2653 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2654 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2655 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2656 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2657 map = isl_map_read_from_str(ctx, str);
2658 map = isl_map_transitive_closure(map, NULL);
2659 assert(map);
2660 isl_map_free(map);
2662 return 0;
2665 /* Check that the actual result of a boolean operation is equal
2666 * to the expected result.
2668 static isl_stat check_bool(isl_ctx *ctx, isl_bool actual, isl_bool expected)
2670 if (actual != expected)
2671 isl_die(ctx, isl_error_unknown,
2672 "incorrect boolean operation", return isl_stat_error);
2673 return isl_stat_ok;
2676 /* Test operations on isl_bool values.
2678 * This tests:
2680 * isl_bool_not
2681 * isl_bool_ok
2683 static int test_isl_bool(isl_ctx *ctx)
2685 if (check_bool(ctx, isl_bool_not(isl_bool_true), isl_bool_false) < 0)
2686 return -1;
2687 if (check_bool(ctx, isl_bool_not(isl_bool_false), isl_bool_true) < 0)
2688 return -1;
2689 if (check_bool(ctx, isl_bool_not(isl_bool_error), isl_bool_error) < 0)
2690 return -1;
2691 if (check_bool(ctx, isl_bool_ok(0), isl_bool_false) < 0)
2692 return -1;
2693 if (check_bool(ctx, isl_bool_ok(1), isl_bool_true) < 0)
2694 return -1;
2695 if (check_bool(ctx, isl_bool_ok(-1), isl_bool_true) < 0)
2696 return -1;
2697 if (check_bool(ctx, isl_bool_ok(2), isl_bool_true) < 0)
2698 return -1;
2699 if (check_bool(ctx, isl_bool_ok(-2), isl_bool_true) < 0)
2700 return -1;
2702 return 0;
2705 static int test_lex(struct isl_ctx *ctx)
2707 isl_space *dim;
2708 isl_map *map;
2709 int empty;
2711 dim = isl_space_set_alloc(ctx, 0, 0);
2712 map = isl_map_lex_le(dim);
2713 empty = isl_map_is_empty(map);
2714 isl_map_free(map);
2716 if (empty < 0)
2717 return -1;
2718 if (empty)
2719 isl_die(ctx, isl_error_unknown,
2720 "expecting non-empty result", return -1);
2722 return 0;
2725 /* Inputs for isl_map_lexmin tests.
2726 * "map" is the input and "lexmin" is the expected result.
2728 struct {
2729 const char *map;
2730 const char *lexmin;
2731 } lexmin_tests [] = {
2732 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2733 "{ [x] -> [5] : 6 <= x <= 8; "
2734 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2735 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2736 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2737 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2738 "{ [x] -> [y] : (4y = x and x >= 0) or "
2739 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2740 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2741 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2742 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2743 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2744 /* Check that empty pieces are properly combined. */
2745 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2746 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2747 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2748 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2749 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2750 "x >= 4 }" },
2751 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2752 "a <= 255 and c <= 255 and d <= 255 - j and "
2753 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2754 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2755 "247d <= 247 + i and 248 - b <= 248d <= c and "
2756 "254d >= i - a + b and 254d >= -a + b and "
2757 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2758 "{ [i, k, j] -> "
2759 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2760 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2761 "247j >= 62738 - i and 509j <= 129795 + i and "
2762 "742j >= 188724 - i; "
2763 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2764 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2765 "16*floor((8 + b)/16) <= 7 + b; "
2766 "[a] -> [1] }",
2767 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2768 "[a] -> [b = 0] : 0 < a <= 509 }" },
2769 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2770 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2773 static int test_lexmin(struct isl_ctx *ctx)
2775 int i;
2776 int equal;
2777 const char *str;
2778 isl_basic_map *bmap;
2779 isl_map *map, *map2;
2780 isl_set *set;
2781 isl_set *set2;
2782 isl_pw_multi_aff *pma;
2784 str = "[p0, p1] -> { [] -> [] : "
2785 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2786 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2787 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2788 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2789 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2790 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2791 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2792 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2793 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2794 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2795 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2796 map = isl_map_read_from_str(ctx, str);
2797 map = isl_map_lexmin(map);
2798 isl_map_free(map);
2800 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2801 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2802 set = isl_set_read_from_str(ctx, str);
2803 set = isl_set_lexmax(set);
2804 str = "[C] -> { [obj,a,b,c] : C = 8 }";
2805 set2 = isl_set_read_from_str(ctx, str);
2806 set = isl_set_intersect(set, set2);
2807 assert(!isl_set_is_empty(set));
2808 isl_set_free(set);
2810 for (i = 0; i < ARRAY_SIZE(lexmin_tests); ++i) {
2811 map = isl_map_read_from_str(ctx, lexmin_tests[i].map);
2812 map = isl_map_lexmin(map);
2813 map2 = isl_map_read_from_str(ctx, lexmin_tests[i].lexmin);
2814 equal = isl_map_is_equal(map, map2);
2815 isl_map_free(map);
2816 isl_map_free(map2);
2818 if (equal < 0)
2819 return -1;
2820 if (!equal)
2821 isl_die(ctx, isl_error_unknown,
2822 "unexpected result", return -1);
2825 str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2826 " 8i' <= i and 8i' >= -7 + i }";
2827 bmap = isl_basic_map_read_from_str(ctx, str);
2828 pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap));
2829 map2 = isl_map_from_pw_multi_aff(pma);
2830 map = isl_map_from_basic_map(bmap);
2831 assert(isl_map_is_equal(map, map2));
2832 isl_map_free(map);
2833 isl_map_free(map2);
2835 str = "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2836 " 8i' <= i and 8i' >= -7 + i }";
2837 set = isl_set_read_from_str(ctx, str);
2838 pma = isl_set_lexmin_pw_multi_aff(isl_set_copy(set));
2839 set2 = isl_set_from_pw_multi_aff(pma);
2840 equal = isl_set_is_equal(set, set2);
2841 isl_set_free(set);
2842 isl_set_free(set2);
2843 if (equal < 0)
2844 return -1;
2845 if (!equal)
2846 isl_die(ctx, isl_error_unknown,
2847 "unexpected difference between set and "
2848 "piecewise affine expression", return -1);
2850 return 0;
2853 /* A specialized isl_set_min_val test case that would return the wrong result
2854 * in earlier versions of isl.
2855 * The explicit call to isl_basic_set_union prevents the second basic set
2856 * from being determined to be empty prior to the call to isl_set_min_val,
2857 * at least at the point where this test case was introduced.
2859 static int test_min_special(isl_ctx *ctx)
2861 const char *str;
2862 isl_basic_set *bset1, *bset2;
2863 isl_set *set;
2864 isl_aff *obj;
2865 isl_val *res;
2866 int ok;
2868 str = "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
2869 bset1 = isl_basic_set_read_from_str(ctx, str);
2870 str = "{ [a, b] : 1 <= a, b and a + b <= 1 }";
2871 bset2 = isl_basic_set_read_from_str(ctx, str);
2872 set = isl_basic_set_union(bset1, bset2);
2873 obj = isl_aff_read_from_str(ctx, "{ [a, b] -> [a] }");
2875 res = isl_set_min_val(set, obj);
2876 ok = isl_val_cmp_si(res, 5) == 0;
2878 isl_aff_free(obj);
2879 isl_set_free(set);
2880 isl_val_free(res);
2882 if (!res)
2883 return -1;
2884 if (!ok)
2885 isl_die(ctx, isl_error_unknown, "unexpected minimum",
2886 return -1);
2888 return 0;
2891 /* A specialized isl_set_min_val test case that would return an error
2892 * in earlier versions of isl.
2894 static int test_min_special2(isl_ctx *ctx)
2896 const char *str;
2897 isl_basic_set *bset;
2898 isl_aff *obj;
2899 isl_val *res;
2901 str = "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
2902 bset = isl_basic_set_read_from_str(ctx, str);
2904 obj = isl_aff_read_from_str(ctx, "{ [i, j, k] -> [i] }");
2906 res = isl_basic_set_max_val(bset, obj);
2908 isl_basic_set_free(bset);
2909 isl_aff_free(obj);
2910 isl_val_free(res);
2912 if (!res)
2913 return -1;
2915 return 0;
2918 struct {
2919 const char *set;
2920 const char *obj;
2921 __isl_give isl_val *(*fn)(__isl_keep isl_set *set,
2922 __isl_keep isl_aff *obj);
2923 const char *res;
2924 } opt_tests[] = {
2925 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val, "-1" },
2926 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val, "1" },
2927 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
2928 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
2929 &isl_set_max_val, "30" },
2933 /* Perform basic isl_set_min_val and isl_set_max_val tests.
2934 * In particular, check the results on non-convex inputs.
2936 static int test_min(struct isl_ctx *ctx)
2938 int i;
2939 isl_set *set;
2940 isl_aff *obj;
2941 isl_val *val, *res;
2942 isl_bool ok;
2944 for (i = 0; i < ARRAY_SIZE(opt_tests); ++i) {
2945 set = isl_set_read_from_str(ctx, opt_tests[i].set);
2946 obj = isl_aff_read_from_str(ctx, opt_tests[i].obj);
2947 res = isl_val_read_from_str(ctx, opt_tests[i].res);
2948 val = opt_tests[i].fn(set, obj);
2949 ok = isl_val_eq(res, val);
2950 isl_val_free(res);
2951 isl_val_free(val);
2952 isl_aff_free(obj);
2953 isl_set_free(set);
2955 if (ok < 0)
2956 return -1;
2957 if (!ok)
2958 isl_die(ctx, isl_error_unknown,
2959 "unexpected optimum", return -1);
2962 if (test_min_special(ctx) < 0)
2963 return -1;
2964 if (test_min_special2(ctx) < 0)
2965 return -1;
2967 return 0;
2970 struct must_may {
2971 isl_map *must;
2972 isl_map *may;
2975 static isl_stat collect_must_may(__isl_take isl_map *dep, int must,
2976 void *dep_user, void *user)
2978 struct must_may *mm = (struct must_may *)user;
2980 if (must)
2981 mm->must = isl_map_union(mm->must, dep);
2982 else
2983 mm->may = isl_map_union(mm->may, dep);
2985 return isl_stat_ok;
2988 static int common_space(void *first, void *second)
2990 int depth = *(int *)first;
2991 return 2 * depth;
2994 static int map_is_equal(__isl_keep isl_map *map, const char *str)
2996 isl_map *map2;
2997 int equal;
2999 if (!map)
3000 return -1;
3002 map2 = isl_map_read_from_str(map->ctx, str);
3003 equal = isl_map_is_equal(map, map2);
3004 isl_map_free(map2);
3006 return equal;
3009 static int map_check_equal(__isl_keep isl_map *map, const char *str)
3011 int equal;
3013 equal = map_is_equal(map, str);
3014 if (equal < 0)
3015 return -1;
3016 if (!equal)
3017 isl_die(isl_map_get_ctx(map), isl_error_unknown,
3018 "result not as expected", return -1);
3019 return 0;
3022 /* Is "set" equal to the set described by "str"?
3024 static isl_bool set_is_equal(__isl_keep isl_set *set, const char *str)
3026 isl_set *set2;
3027 isl_bool equal;
3029 if (!set)
3030 return isl_bool_error;
3032 set2 = isl_set_read_from_str(isl_set_get_ctx(set), str);
3033 equal = isl_set_is_equal(set, set2);
3034 isl_set_free(set2);
3036 return equal;
3039 /* Check that "set" is equal to the set described by "str".
3041 static isl_stat set_check_equal(__isl_keep isl_set *set, const char *str)
3043 isl_bool equal;
3045 equal = set_is_equal(set, str);
3046 if (equal < 0)
3047 return isl_stat_error;
3048 if (!equal)
3049 isl_die(isl_set_get_ctx(set), isl_error_unknown,
3050 "result not as expected", return isl_stat_error);
3051 return isl_stat_ok;
3054 static int test_dep(struct isl_ctx *ctx)
3056 const char *str;
3057 isl_space *dim;
3058 isl_map *map;
3059 isl_access_info *ai;
3060 isl_flow *flow;
3061 int depth;
3062 struct must_may mm;
3064 depth = 3;
3066 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3067 map = isl_map_read_from_str(ctx, str);
3068 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3070 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3071 map = isl_map_read_from_str(ctx, str);
3072 ai = isl_access_info_add_source(ai, map, 1, &depth);
3074 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3075 map = isl_map_read_from_str(ctx, str);
3076 ai = isl_access_info_add_source(ai, map, 1, &depth);
3078 flow = isl_access_info_compute_flow(ai);
3079 dim = isl_space_alloc(ctx, 0, 3, 3);
3080 mm.must = isl_map_empty(isl_space_copy(dim));
3081 mm.may = isl_map_empty(dim);
3083 isl_flow_foreach(flow, collect_must_may, &mm);
3085 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
3086 " [1,10,0] -> [2,5,0] }";
3087 assert(map_is_equal(mm.must, str));
3088 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3089 assert(map_is_equal(mm.may, str));
3091 isl_map_free(mm.must);
3092 isl_map_free(mm.may);
3093 isl_flow_free(flow);
3096 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3097 map = isl_map_read_from_str(ctx, str);
3098 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3100 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3101 map = isl_map_read_from_str(ctx, str);
3102 ai = isl_access_info_add_source(ai, map, 1, &depth);
3104 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3105 map = isl_map_read_from_str(ctx, str);
3106 ai = isl_access_info_add_source(ai, map, 0, &depth);
3108 flow = isl_access_info_compute_flow(ai);
3109 dim = isl_space_alloc(ctx, 0, 3, 3);
3110 mm.must = isl_map_empty(isl_space_copy(dim));
3111 mm.may = isl_map_empty(dim);
3113 isl_flow_foreach(flow, collect_must_may, &mm);
3115 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
3116 assert(map_is_equal(mm.must, str));
3117 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3118 assert(map_is_equal(mm.may, str));
3120 isl_map_free(mm.must);
3121 isl_map_free(mm.may);
3122 isl_flow_free(flow);
3125 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
3126 map = isl_map_read_from_str(ctx, str);
3127 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3129 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3130 map = isl_map_read_from_str(ctx, str);
3131 ai = isl_access_info_add_source(ai, map, 0, &depth);
3133 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
3134 map = isl_map_read_from_str(ctx, str);
3135 ai = isl_access_info_add_source(ai, map, 0, &depth);
3137 flow = isl_access_info_compute_flow(ai);
3138 dim = isl_space_alloc(ctx, 0, 3, 3);
3139 mm.must = isl_map_empty(isl_space_copy(dim));
3140 mm.may = isl_map_empty(dim);
3142 isl_flow_foreach(flow, collect_must_may, &mm);
3144 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
3145 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
3146 assert(map_is_equal(mm.may, str));
3147 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3148 assert(map_is_equal(mm.must, str));
3150 isl_map_free(mm.must);
3151 isl_map_free(mm.may);
3152 isl_flow_free(flow);
3155 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
3156 map = isl_map_read_from_str(ctx, str);
3157 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3159 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3160 map = isl_map_read_from_str(ctx, str);
3161 ai = isl_access_info_add_source(ai, map, 0, &depth);
3163 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
3164 map = isl_map_read_from_str(ctx, str);
3165 ai = isl_access_info_add_source(ai, map, 0, &depth);
3167 flow = isl_access_info_compute_flow(ai);
3168 dim = isl_space_alloc(ctx, 0, 3, 3);
3169 mm.must = isl_map_empty(isl_space_copy(dim));
3170 mm.may = isl_map_empty(dim);
3172 isl_flow_foreach(flow, collect_must_may, &mm);
3174 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
3175 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
3176 assert(map_is_equal(mm.may, str));
3177 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3178 assert(map_is_equal(mm.must, str));
3180 isl_map_free(mm.must);
3181 isl_map_free(mm.may);
3182 isl_flow_free(flow);
3185 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
3186 map = isl_map_read_from_str(ctx, str);
3187 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
3189 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
3190 map = isl_map_read_from_str(ctx, str);
3191 ai = isl_access_info_add_source(ai, map, 0, &depth);
3193 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
3194 map = isl_map_read_from_str(ctx, str);
3195 ai = isl_access_info_add_source(ai, map, 0, &depth);
3197 flow = isl_access_info_compute_flow(ai);
3198 dim = isl_space_alloc(ctx, 0, 3, 3);
3199 mm.must = isl_map_empty(isl_space_copy(dim));
3200 mm.may = isl_map_empty(dim);
3202 isl_flow_foreach(flow, collect_must_may, &mm);
3204 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
3205 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
3206 assert(map_is_equal(mm.may, str));
3207 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
3208 assert(map_is_equal(mm.must, str));
3210 isl_map_free(mm.must);
3211 isl_map_free(mm.may);
3212 isl_flow_free(flow);
3215 depth = 5;
3217 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3218 map = isl_map_read_from_str(ctx, str);
3219 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
3221 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3222 map = isl_map_read_from_str(ctx, str);
3223 ai = isl_access_info_add_source(ai, map, 1, &depth);
3225 flow = isl_access_info_compute_flow(ai);
3226 dim = isl_space_alloc(ctx, 0, 5, 5);
3227 mm.must = isl_map_empty(isl_space_copy(dim));
3228 mm.may = isl_map_empty(dim);
3230 isl_flow_foreach(flow, collect_must_may, &mm);
3232 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3233 assert(map_is_equal(mm.must, str));
3234 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3235 assert(map_is_equal(mm.may, str));
3237 isl_map_free(mm.must);
3238 isl_map_free(mm.may);
3239 isl_flow_free(flow);
3241 return 0;
3244 /* Check that the dependence analysis proceeds without errors.
3245 * Earlier versions of isl would break down during the analysis
3246 * due to the use of the wrong spaces.
3248 static int test_flow(isl_ctx *ctx)
3250 const char *str;
3251 isl_union_map *access, *schedule;
3252 isl_union_map *must_dep, *may_dep;
3253 int r;
3255 str = "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3256 access = isl_union_map_read_from_str(ctx, str);
3257 str = "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3258 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3259 "S2[] -> [1,0,0,0]; "
3260 "S3[] -> [-1,0,0,0] }";
3261 schedule = isl_union_map_read_from_str(ctx, str);
3262 r = isl_union_map_compute_flow(access, isl_union_map_copy(access),
3263 isl_union_map_copy(access), schedule,
3264 &must_dep, &may_dep, NULL, NULL);
3265 isl_union_map_free(may_dep);
3266 isl_union_map_free(must_dep);
3268 return r;
3271 struct {
3272 const char *map;
3273 int sv;
3274 } sv_tests[] = {
3275 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3276 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3277 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3278 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3279 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3280 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3281 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3282 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3283 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3286 int test_sv(isl_ctx *ctx)
3288 isl_union_map *umap;
3289 int i;
3290 int sv;
3292 for (i = 0; i < ARRAY_SIZE(sv_tests); ++i) {
3293 umap = isl_union_map_read_from_str(ctx, sv_tests[i].map);
3294 sv = isl_union_map_is_single_valued(umap);
3295 isl_union_map_free(umap);
3296 if (sv < 0)
3297 return -1;
3298 if (sv_tests[i].sv && !sv)
3299 isl_die(ctx, isl_error_internal,
3300 "map not detected as single valued", return -1);
3301 if (!sv_tests[i].sv && sv)
3302 isl_die(ctx, isl_error_internal,
3303 "map detected as single valued", return -1);
3306 return 0;
3309 struct {
3310 const char *str;
3311 int bijective;
3312 } bijective_tests[] = {
3313 { "[N,M]->{[i,j] -> [i]}", 0 },
3314 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3315 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3316 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3317 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3318 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3319 { "[N,M]->{[i,j] -> []}", 0 },
3320 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3321 { "[N,M]->{[i,j] -> [2i]}", 0 },
3322 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3323 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3324 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3325 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3328 static int test_bijective(struct isl_ctx *ctx)
3330 isl_map *map;
3331 int i;
3332 int bijective;
3334 for (i = 0; i < ARRAY_SIZE(bijective_tests); ++i) {
3335 map = isl_map_read_from_str(ctx, bijective_tests[i].str);
3336 bijective = isl_map_is_bijective(map);
3337 isl_map_free(map);
3338 if (bijective < 0)
3339 return -1;
3340 if (bijective_tests[i].bijective && !bijective)
3341 isl_die(ctx, isl_error_internal,
3342 "map not detected as bijective", return -1);
3343 if (!bijective_tests[i].bijective && bijective)
3344 isl_die(ctx, isl_error_internal,
3345 "map detected as bijective", return -1);
3348 return 0;
3351 /* Inputs for isl_pw_qpolynomial_gist tests.
3352 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3354 struct {
3355 const char *pwqp;
3356 const char *set;
3357 const char *gist;
3358 } pwqp_gist_tests[] = {
3359 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3360 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3361 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3362 "{ [i] -> -1/2 + 1/2 * i }" },
3363 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3366 static int test_pwqp(struct isl_ctx *ctx)
3368 int i;
3369 const char *str;
3370 isl_set *set;
3371 isl_pw_qpolynomial *pwqp1, *pwqp2;
3372 int equal;
3374 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3375 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3377 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
3378 isl_dim_in, 1, 1);
3380 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3381 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3383 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3385 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3387 isl_pw_qpolynomial_free(pwqp1);
3389 for (i = 0; i < ARRAY_SIZE(pwqp_gist_tests); ++i) {
3390 str = pwqp_gist_tests[i].pwqp;
3391 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3392 str = pwqp_gist_tests[i].set;
3393 set = isl_set_read_from_str(ctx, str);
3394 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
3395 str = pwqp_gist_tests[i].gist;
3396 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3397 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3398 equal = isl_pw_qpolynomial_is_zero(pwqp1);
3399 isl_pw_qpolynomial_free(pwqp1);
3401 if (equal < 0)
3402 return -1;
3403 if (!equal)
3404 isl_die(ctx, isl_error_unknown,
3405 "unexpected result", return -1);
3408 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
3409 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3410 str = "{ [i] -> ([(2 * [i/2])/5]) }";
3411 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3413 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3415 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3417 isl_pw_qpolynomial_free(pwqp1);
3419 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
3420 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3421 str = "{ [x] -> x }";
3422 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3424 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3426 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3428 isl_pw_qpolynomial_free(pwqp1);
3430 str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3431 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3432 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3433 pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
3434 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3435 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3436 isl_pw_qpolynomial_free(pwqp1);
3438 str = "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3439 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3440 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3441 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3442 set = isl_set_read_from_str(ctx, "{ [a,b,a] }");
3443 pwqp1 = isl_pw_qpolynomial_intersect_domain(pwqp1, set);
3444 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
3445 isl_pw_qpolynomial_free(pwqp1);
3446 isl_pw_qpolynomial_free(pwqp2);
3447 if (equal < 0)
3448 return -1;
3449 if (!equal)
3450 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3452 str = "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3453 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3454 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3455 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3456 pwqp1 = isl_pw_qpolynomial_fix_val(pwqp1, isl_dim_set, 1,
3457 isl_val_one(ctx));
3458 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
3459 isl_pw_qpolynomial_free(pwqp1);
3460 isl_pw_qpolynomial_free(pwqp2);
3461 if (equal < 0)
3462 return -1;
3463 if (!equal)
3464 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3466 return 0;
3469 static int test_split_periods(isl_ctx *ctx)
3471 const char *str;
3472 isl_pw_qpolynomial *pwqp;
3474 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3475 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3476 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3477 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3479 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
3481 isl_pw_qpolynomial_free(pwqp);
3483 if (!pwqp)
3484 return -1;
3486 return 0;
3489 static int test_union(isl_ctx *ctx)
3491 const char *str;
3492 isl_union_set *uset1, *uset2;
3493 isl_union_map *umap1, *umap2;
3494 int equal;
3496 str = "{ [i] : 0 <= i <= 1 }";
3497 uset1 = isl_union_set_read_from_str(ctx, str);
3498 str = "{ [1] -> [0] }";
3499 umap1 = isl_union_map_read_from_str(ctx, str);
3501 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
3502 equal = isl_union_map_is_equal(umap1, umap2);
3504 isl_union_map_free(umap1);
3505 isl_union_map_free(umap2);
3507 if (equal < 0)
3508 return -1;
3509 if (!equal)
3510 isl_die(ctx, isl_error_unknown, "union maps not equal",
3511 return -1);
3513 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3514 umap1 = isl_union_map_read_from_str(ctx, str);
3515 str = "{ A[i]; B[i] }";
3516 uset1 = isl_union_set_read_from_str(ctx, str);
3518 uset2 = isl_union_map_domain(umap1);
3520 equal = isl_union_set_is_equal(uset1, uset2);
3522 isl_union_set_free(uset1);
3523 isl_union_set_free(uset2);
3525 if (equal < 0)
3526 return -1;
3527 if (!equal)
3528 isl_die(ctx, isl_error_unknown, "union sets not equal",
3529 return -1);
3531 return 0;
3534 /* Check that computing a bound of a non-zero polynomial over an unbounded
3535 * domain does not produce a rational value.
3536 * In particular, check that the upper bound is infinity.
3538 static int test_bound_unbounded_domain(isl_ctx *ctx)
3540 const char *str;
3541 isl_pw_qpolynomial *pwqp;
3542 isl_pw_qpolynomial_fold *pwf, *pwf2;
3543 isl_bool equal;
3545 str = "{ [m,n] -> -m * n }";
3546 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3547 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3548 str = "{ infty }";
3549 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3550 pwf2 = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3551 equal = isl_pw_qpolynomial_fold_plain_is_equal(pwf, pwf2);
3552 isl_pw_qpolynomial_fold_free(pwf);
3553 isl_pw_qpolynomial_fold_free(pwf2);
3555 if (equal < 0)
3556 return -1;
3557 if (!equal)
3558 isl_die(ctx, isl_error_unknown,
3559 "expecting infinite polynomial bound", return -1);
3561 return 0;
3564 static int test_bound(isl_ctx *ctx)
3566 const char *str;
3567 isl_size dim;
3568 isl_pw_qpolynomial *pwqp;
3569 isl_pw_qpolynomial_fold *pwf;
3571 if (test_bound_unbounded_domain(ctx) < 0)
3572 return -1;
3574 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
3575 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3576 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3577 dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in);
3578 isl_pw_qpolynomial_fold_free(pwf);
3579 if (dim < 0)
3580 return -1;
3581 if (dim != 4)
3582 isl_die(ctx, isl_error_unknown, "unexpected input dimension",
3583 return -1);
3585 str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3586 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3587 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3588 dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in);
3589 isl_pw_qpolynomial_fold_free(pwf);
3590 if (dim < 0)
3591 return -1;
3592 if (dim != 1)
3593 isl_die(ctx, isl_error_unknown, "unexpected input dimension",
3594 return -1);
3596 return 0;
3599 /* isl_set is defined to isl_map internally, so the corresponding elements
3600 * are isl_basic_map objects.
3602 #undef EL_BASE
3603 #undef SET_BASE
3604 #define EL_BASE basic_map
3605 #define SET_BASE set
3606 #include "isl_test_list_templ.c"
3608 #undef EL_BASE
3609 #undef SET_BASE
3610 #define EL_BASE basic_set
3611 #define SET_BASE union_set
3612 #include "isl_test_list_templ.c"
3614 #undef EL_BASE
3615 #undef SET_BASE
3616 #define EL_BASE set
3617 #define SET_BASE union_set
3618 #include "isl_test_list_templ.c"
3620 #undef EL_BASE
3621 #undef SET_BASE
3622 #define EL_BASE basic_map
3623 #define SET_BASE map
3624 #include "isl_test_list_templ.c"
3626 #undef EL_BASE
3627 #undef SET_BASE
3628 #define EL_BASE map
3629 #define SET_BASE union_map
3630 #include "isl_test_list_templ.c"
3632 /* Check that the conversion from isl objects to lists works as expected.
3634 static int test_get_list(isl_ctx *ctx)
3636 if (test_get_list_basic_map_from_set(ctx, "{ [0]; [2]; [3] }"))
3637 return -1;
3638 if (test_get_list_basic_set_from_union_set(ctx, "{ A[0]; B[2]; B[3] }"))
3639 return -1;
3640 if (test_get_list_set_from_union_set(ctx, "{ A[0]; A[2]; B[3] }"))
3641 return -1;
3642 if (test_get_list_basic_map_from_map(ctx,
3643 "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }"))
3644 return -1;
3645 if (test_get_list_map_from_union_map(ctx,
3646 "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }"))
3647 return -1;
3649 return 0;
3652 static int test_lift(isl_ctx *ctx)
3654 const char *str;
3655 isl_basic_map *bmap;
3656 isl_basic_set *bset;
3658 str = "{ [i0] : exists e0 : i0 = 4e0 }";
3659 bset = isl_basic_set_read_from_str(ctx, str);
3660 bset = isl_basic_set_lift(bset);
3661 bmap = isl_basic_map_from_range(bset);
3662 bset = isl_basic_map_domain(bmap);
3663 isl_basic_set_free(bset);
3665 return 0;
3668 /* Check that isl_set_is_subset is not confused by identical
3669 * integer divisions.
3670 * The call to isl_set_normalize ensures that the equality constraints
3671 * a = b = 0 are discovered, turning e0 and e1 into identical
3672 * integer divisions. Any further simplification would remove
3673 * the duplicate integer divisions.
3675 static isl_stat test_subset_duplicate_integer_divisions(isl_ctx *ctx)
3677 const char *str;
3678 isl_bool is_subset;
3679 isl_set *set1, *set2;
3681 str = "{ [a, b, c, d] : "
3682 "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), "
3683 "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), "
3684 "e3 = floor((-d + 4*floor((d)/4))/10): "
3685 "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and "
3686 "b >= 0 and a <= 0 and b <= a) }";
3687 set1 = isl_set_read_from_str(ctx, str);
3688 set2 = isl_set_read_from_str(ctx, str);
3689 set2 = isl_set_normalize(set2);
3691 is_subset = isl_set_is_subset(set1, set2);
3693 isl_set_free(set1);
3694 isl_set_free(set2);
3696 if (is_subset < 0)
3697 return isl_stat_error;
3698 if (!is_subset)
3699 isl_die(ctx, isl_error_unknown,
3700 "set is not considered to be a subset of itself",
3701 return isl_stat_error);
3703 return isl_stat_ok;
3706 struct {
3707 const char *set1;
3708 const char *set2;
3709 int subset;
3710 } subset_tests[] = {
3711 { "{ [112, 0] }",
3712 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3713 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3714 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3715 { "{ [65] }",
3716 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3717 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3718 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3719 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3720 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3721 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3722 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3723 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3724 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3725 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3726 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3727 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3728 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3729 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3730 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3731 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3732 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3733 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3734 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3735 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3736 "4e0 <= -57 + i0 + i1)) or "
3737 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3738 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3739 "4e0 >= -61 + i0 + i1)) or "
3740 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3741 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3744 static int test_subset(isl_ctx *ctx)
3746 int i;
3747 isl_set *set1, *set2;
3748 int subset;
3750 if (test_subset_duplicate_integer_divisions(ctx) < 0)
3751 return -1;
3753 for (i = 0; i < ARRAY_SIZE(subset_tests); ++i) {
3754 set1 = isl_set_read_from_str(ctx, subset_tests[i].set1);
3755 set2 = isl_set_read_from_str(ctx, subset_tests[i].set2);
3756 subset = isl_set_is_subset(set1, set2);
3757 isl_set_free(set1);
3758 isl_set_free(set2);
3759 if (subset < 0)
3760 return -1;
3761 if (subset != subset_tests[i].subset)
3762 isl_die(ctx, isl_error_unknown,
3763 "incorrect subset result", return -1);
3766 return 0;
3769 struct {
3770 const char *minuend;
3771 const char *subtrahend;
3772 const char *difference;
3773 } subtract_domain_tests[] = {
3774 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
3775 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
3776 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
3779 static int test_subtract(isl_ctx *ctx)
3781 int i;
3782 isl_union_map *umap1, *umap2;
3783 isl_union_pw_multi_aff *upma1, *upma2;
3784 isl_union_set *uset;
3785 int equal;
3787 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests); ++i) {
3788 umap1 = isl_union_map_read_from_str(ctx,
3789 subtract_domain_tests[i].minuend);
3790 uset = isl_union_set_read_from_str(ctx,
3791 subtract_domain_tests[i].subtrahend);
3792 umap2 = isl_union_map_read_from_str(ctx,
3793 subtract_domain_tests[i].difference);
3794 umap1 = isl_union_map_subtract_domain(umap1, uset);
3795 equal = isl_union_map_is_equal(umap1, umap2);
3796 isl_union_map_free(umap1);
3797 isl_union_map_free(umap2);
3798 if (equal < 0)
3799 return -1;
3800 if (!equal)
3801 isl_die(ctx, isl_error_unknown,
3802 "incorrect subtract domain result", return -1);
3805 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests); ++i) {
3806 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
3807 subtract_domain_tests[i].minuend);
3808 uset = isl_union_set_read_from_str(ctx,
3809 subtract_domain_tests[i].subtrahend);
3810 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
3811 subtract_domain_tests[i].difference);
3812 upma1 = isl_union_pw_multi_aff_subtract_domain(upma1, uset);
3813 equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2);
3814 isl_union_pw_multi_aff_free(upma1);
3815 isl_union_pw_multi_aff_free(upma2);
3816 if (equal < 0)
3817 return -1;
3818 if (!equal)
3819 isl_die(ctx, isl_error_unknown,
3820 "incorrect subtract domain result", return -1);
3823 return 0;
3826 /* Check that intersecting the empty basic set with another basic set
3827 * does not increase the number of constraints. In particular,
3828 * the empty basic set should maintain its canonical representation.
3830 static int test_intersect_1(isl_ctx *ctx)
3832 isl_size n1, n2;
3833 isl_basic_set *bset1, *bset2;
3835 bset1 = isl_basic_set_read_from_str(ctx, "{ [a,b,c] : 1 = 0 }");
3836 bset2 = isl_basic_set_read_from_str(ctx, "{ [1,2,3] }");
3837 n1 = isl_basic_set_n_constraint(bset1);
3838 bset1 = isl_basic_set_intersect(bset1, bset2);
3839 n2 = isl_basic_set_n_constraint(bset1);
3840 isl_basic_set_free(bset1);
3841 if (n1 < 0 || n2 < 0)
3842 return -1;
3843 if (n1 != n2)
3844 isl_die(ctx, isl_error_unknown,
3845 "number of constraints of empty set changed",
3846 return -1);
3848 return 0;
3851 /* Check that intersecting a set with itself does not cause
3852 * an explosion in the number of disjuncts.
3854 static isl_stat test_intersect_2(isl_ctx *ctx)
3856 int i;
3857 isl_set *set;
3859 set = isl_set_read_from_str(ctx, "{ [x,y] : x >= 0 or y >= 0 }");
3860 for (i = 0; i < 100; ++i)
3861 set = isl_set_intersect(set, isl_set_copy(set));
3862 isl_set_free(set);
3863 if (!set)
3864 return isl_stat_error;
3865 return isl_stat_ok;
3868 /* Perform some intersection tests.
3870 static int test_intersect(isl_ctx *ctx)
3872 if (test_intersect_1(ctx) < 0)
3873 return -1;
3874 if (test_intersect_2(ctx) < 0)
3875 return -1;
3877 return 0;
3880 int test_factorize(isl_ctx *ctx)
3882 const char *str;
3883 isl_basic_set *bset;
3884 isl_factorizer *f;
3886 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
3887 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
3888 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
3889 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
3890 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
3891 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
3892 "3i5 >= -2i0 - i2 + 3i4 }";
3893 bset = isl_basic_set_read_from_str(ctx, str);
3894 f = isl_basic_set_factorizer(bset);
3895 isl_basic_set_free(bset);
3896 isl_factorizer_free(f);
3897 if (!f)
3898 isl_die(ctx, isl_error_unknown,
3899 "failed to construct factorizer", return -1);
3901 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
3902 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
3903 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
3904 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
3905 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
3906 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
3907 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
3908 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
3909 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
3910 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
3911 bset = isl_basic_set_read_from_str(ctx, str);
3912 f = isl_basic_set_factorizer(bset);
3913 isl_basic_set_free(bset);
3914 isl_factorizer_free(f);
3915 if (!f)
3916 isl_die(ctx, isl_error_unknown,
3917 "failed to construct factorizer", return -1);
3919 return 0;
3922 static isl_stat check_injective(__isl_take isl_map *map, void *user)
3924 int *injective = user;
3926 *injective = isl_map_is_injective(map);
3927 isl_map_free(map);
3929 if (*injective < 0 || !*injective)
3930 return isl_stat_error;
3932 return isl_stat_ok;
3935 int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
3936 const char *r, const char *s, int tilable, int parallel)
3938 int i;
3939 isl_union_set *D;
3940 isl_union_map *W, *R, *S;
3941 isl_union_map *empty;
3942 isl_union_map *dep_raw, *dep_war, *dep_waw, *dep;
3943 isl_union_map *validity, *proximity, *coincidence;
3944 isl_union_map *schedule;
3945 isl_union_map *test;
3946 isl_union_set *delta;
3947 isl_union_set *domain;
3948 isl_set *delta_set;
3949 isl_set *slice;
3950 isl_set *origin;
3951 isl_schedule_constraints *sc;
3952 isl_schedule *sched;
3953 int is_nonneg, is_parallel, is_tilable, is_injection, is_complete;
3954 isl_size n;
3956 D = isl_union_set_read_from_str(ctx, d);
3957 W = isl_union_map_read_from_str(ctx, w);
3958 R = isl_union_map_read_from_str(ctx, r);
3959 S = isl_union_map_read_from_str(ctx, s);
3961 W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
3962 R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
3964 empty = isl_union_map_empty(isl_union_map_get_space(S));
3965 isl_union_map_compute_flow(isl_union_map_copy(R),
3966 isl_union_map_copy(W), empty,
3967 isl_union_map_copy(S),
3968 &dep_raw, NULL, NULL, NULL);
3969 isl_union_map_compute_flow(isl_union_map_copy(W),
3970 isl_union_map_copy(W),
3971 isl_union_map_copy(R),
3972 isl_union_map_copy(S),
3973 &dep_waw, &dep_war, NULL, NULL);
3975 dep = isl_union_map_union(dep_waw, dep_war);
3976 dep = isl_union_map_union(dep, dep_raw);
3977 validity = isl_union_map_copy(dep);
3978 coincidence = isl_union_map_copy(dep);
3979 proximity = isl_union_map_copy(dep);
3981 sc = isl_schedule_constraints_on_domain(isl_union_set_copy(D));
3982 sc = isl_schedule_constraints_set_validity(sc, validity);
3983 sc = isl_schedule_constraints_set_coincidence(sc, coincidence);
3984 sc = isl_schedule_constraints_set_proximity(sc, proximity);
3985 sched = isl_schedule_constraints_compute_schedule(sc);
3986 schedule = isl_schedule_get_map(sched);
3987 isl_schedule_free(sched);
3988 isl_union_map_free(W);
3989 isl_union_map_free(R);
3990 isl_union_map_free(S);
3992 is_injection = 1;
3993 isl_union_map_foreach_map(schedule, &check_injective, &is_injection);
3995 domain = isl_union_map_domain(isl_union_map_copy(schedule));
3996 is_complete = isl_union_set_is_subset(D, domain);
3997 isl_union_set_free(D);
3998 isl_union_set_free(domain);
4000 test = isl_union_map_reverse(isl_union_map_copy(schedule));
4001 test = isl_union_map_apply_range(test, dep);
4002 test = isl_union_map_apply_range(test, schedule);
4004 delta = isl_union_map_deltas(test);
4005 n = isl_union_set_n_set(delta);
4006 if (n < 0) {
4007 isl_union_set_free(delta);
4008 return -1;
4010 if (n == 0) {
4011 is_tilable = 1;
4012 is_parallel = 1;
4013 is_nonneg = 1;
4014 isl_union_set_free(delta);
4015 } else {
4016 isl_size dim;
4018 delta_set = isl_set_from_union_set(delta);
4020 slice = isl_set_universe(isl_set_get_space(delta_set));
4021 for (i = 0; i < tilable; ++i)
4022 slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
4023 is_tilable = isl_set_is_subset(delta_set, slice);
4024 isl_set_free(slice);
4026 slice = isl_set_universe(isl_set_get_space(delta_set));
4027 for (i = 0; i < parallel; ++i)
4028 slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
4029 is_parallel = isl_set_is_subset(delta_set, slice);
4030 isl_set_free(slice);
4032 origin = isl_set_universe(isl_set_get_space(delta_set));
4033 dim = isl_set_dim(origin, isl_dim_set);
4034 if (dim < 0)
4035 origin = isl_set_free(origin);
4036 for (i = 0; i < dim; ++i)
4037 origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
4039 delta_set = isl_set_union(delta_set, isl_set_copy(origin));
4040 delta_set = isl_set_lexmin(delta_set);
4042 is_nonneg = isl_set_is_equal(delta_set, origin);
4044 isl_set_free(origin);
4045 isl_set_free(delta_set);
4048 if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
4049 is_injection < 0 || is_complete < 0)
4050 return -1;
4051 if (!is_complete)
4052 isl_die(ctx, isl_error_unknown,
4053 "generated schedule incomplete", return -1);
4054 if (!is_injection)
4055 isl_die(ctx, isl_error_unknown,
4056 "generated schedule not injective on each statement",
4057 return -1);
4058 if (!is_nonneg)
4059 isl_die(ctx, isl_error_unknown,
4060 "negative dependences in generated schedule",
4061 return -1);
4062 if (!is_tilable)
4063 isl_die(ctx, isl_error_unknown,
4064 "generated schedule not as tilable as expected",
4065 return -1);
4066 if (!is_parallel)
4067 isl_die(ctx, isl_error_unknown,
4068 "generated schedule not as parallel as expected",
4069 return -1);
4071 return 0;
4074 /* Compute a schedule for the given instance set, validity constraints,
4075 * proximity constraints and context and return a corresponding union map
4076 * representation.
4078 static __isl_give isl_union_map *compute_schedule_with_context(isl_ctx *ctx,
4079 const char *domain, const char *validity, const char *proximity,
4080 const char *context)
4082 isl_set *con;
4083 isl_union_set *dom;
4084 isl_union_map *dep;
4085 isl_union_map *prox;
4086 isl_schedule_constraints *sc;
4087 isl_schedule *schedule;
4088 isl_union_map *sched;
4090 con = isl_set_read_from_str(ctx, context);
4091 dom = isl_union_set_read_from_str(ctx, domain);
4092 dep = isl_union_map_read_from_str(ctx, validity);
4093 prox = isl_union_map_read_from_str(ctx, proximity);
4094 sc = isl_schedule_constraints_on_domain(dom);
4095 sc = isl_schedule_constraints_set_context(sc, con);
4096 sc = isl_schedule_constraints_set_validity(sc, dep);
4097 sc = isl_schedule_constraints_set_proximity(sc, prox);
4098 schedule = isl_schedule_constraints_compute_schedule(sc);
4099 sched = isl_schedule_get_map(schedule);
4100 isl_schedule_free(schedule);
4102 return sched;
4105 /* Compute a schedule for the given instance set, validity constraints and
4106 * proximity constraints and return a corresponding union map representation.
4108 static __isl_give isl_union_map *compute_schedule(isl_ctx *ctx,
4109 const char *domain, const char *validity, const char *proximity)
4111 return compute_schedule_with_context(ctx, domain, validity, proximity,
4112 "{ : }");
4115 /* Check that a schedule can be constructed on the given domain
4116 * with the given validity and proximity constraints.
4118 static int test_has_schedule(isl_ctx *ctx, const char *domain,
4119 const char *validity, const char *proximity)
4121 isl_union_map *sched;
4123 sched = compute_schedule(ctx, domain, validity, proximity);
4124 if (!sched)
4125 return -1;
4127 isl_union_map_free(sched);
4128 return 0;
4131 int test_special_schedule(isl_ctx *ctx, const char *domain,
4132 const char *validity, const char *proximity, const char *expected_sched)
4134 isl_union_map *sched1, *sched2;
4135 int equal;
4137 sched1 = compute_schedule(ctx, domain, validity, proximity);
4138 sched2 = isl_union_map_read_from_str(ctx, expected_sched);
4140 equal = isl_union_map_is_equal(sched1, sched2);
4141 isl_union_map_free(sched1);
4142 isl_union_map_free(sched2);
4144 if (equal < 0)
4145 return -1;
4146 if (!equal)
4147 isl_die(ctx, isl_error_unknown, "unexpected schedule",
4148 return -1);
4150 return 0;
4153 /* Check that the schedule map is properly padded, i.e., that the range
4154 * lives in a single space.
4156 static int test_padded_schedule(isl_ctx *ctx)
4158 const char *str;
4159 isl_union_set *D;
4160 isl_union_map *validity, *proximity;
4161 isl_schedule_constraints *sc;
4162 isl_schedule *sched;
4163 isl_union_map *umap;
4164 isl_union_set *range;
4165 isl_set *set;
4167 str = "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
4168 D = isl_union_set_read_from_str(ctx, str);
4169 validity = isl_union_map_empty(isl_union_set_get_space(D));
4170 proximity = isl_union_map_copy(validity);
4171 sc = isl_schedule_constraints_on_domain(D);
4172 sc = isl_schedule_constraints_set_validity(sc, validity);
4173 sc = isl_schedule_constraints_set_proximity(sc, proximity);
4174 sched = isl_schedule_constraints_compute_schedule(sc);
4175 umap = isl_schedule_get_map(sched);
4176 isl_schedule_free(sched);
4177 range = isl_union_map_range(umap);
4178 set = isl_set_from_union_set(range);
4179 isl_set_free(set);
4181 if (!set)
4182 return -1;
4184 return 0;
4187 /* Check that conditional validity constraints are also taken into
4188 * account across bands.
4189 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
4190 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
4191 * and then check that the adjacent order constraint C[2,1]->D[2,0]
4192 * is enforced by the rest of the schedule.
4194 static int test_special_conditional_schedule_constraints(isl_ctx *ctx)
4196 const char *str;
4197 isl_union_set *domain;
4198 isl_union_map *validity, *proximity, *condition;
4199 isl_union_map *sink, *source, *dep;
4200 isl_schedule_constraints *sc;
4201 isl_schedule *schedule;
4202 isl_union_access_info *access;
4203 isl_union_flow *flow;
4204 int empty;
4206 str = "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4207 "A[k] : k >= 1 and k <= -1 + n; "
4208 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
4209 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
4210 domain = isl_union_set_read_from_str(ctx, str);
4211 sc = isl_schedule_constraints_on_domain(domain);
4212 str = "[n] -> { D[k, i] -> C[1 + k, k - i] : "
4213 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4214 "D[k, i] -> C[1 + k, i] : "
4215 "k <= -2 + n and i >= 1 and i <= -1 + k; "
4216 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
4217 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
4218 validity = isl_union_map_read_from_str(ctx, str);
4219 sc = isl_schedule_constraints_set_validity(sc, validity);
4220 str = "[n] -> { C[k, i] -> D[k, i] : "
4221 "0 <= i <= -1 + k and k <= -1 + n }";
4222 proximity = isl_union_map_read_from_str(ctx, str);
4223 sc = isl_schedule_constraints_set_proximity(sc, proximity);
4224 str = "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
4225 "i <= -1 + k and i >= 1 and k <= -2 + n; "
4226 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
4227 "k <= -1 + n and i >= 0 and i <= -2 + k }";
4228 condition = isl_union_map_read_from_str(ctx, str);
4229 str = "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
4230 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4231 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
4232 "i >= 0 and i <= -1 + k and k <= -1 + n and "
4233 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
4234 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
4235 "i >= 0 and i <= -1 + k and k <= -1 + n; "
4236 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
4237 "k <= -1 + n and i >= 0 and i <= -1 + k and "
4238 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
4239 validity = isl_union_map_read_from_str(ctx, str);
4240 sc = isl_schedule_constraints_set_conditional_validity(sc, condition,
4241 validity);
4242 schedule = isl_schedule_constraints_compute_schedule(sc);
4243 str = "{ D[2,0] -> [] }";
4244 sink = isl_union_map_read_from_str(ctx, str);
4245 access = isl_union_access_info_from_sink(sink);
4246 str = "{ C[2,1] -> [] }";
4247 source = isl_union_map_read_from_str(ctx, str);
4248 access = isl_union_access_info_set_must_source(access, source);
4249 access = isl_union_access_info_set_schedule(access, schedule);
4250 flow = isl_union_access_info_compute_flow(access);
4251 dep = isl_union_flow_get_must_dependence(flow);
4252 isl_union_flow_free(flow);
4253 empty = isl_union_map_is_empty(dep);
4254 isl_union_map_free(dep);
4256 if (empty < 0)
4257 return -1;
4258 if (empty)
4259 isl_die(ctx, isl_error_unknown,
4260 "conditional validity not respected", return -1);
4262 return 0;
4265 /* Check that the test for violated conditional validity constraints
4266 * is not confused by domain compression.
4267 * In particular, earlier versions of isl would apply
4268 * a schedule on the compressed domains to the original domains,
4269 * resulting in a failure to detect that the default schedule
4270 * violates the conditional validity constraints.
4272 static int test_special_conditional_schedule_constraints_2(isl_ctx *ctx)
4274 const char *str;
4275 isl_bool empty;
4276 isl_union_set *domain;
4277 isl_union_map *validity, *condition;
4278 isl_schedule_constraints *sc;
4279 isl_schedule *schedule;
4280 isl_union_map *umap;
4281 isl_map *map, *ge;
4283 str = "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
4284 domain = isl_union_set_read_from_str(ctx, str);
4285 sc = isl_schedule_constraints_on_domain(domain);
4286 str = "{ B[1, i] -> A[0, i + 1] }";
4287 condition = isl_union_map_read_from_str(ctx, str);
4288 str = "{ A[0, i] -> B[1, i - 1] }";
4289 validity = isl_union_map_read_from_str(ctx, str);
4290 sc = isl_schedule_constraints_set_conditional_validity(sc, condition,
4291 isl_union_map_copy(validity));
4292 schedule = isl_schedule_constraints_compute_schedule(sc);
4293 umap = isl_schedule_get_map(schedule);
4294 isl_schedule_free(schedule);
4295 validity = isl_union_map_apply_domain(validity,
4296 isl_union_map_copy(umap));
4297 validity = isl_union_map_apply_range(validity, umap);
4298 map = isl_map_from_union_map(validity);
4299 ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map)));
4300 map = isl_map_intersect(map, ge);
4301 empty = isl_map_is_empty(map);
4302 isl_map_free(map);
4304 if (empty < 0)
4305 return -1;
4306 if (!empty)
4307 isl_die(ctx, isl_error_unknown,
4308 "conditional validity constraints not satisfied",
4309 return -1);
4311 return 0;
4314 /* Input for testing of schedule construction based on
4315 * conditional constraints.
4317 * domain is the iteration domain
4318 * flow are the flow dependences, which determine the validity and
4319 * proximity constraints
4320 * condition are the conditions on the conditional validity constraints
4321 * conditional_validity are the conditional validity constraints
4322 * outer_band_n is the expected number of members in the outer band
4324 struct {
4325 const char *domain;
4326 const char *flow;
4327 const char *condition;
4328 const char *conditional_validity;
4329 int outer_band_n;
4330 } live_range_tests[] = {
4331 /* Contrived example that illustrates that we need to keep
4332 * track of tagged condition dependences and
4333 * tagged conditional validity dependences
4334 * in isl_sched_edge separately.
4335 * In particular, the conditional validity constraints on A
4336 * cannot be satisfied,
4337 * but they can be ignored because there are no corresponding
4338 * condition constraints. However, we do have an additional
4339 * conditional validity constraint that maps to the same
4340 * dependence relation
4341 * as the condition constraint on B. If we did not make a distinction
4342 * between tagged condition and tagged conditional validity
4343 * dependences, then we
4344 * could end up treating this shared dependence as an condition
4345 * constraint on A, forcing a localization of the conditions,
4346 * which is impossible.
4348 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
4349 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
4350 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4351 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4352 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4353 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4356 /* TACO 2013 Fig. 7 */
4357 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4358 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4359 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4360 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4361 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4362 "0 <= i < n and 0 <= j < n - 1 }",
4363 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4364 "0 <= i < n and 0 <= j < j' < n;"
4365 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4366 "0 <= i < i' < n and 0 <= j,j' < n;"
4367 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4368 "0 <= i,j,j' < n and j < j' }",
4371 /* TACO 2013 Fig. 7, without tags */
4372 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4373 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4374 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4375 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4376 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4377 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4378 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4379 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4382 /* TACO 2013 Fig. 12 */
4383 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4384 "S3[i,3] : 0 <= i <= 1 }",
4385 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4386 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4387 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4388 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4389 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4390 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4391 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4392 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4393 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4394 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4395 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4400 /* Test schedule construction based on conditional constraints.
4401 * In particular, check the number of members in the outer band node
4402 * as an indication of whether tiling is possible or not.
4404 static int test_conditional_schedule_constraints(isl_ctx *ctx)
4406 int i;
4407 isl_union_set *domain;
4408 isl_union_map *condition;
4409 isl_union_map *flow;
4410 isl_union_map *validity;
4411 isl_schedule_constraints *sc;
4412 isl_schedule *schedule;
4413 isl_schedule_node *node;
4414 isl_size n_member;
4416 if (test_special_conditional_schedule_constraints(ctx) < 0)
4417 return -1;
4418 if (test_special_conditional_schedule_constraints_2(ctx) < 0)
4419 return -1;
4421 for (i = 0; i < ARRAY_SIZE(live_range_tests); ++i) {
4422 domain = isl_union_set_read_from_str(ctx,
4423 live_range_tests[i].domain);
4424 flow = isl_union_map_read_from_str(ctx,
4425 live_range_tests[i].flow);
4426 condition = isl_union_map_read_from_str(ctx,
4427 live_range_tests[i].condition);
4428 validity = isl_union_map_read_from_str(ctx,
4429 live_range_tests[i].conditional_validity);
4430 sc = isl_schedule_constraints_on_domain(domain);
4431 sc = isl_schedule_constraints_set_validity(sc,
4432 isl_union_map_copy(flow));
4433 sc = isl_schedule_constraints_set_proximity(sc, flow);
4434 sc = isl_schedule_constraints_set_conditional_validity(sc,
4435 condition, validity);
4436 schedule = isl_schedule_constraints_compute_schedule(sc);
4437 node = isl_schedule_get_root(schedule);
4438 while (node &&
4439 isl_schedule_node_get_type(node) != isl_schedule_node_band)
4440 node = isl_schedule_node_first_child(node);
4441 n_member = isl_schedule_node_band_n_member(node);
4442 isl_schedule_node_free(node);
4443 isl_schedule_free(schedule);
4445 if (!schedule || n_member < 0)
4446 return -1;
4447 if (n_member != live_range_tests[i].outer_band_n)
4448 isl_die(ctx, isl_error_unknown,
4449 "unexpected number of members in outer band",
4450 return -1);
4452 return 0;
4455 /* Check that the schedule computed for the given instance set and
4456 * dependence relation strongly satisfies the dependences.
4457 * In particular, check that no instance is scheduled before
4458 * or together with an instance on which it depends.
4459 * Earlier versions of isl would produce a schedule that
4460 * only weakly satisfies the dependences.
4462 static int test_strongly_satisfying_schedule(isl_ctx *ctx)
4464 const char *domain, *dep;
4465 isl_union_map *D, *schedule;
4466 isl_map *map, *ge;
4467 int empty;
4469 domain = "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4470 "A[i0] : 0 <= i0 <= 1 }";
4471 dep = "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4472 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4473 schedule = compute_schedule(ctx, domain, dep, dep);
4474 D = isl_union_map_read_from_str(ctx, dep);
4475 D = isl_union_map_apply_domain(D, isl_union_map_copy(schedule));
4476 D = isl_union_map_apply_range(D, schedule);
4477 map = isl_map_from_union_map(D);
4478 ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map)));
4479 map = isl_map_intersect(map, ge);
4480 empty = isl_map_is_empty(map);
4481 isl_map_free(map);
4483 if (empty < 0)
4484 return -1;
4485 if (!empty)
4486 isl_die(ctx, isl_error_unknown,
4487 "dependences not strongly satisfied", return -1);
4489 return 0;
4492 /* Compute a schedule for input where the instance set constraints
4493 * conflict with the context constraints.
4494 * Earlier versions of isl did not properly handle this situation.
4496 static int test_conflicting_context_schedule(isl_ctx *ctx)
4498 isl_union_map *schedule;
4499 const char *domain, *context;
4501 domain = "[n] -> { A[] : n >= 0 }";
4502 context = "[n] -> { : n < 0 }";
4503 schedule = compute_schedule_with_context(ctx,
4504 domain, "{}", "{}", context);
4505 isl_union_map_free(schedule);
4507 if (!schedule)
4508 return -1;
4510 return 0;
4513 /* Check that a set of schedule constraints that only allow for
4514 * a coalescing schedule still produces a schedule even if the user
4515 * request a non-coalescing schedule. Earlier versions of isl
4516 * would not handle this case correctly.
4518 static int test_coalescing_schedule(isl_ctx *ctx)
4520 const char *domain, *dep;
4521 isl_union_set *I;
4522 isl_union_map *D;
4523 isl_schedule_constraints *sc;
4524 isl_schedule *schedule;
4525 int treat_coalescing;
4527 domain = "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4528 dep = "{ S[a, b] -> S[a + b, 1 - b] }";
4529 I = isl_union_set_read_from_str(ctx, domain);
4530 D = isl_union_map_read_from_str(ctx, dep);
4531 sc = isl_schedule_constraints_on_domain(I);
4532 sc = isl_schedule_constraints_set_validity(sc, D);
4533 treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx);
4534 isl_options_set_schedule_treat_coalescing(ctx, 1);
4535 schedule = isl_schedule_constraints_compute_schedule(sc);
4536 isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing);
4537 isl_schedule_free(schedule);
4538 if (!schedule)
4539 return -1;
4540 return 0;
4543 /* Check that the scheduler does not perform any needless
4544 * compound skewing. Earlier versions of isl would compute
4545 * schedules in terms of transformed schedule coefficients and
4546 * would not accurately keep track of the sum of the original
4547 * schedule coefficients. It could then produce the schedule
4548 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4549 * for the input below instead of the schedule below.
4551 static int test_skewing_schedule(isl_ctx *ctx)
4553 const char *D, *V, *P, *S;
4555 D = "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4556 V = "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4557 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4558 "-1 <= a-i + b-j + c-k <= 1 }";
4559 P = "{ }";
4560 S = "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4562 return test_special_schedule(ctx, D, V, P, S);
4565 int test_schedule(isl_ctx *ctx)
4567 const char *D, *W, *R, *V, *P, *S;
4568 int max_coincidence;
4569 int treat_coalescing;
4571 /* Handle resulting schedule with zero bands. */
4572 if (test_one_schedule(ctx, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4573 return -1;
4575 /* Jacobi */
4576 D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4577 W = "{ S1[t,i] -> a[t,i] }";
4578 R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4579 "S1[t,i] -> a[t-1,i+1] }";
4580 S = "{ S1[t,i] -> [t,i] }";
4581 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4582 return -1;
4584 /* Fig. 5 of CC2008 */
4585 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4586 "j <= -1 + N }";
4587 W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4588 "j >= 2 and j <= -1 + N }";
4589 R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4590 "j >= 2 and j <= -1 + N; "
4591 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4592 "j >= 2 and j <= -1 + N }";
4593 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4594 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4595 return -1;
4597 D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4598 W = "{ S1[i] -> a[i] }";
4599 R = "{ S2[i] -> a[i+1] }";
4600 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4601 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4602 return -1;
4604 D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4605 W = "{ S1[i] -> a[i] }";
4606 R = "{ S2[i] -> a[9-i] }";
4607 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4608 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4609 return -1;
4611 D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4612 W = "{ S1[i] -> a[i] }";
4613 R = "[N] -> { S2[i] -> a[N-1-i] }";
4614 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4615 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4616 return -1;
4618 D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4619 W = "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4620 R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4621 S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4622 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4623 return -1;
4625 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4626 W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4627 R = "{ S2[i,j] -> a[i-1,j] }";
4628 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4629 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
4630 return -1;
4632 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4633 W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4634 R = "{ S2[i,j] -> a[i,j-1] }";
4635 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4636 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
4637 return -1;
4639 D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4640 W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4641 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4642 R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4643 S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4644 "S_0[] -> [0, 0, 0] }";
4645 if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0)
4646 return -1;
4647 ctx->opt->schedule_parametric = 0;
4648 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4649 return -1;
4650 ctx->opt->schedule_parametric = 1;
4652 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4653 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4654 W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4655 R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4656 "S4[i] -> a[i,N] }";
4657 S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4658 "S4[i] -> [4,i,0] }";
4659 max_coincidence = isl_options_get_schedule_maximize_coincidence(ctx);
4660 isl_options_set_schedule_maximize_coincidence(ctx, 0);
4661 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4662 return -1;
4663 isl_options_set_schedule_maximize_coincidence(ctx, max_coincidence);
4665 D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4666 W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4667 "j <= N }";
4668 R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4669 "j <= N; "
4670 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4671 "j <= N }";
4672 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4673 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4674 return -1;
4676 D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4677 " S_2[t] : t >= 0 and t <= -1 + N; "
4678 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4679 "i <= -1 + N }";
4680 W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4681 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4682 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4683 "i >= 0 and i <= -1 + N }";
4684 R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4685 "i >= 0 and i <= -1 + N; "
4686 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4687 S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4688 " S_0[t] -> [0, t, 0] }";
4690 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
4691 return -1;
4692 ctx->opt->schedule_parametric = 0;
4693 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4694 return -1;
4695 ctx->opt->schedule_parametric = 1;
4697 D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4698 S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4699 if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0)
4700 return -1;
4702 D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4703 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4704 W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4705 "j >= 0 and j <= -1 + N; "
4706 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4707 R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4708 "j >= 0 and j <= -1 + N; "
4709 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4710 S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4711 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4712 return -1;
4714 D = "{ S_0[i] : i >= 0 }";
4715 W = "{ S_0[i] -> a[i] : i >= 0 }";
4716 R = "{ S_0[i] -> a[0] : i >= 0 }";
4717 S = "{ S_0[i] -> [0, i, 0] }";
4718 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4719 return -1;
4721 D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
4722 W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
4723 R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
4724 S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
4725 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4726 return -1;
4728 D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
4729 "k <= -1 + n and k >= 0 }";
4730 W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
4731 R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
4732 "k <= -1 + n and k >= 0; "
4733 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
4734 "k <= -1 + n and k >= 0; "
4735 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
4736 "k <= -1 + n and k >= 0 }";
4737 S = "[n] -> { S_0[j, k] -> [2, j, k] }";
4738 ctx->opt->schedule_outer_coincidence = 1;
4739 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4740 return -1;
4741 ctx->opt->schedule_outer_coincidence = 0;
4743 D = "{Stmt_for_body24[i0, i1, i2, i3]:"
4744 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
4745 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
4746 "Stmt_for_body24[i0, i1, 1, 0]:"
4747 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
4748 "Stmt_for_body7[i0, i1, i2]:"
4749 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
4750 "i2 <= 7 }";
4752 V = "{Stmt_for_body24[0, i1, i2, i3] -> "
4753 "Stmt_for_body24[1, i1, i2, i3]:"
4754 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
4755 "i2 >= 1;"
4756 "Stmt_for_body24[0, i1, i2, i3] -> "
4757 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
4758 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
4759 "i3 >= 0;"
4760 "Stmt_for_body24[0, i1, i2, i3] ->"
4761 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
4762 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
4763 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
4764 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
4765 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
4766 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
4767 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
4768 "i1 <= 6 and i1 >= 0;"
4769 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
4770 "Stmt_for_body7[i0, i1, i2] -> "
4771 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
4772 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
4773 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
4774 "Stmt_for_body7[i0, i1, i2] -> "
4775 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
4776 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
4777 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
4778 P = V;
4780 treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx);
4781 isl_options_set_schedule_treat_coalescing(ctx, 0);
4782 if (test_has_schedule(ctx, D, V, P) < 0)
4783 return -1;
4784 isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing);
4786 D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
4787 V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
4788 "j >= 1 and j <= 7;"
4789 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
4790 "j >= 1 and j <= 8 }";
4791 P = "{ }";
4792 S = "{ S_0[i, j] -> [i + j, i] }";
4793 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
4794 if (test_special_schedule(ctx, D, V, P, S) < 0)
4795 return -1;
4796 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
4798 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
4799 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
4800 "j >= 0 and j <= -1 + i }";
4801 V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
4802 "i <= -1 + N and j >= 0;"
4803 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
4804 "i <= -2 + N }";
4805 P = "{ }";
4806 S = "{ S_0[i, j] -> [i, j] }";
4807 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
4808 if (test_special_schedule(ctx, D, V, P, S) < 0)
4809 return -1;
4810 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
4812 /* Test both algorithms on a case with only proximity dependences. */
4813 D = "{ S[i,j] : 0 <= i <= 10 }";
4814 V = "{ }";
4815 P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
4816 S = "{ S[i, j] -> [j, i] }";
4817 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
4818 if (test_special_schedule(ctx, D, V, P, S) < 0)
4819 return -1;
4820 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
4821 if (test_special_schedule(ctx, D, V, P, S) < 0)
4822 return -1;
4824 D = "{ A[a]; B[] }";
4825 V = "{}";
4826 P = "{ A[a] -> B[] }";
4827 if (test_has_schedule(ctx, D, V, P) < 0)
4828 return -1;
4830 if (test_padded_schedule(ctx) < 0)
4831 return -1;
4833 /* Check that check for progress is not confused by rational
4834 * solution.
4836 D = "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
4837 V = "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
4838 "i0 <= -2 + N; "
4839 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
4840 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
4841 P = "{}";
4842 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
4843 if (test_has_schedule(ctx, D, V, P) < 0)
4844 return -1;
4845 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
4847 /* Check that we allow schedule rows that are only non-trivial
4848 * on some full-dimensional domains.
4850 D = "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
4851 V = "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
4852 "S1[j] -> S2[1] : 0 <= j <= 1 }";
4853 P = "{}";
4854 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
4855 if (test_has_schedule(ctx, D, V, P) < 0)
4856 return -1;
4857 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
4859 if (test_conditional_schedule_constraints(ctx) < 0)
4860 return -1;
4862 if (test_strongly_satisfying_schedule(ctx) < 0)
4863 return -1;
4865 if (test_conflicting_context_schedule(ctx) < 0)
4866 return -1;
4868 if (test_coalescing_schedule(ctx) < 0)
4869 return -1;
4870 if (test_skewing_schedule(ctx) < 0)
4871 return -1;
4873 return 0;
4876 /* Perform scheduling tests using the whole component scheduler.
4878 static int test_schedule_whole(isl_ctx *ctx)
4880 int whole;
4881 int r;
4883 whole = isl_options_get_schedule_whole_component(ctx);
4884 isl_options_set_schedule_whole_component(ctx, 1);
4885 r = test_schedule(ctx);
4886 isl_options_set_schedule_whole_component(ctx, whole);
4888 return r;
4891 /* Perform scheduling tests using the incremental scheduler.
4893 static int test_schedule_incremental(isl_ctx *ctx)
4895 int whole;
4896 int r;
4898 whole = isl_options_get_schedule_whole_component(ctx);
4899 isl_options_set_schedule_whole_component(ctx, 0);
4900 r = test_schedule(ctx);
4901 isl_options_set_schedule_whole_component(ctx, whole);
4903 return r;
4906 int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
4908 isl_union_map *umap;
4909 int test;
4911 umap = isl_union_map_read_from_str(ctx, str);
4912 test = isl_union_map_plain_is_injective(umap);
4913 isl_union_map_free(umap);
4914 if (test < 0)
4915 return -1;
4916 if (test == injective)
4917 return 0;
4918 if (injective)
4919 isl_die(ctx, isl_error_unknown,
4920 "map not detected as injective", return -1);
4921 else
4922 isl_die(ctx, isl_error_unknown,
4923 "map detected as injective", return -1);
4926 int test_injective(isl_ctx *ctx)
4928 const char *str;
4930 if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
4931 return -1;
4932 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
4933 return -1;
4934 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
4935 return -1;
4936 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
4937 return -1;
4938 if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
4939 return -1;
4940 if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
4941 return -1;
4942 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
4943 return -1;
4944 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
4945 return -1;
4947 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
4948 if (test_plain_injective(ctx, str, 1))
4949 return -1;
4950 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
4951 if (test_plain_injective(ctx, str, 0))
4952 return -1;
4954 return 0;
4957 static int aff_plain_is_equal(__isl_keep isl_aff *aff, const char *str)
4959 isl_aff *aff2;
4960 int equal;
4962 if (!aff)
4963 return -1;
4965 aff2 = isl_aff_read_from_str(isl_aff_get_ctx(aff), str);
4966 equal = isl_aff_plain_is_equal(aff, aff2);
4967 isl_aff_free(aff2);
4969 return equal;
4972 static int aff_check_plain_equal(__isl_keep isl_aff *aff, const char *str)
4974 int equal;
4976 equal = aff_plain_is_equal(aff, str);
4977 if (equal < 0)
4978 return -1;
4979 if (!equal)
4980 isl_die(isl_aff_get_ctx(aff), isl_error_unknown,
4981 "result not as expected", return -1);
4982 return 0;
4985 /* Is "upa" obviously equal to the isl_union_pw_aff represented by "str"?
4987 static isl_bool union_pw_aff_plain_is_equal(__isl_keep isl_union_pw_aff *upa,
4988 const char *str)
4990 isl_ctx *ctx;
4991 isl_union_pw_aff *upa2;
4992 isl_bool equal;
4994 if (!upa)
4995 return isl_bool_error;
4997 ctx = isl_union_pw_aff_get_ctx(upa);
4998 upa2 = isl_union_pw_aff_read_from_str(ctx, str);
4999 equal = isl_union_pw_aff_plain_is_equal(upa, upa2);
5000 isl_union_pw_aff_free(upa2);
5002 return equal;
5005 /* Check that "upa" is obviously equal to the isl_union_pw_aff
5006 * represented by "str".
5008 static isl_stat union_pw_aff_check_plain_equal(__isl_keep isl_union_pw_aff *upa,
5009 const char *str)
5011 isl_bool equal;
5013 equal = union_pw_aff_plain_is_equal(upa, str);
5014 if (equal < 0)
5015 return isl_stat_error;
5016 if (!equal)
5017 isl_die(isl_union_pw_aff_get_ctx(upa), isl_error_unknown,
5018 "result not as expected", return isl_stat_error);
5019 return isl_stat_ok;
5022 /* Basic tests on isl_union_pw_aff.
5024 * In particular, check that isl_union_pw_aff_aff_on_domain
5025 * aligns the parameters of the input objects and
5026 * that isl_union_pw_aff_param_on_domain_id properly
5027 * introduces the parameter.
5029 static int test_upa(isl_ctx *ctx)
5031 const char *str;
5032 isl_id *id;
5033 isl_aff *aff;
5034 isl_union_set *domain;
5035 isl_union_pw_aff *upa;
5036 isl_stat ok;
5038 aff = isl_aff_read_from_str(ctx, "[N] -> { [N] }");
5039 str = "[M] -> { A[i] : 0 <= i < M; B[] }";
5040 domain = isl_union_set_read_from_str(ctx, str);
5041 upa = isl_union_pw_aff_aff_on_domain(domain, aff);
5042 str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5043 ok = union_pw_aff_check_plain_equal(upa, str);
5044 isl_union_pw_aff_free(upa);
5045 if (ok < 0)
5046 return -1;
5048 id = isl_id_alloc(ctx, "N", NULL);
5049 str = "[M] -> { A[i] : 0 <= i < M; B[] }";
5050 domain = isl_union_set_read_from_str(ctx, str);
5051 upa = isl_union_pw_aff_param_on_domain_id(domain, id);
5052 str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
5053 ok = union_pw_aff_check_plain_equal(upa, str);
5054 isl_union_pw_aff_free(upa);
5055 if (ok < 0)
5056 return -1;
5058 return 0;
5061 struct {
5062 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
5063 __isl_take isl_aff *aff2);
5064 } aff_bin_op[] = {
5065 ['+'] = { &isl_aff_add },
5066 ['-'] = { &isl_aff_sub },
5067 ['*'] = { &isl_aff_mul },
5068 ['/'] = { &isl_aff_div },
5071 struct {
5072 const char *arg1;
5073 unsigned char op;
5074 const char *arg2;
5075 const char *res;
5076 } aff_bin_tests[] = {
5077 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
5078 "{ [i] -> [2i] }" },
5079 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
5080 "{ [i] -> [0] }" },
5081 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
5082 "{ [i] -> [2i] }" },
5083 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
5084 "{ [i] -> [2i] }" },
5085 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
5086 "{ [i] -> [i/2] }" },
5087 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
5088 "{ [i] -> [i] }" },
5089 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
5090 "{ [i] -> [NaN] }" },
5091 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
5092 "{ [i] -> [NaN] }" },
5093 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
5094 "{ [i] -> [NaN] }" },
5095 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
5096 "{ [i] -> [NaN] }" },
5097 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
5098 "{ [i] -> [NaN] }" },
5099 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
5100 "{ [i] -> [NaN] }" },
5101 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
5102 "{ [i] -> [NaN] }" },
5103 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
5104 "{ [i] -> [NaN] }" },
5105 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
5106 "{ [i] -> [NaN] }" },
5107 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
5108 "{ [i] -> [NaN] }" },
5109 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
5110 "{ [i] -> [NaN] }" },
5111 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
5112 "{ [i] -> [NaN] }" },
5115 /* Perform some basic tests of binary operations on isl_aff objects.
5117 static int test_bin_aff(isl_ctx *ctx)
5119 int i;
5120 isl_aff *aff1, *aff2, *res;
5121 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
5122 __isl_take isl_aff *aff2);
5123 int ok;
5125 for (i = 0; i < ARRAY_SIZE(aff_bin_tests); ++i) {
5126 aff1 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg1);
5127 aff2 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg2);
5128 res = isl_aff_read_from_str(ctx, aff_bin_tests[i].res);
5129 fn = aff_bin_op[aff_bin_tests[i].op].fn;
5130 aff1 = fn(aff1, aff2);
5131 if (isl_aff_is_nan(res))
5132 ok = isl_aff_is_nan(aff1);
5133 else
5134 ok = isl_aff_plain_is_equal(aff1, res);
5135 isl_aff_free(aff1);
5136 isl_aff_free(res);
5137 if (ok < 0)
5138 return -1;
5139 if (!ok)
5140 isl_die(ctx, isl_error_unknown,
5141 "unexpected result", return -1);
5144 return 0;
5147 struct {
5148 __isl_give isl_pw_aff *(*fn)(__isl_take isl_pw_aff *pa1,
5149 __isl_take isl_pw_aff *pa2);
5150 } pw_aff_bin_op[] = {
5151 ['m'] = { &isl_pw_aff_min },
5152 ['M'] = { &isl_pw_aff_max },
5155 /* Inputs for binary isl_pw_aff operation tests.
5156 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
5157 * defined by pw_aff_bin_op, and "res" is the expected result.
5159 struct {
5160 const char *arg1;
5161 unsigned char op;
5162 const char *arg2;
5163 const char *res;
5164 } pw_aff_bin_tests[] = {
5165 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
5166 "{ [i] -> [i] }" },
5167 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
5168 "{ [i] -> [i] }" },
5169 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
5170 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
5171 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
5172 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
5173 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
5174 "{ [i] -> [NaN] }" },
5175 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
5176 "{ [i] -> [NaN] }" },
5179 /* Perform some basic tests of binary operations on isl_pw_aff objects.
5181 static int test_bin_pw_aff(isl_ctx *ctx)
5183 int i;
5184 isl_bool ok;
5185 isl_pw_aff *pa1, *pa2, *res;
5187 for (i = 0; i < ARRAY_SIZE(pw_aff_bin_tests); ++i) {
5188 pa1 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg1);
5189 pa2 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg2);
5190 res = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].res);
5191 pa1 = pw_aff_bin_op[pw_aff_bin_tests[i].op].fn(pa1, pa2);
5192 if (isl_pw_aff_involves_nan(res))
5193 ok = isl_pw_aff_involves_nan(pa1);
5194 else
5195 ok = isl_pw_aff_plain_is_equal(pa1, res);
5196 isl_pw_aff_free(pa1);
5197 isl_pw_aff_free(res);
5198 if (ok < 0)
5199 return -1;
5200 if (!ok)
5201 isl_die(ctx, isl_error_unknown,
5202 "unexpected result", return -1);
5205 return 0;
5208 struct {
5209 __isl_give isl_union_pw_multi_aff *(*fn)(
5210 __isl_take isl_union_pw_multi_aff *upma1,
5211 __isl_take isl_union_pw_multi_aff *upma2);
5212 const char *arg1;
5213 const char *arg2;
5214 const char *res;
5215 } upma_bin_tests[] = {
5216 { &isl_union_pw_multi_aff_add, "{ A[] -> [0]; B[0] -> [1] }",
5217 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
5218 { &isl_union_pw_multi_aff_union_add, "{ A[] -> [0]; B[0] -> [1] }",
5219 "{ B[x] -> [2] : x >= 0 }",
5220 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
5221 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff,
5222 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
5223 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
5224 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
5225 "D[i] -> B[2] : i >= 5 }" },
5226 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5227 "{ B[x] -> C[2] : x > 0 }",
5228 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
5229 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5230 "{ B[x] -> A[2] : x >= 0 }",
5231 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
5234 /* Perform some basic tests of binary operations on
5235 * isl_union_pw_multi_aff objects.
5237 static int test_bin_upma(isl_ctx *ctx)
5239 int i;
5240 isl_union_pw_multi_aff *upma1, *upma2, *res;
5241 int ok;
5243 for (i = 0; i < ARRAY_SIZE(upma_bin_tests); ++i) {
5244 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
5245 upma_bin_tests[i].arg1);
5246 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
5247 upma_bin_tests[i].arg2);
5248 res = isl_union_pw_multi_aff_read_from_str(ctx,
5249 upma_bin_tests[i].res);
5250 upma1 = upma_bin_tests[i].fn(upma1, upma2);
5251 ok = isl_union_pw_multi_aff_plain_is_equal(upma1, res);
5252 isl_union_pw_multi_aff_free(upma1);
5253 isl_union_pw_multi_aff_free(res);
5254 if (ok < 0)
5255 return -1;
5256 if (!ok)
5257 isl_die(ctx, isl_error_unknown,
5258 "unexpected result", return -1);
5261 return 0;
5264 struct {
5265 __isl_give isl_union_pw_multi_aff *(*fn)(
5266 __isl_take isl_union_pw_multi_aff *upma1,
5267 __isl_take isl_union_pw_multi_aff *upma2);
5268 const char *arg1;
5269 const char *arg2;
5270 } upma_bin_fail_tests[] = {
5271 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5272 "{ B[x] -> C[2] : x >= 0 }" },
5275 /* Perform some basic tests of binary operations on
5276 * isl_union_pw_multi_aff objects that are expected to fail.
5278 static int test_bin_upma_fail(isl_ctx *ctx)
5280 int i, n;
5281 isl_union_pw_multi_aff *upma1, *upma2;
5282 int on_error;
5284 on_error = isl_options_get_on_error(ctx);
5285 isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE);
5286 n = ARRAY_SIZE(upma_bin_fail_tests);
5287 for (i = 0; i < n; ++i) {
5288 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
5289 upma_bin_fail_tests[i].arg1);
5290 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
5291 upma_bin_fail_tests[i].arg2);
5292 upma1 = upma_bin_fail_tests[i].fn(upma1, upma2);
5293 isl_union_pw_multi_aff_free(upma1);
5294 if (upma1)
5295 break;
5297 isl_options_set_on_error(ctx, on_error);
5298 if (i < n)
5299 isl_die(ctx, isl_error_unknown,
5300 "operation not expected to succeed", return -1);
5302 return 0;
5305 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5306 * "fn" is the function that is tested.
5307 * "arg" is a string description of the input.
5308 * "res" is a string description of the expected result.
5310 struct {
5311 __isl_give isl_multi_pw_aff *(*fn)(__isl_take isl_multi_pw_aff *mpa);
5312 const char *arg;
5313 const char *res;
5314 } mpa_un_tests[] = {
5315 { &isl_multi_pw_aff_range_factor_domain,
5316 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5317 "{ A[x] -> B[(1 : x >= 5)] }" },
5318 { &isl_multi_pw_aff_range_factor_range,
5319 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5320 "{ A[y] -> C[(2 : y <= 10)] }" },
5321 { &isl_multi_pw_aff_range_factor_domain,
5322 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5323 "{ A[x] -> B[(1 : x >= 5)] }" },
5324 { &isl_multi_pw_aff_range_factor_range,
5325 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5326 "{ A[y] -> C[] }" },
5327 { &isl_multi_pw_aff_range_factor_domain,
5328 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5329 "{ A[x] -> B[] }" },
5330 { &isl_multi_pw_aff_range_factor_range,
5331 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5332 "{ A[y] -> C[(2 : y <= 10)] }" },
5333 { &isl_multi_pw_aff_range_factor_domain,
5334 "{ A[x] -> [B[] -> C[]] }",
5335 "{ A[x] -> B[] }" },
5336 { &isl_multi_pw_aff_range_factor_range,
5337 "{ A[x] -> [B[] -> C[]] }",
5338 "{ A[y] -> C[] }" },
5339 { &isl_multi_pw_aff_factor_range,
5340 "{ [B[] -> C[]] }",
5341 "{ C[] }" },
5342 { &isl_multi_pw_aff_range_factor_domain,
5343 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5344 "{ A[x] -> B[] : x >= 0 }" },
5345 { &isl_multi_pw_aff_range_factor_range,
5346 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5347 "{ A[y] -> C[] : y >= 0 }" },
5348 { &isl_multi_pw_aff_factor_range,
5349 "[N] -> { [B[] -> C[]] : N >= 0 }",
5350 "[N] -> { C[] : N >= 0 }" },
5353 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5355 static int test_un_mpa(isl_ctx *ctx)
5357 int i;
5358 isl_bool ok;
5359 isl_multi_pw_aff *mpa, *res;
5361 for (i = 0; i < ARRAY_SIZE(mpa_un_tests); ++i) {
5362 mpa = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].arg);
5363 res = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].res);
5364 mpa = mpa_un_tests[i].fn(mpa);
5365 ok = isl_multi_pw_aff_plain_is_equal(mpa, res);
5366 isl_multi_pw_aff_free(mpa);
5367 isl_multi_pw_aff_free(res);
5368 if (ok < 0)
5369 return -1;
5370 if (!ok)
5371 isl_die(ctx, isl_error_unknown,
5372 "unexpected result", return -1);
5375 return 0;
5378 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5379 * "fn" is the function that is tested.
5380 * "arg1" and "arg2" are string descriptions of the inputs.
5381 * "res" is a string description of the expected result.
5383 struct {
5384 __isl_give isl_multi_pw_aff *(*fn)(
5385 __isl_take isl_multi_pw_aff *mpa1,
5386 __isl_take isl_multi_pw_aff *mpa2);
5387 const char *arg1;
5388 const char *arg2;
5389 const char *res;
5390 } mpa_bin_tests[] = {
5391 { &isl_multi_pw_aff_add, "{ A[] -> [1] }", "{ A[] -> [2] }",
5392 "{ A[] -> [3] }" },
5393 { &isl_multi_pw_aff_add, "{ A[x] -> [(1 : x >= 5)] }",
5394 "{ A[x] -> [(x : x <= 10)] }",
5395 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5396 { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }",
5397 "{ A[x] -> [] : x <= 10 }",
5398 "{ A[x] -> [] : 5 <= x <= 10 }" },
5399 { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }",
5400 "[N] -> { A[x] -> [] : x <= N }",
5401 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5402 { &isl_multi_pw_aff_add,
5403 "[N] -> { A[x] -> [] : x <= N }",
5404 "{ A[x] -> [] : x >= 5 }",
5405 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5406 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }",
5407 "{ A[y] -> C[(2 : y <= 10)] }",
5408 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5409 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }",
5410 "{ A[y] -> C[2] : y <= 10 }",
5411 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5412 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }",
5413 "[N] -> { A[y] -> C[2] : y <= N }",
5414 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5415 { &isl_multi_pw_aff_range_product, "[N] -> { A[x] -> B[1] : x >= N }",
5416 "{ A[y] -> C[2] : y <= 10 }",
5417 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5418 { &isl_multi_pw_aff_range_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5419 "{ A[] -> [B[1] -> C[2]] }" },
5420 { &isl_multi_pw_aff_range_product, "{ A[] -> B[] }", "{ A[] -> C[] }",
5421 "{ A[] -> [B[] -> C[]] }" },
5422 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }",
5423 "{ A[y] -> C[] : y <= 10 }",
5424 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5425 { &isl_multi_pw_aff_range_product, "{ A[y] -> C[] : y <= 10 }",
5426 "{ A[x] -> B[(1 : x >= 5)] }",
5427 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5428 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5429 "{ A[y] -> C[(2 : y <= 10)] }",
5430 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5431 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5432 "{ A[y] -> C[] : y <= 10 }",
5433 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5434 { &isl_multi_pw_aff_product, "{ A[y] -> C[] : y <= 10 }",
5435 "{ A[x] -> B[(1 : x >= 5)] }",
5436 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5437 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5438 "[N] -> { A[y] -> C[] : y <= N }",
5439 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5440 { &isl_multi_pw_aff_product, "[N] -> { A[y] -> C[] : y <= N }",
5441 "{ A[x] -> B[(1 : x >= 5)] }",
5442 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5443 { &isl_multi_pw_aff_product, "{ A[x] -> B[] : x >= 5 }",
5444 "{ A[y] -> C[] : y <= 10 }",
5445 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5446 { &isl_multi_pw_aff_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5447 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5448 { &isl_multi_pw_aff_product, "{ A[] -> B[] }", "{ A[] -> C[] }",
5449 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5450 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5451 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5452 "{ A[a,b] -> C[b + 2a] }" },
5453 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5454 "{ B[i,j] -> C[i + 2j] }",
5455 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5456 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5457 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5458 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5459 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5460 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5461 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5462 "{ B[i,j] -> C[] }",
5463 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5464 "{ A[a,b] -> C[] }" },
5465 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5466 "{ B[i,j] -> C[] : i > j }",
5467 "{ A[a,b] -> B[b,a] }",
5468 "{ A[a,b] -> C[] : b > a }" },
5469 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5470 "{ B[i,j] -> C[] : j > 5 }",
5471 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5472 "{ A[a,b] -> C[] : b > a > 5 }" },
5473 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5474 "[N] -> { B[i,j] -> C[] : j > N }",
5475 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5476 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5477 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5478 "[M,N] -> { B[] -> C[] : N > 5 }",
5479 "[M,N] -> { A[] -> B[] : M > N }",
5480 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5483 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5485 static int test_bin_mpa(isl_ctx *ctx)
5487 int i;
5488 isl_bool ok;
5489 isl_multi_pw_aff *mpa1, *mpa2, *res;
5491 for (i = 0; i < ARRAY_SIZE(mpa_bin_tests); ++i) {
5492 mpa1 = isl_multi_pw_aff_read_from_str(ctx,
5493 mpa_bin_tests[i].arg1);
5494 mpa2 = isl_multi_pw_aff_read_from_str(ctx,
5495 mpa_bin_tests[i].arg2);
5496 res = isl_multi_pw_aff_read_from_str(ctx,
5497 mpa_bin_tests[i].res);
5498 mpa1 = mpa_bin_tests[i].fn(mpa1, mpa2);
5499 ok = isl_multi_pw_aff_plain_is_equal(mpa1, res);
5500 isl_multi_pw_aff_free(mpa1);
5501 isl_multi_pw_aff_free(res);
5502 if (ok < 0)
5503 return -1;
5504 if (!ok)
5505 isl_die(ctx, isl_error_unknown,
5506 "unexpected result", return -1);
5509 return 0;
5512 /* Inputs for basic tests of unary operations on
5513 * isl_multi_union_pw_aff objects.
5514 * "fn" is the function that is tested.
5515 * "arg" is a string description of the input.
5516 * "res" is a string description of the expected result.
5518 struct {
5519 __isl_give isl_multi_union_pw_aff *(*fn)(
5520 __isl_take isl_multi_union_pw_aff *mupa);
5521 const char *arg;
5522 const char *res;
5523 } mupa_un_tests[] = {
5524 { &isl_multi_union_pw_aff_factor_range,
5525 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5526 "C[{ A[] -> [2] }]" },
5527 { &isl_multi_union_pw_aff_factor_range,
5528 "[B[] -> C[{ A[] -> [2] }]]",
5529 "C[{ A[] -> [2] }]" },
5530 { &isl_multi_union_pw_aff_factor_range,
5531 "[B[{ A[] -> [1] }] -> C[]]",
5532 "C[]" },
5533 { &isl_multi_union_pw_aff_factor_range,
5534 "[B[] -> C[]]",
5535 "C[]" },
5536 { &isl_multi_union_pw_aff_factor_range,
5537 "([B[] -> C[]] : { A[x] : x >= 0 })",
5538 "(C[] : { A[x] : x >= 0 })" },
5539 { &isl_multi_union_pw_aff_factor_range,
5540 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
5541 "[N] -> (C[] : { A[x] : x <= N })" },
5542 { &isl_multi_union_pw_aff_factor_range,
5543 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
5544 "[N] -> (C[] : { : N >= 0 })" },
5547 /* Perform some basic tests of unary operations on
5548 * isl_multi_union_pw_aff objects.
5550 static int test_un_mupa(isl_ctx *ctx)
5552 int i;
5553 isl_bool ok;
5554 isl_multi_union_pw_aff *mupa, *res;
5556 for (i = 0; i < ARRAY_SIZE(mupa_un_tests); ++i) {
5557 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5558 mupa_un_tests[i].arg);
5559 res = isl_multi_union_pw_aff_read_from_str(ctx,
5560 mupa_un_tests[i].res);
5561 mupa = mupa_un_tests[i].fn(mupa);
5562 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
5563 isl_multi_union_pw_aff_free(mupa);
5564 isl_multi_union_pw_aff_free(res);
5565 if (ok < 0)
5566 return -1;
5567 if (!ok)
5568 isl_die(ctx, isl_error_unknown,
5569 "unexpected result", return -1);
5572 return 0;
5575 /* Inputs for basic tests of binary operations on
5576 * isl_multi_union_pw_aff objects.
5577 * "fn" is the function that is tested.
5578 * "arg1" and "arg2" are string descriptions of the inputs.
5579 * "res" is a string description of the expected result.
5581 struct {
5582 __isl_give isl_multi_union_pw_aff *(*fn)(
5583 __isl_take isl_multi_union_pw_aff *mupa1,
5584 __isl_take isl_multi_union_pw_aff *mupa2);
5585 const char *arg1;
5586 const char *arg2;
5587 const char *res;
5588 } mupa_bin_tests[] = {
5589 { &isl_multi_union_pw_aff_add, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5590 "[{ A[] -> [3] }]" },
5591 { &isl_multi_union_pw_aff_sub, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5592 "[{ A[] -> [-1] }]" },
5593 { &isl_multi_union_pw_aff_add,
5594 "[{ A[] -> [1]; B[] -> [4] }]",
5595 "[{ A[] -> [2]; C[] -> [5] }]",
5596 "[{ A[] -> [3] }]" },
5597 { &isl_multi_union_pw_aff_union_add,
5598 "[{ A[] -> [1]; B[] -> [4] }]",
5599 "[{ A[] -> [2]; C[] -> [5] }]",
5600 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
5601 { &isl_multi_union_pw_aff_add, "[{ A[x] -> [(1)] : x >= 5 }]",
5602 "[{ A[x] -> [(x)] : x <= 10 }]",
5603 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
5604 { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })",
5605 "([] : { A[x] : x <= 10 })",
5606 "([] : { A[x] : 5 <= x <= 10 })" },
5607 { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })",
5608 "[N] -> ([] : { A[x] : x <= N })",
5609 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
5610 { &isl_multi_union_pw_aff_add, "[N] -> ([] : { A[x] : x >= N })",
5611 "([] : { A[x] : x <= 10 })",
5612 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
5613 { &isl_multi_union_pw_aff_union_add, "[{ A[x] -> [(1)] : x >= 5 }]",
5614 "[{ A[x] -> [(x)] : x <= 10 }]",
5615 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
5616 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
5617 { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 5 })",
5618 "([] : { A[x] : x <= 10 })",
5619 "([] : { A[x] })" },
5620 { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 0 })",
5621 "[N] -> ([] : { A[x] : x >= N })",
5622 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
5623 { &isl_multi_union_pw_aff_union_add,
5624 "[N] -> ([] : { A[] : N >= 0})",
5625 "[N] -> ([] : { A[] : N <= 0})",
5626 "[N] -> ([] : { A[] })" },
5627 { &isl_multi_union_pw_aff_union_add,
5628 "[N] -> ([] : { A[] })",
5629 "[N] -> ([] : { : })",
5630 "[N] -> ([] : { : })" },
5631 { &isl_multi_union_pw_aff_union_add,
5632 "[N] -> ([] : { : })",
5633 "[N] -> ([] : { A[] })",
5634 "[N] -> ([] : { : })" },
5635 { &isl_multi_union_pw_aff_union_add,
5636 "[N] -> ([] : { : N >= 0})",
5637 "[N] -> ([] : { : N <= 0})",
5638 "[N] -> ([] : { : })" },
5639 { &isl_multi_union_pw_aff_range_product,
5640 "B[{ A[] -> [1] }]",
5641 "C[{ A[] -> [2] }]",
5642 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
5643 { &isl_multi_union_pw_aff_range_product,
5644 "(B[] : { A[x] : x >= 5 })",
5645 "(C[] : { A[x] : x <= 10 })",
5646 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
5647 { &isl_multi_union_pw_aff_range_product,
5648 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5649 "(C[] : { A[x] : x <= 10 })",
5650 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
5651 { &isl_multi_union_pw_aff_range_product,
5652 "(C[] : { A[x] : x <= 10 })",
5653 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5654 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
5655 { &isl_multi_union_pw_aff_range_product,
5656 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5657 "[N] -> (C[] : { A[x] : x <= N })",
5658 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
5659 { &isl_multi_union_pw_aff_range_product,
5660 "[N] -> (C[] : { A[x] : x <= N })",
5661 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5662 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
5663 { &isl_multi_union_pw_aff_range_product,
5664 "B[{ A[] -> [1]; D[] -> [3] }]",
5665 "C[{ A[] -> [2] }]",
5666 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
5667 { &isl_multi_union_pw_aff_range_product,
5668 "B[] }]",
5669 "(C[] : { A[x] })",
5670 "([B[] -> C[]] : { A[x] })" },
5671 { &isl_multi_union_pw_aff_range_product,
5672 "(B[] : { A[x] })",
5673 "C[] }]",
5674 "([B[] -> C[]] : { A[x] })" },
5677 /* Perform some basic tests of binary operations on
5678 * isl_multi_union_pw_aff objects.
5680 static int test_bin_mupa(isl_ctx *ctx)
5682 int i;
5683 isl_bool ok;
5684 isl_multi_union_pw_aff *mupa1, *mupa2, *res;
5686 for (i = 0; i < ARRAY_SIZE(mupa_bin_tests); ++i) {
5687 mupa1 = isl_multi_union_pw_aff_read_from_str(ctx,
5688 mupa_bin_tests[i].arg1);
5689 mupa2 = isl_multi_union_pw_aff_read_from_str(ctx,
5690 mupa_bin_tests[i].arg2);
5691 res = isl_multi_union_pw_aff_read_from_str(ctx,
5692 mupa_bin_tests[i].res);
5693 mupa1 = mupa_bin_tests[i].fn(mupa1, mupa2);
5694 ok = isl_multi_union_pw_aff_plain_is_equal(mupa1, res);
5695 isl_multi_union_pw_aff_free(mupa1);
5696 isl_multi_union_pw_aff_free(res);
5697 if (ok < 0)
5698 return -1;
5699 if (!ok)
5700 isl_die(ctx, isl_error_unknown,
5701 "unexpected result", return -1);
5704 return 0;
5707 /* Inputs for basic tests of binary operations on
5708 * pairs of isl_multi_union_pw_aff and isl_set objects.
5709 * "fn" is the function that is tested.
5710 * "arg1" and "arg2" are string descriptions of the inputs.
5711 * "res" is a string description of the expected result.
5713 struct {
5714 __isl_give isl_multi_union_pw_aff *(*fn)(
5715 __isl_take isl_multi_union_pw_aff *mupa,
5716 __isl_take isl_set *set);
5717 const char *arg1;
5718 const char *arg2;
5719 const char *res;
5720 } mupa_set_tests[] = {
5721 { &isl_multi_union_pw_aff_intersect_range,
5722 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
5723 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
5724 { &isl_multi_union_pw_aff_intersect_range,
5725 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
5726 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
5727 { &isl_multi_union_pw_aff_intersect_range,
5728 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
5729 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
5730 { &isl_multi_union_pw_aff_intersect_range,
5731 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
5732 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
5733 { &isl_multi_union_pw_aff_intersect_range,
5734 "C[]", "{ C[] }", "C[]" },
5735 { &isl_multi_union_pw_aff_intersect_range,
5736 "[N] -> (C[] : { : N >= 0 })",
5737 "{ C[] }",
5738 "[N] -> (C[] : { : N >= 0 })" },
5739 { &isl_multi_union_pw_aff_intersect_range,
5740 "(C[] : { A[a,b] })",
5741 "{ C[] }",
5742 "(C[] : { A[a,b] })" },
5743 { &isl_multi_union_pw_aff_intersect_range,
5744 "[N] -> (C[] : { A[a,b] : a,b <= N })",
5745 "{ C[] }",
5746 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
5747 { &isl_multi_union_pw_aff_intersect_range,
5748 "C[]",
5749 "[N] -> { C[] : N >= 0 }",
5750 "[N] -> (C[] : { : N >= 0 })" },
5751 { &isl_multi_union_pw_aff_intersect_range,
5752 "(C[] : { A[a,b] })",
5753 "[N] -> { C[] : N >= 0 }",
5754 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5755 { &isl_multi_union_pw_aff_intersect_range,
5756 "[N] -> (C[] : { : N >= 0 })",
5757 "[N] -> { C[] : N < 1024 }",
5758 "[N] -> (C[] : { : 0 <= N < 1024 })" },
5759 { &isl_multi_union_pw_aff_intersect_params,
5760 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
5761 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
5762 { &isl_multi_union_pw_aff_intersect_params,
5763 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
5764 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
5765 { &isl_multi_union_pw_aff_intersect_params,
5766 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
5767 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
5768 { &isl_multi_union_pw_aff_intersect_params,
5769 "C[]", "[N] -> { : N >= 0 }",
5770 "[N] -> (C[] : { : N >= 0 })" },
5771 { &isl_multi_union_pw_aff_intersect_params,
5772 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
5773 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5774 { &isl_multi_union_pw_aff_intersect_params,
5775 "[N] -> (C[] : { A[a,N] })", "{ : }",
5776 "[N] -> (C[] : { A[a,N] })" },
5777 { &isl_multi_union_pw_aff_intersect_params,
5778 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
5779 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
5782 /* Perform some basic tests of binary operations on
5783 * pairs of isl_multi_union_pw_aff and isl_set objects.
5785 static int test_mupa_set(isl_ctx *ctx)
5787 int i;
5788 isl_bool ok;
5789 isl_multi_union_pw_aff *mupa, *res;
5790 isl_set *set;
5792 for (i = 0; i < ARRAY_SIZE(mupa_set_tests); ++i) {
5793 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5794 mupa_set_tests[i].arg1);
5795 set = isl_set_read_from_str(ctx, mupa_set_tests[i].arg2);
5796 res = isl_multi_union_pw_aff_read_from_str(ctx,
5797 mupa_set_tests[i].res);
5798 mupa = mupa_set_tests[i].fn(mupa, set);
5799 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
5800 isl_multi_union_pw_aff_free(mupa);
5801 isl_multi_union_pw_aff_free(res);
5802 if (ok < 0)
5803 return -1;
5804 if (!ok)
5805 isl_die(ctx, isl_error_unknown,
5806 "unexpected result", return -1);
5809 return 0;
5812 /* Inputs for basic tests of binary operations on
5813 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5814 * "fn" is the function that is tested.
5815 * "arg1" and "arg2" are string descriptions of the inputs.
5816 * "res" is a string description of the expected result.
5818 struct {
5819 __isl_give isl_multi_union_pw_aff *(*fn)(
5820 __isl_take isl_multi_union_pw_aff *mupa,
5821 __isl_take isl_union_set *uset);
5822 const char *arg1;
5823 const char *arg2;
5824 const char *res;
5825 } mupa_uset_tests[] = {
5826 { &isl_multi_union_pw_aff_intersect_domain,
5827 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
5828 "C[{ B[i,i] -> [3i] }]" },
5829 { &isl_multi_union_pw_aff_intersect_domain,
5830 "(C[] : { B[i,j] })", "{ B[i,i] }",
5831 "(C[] : { B[i,i] })" },
5832 { &isl_multi_union_pw_aff_intersect_domain,
5833 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
5834 "[N] -> (C[] : { B[N,N] })" },
5835 { &isl_multi_union_pw_aff_intersect_domain,
5836 "C[]", "{ B[i,i] }",
5837 "(C[] : { B[i,i] })" },
5838 { &isl_multi_union_pw_aff_intersect_domain,
5839 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
5840 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
5843 /* Perform some basic tests of binary operations on
5844 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5846 static int test_mupa_uset(isl_ctx *ctx)
5848 int i;
5849 isl_bool ok;
5850 isl_multi_union_pw_aff *mupa, *res;
5851 isl_union_set *uset;
5853 for (i = 0; i < ARRAY_SIZE(mupa_uset_tests); ++i) {
5854 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5855 mupa_uset_tests[i].arg1);
5856 uset = isl_union_set_read_from_str(ctx,
5857 mupa_uset_tests[i].arg2);
5858 res = isl_multi_union_pw_aff_read_from_str(ctx,
5859 mupa_uset_tests[i].res);
5860 mupa = mupa_uset_tests[i].fn(mupa, uset);
5861 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
5862 isl_multi_union_pw_aff_free(mupa);
5863 isl_multi_union_pw_aff_free(res);
5864 if (ok < 0)
5865 return -1;
5866 if (!ok)
5867 isl_die(ctx, isl_error_unknown,
5868 "unexpected result", return -1);
5871 return 0;
5874 /* Inputs for basic tests of binary operations on
5875 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5876 * "fn" is the function that is tested.
5877 * "arg1" and "arg2" are string descriptions of the inputs.
5878 * "res" is a string description of the expected result.
5880 struct {
5881 __isl_give isl_multi_union_pw_aff *(*fn)(
5882 __isl_take isl_multi_union_pw_aff *mupa,
5883 __isl_take isl_multi_aff *ma);
5884 const char *arg1;
5885 const char *arg2;
5886 const char *res;
5887 } mupa_ma_tests[] = {
5888 { &isl_multi_union_pw_aff_apply_multi_aff,
5889 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5890 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5891 "{ C[a,b] -> D[b,a] }",
5892 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
5893 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
5894 { &isl_multi_union_pw_aff_apply_multi_aff,
5895 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
5896 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5897 "{ C[a,b] -> D[b,a] }",
5898 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
5899 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
5900 { &isl_multi_union_pw_aff_apply_multi_aff,
5901 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5902 "[N] -> { C[a] -> D[a + N] }",
5903 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
5904 { &isl_multi_union_pw_aff_apply_multi_aff,
5905 "C[]",
5906 "{ C[] -> D[] }",
5907 "D[]" },
5908 { &isl_multi_union_pw_aff_apply_multi_aff,
5909 "[N] -> (C[] : { : N >= 0 })",
5910 "{ C[] -> D[] }",
5911 "[N] -> (D[] : { : N >= 0 })" },
5912 { &isl_multi_union_pw_aff_apply_multi_aff,
5913 "C[]",
5914 "[N] -> { C[] -> D[N] }",
5915 "[N] -> D[{ [N] }]" },
5916 { &isl_multi_union_pw_aff_apply_multi_aff,
5917 "(C[] : { A[i,j] : i >= j })",
5918 "{ C[] -> D[] }",
5919 "(D[] : { A[i,j] : i >= j })" },
5920 { &isl_multi_union_pw_aff_apply_multi_aff,
5921 "[N] -> (C[] : { A[i,j] : N >= 0 })",
5922 "{ C[] -> D[] }",
5923 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
5924 { &isl_multi_union_pw_aff_apply_multi_aff,
5925 "(C[] : { A[i,j] : i >= j })",
5926 "[N] -> { C[] -> D[N] }",
5927 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
5930 /* Perform some basic tests of binary operations on
5931 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5933 static int test_mupa_ma(isl_ctx *ctx)
5935 int i;
5936 isl_bool ok;
5937 isl_multi_union_pw_aff *mupa, *res;
5938 isl_multi_aff *ma;
5940 for (i = 0; i < ARRAY_SIZE(mupa_ma_tests); ++i) {
5941 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5942 mupa_ma_tests[i].arg1);
5943 ma = isl_multi_aff_read_from_str(ctx, mupa_ma_tests[i].arg2);
5944 res = isl_multi_union_pw_aff_read_from_str(ctx,
5945 mupa_ma_tests[i].res);
5946 mupa = mupa_ma_tests[i].fn(mupa, ma);
5947 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
5948 isl_multi_union_pw_aff_free(mupa);
5949 isl_multi_union_pw_aff_free(res);
5950 if (ok < 0)
5951 return -1;
5952 if (!ok)
5953 isl_die(ctx, isl_error_unknown,
5954 "unexpected result", return -1);
5957 return 0;
5960 /* Inputs for basic tests of binary operations on
5961 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
5962 * "fn" is the function that is tested.
5963 * "arg1" and "arg2" are string descriptions of the inputs.
5964 * "res" is a string description of the expected result.
5966 struct {
5967 __isl_give isl_union_pw_aff *(*fn)(
5968 __isl_take isl_multi_union_pw_aff *mupa,
5969 __isl_take isl_pw_aff *pa);
5970 const char *arg1;
5971 const char *arg2;
5972 const char *res;
5973 } mupa_pa_tests[] = {
5974 { &isl_multi_union_pw_aff_apply_pw_aff,
5975 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5976 "[N] -> { C[a] -> [a + N] }",
5977 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
5978 { &isl_multi_union_pw_aff_apply_pw_aff,
5979 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5980 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
5981 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
5982 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
5983 { &isl_multi_union_pw_aff_apply_pw_aff,
5984 "C[]",
5985 "[N] -> { C[] -> [N] }",
5986 "[N] -> { [N] }" },
5987 { &isl_multi_union_pw_aff_apply_pw_aff,
5988 "C[]",
5989 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5990 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
5991 { &isl_multi_union_pw_aff_apply_pw_aff,
5992 "[N] -> (C[] : { : N >= 0 })",
5993 "[N] -> { C[] -> [N] }",
5994 "[N] -> { [N] : N >= 0 }" },
5995 { &isl_multi_union_pw_aff_apply_pw_aff,
5996 "[N] -> (C[] : { : N >= 0 })",
5997 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5998 "[N] -> { [N] : N >= 0 }" },
5999 { &isl_multi_union_pw_aff_apply_pw_aff,
6000 "[N] -> (C[] : { : N >= 0 })",
6001 "{ C[] -> [0] }",
6002 "[N] -> { [0] : N >= 0 }" },
6003 { &isl_multi_union_pw_aff_apply_pw_aff,
6004 "(C[] : { A[i,j] : i >= j })",
6005 "[N] -> { C[] -> [N] }",
6006 "[N] -> { A[i,j] -> [N] : i >= j }" },
6007 { &isl_multi_union_pw_aff_apply_pw_aff,
6008 "(C[] : { A[i,j] : i >= j })",
6009 "[N] -> { C[] -> [N] : N >= 0 }",
6010 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
6013 /* Perform some basic tests of binary operations on
6014 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
6016 static int test_mupa_pa(isl_ctx *ctx)
6018 int i;
6019 isl_bool ok;
6020 isl_multi_union_pw_aff *mupa;
6021 isl_union_pw_aff *upa, *res;
6022 isl_pw_aff *pa;
6024 for (i = 0; i < ARRAY_SIZE(mupa_pa_tests); ++i) {
6025 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6026 mupa_pa_tests[i].arg1);
6027 pa = isl_pw_aff_read_from_str(ctx, mupa_pa_tests[i].arg2);
6028 res = isl_union_pw_aff_read_from_str(ctx,
6029 mupa_pa_tests[i].res);
6030 upa = mupa_pa_tests[i].fn(mupa, pa);
6031 ok = isl_union_pw_aff_plain_is_equal(upa, res);
6032 isl_union_pw_aff_free(upa);
6033 isl_union_pw_aff_free(res);
6034 if (ok < 0)
6035 return -1;
6036 if (!ok)
6037 isl_die(ctx, isl_error_unknown,
6038 "unexpected result", return -1);
6041 return 0;
6044 /* Inputs for basic tests of binary operations on
6045 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6046 * "fn" is the function that is tested.
6047 * "arg1" and "arg2" are string descriptions of the inputs.
6048 * "res" is a string description of the expected result.
6050 struct {
6051 __isl_give isl_multi_union_pw_aff *(*fn)(
6052 __isl_take isl_multi_union_pw_aff *mupa,
6053 __isl_take isl_pw_multi_aff *pma);
6054 const char *arg1;
6055 const char *arg2;
6056 const char *res;
6057 } mupa_pma_tests[] = {
6058 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6059 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6060 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6061 "{ C[a,b] -> D[b,a] }",
6062 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
6063 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
6064 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6065 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
6066 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6067 "{ C[a,b] -> D[b,a] }",
6068 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
6069 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
6070 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6071 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6072 "[N] -> { C[a] -> D[a + N] }",
6073 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
6074 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6075 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
6076 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
6077 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
6078 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
6079 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6080 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
6081 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
6082 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
6083 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
6084 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
6085 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
6086 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
6087 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6088 "C[]",
6089 "{ C[] -> D[] }",
6090 "D[]" },
6091 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6092 "[N] -> (C[] : { : N >= 0 })",
6093 "{ C[] -> D[] }",
6094 "[N] -> (D[] : { : N >= 0 })" },
6095 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6096 "C[]",
6097 "[N] -> { C[] -> D[N] }",
6098 "[N] -> D[{ [N] }]" },
6099 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6100 "(C[] : { A[i,j] : i >= j })",
6101 "{ C[] -> D[] }",
6102 "(D[] : { A[i,j] : i >= j })" },
6103 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6104 "[N] -> (C[] : { A[i,j] : N >= 0 })",
6105 "{ C[] -> D[] }",
6106 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
6107 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6108 "(C[] : { A[i,j] : i >= j })",
6109 "[N] -> { C[] -> D[N] }",
6110 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
6111 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6112 "C[]",
6113 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6114 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
6115 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6116 "[N] -> (C[] : { : N >= 0 })",
6117 "[N] -> { C[] -> D[N] }",
6118 "[N] -> D[{ [N] : N >= 0 }]" },
6119 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6120 "[N] -> (C[] : { : N >= 0 })",
6121 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
6122 "[N] -> D[{ [N] : N >= 0 }]" },
6123 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6124 "[N] -> (C[] : { : N >= 0 })",
6125 "{ C[] -> D[0] }",
6126 "[N] -> D[{ [0] : N >= 0 }]" },
6127 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
6128 "(C[] : { A[i,j] : i >= j })",
6129 "[N] -> { C[] -> D[N] : N >= 0 }",
6130 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
6133 /* Perform some basic tests of binary operations on
6134 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
6136 static int test_mupa_pma(isl_ctx *ctx)
6138 int i;
6139 isl_bool ok;
6140 isl_multi_union_pw_aff *mupa, *res;
6141 isl_pw_multi_aff *pma;
6143 for (i = 0; i < ARRAY_SIZE(mupa_pma_tests); ++i) {
6144 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6145 mupa_pma_tests[i].arg1);
6146 pma = isl_pw_multi_aff_read_from_str(ctx,
6147 mupa_pma_tests[i].arg2);
6148 res = isl_multi_union_pw_aff_read_from_str(ctx,
6149 mupa_pma_tests[i].res);
6150 mupa = mupa_pma_tests[i].fn(mupa, pma);
6151 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6152 isl_multi_union_pw_aff_free(mupa);
6153 isl_multi_union_pw_aff_free(res);
6154 if (ok < 0)
6155 return -1;
6156 if (!ok)
6157 isl_die(ctx, isl_error_unknown,
6158 "unexpected result", return -1);
6161 return 0;
6164 /* Inputs for basic tests of binary operations on
6165 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6166 * "fn" is the function that is tested.
6167 * "arg1" and "arg2" are string descriptions of the inputs.
6168 * "res" is a string description of the expected result.
6170 struct {
6171 __isl_give isl_multi_union_pw_aff *(*fn)(
6172 __isl_take isl_multi_union_pw_aff *mupa,
6173 __isl_take isl_union_pw_multi_aff *upma);
6174 const char *arg1;
6175 const char *arg2;
6176 const char *res;
6177 } mupa_upma_tests[] = {
6178 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6179 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
6180 "C[{ A[a,b] -> [b + 2a] }]" },
6181 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6182 "C[{ B[i,j] -> [i + 2j] }]",
6183 "{ A[a,b] -> B[b,a] : b > a }",
6184 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
6185 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6186 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
6187 "{ A[a,b] -> B[b,a] : b > a }",
6188 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
6189 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6190 "C[{ B[i,j] -> [i + 2j] }]",
6191 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
6192 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
6193 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6194 "(C[] : { B[a,b] })",
6195 "{ A[a,b] -> B[b,a] }",
6196 "(C[] : { A[a,b] })" },
6197 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6198 "(C[] : { B[a,b] })",
6199 "{ B[a,b] -> A[b,a] }",
6200 "(C[] : { })" },
6201 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6202 "(C[] : { B[a,b] })",
6203 "{ A[a,b] -> B[b,a] : a > b }",
6204 "(C[] : { A[a,b] : a > b })" },
6205 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6206 "(C[] : { B[a,b] : a > b })",
6207 "{ A[a,b] -> B[b,a] }",
6208 "(C[] : { A[a,b] : b > a })" },
6209 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6210 "[N] -> (C[] : { B[a,b] : a > N })",
6211 "{ A[a,b] -> B[b,a] : a > b }",
6212 "[N] -> (C[] : { A[a,b] : a > b > N })" },
6213 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6214 "(C[] : { B[a,b] : a > b })",
6215 "[N] -> { A[a,b] -> B[b,a] : a > N }",
6216 "[N] -> (C[] : { A[a,b] : b > a > N })" },
6217 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6218 "C[]",
6219 "{ A[a,b] -> B[b,a] }",
6220 "C[]" },
6221 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6222 "[N] -> (C[] : { : N >= 0 })",
6223 "{ A[a,b] -> B[b,a] }",
6224 "[N] -> (C[] : { : N >= 0 })" },
6225 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
6226 "C[]",
6227 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
6228 "[N] -> (C[] : { : N >= 0 })" },
6231 /* Perform some basic tests of binary operations on
6232 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
6234 static int test_mupa_upma(isl_ctx *ctx)
6236 int i;
6237 isl_bool ok;
6238 isl_multi_union_pw_aff *mupa, *res;
6239 isl_union_pw_multi_aff *upma;
6241 for (i = 0; i < ARRAY_SIZE(mupa_upma_tests); ++i) {
6242 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6243 mupa_upma_tests[i].arg1);
6244 upma = isl_union_pw_multi_aff_read_from_str(ctx,
6245 mupa_upma_tests[i].arg2);
6246 res = isl_multi_union_pw_aff_read_from_str(ctx,
6247 mupa_upma_tests[i].res);
6248 mupa = mupa_upma_tests[i].fn(mupa, upma);
6249 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
6250 isl_multi_union_pw_aff_free(mupa);
6251 isl_multi_union_pw_aff_free(res);
6252 if (ok < 0)
6253 return -1;
6254 if (!ok)
6255 isl_die(ctx, isl_error_unknown,
6256 "unexpected result", return -1);
6259 return 0;
6262 /* Check that the input tuple of an isl_aff can be set properly.
6264 static isl_stat test_aff_set_tuple_id(isl_ctx *ctx)
6266 isl_id *id;
6267 isl_aff *aff;
6268 int equal;
6270 aff = isl_aff_read_from_str(ctx, "{ [x] -> [x + 1] }");
6271 id = isl_id_alloc(ctx, "A", NULL);
6272 aff = isl_aff_set_tuple_id(aff, isl_dim_in, id);
6273 equal = aff_check_plain_equal(aff, "{ A[x] -> [x + 1] }");
6274 isl_aff_free(aff);
6275 if (equal < 0)
6276 return isl_stat_error;
6278 return isl_stat_ok;
6281 int test_aff(isl_ctx *ctx)
6283 const char *str;
6284 isl_set *set;
6285 isl_space *space;
6286 isl_local_space *ls;
6287 isl_aff *aff;
6288 int zero, equal;
6290 if (test_upa(ctx) < 0)
6291 return -1;
6292 if (test_bin_aff(ctx) < 0)
6293 return -1;
6294 if (test_bin_pw_aff(ctx) < 0)
6295 return -1;
6296 if (test_bin_upma(ctx) < 0)
6297 return -1;
6298 if (test_bin_upma_fail(ctx) < 0)
6299 return -1;
6300 if (test_un_mpa(ctx) < 0)
6301 return -1;
6302 if (test_bin_mpa(ctx) < 0)
6303 return -1;
6304 if (test_un_mupa(ctx) < 0)
6305 return -1;
6306 if (test_bin_mupa(ctx) < 0)
6307 return -1;
6308 if (test_mupa_set(ctx) < 0)
6309 return -1;
6310 if (test_mupa_uset(ctx) < 0)
6311 return -1;
6312 if (test_mupa_ma(ctx) < 0)
6313 return -1;
6314 if (test_mupa_pa(ctx) < 0)
6315 return -1;
6316 if (test_mupa_pma(ctx) < 0)
6317 return -1;
6318 if (test_mupa_upma(ctx) < 0)
6319 return -1;
6321 space = isl_space_set_alloc(ctx, 0, 1);
6322 ls = isl_local_space_from_space(space);
6323 aff = isl_aff_zero_on_domain(ls);
6325 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6326 aff = isl_aff_scale_down_ui(aff, 3);
6327 aff = isl_aff_floor(aff);
6328 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6329 aff = isl_aff_scale_down_ui(aff, 2);
6330 aff = isl_aff_floor(aff);
6331 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6333 str = "{ [10] }";
6334 set = isl_set_read_from_str(ctx, str);
6335 aff = isl_aff_gist(aff, set);
6337 aff = isl_aff_add_constant_si(aff, -16);
6338 zero = isl_aff_plain_is_zero(aff);
6339 isl_aff_free(aff);
6341 if (zero < 0)
6342 return -1;
6343 if (!zero)
6344 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6346 aff = isl_aff_read_from_str(ctx, "{ [-1] }");
6347 aff = isl_aff_scale_down_ui(aff, 64);
6348 aff = isl_aff_floor(aff);
6349 equal = aff_check_plain_equal(aff, "{ [-1] }");
6350 isl_aff_free(aff);
6351 if (equal < 0)
6352 return -1;
6354 if (test_aff_set_tuple_id(ctx) < 0)
6355 return -1;
6357 return 0;
6360 /* Inputs for isl_set_bind tests.
6361 * "set" is the input set.
6362 * "tuple" is the binding tuple.
6363 * "res" is the expected result.
6365 static
6366 struct {
6367 const char *set;
6368 const char *tuple;
6369 const char *res;
6370 } bind_set_tests[] = {
6371 { "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }",
6372 "{ A[M, N] }",
6373 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6374 { "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }",
6375 "{ B[N, M] }",
6376 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6377 { "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }",
6378 "{ C[N] }",
6379 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" },
6380 { "[M] -> { D[x, N] : x mod 2 = 0 and N mod 8 = 3 and M >= 0 }",
6381 "{ D[M, N] }",
6382 "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 and M >= 0 }" },
6385 /* Perform basic isl_set_bind tests.
6387 static isl_stat test_bind_set(isl_ctx *ctx)
6389 int i;
6391 for (i = 0; i < ARRAY_SIZE(bind_set_tests); ++i) {
6392 const char *str;
6393 isl_set *set;
6394 isl_multi_id *tuple;
6395 isl_stat r;
6397 set = isl_set_read_from_str(ctx, bind_set_tests[i].set);
6398 str = bind_set_tests[i].tuple;
6399 tuple = isl_multi_id_read_from_str(ctx, str);
6400 set = isl_set_bind(set, tuple);
6401 r = set_check_equal(set, bind_set_tests[i].res);
6402 isl_set_free(set);
6403 if (r < 0)
6404 return isl_stat_error;
6407 return isl_stat_ok;
6410 /* Inputs for isl_aff_bind_id tests.
6411 * "aff" is the input expression.
6412 * "id" is the binding id.
6413 * "res" is the expected result.
6415 static
6416 struct {
6417 const char *aff;
6418 const char *id;
6419 const char *res;
6420 } bind_aff_tests[] = {
6421 { "{ [4] }", "M", "[M = 4] -> { : }" },
6422 { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" },
6423 { "[M] -> { [4] }", "M", "[M = 4] -> { : }" },
6424 { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" },
6425 { "{ [NaN] }", "M", "{ : false }" },
6426 { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" },
6429 /* Perform basic isl_aff_bind_id tests.
6431 static isl_stat test_bind_aff(isl_ctx *ctx)
6433 int i;
6435 for (i = 0; i < ARRAY_SIZE(bind_aff_tests); ++i) {
6436 isl_aff *aff;
6437 isl_set *res;
6438 isl_id *id;
6439 isl_stat r;
6441 aff = isl_aff_read_from_str(ctx, bind_aff_tests[i].aff);
6442 id = isl_id_read_from_str(ctx, bind_aff_tests[i].id);
6443 res = isl_set_from_basic_set(isl_aff_bind_id(aff, id));
6444 r = set_check_equal(res, bind_aff_tests[i].res);
6445 isl_set_free(res);
6446 if (r < 0)
6447 return isl_stat_error;
6450 return isl_stat_ok;
6453 /* Perform tests that reinterpret dimensions as parameters.
6455 static int test_bind(isl_ctx *ctx)
6457 if (test_bind_set(ctx) < 0)
6458 return -1;
6459 if (test_bind_aff(ctx) < 0)
6460 return -1;
6462 return 0;
6465 /* Inputs for isl_set_unbind_params tests.
6466 * "set" is the input parameter domain.
6467 * "tuple" is the tuple of the constructed set.
6468 * "res" is the expected result.
6470 struct {
6471 const char *set;
6472 const char *tuple;
6473 const char *res;
6474 } unbind_set_tests[] = {
6475 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
6476 "{ A[M, N] }",
6477 "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }" },
6478 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
6479 "{ B[N, M] }",
6480 "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" },
6481 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
6482 "{ C[N] }",
6483 "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }" },
6484 { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }",
6485 "{ D[T, N] }",
6486 "[M] -> { D[x, N] : M mod 2 = 0 and N mod 8 = 3 }" },
6489 /* Perform basic isl_set_unbind_params tests.
6491 static isl_stat test_unbind_set(isl_ctx *ctx)
6493 int i;
6495 for (i = 0; i < ARRAY_SIZE(unbind_set_tests); ++i) {
6496 const char *str;
6497 isl_set *set;
6498 isl_multi_id *tuple;
6499 isl_stat r;
6501 set = isl_set_read_from_str(ctx, unbind_set_tests[i].set);
6502 str = unbind_set_tests[i].tuple;
6503 tuple = isl_multi_id_read_from_str(ctx, str);
6504 set = isl_set_unbind_params(set, tuple);
6505 r = set_check_equal(set, unbind_set_tests[i].res);
6506 isl_set_free(set);
6507 if (r < 0)
6508 return isl_stat_error;
6511 return isl_stat_ok;
6514 /* Inputs for isl_aff_unbind_params_insert_domain tests.
6515 * "aff" is the input affine expression defined over a parameter domain.
6516 * "tuple" is the tuple of the domain that gets introduced.
6517 * "res" is the expected result.
6519 struct {
6520 const char *aff;
6521 const char *tuple;
6522 const char *res;
6523 } unbind_aff_tests[] = {
6524 { "[M, N] -> { [M + floor(N/2)] }",
6525 "{ A[M, N] }",
6526 "{ A[M, N] -> [M + floor(N/2)] }" },
6527 { "[M, N] -> { [M + floor(N/2)] }",
6528 "{ B[N, M] }",
6529 "{ B[N, M] -> [M + floor(N/2)] }" },
6530 { "[M, N] -> { [M + floor(N/2)] }",
6531 "{ C[N] }",
6532 "[M] -> { C[N] -> [M + floor(N/2)] }" },
6533 { "[M, N] -> { [M + floor(N/2)] }",
6534 "{ D[A, B, C, N, Z] }",
6535 "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" },
6538 /* Perform basic isl_aff_unbind_params_insert_domain tests.
6540 static isl_stat test_unbind_aff(isl_ctx *ctx)
6542 int i;
6544 for (i = 0; i < ARRAY_SIZE(unbind_aff_tests); ++i) {
6545 const char *str;
6546 isl_aff *aff;
6547 isl_multi_id *tuple;
6548 isl_stat r;
6550 aff = isl_aff_read_from_str(ctx, unbind_aff_tests[i].aff);
6551 str = unbind_aff_tests[i].tuple;
6552 tuple = isl_multi_id_read_from_str(ctx, str);
6553 aff = isl_aff_unbind_params_insert_domain(aff, tuple);
6554 r = aff_check_plain_equal(aff, unbind_aff_tests[i].res);
6555 isl_aff_free(aff);
6556 if (r < 0)
6557 return isl_stat_error;
6560 return isl_stat_ok;
6563 /* Perform tests that reinterpret parameters.
6565 static int test_unbind(isl_ctx *ctx)
6567 if (test_unbind_set(ctx) < 0)
6568 return -1;
6569 if (test_unbind_aff(ctx) < 0)
6570 return -1;
6572 return 0;
6575 /* Check that "pa" consists of a single expression.
6577 static int check_single_piece(isl_ctx *ctx, __isl_take isl_pw_aff *pa)
6579 isl_size n;
6581 n = isl_pw_aff_n_piece(pa);
6582 isl_pw_aff_free(pa);
6584 if (n < 0)
6585 return -1;
6586 if (n != 1)
6587 isl_die(ctx, isl_error_unknown, "expecting single expression",
6588 return -1);
6590 return 0;
6593 /* Check that the computation below results in a single expression.
6594 * One or two expressions may result depending on which constraint
6595 * ends up being considered as redundant with respect to the other
6596 * constraints after the projection that is performed internally
6597 * by isl_set_dim_min.
6599 static int test_dim_max_1(isl_ctx *ctx)
6601 const char *str;
6602 isl_set *set;
6603 isl_pw_aff *pa;
6605 str = "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
6606 "-4a <= b <= 3 and b < n - 4a }";
6607 set = isl_set_read_from_str(ctx, str);
6608 pa = isl_set_dim_min(set, 0);
6609 return check_single_piece(ctx, pa);
6612 /* Check that the computation below results in a single expression.
6613 * The PIP problem corresponding to these constraints has a row
6614 * that causes a split of the solution domain. The solver should
6615 * first pick rows that split off empty parts such that the actual
6616 * solution domain does not get split.
6617 * Note that the description contains some redundant constraints.
6618 * If these constraints get removed first, then the row mentioned
6619 * above does not appear in the PIP problem.
6621 static int test_dim_max_2(isl_ctx *ctx)
6623 const char *str;
6624 isl_set *set;
6625 isl_pw_aff *pa;
6627 str = "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
6628 "N > 0 and P >= 0 }";
6629 set = isl_set_read_from_str(ctx, str);
6630 pa = isl_set_dim_max(set, 0);
6631 return check_single_piece(ctx, pa);
6634 int test_dim_max(isl_ctx *ctx)
6636 int equal;
6637 const char *str;
6638 isl_set *set1, *set2;
6639 isl_set *set;
6640 isl_map *map;
6641 isl_pw_aff *pwaff;
6643 if (test_dim_max_1(ctx) < 0)
6644 return -1;
6645 if (test_dim_max_2(ctx) < 0)
6646 return -1;
6648 str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
6649 set = isl_set_read_from_str(ctx, str);
6650 pwaff = isl_set_dim_max(set, 0);
6651 set1 = isl_set_from_pw_aff(pwaff);
6652 str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
6653 set2 = isl_set_read_from_str(ctx, str);
6654 equal = isl_set_is_equal(set1, set2);
6655 isl_set_free(set1);
6656 isl_set_free(set2);
6657 if (equal < 0)
6658 return -1;
6659 if (!equal)
6660 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6662 str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
6663 set = isl_set_read_from_str(ctx, str);
6664 pwaff = isl_set_dim_max(set, 0);
6665 set1 = isl_set_from_pw_aff(pwaff);
6666 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6667 set2 = isl_set_read_from_str(ctx, str);
6668 equal = isl_set_is_equal(set1, set2);
6669 isl_set_free(set1);
6670 isl_set_free(set2);
6671 if (equal < 0)
6672 return -1;
6673 if (!equal)
6674 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6676 str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
6677 set = isl_set_read_from_str(ctx, str);
6678 pwaff = isl_set_dim_max(set, 0);
6679 set1 = isl_set_from_pw_aff(pwaff);
6680 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6681 set2 = isl_set_read_from_str(ctx, str);
6682 equal = isl_set_is_equal(set1, set2);
6683 isl_set_free(set1);
6684 isl_set_free(set2);
6685 if (equal < 0)
6686 return -1;
6687 if (!equal)
6688 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6690 str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
6691 "0 <= i < N and 0 <= j < M }";
6692 map = isl_map_read_from_str(ctx, str);
6693 set = isl_map_range(map);
6695 pwaff = isl_set_dim_max(isl_set_copy(set), 0);
6696 set1 = isl_set_from_pw_aff(pwaff);
6697 str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
6698 set2 = isl_set_read_from_str(ctx, str);
6699 equal = isl_set_is_equal(set1, set2);
6700 isl_set_free(set1);
6701 isl_set_free(set2);
6703 pwaff = isl_set_dim_max(isl_set_copy(set), 3);
6704 set1 = isl_set_from_pw_aff(pwaff);
6705 str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
6706 set2 = isl_set_read_from_str(ctx, str);
6707 if (equal >= 0 && equal)
6708 equal = isl_set_is_equal(set1, set2);
6709 isl_set_free(set1);
6710 isl_set_free(set2);
6712 isl_set_free(set);
6714 if (equal < 0)
6715 return -1;
6716 if (!equal)
6717 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6719 /* Check that solutions are properly merged. */
6720 str = "[n] -> { [a, b, c] : c >= -4a - 2b and "
6721 "c <= -1 + n - 4a - 2b and c >= -2b and "
6722 "4a >= -4 + n and c >= 0 }";
6723 set = isl_set_read_from_str(ctx, str);
6724 pwaff = isl_set_dim_min(set, 2);
6725 set1 = isl_set_from_pw_aff(pwaff);
6726 str = "[n] -> { [(0)] : n >= 1 }";
6727 set2 = isl_set_read_from_str(ctx, str);
6728 equal = isl_set_is_equal(set1, set2);
6729 isl_set_free(set1);
6730 isl_set_free(set2);
6732 if (equal < 0)
6733 return -1;
6734 if (!equal)
6735 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6737 /* Check that empty solution lie in the right space. */
6738 str = "[n] -> { [t,a] : 1 = 0 }";
6739 set = isl_set_read_from_str(ctx, str);
6740 pwaff = isl_set_dim_max(set, 0);
6741 set1 = isl_set_from_pw_aff(pwaff);
6742 str = "[n] -> { [t] : 1 = 0 }";
6743 set2 = isl_set_read_from_str(ctx, str);
6744 equal = isl_set_is_equal(set1, set2);
6745 isl_set_free(set1);
6746 isl_set_free(set2);
6748 if (equal < 0)
6749 return -1;
6750 if (!equal)
6751 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6753 return 0;
6756 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
6758 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff *pma,
6759 const char *str)
6761 isl_ctx *ctx;
6762 isl_pw_multi_aff *pma2;
6763 int equal;
6765 if (!pma)
6766 return -1;
6768 ctx = isl_pw_multi_aff_get_ctx(pma);
6769 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
6770 equal = isl_pw_multi_aff_plain_is_equal(pma, pma2);
6771 isl_pw_multi_aff_free(pma2);
6773 return equal;
6776 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
6777 * represented by "str".
6779 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff *pma,
6780 const char *str)
6782 int equal;
6784 equal = pw_multi_aff_plain_is_equal(pma, str);
6785 if (equal < 0)
6786 return -1;
6787 if (!equal)
6788 isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_unknown,
6789 "result not as expected", return -1);
6790 return 0;
6793 /* Basic test for isl_pw_multi_aff_product.
6795 * Check that multiple pieces are properly handled.
6797 static int test_product_pma(isl_ctx *ctx)
6799 int equal;
6800 const char *str;
6801 isl_pw_multi_aff *pma1, *pma2;
6803 str = "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
6804 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
6805 str = "{ C[] -> D[] }";
6806 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
6807 pma1 = isl_pw_multi_aff_product(pma1, pma2);
6808 str = "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
6809 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
6810 equal = pw_multi_aff_check_plain_equal(pma1, str);
6811 isl_pw_multi_aff_free(pma1);
6812 if (equal < 0)
6813 return -1;
6815 return 0;
6818 int test_product(isl_ctx *ctx)
6820 const char *str;
6821 isl_set *set;
6822 isl_union_set *uset1, *uset2;
6823 int ok;
6825 str = "{ A[i] }";
6826 set = isl_set_read_from_str(ctx, str);
6827 set = isl_set_product(set, isl_set_copy(set));
6828 ok = isl_set_is_wrapping(set);
6829 isl_set_free(set);
6830 if (ok < 0)
6831 return -1;
6832 if (!ok)
6833 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6835 str = "{ [] }";
6836 uset1 = isl_union_set_read_from_str(ctx, str);
6837 uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1));
6838 str = "{ [[] -> []] }";
6839 uset2 = isl_union_set_read_from_str(ctx, str);
6840 ok = isl_union_set_is_equal(uset1, uset2);
6841 isl_union_set_free(uset1);
6842 isl_union_set_free(uset2);
6843 if (ok < 0)
6844 return -1;
6845 if (!ok)
6846 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6848 if (test_product_pma(ctx) < 0)
6849 return -1;
6851 return 0;
6854 /* Check that two sets are not considered disjoint just because
6855 * they have a different set of (named) parameters.
6857 static int test_disjoint(isl_ctx *ctx)
6859 const char *str;
6860 isl_set *set, *set2;
6861 int disjoint;
6863 str = "[n] -> { [[]->[]] }";
6864 set = isl_set_read_from_str(ctx, str);
6865 str = "{ [[]->[]] }";
6866 set2 = isl_set_read_from_str(ctx, str);
6867 disjoint = isl_set_is_disjoint(set, set2);
6868 isl_set_free(set);
6869 isl_set_free(set2);
6870 if (disjoint < 0)
6871 return -1;
6872 if (disjoint)
6873 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6875 return 0;
6878 /* Inputs for isl_pw_multi_aff_is_equal tests.
6879 * "f1" and "f2" are the two function that need to be compared.
6880 * "equal" is the expected result.
6882 struct {
6883 int equal;
6884 const char *f1;
6885 const char *f2;
6886 } pma_equal_tests[] = {
6887 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
6888 "[N] -> { [0] : 0 <= N <= 1 }" },
6889 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6890 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
6891 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6892 "[N] -> { [0] : 0 <= N <= 1 }" },
6893 { 0, "{ [NaN] }", "{ [NaN] }" },
6896 int test_equal(isl_ctx *ctx)
6898 int i;
6899 const char *str;
6900 isl_set *set, *set2;
6901 int equal;
6903 str = "{ S_6[i] }";
6904 set = isl_set_read_from_str(ctx, str);
6905 str = "{ S_7[i] }";
6906 set2 = isl_set_read_from_str(ctx, str);
6907 equal = isl_set_is_equal(set, set2);
6908 isl_set_free(set);
6909 isl_set_free(set2);
6910 if (equal < 0)
6911 return -1;
6912 if (equal)
6913 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6915 for (i = 0; i < ARRAY_SIZE(pma_equal_tests); ++i) {
6916 int expected = pma_equal_tests[i].equal;
6917 isl_pw_multi_aff *f1, *f2;
6919 f1 = isl_pw_multi_aff_read_from_str(ctx, pma_equal_tests[i].f1);
6920 f2 = isl_pw_multi_aff_read_from_str(ctx, pma_equal_tests[i].f2);
6921 equal = isl_pw_multi_aff_is_equal(f1, f2);
6922 isl_pw_multi_aff_free(f1);
6923 isl_pw_multi_aff_free(f2);
6924 if (equal < 0)
6925 return -1;
6926 if (equal != expected)
6927 isl_die(ctx, isl_error_unknown,
6928 "unexpected equality result", return -1);
6931 return 0;
6934 static int test_plain_fixed(isl_ctx *ctx, __isl_take isl_map *map,
6935 enum isl_dim_type type, unsigned pos, int fixed)
6937 isl_bool test;
6939 test = isl_map_plain_is_fixed(map, type, pos, NULL);
6940 isl_map_free(map);
6941 if (test < 0)
6942 return -1;
6943 if (test == fixed)
6944 return 0;
6945 if (fixed)
6946 isl_die(ctx, isl_error_unknown,
6947 "map not detected as fixed", return -1);
6948 else
6949 isl_die(ctx, isl_error_unknown,
6950 "map detected as fixed", return -1);
6953 int test_fixed(isl_ctx *ctx)
6955 const char *str;
6956 isl_map *map;
6958 str = "{ [i] -> [i] }";
6959 map = isl_map_read_from_str(ctx, str);
6960 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 0))
6961 return -1;
6962 str = "{ [i] -> [1] }";
6963 map = isl_map_read_from_str(ctx, str);
6964 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
6965 return -1;
6966 str = "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
6967 map = isl_map_read_from_str(ctx, str);
6968 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
6969 return -1;
6970 map = isl_map_read_from_str(ctx, str);
6971 map = isl_map_neg(map);
6972 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
6973 return -1;
6975 return 0;
6978 struct isl_vertices_test_data {
6979 const char *set;
6980 int n;
6981 const char *vertex[6];
6982 } vertices_tests[] = {
6983 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
6984 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
6985 { "{ A[t, i] : t = 14 and i = 1 }",
6986 1, { "{ A[14, 1] }" } },
6987 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
6988 "c <= m and m <= n and m > 0 }",
6989 6, {
6990 "[n, m] -> { [n, m, m] : 0 < m <= n }",
6991 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
6992 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
6993 "[n, m] -> { [m, m, m] : 0 < m <= n }",
6994 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
6995 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
6996 } },
6999 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
7001 static isl_stat find_vertex(__isl_take isl_vertex *vertex, void *user)
7003 struct isl_vertices_test_data *data = user;
7004 isl_ctx *ctx;
7005 isl_multi_aff *ma;
7006 isl_basic_set *bset;
7007 isl_pw_multi_aff *pma;
7008 int i;
7009 isl_bool equal;
7011 ctx = isl_vertex_get_ctx(vertex);
7012 bset = isl_vertex_get_domain(vertex);
7013 ma = isl_vertex_get_expr(vertex);
7014 pma = isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset), ma);
7016 for (i = 0; i < data->n; ++i) {
7017 isl_pw_multi_aff *pma_i;
7019 pma_i = isl_pw_multi_aff_read_from_str(ctx, data->vertex[i]);
7020 equal = isl_pw_multi_aff_plain_is_equal(pma, pma_i);
7021 isl_pw_multi_aff_free(pma_i);
7023 if (equal < 0 || equal)
7024 break;
7027 isl_pw_multi_aff_free(pma);
7028 isl_vertex_free(vertex);
7030 if (equal < 0)
7031 return isl_stat_error;
7033 return equal ? isl_stat_ok : isl_stat_error;
7036 int test_vertices(isl_ctx *ctx)
7038 int i;
7040 for (i = 0; i < ARRAY_SIZE(vertices_tests); ++i) {
7041 isl_basic_set *bset;
7042 isl_vertices *vertices;
7043 int ok = 1;
7044 isl_size n;
7046 bset = isl_basic_set_read_from_str(ctx, vertices_tests[i].set);
7047 vertices = isl_basic_set_compute_vertices(bset);
7048 n = isl_vertices_get_n_vertices(vertices);
7049 if (vertices_tests[i].n != n)
7050 ok = 0;
7051 if (isl_vertices_foreach_vertex(vertices, &find_vertex,
7052 &vertices_tests[i]) < 0)
7053 ok = 0;
7054 isl_vertices_free(vertices);
7055 isl_basic_set_free(bset);
7057 if (n < 0)
7058 return -1;
7059 if (!ok)
7060 isl_die(ctx, isl_error_unknown, "unexpected vertices",
7061 return -1);
7064 return 0;
7067 int test_union_pw(isl_ctx *ctx)
7069 int equal;
7070 const char *str;
7071 isl_union_set *uset;
7072 isl_union_pw_qpolynomial *upwqp1, *upwqp2;
7074 str = "{ [x] -> x^2 }";
7075 upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str);
7076 upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1);
7077 uset = isl_union_pw_qpolynomial_domain(upwqp1);
7078 upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2);
7079 upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset);
7080 equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2);
7081 isl_union_pw_qpolynomial_free(upwqp1);
7082 isl_union_pw_qpolynomial_free(upwqp2);
7083 if (equal < 0)
7084 return -1;
7085 if (!equal)
7086 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7088 return 0;
7091 /* Inputs for basic tests of functions that select
7092 * subparts of the domain of an isl_multi_union_pw_aff.
7093 * "fn" is the function that is tested.
7094 * "arg" is a string description of the input.
7095 * "res" is a string description of the expected result.
7097 struct {
7098 __isl_give isl_union_set *(*fn)(
7099 __isl_take isl_multi_union_pw_aff *mupa);
7100 const char *arg;
7101 const char *res;
7102 } un_locus_tests[] = {
7103 { &isl_multi_union_pw_aff_zero_union_set,
7104 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
7105 "{ A[0,j]; B[0,j] }" },
7106 { &isl_multi_union_pw_aff_zero_union_set,
7107 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
7108 "{ A[i,i]; B[i,i] : i >= 0 }" },
7109 { &isl_multi_union_pw_aff_zero_union_set,
7110 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
7111 "{ A[i,j]; B[i,i] : i >= 0 }" },
7114 /* Perform some basic tests of functions that select
7115 * subparts of the domain of an isl_multi_union_pw_aff.
7117 static int test_un_locus(isl_ctx *ctx)
7119 int i;
7120 isl_bool ok;
7121 isl_union_set *uset, *res;
7122 isl_multi_union_pw_aff *mupa;
7124 for (i = 0; i < ARRAY_SIZE(un_locus_tests); ++i) {
7125 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
7126 un_locus_tests[i].arg);
7127 res = isl_union_set_read_from_str(ctx, un_locus_tests[i].res);
7128 uset = un_locus_tests[i].fn(mupa);
7129 ok = isl_union_set_is_equal(uset, res);
7130 isl_union_set_free(uset);
7131 isl_union_set_free(res);
7132 if (ok < 0)
7133 return -1;
7134 if (!ok)
7135 isl_die(ctx, isl_error_unknown,
7136 "unexpected result", return -1);
7139 return 0;
7142 /* Inputs for basic tests of functions that select
7143 * subparts of an isl_union_map based on a relation
7144 * specified by an isl_multi_union_pw_aff.
7145 * "fn" is the function that is tested.
7146 * "arg1" and "arg2" are string descriptions of the inputs.
7147 * "res" is a string description of the expected result.
7149 struct {
7150 __isl_give isl_union_map *(*fn)(
7151 __isl_take isl_union_map *umap,
7152 __isl_take isl_multi_union_pw_aff *mupa);
7153 const char *arg1;
7154 const char *arg2;
7155 const char *res;
7156 } bin_locus_tests[] = {
7157 { &isl_union_map_eq_at_multi_union_pw_aff,
7158 "{ A[i,j] -> B[i',j'] }",
7159 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
7160 "{ A[i,j] -> B[i,j'] }" },
7161 { &isl_union_map_eq_at_multi_union_pw_aff,
7162 "{ A[i,j] -> B[i',j'] }",
7163 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
7164 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
7165 "{ A[i,j] -> B[i,j] }" },
7166 { &isl_union_map_eq_at_multi_union_pw_aff,
7167 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
7168 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
7169 "{ A[i,j] -> B[i,j'] }" },
7170 { &isl_union_map_eq_at_multi_union_pw_aff,
7171 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
7172 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
7173 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
7174 { &isl_union_map_eq_at_multi_union_pw_aff,
7175 "{ A[i,j] -> B[i',j'] }",
7176 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
7177 "{ A[i,j] -> B[i,j'] : i > j }" },
7178 { &isl_union_map_lex_lt_at_multi_union_pw_aff,
7179 "{ A[i,j] -> B[i',j'] }",
7180 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
7181 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
7182 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
7183 { &isl_union_map_lex_gt_at_multi_union_pw_aff,
7184 "{ A[i,j] -> B[i',j'] }",
7185 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
7186 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
7187 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
7188 { &isl_union_map_eq_at_multi_union_pw_aff,
7189 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
7190 "(F[] : { A[i,j]; B[i,j] })",
7191 "{ A[i,j] -> B[i',j'] }" },
7192 { &isl_union_map_eq_at_multi_union_pw_aff,
7193 "{ A[i,j] -> B[i',j'] }",
7194 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
7195 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
7196 { &isl_union_map_eq_at_multi_union_pw_aff,
7197 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
7198 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
7199 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
7200 { &isl_union_map_eq_at_multi_union_pw_aff,
7201 "{ A[i,j] -> B[i',j'] }",
7202 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
7203 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
7204 { &isl_union_map_eq_at_multi_union_pw_aff,
7205 "{ A[i,j] -> B[i',j'] }",
7206 "[N] -> (F[] : { : N >= 0 })",
7207 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
7210 /* Perform some basic tests of functions that select
7211 * subparts of an isl_union_map based on a relation
7212 * specified by an isl_multi_union_pw_aff.
7214 static int test_bin_locus(isl_ctx *ctx)
7216 int i;
7217 isl_bool ok;
7218 isl_union_map *umap, *res;
7219 isl_multi_union_pw_aff *mupa;
7221 for (i = 0; i < ARRAY_SIZE(bin_locus_tests); ++i) {
7222 umap = isl_union_map_read_from_str(ctx,
7223 bin_locus_tests[i].arg1);
7224 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
7225 bin_locus_tests[i].arg2);
7226 res = isl_union_map_read_from_str(ctx, bin_locus_tests[i].res);
7227 umap = bin_locus_tests[i].fn(umap, mupa);
7228 ok = isl_union_map_is_equal(umap, res);
7229 isl_union_map_free(umap);
7230 isl_union_map_free(res);
7231 if (ok < 0)
7232 return -1;
7233 if (!ok)
7234 isl_die(ctx, isl_error_unknown,
7235 "unexpected result", return -1);
7238 return 0;
7241 /* Perform basic locus tests.
7243 static int test_locus(isl_ctx *ctx)
7245 if (test_un_locus(ctx) < 0)
7246 return -1;
7247 if (test_bin_locus(ctx) < 0)
7248 return -1;
7249 return 0;
7252 /* Test that isl_union_pw_qpolynomial_eval picks up the function
7253 * defined over the correct domain space.
7255 static int test_eval_1(isl_ctx *ctx)
7257 const char *str;
7258 isl_point *pnt;
7259 isl_set *set;
7260 isl_union_pw_qpolynomial *upwqp;
7261 isl_val *v;
7262 int cmp;
7264 str = "{ A[x] -> x^2; B[x] -> -x^2 }";
7265 upwqp = isl_union_pw_qpolynomial_read_from_str(ctx, str);
7266 str = "{ A[6] }";
7267 set = isl_set_read_from_str(ctx, str);
7268 pnt = isl_set_sample_point(set);
7269 v = isl_union_pw_qpolynomial_eval(upwqp, pnt);
7270 cmp = isl_val_cmp_si(v, 36);
7271 isl_val_free(v);
7273 if (!v)
7274 return -1;
7275 if (cmp != 0)
7276 isl_die(ctx, isl_error_unknown, "unexpected value", return -1);
7278 return 0;
7281 /* Check that isl_qpolynomial_eval handles getting called on a void point.
7283 static int test_eval_2(isl_ctx *ctx)
7285 const char *str;
7286 isl_point *pnt;
7287 isl_set *set;
7288 isl_qpolynomial *qp;
7289 isl_val *v;
7290 isl_bool ok;
7292 str = "{ A[x] -> [x] }";
7293 qp = isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx, str));
7294 str = "{ A[x] : false }";
7295 set = isl_set_read_from_str(ctx, str);
7296 pnt = isl_set_sample_point(set);
7297 v = isl_qpolynomial_eval(qp, pnt);
7298 ok = isl_val_is_nan(v);
7299 isl_val_free(v);
7301 if (ok < 0)
7302 return -1;
7303 if (!ok)
7304 isl_die(ctx, isl_error_unknown, "expecting NaN", return -1);
7306 return 0;
7309 /* Check that a polynomial (without local variables) can be evaluated
7310 * in a rational point.
7312 static isl_stat test_eval_3(isl_ctx *ctx)
7314 isl_pw_qpolynomial *pwqp;
7315 isl_point *pnt;
7316 isl_val *v;
7317 isl_stat r;
7319 pwqp = isl_pw_qpolynomial_read_from_str(ctx, "{ [x] -> x^2 }");
7320 pnt = isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp));
7321 v = isl_val_read_from_str(ctx, "1/2");
7322 pnt = isl_point_set_coordinate_val(pnt, isl_dim_set, 0, v);
7323 v = isl_pw_qpolynomial_eval(pwqp, pnt);
7324 r = val_check_equal(v, "1/4");
7325 isl_val_free(v);
7327 return r;
7330 /* Inputs for isl_pw_aff_eval test.
7331 * "f" is the affine function.
7332 * "p" is the point where the function should be evaluated.
7333 * "res" is the expected result.
7335 struct {
7336 const char *f;
7337 const char *p;
7338 const char *res;
7339 } aff_eval_tests[] = {
7340 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
7341 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
7342 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
7343 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
7344 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
7345 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
7346 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
7347 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
7348 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
7349 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
7350 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
7351 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
7352 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
7353 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
7354 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
7355 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
7356 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
7357 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
7358 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
7359 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
7360 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
7361 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
7362 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
7365 /* Perform basic isl_pw_aff_eval tests.
7367 static int test_eval_aff(isl_ctx *ctx)
7369 int i;
7371 for (i = 0; i < ARRAY_SIZE(aff_eval_tests); ++i) {
7372 isl_stat r;
7373 isl_pw_aff *pa;
7374 isl_set *set;
7375 isl_point *pnt;
7376 isl_val *v;
7378 pa = isl_pw_aff_read_from_str(ctx, aff_eval_tests[i].f);
7379 set = isl_set_read_from_str(ctx, aff_eval_tests[i].p);
7380 pnt = isl_set_sample_point(set);
7381 v = isl_pw_aff_eval(pa, pnt);
7382 r = val_check_equal(v, aff_eval_tests[i].res);
7383 isl_val_free(v);
7384 if (r < 0)
7385 return -1;
7387 return 0;
7390 /* Perform basic evaluation tests.
7392 static int test_eval(isl_ctx *ctx)
7394 if (test_eval_1(ctx) < 0)
7395 return -1;
7396 if (test_eval_2(ctx) < 0)
7397 return -1;
7398 if (test_eval_3(ctx) < 0)
7399 return -1;
7400 if (test_eval_aff(ctx) < 0)
7401 return -1;
7402 return 0;
7405 /* Descriptions of sets that are tested for reparsing after printing.
7407 const char *output_tests[] = {
7408 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
7409 "{ [x] : 1 = 0 }",
7410 "{ [x] : false }",
7411 "{ [x] : x mod 2 = 0 }",
7412 "{ [x] : x mod 2 = 1 }",
7413 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
7414 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
7415 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
7416 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
7417 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
7418 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
7421 /* Check that printing a set and reparsing a set from the printed output
7422 * results in the same set.
7424 static int test_output_set(isl_ctx *ctx)
7426 int i;
7427 char *str;
7428 isl_set *set1, *set2;
7429 isl_bool equal;
7431 for (i = 0; i < ARRAY_SIZE(output_tests); ++i) {
7432 set1 = isl_set_read_from_str(ctx, output_tests[i]);
7433 str = isl_set_to_str(set1);
7434 set2 = isl_set_read_from_str(ctx, str);
7435 free(str);
7436 equal = isl_set_is_equal(set1, set2);
7437 isl_set_free(set1);
7438 isl_set_free(set2);
7439 if (equal < 0)
7440 return -1;
7441 if (!equal)
7442 isl_die(ctx, isl_error_unknown,
7443 "parsed output not the same", return -1);
7446 return 0;
7449 /* Check that an isl_multi_aff is printed using a consistent space.
7451 static isl_stat test_output_ma(isl_ctx *ctx)
7453 char *str;
7454 isl_bool equal;
7455 isl_aff *aff;
7456 isl_multi_aff *ma, *ma2;
7458 ma = isl_multi_aff_read_from_str(ctx, "{ [a, b] -> [a + b] }");
7459 aff = isl_aff_read_from_str(ctx, "{ [c, d] -> [c + d] }");
7460 ma = isl_multi_aff_set_aff(ma, 0, aff);
7461 str = isl_multi_aff_to_str(ma);
7462 ma2 = isl_multi_aff_read_from_str(ctx, str);
7463 free(str);
7464 equal = isl_multi_aff_plain_is_equal(ma, ma2);
7465 isl_multi_aff_free(ma2);
7466 isl_multi_aff_free(ma);
7468 if (equal < 0)
7469 return isl_stat_error;
7470 if (!equal)
7471 isl_die(ctx, isl_error_unknown, "bad conversion",
7472 return isl_stat_error);
7474 return isl_stat_ok;
7477 /* Check that an isl_multi_pw_aff is printed using a consistent space.
7479 static isl_stat test_output_mpa(isl_ctx *ctx)
7481 char *str;
7482 isl_bool equal;
7483 isl_pw_aff *pa;
7484 isl_multi_pw_aff *mpa, *mpa2;
7486 mpa = isl_multi_pw_aff_read_from_str(ctx, "{ [a, b] -> [a + b] }");
7487 pa = isl_pw_aff_read_from_str(ctx, "{ [c, d] -> [c + d] }");
7488 mpa = isl_multi_pw_aff_set_pw_aff(mpa, 0, pa);
7489 str = isl_multi_pw_aff_to_str(mpa);
7490 mpa2 = isl_multi_pw_aff_read_from_str(ctx, str);
7491 free(str);
7492 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2);
7493 isl_multi_pw_aff_free(mpa2);
7494 isl_multi_pw_aff_free(mpa);
7496 if (equal < 0)
7497 return isl_stat_error;
7498 if (!equal)
7499 isl_die(ctx, isl_error_unknown, "bad conversion",
7500 return isl_stat_error);
7502 return isl_stat_ok;
7505 int test_output(isl_ctx *ctx)
7507 char *s;
7508 const char *str;
7509 isl_pw_aff *pa;
7510 isl_printer *p;
7511 int equal;
7513 if (test_output_set(ctx) < 0)
7514 return -1;
7515 if (test_output_ma(ctx) < 0)
7516 return -1;
7517 if (test_output_mpa(ctx) < 0)
7518 return -1;
7520 str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
7521 pa = isl_pw_aff_read_from_str(ctx, str);
7523 p = isl_printer_to_str(ctx);
7524 p = isl_printer_set_output_format(p, ISL_FORMAT_C);
7525 p = isl_printer_print_pw_aff(p, pa);
7526 s = isl_printer_get_str(p);
7527 isl_printer_free(p);
7528 isl_pw_aff_free(pa);
7529 if (!s)
7530 equal = -1;
7531 else
7532 equal = !strcmp(s, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
7533 free(s);
7534 if (equal < 0)
7535 return -1;
7536 if (!equal)
7537 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
7539 return 0;
7542 int test_sample(isl_ctx *ctx)
7544 const char *str;
7545 isl_basic_set *bset1, *bset2;
7546 int empty, subset;
7548 str = "{ [a, b, c, d, e, f, g, h, i, j, k] : "
7549 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
7550 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
7551 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
7552 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
7553 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
7554 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
7555 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
7556 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
7557 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
7558 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
7559 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
7560 "d - 1073741821e and "
7561 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
7562 "3j >= 1 - a + b + 2e and "
7563 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
7564 "3i <= 4 - a + 4b - e and "
7565 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
7566 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
7567 "c <= -1 + a and 3i >= -2 - a + 3e and "
7568 "1073741822e <= 1073741823 - a + 1073741822b + c and "
7569 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
7570 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
7571 "1073741823e >= 1 + 1073741823b - d and "
7572 "3i >= 1073741823b + c - 1073741823e - f and "
7573 "3i >= 1 + 2b + e + 3g }";
7574 bset1 = isl_basic_set_read_from_str(ctx, str);
7575 bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1));
7576 empty = isl_basic_set_is_empty(bset2);
7577 subset = isl_basic_set_is_subset(bset2, bset1);
7578 isl_basic_set_free(bset1);
7579 isl_basic_set_free(bset2);
7580 if (empty < 0 || subset < 0)
7581 return -1;
7582 if (empty)
7583 isl_die(ctx, isl_error_unknown, "point not found", return -1);
7584 if (!subset)
7585 isl_die(ctx, isl_error_unknown, "bad point found", return -1);
7587 return 0;
7590 int test_fixed_power(isl_ctx *ctx)
7592 const char *str;
7593 isl_map *map;
7594 isl_val *exp;
7595 int equal;
7597 str = "{ [i] -> [i + 1] }";
7598 map = isl_map_read_from_str(ctx, str);
7599 exp = isl_val_int_from_si(ctx, 23);
7600 map = isl_map_fixed_power_val(map, exp);
7601 equal = map_check_equal(map, "{ [i] -> [i + 23] }");
7602 isl_map_free(map);
7603 if (equal < 0)
7604 return -1;
7606 return 0;
7609 int test_slice(isl_ctx *ctx)
7611 const char *str;
7612 isl_map *map;
7613 int equal;
7615 str = "{ [i] -> [j] }";
7616 map = isl_map_read_from_str(ctx, str);
7617 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_out, 0);
7618 equal = map_check_equal(map, "{ [i] -> [i] }");
7619 isl_map_free(map);
7620 if (equal < 0)
7621 return -1;
7623 str = "{ [i] -> [j] }";
7624 map = isl_map_read_from_str(ctx, str);
7625 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_in, 0);
7626 equal = map_check_equal(map, "{ [i] -> [j] }");
7627 isl_map_free(map);
7628 if (equal < 0)
7629 return -1;
7631 str = "{ [i] -> [j] }";
7632 map = isl_map_read_from_str(ctx, str);
7633 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_out, 0);
7634 equal = map_check_equal(map, "{ [i] -> [-i] }");
7635 isl_map_free(map);
7636 if (equal < 0)
7637 return -1;
7639 str = "{ [i] -> [j] }";
7640 map = isl_map_read_from_str(ctx, str);
7641 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_in, 0);
7642 equal = map_check_equal(map, "{ [0] -> [j] }");
7643 isl_map_free(map);
7644 if (equal < 0)
7645 return -1;
7647 str = "{ [i] -> [j] }";
7648 map = isl_map_read_from_str(ctx, str);
7649 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_out, 0);
7650 equal = map_check_equal(map, "{ [i] -> [j] : i > j }");
7651 isl_map_free(map);
7652 if (equal < 0)
7653 return -1;
7655 str = "{ [i] -> [j] }";
7656 map = isl_map_read_from_str(ctx, str);
7657 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_in, 0);
7658 equal = map_check_equal(map, "{ [i] -> [j] : false }");
7659 isl_map_free(map);
7660 if (equal < 0)
7661 return -1;
7663 return 0;
7666 int test_eliminate(isl_ctx *ctx)
7668 const char *str;
7669 isl_map *map;
7670 int equal;
7672 str = "{ [i] -> [j] : i = 2j }";
7673 map = isl_map_read_from_str(ctx, str);
7674 map = isl_map_eliminate(map, isl_dim_out, 0, 1);
7675 equal = map_check_equal(map, "{ [i] -> [j] : exists a : i = 2a }");
7676 isl_map_free(map);
7677 if (equal < 0)
7678 return -1;
7680 return 0;
7683 /* Check basic functionality of isl_map_deltas_map.
7685 static int test_deltas_map(isl_ctx *ctx)
7687 const char *str;
7688 isl_map *map;
7689 int equal;
7691 str = "{ A[i] -> A[i + 1] }";
7692 map = isl_map_read_from_str(ctx, str);
7693 map = isl_map_deltas_map(map);
7694 equal = map_check_equal(map, "{ [A[i] -> A[i + 1]] -> A[1] }");
7695 isl_map_free(map);
7696 if (equal < 0)
7697 return -1;
7699 return 0;
7702 /* Check that isl_set_dim_residue_class detects that the values of j
7703 * in the set below are all odd and that it does not detect any spurious
7704 * strides.
7706 static int test_residue_class(isl_ctx *ctx)
7708 const char *str;
7709 isl_set *set;
7710 isl_int m, r;
7711 isl_stat res;
7713 str = "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
7714 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
7715 set = isl_set_read_from_str(ctx, str);
7716 isl_int_init(m);
7717 isl_int_init(r);
7718 res = isl_set_dim_residue_class(set, 1, &m, &r);
7719 if (res >= 0 &&
7720 (isl_int_cmp_si(m, 2) != 0 || isl_int_cmp_si(r, 1) != 0))
7721 isl_die(ctx, isl_error_unknown, "incorrect residue class",
7722 res = isl_stat_error);
7723 isl_int_clear(r);
7724 isl_int_clear(m);
7725 isl_set_free(set);
7727 return res;
7730 static int test_align_parameters_1(isl_ctx *ctx)
7732 const char *str;
7733 isl_space *space;
7734 isl_multi_aff *ma1, *ma2;
7735 int equal;
7737 str = "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
7738 ma1 = isl_multi_aff_read_from_str(ctx, str);
7740 space = isl_space_params_alloc(ctx, 1);
7741 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
7742 ma1 = isl_multi_aff_align_params(ma1, space);
7744 str = "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
7745 ma2 = isl_multi_aff_read_from_str(ctx, str);
7747 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
7749 isl_multi_aff_free(ma1);
7750 isl_multi_aff_free(ma2);
7752 if (equal < 0)
7753 return -1;
7754 if (!equal)
7755 isl_die(ctx, isl_error_unknown,
7756 "result not as expected", return -1);
7758 return 0;
7761 /* Check the isl_multi_*_from_*_list operation in case inputs
7762 * have unaligned parameters.
7763 * In particular, older versions of isl would simply fail
7764 * (without printing any error message).
7766 static isl_stat test_align_parameters_2(isl_ctx *ctx)
7768 isl_space *space;
7769 isl_map *map;
7770 isl_aff *aff;
7771 isl_multi_aff *ma;
7773 map = isl_map_read_from_str(ctx, "{ A[] -> M[x] }");
7774 space = isl_map_get_space(map);
7775 isl_map_free(map);
7777 aff = isl_aff_read_from_str(ctx, "[N] -> { A[] -> [N] }");
7778 ma = isl_multi_aff_from_aff_list(space, isl_aff_list_from_aff(aff));
7779 isl_multi_aff_free(ma);
7781 if (!ma)
7782 return isl_stat_error;
7783 return isl_stat_ok;
7786 /* Perform basic parameter alignment tests.
7788 static int test_align_parameters(isl_ctx *ctx)
7790 if (test_align_parameters_1(ctx) < 0)
7791 return -1;
7792 if (test_align_parameters_2(ctx) < 0)
7793 return -1;
7795 return 0;
7798 /* Check that isl_*_drop_unused_params actually drops the unused parameters
7799 * by comparing the result using isl_*_plain_is_equal.
7800 * Note that this assumes that isl_*_plain_is_equal does not consider
7801 * objects that only differ by unused parameters to be equal.
7803 int test_drop_unused_parameters(isl_ctx *ctx)
7805 const char *str_with, *str_without;
7806 isl_basic_set *bset1, *bset2;
7807 isl_set *set1, *set2;
7808 isl_pw_aff *pwa1, *pwa2;
7809 int equal;
7811 str_with = "[n, m, o] -> { [m] }";
7812 str_without = "[m] -> { [m] }";
7814 bset1 = isl_basic_set_read_from_str(ctx, str_with);
7815 bset2 = isl_basic_set_read_from_str(ctx, str_without);
7816 bset1 = isl_basic_set_drop_unused_params(bset1);
7817 equal = isl_basic_set_plain_is_equal(bset1, bset2);
7818 isl_basic_set_free(bset1);
7819 isl_basic_set_free(bset2);
7821 if (equal < 0)
7822 return -1;
7823 if (!equal)
7824 isl_die(ctx, isl_error_unknown,
7825 "result not as expected", return -1);
7827 set1 = isl_set_read_from_str(ctx, str_with);
7828 set2 = isl_set_read_from_str(ctx, str_without);
7829 set1 = isl_set_drop_unused_params(set1);
7830 equal = isl_set_plain_is_equal(set1, set2);
7831 isl_set_free(set1);
7832 isl_set_free(set2);
7834 if (equal < 0)
7835 return -1;
7836 if (!equal)
7837 isl_die(ctx, isl_error_unknown,
7838 "result not as expected", return -1);
7840 pwa1 = isl_pw_aff_read_from_str(ctx, str_with);
7841 pwa2 = isl_pw_aff_read_from_str(ctx, str_without);
7842 pwa1 = isl_pw_aff_drop_unused_params(pwa1);
7843 equal = isl_pw_aff_plain_is_equal(pwa1, pwa2);
7844 isl_pw_aff_free(pwa1);
7845 isl_pw_aff_free(pwa2);
7847 if (equal < 0)
7848 return -1;
7849 if (!equal)
7850 isl_die(ctx, isl_error_unknown,
7851 "result not as expected", return -1);
7853 return 0;
7856 static int test_list(isl_ctx *ctx)
7858 isl_id *a, *b, *c, *d, *id;
7859 isl_id_list *list;
7860 isl_size n;
7861 int ok;
7863 a = isl_id_alloc(ctx, "a", NULL);
7864 b = isl_id_alloc(ctx, "b", NULL);
7865 c = isl_id_alloc(ctx, "c", NULL);
7866 d = isl_id_alloc(ctx, "d", NULL);
7868 list = isl_id_list_alloc(ctx, 4);
7869 list = isl_id_list_add(list, b);
7870 list = isl_id_list_insert(list, 0, a);
7871 list = isl_id_list_add(list, c);
7872 list = isl_id_list_add(list, d);
7873 list = isl_id_list_drop(list, 1, 1);
7875 n = isl_id_list_n_id(list);
7876 if (n < 0)
7877 return -1;
7878 if (n != 3) {
7879 isl_id_list_free(list);
7880 isl_die(ctx, isl_error_unknown,
7881 "unexpected number of elements in list", return -1);
7884 id = isl_id_list_get_id(list, 0);
7885 ok = id == a;
7886 isl_id_free(id);
7887 id = isl_id_list_get_id(list, 1);
7888 ok = ok && id == c;
7889 isl_id_free(id);
7890 id = isl_id_list_get_id(list, 2);
7891 ok = ok && id == d;
7892 isl_id_free(id);
7894 isl_id_list_free(list);
7896 if (!ok)
7897 isl_die(ctx, isl_error_unknown,
7898 "unexpected elements in list", return -1);
7900 return 0;
7903 /* Check the conversion from an isl_multi_aff to an isl_basic_set.
7905 static isl_stat test_ma_conversion(isl_ctx *ctx)
7907 const char *str;
7908 isl_bool equal;
7909 isl_multi_aff *ma;
7910 isl_basic_set *bset1, *bset2;
7912 str = "[N] -> { A[0, N + 1] }";
7913 ma = isl_multi_aff_read_from_str(ctx, str);
7914 bset1 = isl_basic_set_read_from_str(ctx, str);
7915 bset2 = isl_basic_set_from_multi_aff(ma);
7916 equal = isl_basic_set_is_equal(bset1, bset2);
7917 isl_basic_set_free(bset1);
7918 isl_basic_set_free(bset2);
7919 if (equal < 0)
7920 return isl_stat_error;
7921 if (!equal)
7922 isl_die(ctx, isl_error_unknown, "bad conversion",
7923 return isl_stat_error);
7924 return isl_stat_ok;
7927 const char *set_conversion_tests[] = {
7928 "[N] -> { [i] : N - 1 <= 2 i <= N }",
7929 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
7930 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7931 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7932 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
7933 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
7934 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
7935 "-3 + c <= d <= 28 + c) }",
7938 /* Check that converting from isl_set to isl_pw_multi_aff and back
7939 * to isl_set produces the original isl_set.
7941 static int test_set_conversion(isl_ctx *ctx)
7943 int i;
7944 const char *str;
7945 isl_set *set1, *set2;
7946 isl_pw_multi_aff *pma;
7947 int equal;
7949 for (i = 0; i < ARRAY_SIZE(set_conversion_tests); ++i) {
7950 str = set_conversion_tests[i];
7951 set1 = isl_set_read_from_str(ctx, str);
7952 pma = isl_pw_multi_aff_from_set(isl_set_copy(set1));
7953 set2 = isl_set_from_pw_multi_aff(pma);
7954 equal = isl_set_is_equal(set1, set2);
7955 isl_set_free(set1);
7956 isl_set_free(set2);
7958 if (equal < 0)
7959 return -1;
7960 if (!equal)
7961 isl_die(ctx, isl_error_unknown, "bad conversion",
7962 return -1);
7965 return 0;
7968 const char *conversion_tests[] = {
7969 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7970 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7971 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7972 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7973 "9e <= -2 - 2a) }",
7974 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7975 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7976 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7979 /* Check that converting from isl_map to isl_pw_multi_aff and back
7980 * to isl_map produces the original isl_map.
7982 static int test_map_conversion(isl_ctx *ctx)
7984 int i;
7985 isl_map *map1, *map2;
7986 isl_pw_multi_aff *pma;
7987 int equal;
7989 for (i = 0; i < ARRAY_SIZE(conversion_tests); ++i) {
7990 map1 = isl_map_read_from_str(ctx, conversion_tests[i]);
7991 pma = isl_pw_multi_aff_from_map(isl_map_copy(map1));
7992 map2 = isl_map_from_pw_multi_aff(pma);
7993 equal = isl_map_is_equal(map1, map2);
7994 isl_map_free(map1);
7995 isl_map_free(map2);
7997 if (equal < 0)
7998 return -1;
7999 if (!equal)
8000 isl_die(ctx, isl_error_unknown, "bad conversion",
8001 return -1);
8004 return 0;
8007 /* Descriptions of isl_pw_multi_aff objects for testing conversion
8008 * to isl_multi_pw_aff and back.
8010 const char *mpa_conversion_tests[] = {
8011 "{ [x] -> A[x] }",
8012 "{ [x] -> A[x] : x >= 0 }",
8013 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
8014 "{ [x] -> A[x, x + 1] }",
8015 "{ [x] -> A[] }",
8016 "{ [x] -> A[] : x >= 0 }",
8019 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
8020 * back to isl_pw_multi_aff preserves the original meaning.
8022 static int test_mpa_conversion(isl_ctx *ctx)
8024 int i;
8025 isl_pw_multi_aff *pma1, *pma2;
8026 isl_multi_pw_aff *mpa;
8027 int equal;
8029 for (i = 0; i < ARRAY_SIZE(mpa_conversion_tests); ++i) {
8030 const char *str;
8031 str = mpa_conversion_tests[i];
8032 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
8033 pma2 = isl_pw_multi_aff_copy(pma1);
8034 mpa = isl_multi_pw_aff_from_pw_multi_aff(pma1);
8035 pma1 = isl_pw_multi_aff_from_multi_pw_aff(mpa);
8036 equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
8037 isl_pw_multi_aff_free(pma1);
8038 isl_pw_multi_aff_free(pma2);
8040 if (equal < 0)
8041 return -1;
8042 if (!equal)
8043 isl_die(ctx, isl_error_unknown, "bad conversion",
8044 return -1);
8047 return 0;
8050 /* Descriptions of union maps that should be convertible
8051 * to an isl_multi_union_pw_aff.
8053 const char *umap_mupa_conversion_tests[] = {
8054 "{ [a, b, c, d] -> s0[a, b, e, f] : "
8055 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
8056 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
8057 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
8058 "9e <= -2 - 2a) }",
8059 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
8060 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
8061 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
8062 "{ A[] -> B[0]; C[] -> B[1] }",
8063 "{ A[] -> B[]; C[] -> B[] }",
8066 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
8067 * to isl_union_map produces the original isl_union_map.
8069 static int test_union_map_mupa_conversion(isl_ctx *ctx)
8071 int i;
8072 isl_union_map *umap1, *umap2;
8073 isl_multi_union_pw_aff *mupa;
8074 int equal;
8076 for (i = 0; i < ARRAY_SIZE(umap_mupa_conversion_tests); ++i) {
8077 const char *str;
8078 str = umap_mupa_conversion_tests[i];
8079 umap1 = isl_union_map_read_from_str(ctx, str);
8080 umap2 = isl_union_map_copy(umap1);
8081 mupa = isl_multi_union_pw_aff_from_union_map(umap2);
8082 umap2 = isl_union_map_from_multi_union_pw_aff(mupa);
8083 equal = isl_union_map_is_equal(umap1, umap2);
8084 isl_union_map_free(umap1);
8085 isl_union_map_free(umap2);
8087 if (equal < 0)
8088 return -1;
8089 if (!equal)
8090 isl_die(ctx, isl_error_unknown, "bad conversion",
8091 return -1);
8094 return 0;
8097 static int test_conversion(isl_ctx *ctx)
8099 if (test_ma_conversion(ctx) < 0)
8100 return -1;
8101 if (test_set_conversion(ctx) < 0)
8102 return -1;
8103 if (test_map_conversion(ctx) < 0)
8104 return -1;
8105 if (test_mpa_conversion(ctx) < 0)
8106 return -1;
8107 if (test_union_map_mupa_conversion(ctx) < 0)
8108 return -1;
8109 return 0;
8112 /* Check that isl_basic_map_curry does not modify input.
8114 static int test_curry(isl_ctx *ctx)
8116 const char *str;
8117 isl_basic_map *bmap1, *bmap2;
8118 int equal;
8120 str = "{ [A[] -> B[]] -> C[] }";
8121 bmap1 = isl_basic_map_read_from_str(ctx, str);
8122 bmap2 = isl_basic_map_curry(isl_basic_map_copy(bmap1));
8123 equal = isl_basic_map_is_equal(bmap1, bmap2);
8124 isl_basic_map_free(bmap1);
8125 isl_basic_map_free(bmap2);
8127 if (equal < 0)
8128 return -1;
8129 if (equal)
8130 isl_die(ctx, isl_error_unknown,
8131 "curried map should not be equal to original",
8132 return -1);
8134 return 0;
8137 struct {
8138 const char *set;
8139 const char *ma;
8140 const char *res;
8141 } preimage_tests[] = {
8142 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
8143 "{ A[j,i] -> B[i,j] }",
8144 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
8145 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
8146 "{ A[a,b] -> B[a/2,b/6] }",
8147 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
8148 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
8149 "{ A[a,b] -> B[a/2,b/6] }",
8150 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
8151 "exists i,j : a = 2 i and b = 6 j }" },
8152 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
8153 "[n] -> { : 0 <= n <= 100 }" },
8154 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
8155 "{ A[a] -> B[2a] }",
8156 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
8157 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
8158 "{ A[a] -> B[([a/2])] }",
8159 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
8160 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
8161 "{ A[a] -> B[a,a,a/3] }",
8162 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
8163 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
8164 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
8167 static int test_preimage_basic_set(isl_ctx *ctx)
8169 int i;
8170 isl_basic_set *bset1, *bset2;
8171 isl_multi_aff *ma;
8172 int equal;
8174 for (i = 0; i < ARRAY_SIZE(preimage_tests); ++i) {
8175 bset1 = isl_basic_set_read_from_str(ctx, preimage_tests[i].set);
8176 ma = isl_multi_aff_read_from_str(ctx, preimage_tests[i].ma);
8177 bset2 = isl_basic_set_read_from_str(ctx, preimage_tests[i].res);
8178 bset1 = isl_basic_set_preimage_multi_aff(bset1, ma);
8179 equal = isl_basic_set_is_equal(bset1, bset2);
8180 isl_basic_set_free(bset1);
8181 isl_basic_set_free(bset2);
8182 if (equal < 0)
8183 return -1;
8184 if (!equal)
8185 isl_die(ctx, isl_error_unknown, "bad preimage",
8186 return -1);
8189 return 0;
8192 struct {
8193 const char *map;
8194 const char *ma;
8195 const char *res;
8196 } preimage_domain_tests[] = {
8197 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
8198 "{ A[j,i] -> B[i,j] }",
8199 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
8200 { "{ B[i] -> C[i]; D[i] -> E[i] }",
8201 "{ A[i] -> B[i + 1] }",
8202 "{ A[i] -> C[i + 1] }" },
8203 { "{ B[i] -> C[i]; B[i] -> E[i] }",
8204 "{ A[i] -> B[i + 1] }",
8205 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
8206 { "{ B[i] -> C[([i/2])] }",
8207 "{ A[i] -> B[2i] }",
8208 "{ A[i] -> C[i] }" },
8209 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
8210 "{ A[i] -> B[([i/5]), ([i/7])] }",
8211 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
8212 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
8213 "[N] -> { A[] -> B[([N/5])] }",
8214 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
8215 { "{ B[i] -> C[i] : exists a : i = 5 a }",
8216 "{ A[i] -> B[2i] }",
8217 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
8218 { "{ B[i] -> C[i] : exists a : i = 2 a; "
8219 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
8220 "{ A[i] -> B[2i] }",
8221 "{ A[i] -> C[2i] }" },
8222 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
8223 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
8226 static int test_preimage_union_map(isl_ctx *ctx)
8228 int i;
8229 isl_union_map *umap1, *umap2;
8230 isl_multi_aff *ma;
8231 int equal;
8233 for (i = 0; i < ARRAY_SIZE(preimage_domain_tests); ++i) {
8234 umap1 = isl_union_map_read_from_str(ctx,
8235 preimage_domain_tests[i].map);
8236 ma = isl_multi_aff_read_from_str(ctx,
8237 preimage_domain_tests[i].ma);
8238 umap2 = isl_union_map_read_from_str(ctx,
8239 preimage_domain_tests[i].res);
8240 umap1 = isl_union_map_preimage_domain_multi_aff(umap1, ma);
8241 equal = isl_union_map_is_equal(umap1, umap2);
8242 isl_union_map_free(umap1);
8243 isl_union_map_free(umap2);
8244 if (equal < 0)
8245 return -1;
8246 if (!equal)
8247 isl_die(ctx, isl_error_unknown, "bad preimage",
8248 return -1);
8251 return 0;
8254 static int test_preimage(isl_ctx *ctx)
8256 if (test_preimage_basic_set(ctx) < 0)
8257 return -1;
8258 if (test_preimage_union_map(ctx) < 0)
8259 return -1;
8261 return 0;
8264 struct {
8265 const char *ma1;
8266 const char *ma;
8267 const char *res;
8268 } pullback_tests[] = {
8269 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
8270 "{ A[a,b] -> C[b + 2a] }" },
8271 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
8272 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
8273 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
8274 "{ A[a] -> C[(a)/6] }" },
8275 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
8276 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
8277 "{ A[a] -> C[(2a)/3] }" },
8278 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
8279 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
8280 "{ A[i,j] -> C[i + j, i + j] }"},
8281 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
8282 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
8283 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
8284 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
8285 "{ [i, j] -> [floor((i)/3), j] }",
8286 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
8289 static int test_pullback(isl_ctx *ctx)
8291 int i;
8292 isl_multi_aff *ma1, *ma2;
8293 isl_multi_aff *ma;
8294 int equal;
8296 for (i = 0; i < ARRAY_SIZE(pullback_tests); ++i) {
8297 ma1 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma1);
8298 ma = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma);
8299 ma2 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].res);
8300 ma1 = isl_multi_aff_pullback_multi_aff(ma1, ma);
8301 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
8302 isl_multi_aff_free(ma1);
8303 isl_multi_aff_free(ma2);
8304 if (equal < 0)
8305 return -1;
8306 if (!equal)
8307 isl_die(ctx, isl_error_unknown, "bad pullback",
8308 return -1);
8311 return 0;
8314 /* Check that negation is printed correctly and that equal expressions
8315 * are correctly identified.
8317 static int test_ast(isl_ctx *ctx)
8319 isl_ast_expr *expr, *expr1, *expr2, *expr3;
8320 char *str;
8321 int ok, equal;
8323 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
8324 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
8325 expr = isl_ast_expr_add(expr1, expr2);
8326 expr2 = isl_ast_expr_copy(expr);
8327 expr = isl_ast_expr_neg(expr);
8328 expr2 = isl_ast_expr_neg(expr2);
8329 equal = isl_ast_expr_is_equal(expr, expr2);
8330 str = isl_ast_expr_to_C_str(expr);
8331 ok = str ? !strcmp(str, "-(A + B)") : -1;
8332 free(str);
8333 isl_ast_expr_free(expr);
8334 isl_ast_expr_free(expr2);
8336 if (ok < 0 || equal < 0)
8337 return -1;
8338 if (!equal)
8339 isl_die(ctx, isl_error_unknown,
8340 "equal expressions not considered equal", return -1);
8341 if (!ok)
8342 isl_die(ctx, isl_error_unknown,
8343 "isl_ast_expr printed incorrectly", return -1);
8345 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
8346 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
8347 expr = isl_ast_expr_add(expr1, expr2);
8348 expr3 = isl_ast_expr_from_id(isl_id_alloc(ctx, "C", NULL));
8349 expr = isl_ast_expr_sub(expr3, expr);
8350 str = isl_ast_expr_to_C_str(expr);
8351 ok = str ? !strcmp(str, "C - (A + B)") : -1;
8352 free(str);
8353 isl_ast_expr_free(expr);
8355 if (ok < 0)
8356 return -1;
8357 if (!ok)
8358 isl_die(ctx, isl_error_unknown,
8359 "isl_ast_expr printed incorrectly", return -1);
8361 return 0;
8364 /* Check that isl_ast_build_expr_from_set returns a valid expression
8365 * for an empty set. Note that isl_ast_build_expr_from_set getting
8366 * called on an empty set probably indicates a bug in the caller.
8368 static int test_ast_build(isl_ctx *ctx)
8370 isl_set *set;
8371 isl_ast_build *build;
8372 isl_ast_expr *expr;
8374 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
8375 build = isl_ast_build_from_context(set);
8377 set = isl_set_empty(isl_space_params_alloc(ctx, 0));
8378 expr = isl_ast_build_expr_from_set(build, set);
8380 isl_ast_expr_free(expr);
8381 isl_ast_build_free(build);
8383 if (!expr)
8384 return -1;
8386 return 0;
8389 /* Internal data structure for before_for and after_for callbacks.
8391 * depth is the current depth
8392 * before is the number of times before_for has been called
8393 * after is the number of times after_for has been called
8395 struct isl_test_codegen_data {
8396 int depth;
8397 int before;
8398 int after;
8401 /* This function is called before each for loop in the AST generated
8402 * from test_ast_gen1.
8404 * Increment the number of calls and the depth.
8405 * Check that the space returned by isl_ast_build_get_schedule_space
8406 * matches the target space of the schedule returned by
8407 * isl_ast_build_get_schedule.
8408 * Return an isl_id that is checked by the corresponding call
8409 * to after_for.
8411 static __isl_give isl_id *before_for(__isl_keep isl_ast_build *build,
8412 void *user)
8414 struct isl_test_codegen_data *data = user;
8415 isl_ctx *ctx;
8416 isl_space *space;
8417 isl_union_map *schedule;
8418 isl_union_set *uset;
8419 isl_set *set;
8420 isl_bool empty;
8421 isl_size n;
8422 char name[] = "d0";
8424 ctx = isl_ast_build_get_ctx(build);
8426 if (data->before >= 3)
8427 isl_die(ctx, isl_error_unknown,
8428 "unexpected number of for nodes", return NULL);
8429 if (data->depth >= 2)
8430 isl_die(ctx, isl_error_unknown,
8431 "unexpected depth", return NULL);
8433 snprintf(name, sizeof(name), "d%d", data->depth);
8434 data->before++;
8435 data->depth++;
8437 schedule = isl_ast_build_get_schedule(build);
8438 uset = isl_union_map_range(schedule);
8439 n = isl_union_set_n_set(uset);
8440 if (n != 1) {
8441 isl_union_set_free(uset);
8442 if (n < 0)
8443 return NULL;
8444 isl_die(ctx, isl_error_unknown,
8445 "expecting single range space", return NULL);
8448 space = isl_ast_build_get_schedule_space(build);
8449 set = isl_union_set_extract_set(uset, space);
8450 isl_union_set_free(uset);
8451 empty = isl_set_is_empty(set);
8452 isl_set_free(set);
8454 if (empty < 0)
8455 return NULL;
8456 if (empty)
8457 isl_die(ctx, isl_error_unknown,
8458 "spaces don't match", return NULL);
8460 return isl_id_alloc(ctx, name, NULL);
8463 /* This function is called after each for loop in the AST generated
8464 * from test_ast_gen1.
8466 * Increment the number of calls and decrement the depth.
8467 * Check that the annotation attached to the node matches
8468 * the isl_id returned by the corresponding call to before_for.
8470 static __isl_give isl_ast_node *after_for(__isl_take isl_ast_node *node,
8471 __isl_keep isl_ast_build *build, void *user)
8473 struct isl_test_codegen_data *data = user;
8474 isl_id *id;
8475 const char *name;
8476 int valid;
8478 data->after++;
8479 data->depth--;
8481 if (data->after > data->before)
8482 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
8483 "mismatch in number of for nodes",
8484 return isl_ast_node_free(node));
8486 id = isl_ast_node_get_annotation(node);
8487 if (!id)
8488 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
8489 "missing annotation", return isl_ast_node_free(node));
8491 name = isl_id_get_name(id);
8492 valid = name && atoi(name + 1) == data->depth;
8493 isl_id_free(id);
8495 if (!valid)
8496 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
8497 "wrong annotation", return isl_ast_node_free(node));
8499 return node;
8502 /* Check that the before_each_for and after_each_for callbacks
8503 * are called for each for loop in the generated code,
8504 * that they are called in the right order and that the isl_id
8505 * returned from the before_each_for callback is attached to
8506 * the isl_ast_node passed to the corresponding after_each_for call.
8508 static int test_ast_gen1(isl_ctx *ctx)
8510 const char *str;
8511 isl_set *set;
8512 isl_union_map *schedule;
8513 isl_ast_build *build;
8514 isl_ast_node *tree;
8515 struct isl_test_codegen_data data;
8517 str = "[N] -> { : N >= 10 }";
8518 set = isl_set_read_from_str(ctx, str);
8519 str = "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
8520 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
8521 schedule = isl_union_map_read_from_str(ctx, str);
8523 data.before = 0;
8524 data.after = 0;
8525 data.depth = 0;
8526 build = isl_ast_build_from_context(set);
8527 build = isl_ast_build_set_before_each_for(build,
8528 &before_for, &data);
8529 build = isl_ast_build_set_after_each_for(build,
8530 &after_for, &data);
8531 tree = isl_ast_build_node_from_schedule_map(build, schedule);
8532 isl_ast_build_free(build);
8533 if (!tree)
8534 return -1;
8536 isl_ast_node_free(tree);
8538 if (data.before != 3 || data.after != 3)
8539 isl_die(ctx, isl_error_unknown,
8540 "unexpected number of for nodes", return -1);
8542 return 0;
8545 /* Check that the AST generator handles domains that are integrally disjoint
8546 * but not rationally disjoint.
8548 static int test_ast_gen2(isl_ctx *ctx)
8550 const char *str;
8551 isl_set *set;
8552 isl_union_map *schedule;
8553 isl_union_map *options;
8554 isl_ast_build *build;
8555 isl_ast_node *tree;
8557 str = "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
8558 schedule = isl_union_map_read_from_str(ctx, str);
8559 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
8560 build = isl_ast_build_from_context(set);
8562 str = "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
8563 options = isl_union_map_read_from_str(ctx, str);
8564 build = isl_ast_build_set_options(build, options);
8565 tree = isl_ast_build_node_from_schedule_map(build, schedule);
8566 isl_ast_build_free(build);
8567 if (!tree)
8568 return -1;
8569 isl_ast_node_free(tree);
8571 return 0;
8574 /* Increment *user on each call.
8576 static __isl_give isl_ast_node *count_domains(__isl_take isl_ast_node *node,
8577 __isl_keep isl_ast_build *build, void *user)
8579 int *n = user;
8581 (*n)++;
8583 return node;
8586 /* Test that unrolling tries to minimize the number of instances.
8587 * In particular, for the schedule given below, make sure it generates
8588 * 3 nodes (rather than 101).
8590 static int test_ast_gen3(isl_ctx *ctx)
8592 const char *str;
8593 isl_set *set;
8594 isl_union_map *schedule;
8595 isl_union_map *options;
8596 isl_ast_build *build;
8597 isl_ast_node *tree;
8598 int n_domain = 0;
8600 str = "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
8601 schedule = isl_union_map_read_from_str(ctx, str);
8602 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
8604 str = "{ [i] -> unroll[0] }";
8605 options = isl_union_map_read_from_str(ctx, str);
8607 build = isl_ast_build_from_context(set);
8608 build = isl_ast_build_set_options(build, options);
8609 build = isl_ast_build_set_at_each_domain(build,
8610 &count_domains, &n_domain);
8611 tree = isl_ast_build_node_from_schedule_map(build, schedule);
8612 isl_ast_build_free(build);
8613 if (!tree)
8614 return -1;
8616 isl_ast_node_free(tree);
8618 if (n_domain != 3)
8619 isl_die(ctx, isl_error_unknown,
8620 "unexpected number of for nodes", return -1);
8622 return 0;
8625 /* Check that if the ast_build_exploit_nested_bounds options is set,
8626 * we do not get an outer if node in the generated AST,
8627 * while we do get such an outer if node if the options is not set.
8629 static int test_ast_gen4(isl_ctx *ctx)
8631 const char *str;
8632 isl_set *set;
8633 isl_union_map *schedule;
8634 isl_ast_build *build;
8635 isl_ast_node *tree;
8636 enum isl_ast_node_type type;
8637 int enb;
8639 enb = isl_options_get_ast_build_exploit_nested_bounds(ctx);
8640 str = "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
8642 isl_options_set_ast_build_exploit_nested_bounds(ctx, 1);
8644 schedule = isl_union_map_read_from_str(ctx, str);
8645 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
8646 build = isl_ast_build_from_context(set);
8647 tree = isl_ast_build_node_from_schedule_map(build, schedule);
8648 isl_ast_build_free(build);
8649 if (!tree)
8650 return -1;
8652 type = isl_ast_node_get_type(tree);
8653 isl_ast_node_free(tree);
8655 if (type == isl_ast_node_if)
8656 isl_die(ctx, isl_error_unknown,
8657 "not expecting if node", return -1);
8659 isl_options_set_ast_build_exploit_nested_bounds(ctx, 0);
8661 schedule = isl_union_map_read_from_str(ctx, str);
8662 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
8663 build = isl_ast_build_from_context(set);
8664 tree = isl_ast_build_node_from_schedule_map(build, schedule);
8665 isl_ast_build_free(build);
8666 if (!tree)
8667 return -1;
8669 type = isl_ast_node_get_type(tree);
8670 isl_ast_node_free(tree);
8672 if (type != isl_ast_node_if)
8673 isl_die(ctx, isl_error_unknown,
8674 "expecting if node", return -1);
8676 isl_options_set_ast_build_exploit_nested_bounds(ctx, enb);
8678 return 0;
8681 /* This function is called for each leaf in the AST generated
8682 * from test_ast_gen5.
8684 * We finalize the AST generation by extending the outer schedule
8685 * with a zero-dimensional schedule. If this results in any for loops,
8686 * then this means that we did not pass along enough information
8687 * about the outer schedule to the inner AST generation.
8689 static __isl_give isl_ast_node *create_leaf(__isl_take isl_ast_build *build,
8690 void *user)
8692 isl_union_map *schedule, *extra;
8693 isl_ast_node *tree;
8695 schedule = isl_ast_build_get_schedule(build);
8696 extra = isl_union_map_copy(schedule);
8697 extra = isl_union_map_from_domain(isl_union_map_domain(extra));
8698 schedule = isl_union_map_range_product(schedule, extra);
8699 tree = isl_ast_build_node_from_schedule_map(build, schedule);
8700 isl_ast_build_free(build);
8702 if (!tree)
8703 return NULL;
8705 if (isl_ast_node_get_type(tree) == isl_ast_node_for)
8706 isl_die(isl_ast_node_get_ctx(tree), isl_error_unknown,
8707 "code should not contain any for loop",
8708 return isl_ast_node_free(tree));
8710 return tree;
8713 /* Check that we do not lose any information when going back and
8714 * forth between internal and external schedule.
8716 * In particular, we create an AST where we unroll the only
8717 * non-constant dimension in the schedule. We therefore do
8718 * not expect any for loops in the AST. However, older versions
8719 * of isl would not pass along enough information about the outer
8720 * schedule when performing an inner code generation from a create_leaf
8721 * callback, resulting in the inner code generation producing a for loop.
8723 static int test_ast_gen5(isl_ctx *ctx)
8725 const char *str;
8726 isl_set *set;
8727 isl_union_map *schedule, *options;
8728 isl_ast_build *build;
8729 isl_ast_node *tree;
8731 str = "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
8732 schedule = isl_union_map_read_from_str(ctx, str);
8734 str = "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
8735 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
8736 options = isl_union_map_read_from_str(ctx, str);
8738 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
8739 build = isl_ast_build_from_context(set);
8740 build = isl_ast_build_set_options(build, options);
8741 build = isl_ast_build_set_create_leaf(build, &create_leaf, NULL);
8742 tree = isl_ast_build_node_from_schedule_map(build, schedule);
8743 isl_ast_build_free(build);
8744 isl_ast_node_free(tree);
8745 if (!tree)
8746 return -1;
8748 return 0;
8751 /* Check that the expression
8753 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
8755 * is not combined into
8757 * min(n/2, 0)
8759 * as this would result in n/2 being evaluated in parts of
8760 * the definition domain where n is not a multiple of 2.
8762 static int test_ast_expr(isl_ctx *ctx)
8764 const char *str;
8765 isl_pw_aff *pa;
8766 isl_ast_build *build;
8767 isl_ast_expr *expr;
8768 int min_max;
8769 int is_min;
8771 min_max = isl_options_get_ast_build_detect_min_max(ctx);
8772 isl_options_set_ast_build_detect_min_max(ctx, 1);
8774 str = "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
8775 pa = isl_pw_aff_read_from_str(ctx, str);
8776 build = isl_ast_build_alloc(ctx);
8777 expr = isl_ast_build_expr_from_pw_aff(build, pa);
8778 is_min = isl_ast_expr_get_type(expr) == isl_ast_expr_op &&
8779 isl_ast_expr_get_op_type(expr) == isl_ast_expr_op_min;
8780 isl_ast_build_free(build);
8781 isl_ast_expr_free(expr);
8783 isl_options_set_ast_build_detect_min_max(ctx, min_max);
8785 if (!expr)
8786 return -1;
8787 if (is_min)
8788 isl_die(ctx, isl_error_unknown,
8789 "expressions should not be combined", return -1);
8791 return 0;
8794 static int test_ast_gen(isl_ctx *ctx)
8796 if (test_ast_gen1(ctx) < 0)
8797 return -1;
8798 if (test_ast_gen2(ctx) < 0)
8799 return -1;
8800 if (test_ast_gen3(ctx) < 0)
8801 return -1;
8802 if (test_ast_gen4(ctx) < 0)
8803 return -1;
8804 if (test_ast_gen5(ctx) < 0)
8805 return -1;
8806 if (test_ast_expr(ctx) < 0)
8807 return -1;
8808 return 0;
8811 /* Check if dropping output dimensions from an isl_pw_multi_aff
8812 * works properly.
8814 static int test_pw_multi_aff(isl_ctx *ctx)
8816 const char *str;
8817 isl_pw_multi_aff *pma1, *pma2;
8818 int equal;
8820 str = "{ [i,j] -> [i+j, 4i-j] }";
8821 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
8822 str = "{ [i,j] -> [4i-j] }";
8823 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
8825 pma1 = isl_pw_multi_aff_drop_dims(pma1, isl_dim_out, 0, 1);
8827 equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
8829 isl_pw_multi_aff_free(pma1);
8830 isl_pw_multi_aff_free(pma2);
8831 if (equal < 0)
8832 return -1;
8833 if (!equal)
8834 isl_die(ctx, isl_error_unknown,
8835 "expressions not equal", return -1);
8837 return 0;
8840 /* Check that we can properly parse multi piecewise affine expressions
8841 * where the piecewise affine expressions have different domains.
8843 static int test_multi_pw_aff_1(isl_ctx *ctx)
8845 const char *str;
8846 isl_set *dom, *dom2;
8847 isl_multi_pw_aff *mpa1, *mpa2;
8848 isl_pw_aff *pa;
8849 int equal;
8850 int equal_domain;
8852 mpa1 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [i] }");
8853 dom = isl_set_read_from_str(ctx, "{ [i] : i > 0 }");
8854 mpa1 = isl_multi_pw_aff_intersect_domain(mpa1, dom);
8855 mpa2 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [2i] }");
8856 mpa2 = isl_multi_pw_aff_flat_range_product(mpa1, mpa2);
8857 str = "{ [i] -> [(i : i > 0), 2i] }";
8858 mpa1 = isl_multi_pw_aff_read_from_str(ctx, str);
8860 equal = isl_multi_pw_aff_plain_is_equal(mpa1, mpa2);
8862 pa = isl_multi_pw_aff_get_pw_aff(mpa1, 0);
8863 dom = isl_pw_aff_domain(pa);
8864 pa = isl_multi_pw_aff_get_pw_aff(mpa1, 1);
8865 dom2 = isl_pw_aff_domain(pa);
8866 equal_domain = isl_set_is_equal(dom, dom2);
8868 isl_set_free(dom);
8869 isl_set_free(dom2);
8870 isl_multi_pw_aff_free(mpa1);
8871 isl_multi_pw_aff_free(mpa2);
8873 if (equal < 0)
8874 return -1;
8875 if (!equal)
8876 isl_die(ctx, isl_error_unknown,
8877 "expressions not equal", return -1);
8879 if (equal_domain < 0)
8880 return -1;
8881 if (equal_domain)
8882 isl_die(ctx, isl_error_unknown,
8883 "domains unexpectedly equal", return -1);
8885 return 0;
8888 /* Check that the dimensions in the explicit domain
8889 * of a multi piecewise affine expression are properly
8890 * taken into account.
8892 static int test_multi_pw_aff_2(isl_ctx *ctx)
8894 const char *str;
8895 isl_bool involves1, involves2, involves3, equal;
8896 isl_multi_pw_aff *mpa, *mpa1, *mpa2;
8898 str = "{ A[x,y] -> B[] : x >= y }";
8899 mpa = isl_multi_pw_aff_read_from_str(ctx, str);
8900 involves1 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 2);
8901 mpa1 = isl_multi_pw_aff_copy(mpa);
8903 mpa = isl_multi_pw_aff_insert_dims(mpa, isl_dim_in, 0, 1);
8904 involves2 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 1);
8905 involves3 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 1, 2);
8906 str = "{ [a,x,y] -> B[] : x >= y }";
8907 mpa2 = isl_multi_pw_aff_read_from_str(ctx, str);
8908 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2);
8909 isl_multi_pw_aff_free(mpa2);
8911 mpa = isl_multi_pw_aff_drop_dims(mpa, isl_dim_in, 0, 1);
8912 mpa = isl_multi_pw_aff_set_tuple_name(mpa, isl_dim_in, "A");
8913 if (equal >= 0 && equal)
8914 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa1);
8915 isl_multi_pw_aff_free(mpa1);
8916 isl_multi_pw_aff_free(mpa);
8918 if (involves1 < 0 || involves2 < 0 || involves3 < 0 || equal < 0)
8919 return -1;
8920 if (!equal)
8921 isl_die(ctx, isl_error_unknown,
8922 "incorrect result of dimension insertion/removal",
8923 return isl_stat_error);
8924 if (!involves1 || involves2 || !involves3)
8925 isl_die(ctx, isl_error_unknown,
8926 "incorrect characterization of involved dimensions",
8927 return isl_stat_error);
8929 return 0;
8932 /* Check that isl_multi_union_pw_aff_multi_val_on_domain
8933 * sets the explicit domain of a zero-dimensional result,
8934 * such that it can be converted to an isl_union_map.
8936 static isl_stat test_multi_pw_aff_3(isl_ctx *ctx)
8938 isl_space *space;
8939 isl_union_set *dom;
8940 isl_multi_val *mv;
8941 isl_multi_union_pw_aff *mupa;
8942 isl_union_map *umap;
8944 dom = isl_union_set_read_from_str(ctx, "{ A[]; B[] }");
8945 space = isl_union_set_get_space(dom);
8946 mv = isl_multi_val_zero(isl_space_set_from_params(space));
8947 mupa = isl_multi_union_pw_aff_multi_val_on_domain(dom, mv);
8948 umap = isl_union_map_from_multi_union_pw_aff(mupa);
8949 isl_union_map_free(umap);
8950 if (!umap)
8951 return isl_stat_error;
8953 return isl_stat_ok;
8956 /* Perform some tests on multi piecewise affine expressions.
8958 static int test_multi_pw_aff(isl_ctx *ctx)
8960 if (test_multi_pw_aff_1(ctx) < 0)
8961 return -1;
8962 if (test_multi_pw_aff_2(ctx) < 0)
8963 return -1;
8964 if (test_multi_pw_aff_3(ctx) < 0)
8965 return -1;
8966 return 0;
8969 /* This is a regression test for a bug where isl_basic_map_simplify
8970 * would end up in an infinite loop. In particular, we construct
8971 * an empty basic set that is not obviously empty.
8972 * isl_basic_set_is_empty marks the basic set as empty.
8973 * After projecting out i3, the variable can be dropped completely,
8974 * but isl_basic_map_simplify refrains from doing so if the basic set
8975 * is empty and would end up in an infinite loop if it didn't test
8976 * explicitly for empty basic maps in the outer loop.
8978 static int test_simplify_1(isl_ctx *ctx)
8980 const char *str;
8981 isl_basic_set *bset;
8982 int empty;
8984 str = "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
8985 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
8986 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
8987 "i3 >= i2 }";
8988 bset = isl_basic_set_read_from_str(ctx, str);
8989 empty = isl_basic_set_is_empty(bset);
8990 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
8991 isl_basic_set_free(bset);
8992 if (!bset)
8993 return -1;
8994 if (!empty)
8995 isl_die(ctx, isl_error_unknown,
8996 "basic set should be empty", return -1);
8998 return 0;
9001 /* Check that the equality in the set description below
9002 * is simplified away.
9004 static int test_simplify_2(isl_ctx *ctx)
9006 const char *str;
9007 isl_basic_set *bset;
9008 isl_bool universe;
9010 str = "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
9011 bset = isl_basic_set_read_from_str(ctx, str);
9012 universe = isl_basic_set_plain_is_universe(bset);
9013 isl_basic_set_free(bset);
9015 if (universe < 0)
9016 return -1;
9017 if (!universe)
9018 isl_die(ctx, isl_error_unknown,
9019 "equality not simplified away", return -1);
9020 return 0;
9023 /* Some simplification tests.
9025 static int test_simplify(isl_ctx *ctx)
9027 if (test_simplify_1(ctx) < 0)
9028 return -1;
9029 if (test_simplify_2(ctx) < 0)
9030 return -1;
9031 return 0;
9034 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
9035 * with gbr context would fail to disable the use of the shifted tableau
9036 * when transferring equalities for the input to the context, resulting
9037 * in invalid sample values.
9039 static int test_partial_lexmin(isl_ctx *ctx)
9041 const char *str;
9042 isl_basic_set *bset;
9043 isl_basic_map *bmap;
9044 isl_map *map;
9046 str = "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
9047 bmap = isl_basic_map_read_from_str(ctx, str);
9048 str = "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
9049 bset = isl_basic_set_read_from_str(ctx, str);
9050 map = isl_basic_map_partial_lexmin(bmap, bset, NULL);
9051 isl_map_free(map);
9053 if (!map)
9054 return -1;
9056 return 0;
9059 /* Check that the variable compression performed on the existentially
9060 * quantified variables inside isl_basic_set_compute_divs is not confused
9061 * by the implicit equalities among the parameters.
9063 static int test_compute_divs(isl_ctx *ctx)
9065 const char *str;
9066 isl_basic_set *bset;
9067 isl_set *set;
9069 str = "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
9070 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
9071 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
9072 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
9073 bset = isl_basic_set_read_from_str(ctx, str);
9074 set = isl_basic_set_compute_divs(bset);
9075 isl_set_free(set);
9076 if (!set)
9077 return -1;
9079 return 0;
9082 /* Check that isl_schedule_get_map is not confused by a schedule tree
9083 * with divergent filter node parameters, as can result from a call
9084 * to isl_schedule_intersect_domain.
9086 static int test_schedule_tree(isl_ctx *ctx)
9088 const char *str;
9089 isl_union_set *uset;
9090 isl_schedule *sched1, *sched2;
9091 isl_union_map *umap;
9093 uset = isl_union_set_read_from_str(ctx, "{ A[i] }");
9094 sched1 = isl_schedule_from_domain(uset);
9095 uset = isl_union_set_read_from_str(ctx, "{ B[] }");
9096 sched2 = isl_schedule_from_domain(uset);
9098 sched1 = isl_schedule_sequence(sched1, sched2);
9099 str = "[n] -> { A[i] : 0 <= i < n; B[] }";
9100 uset = isl_union_set_read_from_str(ctx, str);
9101 sched1 = isl_schedule_intersect_domain(sched1, uset);
9102 umap = isl_schedule_get_map(sched1);
9103 isl_schedule_free(sched1);
9104 isl_union_map_free(umap);
9105 if (!umap)
9106 return -1;
9108 return 0;
9111 /* Check that a zero-dimensional prefix schedule keeps track
9112 * of the domain and outer filters.
9114 static int test_schedule_tree_prefix(isl_ctx *ctx)
9116 const char *str;
9117 isl_bool equal;
9118 isl_union_set *uset;
9119 isl_union_set_list *filters;
9120 isl_multi_union_pw_aff *mupa, *mupa2;
9121 isl_schedule_node *node;
9123 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
9124 uset = isl_union_set_read_from_str(ctx, str);
9125 node = isl_schedule_node_from_domain(uset);
9126 node = isl_schedule_node_child(node, 0);
9128 str = "{ S1[i,j] : i > j }";
9129 uset = isl_union_set_read_from_str(ctx, str);
9130 filters = isl_union_set_list_from_union_set(uset);
9131 str = "{ S1[i,j] : i <= j; S2[i,j] }";
9132 uset = isl_union_set_read_from_str(ctx, str);
9133 filters = isl_union_set_list_add(filters, uset);
9134 node = isl_schedule_node_insert_sequence(node, filters);
9136 node = isl_schedule_node_child(node, 0);
9137 node = isl_schedule_node_child(node, 0);
9138 mupa = isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node);
9139 str = "([] : { S1[i,j] : i > j })";
9140 mupa2 = isl_multi_union_pw_aff_read_from_str(ctx, str);
9141 equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2);
9142 isl_multi_union_pw_aff_free(mupa2);
9143 isl_multi_union_pw_aff_free(mupa);
9144 isl_schedule_node_free(node);
9146 if (equal < 0)
9147 return -1;
9148 if (!equal)
9149 isl_die(ctx, isl_error_unknown, "unexpected prefix schedule",
9150 return -1);
9152 return 0;
9155 /* Check that the reaching domain elements and the prefix schedule
9156 * at a leaf node are the same before and after grouping.
9158 static int test_schedule_tree_group_1(isl_ctx *ctx)
9160 int equal;
9161 const char *str;
9162 isl_id *id;
9163 isl_union_set *uset;
9164 isl_multi_union_pw_aff *mupa;
9165 isl_union_pw_multi_aff *upma1, *upma2;
9166 isl_union_set *domain1, *domain2;
9167 isl_union_map *umap1, *umap2;
9168 isl_schedule_node *node;
9170 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
9171 uset = isl_union_set_read_from_str(ctx, str);
9172 node = isl_schedule_node_from_domain(uset);
9173 node = isl_schedule_node_child(node, 0);
9174 str = "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
9175 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
9176 node = isl_schedule_node_insert_partial_schedule(node, mupa);
9177 node = isl_schedule_node_child(node, 0);
9178 str = "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
9179 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
9180 node = isl_schedule_node_insert_partial_schedule(node, mupa);
9181 node = isl_schedule_node_child(node, 0);
9182 umap1 = isl_schedule_node_get_prefix_schedule_union_map(node);
9183 upma1 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node);
9184 domain1 = isl_schedule_node_get_domain(node);
9185 id = isl_id_alloc(ctx, "group", NULL);
9186 node = isl_schedule_node_parent(node);
9187 node = isl_schedule_node_group(node, id);
9188 node = isl_schedule_node_child(node, 0);
9189 umap2 = isl_schedule_node_get_prefix_schedule_union_map(node);
9190 upma2 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node);
9191 domain2 = isl_schedule_node_get_domain(node);
9192 equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2);
9193 if (equal >= 0 && equal)
9194 equal = isl_union_set_is_equal(domain1, domain2);
9195 if (equal >= 0 && equal)
9196 equal = isl_union_map_is_equal(umap1, umap2);
9197 isl_union_map_free(umap1);
9198 isl_union_map_free(umap2);
9199 isl_union_set_free(domain1);
9200 isl_union_set_free(domain2);
9201 isl_union_pw_multi_aff_free(upma1);
9202 isl_union_pw_multi_aff_free(upma2);
9203 isl_schedule_node_free(node);
9205 if (equal < 0)
9206 return -1;
9207 if (!equal)
9208 isl_die(ctx, isl_error_unknown,
9209 "expressions not equal", return -1);
9211 return 0;
9214 /* Check that we can have nested groupings and that the union map
9215 * schedule representation is the same before and after the grouping.
9216 * Note that after the grouping, the union map representation contains
9217 * the domain constraints from the ranges of the expansion nodes,
9218 * while they are missing from the union map representation of
9219 * the tree without expansion nodes.
9221 * Also check that the global expansion is as expected.
9223 static int test_schedule_tree_group_2(isl_ctx *ctx)
9225 int equal, equal_expansion;
9226 const char *str;
9227 isl_id *id;
9228 isl_union_set *uset;
9229 isl_union_map *umap1, *umap2;
9230 isl_union_map *expansion1, *expansion2;
9231 isl_union_set_list *filters;
9232 isl_multi_union_pw_aff *mupa;
9233 isl_schedule *schedule;
9234 isl_schedule_node *node;
9236 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
9237 "S3[i,j] : 0 <= i,j < 10 }";
9238 uset = isl_union_set_read_from_str(ctx, str);
9239 node = isl_schedule_node_from_domain(uset);
9240 node = isl_schedule_node_child(node, 0);
9241 str = "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
9242 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
9243 node = isl_schedule_node_insert_partial_schedule(node, mupa);
9244 node = isl_schedule_node_child(node, 0);
9245 str = "{ S1[i,j] }";
9246 uset = isl_union_set_read_from_str(ctx, str);
9247 filters = isl_union_set_list_from_union_set(uset);
9248 str = "{ S2[i,j]; S3[i,j] }";
9249 uset = isl_union_set_read_from_str(ctx, str);
9250 filters = isl_union_set_list_add(filters, uset);
9251 node = isl_schedule_node_insert_sequence(node, filters);
9252 node = isl_schedule_node_child(node, 1);
9253 node = isl_schedule_node_child(node, 0);
9254 str = "{ S2[i,j] }";
9255 uset = isl_union_set_read_from_str(ctx, str);
9256 filters = isl_union_set_list_from_union_set(uset);
9257 str = "{ S3[i,j] }";
9258 uset = isl_union_set_read_from_str(ctx, str);
9259 filters = isl_union_set_list_add(filters, uset);
9260 node = isl_schedule_node_insert_sequence(node, filters);
9262 schedule = isl_schedule_node_get_schedule(node);
9263 umap1 = isl_schedule_get_map(schedule);
9264 uset = isl_schedule_get_domain(schedule);
9265 umap1 = isl_union_map_intersect_domain(umap1, uset);
9266 isl_schedule_free(schedule);
9268 node = isl_schedule_node_parent(node);
9269 node = isl_schedule_node_parent(node);
9270 id = isl_id_alloc(ctx, "group1", NULL);
9271 node = isl_schedule_node_group(node, id);
9272 node = isl_schedule_node_child(node, 1);
9273 node = isl_schedule_node_child(node, 0);
9274 id = isl_id_alloc(ctx, "group2", NULL);
9275 node = isl_schedule_node_group(node, id);
9277 schedule = isl_schedule_node_get_schedule(node);
9278 umap2 = isl_schedule_get_map(schedule);
9279 isl_schedule_free(schedule);
9281 node = isl_schedule_node_root(node);
9282 node = isl_schedule_node_child(node, 0);
9283 expansion1 = isl_schedule_node_get_subtree_expansion(node);
9284 isl_schedule_node_free(node);
9286 str = "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
9287 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
9288 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
9290 expansion2 = isl_union_map_read_from_str(ctx, str);
9292 equal = isl_union_map_is_equal(umap1, umap2);
9293 equal_expansion = isl_union_map_is_equal(expansion1, expansion2);
9295 isl_union_map_free(umap1);
9296 isl_union_map_free(umap2);
9297 isl_union_map_free(expansion1);
9298 isl_union_map_free(expansion2);
9300 if (equal < 0 || equal_expansion < 0)
9301 return -1;
9302 if (!equal)
9303 isl_die(ctx, isl_error_unknown,
9304 "expressions not equal", return -1);
9305 if (!equal_expansion)
9306 isl_die(ctx, isl_error_unknown,
9307 "unexpected expansion", return -1);
9309 return 0;
9312 /* Some tests for the isl_schedule_node_group function.
9314 static int test_schedule_tree_group(isl_ctx *ctx)
9316 if (test_schedule_tree_group_1(ctx) < 0)
9317 return -1;
9318 if (test_schedule_tree_group_2(ctx) < 0)
9319 return -1;
9320 return 0;
9323 struct {
9324 const char *set;
9325 const char *dual;
9326 } coef_tests[] = {
9327 { "{ rat: [i] : 0 <= i <= 10 }",
9328 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
9329 { "{ rat: [i] : FALSE }",
9330 "{ rat: coefficients[[cst] -> [a]] }" },
9331 { "{ rat: [i] : }",
9332 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
9335 struct {
9336 const char *set;
9337 const char *dual;
9338 } sol_tests[] = {
9339 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
9340 "{ rat: [i] : 0 <= i <= 10 }" },
9341 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
9342 "{ rat: [i] }" },
9343 { "{ rat: coefficients[[cst] -> [a]] }",
9344 "{ rat: [i] : FALSE }" },
9347 /* Test the basic functionality of isl_basic_set_coefficients and
9348 * isl_basic_set_solutions.
9350 static int test_dual(isl_ctx *ctx)
9352 int i;
9354 for (i = 0; i < ARRAY_SIZE(coef_tests); ++i) {
9355 int equal;
9356 isl_basic_set *bset1, *bset2;
9358 bset1 = isl_basic_set_read_from_str(ctx, coef_tests[i].set);
9359 bset2 = isl_basic_set_read_from_str(ctx, coef_tests[i].dual);
9360 bset1 = isl_basic_set_coefficients(bset1);
9361 equal = isl_basic_set_is_equal(bset1, bset2);
9362 isl_basic_set_free(bset1);
9363 isl_basic_set_free(bset2);
9364 if (equal < 0)
9365 return -1;
9366 if (!equal)
9367 isl_die(ctx, isl_error_unknown,
9368 "incorrect dual", return -1);
9371 for (i = 0; i < ARRAY_SIZE(sol_tests); ++i) {
9372 int equal;
9373 isl_basic_set *bset1, *bset2;
9375 bset1 = isl_basic_set_read_from_str(ctx, sol_tests[i].set);
9376 bset2 = isl_basic_set_read_from_str(ctx, sol_tests[i].dual);
9377 bset1 = isl_basic_set_solutions(bset1);
9378 equal = isl_basic_set_is_equal(bset1, bset2);
9379 isl_basic_set_free(bset1);
9380 isl_basic_set_free(bset2);
9381 if (equal < 0)
9382 return -1;
9383 if (!equal)
9384 isl_die(ctx, isl_error_unknown,
9385 "incorrect dual", return -1);
9388 return 0;
9391 struct {
9392 int scale_tile;
9393 int shift_point;
9394 const char *domain;
9395 const char *schedule;
9396 const char *sizes;
9397 const char *tile;
9398 const char *point;
9399 } tile_tests[] = {
9400 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
9401 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9402 "{ [32,32] }",
9403 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
9404 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9406 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
9407 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9408 "{ [32,32] }",
9409 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
9410 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9412 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
9413 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9414 "{ [32,32] }",
9415 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
9416 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
9418 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
9419 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
9420 "{ [32,32] }",
9421 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
9422 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
9426 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
9427 * tile the band and then check if the tile and point bands have the
9428 * expected partial schedule.
9430 static int test_tile(isl_ctx *ctx)
9432 int i;
9433 int scale;
9434 int shift;
9436 scale = isl_options_get_tile_scale_tile_loops(ctx);
9437 shift = isl_options_get_tile_shift_point_loops(ctx);
9439 for (i = 0; i < ARRAY_SIZE(tile_tests); ++i) {
9440 int opt;
9441 int equal;
9442 const char *str;
9443 isl_union_set *domain;
9444 isl_multi_union_pw_aff *mupa, *mupa2;
9445 isl_schedule_node *node;
9446 isl_multi_val *sizes;
9448 opt = tile_tests[i].scale_tile;
9449 isl_options_set_tile_scale_tile_loops(ctx, opt);
9450 opt = tile_tests[i].shift_point;
9451 isl_options_set_tile_shift_point_loops(ctx, opt);
9453 str = tile_tests[i].domain;
9454 domain = isl_union_set_read_from_str(ctx, str);
9455 node = isl_schedule_node_from_domain(domain);
9456 node = isl_schedule_node_child(node, 0);
9457 str = tile_tests[i].schedule;
9458 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
9459 node = isl_schedule_node_insert_partial_schedule(node, mupa);
9460 str = tile_tests[i].sizes;
9461 sizes = isl_multi_val_read_from_str(ctx, str);
9462 node = isl_schedule_node_band_tile(node, sizes);
9464 str = tile_tests[i].tile;
9465 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
9466 mupa2 = isl_schedule_node_band_get_partial_schedule(node);
9467 equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2);
9468 isl_multi_union_pw_aff_free(mupa);
9469 isl_multi_union_pw_aff_free(mupa2);
9471 node = isl_schedule_node_child(node, 0);
9473 str = tile_tests[i].point;
9474 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
9475 mupa2 = isl_schedule_node_band_get_partial_schedule(node);
9476 if (equal >= 0 && equal)
9477 equal = isl_multi_union_pw_aff_plain_is_equal(mupa,
9478 mupa2);
9479 isl_multi_union_pw_aff_free(mupa);
9480 isl_multi_union_pw_aff_free(mupa2);
9482 isl_schedule_node_free(node);
9484 if (equal < 0)
9485 return -1;
9486 if (!equal)
9487 isl_die(ctx, isl_error_unknown,
9488 "unexpected result", return -1);
9491 isl_options_set_tile_scale_tile_loops(ctx, scale);
9492 isl_options_set_tile_shift_point_loops(ctx, shift);
9494 return 0;
9497 /* Check that the domain hash of a space is equal to the hash
9498 * of the domain of the space.
9500 static int test_domain_hash(isl_ctx *ctx)
9502 isl_map *map;
9503 isl_space *space;
9504 uint32_t hash1, hash2;
9506 map = isl_map_read_from_str(ctx, "[n] -> { A[B[x] -> C[]] -> D[] }");
9507 space = isl_map_get_space(map);
9508 isl_map_free(map);
9509 hash1 = isl_space_get_domain_hash(space);
9510 space = isl_space_domain(space);
9511 hash2 = isl_space_get_hash(space);
9512 isl_space_free(space);
9514 if (!space)
9515 return -1;
9516 if (hash1 != hash2)
9517 isl_die(ctx, isl_error_unknown,
9518 "domain hash not equal to hash of domain", return -1);
9520 return 0;
9523 /* Check that a universe basic set that is not obviously equal to the universe
9524 * is still recognized as being equal to the universe.
9526 static int test_universe(isl_ctx *ctx)
9528 const char *s;
9529 isl_basic_set *bset;
9530 isl_bool is_univ;
9532 s = "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
9533 bset = isl_basic_set_read_from_str(ctx, s);
9534 is_univ = isl_basic_set_is_universe(bset);
9535 isl_basic_set_free(bset);
9537 if (is_univ < 0)
9538 return -1;
9539 if (!is_univ)
9540 isl_die(ctx, isl_error_unknown,
9541 "not recognized as universe set", return -1);
9543 return 0;
9546 /* Sets for which chambers are computed and checked.
9548 const char *chambers_tests[] = {
9549 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
9550 "z >= 0 and z <= C - y and z <= B - x - y }",
9553 /* Add the domain of "cell" to "cells".
9555 static isl_stat add_cell(__isl_take isl_cell *cell, void *user)
9557 isl_basic_set_list **cells = user;
9558 isl_basic_set *dom;
9560 dom = isl_cell_get_domain(cell);
9561 isl_cell_free(cell);
9562 *cells = isl_basic_set_list_add(*cells, dom);
9564 return *cells ? isl_stat_ok : isl_stat_error;
9567 /* Check that the elements of "list" are pairwise disjoint.
9569 static isl_stat check_pairwise_disjoint(__isl_keep isl_basic_set_list *list)
9571 int i, j;
9572 isl_size n;
9574 n = isl_basic_set_list_n_basic_set(list);
9575 if (n < 0)
9576 return isl_stat_error;
9578 for (i = 0; i < n; ++i) {
9579 isl_basic_set *bset_i;
9581 bset_i = isl_basic_set_list_get_basic_set(list, i);
9582 for (j = i + 1; j < n; ++j) {
9583 isl_basic_set *bset_j;
9584 isl_bool disjoint;
9586 bset_j = isl_basic_set_list_get_basic_set(list, j);
9587 disjoint = isl_basic_set_is_disjoint(bset_i, bset_j);
9588 isl_basic_set_free(bset_j);
9589 if (!disjoint)
9590 isl_die(isl_basic_set_list_get_ctx(list),
9591 isl_error_unknown, "not disjoint",
9592 break);
9593 if (disjoint < 0 || !disjoint)
9594 break;
9596 isl_basic_set_free(bset_i);
9597 if (j < n)
9598 return isl_stat_error;
9601 return isl_stat_ok;
9604 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
9605 * are pairwise disjoint.
9607 static int test_chambers(isl_ctx *ctx)
9609 int i;
9611 for (i = 0; i < ARRAY_SIZE(chambers_tests); ++i) {
9612 isl_basic_set *bset;
9613 isl_vertices *vertices;
9614 isl_basic_set_list *cells;
9615 isl_stat ok;
9617 bset = isl_basic_set_read_from_str(ctx, chambers_tests[i]);
9618 vertices = isl_basic_set_compute_vertices(bset);
9619 cells = isl_basic_set_list_alloc(ctx, 0);
9620 if (isl_vertices_foreach_disjoint_cell(vertices, &add_cell,
9621 &cells) < 0)
9622 cells = isl_basic_set_list_free(cells);
9623 ok = check_pairwise_disjoint(cells);
9624 isl_basic_set_list_free(cells);
9625 isl_vertices_free(vertices);
9626 isl_basic_set_free(bset);
9628 if (ok < 0)
9629 return -1;
9632 return 0;
9635 struct {
9636 const char *name;
9637 int (*fn)(isl_ctx *ctx);
9638 } tests [] = {
9639 { "universe", &test_universe },
9640 { "domain hash", &test_domain_hash },
9641 { "dual", &test_dual },
9642 { "dependence analysis", &test_flow },
9643 { "val", &test_val },
9644 { "compute divs", &test_compute_divs },
9645 { "partial lexmin", &test_partial_lexmin },
9646 { "simplify", &test_simplify },
9647 { "curry", &test_curry },
9648 { "piecewise multi affine expressions", &test_pw_multi_aff },
9649 { "multi piecewise affine expressions", &test_multi_pw_aff },
9650 { "conversion", &test_conversion },
9651 { "list", &test_list },
9652 { "align parameters", &test_align_parameters },
9653 { "drop unused parameters", &test_drop_unused_parameters },
9654 { "preimage", &test_preimage },
9655 { "pullback", &test_pullback },
9656 { "AST", &test_ast },
9657 { "AST build", &test_ast_build },
9658 { "AST generation", &test_ast_gen },
9659 { "eliminate", &test_eliminate },
9660 { "deltas_map", &test_deltas_map },
9661 { "residue class", &test_residue_class },
9662 { "div", &test_div },
9663 { "slice", &test_slice },
9664 { "fixed power", &test_fixed_power },
9665 { "sample", &test_sample },
9666 { "output", &test_output },
9667 { "vertices", &test_vertices },
9668 { "chambers", &test_chambers },
9669 { "fixed", &test_fixed },
9670 { "equal", &test_equal },
9671 { "disjoint", &test_disjoint },
9672 { "product", &test_product },
9673 { "dim_max", &test_dim_max },
9674 { "affine", &test_aff },
9675 { "injective", &test_injective },
9676 { "schedule (whole component)", &test_schedule_whole },
9677 { "schedule (incremental)", &test_schedule_incremental },
9678 { "schedule tree", &test_schedule_tree },
9679 { "schedule tree prefix", &test_schedule_tree_prefix },
9680 { "schedule tree grouping", &test_schedule_tree_group },
9681 { "tile", &test_tile },
9682 { "union_pw", &test_union_pw },
9683 { "locus", &test_locus },
9684 { "eval", &test_eval },
9685 { "parse", &test_parse },
9686 { "single-valued", &test_sv },
9687 { "affine hull", &test_affine_hull },
9688 { "simple_hull", &test_simple_hull },
9689 { "coalesce", &test_coalesce },
9690 { "factorize", &test_factorize },
9691 { "subset", &test_subset },
9692 { "subtract", &test_subtract },
9693 { "intersect", &test_intersect },
9694 { "lexmin", &test_lexmin },
9695 { "min", &test_min },
9696 { "gist", &test_gist },
9697 { "piecewise quasi-polynomials", &test_pwqp },
9698 { "lift", &test_lift },
9699 { "bind parameters", &test_bind },
9700 { "unbind parameters", &test_unbind },
9701 { "bound", &test_bound },
9702 { "get lists", &test_get_list },
9703 { "union", &test_union },
9704 { "split periods", &test_split_periods },
9705 { "lexicographic order", &test_lex },
9706 { "bijectivity", &test_bijective },
9707 { "dataflow analysis", &test_dep },
9708 { "reading", &test_read },
9709 { "bounded", &test_bounded },
9710 { "construction", &test_construction },
9711 { "dimension manipulation", &test_dim },
9712 { "map application", &test_application },
9713 { "convex hull", &test_convex_hull },
9714 { "transitive closure", &test_closure },
9715 { "isl_bool", &test_isl_bool},
9718 int main(int argc, char **argv)
9720 int i;
9721 struct isl_ctx *ctx;
9722 struct isl_options *options;
9724 options = isl_options_new_with_defaults();
9725 assert(options);
9726 argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL);
9728 ctx = isl_ctx_alloc_with_options(&isl_options_args, options);
9729 for (i = 0; i < ARRAY_SIZE(tests); ++i) {
9730 printf("%s\n", tests[i].name);
9731 if (tests[i].fn(ctx) < 0)
9732 goto error;
9734 isl_ctx_free(ctx);
9735 return 0;
9736 error:
9737 isl_ctx_free(ctx);
9738 return -1;