isl_local_space.c: add missing include
[isl.git] / isl_test.c
blobad1e44551f7f9168c78a737b19fc0a2a0d3d2467
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/set.h>
26 #include <isl/flow.h>
27 #include <isl_constraint_private.h>
28 #include <isl/polynomial.h>
29 #include <isl/union_set.h>
30 #include <isl/union_map.h>
31 #include <isl_factorization.h>
32 #include <isl/schedule.h>
33 #include <isl/schedule_node.h>
34 #include <isl_options_private.h>
35 #include <isl_vertices_private.h>
36 #include <isl/ast_build.h>
37 #include <isl/val.h>
38 #include <isl/ilp.h>
39 #include <isl_ast_build_expr.h>
40 #include <isl/options.h>
42 #include "isl_srcdir.c"
44 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
46 static char *get_filename(isl_ctx *ctx, const char *name, const char *suffix) {
47 char *filename;
48 int length;
49 char *pattern = "%s/test_inputs/%s.%s";
51 length = strlen(pattern) - 6 + strlen(srcdir) + strlen(name)
52 + strlen(suffix) + 1;
53 filename = isl_alloc_array(ctx, char, length);
55 if (!filename)
56 return NULL;
58 sprintf(filename, pattern, srcdir, name, suffix);
60 return filename;
63 void test_parse_map(isl_ctx *ctx, const char *str)
65 isl_map *map;
67 map = isl_map_read_from_str(ctx, str);
68 assert(map);
69 isl_map_free(map);
72 int test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
74 isl_map *map, *map2;
75 int equal;
77 map = isl_map_read_from_str(ctx, str);
78 map2 = isl_map_read_from_str(ctx, str2);
79 equal = isl_map_is_equal(map, map2);
80 isl_map_free(map);
81 isl_map_free(map2);
83 if (equal < 0)
84 return -1;
85 if (!equal)
86 isl_die(ctx, isl_error_unknown, "maps not equal",
87 return -1);
89 return 0;
92 void test_parse_pwqp(isl_ctx *ctx, const char *str)
94 isl_pw_qpolynomial *pwqp;
96 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
97 assert(pwqp);
98 isl_pw_qpolynomial_free(pwqp);
101 static void test_parse_pwaff(isl_ctx *ctx, const char *str)
103 isl_pw_aff *pwaff;
105 pwaff = isl_pw_aff_read_from_str(ctx, str);
106 assert(pwaff);
107 isl_pw_aff_free(pwaff);
110 /* Check that we can read an isl_multi_val from "str" without errors.
112 static int test_parse_multi_val(isl_ctx *ctx, const char *str)
114 isl_multi_val *mv;
116 mv = isl_multi_val_read_from_str(ctx, str);
117 isl_multi_val_free(mv);
119 return mv ? 0 : -1;
122 /* Check that printing "mpa" and parsing the output results
123 * in the same expression.
125 static isl_stat check_reparse_mpa(isl_ctx *ctx,
126 __isl_take isl_multi_pw_aff *mpa)
128 char *str;
129 isl_bool equal;
130 isl_multi_pw_aff *mpa2;
132 str = isl_multi_pw_aff_to_str(mpa);
133 mpa2 = isl_multi_pw_aff_read_from_str(ctx, str);
134 free(str);
135 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2);
136 isl_multi_pw_aff_free(mpa);
137 isl_multi_pw_aff_free(mpa2);
138 if (equal < 0)
139 return isl_stat_error;
140 if (!equal)
141 isl_die(ctx, isl_error_unknown,
142 "parsed function not equal to original",
143 return isl_stat_error);
145 return isl_stat_ok;
148 /* String descriptions of multi piecewise affine expressions
149 * that are used for testing printing and parsing.
151 const char *parse_multi_mpa_tests[] = {
152 "{ A[x, y] -> [] : x + y >= 0 }",
153 "{ A[x, y] -> B[] : x + y >= 0 }",
154 "{ A[x, y] -> [x] : x + y >= 0 }",
155 "[N] -> { A[x, y] -> [x] : x + y <= N }",
156 "{ A[x, y] -> [x, y] : x + y >= 0 }",
157 "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }",
158 "[N] -> { [] : N >= 0 }",
159 "[N] -> { [] : N >= 0 }",
160 "[N] -> { [N] : N >= 0 }",
161 "[N] -> { [N, N + 1] : N >= 0 }",
162 "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }",
165 /* Test parsing of multi piecewise affine expressions by printing
166 * the expressions and checking that parsing the output results
167 * in the same expression.
168 * Do this for a couple of manually constructed expressions and
169 * a set of expressions parsed from strings.
171 static int test_parse_mpa(isl_ctx *ctx)
173 int i;
174 isl_space *space;
175 isl_set *dom;
176 isl_multi_pw_aff *mpa;
177 isl_stat r;
179 space = isl_space_set_alloc(ctx, 0, 0);
180 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
181 mpa = isl_multi_pw_aff_zero(space);
182 r = check_reparse_mpa(ctx, mpa);
183 if (r < 0)
184 return -1;
186 space = isl_space_set_alloc(ctx, 1, 0);
187 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
188 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
189 dom = isl_set_universe(isl_space_params(isl_space_copy(space)));
190 dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5);
191 mpa = isl_multi_pw_aff_zero(space);
192 mpa = isl_multi_pw_aff_intersect_domain(mpa, dom);
193 r = check_reparse_mpa(ctx, mpa);
194 if (r < 0)
195 return -1;
197 for (i = 0; i < ARRAY_SIZE(parse_multi_mpa_tests); ++i) {
198 const char *str;
200 str = parse_multi_mpa_tests[i];
201 mpa = isl_multi_pw_aff_read_from_str(ctx, str);
202 r = check_reparse_mpa(ctx, mpa);
203 if (r < 0)
204 return -1;
207 return 0;
210 /* Check that printing "mupa" and parsing the output results
211 * in the same expression.
213 static isl_stat check_reparse_mupa(isl_ctx *ctx,
214 __isl_take isl_multi_union_pw_aff *mupa)
216 char *str;
217 isl_bool equal;
218 isl_multi_union_pw_aff *mupa2;
220 str = isl_multi_union_pw_aff_to_str(mupa);
221 mupa2 = isl_multi_union_pw_aff_read_from_str(ctx, str);
222 free(str);
223 equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2);
224 isl_multi_union_pw_aff_free(mupa);
225 isl_multi_union_pw_aff_free(mupa2);
226 if (equal < 0)
227 return isl_stat_error;
228 if (!equal)
229 isl_die(ctx, isl_error_unknown,
230 "parsed function not equal to original",
231 return isl_stat_error);
233 return isl_stat_ok;
236 /* String descriptions of multi union piecewise affine expressions
237 * that are used for testing printing and parsing.
239 const char *parse_multi_mupa_tests[] = {
240 "[]",
241 "A[]",
242 "A[B[] -> C[]]",
243 "(A[] : { S[x] : x > 0; T[y] : y >= 0 })",
244 "(A[] : { })",
245 "[N] -> (A[] : { })",
246 "[N] -> (A[] : { : N >= 0 })",
247 "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })",
248 "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })",
249 "A[{ S[x] -> [x + 1]; T[x] -> [x] }]",
250 "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : "
251 "{ S[x] : x > 0; T[y] : y >= 0 })",
254 /* Test parsing of multi union piecewise affine expressions by printing
255 * the expressions and checking that parsing the output results
256 * in the same expression.
257 * Do this for a couple of manually constructed expressions and
258 * a set of expressions parsed from strings.
260 static int test_parse_mupa(isl_ctx *ctx)
262 int i;
263 isl_space *space;
264 isl_multi_union_pw_aff *mupa;
265 isl_set *dom;
266 isl_union_set *uset;
267 isl_stat r;
269 space = isl_space_set_alloc(ctx, 0, 0);
270 space = isl_space_set_tuple_name(space, isl_dim_set, "A");
271 mupa = isl_multi_union_pw_aff_zero(space);
272 r = check_reparse_mupa(ctx, mupa);
273 if (r < 0)
274 return -1;
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, "A");
279 dom = isl_set_universe(space);
280 dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5);
281 uset = isl_union_set_from_set(dom);
282 space = isl_space_set_alloc(ctx, 1, 0);
283 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
284 space = isl_space_set_tuple_name(space, isl_dim_set, "B");
285 mupa = isl_multi_union_pw_aff_zero(space);
286 mupa = isl_multi_union_pw_aff_intersect_domain(mupa, uset);
287 r = check_reparse_mupa(ctx, mupa);
288 if (r < 0)
289 return -1;
291 for (i = 0; i < ARRAY_SIZE(parse_multi_mupa_tests); ++i) {
292 const char *str;
294 str = parse_multi_mupa_tests[i];
295 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
296 r = check_reparse_mupa(ctx, mupa);
297 if (r < 0)
298 return -1;
301 return 0;
304 /* Test parsing of multi expressions.
306 static int test_parse_multi(isl_ctx *ctx)
308 if (test_parse_mpa(ctx) < 0)
309 return -1;
310 if (test_parse_mupa(ctx) < 0)
311 return -1;
313 return 0;
316 /* Pairs of binary relation representations that should represent
317 * the same binary relations.
319 struct {
320 const char *map1;
321 const char *map2;
322 } parse_map_equal_tests[] = {
323 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
324 "{ [x, y] : 2y >= 6 - x }" },
325 { "{ [x,y] : x <= min(y, 2*y+3) }",
326 "{ [x,y] : x <= y, 2*y + 3 }" },
327 { "{ [x,y] : x >= min(y, 2*y+3) }",
328 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
329 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
330 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
331 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
332 "{ [i,j] -> [min(i,j)] }" },
333 { "{ [i,j] : i != j }",
334 "{ [i,j] : i < j or i > j }" },
335 { "{ [i,j] : (i+1)*2 >= j }",
336 "{ [i, j] : j <= 2 + 2i }" },
337 { "{ [i] -> [i > 0 ? 4 : 5] }",
338 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
339 { "[N=2,M] -> { [i=[(M+N)/4]] }",
340 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
341 { "{ [x] : x >= 0 }",
342 "{ [x] : x-0 >= 0 }" },
343 { "{ [i] : ((i > 10)) }",
344 "{ [i] : i >= 11 }" },
345 { "{ [i] -> [0] }",
346 "{ [i] -> [0 * i] }" },
347 { "{ [a] -> [b] : (not false) }",
348 "{ [a] -> [b] : true }" },
349 { "{ [i] : i/2 <= 5 }",
350 "{ [i] : i <= 10 }" },
351 { "{Sym=[n] [i] : i <= n }",
352 "[n] -> { [i] : i <= n }" },
353 { "{ [*] }",
354 "{ [a] }" },
355 { "{ [i] : 2*floor(i/2) = i }",
356 "{ [i] : exists a : i = 2 a }" },
357 { "{ [a] -> [b] : a = 5 implies b = 5 }",
358 "{ [a] -> [b] : a != 5 or b = 5 }" },
359 { "{ [a] -> [a - 1 : a > 0] }",
360 "{ [a] -> [a - 1] : a > 0 }" },
361 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
362 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
363 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
364 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
365 { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
366 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
367 { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
368 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
369 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
370 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
371 { "{ [a,b] -> [i,j] : a,b << i,j }",
372 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
373 { "{ [a,b] -> [i,j] : a,b <<= i,j }",
374 "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" },
375 { "{ [a,b] -> [i,j] : a,b >> i,j }",
376 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
377 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
378 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
379 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
380 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
381 "8c < n - 32a and i < n and c >= 0 and "
382 "c <= 3 and c >= -4a) }",
383 "{ [n] -> [i] : 0 <= i < n }" },
384 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
385 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
386 "{ [x] -> [] : 0 <= x <= 15 }" },
387 { "{ [x] -> [x] : }",
388 "{ [x] -> [x] }" },
391 int test_parse(struct isl_ctx *ctx)
393 int i;
394 isl_map *map, *map2;
395 const char *str, *str2;
397 if (test_parse_multi_val(ctx, "{ A[B[2] -> C[5, 7]] }") < 0)
398 return -1;
399 if (test_parse_multi_val(ctx, "[n] -> { [2] }") < 0)
400 return -1;
401 if (test_parse_multi_val(ctx, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
402 return -1;
403 if (test_parse_multi(ctx) < 0)
404 return -1;
406 str = "{ [i] -> [-i] }";
407 map = isl_map_read_from_str(ctx, str);
408 assert(map);
409 isl_map_free(map);
411 str = "{ A[i] -> L[([i/3])] }";
412 map = isl_map_read_from_str(ctx, str);
413 assert(map);
414 isl_map_free(map);
416 test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
417 test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : "
418 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
420 for (i = 0; i < ARRAY_SIZE(parse_map_equal_tests); ++i) {
421 str = parse_map_equal_tests[i].map1;
422 str2 = parse_map_equal_tests[i].map2;
423 if (test_parse_map_equal(ctx, str, str2) < 0)
424 return -1;
427 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
428 map = isl_map_read_from_str(ctx, str);
429 str = "{ [new, old] -> [o0, o1] : "
430 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
431 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
432 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
433 map2 = isl_map_read_from_str(ctx, str);
434 assert(isl_map_is_equal(map, map2));
435 isl_map_free(map);
436 isl_map_free(map2);
438 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
439 map = isl_map_read_from_str(ctx, str);
440 str = "{[new,old] -> [(new+1)%2,(old+1)%2]}";
441 map2 = isl_map_read_from_str(ctx, str);
442 assert(isl_map_is_equal(map, map2));
443 isl_map_free(map);
444 isl_map_free(map2);
446 test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
447 test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
448 test_parse_pwaff(ctx, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
449 test_parse_pwqp(ctx, "{ [x] -> ([(x)/2] * [(x)/3]) }");
450 test_parse_pwaff(ctx, "{ [] -> [(100)] }");
452 return 0;
455 static int test_read(isl_ctx *ctx)
457 char *filename;
458 FILE *input;
459 isl_basic_set *bset1, *bset2;
460 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
461 int equal;
463 filename = get_filename(ctx, "set", "omega");
464 assert(filename);
465 input = fopen(filename, "r");
466 assert(input);
468 bset1 = isl_basic_set_read_from_file(ctx, input);
469 bset2 = isl_basic_set_read_from_str(ctx, str);
471 equal = isl_basic_set_is_equal(bset1, bset2);
473 isl_basic_set_free(bset1);
474 isl_basic_set_free(bset2);
475 free(filename);
477 fclose(input);
479 if (equal < 0)
480 return -1;
481 if (!equal)
482 isl_die(ctx, isl_error_unknown,
483 "read sets not equal", return -1);
485 return 0;
488 static int test_bounded(isl_ctx *ctx)
490 isl_set *set;
491 isl_bool bounded;
493 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }");
494 bounded = isl_set_is_bounded(set);
495 isl_set_free(set);
497 if (bounded < 0)
498 return -1;
499 if (!bounded)
500 isl_die(ctx, isl_error_unknown,
501 "set not considered bounded", return -1);
503 set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }");
504 bounded = isl_set_is_bounded(set);
505 assert(!bounded);
506 isl_set_free(set);
508 if (bounded < 0)
509 return -1;
510 if (bounded)
511 isl_die(ctx, isl_error_unknown,
512 "set considered bounded", return -1);
514 set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }");
515 bounded = isl_set_is_bounded(set);
516 isl_set_free(set);
518 if (bounded < 0)
519 return -1;
520 if (bounded)
521 isl_die(ctx, isl_error_unknown,
522 "set considered bounded", return -1);
524 return 0;
527 /* Construct the basic set { [i] : 5 <= i <= N } */
528 static int test_construction_1(isl_ctx *ctx)
530 isl_space *dim;
531 isl_local_space *ls;
532 isl_basic_set *bset;
533 isl_constraint *c;
535 dim = isl_space_set_alloc(ctx, 1, 1);
536 bset = isl_basic_set_universe(isl_space_copy(dim));
537 ls = isl_local_space_from_space(dim);
539 c = isl_constraint_alloc_inequality(isl_local_space_copy(ls));
540 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
541 c = isl_constraint_set_coefficient_si(c, isl_dim_param, 0, 1);
542 bset = isl_basic_set_add_constraint(bset, c);
544 c = isl_constraint_alloc_inequality(isl_local_space_copy(ls));
545 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
546 c = isl_constraint_set_constant_si(c, -5);
547 bset = isl_basic_set_add_constraint(bset, c);
549 isl_local_space_free(ls);
550 isl_basic_set_free(bset);
552 return 0;
555 /* Construct the basic set { [x] : -100 <= x <= 100 }
556 * using isl_basic_set_{lower,upper}_bound_val and
557 * check that it is equal the same basic set parsed from a string.
559 static int test_construction_2(isl_ctx *ctx)
561 isl_bool equal;
562 isl_val *v;
563 isl_space *space;
564 isl_basic_set *bset1, *bset2;
566 v = isl_val_int_from_si(ctx, 100);
567 space = isl_space_set_alloc(ctx, 0, 1);
568 bset1 = isl_basic_set_universe(space);
569 bset1 = isl_basic_set_upper_bound_val(bset1, isl_dim_set, 0,
570 isl_val_copy(v));
571 bset1 = isl_basic_set_lower_bound_val(bset1, isl_dim_set, 0,
572 isl_val_neg(v));
573 bset2 = isl_basic_set_read_from_str(ctx, "{ [x] : -100 <= x <= 100 }");
574 equal = isl_basic_set_is_equal(bset1, bset2);
575 isl_basic_set_free(bset1);
576 isl_basic_set_free(bset2);
578 if (equal < 0)
579 return -1;
580 if (!equal)
581 isl_die(ctx, isl_error_unknown,
582 "failed construction", return -1);
584 return 0;
587 /* Basic tests for constructing basic sets.
589 static int test_construction(isl_ctx *ctx)
591 if (test_construction_1(ctx) < 0)
592 return -1;
593 if (test_construction_2(ctx) < 0)
594 return -1;
595 return 0;
598 static int test_dim(isl_ctx *ctx)
600 const char *str;
601 isl_map *map1, *map2;
602 int equal;
604 map1 = isl_map_read_from_str(ctx,
605 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
606 map1 = isl_map_add_dims(map1, isl_dim_in, 1);
607 map2 = isl_map_read_from_str(ctx,
608 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
609 equal = isl_map_is_equal(map1, map2);
610 isl_map_free(map2);
612 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
613 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }");
614 if (equal >= 0 && equal)
615 equal = isl_map_is_equal(map1, map2);
617 isl_map_free(map1);
618 isl_map_free(map2);
620 if (equal < 0)
621 return -1;
622 if (!equal)
623 isl_die(ctx, isl_error_unknown,
624 "unexpected result", return -1);
626 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
627 map1 = isl_map_read_from_str(ctx, str);
628 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
629 map2 = isl_map_read_from_str(ctx, str);
630 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
631 equal = isl_map_is_equal(map1, map2);
632 isl_map_free(map1);
633 isl_map_free(map2);
635 if (equal < 0)
636 return -1;
637 if (!equal)
638 isl_die(ctx, isl_error_unknown,
639 "unexpected result", return -1);
641 return 0;
644 /* Check that "val" is equal to the value described by "str".
645 * If "str" is "NaN", then check for a NaN value explicitly.
647 static isl_stat val_check_equal(__isl_keep isl_val *val, const char *str)
649 isl_bool ok, is_nan;
650 isl_ctx *ctx;
651 isl_val *res;
653 if (!val)
654 return isl_stat_error;
656 ctx = isl_val_get_ctx(val);
657 res = isl_val_read_from_str(ctx, str);
658 is_nan = isl_val_is_nan(res);
659 if (is_nan < 0)
660 ok = isl_bool_error;
661 else if (is_nan)
662 ok = isl_val_is_nan(val);
663 else
664 ok = isl_val_eq(val, res);
665 isl_val_free(res);
666 if (ok < 0)
667 return isl_stat_error;
668 if (!ok)
669 isl_die(ctx, isl_error_unknown,
670 "unexpected result", return isl_stat_error);
671 return isl_stat_ok;
674 struct {
675 __isl_give isl_val *(*op)(__isl_take isl_val *v);
676 const char *arg;
677 const char *res;
678 } val_un_tests[] = {
679 { &isl_val_neg, "0", "0" },
680 { &isl_val_abs, "0", "0" },
681 { &isl_val_2exp, "0", "1" },
682 { &isl_val_floor, "0", "0" },
683 { &isl_val_ceil, "0", "0" },
684 { &isl_val_neg, "1", "-1" },
685 { &isl_val_neg, "-1", "1" },
686 { &isl_val_neg, "1/2", "-1/2" },
687 { &isl_val_neg, "-1/2", "1/2" },
688 { &isl_val_neg, "infty", "-infty" },
689 { &isl_val_neg, "-infty", "infty" },
690 { &isl_val_neg, "NaN", "NaN" },
691 { &isl_val_abs, "1", "1" },
692 { &isl_val_abs, "-1", "1" },
693 { &isl_val_abs, "1/2", "1/2" },
694 { &isl_val_abs, "-1/2", "1/2" },
695 { &isl_val_abs, "infty", "infty" },
696 { &isl_val_abs, "-infty", "infty" },
697 { &isl_val_abs, "NaN", "NaN" },
698 { &isl_val_floor, "1", "1" },
699 { &isl_val_floor, "-1", "-1" },
700 { &isl_val_floor, "1/2", "0" },
701 { &isl_val_floor, "-1/2", "-1" },
702 { &isl_val_floor, "infty", "infty" },
703 { &isl_val_floor, "-infty", "-infty" },
704 { &isl_val_floor, "NaN", "NaN" },
705 { &isl_val_ceil, "1", "1" },
706 { &isl_val_ceil, "-1", "-1" },
707 { &isl_val_ceil, "1/2", "1" },
708 { &isl_val_ceil, "-1/2", "0" },
709 { &isl_val_ceil, "infty", "infty" },
710 { &isl_val_ceil, "-infty", "-infty" },
711 { &isl_val_ceil, "NaN", "NaN" },
712 { &isl_val_2exp, "-3", "1/8" },
713 { &isl_val_2exp, "-1", "1/2" },
714 { &isl_val_2exp, "1", "2" },
715 { &isl_val_2exp, "2", "4" },
716 { &isl_val_2exp, "3", "8" },
717 { &isl_val_inv, "1", "1" },
718 { &isl_val_inv, "2", "1/2" },
719 { &isl_val_inv, "1/2", "2" },
720 { &isl_val_inv, "-2", "-1/2" },
721 { &isl_val_inv, "-1/2", "-2" },
722 { &isl_val_inv, "0", "NaN" },
723 { &isl_val_inv, "NaN", "NaN" },
724 { &isl_val_inv, "infty", "0" },
725 { &isl_val_inv, "-infty", "0" },
728 /* Perform some basic tests of unary operations on isl_val objects.
730 static int test_un_val(isl_ctx *ctx)
732 int i;
733 isl_val *v;
734 __isl_give isl_val *(*fn)(__isl_take isl_val *v);
736 for (i = 0; i < ARRAY_SIZE(val_un_tests); ++i) {
737 isl_stat r;
739 v = isl_val_read_from_str(ctx, val_un_tests[i].arg);
740 fn = val_un_tests[i].op;
741 v = fn(v);
742 r = val_check_equal(v, val_un_tests[i].res);
743 isl_val_free(v);
744 if (r < 0)
745 return -1;
748 return 0;
751 struct {
752 __isl_give isl_val *(*fn)(__isl_take isl_val *v1,
753 __isl_take isl_val *v2);
754 } val_bin_op[] = {
755 ['+'] = { &isl_val_add },
756 ['-'] = { &isl_val_sub },
757 ['*'] = { &isl_val_mul },
758 ['/'] = { &isl_val_div },
759 ['g'] = { &isl_val_gcd },
760 ['m'] = { &isl_val_min },
761 ['M'] = { &isl_val_max },
764 struct {
765 const char *arg1;
766 unsigned char op;
767 const char *arg2;
768 const char *res;
769 } val_bin_tests[] = {
770 { "0", '+', "0", "0" },
771 { "1", '+', "0", "1" },
772 { "1", '+', "1", "2" },
773 { "1", '-', "1", "0" },
774 { "1", '*', "1", "1" },
775 { "1", '/', "1", "1" },
776 { "2", '*', "3", "6" },
777 { "2", '*', "1/2", "1" },
778 { "2", '*', "1/3", "2/3" },
779 { "2/3", '*', "3/5", "2/5" },
780 { "2/3", '*', "7/5", "14/15" },
781 { "2", '/', "1/2", "4" },
782 { "-2", '/', "-1/2", "4" },
783 { "-2", '/', "1/2", "-4" },
784 { "2", '/', "-1/2", "-4" },
785 { "2", '/', "2", "1" },
786 { "2", '/', "3", "2/3" },
787 { "2/3", '/', "5/3", "2/5" },
788 { "2/3", '/', "5/7", "14/15" },
789 { "0", '/', "0", "NaN" },
790 { "42", '/', "0", "NaN" },
791 { "-42", '/', "0", "NaN" },
792 { "infty", '/', "0", "NaN" },
793 { "-infty", '/', "0", "NaN" },
794 { "NaN", '/', "0", "NaN" },
795 { "0", '/', "NaN", "NaN" },
796 { "42", '/', "NaN", "NaN" },
797 { "-42", '/', "NaN", "NaN" },
798 { "infty", '/', "NaN", "NaN" },
799 { "-infty", '/', "NaN", "NaN" },
800 { "NaN", '/', "NaN", "NaN" },
801 { "0", '/', "infty", "0" },
802 { "42", '/', "infty", "0" },
803 { "-42", '/', "infty", "0" },
804 { "infty", '/', "infty", "NaN" },
805 { "-infty", '/', "infty", "NaN" },
806 { "NaN", '/', "infty", "NaN" },
807 { "0", '/', "-infty", "0" },
808 { "42", '/', "-infty", "0" },
809 { "-42", '/', "-infty", "0" },
810 { "infty", '/', "-infty", "NaN" },
811 { "-infty", '/', "-infty", "NaN" },
812 { "NaN", '/', "-infty", "NaN" },
813 { "1", '-', "1/3", "2/3" },
814 { "1/3", '+', "1/2", "5/6" },
815 { "1/2", '+', "1/2", "1" },
816 { "3/4", '-', "1/4", "1/2" },
817 { "1/2", '-', "1/3", "1/6" },
818 { "infty", '+', "42", "infty" },
819 { "infty", '+', "infty", "infty" },
820 { "42", '+', "infty", "infty" },
821 { "infty", '-', "infty", "NaN" },
822 { "infty", '*', "infty", "infty" },
823 { "infty", '*', "-infty", "-infty" },
824 { "-infty", '*', "infty", "-infty" },
825 { "-infty", '*', "-infty", "infty" },
826 { "0", '*', "infty", "NaN" },
827 { "1", '*', "infty", "infty" },
828 { "infty", '*', "0", "NaN" },
829 { "infty", '*', "42", "infty" },
830 { "42", '-', "infty", "-infty" },
831 { "infty", '+', "-infty", "NaN" },
832 { "4", 'g', "6", "2" },
833 { "5", 'g', "6", "1" },
834 { "42", 'm', "3", "3" },
835 { "42", 'M', "3", "42" },
836 { "3", 'm', "42", "3" },
837 { "3", 'M', "42", "42" },
838 { "42", 'm', "infty", "42" },
839 { "42", 'M', "infty", "infty" },
840 { "42", 'm', "-infty", "-infty" },
841 { "42", 'M', "-infty", "42" },
842 { "42", 'm', "NaN", "NaN" },
843 { "42", 'M', "NaN", "NaN" },
844 { "infty", 'm', "-infty", "-infty" },
845 { "infty", 'M', "-infty", "infty" },
848 /* Perform some basic tests of binary operations on isl_val objects.
850 static int test_bin_val(isl_ctx *ctx)
852 int i;
853 isl_val *v1, *v2, *res;
854 __isl_give isl_val *(*fn)(__isl_take isl_val *v1,
855 __isl_take isl_val *v2);
856 int ok;
858 for (i = 0; i < ARRAY_SIZE(val_bin_tests); ++i) {
859 v1 = isl_val_read_from_str(ctx, val_bin_tests[i].arg1);
860 v2 = isl_val_read_from_str(ctx, val_bin_tests[i].arg2);
861 res = isl_val_read_from_str(ctx, val_bin_tests[i].res);
862 fn = val_bin_op[val_bin_tests[i].op].fn;
863 v1 = fn(v1, v2);
864 if (isl_val_is_nan(res))
865 ok = isl_val_is_nan(v1);
866 else
867 ok = isl_val_eq(v1, res);
868 isl_val_free(v1);
869 isl_val_free(res);
870 if (ok < 0)
871 return -1;
872 if (!ok)
873 isl_die(ctx, isl_error_unknown,
874 "unexpected result", return -1);
877 return 0;
880 /* Perform some basic tests on isl_val objects.
882 static int test_val(isl_ctx *ctx)
884 if (test_un_val(ctx) < 0)
885 return -1;
886 if (test_bin_val(ctx) < 0)
887 return -1;
888 return 0;
891 /* Sets described using existentially quantified variables that
892 * can also be described without.
894 static const char *elimination_tests[] = {
895 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
896 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
897 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
900 /* Check that redundant existentially quantified variables are
901 * getting removed.
903 static int test_elimination(isl_ctx *ctx)
905 int i;
906 unsigned n;
907 isl_basic_set *bset;
909 for (i = 0; i < ARRAY_SIZE(elimination_tests); ++i) {
910 bset = isl_basic_set_read_from_str(ctx, elimination_tests[i]);
911 n = isl_basic_set_dim(bset, isl_dim_div);
912 isl_basic_set_free(bset);
913 if (!bset)
914 return -1;
915 if (n != 0)
916 isl_die(ctx, isl_error_unknown,
917 "expecting no existentials", return -1);
920 return 0;
923 static int test_div(isl_ctx *ctx)
925 const char *str;
926 int empty;
927 isl_space *dim;
928 isl_set *set;
929 isl_local_space *ls;
930 struct isl_basic_set *bset;
931 struct isl_constraint *c;
933 /* test 1 */
934 dim = isl_space_set_alloc(ctx, 0, 3);
935 bset = isl_basic_set_universe(isl_space_copy(dim));
936 ls = isl_local_space_from_space(dim);
938 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
939 c = isl_constraint_set_constant_si(c, -1);
940 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
941 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
942 bset = isl_basic_set_add_constraint(bset, c);
944 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
945 c = isl_constraint_set_constant_si(c, 1);
946 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
947 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3);
948 bset = isl_basic_set_add_constraint(bset, c);
950 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
952 assert(bset && bset->n_div == 1);
953 isl_local_space_free(ls);
954 isl_basic_set_free(bset);
956 /* test 2 */
957 dim = isl_space_set_alloc(ctx, 0, 3);
958 bset = isl_basic_set_universe(isl_space_copy(dim));
959 ls = isl_local_space_from_space(dim);
961 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
962 c = isl_constraint_set_constant_si(c, 1);
963 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
964 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
965 bset = isl_basic_set_add_constraint(bset, c);
967 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
968 c = isl_constraint_set_constant_si(c, -1);
969 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
970 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3);
971 bset = isl_basic_set_add_constraint(bset, c);
973 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
975 assert(bset && bset->n_div == 1);
976 isl_local_space_free(ls);
977 isl_basic_set_free(bset);
979 /* test 3 */
980 dim = isl_space_set_alloc(ctx, 0, 3);
981 bset = isl_basic_set_universe(isl_space_copy(dim));
982 ls = isl_local_space_from_space(dim);
984 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
985 c = isl_constraint_set_constant_si(c, 1);
986 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
987 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
988 bset = isl_basic_set_add_constraint(bset, c);
990 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
991 c = isl_constraint_set_constant_si(c, -3);
992 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
993 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 4);
994 bset = isl_basic_set_add_constraint(bset, c);
996 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
998 assert(bset && bset->n_div == 1);
999 isl_local_space_free(ls);
1000 isl_basic_set_free(bset);
1002 /* test 4 */
1003 dim = isl_space_set_alloc(ctx, 0, 3);
1004 bset = isl_basic_set_universe(isl_space_copy(dim));
1005 ls = isl_local_space_from_space(dim);
1007 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1008 c = isl_constraint_set_constant_si(c, 2);
1009 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1010 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, 3);
1011 bset = isl_basic_set_add_constraint(bset, c);
1013 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1014 c = isl_constraint_set_constant_si(c, -1);
1015 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1016 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 6);
1017 bset = isl_basic_set_add_constraint(bset, c);
1019 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
1021 assert(isl_basic_set_is_empty(bset));
1022 isl_local_space_free(ls);
1023 isl_basic_set_free(bset);
1025 /* test 5 */
1026 dim = isl_space_set_alloc(ctx, 0, 3);
1027 bset = isl_basic_set_universe(isl_space_copy(dim));
1028 ls = isl_local_space_from_space(dim);
1030 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1031 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1032 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 3);
1033 bset = isl_basic_set_add_constraint(bset, c);
1035 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1036 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1037 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1038 bset = isl_basic_set_add_constraint(bset, c);
1040 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
1042 assert(bset && bset->n_div == 0);
1043 isl_basic_set_free(bset);
1044 isl_local_space_free(ls);
1046 /* test 6 */
1047 dim = isl_space_set_alloc(ctx, 0, 3);
1048 bset = isl_basic_set_universe(isl_space_copy(dim));
1049 ls = isl_local_space_from_space(dim);
1051 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1052 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1053 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 6);
1054 bset = isl_basic_set_add_constraint(bset, c);
1056 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1057 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1058 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1059 bset = isl_basic_set_add_constraint(bset, c);
1061 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
1063 assert(bset && bset->n_div == 1);
1064 isl_basic_set_free(bset);
1065 isl_local_space_free(ls);
1067 /* test 7 */
1068 /* This test is a bit tricky. We set up an equality
1069 * a + 3b + 3c = 6 e0
1070 * Normalization of divs creates _two_ divs
1071 * a = 3 e0
1072 * c - b - e0 = 2 e1
1073 * Afterwards e0 is removed again because it has coefficient -1
1074 * and we end up with the original equality and div again.
1075 * Perhaps we can avoid the introduction of this temporary div.
1077 dim = isl_space_set_alloc(ctx, 0, 4);
1078 bset = isl_basic_set_universe(isl_space_copy(dim));
1079 ls = isl_local_space_from_space(dim);
1081 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1082 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1083 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1084 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -3);
1085 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, 6);
1086 bset = isl_basic_set_add_constraint(bset, c);
1088 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
1090 /* Test disabled for now */
1092 assert(bset && bset->n_div == 1);
1094 isl_local_space_free(ls);
1095 isl_basic_set_free(bset);
1097 /* test 8 */
1098 dim = isl_space_set_alloc(ctx, 0, 5);
1099 bset = isl_basic_set_universe(isl_space_copy(dim));
1100 ls = isl_local_space_from_space(dim);
1102 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1103 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1104 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -3);
1105 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, -3);
1106 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 4, 6);
1107 bset = isl_basic_set_add_constraint(bset, c);
1109 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1110 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1111 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, 1);
1112 c = isl_constraint_set_constant_si(c, 1);
1113 bset = isl_basic_set_add_constraint(bset, c);
1115 bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1);
1117 /* Test disabled for now */
1119 assert(bset && bset->n_div == 1);
1121 isl_local_space_free(ls);
1122 isl_basic_set_free(bset);
1124 /* test 9 */
1125 dim = isl_space_set_alloc(ctx, 0, 4);
1126 bset = isl_basic_set_universe(isl_space_copy(dim));
1127 ls = isl_local_space_from_space(dim);
1129 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1130 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1131 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 1, -1);
1132 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -2);
1133 bset = isl_basic_set_add_constraint(bset, c);
1135 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1136 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, -1);
1137 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 3, 3);
1138 c = isl_constraint_set_constant_si(c, 2);
1139 bset = isl_basic_set_add_constraint(bset, c);
1141 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2);
1143 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
1145 assert(!isl_basic_set_is_empty(bset));
1147 isl_local_space_free(ls);
1148 isl_basic_set_free(bset);
1150 /* test 10 */
1151 dim = isl_space_set_alloc(ctx, 0, 3);
1152 bset = isl_basic_set_universe(isl_space_copy(dim));
1153 ls = isl_local_space_from_space(dim);
1155 c = isl_constraint_alloc_equality(isl_local_space_copy(ls));
1156 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 0, 1);
1157 c = isl_constraint_set_coefficient_si(c, isl_dim_set, 2, -2);
1158 bset = isl_basic_set_add_constraint(bset, c);
1160 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
1162 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
1164 isl_local_space_free(ls);
1165 isl_basic_set_free(bset);
1167 str = "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1168 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1169 set = isl_set_read_from_str(ctx, str);
1170 set = isl_set_compute_divs(set);
1171 isl_set_free(set);
1172 if (!set)
1173 return -1;
1175 if (test_elimination(ctx) < 0)
1176 return -1;
1178 str = "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1179 set = isl_set_read_from_str(ctx, str);
1180 set = isl_set_remove_divs_involving_dims(set, isl_dim_set, 0, 2);
1181 set = isl_set_fix_si(set, isl_dim_set, 2, -3);
1182 empty = isl_set_is_empty(set);
1183 isl_set_free(set);
1184 if (empty < 0)
1185 return -1;
1186 if (!empty)
1187 isl_die(ctx, isl_error_unknown,
1188 "result not as accurate as expected", return -1);
1190 return 0;
1193 void test_application_case(struct isl_ctx *ctx, const char *name)
1195 char *filename;
1196 FILE *input;
1197 struct isl_basic_set *bset1, *bset2;
1198 struct isl_basic_map *bmap;
1200 filename = get_filename(ctx, name, "omega");
1201 assert(filename);
1202 input = fopen(filename, "r");
1203 assert(input);
1205 bset1 = isl_basic_set_read_from_file(ctx, input);
1206 bmap = isl_basic_map_read_from_file(ctx, input);
1208 bset1 = isl_basic_set_apply(bset1, bmap);
1210 bset2 = isl_basic_set_read_from_file(ctx, input);
1212 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1214 isl_basic_set_free(bset1);
1215 isl_basic_set_free(bset2);
1216 free(filename);
1218 fclose(input);
1221 static int test_application(isl_ctx *ctx)
1223 test_application_case(ctx, "application");
1224 test_application_case(ctx, "application2");
1226 return 0;
1229 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
1231 char *filename;
1232 FILE *input;
1233 struct isl_basic_set *bset1, *bset2;
1235 filename = get_filename(ctx, name, "polylib");
1236 assert(filename);
1237 input = fopen(filename, "r");
1238 assert(input);
1240 bset1 = isl_basic_set_read_from_file(ctx, input);
1241 bset2 = isl_basic_set_read_from_file(ctx, input);
1243 bset1 = isl_basic_set_affine_hull(bset1);
1245 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1247 isl_basic_set_free(bset1);
1248 isl_basic_set_free(bset2);
1249 free(filename);
1251 fclose(input);
1254 int test_affine_hull(struct isl_ctx *ctx)
1256 const char *str;
1257 isl_set *set;
1258 isl_basic_set *bset, *bset2;
1259 int n;
1260 int subset;
1262 test_affine_hull_case(ctx, "affine2");
1263 test_affine_hull_case(ctx, "affine");
1264 test_affine_hull_case(ctx, "affine3");
1266 str = "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1267 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1268 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1269 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1270 set = isl_set_read_from_str(ctx, str);
1271 bset = isl_set_affine_hull(set);
1272 n = isl_basic_set_dim(bset, isl_dim_div);
1273 isl_basic_set_free(bset);
1274 if (n != 0)
1275 isl_die(ctx, isl_error_unknown, "not expecting any divs",
1276 return -1);
1278 /* Check that isl_map_affine_hull is not confused by
1279 * the reordering of divs in isl_map_align_divs.
1281 str = "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1282 "32e0 = b and 32e1 = c); "
1283 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1284 set = isl_set_read_from_str(ctx, str);
1285 bset = isl_set_affine_hull(set);
1286 isl_basic_set_free(bset);
1287 if (!bset)
1288 return -1;
1290 str = "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1291 "32e2 = 31 + 31e0 }";
1292 set = isl_set_read_from_str(ctx, str);
1293 bset = isl_set_affine_hull(set);
1294 str = "{ [a] : exists e : a = 32 e }";
1295 bset2 = isl_basic_set_read_from_str(ctx, str);
1296 subset = isl_basic_set_is_subset(bset, bset2);
1297 isl_basic_set_free(bset);
1298 isl_basic_set_free(bset2);
1299 if (subset < 0)
1300 return -1;
1301 if (!subset)
1302 isl_die(ctx, isl_error_unknown, "not as accurate as expected",
1303 return -1);
1305 return 0;
1308 /* Pairs of maps and the corresponding expected results of
1309 * isl_map_plain_unshifted_simple_hull.
1311 struct {
1312 const char *map;
1313 const char *hull;
1314 } plain_unshifted_simple_hull_tests[] = {
1315 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1316 "{ [i] -> [j] : i >= 1 }" },
1317 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1318 "(j mod 4 = 2 and k mod 6 = n) }",
1319 "{ [n] -> [i,j,k] : j mod 4 = 2 }" },
1322 /* Basic tests for isl_map_plain_unshifted_simple_hull.
1324 static int test_plain_unshifted_simple_hull(isl_ctx *ctx)
1326 int i;
1327 isl_map *map;
1328 isl_basic_map *hull, *expected;
1329 isl_bool equal;
1331 for (i = 0; i < ARRAY_SIZE(plain_unshifted_simple_hull_tests); ++i) {
1332 const char *str;
1333 str = plain_unshifted_simple_hull_tests[i].map;
1334 map = isl_map_read_from_str(ctx, str);
1335 str = plain_unshifted_simple_hull_tests[i].hull;
1336 expected = isl_basic_map_read_from_str(ctx, str);
1337 hull = isl_map_plain_unshifted_simple_hull(map);
1338 equal = isl_basic_map_is_equal(hull, expected);
1339 isl_basic_map_free(hull);
1340 isl_basic_map_free(expected);
1341 if (equal < 0)
1342 return -1;
1343 if (!equal)
1344 isl_die(ctx, isl_error_unknown, "unexpected hull",
1345 return -1);
1348 return 0;
1351 /* Pairs of sets and the corresponding expected results of
1352 * isl_set_unshifted_simple_hull.
1354 struct {
1355 const char *set;
1356 const char *hull;
1357 } unshifted_simple_hull_tests[] = {
1358 { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1359 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1362 /* Basic tests for isl_set_unshifted_simple_hull.
1364 static int test_unshifted_simple_hull(isl_ctx *ctx)
1366 int i;
1367 isl_set *set;
1368 isl_basic_set *hull, *expected;
1369 isl_bool equal;
1371 for (i = 0; i < ARRAY_SIZE(unshifted_simple_hull_tests); ++i) {
1372 const char *str;
1373 str = unshifted_simple_hull_tests[i].set;
1374 set = isl_set_read_from_str(ctx, str);
1375 str = unshifted_simple_hull_tests[i].hull;
1376 expected = isl_basic_set_read_from_str(ctx, str);
1377 hull = isl_set_unshifted_simple_hull(set);
1378 equal = isl_basic_set_is_equal(hull, expected);
1379 isl_basic_set_free(hull);
1380 isl_basic_set_free(expected);
1381 if (equal < 0)
1382 return -1;
1383 if (!equal)
1384 isl_die(ctx, isl_error_unknown, "unexpected hull",
1385 return -1);
1388 return 0;
1391 static int test_simple_hull(struct isl_ctx *ctx)
1393 const char *str;
1394 isl_set *set;
1395 isl_basic_set *bset;
1396 isl_bool is_empty;
1398 str = "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1399 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1400 set = isl_set_read_from_str(ctx, str);
1401 bset = isl_set_simple_hull(set);
1402 is_empty = isl_basic_set_is_empty(bset);
1403 isl_basic_set_free(bset);
1405 if (is_empty == isl_bool_error)
1406 return -1;
1408 if (is_empty == isl_bool_false)
1409 isl_die(ctx, isl_error_unknown, "Empty set should be detected",
1410 return -1);
1412 if (test_plain_unshifted_simple_hull(ctx) < 0)
1413 return -1;
1414 if (test_unshifted_simple_hull(ctx) < 0)
1415 return -1;
1417 return 0;
1420 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
1422 char *filename;
1423 FILE *input;
1424 struct isl_basic_set *bset1, *bset2;
1425 struct isl_set *set;
1427 filename = get_filename(ctx, name, "polylib");
1428 assert(filename);
1429 input = fopen(filename, "r");
1430 assert(input);
1432 bset1 = isl_basic_set_read_from_file(ctx, input);
1433 bset2 = isl_basic_set_read_from_file(ctx, input);
1435 set = isl_basic_set_union(bset1, bset2);
1436 bset1 = isl_set_convex_hull(set);
1438 bset2 = isl_basic_set_read_from_file(ctx, input);
1440 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1442 isl_basic_set_free(bset1);
1443 isl_basic_set_free(bset2);
1444 free(filename);
1446 fclose(input);
1449 struct {
1450 const char *set;
1451 const char *hull;
1452 } convex_hull_tests[] = {
1453 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1454 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1455 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1456 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1457 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1458 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1459 "i2 <= 5 and i2 >= 4; "
1460 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1461 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1462 "i2 <= 5 + i0 and i2 >= i0 }" },
1463 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1464 "{ [x, y] : 1 = 0 }" },
1465 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1466 "[x, y, 0] : x >= 0 and y < 0 }",
1467 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1470 static int test_convex_hull_algo(isl_ctx *ctx, int convex)
1472 int i;
1473 int orig_convex = ctx->opt->convex;
1474 ctx->opt->convex = convex;
1476 test_convex_hull_case(ctx, "convex0");
1477 test_convex_hull_case(ctx, "convex1");
1478 test_convex_hull_case(ctx, "convex2");
1479 test_convex_hull_case(ctx, "convex3");
1480 test_convex_hull_case(ctx, "convex4");
1481 test_convex_hull_case(ctx, "convex5");
1482 test_convex_hull_case(ctx, "convex6");
1483 test_convex_hull_case(ctx, "convex7");
1484 test_convex_hull_case(ctx, "convex8");
1485 test_convex_hull_case(ctx, "convex9");
1486 test_convex_hull_case(ctx, "convex10");
1487 test_convex_hull_case(ctx, "convex11");
1488 test_convex_hull_case(ctx, "convex12");
1489 test_convex_hull_case(ctx, "convex13");
1490 test_convex_hull_case(ctx, "convex14");
1491 test_convex_hull_case(ctx, "convex15");
1493 for (i = 0; i < ARRAY_SIZE(convex_hull_tests); ++i) {
1494 isl_set *set1, *set2;
1495 int equal;
1497 set1 = isl_set_read_from_str(ctx, convex_hull_tests[i].set);
1498 set2 = isl_set_read_from_str(ctx, convex_hull_tests[i].hull);
1499 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
1500 equal = isl_set_is_equal(set1, set2);
1501 isl_set_free(set1);
1502 isl_set_free(set2);
1504 if (equal < 0)
1505 return -1;
1506 if (!equal)
1507 isl_die(ctx, isl_error_unknown,
1508 "unexpected convex hull", return -1);
1511 ctx->opt->convex = orig_convex;
1513 return 0;
1516 static int test_convex_hull(isl_ctx *ctx)
1518 if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM) < 0)
1519 return -1;
1520 if (test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP) < 0)
1521 return -1;
1522 return 0;
1525 void test_gist_case(struct isl_ctx *ctx, const char *name)
1527 char *filename;
1528 FILE *input;
1529 struct isl_basic_set *bset1, *bset2;
1531 filename = get_filename(ctx, name, "polylib");
1532 assert(filename);
1533 input = fopen(filename, "r");
1534 assert(input);
1536 bset1 = isl_basic_set_read_from_file(ctx, input);
1537 bset2 = isl_basic_set_read_from_file(ctx, input);
1539 bset1 = isl_basic_set_gist(bset1, bset2);
1541 bset2 = isl_basic_set_read_from_file(ctx, input);
1543 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1545 isl_basic_set_free(bset1);
1546 isl_basic_set_free(bset2);
1547 free(filename);
1549 fclose(input);
1552 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1554 struct {
1555 const char *map;
1556 const char *context;
1557 const char *gist;
1558 } plain_gist_tests[] = {
1559 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1560 "{ [i] -> [j] : i >= 1 }",
1561 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1562 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1563 "(j mod 4 = 2 and k mod 6 = n) }",
1564 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1565 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1566 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1567 "{ [i] -> [j] : i > j }",
1568 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1571 /* Basic tests for isl_map_plain_gist_basic_map.
1573 static int test_plain_gist(isl_ctx *ctx)
1575 int i;
1577 for (i = 0; i < ARRAY_SIZE(plain_gist_tests); ++i) {
1578 const char *str;
1579 int equal;
1580 isl_map *map, *gist;
1581 isl_basic_map *context;
1583 map = isl_map_read_from_str(ctx, plain_gist_tests[i].map);
1584 str = plain_gist_tests[i].context;
1585 context = isl_basic_map_read_from_str(ctx, str);
1586 map = isl_map_plain_gist_basic_map(map, context);
1587 gist = isl_map_read_from_str(ctx, plain_gist_tests[i].gist);
1588 equal = isl_map_is_equal(map, gist);
1589 isl_map_free(map);
1590 isl_map_free(gist);
1591 if (equal < 0)
1592 return -1;
1593 if (!equal)
1594 isl_die(ctx, isl_error_unknown,
1595 "incorrect gist result", return -1);
1598 return 0;
1601 struct {
1602 const char *set;
1603 const char *context;
1604 const char *gist;
1605 } gist_tests[] = {
1606 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1607 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1608 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1609 "{ [a, b, c] : a <= 15 }" },
1610 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1611 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1612 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1613 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1614 { "{ [m, n, a, b] : a <= 2147 + n }",
1615 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1616 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1617 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1618 "b >= 0) }",
1619 "{ [m, n, ku, kl] }" },
1620 { "{ [a, a, b] : a >= 10 }",
1621 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1622 "{ [a, a, b] : a >= 10 }" },
1623 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1624 "{ [0, j] : j >= 0 }" },
1625 /* Check that no constraints on i6 are introduced in the gist */
1626 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1627 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1628 "5e0 <= 381 - t1 and i4 <= 1) }",
1629 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1630 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1631 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1632 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1633 "20e0 >= 1511 - 4t1 - 5i4) }" },
1634 /* Check that no constraints on i6 are introduced in the gist */
1635 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1636 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1637 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1638 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1639 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1640 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1641 "20e1 <= 1530 - 4t1 - 5i4 and "
1642 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1643 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1644 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1645 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1646 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1647 "10e0 <= -91 + 5i4 + 4i6 and "
1648 "10e0 >= -105 + 5i4 + 4i6) }",
1649 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1650 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1651 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1652 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1653 "{ [a, b, q, p] : b >= 1 + a }",
1654 "{ [a, b, q, p] : false }" },
1655 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1656 "[n] -> { [x] : x mod 32 = 0 }",
1657 "[n] -> { [x = n] }" },
1658 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1659 "{ [x] : x mod 2 = 0 }" },
1660 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1661 "{ [x] : x mod 128 = 0 }" },
1662 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1663 "{ [x] : x mod 3200 = 0 }" },
1664 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1665 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1666 "{ [a, b, c = a] }" },
1667 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1668 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1669 "{ [a, b, c = a] : a mod 3 = 0 }" },
1670 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1671 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1672 "{ [x] }" },
1673 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1674 "{ [x,y] : 1 <= y <= 3 }",
1675 "{ [x,y] }" },
1678 /* Check that isl_set_gist behaves as expected.
1680 * For the test cases in gist_tests, besides checking that the result
1681 * is as expected, also check that applying the gist operation does
1682 * not modify the input set (an earlier version of isl would do that) and
1683 * that the test case is consistent, i.e., that the gist has the same
1684 * intersection with the context as the input set.
1686 static int test_gist(struct isl_ctx *ctx)
1688 int i;
1689 const char *str;
1690 isl_basic_set *bset1, *bset2;
1691 isl_map *map1, *map2;
1692 int equal;
1694 for (i = 0; i < ARRAY_SIZE(gist_tests); ++i) {
1695 int equal_input, equal_intersection;
1696 isl_set *set1, *set2, *copy, *context;
1698 set1 = isl_set_read_from_str(ctx, gist_tests[i].set);
1699 context = isl_set_read_from_str(ctx, gist_tests[i].context);
1700 copy = isl_set_copy(set1);
1701 set1 = isl_set_gist(set1, isl_set_copy(context));
1702 set2 = isl_set_read_from_str(ctx, gist_tests[i].gist);
1703 equal = isl_set_is_equal(set1, set2);
1704 isl_set_free(set1);
1705 set1 = isl_set_read_from_str(ctx, gist_tests[i].set);
1706 equal_input = isl_set_is_equal(set1, copy);
1707 isl_set_free(copy);
1708 set1 = isl_set_intersect(set1, isl_set_copy(context));
1709 set2 = isl_set_intersect(set2, context);
1710 equal_intersection = isl_set_is_equal(set1, set2);
1711 isl_set_free(set2);
1712 isl_set_free(set1);
1713 if (equal < 0 || equal_input < 0 || equal_intersection < 0)
1714 return -1;
1715 if (!equal)
1716 isl_die(ctx, isl_error_unknown,
1717 "incorrect gist result", return -1);
1718 if (!equal_input)
1719 isl_die(ctx, isl_error_unknown,
1720 "gist modified input", return -1);
1721 if (!equal_input)
1722 isl_die(ctx, isl_error_unknown,
1723 "inconsistent gist test case", return -1);
1726 test_gist_case(ctx, "gist1");
1728 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
1729 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1730 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1731 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1732 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1733 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1734 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1735 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1736 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1737 bset1 = isl_basic_set_read_from_str(ctx, str);
1738 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1739 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1740 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1741 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1742 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1743 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1744 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1745 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1746 bset2 = isl_basic_set_read_from_str(ctx, str);
1747 bset1 = isl_basic_set_gist(bset1, bset2);
1748 assert(bset1 && bset1->n_div == 0);
1749 isl_basic_set_free(bset1);
1751 /* Check that the integer divisions of the second disjunct
1752 * do not spread to the first disjunct.
1754 str = "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1755 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1756 "(exists (e0 = [(-1 + t1)/16], "
1757 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1758 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1759 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1760 "o0 <= 4294967295 and t1 <= -1)) }";
1761 map1 = isl_map_read_from_str(ctx, str);
1762 str = "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1763 map2 = isl_map_read_from_str(ctx, str);
1764 map1 = isl_map_gist(map1, map2);
1765 if (!map1)
1766 return -1;
1767 if (map1->n != 1)
1768 isl_die(ctx, isl_error_unknown, "expecting single disjunct",
1769 isl_map_free(map1); return -1);
1770 if (isl_basic_map_dim(map1->p[0], isl_dim_div) != 1)
1771 isl_die(ctx, isl_error_unknown, "expecting single div",
1772 isl_map_free(map1); return -1);
1773 isl_map_free(map1);
1775 if (test_plain_gist(ctx) < 0)
1776 return -1;
1778 return 0;
1781 int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
1783 isl_set *set, *set2;
1784 int equal;
1785 int one;
1787 set = isl_set_read_from_str(ctx, str);
1788 set = isl_set_coalesce(set);
1789 set2 = isl_set_read_from_str(ctx, str);
1790 equal = isl_set_is_equal(set, set2);
1791 one = set && set->n == 1;
1792 isl_set_free(set);
1793 isl_set_free(set2);
1795 if (equal < 0)
1796 return -1;
1797 if (!equal)
1798 isl_die(ctx, isl_error_unknown,
1799 "coalesced set not equal to input", return -1);
1800 if (check_one && !one)
1801 isl_die(ctx, isl_error_unknown,
1802 "coalesced set should not be a union", return -1);
1804 return 0;
1807 /* Inputs for coalescing tests with unbounded wrapping.
1808 * "str" is a string representation of the input set.
1809 * "single_disjunct" is set if we expect the result to consist of
1810 * a single disjunct.
1812 struct {
1813 int single_disjunct;
1814 const char *str;
1815 } coalesce_unbounded_tests[] = {
1816 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1817 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1818 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1819 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1820 "-10 <= y <= 0}" },
1821 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1822 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1823 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1824 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1827 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1828 * option turned off.
1830 int test_coalesce_unbounded_wrapping(isl_ctx *ctx)
1832 int i;
1833 int r = 0;
1834 int bounded;
1836 bounded = isl_options_get_coalesce_bounded_wrapping(ctx);
1837 isl_options_set_coalesce_bounded_wrapping(ctx, 0);
1839 for (i = 0; i < ARRAY_SIZE(coalesce_unbounded_tests); ++i) {
1840 const char *str = coalesce_unbounded_tests[i].str;
1841 int check_one = coalesce_unbounded_tests[i].single_disjunct;
1842 if (test_coalesce_set(ctx, str, check_one) >= 0)
1843 continue;
1844 r = -1;
1845 break;
1848 isl_options_set_coalesce_bounded_wrapping(ctx, bounded);
1850 return r;
1853 /* Inputs for coalescing tests.
1854 * "str" is a string representation of the input set.
1855 * "single_disjunct" is set if we expect the result to consist of
1856 * a single disjunct.
1858 struct {
1859 int single_disjunct;
1860 const char *str;
1861 } coalesce_tests[] = {
1862 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1863 "y >= x & x >= 2 & 5 >= y }" },
1864 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1865 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1866 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1867 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1868 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1869 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1870 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1871 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1872 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1873 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1874 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1875 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1876 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1877 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1878 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1879 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1880 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1881 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1882 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1883 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1884 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1885 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1886 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1887 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1888 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1889 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1890 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1891 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1892 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1893 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1894 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1895 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1896 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1897 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1898 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1899 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1900 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1901 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1902 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1903 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1904 "[o0, o1, o2, o3, o4, o5, o6]] : "
1905 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1906 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1907 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1908 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1909 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1910 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1911 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1912 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1913 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1914 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1915 "o6 >= i3 + i6 - o3 and M >= 0 and "
1916 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1917 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1918 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1919 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1920 "(o0 = 0 and M >= 2 and N >= 3) or "
1921 "(M = 0 and o0 = 0 and N >= 3) }" },
1922 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1923 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1924 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1925 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1926 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1927 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1928 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1929 "(y = 3 and x = 1) }" },
1930 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1931 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1932 "i1 <= M and i3 <= M and i4 <= M) or "
1933 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1934 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1935 "i4 <= -1 + M) }" },
1936 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1937 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1938 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1939 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1940 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1941 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1942 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1943 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1944 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1945 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1946 { 0, "{ [a, b] : exists e : 2e = a and "
1947 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1948 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1949 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1950 "j >= 1 and j' <= i + j - i' and i >= 1; "
1951 "[1, 1, 1, 1] }" },
1952 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1953 "[i,j] : exists a : j = 3a }" },
1954 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1955 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1956 "a >= 3) or "
1957 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1958 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1959 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1960 "c <= 6 + 8a and a >= 3; "
1961 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1962 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1963 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1964 "[x,0] : 3 <= x <= 4 }" },
1965 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1966 "[x,0] : 4 <= x <= 5 }" },
1967 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1968 "[x,0] : 3 <= x <= 5 }" },
1969 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1970 "[x,0] : 3 <= x <= 4 }" },
1971 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1972 "i1 <= 0; "
1973 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1974 { 1, "{ [0,0]; [1,1] }" },
1975 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
1976 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
1977 "ii <= k;"
1978 "[k, 0, k] : k <= 6 and k >= 1 }" },
1979 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
1980 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
1981 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
1982 { 1, "[n] -> { [1] : n >= 0;"
1983 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
1984 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
1985 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
1986 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
1987 "2e0 <= x and 2e0 <= n);"
1988 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
1989 "n >= 0) }" },
1990 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
1991 "128e0 >= -134 + 127t1 and t1 >= 2 and "
1992 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
1993 "t1 = 1 }" },
1994 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
1995 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
1996 "[0, 0] }" },
1997 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
1998 "t1 >= 13 and t1 <= 16);"
1999 "[t1] : t1 <= 15 and t1 >= 12 }" },
2000 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
2001 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
2002 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
2003 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
2004 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
2005 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
2006 "i <= 4j + 2 }" },
2007 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
2008 "(exists (e0 : 3e0 = -2 + c0)) }" },
2009 { 0, "[n, b0, t0] -> "
2010 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2011 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2012 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2013 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2014 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
2015 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
2016 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
2017 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
2018 "(exists (e0 = floor((-32b0 + i4)/1048576), "
2019 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
2020 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
2021 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
2022 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
2023 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
2024 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
2025 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
2026 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
2027 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
2028 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
2029 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
2030 { 0, "{ [i0, i1, i2] : "
2031 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
2032 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
2033 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
2034 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
2035 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
2036 "32e0 <= 31 + i0)) or "
2037 "i0 >= 0 }" },
2038 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
2039 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
2040 "2*floor((c)/2) = c and 0 <= a <= 192;"
2041 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
2043 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
2044 "(0 <= a <= b <= n) }" },
2045 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
2046 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
2047 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
2048 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2049 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2050 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2051 "b = 3 and 9e0 <= -19 + 2c)) }" },
2052 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
2053 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2054 "(a = 4 and b = 3 and "
2055 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
2056 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
2057 "(b = -1 + a and 0 < a <= 3 and "
2058 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
2059 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
2060 "b = 3 and 9e0 <= -19 + 2c)) }" },
2061 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2062 "[1, 0] }" },
2063 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
2064 "[0, 1] }" },
2065 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2066 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
2067 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
2068 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
2069 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
2070 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
2071 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
2072 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
2073 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
2074 { 1, "{ [a] : a <= 8 and "
2075 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
2076 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
2077 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
2078 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
2079 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
2080 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2081 "(a < 0 and 3*floor((a)/3) < a) }" },
2082 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
2083 "(a < -1 and 3*floor((a)/3) < a) }" },
2084 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
2085 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
2086 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
2087 "or (2 <= a <= 15 and b < a)) }" },
2088 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
2089 "32*floor((a)/32) < a) or a <= 15) }" },
2090 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
2091 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
2092 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
2093 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
2094 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
2095 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
2096 "S_0[n] : n <= m <= 2 + n }" },
2097 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
2098 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
2099 "2e0 <= a + b); "
2100 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
2101 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
2102 "2e0 < -a + 2b) }" },
2103 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
2104 "[i, 0, i] : 0 <= i <= 7 }" },
2105 { 1, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [1, 1] }" },
2106 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [0, 2] }" },
2107 { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" },
2108 { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" },
2109 { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" },
2112 /* A specialized coalescing test case that would result
2113 * in a segmentation fault or a failed assertion in earlier versions of isl.
2115 static int test_coalesce_special(struct isl_ctx *ctx)
2117 const char *str;
2118 isl_map *map1, *map2;
2120 str = "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2121 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
2122 "(y = 201 and o1 <= 239 and o1 >= 212) or "
2123 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
2124 "o1 <= 239 and o1 >= 212)) or "
2125 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
2126 "o1 <= 241 and o1 >= 240));"
2127 "[S_L220_OUT[] -> T7[]] -> "
2128 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
2129 "(y = 2 and o1 <= 241 and o1 >= 212) or "
2130 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
2131 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
2132 map1 = isl_map_read_from_str(ctx, str);
2133 map1 = isl_map_align_divs_internal(map1);
2134 map1 = isl_map_coalesce(map1);
2135 str = "[y] -> { [S_L220_OUT[] -> T7[]] -> "
2136 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
2137 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
2138 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
2139 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
2140 map2 = isl_map_read_from_str(ctx, str);
2141 map2 = isl_map_union(map2, map1);
2142 map2 = isl_map_align_divs_internal(map2);
2143 map2 = isl_map_coalesce(map2);
2144 isl_map_free(map2);
2145 if (!map2)
2146 return -1;
2148 return 0;
2151 /* A specialized coalescing test case that would result in an assertion
2152 * in an earlier version of isl.
2153 * The explicit call to isl_basic_set_union prevents the implicit
2154 * equality constraints in the first basic map from being detected prior
2155 * to the call to isl_set_coalesce, at least at the point
2156 * where this test case was introduced.
2158 static int test_coalesce_special2(struct isl_ctx *ctx)
2160 const char *str;
2161 isl_basic_set *bset1, *bset2;
2162 isl_set *set;
2164 str = "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2165 bset1 = isl_basic_set_read_from_str(ctx, str);
2166 str = "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2167 bset2 = isl_basic_set_read_from_str(ctx, str);
2168 set = isl_basic_set_union(bset1, bset2);
2169 set = isl_set_coalesce(set);
2170 isl_set_free(set);
2172 if (!set)
2173 return -1;
2174 return 0;
2177 /* Check that calling isl_set_coalesce does not leave other sets
2178 * that may share some information with the input to isl_set_coalesce
2179 * in an inconsistent state.
2180 * In particular, older versions of isl would modify all copies
2181 * of the basic sets in the isl_set_coalesce input in a way
2182 * that could leave them in an inconsistent state.
2183 * The result of printing any other set containing one of these
2184 * basic sets would then result in an invalid set description.
2186 static int test_coalesce_special3(isl_ctx *ctx)
2188 const char *str;
2189 char *s;
2190 isl_set *set1, *set2;
2191 isl_printer *p;
2193 set1 = isl_set_read_from_str(ctx, "{ [0, 0, 0] }");
2194 str = "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2195 set2 = isl_set_read_from_str(ctx, str);
2196 set1 = isl_set_union(set1, isl_set_copy(set2));
2197 set1 = isl_set_coalesce(set1);
2198 isl_set_free(set1);
2200 p = isl_printer_to_str(ctx);
2201 p = isl_printer_print_set(p, set2);
2202 isl_set_free(set2);
2203 s = isl_printer_get_str(p);
2204 isl_printer_free(p);
2205 set1 = isl_set_read_from_str(ctx, s);
2206 free(s);
2207 isl_set_free(set1);
2209 if (!set1)
2210 return -1;
2212 return 0;
2215 /* Test the functionality of isl_set_coalesce.
2216 * That is, check that the output is always equal to the input
2217 * and in some cases that the result consists of a single disjunct.
2219 static int test_coalesce(struct isl_ctx *ctx)
2221 int i;
2223 for (i = 0; i < ARRAY_SIZE(coalesce_tests); ++i) {
2224 const char *str = coalesce_tests[i].str;
2225 int check_one = coalesce_tests[i].single_disjunct;
2226 if (test_coalesce_set(ctx, str, check_one) < 0)
2227 return -1;
2230 if (test_coalesce_unbounded_wrapping(ctx) < 0)
2231 return -1;
2232 if (test_coalesce_special(ctx) < 0)
2233 return -1;
2234 if (test_coalesce_special2(ctx) < 0)
2235 return -1;
2236 if (test_coalesce_special3(ctx) < 0)
2237 return -1;
2239 return 0;
2242 /* Construct a representation of the graph on the right of Figure 1
2243 * in "Computing the Transitive Closure of a Union of
2244 * Affine Integer Tuple Relations".
2246 static __isl_give isl_map *cocoa_fig_1_right_graph(isl_ctx *ctx)
2248 isl_set *dom;
2249 isl_map *up, *right;
2251 dom = isl_set_read_from_str(ctx,
2252 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2253 "2 x - 3 y + 3 >= 0 }");
2254 right = isl_map_read_from_str(ctx,
2255 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2256 up = isl_map_read_from_str(ctx,
2257 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2258 right = isl_map_intersect_domain(right, isl_set_copy(dom));
2259 right = isl_map_intersect_range(right, isl_set_copy(dom));
2260 up = isl_map_intersect_domain(up, isl_set_copy(dom));
2261 up = isl_map_intersect_range(up, dom);
2262 return isl_map_union(up, right);
2265 /* Construct a representation of the power of the graph
2266 * on the right of Figure 1 in "Computing the Transitive Closure of
2267 * a Union of Affine Integer Tuple Relations".
2269 static __isl_give isl_map *cocoa_fig_1_right_power(isl_ctx *ctx)
2271 return isl_map_read_from_str(ctx,
2272 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2273 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2274 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2277 /* Construct a representation of the transitive closure of the graph
2278 * on the right of Figure 1 in "Computing the Transitive Closure of
2279 * a Union of Affine Integer Tuple Relations".
2281 static __isl_give isl_map *cocoa_fig_1_right_tc(isl_ctx *ctx)
2283 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx)));
2286 static int test_closure(isl_ctx *ctx)
2288 const char *str;
2289 isl_map *map, *map2;
2290 int exact, equal;
2292 /* COCOA example 1 */
2293 map = isl_map_read_from_str(ctx,
2294 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2295 "1 <= i and i < n and 1 <= j and j < n or "
2296 "i2 = i + 1 and j2 = j - 1 and "
2297 "1 <= i and i < n and 2 <= j and j <= n }");
2298 map = isl_map_power(map, &exact);
2299 assert(exact);
2300 isl_map_free(map);
2302 /* COCOA example 1 */
2303 map = isl_map_read_from_str(ctx,
2304 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2305 "1 <= i and i < n and 1 <= j and j < n or "
2306 "i2 = i + 1 and j2 = j - 1 and "
2307 "1 <= i and i < n and 2 <= j and j <= n }");
2308 map = isl_map_transitive_closure(map, &exact);
2309 assert(exact);
2310 map2 = isl_map_read_from_str(ctx,
2311 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2312 "1 <= i and i < n and 1 <= j and j <= n and "
2313 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2314 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2315 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2316 assert(isl_map_is_equal(map, map2));
2317 isl_map_free(map2);
2318 isl_map_free(map);
2320 map = isl_map_read_from_str(ctx,
2321 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2322 " 0 <= y and y <= n }");
2323 map = isl_map_transitive_closure(map, &exact);
2324 map2 = isl_map_read_from_str(ctx,
2325 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2326 " 0 <= y and y <= n }");
2327 assert(isl_map_is_equal(map, map2));
2328 isl_map_free(map2);
2329 isl_map_free(map);
2331 /* COCOA example 2 */
2332 map = isl_map_read_from_str(ctx,
2333 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2334 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2335 "i2 = i + 2 and j2 = j - 2 and "
2336 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2337 map = isl_map_transitive_closure(map, &exact);
2338 assert(exact);
2339 map2 = isl_map_read_from_str(ctx,
2340 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2341 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2342 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2343 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2344 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2345 assert(isl_map_is_equal(map, map2));
2346 isl_map_free(map);
2347 isl_map_free(map2);
2349 /* COCOA Fig.2 left */
2350 map = isl_map_read_from_str(ctx,
2351 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2352 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2353 "j <= n or "
2354 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2355 "j <= 2 i - 3 and j <= n - 2 or "
2356 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2357 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2358 map = isl_map_transitive_closure(map, &exact);
2359 assert(exact);
2360 isl_map_free(map);
2362 /* COCOA Fig.2 right */
2363 map = isl_map_read_from_str(ctx,
2364 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2365 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2366 "j <= n or "
2367 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2368 "j <= 2 i - 4 and j <= n - 3 or "
2369 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2370 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2371 map = isl_map_power(map, &exact);
2372 assert(exact);
2373 isl_map_free(map);
2375 /* COCOA Fig.2 right */
2376 map = isl_map_read_from_str(ctx,
2377 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2378 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2379 "j <= n or "
2380 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2381 "j <= 2 i - 4 and j <= n - 3 or "
2382 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2383 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2384 map = isl_map_transitive_closure(map, &exact);
2385 assert(exact);
2386 map2 = isl_map_read_from_str(ctx,
2387 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2388 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2389 "j <= n and 3 + i + 2 j <= 3 n and "
2390 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2391 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2392 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2393 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2394 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2395 assert(isl_map_is_equal(map, map2));
2396 isl_map_free(map2);
2397 isl_map_free(map);
2399 map = cocoa_fig_1_right_graph(ctx);
2400 map = isl_map_transitive_closure(map, &exact);
2401 assert(exact);
2402 map2 = cocoa_fig_1_right_tc(ctx);
2403 assert(isl_map_is_equal(map, map2));
2404 isl_map_free(map2);
2405 isl_map_free(map);
2407 map = cocoa_fig_1_right_graph(ctx);
2408 map = isl_map_power(map, &exact);
2409 map2 = cocoa_fig_1_right_power(ctx);
2410 equal = isl_map_is_equal(map, map2);
2411 isl_map_free(map2);
2412 isl_map_free(map);
2413 if (equal < 0)
2414 return -1;
2415 if (!exact)
2416 isl_die(ctx, isl_error_unknown, "power not exact", return -1);
2417 if (!equal)
2418 isl_die(ctx, isl_error_unknown, "unexpected power", return -1);
2420 /* COCOA Theorem 1 counter example */
2421 map = isl_map_read_from_str(ctx,
2422 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2423 "i2 = 1 and j2 = j or "
2424 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2425 map = isl_map_transitive_closure(map, &exact);
2426 assert(exact);
2427 isl_map_free(map);
2429 map = isl_map_read_from_str(ctx,
2430 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2431 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2432 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2433 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2434 map = isl_map_transitive_closure(map, &exact);
2435 assert(exact);
2436 isl_map_free(map);
2438 /* Kelly et al 1996, fig 12 */
2439 map = isl_map_read_from_str(ctx,
2440 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2441 "1 <= i,j,j+1 <= n or "
2442 "j = n and j2 = 1 and i2 = i + 1 and "
2443 "1 <= i,i+1 <= n }");
2444 map = isl_map_transitive_closure(map, &exact);
2445 assert(exact);
2446 map2 = isl_map_read_from_str(ctx,
2447 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2448 "1 <= i <= n and i = i2 or "
2449 "1 <= i < i2 <= n and 1 <= j <= n and "
2450 "1 <= j2 <= n }");
2451 assert(isl_map_is_equal(map, map2));
2452 isl_map_free(map2);
2453 isl_map_free(map);
2455 /* Omega's closure4 */
2456 map = isl_map_read_from_str(ctx,
2457 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2458 "1 <= x,y <= 10 or "
2459 "x2 = x + 1 and y2 = y and "
2460 "1 <= x <= 20 && 5 <= y <= 15 }");
2461 map = isl_map_transitive_closure(map, &exact);
2462 assert(exact);
2463 isl_map_free(map);
2465 map = isl_map_read_from_str(ctx,
2466 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2467 map = isl_map_transitive_closure(map, &exact);
2468 assert(!exact);
2469 map2 = isl_map_read_from_str(ctx,
2470 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2471 assert(isl_map_is_equal(map, map2));
2472 isl_map_free(map);
2473 isl_map_free(map2);
2475 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2476 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2477 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2478 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2479 map = isl_map_read_from_str(ctx, str);
2480 map = isl_map_transitive_closure(map, &exact);
2481 assert(exact);
2482 map2 = isl_map_read_from_str(ctx, str);
2483 assert(isl_map_is_equal(map, map2));
2484 isl_map_free(map);
2485 isl_map_free(map2);
2487 str = "{[0] -> [1]; [2] -> [3]}";
2488 map = isl_map_read_from_str(ctx, str);
2489 map = isl_map_transitive_closure(map, &exact);
2490 assert(exact);
2491 map2 = isl_map_read_from_str(ctx, str);
2492 assert(isl_map_is_equal(map, map2));
2493 isl_map_free(map);
2494 isl_map_free(map2);
2496 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2497 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2498 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2499 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2500 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2501 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2502 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2503 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2504 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2505 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2506 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2507 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2508 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2509 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2510 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2511 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2512 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2513 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2514 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2515 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2516 map = isl_map_read_from_str(ctx, str);
2517 map = isl_map_transitive_closure(map, NULL);
2518 assert(map);
2519 isl_map_free(map);
2521 return 0;
2524 static int test_lex(struct isl_ctx *ctx)
2526 isl_space *dim;
2527 isl_map *map;
2528 int empty;
2530 dim = isl_space_set_alloc(ctx, 0, 0);
2531 map = isl_map_lex_le(dim);
2532 empty = isl_map_is_empty(map);
2533 isl_map_free(map);
2535 if (empty < 0)
2536 return -1;
2537 if (empty)
2538 isl_die(ctx, isl_error_unknown,
2539 "expecting non-empty result", return -1);
2541 return 0;
2544 /* Inputs for isl_map_lexmin tests.
2545 * "map" is the input and "lexmin" is the expected result.
2547 struct {
2548 const char *map;
2549 const char *lexmin;
2550 } lexmin_tests [] = {
2551 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2552 "{ [x] -> [5] : 6 <= x <= 8; "
2553 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2554 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2555 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2556 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2557 "{ [x] -> [y] : (4y = x and x >= 0) or "
2558 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2559 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2560 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2561 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2562 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2563 /* Check that empty pieces are properly combined. */
2564 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2565 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2566 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2567 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2568 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2569 "x >= 4 }" },
2570 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2571 "a <= 255 and c <= 255 and d <= 255 - j and "
2572 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2573 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2574 "247d <= 247 + i and 248 - b <= 248d <= c and "
2575 "254d >= i - a + b and 254d >= -a + b and "
2576 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2577 "{ [i, k, j] -> "
2578 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2579 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2580 "247j >= 62738 - i and 509j <= 129795 + i and "
2581 "742j >= 188724 - i; "
2582 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2583 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2584 "16*floor((8 + b)/16) <= 7 + b; "
2585 "[a] -> [1] }",
2586 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2587 "[a] -> [b = 0] : 0 < a <= 509 }" },
2588 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2589 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2592 static int test_lexmin(struct isl_ctx *ctx)
2594 int i;
2595 int equal;
2596 const char *str;
2597 isl_basic_map *bmap;
2598 isl_map *map, *map2;
2599 isl_set *set;
2600 isl_set *set2;
2601 isl_pw_multi_aff *pma;
2603 str = "[p0, p1] -> { [] -> [] : "
2604 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2605 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2606 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2607 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2608 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2609 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2610 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2611 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2612 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2613 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2614 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2615 map = isl_map_read_from_str(ctx, str);
2616 map = isl_map_lexmin(map);
2617 isl_map_free(map);
2619 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2620 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2621 set = isl_set_read_from_str(ctx, str);
2622 set = isl_set_lexmax(set);
2623 str = "[C] -> { [obj,a,b,c] : C = 8 }";
2624 set2 = isl_set_read_from_str(ctx, str);
2625 set = isl_set_intersect(set, set2);
2626 assert(!isl_set_is_empty(set));
2627 isl_set_free(set);
2629 for (i = 0; i < ARRAY_SIZE(lexmin_tests); ++i) {
2630 map = isl_map_read_from_str(ctx, lexmin_tests[i].map);
2631 map = isl_map_lexmin(map);
2632 map2 = isl_map_read_from_str(ctx, lexmin_tests[i].lexmin);
2633 equal = isl_map_is_equal(map, map2);
2634 isl_map_free(map);
2635 isl_map_free(map2);
2637 if (equal < 0)
2638 return -1;
2639 if (!equal)
2640 isl_die(ctx, isl_error_unknown,
2641 "unexpected result", return -1);
2644 str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2645 " 8i' <= i and 8i' >= -7 + i }";
2646 bmap = isl_basic_map_read_from_str(ctx, str);
2647 pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap));
2648 map2 = isl_map_from_pw_multi_aff(pma);
2649 map = isl_map_from_basic_map(bmap);
2650 assert(isl_map_is_equal(map, map2));
2651 isl_map_free(map);
2652 isl_map_free(map2);
2654 str = "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2655 " 8i' <= i and 8i' >= -7 + i }";
2656 set = isl_set_read_from_str(ctx, str);
2657 pma = isl_set_lexmin_pw_multi_aff(isl_set_copy(set));
2658 set2 = isl_set_from_pw_multi_aff(pma);
2659 equal = isl_set_is_equal(set, set2);
2660 isl_set_free(set);
2661 isl_set_free(set2);
2662 if (equal < 0)
2663 return -1;
2664 if (!equal)
2665 isl_die(ctx, isl_error_unknown,
2666 "unexpected difference between set and "
2667 "piecewise affine expression", return -1);
2669 return 0;
2672 /* A specialized isl_set_min_val test case that would return the wrong result
2673 * in earlier versions of isl.
2674 * The explicit call to isl_basic_set_union prevents the second basic set
2675 * from being determined to be empty prior to the call to isl_set_min_val,
2676 * at least at the point where this test case was introduced.
2678 static int test_min_special(isl_ctx *ctx)
2680 const char *str;
2681 isl_basic_set *bset1, *bset2;
2682 isl_set *set;
2683 isl_aff *obj;
2684 isl_val *res;
2685 int ok;
2687 str = "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
2688 bset1 = isl_basic_set_read_from_str(ctx, str);
2689 str = "{ [a, b] : 1 <= a, b and a + b <= 1 }";
2690 bset2 = isl_basic_set_read_from_str(ctx, str);
2691 set = isl_basic_set_union(bset1, bset2);
2692 obj = isl_aff_read_from_str(ctx, "{ [a, b] -> [a] }");
2694 res = isl_set_min_val(set, obj);
2695 ok = isl_val_cmp_si(res, 5) == 0;
2697 isl_aff_free(obj);
2698 isl_set_free(set);
2699 isl_val_free(res);
2701 if (!res)
2702 return -1;
2703 if (!ok)
2704 isl_die(ctx, isl_error_unknown, "unexpected minimum",
2705 return -1);
2707 return 0;
2710 /* A specialized isl_set_min_val test case that would return an error
2711 * in earlier versions of isl.
2713 static int test_min_special2(isl_ctx *ctx)
2715 const char *str;
2716 isl_basic_set *bset;
2717 isl_aff *obj;
2718 isl_val *res;
2720 str = "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
2721 bset = isl_basic_set_read_from_str(ctx, str);
2723 obj = isl_aff_read_from_str(ctx, "{ [i, j, k] -> [i] }");
2725 res = isl_basic_set_max_val(bset, obj);
2727 isl_basic_set_free(bset);
2728 isl_aff_free(obj);
2729 isl_val_free(res);
2731 if (!res)
2732 return -1;
2734 return 0;
2737 struct {
2738 const char *set;
2739 const char *obj;
2740 __isl_give isl_val *(*fn)(__isl_keep isl_set *set,
2741 __isl_keep isl_aff *obj);
2742 const char *res;
2743 } opt_tests[] = {
2744 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val, "-1" },
2745 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val, "1" },
2746 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
2747 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
2748 &isl_set_max_val, "30" },
2752 /* Perform basic isl_set_min_val and isl_set_max_val tests.
2753 * In particular, check the results on non-convex inputs.
2755 static int test_min(struct isl_ctx *ctx)
2757 int i;
2758 isl_set *set;
2759 isl_aff *obj;
2760 isl_val *val, *res;
2761 isl_bool ok;
2763 for (i = 0; i < ARRAY_SIZE(opt_tests); ++i) {
2764 set = isl_set_read_from_str(ctx, opt_tests[i].set);
2765 obj = isl_aff_read_from_str(ctx, opt_tests[i].obj);
2766 res = isl_val_read_from_str(ctx, opt_tests[i].res);
2767 val = opt_tests[i].fn(set, obj);
2768 ok = isl_val_eq(res, val);
2769 isl_val_free(res);
2770 isl_val_free(val);
2771 isl_aff_free(obj);
2772 isl_set_free(set);
2774 if (ok < 0)
2775 return -1;
2776 if (!ok)
2777 isl_die(ctx, isl_error_unknown,
2778 "unexpected optimum", return -1);
2781 if (test_min_special(ctx) < 0)
2782 return -1;
2783 if (test_min_special2(ctx) < 0)
2784 return -1;
2786 return 0;
2789 struct must_may {
2790 isl_map *must;
2791 isl_map *may;
2794 static isl_stat collect_must_may(__isl_take isl_map *dep, int must,
2795 void *dep_user, void *user)
2797 struct must_may *mm = (struct must_may *)user;
2799 if (must)
2800 mm->must = isl_map_union(mm->must, dep);
2801 else
2802 mm->may = isl_map_union(mm->may, dep);
2804 return isl_stat_ok;
2807 static int common_space(void *first, void *second)
2809 int depth = *(int *)first;
2810 return 2 * depth;
2813 static int map_is_equal(__isl_keep isl_map *map, const char *str)
2815 isl_map *map2;
2816 int equal;
2818 if (!map)
2819 return -1;
2821 map2 = isl_map_read_from_str(map->ctx, str);
2822 equal = isl_map_is_equal(map, map2);
2823 isl_map_free(map2);
2825 return equal;
2828 static int map_check_equal(__isl_keep isl_map *map, const char *str)
2830 int equal;
2832 equal = map_is_equal(map, str);
2833 if (equal < 0)
2834 return -1;
2835 if (!equal)
2836 isl_die(isl_map_get_ctx(map), isl_error_unknown,
2837 "result not as expected", return -1);
2838 return 0;
2841 static int test_dep(struct isl_ctx *ctx)
2843 const char *str;
2844 isl_space *dim;
2845 isl_map *map;
2846 isl_access_info *ai;
2847 isl_flow *flow;
2848 int depth;
2849 struct must_may mm;
2851 depth = 3;
2853 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2854 map = isl_map_read_from_str(ctx, str);
2855 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
2857 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2858 map = isl_map_read_from_str(ctx, str);
2859 ai = isl_access_info_add_source(ai, map, 1, &depth);
2861 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2862 map = isl_map_read_from_str(ctx, str);
2863 ai = isl_access_info_add_source(ai, map, 1, &depth);
2865 flow = isl_access_info_compute_flow(ai);
2866 dim = isl_space_alloc(ctx, 0, 3, 3);
2867 mm.must = isl_map_empty(isl_space_copy(dim));
2868 mm.may = isl_map_empty(dim);
2870 isl_flow_foreach(flow, collect_must_may, &mm);
2872 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
2873 " [1,10,0] -> [2,5,0] }";
2874 assert(map_is_equal(mm.must, str));
2875 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2876 assert(map_is_equal(mm.may, str));
2878 isl_map_free(mm.must);
2879 isl_map_free(mm.may);
2880 isl_flow_free(flow);
2883 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2884 map = isl_map_read_from_str(ctx, str);
2885 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
2887 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2888 map = isl_map_read_from_str(ctx, str);
2889 ai = isl_access_info_add_source(ai, map, 1, &depth);
2891 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2892 map = isl_map_read_from_str(ctx, str);
2893 ai = isl_access_info_add_source(ai, map, 0, &depth);
2895 flow = isl_access_info_compute_flow(ai);
2896 dim = isl_space_alloc(ctx, 0, 3, 3);
2897 mm.must = isl_map_empty(isl_space_copy(dim));
2898 mm.may = isl_map_empty(dim);
2900 isl_flow_foreach(flow, collect_must_may, &mm);
2902 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2903 assert(map_is_equal(mm.must, str));
2904 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2905 assert(map_is_equal(mm.may, str));
2907 isl_map_free(mm.must);
2908 isl_map_free(mm.may);
2909 isl_flow_free(flow);
2912 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2913 map = isl_map_read_from_str(ctx, str);
2914 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
2916 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2917 map = isl_map_read_from_str(ctx, str);
2918 ai = isl_access_info_add_source(ai, map, 0, &depth);
2920 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2921 map = isl_map_read_from_str(ctx, str);
2922 ai = isl_access_info_add_source(ai, map, 0, &depth);
2924 flow = isl_access_info_compute_flow(ai);
2925 dim = isl_space_alloc(ctx, 0, 3, 3);
2926 mm.must = isl_map_empty(isl_space_copy(dim));
2927 mm.may = isl_map_empty(dim);
2929 isl_flow_foreach(flow, collect_must_may, &mm);
2931 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
2932 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2933 assert(map_is_equal(mm.may, str));
2934 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2935 assert(map_is_equal(mm.must, str));
2937 isl_map_free(mm.must);
2938 isl_map_free(mm.may);
2939 isl_flow_free(flow);
2942 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
2943 map = isl_map_read_from_str(ctx, str);
2944 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
2946 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2947 map = isl_map_read_from_str(ctx, str);
2948 ai = isl_access_info_add_source(ai, map, 0, &depth);
2950 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
2951 map = isl_map_read_from_str(ctx, str);
2952 ai = isl_access_info_add_source(ai, map, 0, &depth);
2954 flow = isl_access_info_compute_flow(ai);
2955 dim = isl_space_alloc(ctx, 0, 3, 3);
2956 mm.must = isl_map_empty(isl_space_copy(dim));
2957 mm.may = isl_map_empty(dim);
2959 isl_flow_foreach(flow, collect_must_may, &mm);
2961 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2962 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2963 assert(map_is_equal(mm.may, str));
2964 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2965 assert(map_is_equal(mm.must, str));
2967 isl_map_free(mm.must);
2968 isl_map_free(mm.may);
2969 isl_flow_free(flow);
2972 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2973 map = isl_map_read_from_str(ctx, str);
2974 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
2976 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2977 map = isl_map_read_from_str(ctx, str);
2978 ai = isl_access_info_add_source(ai, map, 0, &depth);
2980 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2981 map = isl_map_read_from_str(ctx, str);
2982 ai = isl_access_info_add_source(ai, map, 0, &depth);
2984 flow = isl_access_info_compute_flow(ai);
2985 dim = isl_space_alloc(ctx, 0, 3, 3);
2986 mm.must = isl_map_empty(isl_space_copy(dim));
2987 mm.may = isl_map_empty(dim);
2989 isl_flow_foreach(flow, collect_must_may, &mm);
2991 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2992 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2993 assert(map_is_equal(mm.may, str));
2994 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2995 assert(map_is_equal(mm.must, str));
2997 isl_map_free(mm.must);
2998 isl_map_free(mm.may);
2999 isl_flow_free(flow);
3002 depth = 5;
3004 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3005 map = isl_map_read_from_str(ctx, str);
3006 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
3008 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
3009 map = isl_map_read_from_str(ctx, str);
3010 ai = isl_access_info_add_source(ai, map, 1, &depth);
3012 flow = isl_access_info_compute_flow(ai);
3013 dim = isl_space_alloc(ctx, 0, 5, 5);
3014 mm.must = isl_map_empty(isl_space_copy(dim));
3015 mm.may = isl_map_empty(dim);
3017 isl_flow_foreach(flow, collect_must_may, &mm);
3019 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
3020 assert(map_is_equal(mm.must, str));
3021 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
3022 assert(map_is_equal(mm.may, str));
3024 isl_map_free(mm.must);
3025 isl_map_free(mm.may);
3026 isl_flow_free(flow);
3028 return 0;
3031 /* Check that the dependence analysis proceeds without errors.
3032 * Earlier versions of isl would break down during the analysis
3033 * due to the use of the wrong spaces.
3035 static int test_flow(isl_ctx *ctx)
3037 const char *str;
3038 isl_union_map *access, *schedule;
3039 isl_union_map *must_dep, *may_dep;
3040 int r;
3042 str = "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
3043 access = isl_union_map_read_from_str(ctx, str);
3044 str = "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
3045 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
3046 "S2[] -> [1,0,0,0]; "
3047 "S3[] -> [-1,0,0,0] }";
3048 schedule = isl_union_map_read_from_str(ctx, str);
3049 r = isl_union_map_compute_flow(access, isl_union_map_copy(access),
3050 isl_union_map_copy(access), schedule,
3051 &must_dep, &may_dep, NULL, NULL);
3052 isl_union_map_free(may_dep);
3053 isl_union_map_free(must_dep);
3055 return r;
3058 struct {
3059 const char *map;
3060 int sv;
3061 } sv_tests[] = {
3062 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
3063 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
3064 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
3065 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
3066 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
3067 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
3068 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3069 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
3070 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
3073 int test_sv(isl_ctx *ctx)
3075 isl_union_map *umap;
3076 int i;
3077 int sv;
3079 for (i = 0; i < ARRAY_SIZE(sv_tests); ++i) {
3080 umap = isl_union_map_read_from_str(ctx, sv_tests[i].map);
3081 sv = isl_union_map_is_single_valued(umap);
3082 isl_union_map_free(umap);
3083 if (sv < 0)
3084 return -1;
3085 if (sv_tests[i].sv && !sv)
3086 isl_die(ctx, isl_error_internal,
3087 "map not detected as single valued", return -1);
3088 if (!sv_tests[i].sv && sv)
3089 isl_die(ctx, isl_error_internal,
3090 "map detected as single valued", return -1);
3093 return 0;
3096 struct {
3097 const char *str;
3098 int bijective;
3099 } bijective_tests[] = {
3100 { "[N,M]->{[i,j] -> [i]}", 0 },
3101 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
3102 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
3103 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
3104 { "[N,M]->{[i,j] -> [j,i]}", 1 },
3105 { "[N,M]->{[i,j] -> [i+j]}", 0 },
3106 { "[N,M]->{[i,j] -> []}", 0 },
3107 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
3108 { "[N,M]->{[i,j] -> [2i]}", 0 },
3109 { "[N,M]->{[i,j] -> [i,i]}", 0 },
3110 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
3111 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
3112 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
3115 static int test_bijective(struct isl_ctx *ctx)
3117 isl_map *map;
3118 int i;
3119 int bijective;
3121 for (i = 0; i < ARRAY_SIZE(bijective_tests); ++i) {
3122 map = isl_map_read_from_str(ctx, bijective_tests[i].str);
3123 bijective = isl_map_is_bijective(map);
3124 isl_map_free(map);
3125 if (bijective < 0)
3126 return -1;
3127 if (bijective_tests[i].bijective && !bijective)
3128 isl_die(ctx, isl_error_internal,
3129 "map not detected as bijective", return -1);
3130 if (!bijective_tests[i].bijective && bijective)
3131 isl_die(ctx, isl_error_internal,
3132 "map detected as bijective", return -1);
3135 return 0;
3138 /* Inputs for isl_pw_qpolynomial_gist tests.
3139 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
3141 struct {
3142 const char *pwqp;
3143 const char *set;
3144 const char *gist;
3145 } pwqp_gist_tests[] = {
3146 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
3147 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
3148 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
3149 "{ [i] -> -1/2 + 1/2 * i }" },
3150 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
3153 static int test_pwqp(struct isl_ctx *ctx)
3155 int i;
3156 const char *str;
3157 isl_set *set;
3158 isl_pw_qpolynomial *pwqp1, *pwqp2;
3159 int equal;
3161 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3162 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3164 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
3165 isl_dim_in, 1, 1);
3167 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3168 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3170 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3172 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3174 isl_pw_qpolynomial_free(pwqp1);
3176 for (i = 0; i < ARRAY_SIZE(pwqp_gist_tests); ++i) {
3177 str = pwqp_gist_tests[i].pwqp;
3178 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3179 str = pwqp_gist_tests[i].set;
3180 set = isl_set_read_from_str(ctx, str);
3181 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
3182 str = pwqp_gist_tests[i].gist;
3183 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3184 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3185 equal = isl_pw_qpolynomial_is_zero(pwqp1);
3186 isl_pw_qpolynomial_free(pwqp1);
3188 if (equal < 0)
3189 return -1;
3190 if (!equal)
3191 isl_die(ctx, isl_error_unknown,
3192 "unexpected result", return -1);
3195 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
3196 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3197 str = "{ [i] -> ([(2 * [i/2])/5]) }";
3198 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3200 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3202 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3204 isl_pw_qpolynomial_free(pwqp1);
3206 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
3207 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3208 str = "{ [x] -> x }";
3209 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3211 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3213 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3215 isl_pw_qpolynomial_free(pwqp1);
3217 str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3218 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3219 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3220 pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
3221 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
3222 assert(isl_pw_qpolynomial_is_zero(pwqp1));
3223 isl_pw_qpolynomial_free(pwqp1);
3225 str = "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3226 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3227 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3228 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3229 set = isl_set_read_from_str(ctx, "{ [a,b,a] }");
3230 pwqp1 = isl_pw_qpolynomial_intersect_domain(pwqp1, set);
3231 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
3232 isl_pw_qpolynomial_free(pwqp1);
3233 isl_pw_qpolynomial_free(pwqp2);
3234 if (equal < 0)
3235 return -1;
3236 if (!equal)
3237 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3239 str = "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3240 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
3241 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3242 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
3243 pwqp1 = isl_pw_qpolynomial_fix_val(pwqp1, isl_dim_set, 1,
3244 isl_val_one(ctx));
3245 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
3246 isl_pw_qpolynomial_free(pwqp1);
3247 isl_pw_qpolynomial_free(pwqp2);
3248 if (equal < 0)
3249 return -1;
3250 if (!equal)
3251 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3253 return 0;
3256 static int test_split_periods(isl_ctx *ctx)
3258 const char *str;
3259 isl_pw_qpolynomial *pwqp;
3261 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3262 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3263 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3264 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3266 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
3268 isl_pw_qpolynomial_free(pwqp);
3270 if (!pwqp)
3271 return -1;
3273 return 0;
3276 static int test_union(isl_ctx *ctx)
3278 const char *str;
3279 isl_union_set *uset1, *uset2;
3280 isl_union_map *umap1, *umap2;
3281 int equal;
3283 str = "{ [i] : 0 <= i <= 1 }";
3284 uset1 = isl_union_set_read_from_str(ctx, str);
3285 str = "{ [1] -> [0] }";
3286 umap1 = isl_union_map_read_from_str(ctx, str);
3288 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
3289 equal = isl_union_map_is_equal(umap1, umap2);
3291 isl_union_map_free(umap1);
3292 isl_union_map_free(umap2);
3294 if (equal < 0)
3295 return -1;
3296 if (!equal)
3297 isl_die(ctx, isl_error_unknown, "union maps not equal",
3298 return -1);
3300 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3301 umap1 = isl_union_map_read_from_str(ctx, str);
3302 str = "{ A[i]; B[i] }";
3303 uset1 = isl_union_set_read_from_str(ctx, str);
3305 uset2 = isl_union_map_domain(umap1);
3307 equal = isl_union_set_is_equal(uset1, uset2);
3309 isl_union_set_free(uset1);
3310 isl_union_set_free(uset2);
3312 if (equal < 0)
3313 return -1;
3314 if (!equal)
3315 isl_die(ctx, isl_error_unknown, "union sets not equal",
3316 return -1);
3318 return 0;
3321 /* Check that computing a bound of a non-zero polynomial over an unbounded
3322 * domain does not produce a rational value.
3323 * In particular, check that the upper bound is infinity.
3325 static int test_bound_unbounded_domain(isl_ctx *ctx)
3327 const char *str;
3328 isl_pw_qpolynomial *pwqp;
3329 isl_pw_qpolynomial_fold *pwf, *pwf2;
3330 isl_bool equal;
3332 str = "{ [m,n] -> -m * n }";
3333 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3334 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3335 str = "{ infty }";
3336 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3337 pwf2 = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3338 equal = isl_pw_qpolynomial_fold_plain_is_equal(pwf, pwf2);
3339 isl_pw_qpolynomial_fold_free(pwf);
3340 isl_pw_qpolynomial_fold_free(pwf2);
3342 if (equal < 0)
3343 return -1;
3344 if (!equal)
3345 isl_die(ctx, isl_error_unknown,
3346 "expecting infinite polynomial bound", return -1);
3348 return 0;
3351 static int test_bound(isl_ctx *ctx)
3353 const char *str;
3354 unsigned dim;
3355 isl_pw_qpolynomial *pwqp;
3356 isl_pw_qpolynomial_fold *pwf;
3358 if (test_bound_unbounded_domain(ctx) < 0)
3359 return -1;
3361 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
3362 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3363 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3364 dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in);
3365 isl_pw_qpolynomial_fold_free(pwf);
3366 if (dim != 4)
3367 isl_die(ctx, isl_error_unknown, "unexpected input dimension",
3368 return -1);
3370 str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3371 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
3372 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
3373 dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in);
3374 isl_pw_qpolynomial_fold_free(pwf);
3375 if (dim != 1)
3376 isl_die(ctx, isl_error_unknown, "unexpected input dimension",
3377 return -1);
3379 return 0;
3382 static int test_lift(isl_ctx *ctx)
3384 const char *str;
3385 isl_basic_map *bmap;
3386 isl_basic_set *bset;
3388 str = "{ [i0] : exists e0 : i0 = 4e0 }";
3389 bset = isl_basic_set_read_from_str(ctx, str);
3390 bset = isl_basic_set_lift(bset);
3391 bmap = isl_basic_map_from_range(bset);
3392 bset = isl_basic_map_domain(bmap);
3393 isl_basic_set_free(bset);
3395 return 0;
3398 struct {
3399 const char *set1;
3400 const char *set2;
3401 int subset;
3402 } subset_tests[] = {
3403 { "{ [112, 0] }",
3404 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3405 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3406 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3407 { "{ [65] }",
3408 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3409 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3410 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3411 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3412 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3413 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3414 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3415 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3416 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3417 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3418 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3419 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3420 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3421 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3422 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3423 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3424 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3425 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3426 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3427 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3428 "4e0 <= -57 + i0 + i1)) or "
3429 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3430 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3431 "4e0 >= -61 + i0 + i1)) or "
3432 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3433 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3436 static int test_subset(isl_ctx *ctx)
3438 int i;
3439 isl_set *set1, *set2;
3440 int subset;
3442 for (i = 0; i < ARRAY_SIZE(subset_tests); ++i) {
3443 set1 = isl_set_read_from_str(ctx, subset_tests[i].set1);
3444 set2 = isl_set_read_from_str(ctx, subset_tests[i].set2);
3445 subset = isl_set_is_subset(set1, set2);
3446 isl_set_free(set1);
3447 isl_set_free(set2);
3448 if (subset < 0)
3449 return -1;
3450 if (subset != subset_tests[i].subset)
3451 isl_die(ctx, isl_error_unknown,
3452 "incorrect subset result", return -1);
3455 return 0;
3458 struct {
3459 const char *minuend;
3460 const char *subtrahend;
3461 const char *difference;
3462 } subtract_domain_tests[] = {
3463 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
3464 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
3465 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
3468 static int test_subtract(isl_ctx *ctx)
3470 int i;
3471 isl_union_map *umap1, *umap2;
3472 isl_union_pw_multi_aff *upma1, *upma2;
3473 isl_union_set *uset;
3474 int equal;
3476 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests); ++i) {
3477 umap1 = isl_union_map_read_from_str(ctx,
3478 subtract_domain_tests[i].minuend);
3479 uset = isl_union_set_read_from_str(ctx,
3480 subtract_domain_tests[i].subtrahend);
3481 umap2 = isl_union_map_read_from_str(ctx,
3482 subtract_domain_tests[i].difference);
3483 umap1 = isl_union_map_subtract_domain(umap1, uset);
3484 equal = isl_union_map_is_equal(umap1, umap2);
3485 isl_union_map_free(umap1);
3486 isl_union_map_free(umap2);
3487 if (equal < 0)
3488 return -1;
3489 if (!equal)
3490 isl_die(ctx, isl_error_unknown,
3491 "incorrect subtract domain result", return -1);
3494 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests); ++i) {
3495 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
3496 subtract_domain_tests[i].minuend);
3497 uset = isl_union_set_read_from_str(ctx,
3498 subtract_domain_tests[i].subtrahend);
3499 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
3500 subtract_domain_tests[i].difference);
3501 upma1 = isl_union_pw_multi_aff_subtract_domain(upma1, uset);
3502 equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2);
3503 isl_union_pw_multi_aff_free(upma1);
3504 isl_union_pw_multi_aff_free(upma2);
3505 if (equal < 0)
3506 return -1;
3507 if (!equal)
3508 isl_die(ctx, isl_error_unknown,
3509 "incorrect subtract domain result", return -1);
3512 return 0;
3515 /* Check that intersecting the empty basic set with another basic set
3516 * does not increase the number of constraints. In particular,
3517 * the empty basic set should maintain its canonical representation.
3519 static int test_intersect(isl_ctx *ctx)
3521 int n1, n2;
3522 isl_basic_set *bset1, *bset2;
3524 bset1 = isl_basic_set_read_from_str(ctx, "{ [a,b,c] : 1 = 0 }");
3525 bset2 = isl_basic_set_read_from_str(ctx, "{ [1,2,3] }");
3526 n1 = isl_basic_set_n_constraint(bset1);
3527 bset1 = isl_basic_set_intersect(bset1, bset2);
3528 n2 = isl_basic_set_n_constraint(bset1);
3529 isl_basic_set_free(bset1);
3530 if (!bset1)
3531 return -1;
3532 if (n1 != n2)
3533 isl_die(ctx, isl_error_unknown,
3534 "number of constraints of empty set changed",
3535 return -1);
3537 return 0;
3540 int test_factorize(isl_ctx *ctx)
3542 const char *str;
3543 isl_basic_set *bset;
3544 isl_factorizer *f;
3546 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
3547 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
3548 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
3549 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
3550 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
3551 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
3552 "3i5 >= -2i0 - i2 + 3i4 }";
3553 bset = isl_basic_set_read_from_str(ctx, str);
3554 f = isl_basic_set_factorizer(bset);
3555 isl_basic_set_free(bset);
3556 isl_factorizer_free(f);
3557 if (!f)
3558 isl_die(ctx, isl_error_unknown,
3559 "failed to construct factorizer", return -1);
3561 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
3562 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
3563 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
3564 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
3565 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
3566 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
3567 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
3568 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
3569 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
3570 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
3571 bset = isl_basic_set_read_from_str(ctx, str);
3572 f = isl_basic_set_factorizer(bset);
3573 isl_basic_set_free(bset);
3574 isl_factorizer_free(f);
3575 if (!f)
3576 isl_die(ctx, isl_error_unknown,
3577 "failed to construct factorizer", return -1);
3579 return 0;
3582 static isl_stat check_injective(__isl_take isl_map *map, void *user)
3584 int *injective = user;
3586 *injective = isl_map_is_injective(map);
3587 isl_map_free(map);
3589 if (*injective < 0 || !*injective)
3590 return isl_stat_error;
3592 return isl_stat_ok;
3595 int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
3596 const char *r, const char *s, int tilable, int parallel)
3598 int i;
3599 isl_union_set *D;
3600 isl_union_map *W, *R, *S;
3601 isl_union_map *empty;
3602 isl_union_map *dep_raw, *dep_war, *dep_waw, *dep;
3603 isl_union_map *validity, *proximity, *coincidence;
3604 isl_union_map *schedule;
3605 isl_union_map *test;
3606 isl_union_set *delta;
3607 isl_union_set *domain;
3608 isl_set *delta_set;
3609 isl_set *slice;
3610 isl_set *origin;
3611 isl_schedule_constraints *sc;
3612 isl_schedule *sched;
3613 int is_nonneg, is_parallel, is_tilable, is_injection, is_complete;
3615 D = isl_union_set_read_from_str(ctx, d);
3616 W = isl_union_map_read_from_str(ctx, w);
3617 R = isl_union_map_read_from_str(ctx, r);
3618 S = isl_union_map_read_from_str(ctx, s);
3620 W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
3621 R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
3623 empty = isl_union_map_empty(isl_union_map_get_space(S));
3624 isl_union_map_compute_flow(isl_union_map_copy(R),
3625 isl_union_map_copy(W), empty,
3626 isl_union_map_copy(S),
3627 &dep_raw, NULL, NULL, NULL);
3628 isl_union_map_compute_flow(isl_union_map_copy(W),
3629 isl_union_map_copy(W),
3630 isl_union_map_copy(R),
3631 isl_union_map_copy(S),
3632 &dep_waw, &dep_war, NULL, NULL);
3634 dep = isl_union_map_union(dep_waw, dep_war);
3635 dep = isl_union_map_union(dep, dep_raw);
3636 validity = isl_union_map_copy(dep);
3637 coincidence = isl_union_map_copy(dep);
3638 proximity = isl_union_map_copy(dep);
3640 sc = isl_schedule_constraints_on_domain(isl_union_set_copy(D));
3641 sc = isl_schedule_constraints_set_validity(sc, validity);
3642 sc = isl_schedule_constraints_set_coincidence(sc, coincidence);
3643 sc = isl_schedule_constraints_set_proximity(sc, proximity);
3644 sched = isl_schedule_constraints_compute_schedule(sc);
3645 schedule = isl_schedule_get_map(sched);
3646 isl_schedule_free(sched);
3647 isl_union_map_free(W);
3648 isl_union_map_free(R);
3649 isl_union_map_free(S);
3651 is_injection = 1;
3652 isl_union_map_foreach_map(schedule, &check_injective, &is_injection);
3654 domain = isl_union_map_domain(isl_union_map_copy(schedule));
3655 is_complete = isl_union_set_is_subset(D, domain);
3656 isl_union_set_free(D);
3657 isl_union_set_free(domain);
3659 test = isl_union_map_reverse(isl_union_map_copy(schedule));
3660 test = isl_union_map_apply_range(test, dep);
3661 test = isl_union_map_apply_range(test, schedule);
3663 delta = isl_union_map_deltas(test);
3664 if (isl_union_set_n_set(delta) == 0) {
3665 is_tilable = 1;
3666 is_parallel = 1;
3667 is_nonneg = 1;
3668 isl_union_set_free(delta);
3669 } else {
3670 delta_set = isl_set_from_union_set(delta);
3672 slice = isl_set_universe(isl_set_get_space(delta_set));
3673 for (i = 0; i < tilable; ++i)
3674 slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
3675 is_tilable = isl_set_is_subset(delta_set, slice);
3676 isl_set_free(slice);
3678 slice = isl_set_universe(isl_set_get_space(delta_set));
3679 for (i = 0; i < parallel; ++i)
3680 slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
3681 is_parallel = isl_set_is_subset(delta_set, slice);
3682 isl_set_free(slice);
3684 origin = isl_set_universe(isl_set_get_space(delta_set));
3685 for (i = 0; i < isl_set_dim(origin, isl_dim_set); ++i)
3686 origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
3688 delta_set = isl_set_union(delta_set, isl_set_copy(origin));
3689 delta_set = isl_set_lexmin(delta_set);
3691 is_nonneg = isl_set_is_equal(delta_set, origin);
3693 isl_set_free(origin);
3694 isl_set_free(delta_set);
3697 if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
3698 is_injection < 0 || is_complete < 0)
3699 return -1;
3700 if (!is_complete)
3701 isl_die(ctx, isl_error_unknown,
3702 "generated schedule incomplete", return -1);
3703 if (!is_injection)
3704 isl_die(ctx, isl_error_unknown,
3705 "generated schedule not injective on each statement",
3706 return -1);
3707 if (!is_nonneg)
3708 isl_die(ctx, isl_error_unknown,
3709 "negative dependences in generated schedule",
3710 return -1);
3711 if (!is_tilable)
3712 isl_die(ctx, isl_error_unknown,
3713 "generated schedule not as tilable as expected",
3714 return -1);
3715 if (!is_parallel)
3716 isl_die(ctx, isl_error_unknown,
3717 "generated schedule not as parallel as expected",
3718 return -1);
3720 return 0;
3723 /* Compute a schedule for the given instance set, validity constraints,
3724 * proximity constraints and context and return a corresponding union map
3725 * representation.
3727 static __isl_give isl_union_map *compute_schedule_with_context(isl_ctx *ctx,
3728 const char *domain, const char *validity, const char *proximity,
3729 const char *context)
3731 isl_set *con;
3732 isl_union_set *dom;
3733 isl_union_map *dep;
3734 isl_union_map *prox;
3735 isl_schedule_constraints *sc;
3736 isl_schedule *schedule;
3737 isl_union_map *sched;
3739 con = isl_set_read_from_str(ctx, context);
3740 dom = isl_union_set_read_from_str(ctx, domain);
3741 dep = isl_union_map_read_from_str(ctx, validity);
3742 prox = isl_union_map_read_from_str(ctx, proximity);
3743 sc = isl_schedule_constraints_on_domain(dom);
3744 sc = isl_schedule_constraints_set_context(sc, con);
3745 sc = isl_schedule_constraints_set_validity(sc, dep);
3746 sc = isl_schedule_constraints_set_proximity(sc, prox);
3747 schedule = isl_schedule_constraints_compute_schedule(sc);
3748 sched = isl_schedule_get_map(schedule);
3749 isl_schedule_free(schedule);
3751 return sched;
3754 /* Compute a schedule for the given instance set, validity constraints and
3755 * proximity constraints and return a corresponding union map representation.
3757 static __isl_give isl_union_map *compute_schedule(isl_ctx *ctx,
3758 const char *domain, const char *validity, const char *proximity)
3760 return compute_schedule_with_context(ctx, domain, validity, proximity,
3761 "{ : }");
3764 /* Check that a schedule can be constructed on the given domain
3765 * with the given validity and proximity constraints.
3767 static int test_has_schedule(isl_ctx *ctx, const char *domain,
3768 const char *validity, const char *proximity)
3770 isl_union_map *sched;
3772 sched = compute_schedule(ctx, domain, validity, proximity);
3773 if (!sched)
3774 return -1;
3776 isl_union_map_free(sched);
3777 return 0;
3780 int test_special_schedule(isl_ctx *ctx, const char *domain,
3781 const char *validity, const char *proximity, const char *expected_sched)
3783 isl_union_map *sched1, *sched2;
3784 int equal;
3786 sched1 = compute_schedule(ctx, domain, validity, proximity);
3787 sched2 = isl_union_map_read_from_str(ctx, expected_sched);
3789 equal = isl_union_map_is_equal(sched1, sched2);
3790 isl_union_map_free(sched1);
3791 isl_union_map_free(sched2);
3793 if (equal < 0)
3794 return -1;
3795 if (!equal)
3796 isl_die(ctx, isl_error_unknown, "unexpected schedule",
3797 return -1);
3799 return 0;
3802 /* Check that the schedule map is properly padded, i.e., that the range
3803 * lives in a single space.
3805 static int test_padded_schedule(isl_ctx *ctx)
3807 const char *str;
3808 isl_union_set *D;
3809 isl_union_map *validity, *proximity;
3810 isl_schedule_constraints *sc;
3811 isl_schedule *sched;
3812 isl_union_map *umap;
3813 isl_union_set *range;
3814 isl_set *set;
3816 str = "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
3817 D = isl_union_set_read_from_str(ctx, str);
3818 validity = isl_union_map_empty(isl_union_set_get_space(D));
3819 proximity = isl_union_map_copy(validity);
3820 sc = isl_schedule_constraints_on_domain(D);
3821 sc = isl_schedule_constraints_set_validity(sc, validity);
3822 sc = isl_schedule_constraints_set_proximity(sc, proximity);
3823 sched = isl_schedule_constraints_compute_schedule(sc);
3824 umap = isl_schedule_get_map(sched);
3825 isl_schedule_free(sched);
3826 range = isl_union_map_range(umap);
3827 set = isl_set_from_union_set(range);
3828 isl_set_free(set);
3830 if (!set)
3831 return -1;
3833 return 0;
3836 /* Check that conditional validity constraints are also taken into
3837 * account across bands.
3838 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
3839 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
3840 * and then check that the adjacent order constraint C[2,1]->D[2,0]
3841 * is enforced by the rest of the schedule.
3843 static int test_special_conditional_schedule_constraints(isl_ctx *ctx)
3845 const char *str;
3846 isl_union_set *domain;
3847 isl_union_map *validity, *proximity, *condition;
3848 isl_union_map *sink, *source, *dep;
3849 isl_schedule_constraints *sc;
3850 isl_schedule *schedule;
3851 isl_union_access_info *access;
3852 isl_union_flow *flow;
3853 int empty;
3855 str = "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3856 "A[k] : k >= 1 and k <= -1 + n; "
3857 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3858 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
3859 domain = isl_union_set_read_from_str(ctx, str);
3860 sc = isl_schedule_constraints_on_domain(domain);
3861 str = "[n] -> { D[k, i] -> C[1 + k, k - i] : "
3862 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3863 "D[k, i] -> C[1 + k, i] : "
3864 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3865 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
3866 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
3867 validity = isl_union_map_read_from_str(ctx, str);
3868 sc = isl_schedule_constraints_set_validity(sc, validity);
3869 str = "[n] -> { C[k, i] -> D[k, i] : "
3870 "0 <= i <= -1 + k and k <= -1 + n }";
3871 proximity = isl_union_map_read_from_str(ctx, str);
3872 sc = isl_schedule_constraints_set_proximity(sc, proximity);
3873 str = "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
3874 "i <= -1 + k and i >= 1 and k <= -2 + n; "
3875 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
3876 "k <= -1 + n and i >= 0 and i <= -2 + k }";
3877 condition = isl_union_map_read_from_str(ctx, str);
3878 str = "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
3879 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3880 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
3881 "i >= 0 and i <= -1 + k and k <= -1 + n and "
3882 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
3883 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
3884 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3885 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
3886 "k <= -1 + n and i >= 0 and i <= -1 + k and "
3887 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
3888 validity = isl_union_map_read_from_str(ctx, str);
3889 sc = isl_schedule_constraints_set_conditional_validity(sc, condition,
3890 validity);
3891 schedule = isl_schedule_constraints_compute_schedule(sc);
3892 str = "{ D[2,0] -> [] }";
3893 sink = isl_union_map_read_from_str(ctx, str);
3894 access = isl_union_access_info_from_sink(sink);
3895 str = "{ C[2,1] -> [] }";
3896 source = isl_union_map_read_from_str(ctx, str);
3897 access = isl_union_access_info_set_must_source(access, source);
3898 access = isl_union_access_info_set_schedule(access, schedule);
3899 flow = isl_union_access_info_compute_flow(access);
3900 dep = isl_union_flow_get_must_dependence(flow);
3901 isl_union_flow_free(flow);
3902 empty = isl_union_map_is_empty(dep);
3903 isl_union_map_free(dep);
3905 if (empty < 0)
3906 return -1;
3907 if (empty)
3908 isl_die(ctx, isl_error_unknown,
3909 "conditional validity not respected", return -1);
3911 return 0;
3914 /* Check that the test for violated conditional validity constraints
3915 * is not confused by domain compression.
3916 * In particular, earlier versions of isl would apply
3917 * a schedule on the compressed domains to the original domains,
3918 * resulting in a failure to detect that the default schedule
3919 * violates the conditional validity constraints.
3921 static int test_special_conditional_schedule_constraints_2(isl_ctx *ctx)
3923 const char *str;
3924 isl_bool empty;
3925 isl_union_set *domain;
3926 isl_union_map *validity, *condition;
3927 isl_schedule_constraints *sc;
3928 isl_schedule *schedule;
3929 isl_union_map *umap;
3930 isl_map *map, *ge;
3932 str = "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
3933 domain = isl_union_set_read_from_str(ctx, str);
3934 sc = isl_schedule_constraints_on_domain(domain);
3935 str = "{ B[1, i] -> A[0, i + 1] }";
3936 condition = isl_union_map_read_from_str(ctx, str);
3937 str = "{ A[0, i] -> B[1, i - 1] }";
3938 validity = isl_union_map_read_from_str(ctx, str);
3939 sc = isl_schedule_constraints_set_conditional_validity(sc, condition,
3940 isl_union_map_copy(validity));
3941 schedule = isl_schedule_constraints_compute_schedule(sc);
3942 umap = isl_schedule_get_map(schedule);
3943 isl_schedule_free(schedule);
3944 validity = isl_union_map_apply_domain(validity,
3945 isl_union_map_copy(umap));
3946 validity = isl_union_map_apply_range(validity, umap);
3947 map = isl_map_from_union_map(validity);
3948 ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map)));
3949 map = isl_map_intersect(map, ge);
3950 empty = isl_map_is_empty(map);
3951 isl_map_free(map);
3953 if (empty < 0)
3954 return -1;
3955 if (!empty)
3956 isl_die(ctx, isl_error_unknown,
3957 "conditional validity constraints not satisfied",
3958 return -1);
3960 return 0;
3963 /* Input for testing of schedule construction based on
3964 * conditional constraints.
3966 * domain is the iteration domain
3967 * flow are the flow dependences, which determine the validity and
3968 * proximity constraints
3969 * condition are the conditions on the conditional validity constraints
3970 * conditional_validity are the conditional validity constraints
3971 * outer_band_n is the expected number of members in the outer band
3973 struct {
3974 const char *domain;
3975 const char *flow;
3976 const char *condition;
3977 const char *conditional_validity;
3978 int outer_band_n;
3979 } live_range_tests[] = {
3980 /* Contrived example that illustrates that we need to keep
3981 * track of tagged condition dependences and
3982 * tagged conditional validity dependences
3983 * in isl_sched_edge separately.
3984 * In particular, the conditional validity constraints on A
3985 * cannot be satisfied,
3986 * but they can be ignored because there are no corresponding
3987 * condition constraints. However, we do have an additional
3988 * conditional validity constraint that maps to the same
3989 * dependence relation
3990 * as the condition constraint on B. If we did not make a distinction
3991 * between tagged condition and tagged conditional validity
3992 * dependences, then we
3993 * could end up treating this shared dependence as an condition
3994 * constraint on A, forcing a localization of the conditions,
3995 * which is impossible.
3997 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
3998 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
3999 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
4000 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4001 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
4002 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
4005 /* TACO 2013 Fig. 7 */
4006 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4007 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4008 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4009 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
4010 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
4011 "0 <= i < n and 0 <= j < n - 1 }",
4012 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
4013 "0 <= i < n and 0 <= j < j' < n;"
4014 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
4015 "0 <= i < i' < n and 0 <= j,j' < n;"
4016 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
4017 "0 <= i,j,j' < n and j < j' }",
4020 /* TACO 2013 Fig. 7, without tags */
4021 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
4022 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4023 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4024 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
4025 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
4026 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
4027 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
4028 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
4031 /* TACO 2013 Fig. 12 */
4032 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
4033 "S3[i,3] : 0 <= i <= 1 }",
4034 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
4035 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
4036 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
4037 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
4038 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4039 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
4040 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
4041 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
4042 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
4043 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
4044 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
4049 /* Test schedule construction based on conditional constraints.
4050 * In particular, check the number of members in the outer band node
4051 * as an indication of whether tiling is possible or not.
4053 static int test_conditional_schedule_constraints(isl_ctx *ctx)
4055 int i;
4056 isl_union_set *domain;
4057 isl_union_map *condition;
4058 isl_union_map *flow;
4059 isl_union_map *validity;
4060 isl_schedule_constraints *sc;
4061 isl_schedule *schedule;
4062 isl_schedule_node *node;
4063 int n_member;
4065 if (test_special_conditional_schedule_constraints(ctx) < 0)
4066 return -1;
4067 if (test_special_conditional_schedule_constraints_2(ctx) < 0)
4068 return -1;
4070 for (i = 0; i < ARRAY_SIZE(live_range_tests); ++i) {
4071 domain = isl_union_set_read_from_str(ctx,
4072 live_range_tests[i].domain);
4073 flow = isl_union_map_read_from_str(ctx,
4074 live_range_tests[i].flow);
4075 condition = isl_union_map_read_from_str(ctx,
4076 live_range_tests[i].condition);
4077 validity = isl_union_map_read_from_str(ctx,
4078 live_range_tests[i].conditional_validity);
4079 sc = isl_schedule_constraints_on_domain(domain);
4080 sc = isl_schedule_constraints_set_validity(sc,
4081 isl_union_map_copy(flow));
4082 sc = isl_schedule_constraints_set_proximity(sc, flow);
4083 sc = isl_schedule_constraints_set_conditional_validity(sc,
4084 condition, validity);
4085 schedule = isl_schedule_constraints_compute_schedule(sc);
4086 node = isl_schedule_get_root(schedule);
4087 while (node &&
4088 isl_schedule_node_get_type(node) != isl_schedule_node_band)
4089 node = isl_schedule_node_first_child(node);
4090 n_member = isl_schedule_node_band_n_member(node);
4091 isl_schedule_node_free(node);
4092 isl_schedule_free(schedule);
4094 if (!schedule)
4095 return -1;
4096 if (n_member != live_range_tests[i].outer_band_n)
4097 isl_die(ctx, isl_error_unknown,
4098 "unexpected number of members in outer band",
4099 return -1);
4101 return 0;
4104 /* Check that the schedule computed for the given instance set and
4105 * dependence relation strongly satisfies the dependences.
4106 * In particular, check that no instance is scheduled before
4107 * or together with an instance on which it depends.
4108 * Earlier versions of isl would produce a schedule that
4109 * only weakly satisfies the dependences.
4111 static int test_strongly_satisfying_schedule(isl_ctx *ctx)
4113 const char *domain, *dep;
4114 isl_union_map *D, *schedule;
4115 isl_map *map, *ge;
4116 int empty;
4118 domain = "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
4119 "A[i0] : 0 <= i0 <= 1 }";
4120 dep = "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
4121 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
4122 schedule = compute_schedule(ctx, domain, dep, dep);
4123 D = isl_union_map_read_from_str(ctx, dep);
4124 D = isl_union_map_apply_domain(D, isl_union_map_copy(schedule));
4125 D = isl_union_map_apply_range(D, schedule);
4126 map = isl_map_from_union_map(D);
4127 ge = isl_map_lex_ge(isl_space_domain(isl_map_get_space(map)));
4128 map = isl_map_intersect(map, ge);
4129 empty = isl_map_is_empty(map);
4130 isl_map_free(map);
4132 if (empty < 0)
4133 return -1;
4134 if (!empty)
4135 isl_die(ctx, isl_error_unknown,
4136 "dependences not strongly satisfied", return -1);
4138 return 0;
4141 /* Compute a schedule for input where the instance set constraints
4142 * conflict with the context constraints.
4143 * Earlier versions of isl did not properly handle this situation.
4145 static int test_conflicting_context_schedule(isl_ctx *ctx)
4147 isl_union_map *schedule;
4148 const char *domain, *context;
4150 domain = "[n] -> { A[] : n >= 0 }";
4151 context = "[n] -> { : n < 0 }";
4152 schedule = compute_schedule_with_context(ctx,
4153 domain, "{}", "{}", context);
4154 isl_union_map_free(schedule);
4156 if (!schedule)
4157 return -1;
4159 return 0;
4162 /* Check that the dependence carrying step is not confused by
4163 * a bound on the coefficient size.
4164 * In particular, force the scheduler to move to a dependence carrying
4165 * step by demanding outer coincidence and bound the size of
4166 * the coefficients. Earlier versions of isl would take this
4167 * bound into account while carrying dependences, breaking
4168 * fundamental assumptions.
4169 * On the other hand, the dependence carrying step now tries
4170 * to prevent loop coalescing by default, so check that indeed
4171 * no loop coalescing occurs by comparing the computed schedule
4172 * to the expected non-coalescing schedule.
4174 static int test_bounded_coefficients_schedule(isl_ctx *ctx)
4176 const char *domain, *dep;
4177 isl_union_set *I;
4178 isl_union_map *D;
4179 isl_schedule_constraints *sc;
4180 isl_schedule *schedule;
4181 isl_union_map *sched1, *sched2;
4182 isl_bool equal;
4184 domain = "{ C[i0, i1] : 2 <= i0 <= 3999 and 0 <= i1 <= -1 + i0 }";
4185 dep = "{ C[i0, i1] -> C[i0, 1 + i1] : i0 <= 3999 and i1 >= 0 and "
4186 "i1 <= -2 + i0; "
4187 "C[i0, -1 + i0] -> C[1 + i0, 0] : i0 <= 3998 and i0 >= 1 }";
4188 I = isl_union_set_read_from_str(ctx, domain);
4189 D = isl_union_map_read_from_str(ctx, dep);
4190 sc = isl_schedule_constraints_on_domain(I);
4191 sc = isl_schedule_constraints_set_validity(sc, isl_union_map_copy(D));
4192 sc = isl_schedule_constraints_set_coincidence(sc, D);
4193 isl_options_set_schedule_outer_coincidence(ctx, 1);
4194 isl_options_set_schedule_max_coefficient(ctx, 20);
4195 schedule = isl_schedule_constraints_compute_schedule(sc);
4196 isl_options_set_schedule_max_coefficient(ctx, -1);
4197 isl_options_set_schedule_outer_coincidence(ctx, 0);
4198 sched1 = isl_schedule_get_map(schedule);
4199 isl_schedule_free(schedule);
4201 sched2 = isl_union_map_read_from_str(ctx, "{ C[x,y] -> [x,y] }");
4202 equal = isl_union_map_is_equal(sched1, sched2);
4203 isl_union_map_free(sched1);
4204 isl_union_map_free(sched2);
4206 if (equal < 0)
4207 return -1;
4208 if (!equal)
4209 isl_die(ctx, isl_error_unknown,
4210 "unexpected schedule", return -1);
4212 return 0;
4215 /* Check that the bounds on the coefficients are respected.
4216 * This function checks for a particular output schedule,
4217 * but the exact output is not important, only that it does
4218 * not contain any coefficients greater than 4.
4219 * It is, however, easier to check for a particular output.
4220 * This test is only run for the whole component scheduler
4221 * because the incremental scheduler produces a slightly different schedule.
4223 static int test_bounded_coefficients_schedule_whole(isl_ctx *ctx)
4225 const char *domain, *dep, *str;
4226 isl_union_set *I;
4227 isl_union_map *D;
4228 isl_schedule_constraints *sc;
4229 isl_schedule *schedule;
4230 isl_union_map *sched1, *sched2;
4231 isl_bool equal;
4233 domain = "{ S_4[i, j, k] : 0 <= i < j <= 10 and 0 <= k <= 100; "
4234 "S_2[i, j] : 0 <= i < j <= 10; S_6[i, j] : 0 <= i < j <= 10 }";
4235 dep = "{ S_2[0, j] -> S_4[0, j, 0] : 0 < j <= 10; "
4236 "S_4[0, j, 100] -> S_6[0, j] : 0 < j <= 10 }";
4237 I = isl_union_set_read_from_str(ctx, domain);
4238 D = isl_union_map_read_from_str(ctx, dep);
4239 sc = isl_schedule_constraints_on_domain(I);
4240 sc = isl_schedule_constraints_set_validity(sc, D);
4241 isl_options_set_schedule_max_constant_term(ctx, 10);
4242 isl_options_set_schedule_max_coefficient(ctx, 4);
4243 schedule = isl_schedule_constraints_compute_schedule(sc);
4244 isl_options_set_schedule_max_coefficient(ctx, -1);
4245 isl_options_set_schedule_max_constant_term(ctx, -1);
4246 sched1 = isl_schedule_get_map(schedule);
4247 isl_schedule_free(schedule);
4249 str = "{ S_4[i, j, k] -> [i, j, 10 - k]; "
4250 "S_2[i, j] -> [0, i, j]; S_6[i, j] -> [0, 10 + i, j] }";
4251 sched2 = isl_union_map_read_from_str(ctx, str);
4252 equal = isl_union_map_is_equal(sched1, sched2);
4253 isl_union_map_free(sched1);
4254 isl_union_map_free(sched2);
4256 if (equal < 0)
4257 return -1;
4258 if (!equal)
4259 isl_die(ctx, isl_error_unknown,
4260 "unexpected schedule", return -1);
4262 return 0;
4265 /* Check that a set of schedule constraints that only allow for
4266 * a coalescing schedule still produces a schedule even if the user
4267 * request a non-coalescing schedule. Earlier versions of isl
4268 * would not handle this case correctly.
4270 static int test_coalescing_schedule(isl_ctx *ctx)
4272 const char *domain, *dep;
4273 isl_union_set *I;
4274 isl_union_map *D;
4275 isl_schedule_constraints *sc;
4276 isl_schedule *schedule;
4277 int treat_coalescing;
4279 domain = "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4280 dep = "{ S[a, b] -> S[a + b, 1 - b] }";
4281 I = isl_union_set_read_from_str(ctx, domain);
4282 D = isl_union_map_read_from_str(ctx, dep);
4283 sc = isl_schedule_constraints_on_domain(I);
4284 sc = isl_schedule_constraints_set_validity(sc, D);
4285 treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx);
4286 isl_options_set_schedule_treat_coalescing(ctx, 1);
4287 schedule = isl_schedule_constraints_compute_schedule(sc);
4288 isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing);
4289 isl_schedule_free(schedule);
4290 if (!schedule)
4291 return -1;
4292 return 0;
4295 /* Check that the scheduler does not perform any needless
4296 * compound skewing. Earlier versions of isl would compute
4297 * schedules in terms of transformed schedule coefficients and
4298 * would not accurately keep track of the sum of the original
4299 * schedule coefficients. It could then produce the schedule
4300 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4301 * for the input below instead of the schedule below.
4303 static int test_skewing_schedule(isl_ctx *ctx)
4305 const char *D, *V, *P, *S;
4307 D = "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4308 V = "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4309 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4310 "-1 <= a-i + b-j + c-k <= 1 }";
4311 P = "{ }";
4312 S = "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4314 return test_special_schedule(ctx, D, V, P, S);
4317 int test_schedule(isl_ctx *ctx)
4319 const char *D, *W, *R, *V, *P, *S;
4320 int max_coincidence;
4321 int treat_coalescing;
4323 /* Handle resulting schedule with zero bands. */
4324 if (test_one_schedule(ctx, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4325 return -1;
4327 /* Jacobi */
4328 D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4329 W = "{ S1[t,i] -> a[t,i] }";
4330 R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4331 "S1[t,i] -> a[t-1,i+1] }";
4332 S = "{ S1[t,i] -> [t,i] }";
4333 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4334 return -1;
4336 /* Fig. 5 of CC2008 */
4337 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4338 "j <= -1 + N }";
4339 W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4340 "j >= 2 and j <= -1 + N }";
4341 R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4342 "j >= 2 and j <= -1 + N; "
4343 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4344 "j >= 2 and j <= -1 + N }";
4345 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4346 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4347 return -1;
4349 D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4350 W = "{ S1[i] -> a[i] }";
4351 R = "{ S2[i] -> a[i+1] }";
4352 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4353 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4354 return -1;
4356 D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4357 W = "{ S1[i] -> a[i] }";
4358 R = "{ S2[i] -> a[9-i] }";
4359 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4360 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4361 return -1;
4363 D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4364 W = "{ S1[i] -> a[i] }";
4365 R = "[N] -> { S2[i] -> a[N-1-i] }";
4366 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4367 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
4368 return -1;
4370 D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4371 W = "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4372 R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4373 S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4374 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4375 return -1;
4377 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4378 W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4379 R = "{ S2[i,j] -> a[i-1,j] }";
4380 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4381 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
4382 return -1;
4384 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4385 W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4386 R = "{ S2[i,j] -> a[i,j-1] }";
4387 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4388 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
4389 return -1;
4391 D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4392 W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4393 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4394 R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4395 S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4396 "S_0[] -> [0, 0, 0] }";
4397 if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0)
4398 return -1;
4399 ctx->opt->schedule_parametric = 0;
4400 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4401 return -1;
4402 ctx->opt->schedule_parametric = 1;
4404 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4405 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4406 W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4407 R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4408 "S4[i] -> a[i,N] }";
4409 S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4410 "S4[i] -> [4,i,0] }";
4411 max_coincidence = isl_options_get_schedule_maximize_coincidence(ctx);
4412 isl_options_set_schedule_maximize_coincidence(ctx, 0);
4413 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
4414 return -1;
4415 isl_options_set_schedule_maximize_coincidence(ctx, max_coincidence);
4417 D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4418 W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4419 "j <= N }";
4420 R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4421 "j <= N; "
4422 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4423 "j <= N }";
4424 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4425 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4426 return -1;
4428 D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4429 " S_2[t] : t >= 0 and t <= -1 + N; "
4430 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4431 "i <= -1 + N }";
4432 W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4433 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4434 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4435 "i >= 0 and i <= -1 + N }";
4436 R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4437 "i >= 0 and i <= -1 + N; "
4438 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4439 S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4440 " S_0[t] -> [0, t, 0] }";
4442 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
4443 return -1;
4444 ctx->opt->schedule_parametric = 0;
4445 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4446 return -1;
4447 ctx->opt->schedule_parametric = 1;
4449 D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4450 S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4451 if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0)
4452 return -1;
4454 D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4455 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4456 W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4457 "j >= 0 and j <= -1 + N; "
4458 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4459 R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4460 "j >= 0 and j <= -1 + N; "
4461 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4462 S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4463 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4464 return -1;
4466 D = "{ S_0[i] : i >= 0 }";
4467 W = "{ S_0[i] -> a[i] : i >= 0 }";
4468 R = "{ S_0[i] -> a[0] : i >= 0 }";
4469 S = "{ S_0[i] -> [0, i, 0] }";
4470 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4471 return -1;
4473 D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
4474 W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
4475 R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
4476 S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
4477 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4478 return -1;
4480 D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
4481 "k <= -1 + n and k >= 0 }";
4482 W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
4483 R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
4484 "k <= -1 + n and k >= 0; "
4485 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
4486 "k <= -1 + n and k >= 0; "
4487 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
4488 "k <= -1 + n and k >= 0 }";
4489 S = "[n] -> { S_0[j, k] -> [2, j, k] }";
4490 ctx->opt->schedule_outer_coincidence = 1;
4491 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
4492 return -1;
4493 ctx->opt->schedule_outer_coincidence = 0;
4495 D = "{Stmt_for_body24[i0, i1, i2, i3]:"
4496 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
4497 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
4498 "Stmt_for_body24[i0, i1, 1, 0]:"
4499 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
4500 "Stmt_for_body7[i0, i1, i2]:"
4501 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
4502 "i2 <= 7 }";
4504 V = "{Stmt_for_body24[0, i1, i2, i3] -> "
4505 "Stmt_for_body24[1, i1, i2, i3]:"
4506 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
4507 "i2 >= 1;"
4508 "Stmt_for_body24[0, i1, i2, i3] -> "
4509 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
4510 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
4511 "i3 >= 0;"
4512 "Stmt_for_body24[0, i1, i2, i3] ->"
4513 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
4514 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
4515 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
4516 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
4517 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
4518 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
4519 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
4520 "i1 <= 6 and i1 >= 0;"
4521 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
4522 "Stmt_for_body7[i0, i1, i2] -> "
4523 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
4524 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
4525 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
4526 "Stmt_for_body7[i0, i1, i2] -> "
4527 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
4528 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
4529 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
4530 P = V;
4532 treat_coalescing = isl_options_get_schedule_treat_coalescing(ctx);
4533 isl_options_set_schedule_treat_coalescing(ctx, 0);
4534 if (test_has_schedule(ctx, D, V, P) < 0)
4535 return -1;
4536 isl_options_set_schedule_treat_coalescing(ctx, treat_coalescing);
4538 D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
4539 V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
4540 "j >= 1 and j <= 7;"
4541 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
4542 "j >= 1 and j <= 8 }";
4543 P = "{ }";
4544 S = "{ S_0[i, j] -> [i + j, i] }";
4545 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
4546 if (test_special_schedule(ctx, D, V, P, S) < 0)
4547 return -1;
4548 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
4550 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
4551 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
4552 "j >= 0 and j <= -1 + i }";
4553 V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
4554 "i <= -1 + N and j >= 0;"
4555 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
4556 "i <= -2 + N }";
4557 P = "{ }";
4558 S = "{ S_0[i, j] -> [i, j] }";
4559 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
4560 if (test_special_schedule(ctx, D, V, P, S) < 0)
4561 return -1;
4562 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
4564 /* Test both algorithms on a case with only proximity dependences. */
4565 D = "{ S[i,j] : 0 <= i <= 10 }";
4566 V = "{ }";
4567 P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
4568 S = "{ S[i, j] -> [j, i] }";
4569 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
4570 if (test_special_schedule(ctx, D, V, P, S) < 0)
4571 return -1;
4572 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
4573 if (test_special_schedule(ctx, D, V, P, S) < 0)
4574 return -1;
4576 D = "{ A[a]; B[] }";
4577 V = "{}";
4578 P = "{ A[a] -> B[] }";
4579 if (test_has_schedule(ctx, D, V, P) < 0)
4580 return -1;
4582 if (test_padded_schedule(ctx) < 0)
4583 return -1;
4585 /* Check that check for progress is not confused by rational
4586 * solution.
4588 D = "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
4589 V = "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
4590 "i0 <= -2 + N; "
4591 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
4592 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
4593 P = "{}";
4594 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
4595 if (test_has_schedule(ctx, D, V, P) < 0)
4596 return -1;
4597 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
4599 /* Check that we allow schedule rows that are only non-trivial
4600 * on some full-dimensional domains.
4602 D = "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
4603 V = "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
4604 "S1[j] -> S2[1] : 0 <= j <= 1 }";
4605 P = "{}";
4606 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
4607 if (test_has_schedule(ctx, D, V, P) < 0)
4608 return -1;
4609 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
4611 if (test_conditional_schedule_constraints(ctx) < 0)
4612 return -1;
4614 if (test_strongly_satisfying_schedule(ctx) < 0)
4615 return -1;
4617 if (test_conflicting_context_schedule(ctx) < 0)
4618 return -1;
4620 if (test_bounded_coefficients_schedule(ctx) < 0)
4621 return -1;
4622 if (test_coalescing_schedule(ctx) < 0)
4623 return -1;
4624 if (test_skewing_schedule(ctx) < 0)
4625 return -1;
4627 return 0;
4630 /* Perform scheduling tests using the whole component scheduler.
4632 static int test_schedule_whole(isl_ctx *ctx)
4634 int whole;
4635 int r;
4637 whole = isl_options_get_schedule_whole_component(ctx);
4638 isl_options_set_schedule_whole_component(ctx, 1);
4639 r = test_schedule(ctx);
4640 if (r >= 0)
4641 r = test_bounded_coefficients_schedule_whole(ctx);
4642 isl_options_set_schedule_whole_component(ctx, whole);
4644 return r;
4647 /* Perform scheduling tests using the incremental scheduler.
4649 static int test_schedule_incremental(isl_ctx *ctx)
4651 int whole;
4652 int r;
4654 whole = isl_options_get_schedule_whole_component(ctx);
4655 isl_options_set_schedule_whole_component(ctx, 0);
4656 r = test_schedule(ctx);
4657 isl_options_set_schedule_whole_component(ctx, whole);
4659 return r;
4662 int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
4664 isl_union_map *umap;
4665 int test;
4667 umap = isl_union_map_read_from_str(ctx, str);
4668 test = isl_union_map_plain_is_injective(umap);
4669 isl_union_map_free(umap);
4670 if (test < 0)
4671 return -1;
4672 if (test == injective)
4673 return 0;
4674 if (injective)
4675 isl_die(ctx, isl_error_unknown,
4676 "map not detected as injective", return -1);
4677 else
4678 isl_die(ctx, isl_error_unknown,
4679 "map detected as injective", return -1);
4682 int test_injective(isl_ctx *ctx)
4684 const char *str;
4686 if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
4687 return -1;
4688 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
4689 return -1;
4690 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
4691 return -1;
4692 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
4693 return -1;
4694 if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
4695 return -1;
4696 if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
4697 return -1;
4698 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
4699 return -1;
4700 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
4701 return -1;
4703 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
4704 if (test_plain_injective(ctx, str, 1))
4705 return -1;
4706 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
4707 if (test_plain_injective(ctx, str, 0))
4708 return -1;
4710 return 0;
4713 static int aff_plain_is_equal(__isl_keep isl_aff *aff, const char *str)
4715 isl_aff *aff2;
4716 int equal;
4718 if (!aff)
4719 return -1;
4721 aff2 = isl_aff_read_from_str(isl_aff_get_ctx(aff), str);
4722 equal = isl_aff_plain_is_equal(aff, aff2);
4723 isl_aff_free(aff2);
4725 return equal;
4728 static int aff_check_plain_equal(__isl_keep isl_aff *aff, const char *str)
4730 int equal;
4732 equal = aff_plain_is_equal(aff, str);
4733 if (equal < 0)
4734 return -1;
4735 if (!equal)
4736 isl_die(isl_aff_get_ctx(aff), isl_error_unknown,
4737 "result not as expected", return -1);
4738 return 0;
4741 /* Is "upa" obviously equal to the isl_union_pw_aff represented by "str"?
4743 static isl_bool union_pw_aff_plain_is_equal(__isl_keep isl_union_pw_aff *upa,
4744 const char *str)
4746 isl_ctx *ctx;
4747 isl_union_pw_aff *upa2;
4748 isl_bool equal;
4750 if (!upa)
4751 return isl_bool_error;
4753 ctx = isl_union_pw_aff_get_ctx(upa);
4754 upa2 = isl_union_pw_aff_read_from_str(ctx, str);
4755 equal = isl_union_pw_aff_plain_is_equal(upa, upa2);
4756 isl_union_pw_aff_free(upa2);
4758 return equal;
4761 /* Check that "upa" is obviously equal to the isl_union_pw_aff
4762 * represented by "str".
4764 static isl_stat union_pw_aff_check_plain_equal(__isl_keep isl_union_pw_aff *upa,
4765 const char *str)
4767 isl_bool equal;
4769 equal = union_pw_aff_plain_is_equal(upa, str);
4770 if (equal < 0)
4771 return isl_stat_error;
4772 if (!equal)
4773 isl_die(isl_union_pw_aff_get_ctx(upa), isl_error_unknown,
4774 "result not as expected", return isl_stat_error);
4775 return isl_stat_ok;
4778 /* Basic tests on isl_union_pw_aff.
4780 * In particular, check that isl_union_pw_aff_aff_on_domain
4781 * aligns the parameters of the input objects and
4782 * that isl_union_pw_aff_param_on_domain_id properly
4783 * introduces the parameter.
4785 static int test_upa(isl_ctx *ctx)
4787 const char *str;
4788 isl_id *id;
4789 isl_aff *aff;
4790 isl_union_set *domain;
4791 isl_union_pw_aff *upa;
4792 isl_stat ok;
4794 aff = isl_aff_read_from_str(ctx, "[N] -> { [N] }");
4795 str = "[M] -> { A[i] : 0 <= i < M; B[] }";
4796 domain = isl_union_set_read_from_str(ctx, str);
4797 upa = isl_union_pw_aff_aff_on_domain(domain, aff);
4798 str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
4799 ok = union_pw_aff_check_plain_equal(upa, str);
4800 isl_union_pw_aff_free(upa);
4801 if (ok < 0)
4802 return -1;
4804 id = isl_id_alloc(ctx, "N", NULL);
4805 str = "[M] -> { A[i] : 0 <= i < M; B[] }";
4806 domain = isl_union_set_read_from_str(ctx, str);
4807 upa = isl_union_pw_aff_param_on_domain_id(domain, id);
4808 str = "[N, M] -> { A[i] -> [N] : 0 <= i < M; B[] -> [N] }";
4809 ok = union_pw_aff_check_plain_equal(upa, str);
4810 isl_union_pw_aff_free(upa);
4811 if (ok < 0)
4812 return -1;
4814 return 0;
4817 struct {
4818 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
4819 __isl_take isl_aff *aff2);
4820 } aff_bin_op[] = {
4821 ['+'] = { &isl_aff_add },
4822 ['-'] = { &isl_aff_sub },
4823 ['*'] = { &isl_aff_mul },
4824 ['/'] = { &isl_aff_div },
4827 struct {
4828 const char *arg1;
4829 unsigned char op;
4830 const char *arg2;
4831 const char *res;
4832 } aff_bin_tests[] = {
4833 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
4834 "{ [i] -> [2i] }" },
4835 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
4836 "{ [i] -> [0] }" },
4837 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
4838 "{ [i] -> [2i] }" },
4839 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
4840 "{ [i] -> [2i] }" },
4841 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
4842 "{ [i] -> [i/2] }" },
4843 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
4844 "{ [i] -> [i] }" },
4845 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
4846 "{ [i] -> [NaN] }" },
4847 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
4848 "{ [i] -> [NaN] }" },
4849 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
4850 "{ [i] -> [NaN] }" },
4851 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
4852 "{ [i] -> [NaN] }" },
4853 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
4854 "{ [i] -> [NaN] }" },
4855 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
4856 "{ [i] -> [NaN] }" },
4857 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
4858 "{ [i] -> [NaN] }" },
4859 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
4860 "{ [i] -> [NaN] }" },
4861 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
4862 "{ [i] -> [NaN] }" },
4863 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
4864 "{ [i] -> [NaN] }" },
4865 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
4866 "{ [i] -> [NaN] }" },
4867 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
4868 "{ [i] -> [NaN] }" },
4871 /* Perform some basic tests of binary operations on isl_aff objects.
4873 static int test_bin_aff(isl_ctx *ctx)
4875 int i;
4876 isl_aff *aff1, *aff2, *res;
4877 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
4878 __isl_take isl_aff *aff2);
4879 int ok;
4881 for (i = 0; i < ARRAY_SIZE(aff_bin_tests); ++i) {
4882 aff1 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg1);
4883 aff2 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg2);
4884 res = isl_aff_read_from_str(ctx, aff_bin_tests[i].res);
4885 fn = aff_bin_op[aff_bin_tests[i].op].fn;
4886 aff1 = fn(aff1, aff2);
4887 if (isl_aff_is_nan(res))
4888 ok = isl_aff_is_nan(aff1);
4889 else
4890 ok = isl_aff_plain_is_equal(aff1, res);
4891 isl_aff_free(aff1);
4892 isl_aff_free(res);
4893 if (ok < 0)
4894 return -1;
4895 if (!ok)
4896 isl_die(ctx, isl_error_unknown,
4897 "unexpected result", return -1);
4900 return 0;
4903 struct {
4904 __isl_give isl_pw_aff *(*fn)(__isl_take isl_pw_aff *pa1,
4905 __isl_take isl_pw_aff *pa2);
4906 } pw_aff_bin_op[] = {
4907 ['m'] = { &isl_pw_aff_min },
4908 ['M'] = { &isl_pw_aff_max },
4911 /* Inputs for binary isl_pw_aff operation tests.
4912 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
4913 * defined by pw_aff_bin_op, and "res" is the expected result.
4915 struct {
4916 const char *arg1;
4917 unsigned char op;
4918 const char *arg2;
4919 const char *res;
4920 } pw_aff_bin_tests[] = {
4921 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
4922 "{ [i] -> [i] }" },
4923 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
4924 "{ [i] -> [i] }" },
4925 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
4926 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
4927 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
4928 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
4929 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
4930 "{ [i] -> [NaN] }" },
4931 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
4932 "{ [i] -> [NaN] }" },
4935 /* Perform some basic tests of binary operations on isl_pw_aff objects.
4937 static int test_bin_pw_aff(isl_ctx *ctx)
4939 int i;
4940 isl_bool ok;
4941 isl_pw_aff *pa1, *pa2, *res;
4943 for (i = 0; i < ARRAY_SIZE(pw_aff_bin_tests); ++i) {
4944 pa1 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg1);
4945 pa2 = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].arg2);
4946 res = isl_pw_aff_read_from_str(ctx, pw_aff_bin_tests[i].res);
4947 pa1 = pw_aff_bin_op[pw_aff_bin_tests[i].op].fn(pa1, pa2);
4948 if (isl_pw_aff_involves_nan(res))
4949 ok = isl_pw_aff_involves_nan(pa1);
4950 else
4951 ok = isl_pw_aff_plain_is_equal(pa1, res);
4952 isl_pw_aff_free(pa1);
4953 isl_pw_aff_free(res);
4954 if (ok < 0)
4955 return -1;
4956 if (!ok)
4957 isl_die(ctx, isl_error_unknown,
4958 "unexpected result", return -1);
4961 return 0;
4964 struct {
4965 __isl_give isl_union_pw_multi_aff *(*fn)(
4966 __isl_take isl_union_pw_multi_aff *upma1,
4967 __isl_take isl_union_pw_multi_aff *upma2);
4968 const char *arg1;
4969 const char *arg2;
4970 const char *res;
4971 } upma_bin_tests[] = {
4972 { &isl_union_pw_multi_aff_add, "{ A[] -> [0]; B[0] -> [1] }",
4973 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
4974 { &isl_union_pw_multi_aff_union_add, "{ A[] -> [0]; B[0] -> [1] }",
4975 "{ B[x] -> [2] : x >= 0 }",
4976 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
4977 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff,
4978 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
4979 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
4980 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
4981 "D[i] -> B[2] : i >= 5 }" },
4982 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
4983 "{ B[x] -> C[2] : x > 0 }",
4984 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
4985 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
4986 "{ B[x] -> A[2] : x >= 0 }",
4987 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
4990 /* Perform some basic tests of binary operations on
4991 * isl_union_pw_multi_aff objects.
4993 static int test_bin_upma(isl_ctx *ctx)
4995 int i;
4996 isl_union_pw_multi_aff *upma1, *upma2, *res;
4997 int ok;
4999 for (i = 0; i < ARRAY_SIZE(upma_bin_tests); ++i) {
5000 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
5001 upma_bin_tests[i].arg1);
5002 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
5003 upma_bin_tests[i].arg2);
5004 res = isl_union_pw_multi_aff_read_from_str(ctx,
5005 upma_bin_tests[i].res);
5006 upma1 = upma_bin_tests[i].fn(upma1, upma2);
5007 ok = isl_union_pw_multi_aff_plain_is_equal(upma1, res);
5008 isl_union_pw_multi_aff_free(upma1);
5009 isl_union_pw_multi_aff_free(res);
5010 if (ok < 0)
5011 return -1;
5012 if (!ok)
5013 isl_die(ctx, isl_error_unknown,
5014 "unexpected result", return -1);
5017 return 0;
5020 struct {
5021 __isl_give isl_union_pw_multi_aff *(*fn)(
5022 __isl_take isl_union_pw_multi_aff *upma1,
5023 __isl_take isl_union_pw_multi_aff *upma2);
5024 const char *arg1;
5025 const char *arg2;
5026 } upma_bin_fail_tests[] = {
5027 { &isl_union_pw_multi_aff_union_add, "{ B[x] -> A[1] : x <= 0 }",
5028 "{ B[x] -> C[2] : x >= 0 }" },
5031 /* Perform some basic tests of binary operations on
5032 * isl_union_pw_multi_aff objects that are expected to fail.
5034 static int test_bin_upma_fail(isl_ctx *ctx)
5036 int i, n;
5037 isl_union_pw_multi_aff *upma1, *upma2;
5038 int on_error;
5040 on_error = isl_options_get_on_error(ctx);
5041 isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE);
5042 n = ARRAY_SIZE(upma_bin_fail_tests);
5043 for (i = 0; i < n; ++i) {
5044 upma1 = isl_union_pw_multi_aff_read_from_str(ctx,
5045 upma_bin_fail_tests[i].arg1);
5046 upma2 = isl_union_pw_multi_aff_read_from_str(ctx,
5047 upma_bin_fail_tests[i].arg2);
5048 upma1 = upma_bin_fail_tests[i].fn(upma1, upma2);
5049 isl_union_pw_multi_aff_free(upma1);
5050 if (upma1)
5051 break;
5053 isl_options_set_on_error(ctx, on_error);
5054 if (i < n)
5055 isl_die(ctx, isl_error_unknown,
5056 "operation not expected to succeed", return -1);
5058 return 0;
5061 /* Inputs for basic tests of unary operations on isl_multi_pw_aff objects.
5062 * "fn" is the function that is tested.
5063 * "arg" is a string description of the input.
5064 * "res" is a string description of the expected result.
5066 struct {
5067 __isl_give isl_multi_pw_aff *(*fn)(__isl_take isl_multi_pw_aff *mpa);
5068 const char *arg;
5069 const char *res;
5070 } mpa_un_tests[] = {
5071 { &isl_multi_pw_aff_range_factor_domain,
5072 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5073 "{ A[x] -> B[(1 : x >= 5)] }" },
5074 { &isl_multi_pw_aff_range_factor_range,
5075 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }",
5076 "{ A[y] -> C[(2 : y <= 10)] }" },
5077 { &isl_multi_pw_aff_range_factor_domain,
5078 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5079 "{ A[x] -> B[(1 : x >= 5)] }" },
5080 { &isl_multi_pw_aff_range_factor_range,
5081 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }",
5082 "{ A[y] -> C[] }" },
5083 { &isl_multi_pw_aff_range_factor_domain,
5084 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5085 "{ A[x] -> B[] }" },
5086 { &isl_multi_pw_aff_range_factor_range,
5087 "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }",
5088 "{ A[y] -> C[(2 : y <= 10)] }" },
5089 { &isl_multi_pw_aff_range_factor_domain,
5090 "{ A[x] -> [B[] -> C[]] }",
5091 "{ A[x] -> B[] }" },
5092 { &isl_multi_pw_aff_range_factor_range,
5093 "{ A[x] -> [B[] -> C[]] }",
5094 "{ A[y] -> C[] }" },
5095 { &isl_multi_pw_aff_factor_range,
5096 "{ [B[] -> C[]] }",
5097 "{ C[] }" },
5098 { &isl_multi_pw_aff_range_factor_domain,
5099 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5100 "{ A[x] -> B[] : x >= 0 }" },
5101 { &isl_multi_pw_aff_range_factor_range,
5102 "{ A[x] -> [B[] -> C[]] : x >= 0 }",
5103 "{ A[y] -> C[] : y >= 0 }" },
5104 { &isl_multi_pw_aff_factor_range,
5105 "[N] -> { [B[] -> C[]] : N >= 0 }",
5106 "[N] -> { C[] : N >= 0 }" },
5109 /* Perform some basic tests of unary operations on isl_multi_pw_aff objects.
5111 static int test_un_mpa(isl_ctx *ctx)
5113 int i;
5114 isl_bool ok;
5115 isl_multi_pw_aff *mpa, *res;
5117 for (i = 0; i < ARRAY_SIZE(mpa_un_tests); ++i) {
5118 mpa = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].arg);
5119 res = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].res);
5120 mpa = mpa_un_tests[i].fn(mpa);
5121 ok = isl_multi_pw_aff_plain_is_equal(mpa, res);
5122 isl_multi_pw_aff_free(mpa);
5123 isl_multi_pw_aff_free(res);
5124 if (ok < 0)
5125 return -1;
5126 if (!ok)
5127 isl_die(ctx, isl_error_unknown,
5128 "unexpected result", return -1);
5131 return 0;
5134 /* Inputs for basic tests of binary operations on isl_multi_pw_aff objects.
5135 * "fn" is the function that is tested.
5136 * "arg1" and "arg2" are string descriptions of the inputs.
5137 * "res" is a string description of the expected result.
5139 struct {
5140 __isl_give isl_multi_pw_aff *(*fn)(
5141 __isl_take isl_multi_pw_aff *mpa1,
5142 __isl_take isl_multi_pw_aff *mpa2);
5143 const char *arg1;
5144 const char *arg2;
5145 const char *res;
5146 } mpa_bin_tests[] = {
5147 { &isl_multi_pw_aff_add, "{ A[] -> [1] }", "{ A[] -> [2] }",
5148 "{ A[] -> [3] }" },
5149 { &isl_multi_pw_aff_add, "{ A[x] -> [(1 : x >= 5)] }",
5150 "{ A[x] -> [(x : x <= 10)] }",
5151 "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" },
5152 { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }",
5153 "{ A[x] -> [] : x <= 10 }",
5154 "{ A[x] -> [] : 5 <= x <= 10 }" },
5155 { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }",
5156 "[N] -> { A[x] -> [] : x <= N }",
5157 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5158 { &isl_multi_pw_aff_add,
5159 "[N] -> { A[x] -> [] : x <= N }",
5160 "{ A[x] -> [] : x >= 5 }",
5161 "[N] -> { A[x] -> [] : 5 <= x <= N }" },
5162 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }",
5163 "{ A[y] -> C[(2 : y <= 10)] }",
5164 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5165 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }",
5166 "{ A[y] -> C[2] : y <= 10 }",
5167 "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" },
5168 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }",
5169 "[N] -> { A[y] -> C[2] : y <= N }",
5170 "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" },
5171 { &isl_multi_pw_aff_range_product, "[N] -> { A[x] -> B[1] : x >= N }",
5172 "{ A[y] -> C[2] : y <= 10 }",
5173 "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" },
5174 { &isl_multi_pw_aff_range_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5175 "{ A[] -> [B[1] -> C[2]] }" },
5176 { &isl_multi_pw_aff_range_product, "{ A[] -> B[] }", "{ A[] -> C[] }",
5177 "{ A[] -> [B[] -> C[]] }" },
5178 { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }",
5179 "{ A[y] -> C[] : y <= 10 }",
5180 "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" },
5181 { &isl_multi_pw_aff_range_product, "{ A[y] -> C[] : y <= 10 }",
5182 "{ A[x] -> B[(1 : x >= 5)] }",
5183 "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" },
5184 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5185 "{ A[y] -> C[(2 : y <= 10)] }",
5186 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" },
5187 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5188 "{ A[y] -> C[] : y <= 10 }",
5189 "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" },
5190 { &isl_multi_pw_aff_product, "{ A[y] -> C[] : y <= 10 }",
5191 "{ A[x] -> B[(1 : x >= 5)] }",
5192 "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" },
5193 { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }",
5194 "[N] -> { A[y] -> C[] : y <= N }",
5195 "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" },
5196 { &isl_multi_pw_aff_product, "[N] -> { A[y] -> C[] : y <= N }",
5197 "{ A[x] -> B[(1 : x >= 5)] }",
5198 "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" },
5199 { &isl_multi_pw_aff_product, "{ A[x] -> B[] : x >= 5 }",
5200 "{ A[y] -> C[] : y <= 10 }",
5201 "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" },
5202 { &isl_multi_pw_aff_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }",
5203 "{ [A[] -> A[]] -> [B[1] -> C[2]] }" },
5204 { &isl_multi_pw_aff_product, "{ A[] -> B[] }", "{ A[] -> C[] }",
5205 "{ [A[] -> A[]] -> [B[] -> C[]] }" },
5206 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5207 "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }",
5208 "{ A[a,b] -> C[b + 2a] }" },
5209 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5210 "{ B[i,j] -> C[i + 2j] }",
5211 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5212 "{ A[a,b] -> C[(b + 2a : b > a)] }" },
5213 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5214 "{ B[i,j] -> C[(i + 2j : j > 4)] }",
5215 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5216 "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" },
5217 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5218 "{ B[i,j] -> C[] }",
5219 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5220 "{ A[a,b] -> C[] }" },
5221 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5222 "{ B[i,j] -> C[] : i > j }",
5223 "{ A[a,b] -> B[b,a] }",
5224 "{ A[a,b] -> C[] : b > a }" },
5225 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5226 "{ B[i,j] -> C[] : j > 5 }",
5227 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5228 "{ A[a,b] -> C[] : b > a > 5 }" },
5229 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5230 "[N] -> { B[i,j] -> C[] : j > N }",
5231 "{ A[a,b] -> B[(b : b > a),(a : b > a)] }",
5232 "[N] -> { A[a,b] -> C[] : b > a > N }" },
5233 { &isl_multi_pw_aff_pullback_multi_pw_aff,
5234 "[M,N] -> { B[] -> C[] : N > 5 }",
5235 "[M,N] -> { A[] -> B[] : M > N }",
5236 "[M,N] -> { A[] -> C[] : M > N > 5 }" },
5239 /* Perform some basic tests of binary operations on isl_multi_pw_aff objects.
5241 static int test_bin_mpa(isl_ctx *ctx)
5243 int i;
5244 isl_bool ok;
5245 isl_multi_pw_aff *mpa1, *mpa2, *res;
5247 for (i = 0; i < ARRAY_SIZE(mpa_bin_tests); ++i) {
5248 mpa1 = isl_multi_pw_aff_read_from_str(ctx,
5249 mpa_bin_tests[i].arg1);
5250 mpa2 = isl_multi_pw_aff_read_from_str(ctx,
5251 mpa_bin_tests[i].arg2);
5252 res = isl_multi_pw_aff_read_from_str(ctx,
5253 mpa_bin_tests[i].res);
5254 mpa1 = mpa_bin_tests[i].fn(mpa1, mpa2);
5255 ok = isl_multi_pw_aff_plain_is_equal(mpa1, res);
5256 isl_multi_pw_aff_free(mpa1);
5257 isl_multi_pw_aff_free(res);
5258 if (ok < 0)
5259 return -1;
5260 if (!ok)
5261 isl_die(ctx, isl_error_unknown,
5262 "unexpected result", return -1);
5265 return 0;
5268 /* Inputs for basic tests of unary operations on
5269 * isl_multi_union_pw_aff objects.
5270 * "fn" is the function that is tested.
5271 * "arg" is a string description of the input.
5272 * "res" is a string description of the expected result.
5274 struct {
5275 __isl_give isl_multi_union_pw_aff *(*fn)(
5276 __isl_take isl_multi_union_pw_aff *mupa);
5277 const char *arg;
5278 const char *res;
5279 } mupa_un_tests[] = {
5280 { &isl_multi_union_pw_aff_factor_range,
5281 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]",
5282 "C[{ A[] -> [2] }]" },
5283 { &isl_multi_union_pw_aff_factor_range,
5284 "[B[] -> C[{ A[] -> [2] }]]",
5285 "C[{ A[] -> [2] }]" },
5286 { &isl_multi_union_pw_aff_factor_range,
5287 "[B[{ A[] -> [1] }] -> C[]]",
5288 "C[]" },
5289 { &isl_multi_union_pw_aff_factor_range,
5290 "[B[] -> C[]]",
5291 "C[]" },
5292 { &isl_multi_union_pw_aff_factor_range,
5293 "([B[] -> C[]] : { A[x] : x >= 0 })",
5294 "(C[] : { A[x] : x >= 0 })" },
5295 { &isl_multi_union_pw_aff_factor_range,
5296 "[N] -> ([B[] -> C[]] : { A[x] : x <= N })",
5297 "[N] -> (C[] : { A[x] : x <= N })" },
5298 { &isl_multi_union_pw_aff_factor_range,
5299 "[N] -> ([B[] -> C[]] : { : N >= 0 })",
5300 "[N] -> (C[] : { : N >= 0 })" },
5303 /* Perform some basic tests of unary operations on
5304 * isl_multi_union_pw_aff objects.
5306 static int test_un_mupa(isl_ctx *ctx)
5308 int i;
5309 isl_bool ok;
5310 isl_multi_union_pw_aff *mupa, *res;
5312 for (i = 0; i < ARRAY_SIZE(mupa_un_tests); ++i) {
5313 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5314 mupa_un_tests[i].arg);
5315 res = isl_multi_union_pw_aff_read_from_str(ctx,
5316 mupa_un_tests[i].res);
5317 mupa = mupa_un_tests[i].fn(mupa);
5318 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
5319 isl_multi_union_pw_aff_free(mupa);
5320 isl_multi_union_pw_aff_free(res);
5321 if (ok < 0)
5322 return -1;
5323 if (!ok)
5324 isl_die(ctx, isl_error_unknown,
5325 "unexpected result", return -1);
5328 return 0;
5331 /* Inputs for basic tests of binary operations on
5332 * isl_multi_union_pw_aff objects.
5333 * "fn" is the function that is tested.
5334 * "arg1" and "arg2" are string descriptions of the inputs.
5335 * "res" is a string description of the expected result.
5337 struct {
5338 __isl_give isl_multi_union_pw_aff *(*fn)(
5339 __isl_take isl_multi_union_pw_aff *mupa1,
5340 __isl_take isl_multi_union_pw_aff *mupa2);
5341 const char *arg1;
5342 const char *arg2;
5343 const char *res;
5344 } mupa_bin_tests[] = {
5345 { &isl_multi_union_pw_aff_add, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5346 "[{ A[] -> [3] }]" },
5347 { &isl_multi_union_pw_aff_sub, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]",
5348 "[{ A[] -> [-1] }]" },
5349 { &isl_multi_union_pw_aff_add,
5350 "[{ A[] -> [1]; B[] -> [4] }]",
5351 "[{ A[] -> [2]; C[] -> [5] }]",
5352 "[{ A[] -> [3] }]" },
5353 { &isl_multi_union_pw_aff_union_add,
5354 "[{ A[] -> [1]; B[] -> [4] }]",
5355 "[{ A[] -> [2]; C[] -> [5] }]",
5356 "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" },
5357 { &isl_multi_union_pw_aff_add, "[{ A[x] -> [(1)] : x >= 5 }]",
5358 "[{ A[x] -> [(x)] : x <= 10 }]",
5359 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" },
5360 { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })",
5361 "([] : { A[x] : x <= 10 })",
5362 "([] : { A[x] : 5 <= x <= 10 })" },
5363 { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })",
5364 "[N] -> ([] : { A[x] : x <= N })",
5365 "[N] -> ([] : { A[x] : 5 <= x <= N })" },
5366 { &isl_multi_union_pw_aff_add, "[N] -> ([] : { A[x] : x >= N })",
5367 "([] : { A[x] : x <= 10 })",
5368 "[N] -> ([] : { A[x] : N <= x <= 10 })" },
5369 { &isl_multi_union_pw_aff_union_add, "[{ A[x] -> [(1)] : x >= 5 }]",
5370 "[{ A[x] -> [(x)] : x <= 10 }]",
5371 "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; "
5372 "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" },
5373 { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 5 })",
5374 "([] : { A[x] : x <= 10 })",
5375 "([] : { A[x] })" },
5376 { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 0 })",
5377 "[N] -> ([] : { A[x] : x >= N })",
5378 "[N] -> ([] : { A[x] : x >= 0 or x >= N })" },
5379 { &isl_multi_union_pw_aff_union_add,
5380 "[N] -> ([] : { A[] : N >= 0})",
5381 "[N] -> ([] : { A[] : N <= 0})",
5382 "[N] -> ([] : { A[] })" },
5383 { &isl_multi_union_pw_aff_union_add,
5384 "[N] -> ([] : { A[] })",
5385 "[N] -> ([] : { : })",
5386 "[N] -> ([] : { : })" },
5387 { &isl_multi_union_pw_aff_union_add,
5388 "[N] -> ([] : { : })",
5389 "[N] -> ([] : { A[] })",
5390 "[N] -> ([] : { : })" },
5391 { &isl_multi_union_pw_aff_union_add,
5392 "[N] -> ([] : { : N >= 0})",
5393 "[N] -> ([] : { : N <= 0})",
5394 "[N] -> ([] : { : })" },
5395 { &isl_multi_union_pw_aff_range_product,
5396 "B[{ A[] -> [1] }]",
5397 "C[{ A[] -> [2] }]",
5398 "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" },
5399 { &isl_multi_union_pw_aff_range_product,
5400 "(B[] : { A[x] : x >= 5 })",
5401 "(C[] : { A[x] : x <= 10 })",
5402 "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" },
5403 { &isl_multi_union_pw_aff_range_product,
5404 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5405 "(C[] : { A[x] : x <= 10 })",
5406 "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" },
5407 { &isl_multi_union_pw_aff_range_product,
5408 "(C[] : { A[x] : x <= 10 })",
5409 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5410 "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" },
5411 { &isl_multi_union_pw_aff_range_product,
5412 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5413 "[N] -> (C[] : { A[x] : x <= N })",
5414 "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" },
5415 { &isl_multi_union_pw_aff_range_product,
5416 "[N] -> (C[] : { A[x] : x <= N })",
5417 "B[{ A[x] -> [x + 1] : x >= 5 }]",
5418 "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" },
5419 { &isl_multi_union_pw_aff_range_product,
5420 "B[{ A[] -> [1]; D[] -> [3] }]",
5421 "C[{ A[] -> [2] }]",
5422 "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" },
5425 /* Perform some basic tests of binary operations on
5426 * isl_multi_union_pw_aff objects.
5428 static int test_bin_mupa(isl_ctx *ctx)
5430 int i;
5431 isl_bool ok;
5432 isl_multi_union_pw_aff *mupa1, *mupa2, *res;
5434 for (i = 0; i < ARRAY_SIZE(mupa_bin_tests); ++i) {
5435 mupa1 = isl_multi_union_pw_aff_read_from_str(ctx,
5436 mupa_bin_tests[i].arg1);
5437 mupa2 = isl_multi_union_pw_aff_read_from_str(ctx,
5438 mupa_bin_tests[i].arg2);
5439 res = isl_multi_union_pw_aff_read_from_str(ctx,
5440 mupa_bin_tests[i].res);
5441 mupa1 = mupa_bin_tests[i].fn(mupa1, mupa2);
5442 ok = isl_multi_union_pw_aff_plain_is_equal(mupa1, res);
5443 isl_multi_union_pw_aff_free(mupa1);
5444 isl_multi_union_pw_aff_free(res);
5445 if (ok < 0)
5446 return -1;
5447 if (!ok)
5448 isl_die(ctx, isl_error_unknown,
5449 "unexpected result", return -1);
5452 return 0;
5455 /* Inputs for basic tests of binary operations on
5456 * pairs of isl_multi_union_pw_aff and isl_set objects.
5457 * "fn" is the function that is tested.
5458 * "arg1" and "arg2" are string descriptions of the inputs.
5459 * "res" is a string description of the expected result.
5461 struct {
5462 __isl_give isl_multi_union_pw_aff *(*fn)(
5463 __isl_take isl_multi_union_pw_aff *mupa,
5464 __isl_take isl_set *set);
5465 const char *arg1;
5466 const char *arg2;
5467 const char *res;
5468 } mupa_set_tests[] = {
5469 { &isl_multi_union_pw_aff_intersect_range,
5470 "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }",
5471 "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" },
5472 { &isl_multi_union_pw_aff_intersect_range,
5473 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }",
5474 "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" },
5475 { &isl_multi_union_pw_aff_intersect_range,
5476 "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }",
5477 "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" },
5478 { &isl_multi_union_pw_aff_intersect_range,
5479 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }",
5480 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" },
5481 { &isl_multi_union_pw_aff_intersect_range,
5482 "C[]", "{ C[] }", "C[]" },
5483 { &isl_multi_union_pw_aff_intersect_range,
5484 "[N] -> (C[] : { : N >= 0 })",
5485 "{ C[] }",
5486 "[N] -> (C[] : { : N >= 0 })" },
5487 { &isl_multi_union_pw_aff_intersect_range,
5488 "(C[] : { A[a,b] })",
5489 "{ C[] }",
5490 "(C[] : { A[a,b] })" },
5491 { &isl_multi_union_pw_aff_intersect_range,
5492 "[N] -> (C[] : { A[a,b] : a,b <= N })",
5493 "{ C[] }",
5494 "[N] -> (C[] : { A[a,b] : a,b <= N })" },
5495 { &isl_multi_union_pw_aff_intersect_range,
5496 "C[]",
5497 "[N] -> { C[] : N >= 0 }",
5498 "[N] -> (C[] : { : N >= 0 })" },
5499 { &isl_multi_union_pw_aff_intersect_range,
5500 "(C[] : { A[a,b] })",
5501 "[N] -> { C[] : N >= 0 }",
5502 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5503 { &isl_multi_union_pw_aff_intersect_range,
5504 "[N] -> (C[] : { : N >= 0 })",
5505 "[N] -> { C[] : N < 1024 }",
5506 "[N] -> (C[] : { : 0 <= N < 1024 })" },
5507 { &isl_multi_union_pw_aff_intersect_params,
5508 "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }",
5509 "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" },
5510 { &isl_multi_union_pw_aff_intersect_params,
5511 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }",
5512 "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" },
5513 { &isl_multi_union_pw_aff_intersect_params,
5514 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }",
5515 "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" },
5516 { &isl_multi_union_pw_aff_intersect_params,
5517 "C[]", "[N] -> { : N >= 0 }",
5518 "[N] -> (C[] : { : N >= 0 })" },
5519 { &isl_multi_union_pw_aff_intersect_params,
5520 "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }",
5521 "[N] -> (C[] : { A[a,b] : N >= 0 })" },
5522 { &isl_multi_union_pw_aff_intersect_params,
5523 "[N] -> (C[] : { A[a,N] })", "{ : }",
5524 "[N] -> (C[] : { A[a,N] })" },
5525 { &isl_multi_union_pw_aff_intersect_params,
5526 "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }",
5527 "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" },
5530 /* Perform some basic tests of binary operations on
5531 * pairs of isl_multi_union_pw_aff and isl_set objects.
5533 static int test_mupa_set(isl_ctx *ctx)
5535 int i;
5536 isl_bool ok;
5537 isl_multi_union_pw_aff *mupa, *res;
5538 isl_set *set;
5540 for (i = 0; i < ARRAY_SIZE(mupa_set_tests); ++i) {
5541 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5542 mupa_set_tests[i].arg1);
5543 set = isl_set_read_from_str(ctx, mupa_set_tests[i].arg2);
5544 res = isl_multi_union_pw_aff_read_from_str(ctx,
5545 mupa_set_tests[i].res);
5546 mupa = mupa_set_tests[i].fn(mupa, set);
5547 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
5548 isl_multi_union_pw_aff_free(mupa);
5549 isl_multi_union_pw_aff_free(res);
5550 if (ok < 0)
5551 return -1;
5552 if (!ok)
5553 isl_die(ctx, isl_error_unknown,
5554 "unexpected result", return -1);
5557 return 0;
5560 /* Inputs for basic tests of binary operations on
5561 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5562 * "fn" is the function that is tested.
5563 * "arg1" and "arg2" are string descriptions of the inputs.
5564 * "res" is a string description of the expected result.
5566 struct {
5567 __isl_give isl_multi_union_pw_aff *(*fn)(
5568 __isl_take isl_multi_union_pw_aff *mupa,
5569 __isl_take isl_union_set *uset);
5570 const char *arg1;
5571 const char *arg2;
5572 const char *res;
5573 } mupa_uset_tests[] = {
5574 { &isl_multi_union_pw_aff_intersect_domain,
5575 "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }",
5576 "C[{ B[i,i] -> [3i] }]" },
5577 { &isl_multi_union_pw_aff_intersect_domain,
5578 "(C[] : { B[i,j] })", "{ B[i,i] }",
5579 "(C[] : { B[i,i] })" },
5580 { &isl_multi_union_pw_aff_intersect_domain,
5581 "(C[] : { B[i,j] })", "[N] -> { B[N,N] }",
5582 "[N] -> (C[] : { B[N,N] })" },
5583 { &isl_multi_union_pw_aff_intersect_domain,
5584 "C[]", "{ B[i,i] }",
5585 "(C[] : { B[i,i] })" },
5586 { &isl_multi_union_pw_aff_intersect_domain,
5587 "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }",
5588 "[N] -> (C[] : { B[i,i] : N >= 0 })" },
5591 /* Perform some basic tests of binary operations on
5592 * pairs of isl_multi_union_pw_aff and isl_union_set objects.
5594 static int test_mupa_uset(isl_ctx *ctx)
5596 int i;
5597 isl_bool ok;
5598 isl_multi_union_pw_aff *mupa, *res;
5599 isl_union_set *uset;
5601 for (i = 0; i < ARRAY_SIZE(mupa_uset_tests); ++i) {
5602 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5603 mupa_uset_tests[i].arg1);
5604 uset = isl_union_set_read_from_str(ctx,
5605 mupa_uset_tests[i].arg2);
5606 res = isl_multi_union_pw_aff_read_from_str(ctx,
5607 mupa_uset_tests[i].res);
5608 mupa = mupa_uset_tests[i].fn(mupa, uset);
5609 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
5610 isl_multi_union_pw_aff_free(mupa);
5611 isl_multi_union_pw_aff_free(res);
5612 if (ok < 0)
5613 return -1;
5614 if (!ok)
5615 isl_die(ctx, isl_error_unknown,
5616 "unexpected result", return -1);
5619 return 0;
5622 /* Inputs for basic tests of binary operations on
5623 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5624 * "fn" is the function that is tested.
5625 * "arg1" and "arg2" are string descriptions of the inputs.
5626 * "res" is a string description of the expected result.
5628 struct {
5629 __isl_give isl_multi_union_pw_aff *(*fn)(
5630 __isl_take isl_multi_union_pw_aff *mupa,
5631 __isl_take isl_multi_aff *ma);
5632 const char *arg1;
5633 const char *arg2;
5634 const char *res;
5635 } mupa_ma_tests[] = {
5636 { &isl_multi_union_pw_aff_apply_multi_aff,
5637 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5638 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5639 "{ C[a,b] -> D[b,a] }",
5640 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
5641 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
5642 { &isl_multi_union_pw_aff_apply_multi_aff,
5643 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
5644 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5645 "{ C[a,b] -> D[b,a] }",
5646 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
5647 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
5648 { &isl_multi_union_pw_aff_apply_multi_aff,
5649 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5650 "[N] -> { C[a] -> D[a + N] }",
5651 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " },
5652 { &isl_multi_union_pw_aff_apply_multi_aff,
5653 "C[]",
5654 "{ C[] -> D[] }",
5655 "D[]" },
5656 { &isl_multi_union_pw_aff_apply_multi_aff,
5657 "[N] -> (C[] : { : N >= 0 })",
5658 "{ C[] -> D[] }",
5659 "[N] -> (D[] : { : N >= 0 })" },
5660 { &isl_multi_union_pw_aff_apply_multi_aff,
5661 "C[]",
5662 "[N] -> { C[] -> D[N] }",
5663 "[N] -> D[{ [N] }]" },
5664 { &isl_multi_union_pw_aff_apply_multi_aff,
5665 "(C[] : { A[i,j] : i >= j })",
5666 "{ C[] -> D[] }",
5667 "(D[] : { A[i,j] : i >= j })" },
5668 { &isl_multi_union_pw_aff_apply_multi_aff,
5669 "[N] -> (C[] : { A[i,j] : N >= 0 })",
5670 "{ C[] -> D[] }",
5671 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
5672 { &isl_multi_union_pw_aff_apply_multi_aff,
5673 "(C[] : { A[i,j] : i >= j })",
5674 "[N] -> { C[] -> D[N] }",
5675 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
5678 /* Perform some basic tests of binary operations on
5679 * pairs of isl_multi_union_pw_aff and isl_multi_aff objects.
5681 static int test_mupa_ma(isl_ctx *ctx)
5683 int i;
5684 isl_bool ok;
5685 isl_multi_union_pw_aff *mupa, *res;
5686 isl_multi_aff *ma;
5688 for (i = 0; i < ARRAY_SIZE(mupa_ma_tests); ++i) {
5689 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5690 mupa_ma_tests[i].arg1);
5691 ma = isl_multi_aff_read_from_str(ctx, mupa_ma_tests[i].arg2);
5692 res = isl_multi_union_pw_aff_read_from_str(ctx,
5693 mupa_ma_tests[i].res);
5694 mupa = mupa_ma_tests[i].fn(mupa, ma);
5695 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
5696 isl_multi_union_pw_aff_free(mupa);
5697 isl_multi_union_pw_aff_free(res);
5698 if (ok < 0)
5699 return -1;
5700 if (!ok)
5701 isl_die(ctx, isl_error_unknown,
5702 "unexpected result", return -1);
5705 return 0;
5708 /* Inputs for basic tests of binary operations on
5709 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
5710 * "fn" is the function that is tested.
5711 * "arg1" and "arg2" are string descriptions of the inputs.
5712 * "res" is a string description of the expected result.
5714 struct {
5715 __isl_give isl_union_pw_aff *(*fn)(
5716 __isl_take isl_multi_union_pw_aff *mupa,
5717 __isl_take isl_pw_aff *pa);
5718 const char *arg1;
5719 const char *arg2;
5720 const char *res;
5721 } mupa_pa_tests[] = {
5722 { &isl_multi_union_pw_aff_apply_pw_aff,
5723 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5724 "[N] -> { C[a] -> [a + N] }",
5725 "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" },
5726 { &isl_multi_union_pw_aff_apply_pw_aff,
5727 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5728 "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }",
5729 "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
5730 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" },
5731 { &isl_multi_union_pw_aff_apply_pw_aff,
5732 "C[]",
5733 "[N] -> { C[] -> [N] }",
5734 "[N] -> { [N] }" },
5735 { &isl_multi_union_pw_aff_apply_pw_aff,
5736 "C[]",
5737 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5738 "[N] -> { [N] : N >= 0; [-N] : N < 0 }" },
5739 { &isl_multi_union_pw_aff_apply_pw_aff,
5740 "[N] -> (C[] : { : N >= 0 })",
5741 "[N] -> { C[] -> [N] }",
5742 "[N] -> { [N] : N >= 0 }" },
5743 { &isl_multi_union_pw_aff_apply_pw_aff,
5744 "[N] -> (C[] : { : N >= 0 })",
5745 "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }",
5746 "[N] -> { [N] : N >= 0 }" },
5747 { &isl_multi_union_pw_aff_apply_pw_aff,
5748 "[N] -> (C[] : { : N >= 0 })",
5749 "{ C[] -> [0] }",
5750 "[N] -> { [0] : N >= 0 }" },
5751 { &isl_multi_union_pw_aff_apply_pw_aff,
5752 "(C[] : { A[i,j] : i >= j })",
5753 "[N] -> { C[] -> [N] }",
5754 "[N] -> { A[i,j] -> [N] : i >= j }" },
5755 { &isl_multi_union_pw_aff_apply_pw_aff,
5756 "(C[] : { A[i,j] : i >= j })",
5757 "[N] -> { C[] -> [N] : N >= 0 }",
5758 "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" },
5761 /* Perform some basic tests of binary operations on
5762 * pairs of isl_multi_union_pw_aff and isl_pw_aff objects.
5764 static int test_mupa_pa(isl_ctx *ctx)
5766 int i;
5767 isl_bool ok;
5768 isl_multi_union_pw_aff *mupa;
5769 isl_union_pw_aff *upa, *res;
5770 isl_pw_aff *pa;
5772 for (i = 0; i < ARRAY_SIZE(mupa_pa_tests); ++i) {
5773 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5774 mupa_pa_tests[i].arg1);
5775 pa = isl_pw_aff_read_from_str(ctx, mupa_pa_tests[i].arg2);
5776 res = isl_union_pw_aff_read_from_str(ctx,
5777 mupa_pa_tests[i].res);
5778 upa = mupa_pa_tests[i].fn(mupa, pa);
5779 ok = isl_union_pw_aff_plain_is_equal(upa, res);
5780 isl_union_pw_aff_free(upa);
5781 isl_union_pw_aff_free(res);
5782 if (ok < 0)
5783 return -1;
5784 if (!ok)
5785 isl_die(ctx, isl_error_unknown,
5786 "unexpected result", return -1);
5789 return 0;
5792 /* Inputs for basic tests of binary operations on
5793 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
5794 * "fn" is the function that is tested.
5795 * "arg1" and "arg2" are string descriptions of the inputs.
5796 * "res" is a string description of the expected result.
5798 struct {
5799 __isl_give isl_multi_union_pw_aff *(*fn)(
5800 __isl_take isl_multi_union_pw_aff *mupa,
5801 __isl_take isl_pw_multi_aff *pma);
5802 const char *arg1;
5803 const char *arg2;
5804 const char *res;
5805 } mupa_pma_tests[] = {
5806 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5807 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5808 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5809 "{ C[a,b] -> D[b,a] }",
5810 "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, "
5811 "{ A[i,j] -> [i]; B[i,j] -> [j] }]" },
5812 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5813 "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, "
5814 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5815 "{ C[a,b] -> D[b,a] }",
5816 "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, "
5817 "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" },
5818 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5819 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5820 "[N] -> { C[a] -> D[a + N] }",
5821 "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" },
5822 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5823 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]",
5824 "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }",
5825 "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; "
5826 "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" },
5827 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5828 "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, "
5829 "{ A[i,j] -> [j]; B[i,j] -> [i] }]",
5830 "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }",
5831 "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; "
5832 "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, "
5833 "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; "
5834 "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" },
5835 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5836 "C[]",
5837 "{ C[] -> D[] }",
5838 "D[]" },
5839 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5840 "[N] -> (C[] : { : N >= 0 })",
5841 "{ C[] -> D[] }",
5842 "[N] -> (D[] : { : N >= 0 })" },
5843 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5844 "C[]",
5845 "[N] -> { C[] -> D[N] }",
5846 "[N] -> D[{ [N] }]" },
5847 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5848 "(C[] : { A[i,j] : i >= j })",
5849 "{ C[] -> D[] }",
5850 "(D[] : { A[i,j] : i >= j })" },
5851 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5852 "[N] -> (C[] : { A[i,j] : N >= 0 })",
5853 "{ C[] -> D[] }",
5854 "[N] -> (D[] : { A[i,j] : N >= 0 })" },
5855 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5856 "(C[] : { A[i,j] : i >= j })",
5857 "[N] -> { C[] -> D[N] }",
5858 "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" },
5859 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5860 "C[]",
5861 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
5862 "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" },
5863 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5864 "[N] -> (C[] : { : N >= 0 })",
5865 "[N] -> { C[] -> D[N] }",
5866 "[N] -> D[{ [N] : N >= 0 }]" },
5867 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5868 "[N] -> (C[] : { : N >= 0 })",
5869 "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }",
5870 "[N] -> D[{ [N] : N >= 0 }]" },
5871 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5872 "[N] -> (C[] : { : N >= 0 })",
5873 "{ C[] -> D[0] }",
5874 "[N] -> D[{ [0] : N >= 0 }]" },
5875 { &isl_multi_union_pw_aff_apply_pw_multi_aff,
5876 "(C[] : { A[i,j] : i >= j })",
5877 "[N] -> { C[] -> D[N] : N >= 0 }",
5878 "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" },
5881 /* Perform some basic tests of binary operations on
5882 * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects.
5884 static int test_mupa_pma(isl_ctx *ctx)
5886 int i;
5887 isl_bool ok;
5888 isl_multi_union_pw_aff *mupa, *res;
5889 isl_pw_multi_aff *pma;
5891 for (i = 0; i < ARRAY_SIZE(mupa_pma_tests); ++i) {
5892 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5893 mupa_pma_tests[i].arg1);
5894 pma = isl_pw_multi_aff_read_from_str(ctx,
5895 mupa_pma_tests[i].arg2);
5896 res = isl_multi_union_pw_aff_read_from_str(ctx,
5897 mupa_pma_tests[i].res);
5898 mupa = mupa_pma_tests[i].fn(mupa, pma);
5899 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
5900 isl_multi_union_pw_aff_free(mupa);
5901 isl_multi_union_pw_aff_free(res);
5902 if (ok < 0)
5903 return -1;
5904 if (!ok)
5905 isl_die(ctx, isl_error_unknown,
5906 "unexpected result", return -1);
5909 return 0;
5912 /* Inputs for basic tests of binary operations on
5913 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
5914 * "fn" is the function that is tested.
5915 * "arg1" and "arg2" are string descriptions of the inputs.
5916 * "res" is a string description of the expected result.
5918 struct {
5919 __isl_give isl_multi_union_pw_aff *(*fn)(
5920 __isl_take isl_multi_union_pw_aff *mupa,
5921 __isl_take isl_union_pw_multi_aff *upma);
5922 const char *arg1;
5923 const char *arg2;
5924 const char *res;
5925 } mupa_upma_tests[] = {
5926 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
5927 "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }",
5928 "C[{ A[a,b] -> [b + 2a] }]" },
5929 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
5930 "C[{ B[i,j] -> [i + 2j] }]",
5931 "{ A[a,b] -> B[b,a] : b > a }",
5932 "C[{ A[a,b] -> [b + 2a] : b > a }]" },
5933 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
5934 "C[{ B[i,j] -> [i + 2j] : j > 4 }]",
5935 "{ A[a,b] -> B[b,a] : b > a }",
5936 "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" },
5937 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
5938 "C[{ B[i,j] -> [i + 2j] }]",
5939 "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }",
5940 "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" },
5941 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
5942 "(C[] : { B[a,b] })",
5943 "{ A[a,b] -> B[b,a] }",
5944 "(C[] : { A[a,b] })" },
5945 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
5946 "(C[] : { B[a,b] })",
5947 "{ B[a,b] -> A[b,a] }",
5948 "(C[] : { })" },
5949 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
5950 "(C[] : { B[a,b] })",
5951 "{ A[a,b] -> B[b,a] : a > b }",
5952 "(C[] : { A[a,b] : a > b })" },
5953 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
5954 "(C[] : { B[a,b] : a > b })",
5955 "{ A[a,b] -> B[b,a] }",
5956 "(C[] : { A[a,b] : b > a })" },
5957 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
5958 "[N] -> (C[] : { B[a,b] : a > N })",
5959 "{ A[a,b] -> B[b,a] : a > b }",
5960 "[N] -> (C[] : { A[a,b] : a > b > N })" },
5961 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
5962 "(C[] : { B[a,b] : a > b })",
5963 "[N] -> { A[a,b] -> B[b,a] : a > N }",
5964 "[N] -> (C[] : { A[a,b] : b > a > N })" },
5965 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
5966 "C[]",
5967 "{ A[a,b] -> B[b,a] }",
5968 "C[]" },
5969 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
5970 "[N] -> (C[] : { : N >= 0 })",
5971 "{ A[a,b] -> B[b,a] }",
5972 "[N] -> (C[] : { : N >= 0 })" },
5973 { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff,
5974 "C[]",
5975 "[N] -> { A[a,b] -> B[b,a] : N >= 0 }",
5976 "[N] -> (C[] : { : N >= 0 })" },
5979 /* Perform some basic tests of binary operations on
5980 * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects.
5982 static int test_mupa_upma(isl_ctx *ctx)
5984 int i;
5985 isl_bool ok;
5986 isl_multi_union_pw_aff *mupa, *res;
5987 isl_union_pw_multi_aff *upma;
5989 for (i = 0; i < ARRAY_SIZE(mupa_upma_tests); ++i) {
5990 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
5991 mupa_upma_tests[i].arg1);
5992 upma = isl_union_pw_multi_aff_read_from_str(ctx,
5993 mupa_upma_tests[i].arg2);
5994 res = isl_multi_union_pw_aff_read_from_str(ctx,
5995 mupa_upma_tests[i].res);
5996 mupa = mupa_upma_tests[i].fn(mupa, upma);
5997 ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res);
5998 isl_multi_union_pw_aff_free(mupa);
5999 isl_multi_union_pw_aff_free(res);
6000 if (ok < 0)
6001 return -1;
6002 if (!ok)
6003 isl_die(ctx, isl_error_unknown,
6004 "unexpected result", return -1);
6007 return 0;
6010 int test_aff(isl_ctx *ctx)
6012 const char *str;
6013 isl_set *set;
6014 isl_space *space;
6015 isl_local_space *ls;
6016 isl_aff *aff;
6017 int zero, equal;
6019 if (test_upa(ctx) < 0)
6020 return -1;
6021 if (test_bin_aff(ctx) < 0)
6022 return -1;
6023 if (test_bin_pw_aff(ctx) < 0)
6024 return -1;
6025 if (test_bin_upma(ctx) < 0)
6026 return -1;
6027 if (test_bin_upma_fail(ctx) < 0)
6028 return -1;
6029 if (test_un_mpa(ctx) < 0)
6030 return -1;
6031 if (test_bin_mpa(ctx) < 0)
6032 return -1;
6033 if (test_un_mupa(ctx) < 0)
6034 return -1;
6035 if (test_bin_mupa(ctx) < 0)
6036 return -1;
6037 if (test_mupa_set(ctx) < 0)
6038 return -1;
6039 if (test_mupa_uset(ctx) < 0)
6040 return -1;
6041 if (test_mupa_ma(ctx) < 0)
6042 return -1;
6043 if (test_mupa_pa(ctx) < 0)
6044 return -1;
6045 if (test_mupa_pma(ctx) < 0)
6046 return -1;
6047 if (test_mupa_upma(ctx) < 0)
6048 return -1;
6050 space = isl_space_set_alloc(ctx, 0, 1);
6051 ls = isl_local_space_from_space(space);
6052 aff = isl_aff_zero_on_domain(ls);
6054 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6055 aff = isl_aff_scale_down_ui(aff, 3);
6056 aff = isl_aff_floor(aff);
6057 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6058 aff = isl_aff_scale_down_ui(aff, 2);
6059 aff = isl_aff_floor(aff);
6060 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
6062 str = "{ [10] }";
6063 set = isl_set_read_from_str(ctx, str);
6064 aff = isl_aff_gist(aff, set);
6066 aff = isl_aff_add_constant_si(aff, -16);
6067 zero = isl_aff_plain_is_zero(aff);
6068 isl_aff_free(aff);
6070 if (zero < 0)
6071 return -1;
6072 if (!zero)
6073 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6075 aff = isl_aff_read_from_str(ctx, "{ [-1] }");
6076 aff = isl_aff_scale_down_ui(aff, 64);
6077 aff = isl_aff_floor(aff);
6078 equal = aff_check_plain_equal(aff, "{ [-1] }");
6079 isl_aff_free(aff);
6080 if (equal < 0)
6081 return -1;
6083 return 0;
6086 /* Check that "pa" consists of a single expression.
6088 static int check_single_piece(isl_ctx *ctx, __isl_take isl_pw_aff *pa)
6090 int n;
6092 n = isl_pw_aff_n_piece(pa);
6093 isl_pw_aff_free(pa);
6095 if (!pa)
6096 return -1;
6097 if (n != 1)
6098 isl_die(ctx, isl_error_unknown, "expecting single expression",
6099 return -1);
6101 return 0;
6104 /* Check that the computation below results in a single expression.
6105 * One or two expressions may result depending on which constraint
6106 * ends up being considered as redundant with respect to the other
6107 * constraints after the projection that is performed internally
6108 * by isl_set_dim_min.
6110 static int test_dim_max_1(isl_ctx *ctx)
6112 const char *str;
6113 isl_set *set;
6114 isl_pw_aff *pa;
6116 str = "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
6117 "-4a <= b <= 3 and b < n - 4a }";
6118 set = isl_set_read_from_str(ctx, str);
6119 pa = isl_set_dim_min(set, 0);
6120 return check_single_piece(ctx, pa);
6123 /* Check that the computation below results in a single expression.
6124 * The PIP problem corresponding to these constraints has a row
6125 * that causes a split of the solution domain. The solver should
6126 * first pick rows that split off empty parts such that the actual
6127 * solution domain does not get split.
6128 * Note that the description contains some redundant constraints.
6129 * If these constraints get removed first, then the row mentioned
6130 * above does not appear in the PIP problem.
6132 static int test_dim_max_2(isl_ctx *ctx)
6134 const char *str;
6135 isl_set *set;
6136 isl_pw_aff *pa;
6138 str = "[P, N] -> { [a] : a < N and a >= 0 and N > P and a <= P and "
6139 "N > 0 and P >= 0 }";
6140 set = isl_set_read_from_str(ctx, str);
6141 pa = isl_set_dim_max(set, 0);
6142 return check_single_piece(ctx, pa);
6145 int test_dim_max(isl_ctx *ctx)
6147 int equal;
6148 const char *str;
6149 isl_set *set1, *set2;
6150 isl_set *set;
6151 isl_map *map;
6152 isl_pw_aff *pwaff;
6154 if (test_dim_max_1(ctx) < 0)
6155 return -1;
6156 if (test_dim_max_2(ctx) < 0)
6157 return -1;
6159 str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
6160 set = isl_set_read_from_str(ctx, str);
6161 pwaff = isl_set_dim_max(set, 0);
6162 set1 = isl_set_from_pw_aff(pwaff);
6163 str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
6164 set2 = isl_set_read_from_str(ctx, str);
6165 equal = isl_set_is_equal(set1, set2);
6166 isl_set_free(set1);
6167 isl_set_free(set2);
6168 if (equal < 0)
6169 return -1;
6170 if (!equal)
6171 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6173 str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
6174 set = isl_set_read_from_str(ctx, str);
6175 pwaff = isl_set_dim_max(set, 0);
6176 set1 = isl_set_from_pw_aff(pwaff);
6177 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6178 set2 = isl_set_read_from_str(ctx, str);
6179 equal = isl_set_is_equal(set1, set2);
6180 isl_set_free(set1);
6181 isl_set_free(set2);
6182 if (equal < 0)
6183 return -1;
6184 if (!equal)
6185 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6187 str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
6188 set = isl_set_read_from_str(ctx, str);
6189 pwaff = isl_set_dim_max(set, 0);
6190 set1 = isl_set_from_pw_aff(pwaff);
6191 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
6192 set2 = isl_set_read_from_str(ctx, str);
6193 equal = isl_set_is_equal(set1, set2);
6194 isl_set_free(set1);
6195 isl_set_free(set2);
6196 if (equal < 0)
6197 return -1;
6198 if (!equal)
6199 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6201 str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
6202 "0 <= i < N and 0 <= j < M }";
6203 map = isl_map_read_from_str(ctx, str);
6204 set = isl_map_range(map);
6206 pwaff = isl_set_dim_max(isl_set_copy(set), 0);
6207 set1 = isl_set_from_pw_aff(pwaff);
6208 str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
6209 set2 = isl_set_read_from_str(ctx, str);
6210 equal = isl_set_is_equal(set1, set2);
6211 isl_set_free(set1);
6212 isl_set_free(set2);
6214 pwaff = isl_set_dim_max(isl_set_copy(set), 3);
6215 set1 = isl_set_from_pw_aff(pwaff);
6216 str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
6217 set2 = isl_set_read_from_str(ctx, str);
6218 if (equal >= 0 && equal)
6219 equal = isl_set_is_equal(set1, set2);
6220 isl_set_free(set1);
6221 isl_set_free(set2);
6223 isl_set_free(set);
6225 if (equal < 0)
6226 return -1;
6227 if (!equal)
6228 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6230 /* Check that solutions are properly merged. */
6231 str = "[n] -> { [a, b, c] : c >= -4a - 2b and "
6232 "c <= -1 + n - 4a - 2b and c >= -2b and "
6233 "4a >= -4 + n and c >= 0 }";
6234 set = isl_set_read_from_str(ctx, str);
6235 pwaff = isl_set_dim_min(set, 2);
6236 set1 = isl_set_from_pw_aff(pwaff);
6237 str = "[n] -> { [(0)] : n >= 1 }";
6238 set2 = isl_set_read_from_str(ctx, str);
6239 equal = isl_set_is_equal(set1, set2);
6240 isl_set_free(set1);
6241 isl_set_free(set2);
6243 if (equal < 0)
6244 return -1;
6245 if (!equal)
6246 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6248 /* Check that empty solution lie in the right space. */
6249 str = "[n] -> { [t,a] : 1 = 0 }";
6250 set = isl_set_read_from_str(ctx, str);
6251 pwaff = isl_set_dim_max(set, 0);
6252 set1 = isl_set_from_pw_aff(pwaff);
6253 str = "[n] -> { [t] : 1 = 0 }";
6254 set2 = isl_set_read_from_str(ctx, str);
6255 equal = isl_set_is_equal(set1, set2);
6256 isl_set_free(set1);
6257 isl_set_free(set2);
6259 if (equal < 0)
6260 return -1;
6261 if (!equal)
6262 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6264 return 0;
6267 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
6269 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff *pma,
6270 const char *str)
6272 isl_ctx *ctx;
6273 isl_pw_multi_aff *pma2;
6274 int equal;
6276 if (!pma)
6277 return -1;
6279 ctx = isl_pw_multi_aff_get_ctx(pma);
6280 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
6281 equal = isl_pw_multi_aff_plain_is_equal(pma, pma2);
6282 isl_pw_multi_aff_free(pma2);
6284 return equal;
6287 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
6288 * represented by "str".
6290 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff *pma,
6291 const char *str)
6293 int equal;
6295 equal = pw_multi_aff_plain_is_equal(pma, str);
6296 if (equal < 0)
6297 return -1;
6298 if (!equal)
6299 isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_unknown,
6300 "result not as expected", return -1);
6301 return 0;
6304 /* Basic test for isl_pw_multi_aff_product.
6306 * Check that multiple pieces are properly handled.
6308 static int test_product_pma(isl_ctx *ctx)
6310 int equal;
6311 const char *str;
6312 isl_pw_multi_aff *pma1, *pma2;
6314 str = "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
6315 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
6316 str = "{ C[] -> D[] }";
6317 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
6318 pma1 = isl_pw_multi_aff_product(pma1, pma2);
6319 str = "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
6320 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
6321 equal = pw_multi_aff_check_plain_equal(pma1, str);
6322 isl_pw_multi_aff_free(pma1);
6323 if (equal < 0)
6324 return -1;
6326 return 0;
6329 int test_product(isl_ctx *ctx)
6331 const char *str;
6332 isl_set *set;
6333 isl_union_set *uset1, *uset2;
6334 int ok;
6336 str = "{ A[i] }";
6337 set = isl_set_read_from_str(ctx, str);
6338 set = isl_set_product(set, isl_set_copy(set));
6339 ok = isl_set_is_wrapping(set);
6340 isl_set_free(set);
6341 if (ok < 0)
6342 return -1;
6343 if (!ok)
6344 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6346 str = "{ [] }";
6347 uset1 = isl_union_set_read_from_str(ctx, str);
6348 uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1));
6349 str = "{ [[] -> []] }";
6350 uset2 = isl_union_set_read_from_str(ctx, str);
6351 ok = isl_union_set_is_equal(uset1, uset2);
6352 isl_union_set_free(uset1);
6353 isl_union_set_free(uset2);
6354 if (ok < 0)
6355 return -1;
6356 if (!ok)
6357 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6359 if (test_product_pma(ctx) < 0)
6360 return -1;
6362 return 0;
6365 /* Check that two sets are not considered disjoint just because
6366 * they have a different set of (named) parameters.
6368 static int test_disjoint(isl_ctx *ctx)
6370 const char *str;
6371 isl_set *set, *set2;
6372 int disjoint;
6374 str = "[n] -> { [[]->[]] }";
6375 set = isl_set_read_from_str(ctx, str);
6376 str = "{ [[]->[]] }";
6377 set2 = isl_set_read_from_str(ctx, str);
6378 disjoint = isl_set_is_disjoint(set, set2);
6379 isl_set_free(set);
6380 isl_set_free(set2);
6381 if (disjoint < 0)
6382 return -1;
6383 if (disjoint)
6384 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6386 return 0;
6389 /* Inputs for isl_pw_multi_aff_is_equal tests.
6390 * "f1" and "f2" are the two function that need to be compared.
6391 * "equal" is the expected result.
6393 struct {
6394 int equal;
6395 const char *f1;
6396 const char *f2;
6397 } pma_equal_tests[] = {
6398 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
6399 "[N] -> { [0] : 0 <= N <= 1 }" },
6400 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6401 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
6402 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
6403 "[N] -> { [0] : 0 <= N <= 1 }" },
6404 { 0, "{ [NaN] }", "{ [NaN] }" },
6407 int test_equal(isl_ctx *ctx)
6409 int i;
6410 const char *str;
6411 isl_set *set, *set2;
6412 int equal;
6414 str = "{ S_6[i] }";
6415 set = isl_set_read_from_str(ctx, str);
6416 str = "{ S_7[i] }";
6417 set2 = isl_set_read_from_str(ctx, str);
6418 equal = isl_set_is_equal(set, set2);
6419 isl_set_free(set);
6420 isl_set_free(set2);
6421 if (equal < 0)
6422 return -1;
6423 if (equal)
6424 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6426 for (i = 0; i < ARRAY_SIZE(pma_equal_tests); ++i) {
6427 int expected = pma_equal_tests[i].equal;
6428 isl_pw_multi_aff *f1, *f2;
6430 f1 = isl_pw_multi_aff_read_from_str(ctx, pma_equal_tests[i].f1);
6431 f2 = isl_pw_multi_aff_read_from_str(ctx, pma_equal_tests[i].f2);
6432 equal = isl_pw_multi_aff_is_equal(f1, f2);
6433 isl_pw_multi_aff_free(f1);
6434 isl_pw_multi_aff_free(f2);
6435 if (equal < 0)
6436 return -1;
6437 if (equal != expected)
6438 isl_die(ctx, isl_error_unknown,
6439 "unexpected equality result", return -1);
6442 return 0;
6445 static int test_plain_fixed(isl_ctx *ctx, __isl_take isl_map *map,
6446 enum isl_dim_type type, unsigned pos, int fixed)
6448 isl_bool test;
6450 test = isl_map_plain_is_fixed(map, type, pos, NULL);
6451 isl_map_free(map);
6452 if (test < 0)
6453 return -1;
6454 if (test == fixed)
6455 return 0;
6456 if (fixed)
6457 isl_die(ctx, isl_error_unknown,
6458 "map not detected as fixed", return -1);
6459 else
6460 isl_die(ctx, isl_error_unknown,
6461 "map detected as fixed", return -1);
6464 int test_fixed(isl_ctx *ctx)
6466 const char *str;
6467 isl_map *map;
6469 str = "{ [i] -> [i] }";
6470 map = isl_map_read_from_str(ctx, str);
6471 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 0))
6472 return -1;
6473 str = "{ [i] -> [1] }";
6474 map = isl_map_read_from_str(ctx, str);
6475 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
6476 return -1;
6477 str = "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
6478 map = isl_map_read_from_str(ctx, str);
6479 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
6480 return -1;
6481 map = isl_map_read_from_str(ctx, str);
6482 map = isl_map_neg(map);
6483 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
6484 return -1;
6486 return 0;
6489 struct isl_vertices_test_data {
6490 const char *set;
6491 int n;
6492 const char *vertex[6];
6493 } vertices_tests[] = {
6494 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
6495 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
6496 { "{ A[t, i] : t = 14 and i = 1 }",
6497 1, { "{ A[14, 1] }" } },
6498 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
6499 "c <= m and m <= n and m > 0 }",
6500 6, {
6501 "[n, m] -> { [n, m, m] : 0 < m <= n }",
6502 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
6503 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
6504 "[n, m] -> { [m, m, m] : 0 < m <= n }",
6505 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
6506 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
6507 } },
6510 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
6512 static isl_stat find_vertex(__isl_take isl_vertex *vertex, void *user)
6514 struct isl_vertices_test_data *data = user;
6515 isl_ctx *ctx;
6516 isl_multi_aff *ma;
6517 isl_basic_set *bset;
6518 isl_pw_multi_aff *pma;
6519 int i;
6520 isl_bool equal;
6522 ctx = isl_vertex_get_ctx(vertex);
6523 bset = isl_vertex_get_domain(vertex);
6524 ma = isl_vertex_get_expr(vertex);
6525 pma = isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset), ma);
6527 for (i = 0; i < data->n; ++i) {
6528 isl_pw_multi_aff *pma_i;
6530 pma_i = isl_pw_multi_aff_read_from_str(ctx, data->vertex[i]);
6531 equal = isl_pw_multi_aff_plain_is_equal(pma, pma_i);
6532 isl_pw_multi_aff_free(pma_i);
6534 if (equal < 0 || equal)
6535 break;
6538 isl_pw_multi_aff_free(pma);
6539 isl_vertex_free(vertex);
6541 if (equal < 0)
6542 return isl_stat_error;
6544 return equal ? isl_stat_ok : isl_stat_error;
6547 int test_vertices(isl_ctx *ctx)
6549 int i;
6551 for (i = 0; i < ARRAY_SIZE(vertices_tests); ++i) {
6552 isl_basic_set *bset;
6553 isl_vertices *vertices;
6554 int ok = 1;
6555 int n;
6557 bset = isl_basic_set_read_from_str(ctx, vertices_tests[i].set);
6558 vertices = isl_basic_set_compute_vertices(bset);
6559 n = isl_vertices_get_n_vertices(vertices);
6560 if (vertices_tests[i].n != n)
6561 ok = 0;
6562 if (isl_vertices_foreach_vertex(vertices, &find_vertex,
6563 &vertices_tests[i]) < 0)
6564 ok = 0;
6565 isl_vertices_free(vertices);
6566 isl_basic_set_free(bset);
6568 if (!vertices)
6569 return -1;
6570 if (!ok)
6571 isl_die(ctx, isl_error_unknown, "unexpected vertices",
6572 return -1);
6575 return 0;
6578 int test_union_pw(isl_ctx *ctx)
6580 int equal;
6581 const char *str;
6582 isl_union_set *uset;
6583 isl_union_pw_qpolynomial *upwqp1, *upwqp2;
6585 str = "{ [x] -> x^2 }";
6586 upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str);
6587 upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1);
6588 uset = isl_union_pw_qpolynomial_domain(upwqp1);
6589 upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2);
6590 upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset);
6591 equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2);
6592 isl_union_pw_qpolynomial_free(upwqp1);
6593 isl_union_pw_qpolynomial_free(upwqp2);
6594 if (equal < 0)
6595 return -1;
6596 if (!equal)
6597 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6599 return 0;
6602 /* Inputs for basic tests of functions that select
6603 * subparts of the domain of an isl_multi_union_pw_aff.
6604 * "fn" is the function that is tested.
6605 * "arg" is a string description of the input.
6606 * "res" is a string description of the expected result.
6608 struct {
6609 __isl_give isl_union_set *(*fn)(
6610 __isl_take isl_multi_union_pw_aff *mupa);
6611 const char *arg;
6612 const char *res;
6613 } un_locus_tests[] = {
6614 { &isl_multi_union_pw_aff_zero_union_set,
6615 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6616 "{ A[0,j]; B[0,j] }" },
6617 { &isl_multi_union_pw_aff_zero_union_set,
6618 "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]",
6619 "{ A[i,i]; B[i,i] : i >= 0 }" },
6620 { &isl_multi_union_pw_aff_zero_union_set,
6621 "(F[] : { A[i,j]; B[i,i] : i >= 0 })",
6622 "{ A[i,j]; B[i,i] : i >= 0 }" },
6625 /* Perform some basic tests of functions that select
6626 * subparts of the domain of an isl_multi_union_pw_aff.
6628 static int test_un_locus(isl_ctx *ctx)
6630 int i;
6631 isl_bool ok;
6632 isl_union_set *uset, *res;
6633 isl_multi_union_pw_aff *mupa;
6635 for (i = 0; i < ARRAY_SIZE(un_locus_tests); ++i) {
6636 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6637 un_locus_tests[i].arg);
6638 res = isl_union_set_read_from_str(ctx, un_locus_tests[i].res);
6639 uset = un_locus_tests[i].fn(mupa);
6640 ok = isl_union_set_is_equal(uset, res);
6641 isl_union_set_free(uset);
6642 isl_union_set_free(res);
6643 if (ok < 0)
6644 return -1;
6645 if (!ok)
6646 isl_die(ctx, isl_error_unknown,
6647 "unexpected result", return -1);
6650 return 0;
6653 /* Inputs for basic tests of functions that select
6654 * subparts of an isl_union_map based on a relation
6655 * specified by an isl_multi_union_pw_aff.
6656 * "fn" is the function that is tested.
6657 * "arg1" and "arg2" are string descriptions of the inputs.
6658 * "res" is a string description of the expected result.
6660 struct {
6661 __isl_give isl_union_map *(*fn)(
6662 __isl_take isl_union_map *umap,
6663 __isl_take isl_multi_union_pw_aff *mupa);
6664 const char *arg1;
6665 const char *arg2;
6666 const char *res;
6667 } bin_locus_tests[] = {
6668 { &isl_union_map_eq_at_multi_union_pw_aff,
6669 "{ A[i,j] -> B[i',j'] }",
6670 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6671 "{ A[i,j] -> B[i,j'] }" },
6672 { &isl_union_map_eq_at_multi_union_pw_aff,
6673 "{ A[i,j] -> B[i',j'] }",
6674 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6675 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6676 "{ A[i,j] -> B[i,j] }" },
6677 { &isl_union_map_eq_at_multi_union_pw_aff,
6678 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6679 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]",
6680 "{ A[i,j] -> B[i,j'] }" },
6681 { &isl_union_map_eq_at_multi_union_pw_aff,
6682 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6683 "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]",
6684 "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" },
6685 { &isl_union_map_eq_at_multi_union_pw_aff,
6686 "{ A[i,j] -> B[i',j'] }",
6687 "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]",
6688 "{ A[i,j] -> B[i,j'] : i > j }" },
6689 { &isl_union_map_lex_lt_at_multi_union_pw_aff,
6690 "{ A[i,j] -> B[i',j'] }",
6691 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6692 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6693 "{ A[i,j] -> B[i',j'] : i,j << i',j' }" },
6694 { &isl_union_map_lex_gt_at_multi_union_pw_aff,
6695 "{ A[i,j] -> B[i',j'] }",
6696 "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, "
6697 "{ A[i,j] -> [j]; B[i,j] -> [j] }]",
6698 "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" },
6699 { &isl_union_map_eq_at_multi_union_pw_aff,
6700 "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }",
6701 "(F[] : { A[i,j]; B[i,j] })",
6702 "{ A[i,j] -> B[i',j'] }" },
6703 { &isl_union_map_eq_at_multi_union_pw_aff,
6704 "{ A[i,j] -> B[i',j'] }",
6705 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6706 "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" },
6707 { &isl_union_map_eq_at_multi_union_pw_aff,
6708 "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }",
6709 "(F[] : { A[i,j] : i > j; B[i,j] : i < j })",
6710 "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" },
6711 { &isl_union_map_eq_at_multi_union_pw_aff,
6712 "{ A[i,j] -> B[i',j'] }",
6713 "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })",
6714 "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" },
6715 { &isl_union_map_eq_at_multi_union_pw_aff,
6716 "{ A[i,j] -> B[i',j'] }",
6717 "[N] -> (F[] : { : N >= 0 })",
6718 "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" },
6721 /* Perform some basic tests of functions that select
6722 * subparts of an isl_union_map based on a relation
6723 * specified by an isl_multi_union_pw_aff.
6725 static int test_bin_locus(isl_ctx *ctx)
6727 int i;
6728 isl_bool ok;
6729 isl_union_map *umap, *res;
6730 isl_multi_union_pw_aff *mupa;
6732 for (i = 0; i < ARRAY_SIZE(bin_locus_tests); ++i) {
6733 umap = isl_union_map_read_from_str(ctx,
6734 bin_locus_tests[i].arg1);
6735 mupa = isl_multi_union_pw_aff_read_from_str(ctx,
6736 bin_locus_tests[i].arg2);
6737 res = isl_union_map_read_from_str(ctx, bin_locus_tests[i].res);
6738 umap = bin_locus_tests[i].fn(umap, mupa);
6739 ok = isl_union_map_is_equal(umap, res);
6740 isl_union_map_free(umap);
6741 isl_union_map_free(res);
6742 if (ok < 0)
6743 return -1;
6744 if (!ok)
6745 isl_die(ctx, isl_error_unknown,
6746 "unexpected result", return -1);
6749 return 0;
6752 /* Perform basic locus tests.
6754 static int test_locus(isl_ctx *ctx)
6756 if (test_un_locus(ctx) < 0)
6757 return -1;
6758 if (test_bin_locus(ctx) < 0)
6759 return -1;
6760 return 0;
6763 /* Test that isl_union_pw_qpolynomial_eval picks up the function
6764 * defined over the correct domain space.
6766 static int test_eval_1(isl_ctx *ctx)
6768 const char *str;
6769 isl_point *pnt;
6770 isl_set *set;
6771 isl_union_pw_qpolynomial *upwqp;
6772 isl_val *v;
6773 int cmp;
6775 str = "{ A[x] -> x^2; B[x] -> -x^2 }";
6776 upwqp = isl_union_pw_qpolynomial_read_from_str(ctx, str);
6777 str = "{ A[6] }";
6778 set = isl_set_read_from_str(ctx, str);
6779 pnt = isl_set_sample_point(set);
6780 v = isl_union_pw_qpolynomial_eval(upwqp, pnt);
6781 cmp = isl_val_cmp_si(v, 36);
6782 isl_val_free(v);
6784 if (!v)
6785 return -1;
6786 if (cmp != 0)
6787 isl_die(ctx, isl_error_unknown, "unexpected value", return -1);
6789 return 0;
6792 /* Check that isl_qpolynomial_eval handles getting called on a void point.
6794 static int test_eval_2(isl_ctx *ctx)
6796 const char *str;
6797 isl_point *pnt;
6798 isl_set *set;
6799 isl_qpolynomial *qp;
6800 isl_val *v;
6801 isl_bool ok;
6803 str = "{ A[x] -> [x] }";
6804 qp = isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx, str));
6805 str = "{ A[x] : false }";
6806 set = isl_set_read_from_str(ctx, str);
6807 pnt = isl_set_sample_point(set);
6808 v = isl_qpolynomial_eval(qp, pnt);
6809 ok = isl_val_is_nan(v);
6810 isl_val_free(v);
6812 if (ok < 0)
6813 return -1;
6814 if (!ok)
6815 isl_die(ctx, isl_error_unknown, "expecting NaN", return -1);
6817 return 0;
6820 /* Inputs for isl_pw_aff_eval test.
6821 * "f" is the affine function.
6822 * "p" is the point where the function should be evaluated.
6823 * "res" is the expected result.
6825 struct {
6826 const char *f;
6827 const char *p;
6828 const char *res;
6829 } aff_eval_tests[] = {
6830 { "{ [i] -> [2 * i] }", "{ [4] }", "8" },
6831 { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" },
6832 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" },
6833 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" },
6834 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" },
6835 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" },
6836 { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" },
6837 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" },
6838 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" },
6839 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" },
6840 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" },
6841 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" },
6842 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" },
6843 { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" },
6844 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" },
6845 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" },
6846 { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" },
6847 { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" },
6848 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" },
6849 { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" },
6850 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" },
6851 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" },
6852 { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" },
6855 /* Perform basic isl_pw_aff_eval tests.
6857 static int test_eval_aff(isl_ctx *ctx)
6859 int i;
6861 for (i = 0; i < ARRAY_SIZE(aff_eval_tests); ++i) {
6862 isl_stat r;
6863 isl_pw_aff *pa;
6864 isl_set *set;
6865 isl_point *pnt;
6866 isl_val *v;
6868 pa = isl_pw_aff_read_from_str(ctx, aff_eval_tests[i].f);
6869 set = isl_set_read_from_str(ctx, aff_eval_tests[i].p);
6870 pnt = isl_set_sample_point(set);
6871 v = isl_pw_aff_eval(pa, pnt);
6872 r = val_check_equal(v, aff_eval_tests[i].res);
6873 isl_val_free(v);
6874 if (r < 0)
6875 return -1;
6877 return 0;
6880 /* Perform basic evaluation tests.
6882 static int test_eval(isl_ctx *ctx)
6884 if (test_eval_1(ctx) < 0)
6885 return -1;
6886 if (test_eval_2(ctx) < 0)
6887 return -1;
6888 if (test_eval_aff(ctx) < 0)
6889 return -1;
6890 return 0;
6893 /* Descriptions of sets that are tested for reparsing after printing.
6895 const char *output_tests[] = {
6896 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
6897 "{ [x] : 1 = 0 }",
6898 "{ [x] : false }",
6899 "{ [x] : x mod 2 = 0 }",
6900 "{ [x] : x mod 2 = 1 }",
6901 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) < x }",
6902 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) < x }",
6903 "{ [x, y] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
6904 "{ [y, x] : x mod 2 = 0 and 3*floor(y/2) = x + y }",
6905 "[n] -> { [y, x] : 2*((x + 2y) mod 3) = n }",
6906 "{ [x, y] : (2*floor(x/3) + 3*floor(y/4)) mod 5 = x }",
6909 /* Check that printing a set and reparsing a set from the printed output
6910 * results in the same set.
6912 static int test_output_set(isl_ctx *ctx)
6914 int i;
6915 char *str;
6916 isl_set *set1, *set2;
6917 isl_bool equal;
6919 for (i = 0; i < ARRAY_SIZE(output_tests); ++i) {
6920 set1 = isl_set_read_from_str(ctx, output_tests[i]);
6921 str = isl_set_to_str(set1);
6922 set2 = isl_set_read_from_str(ctx, str);
6923 free(str);
6924 equal = isl_set_is_equal(set1, set2);
6925 isl_set_free(set1);
6926 isl_set_free(set2);
6927 if (equal < 0)
6928 return -1;
6929 if (!equal)
6930 isl_die(ctx, isl_error_unknown,
6931 "parsed output not the same", return -1);
6934 return 0;
6937 int test_output(isl_ctx *ctx)
6939 char *s;
6940 const char *str;
6941 isl_pw_aff *pa;
6942 isl_printer *p;
6943 int equal;
6945 if (test_output_set(ctx) < 0)
6946 return -1;
6948 str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
6949 pa = isl_pw_aff_read_from_str(ctx, str);
6951 p = isl_printer_to_str(ctx);
6952 p = isl_printer_set_output_format(p, ISL_FORMAT_C);
6953 p = isl_printer_print_pw_aff(p, pa);
6954 s = isl_printer_get_str(p);
6955 isl_printer_free(p);
6956 isl_pw_aff_free(pa);
6957 if (!s)
6958 equal = -1;
6959 else
6960 equal = !strcmp(s, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
6961 free(s);
6962 if (equal < 0)
6963 return -1;
6964 if (!equal)
6965 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
6967 return 0;
6970 int test_sample(isl_ctx *ctx)
6972 const char *str;
6973 isl_basic_set *bset1, *bset2;
6974 int empty, subset;
6976 str = "{ [a, b, c, d, e, f, g, h, i, j, k] : "
6977 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
6978 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
6979 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
6980 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
6981 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
6982 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
6983 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
6984 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
6985 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
6986 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
6987 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
6988 "d - 1073741821e and "
6989 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
6990 "3j >= 1 - a + b + 2e and "
6991 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
6992 "3i <= 4 - a + 4b - e and "
6993 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
6994 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
6995 "c <= -1 + a and 3i >= -2 - a + 3e and "
6996 "1073741822e <= 1073741823 - a + 1073741822b + c and "
6997 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
6998 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
6999 "1073741823e >= 1 + 1073741823b - d and "
7000 "3i >= 1073741823b + c - 1073741823e - f and "
7001 "3i >= 1 + 2b + e + 3g }";
7002 bset1 = isl_basic_set_read_from_str(ctx, str);
7003 bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1));
7004 empty = isl_basic_set_is_empty(bset2);
7005 subset = isl_basic_set_is_subset(bset2, bset1);
7006 isl_basic_set_free(bset1);
7007 isl_basic_set_free(bset2);
7008 if (empty < 0 || subset < 0)
7009 return -1;
7010 if (empty)
7011 isl_die(ctx, isl_error_unknown, "point not found", return -1);
7012 if (!subset)
7013 isl_die(ctx, isl_error_unknown, "bad point found", return -1);
7015 return 0;
7018 int test_fixed_power(isl_ctx *ctx)
7020 const char *str;
7021 isl_map *map;
7022 isl_val *exp;
7023 int equal;
7025 str = "{ [i] -> [i + 1] }";
7026 map = isl_map_read_from_str(ctx, str);
7027 exp = isl_val_int_from_si(ctx, 23);
7028 map = isl_map_fixed_power_val(map, exp);
7029 equal = map_check_equal(map, "{ [i] -> [i + 23] }");
7030 isl_map_free(map);
7031 if (equal < 0)
7032 return -1;
7034 return 0;
7037 int test_slice(isl_ctx *ctx)
7039 const char *str;
7040 isl_map *map;
7041 int equal;
7043 str = "{ [i] -> [j] }";
7044 map = isl_map_read_from_str(ctx, str);
7045 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_out, 0);
7046 equal = map_check_equal(map, "{ [i] -> [i] }");
7047 isl_map_free(map);
7048 if (equal < 0)
7049 return -1;
7051 str = "{ [i] -> [j] }";
7052 map = isl_map_read_from_str(ctx, str);
7053 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_in, 0);
7054 equal = map_check_equal(map, "{ [i] -> [j] }");
7055 isl_map_free(map);
7056 if (equal < 0)
7057 return -1;
7059 str = "{ [i] -> [j] }";
7060 map = isl_map_read_from_str(ctx, str);
7061 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_out, 0);
7062 equal = map_check_equal(map, "{ [i] -> [-i] }");
7063 isl_map_free(map);
7064 if (equal < 0)
7065 return -1;
7067 str = "{ [i] -> [j] }";
7068 map = isl_map_read_from_str(ctx, str);
7069 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_in, 0);
7070 equal = map_check_equal(map, "{ [0] -> [j] }");
7071 isl_map_free(map);
7072 if (equal < 0)
7073 return -1;
7075 str = "{ [i] -> [j] }";
7076 map = isl_map_read_from_str(ctx, str);
7077 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_out, 0);
7078 equal = map_check_equal(map, "{ [i] -> [j] : i > j }");
7079 isl_map_free(map);
7080 if (equal < 0)
7081 return -1;
7083 str = "{ [i] -> [j] }";
7084 map = isl_map_read_from_str(ctx, str);
7085 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_in, 0);
7086 equal = map_check_equal(map, "{ [i] -> [j] : false }");
7087 isl_map_free(map);
7088 if (equal < 0)
7089 return -1;
7091 return 0;
7094 int test_eliminate(isl_ctx *ctx)
7096 const char *str;
7097 isl_map *map;
7098 int equal;
7100 str = "{ [i] -> [j] : i = 2j }";
7101 map = isl_map_read_from_str(ctx, str);
7102 map = isl_map_eliminate(map, isl_dim_out, 0, 1);
7103 equal = map_check_equal(map, "{ [i] -> [j] : exists a : i = 2a }");
7104 isl_map_free(map);
7105 if (equal < 0)
7106 return -1;
7108 return 0;
7111 /* Check that isl_set_dim_residue_class detects that the values of j
7112 * in the set below are all odd and that it does not detect any spurious
7113 * strides.
7115 static int test_residue_class(isl_ctx *ctx)
7117 const char *str;
7118 isl_set *set;
7119 isl_int m, r;
7120 isl_stat res;
7122 str = "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
7123 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
7124 set = isl_set_read_from_str(ctx, str);
7125 isl_int_init(m);
7126 isl_int_init(r);
7127 res = isl_set_dim_residue_class(set, 1, &m, &r);
7128 if (res >= 0 &&
7129 (isl_int_cmp_si(m, 2) != 0 || isl_int_cmp_si(r, 1) != 0))
7130 isl_die(ctx, isl_error_unknown, "incorrect residue class",
7131 res = isl_stat_error);
7132 isl_int_clear(r);
7133 isl_int_clear(m);
7134 isl_set_free(set);
7136 return res;
7139 int test_align_parameters(isl_ctx *ctx)
7141 const char *str;
7142 isl_space *space;
7143 isl_multi_aff *ma1, *ma2;
7144 int equal;
7146 str = "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
7147 ma1 = isl_multi_aff_read_from_str(ctx, str);
7149 space = isl_space_params_alloc(ctx, 1);
7150 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
7151 ma1 = isl_multi_aff_align_params(ma1, space);
7153 str = "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
7154 ma2 = isl_multi_aff_read_from_str(ctx, str);
7156 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
7158 isl_multi_aff_free(ma1);
7159 isl_multi_aff_free(ma2);
7161 if (equal < 0)
7162 return -1;
7163 if (!equal)
7164 isl_die(ctx, isl_error_unknown,
7165 "result not as expected", return -1);
7167 return 0;
7170 static int test_list(isl_ctx *ctx)
7172 isl_id *a, *b, *c, *d, *id;
7173 isl_id_list *list;
7174 int ok;
7176 a = isl_id_alloc(ctx, "a", NULL);
7177 b = isl_id_alloc(ctx, "b", NULL);
7178 c = isl_id_alloc(ctx, "c", NULL);
7179 d = isl_id_alloc(ctx, "d", NULL);
7181 list = isl_id_list_alloc(ctx, 4);
7182 list = isl_id_list_add(list, b);
7183 list = isl_id_list_insert(list, 0, a);
7184 list = isl_id_list_add(list, c);
7185 list = isl_id_list_add(list, d);
7186 list = isl_id_list_drop(list, 1, 1);
7188 if (!list)
7189 return -1;
7190 if (isl_id_list_n_id(list) != 3) {
7191 isl_id_list_free(list);
7192 isl_die(ctx, isl_error_unknown,
7193 "unexpected number of elements in list", return -1);
7196 id = isl_id_list_get_id(list, 0);
7197 ok = id == a;
7198 isl_id_free(id);
7199 id = isl_id_list_get_id(list, 1);
7200 ok = ok && id == c;
7201 isl_id_free(id);
7202 id = isl_id_list_get_id(list, 2);
7203 ok = ok && id == d;
7204 isl_id_free(id);
7206 isl_id_list_free(list);
7208 if (!ok)
7209 isl_die(ctx, isl_error_unknown,
7210 "unexpected elements in list", return -1);
7212 return 0;
7215 const char *set_conversion_tests[] = {
7216 "[N] -> { [i] : N - 1 <= 2 i <= N }",
7217 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
7218 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7219 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
7220 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
7221 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
7222 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
7223 "-3 + c <= d <= 28 + c) }",
7226 /* Check that converting from isl_set to isl_pw_multi_aff and back
7227 * to isl_set produces the original isl_set.
7229 static int test_set_conversion(isl_ctx *ctx)
7231 int i;
7232 const char *str;
7233 isl_set *set1, *set2;
7234 isl_pw_multi_aff *pma;
7235 int equal;
7237 for (i = 0; i < ARRAY_SIZE(set_conversion_tests); ++i) {
7238 str = set_conversion_tests[i];
7239 set1 = isl_set_read_from_str(ctx, str);
7240 pma = isl_pw_multi_aff_from_set(isl_set_copy(set1));
7241 set2 = isl_set_from_pw_multi_aff(pma);
7242 equal = isl_set_is_equal(set1, set2);
7243 isl_set_free(set1);
7244 isl_set_free(set2);
7246 if (equal < 0)
7247 return -1;
7248 if (!equal)
7249 isl_die(ctx, isl_error_unknown, "bad conversion",
7250 return -1);
7253 return 0;
7256 const char *conversion_tests[] = {
7257 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7258 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7259 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7260 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7261 "9e <= -2 - 2a) }",
7262 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7263 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7264 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7267 /* Check that converting from isl_map to isl_pw_multi_aff and back
7268 * to isl_map produces the original isl_map.
7270 static int test_map_conversion(isl_ctx *ctx)
7272 int i;
7273 isl_map *map1, *map2;
7274 isl_pw_multi_aff *pma;
7275 int equal;
7277 for (i = 0; i < ARRAY_SIZE(conversion_tests); ++i) {
7278 map1 = isl_map_read_from_str(ctx, conversion_tests[i]);
7279 pma = isl_pw_multi_aff_from_map(isl_map_copy(map1));
7280 map2 = isl_map_from_pw_multi_aff(pma);
7281 equal = isl_map_is_equal(map1, map2);
7282 isl_map_free(map1);
7283 isl_map_free(map2);
7285 if (equal < 0)
7286 return -1;
7287 if (!equal)
7288 isl_die(ctx, isl_error_unknown, "bad conversion",
7289 return -1);
7292 return 0;
7295 /* Descriptions of isl_pw_multi_aff objects for testing conversion
7296 * to isl_multi_pw_aff and back.
7298 const char *mpa_conversion_tests[] = {
7299 "{ [x] -> A[x] }",
7300 "{ [x] -> A[x] : x >= 0 }",
7301 "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }",
7302 "{ [x] -> A[x, x + 1] }",
7303 "{ [x] -> A[] }",
7304 "{ [x] -> A[] : x >= 0 }",
7307 /* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and
7308 * back to isl_pw_multi_aff preserves the original meaning.
7310 static int test_mpa_conversion(isl_ctx *ctx)
7312 int i;
7313 isl_pw_multi_aff *pma1, *pma2;
7314 isl_multi_pw_aff *mpa;
7315 int equal;
7317 for (i = 0; i < ARRAY_SIZE(mpa_conversion_tests); ++i) {
7318 const char *str;
7319 str = mpa_conversion_tests[i];
7320 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
7321 pma2 = isl_pw_multi_aff_copy(pma1);
7322 mpa = isl_multi_pw_aff_from_pw_multi_aff(pma1);
7323 pma1 = isl_pw_multi_aff_from_multi_pw_aff(mpa);
7324 equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
7325 isl_pw_multi_aff_free(pma1);
7326 isl_pw_multi_aff_free(pma2);
7328 if (equal < 0)
7329 return -1;
7330 if (!equal)
7331 isl_die(ctx, isl_error_unknown, "bad conversion",
7332 return -1);
7335 return 0;
7338 /* Descriptions of union maps that should be convertible
7339 * to an isl_multi_union_pw_aff.
7341 const char *umap_mupa_conversion_tests[] = {
7342 "{ [a, b, c, d] -> s0[a, b, e, f] : "
7343 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
7344 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
7345 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
7346 "9e <= -2 - 2a) }",
7347 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
7348 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
7349 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
7350 "{ A[] -> B[0]; C[] -> B[1] }",
7351 "{ A[] -> B[]; C[] -> B[] }",
7354 /* Check that converting from isl_union_map to isl_multi_union_pw_aff and back
7355 * to isl_union_map produces the original isl_union_map.
7357 static int test_union_map_mupa_conversion(isl_ctx *ctx)
7359 int i;
7360 isl_union_map *umap1, *umap2;
7361 isl_multi_union_pw_aff *mupa;
7362 int equal;
7364 for (i = 0; i < ARRAY_SIZE(umap_mupa_conversion_tests); ++i) {
7365 const char *str;
7366 str = umap_mupa_conversion_tests[i];
7367 umap1 = isl_union_map_read_from_str(ctx, str);
7368 umap2 = isl_union_map_copy(umap1);
7369 mupa = isl_multi_union_pw_aff_from_union_map(umap2);
7370 umap2 = isl_union_map_from_multi_union_pw_aff(mupa);
7371 equal = isl_union_map_is_equal(umap1, umap2);
7372 isl_union_map_free(umap1);
7373 isl_union_map_free(umap2);
7375 if (equal < 0)
7376 return -1;
7377 if (!equal)
7378 isl_die(ctx, isl_error_unknown, "bad conversion",
7379 return -1);
7382 return 0;
7385 static int test_conversion(isl_ctx *ctx)
7387 if (test_set_conversion(ctx) < 0)
7388 return -1;
7389 if (test_map_conversion(ctx) < 0)
7390 return -1;
7391 if (test_mpa_conversion(ctx) < 0)
7392 return -1;
7393 if (test_union_map_mupa_conversion(ctx) < 0)
7394 return -1;
7395 return 0;
7398 /* Check that isl_basic_map_curry does not modify input.
7400 static int test_curry(isl_ctx *ctx)
7402 const char *str;
7403 isl_basic_map *bmap1, *bmap2;
7404 int equal;
7406 str = "{ [A[] -> B[]] -> C[] }";
7407 bmap1 = isl_basic_map_read_from_str(ctx, str);
7408 bmap2 = isl_basic_map_curry(isl_basic_map_copy(bmap1));
7409 equal = isl_basic_map_is_equal(bmap1, bmap2);
7410 isl_basic_map_free(bmap1);
7411 isl_basic_map_free(bmap2);
7413 if (equal < 0)
7414 return -1;
7415 if (equal)
7416 isl_die(ctx, isl_error_unknown,
7417 "curried map should not be equal to original",
7418 return -1);
7420 return 0;
7423 struct {
7424 const char *set;
7425 const char *ma;
7426 const char *res;
7427 } preimage_tests[] = {
7428 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
7429 "{ A[j,i] -> B[i,j] }",
7430 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
7431 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7432 "{ A[a,b] -> B[a/2,b/6] }",
7433 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
7434 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
7435 "{ A[a,b] -> B[a/2,b/6] }",
7436 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
7437 "exists i,j : a = 2 i and b = 6 j }" },
7438 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
7439 "[n] -> { : 0 <= n <= 100 }" },
7440 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7441 "{ A[a] -> B[2a] }",
7442 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
7443 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
7444 "{ A[a] -> B[([a/2])] }",
7445 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
7446 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
7447 "{ A[a] -> B[a,a,a/3] }",
7448 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
7449 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
7450 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
7453 static int test_preimage_basic_set(isl_ctx *ctx)
7455 int i;
7456 isl_basic_set *bset1, *bset2;
7457 isl_multi_aff *ma;
7458 int equal;
7460 for (i = 0; i < ARRAY_SIZE(preimage_tests); ++i) {
7461 bset1 = isl_basic_set_read_from_str(ctx, preimage_tests[i].set);
7462 ma = isl_multi_aff_read_from_str(ctx, preimage_tests[i].ma);
7463 bset2 = isl_basic_set_read_from_str(ctx, preimage_tests[i].res);
7464 bset1 = isl_basic_set_preimage_multi_aff(bset1, ma);
7465 equal = isl_basic_set_is_equal(bset1, bset2);
7466 isl_basic_set_free(bset1);
7467 isl_basic_set_free(bset2);
7468 if (equal < 0)
7469 return -1;
7470 if (!equal)
7471 isl_die(ctx, isl_error_unknown, "bad preimage",
7472 return -1);
7475 return 0;
7478 struct {
7479 const char *map;
7480 const char *ma;
7481 const char *res;
7482 } preimage_domain_tests[] = {
7483 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
7484 "{ A[j,i] -> B[i,j] }",
7485 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
7486 { "{ B[i] -> C[i]; D[i] -> E[i] }",
7487 "{ A[i] -> B[i + 1] }",
7488 "{ A[i] -> C[i + 1] }" },
7489 { "{ B[i] -> C[i]; B[i] -> E[i] }",
7490 "{ A[i] -> B[i + 1] }",
7491 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
7492 { "{ B[i] -> C[([i/2])] }",
7493 "{ A[i] -> B[2i] }",
7494 "{ A[i] -> C[i] }" },
7495 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
7496 "{ A[i] -> B[([i/5]), ([i/7])] }",
7497 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
7498 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
7499 "[N] -> { A[] -> B[([N/5])] }",
7500 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
7501 { "{ B[i] -> C[i] : exists a : i = 5 a }",
7502 "{ A[i] -> B[2i] }",
7503 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
7504 { "{ B[i] -> C[i] : exists a : i = 2 a; "
7505 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
7506 "{ A[i] -> B[2i] }",
7507 "{ A[i] -> C[2i] }" },
7508 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
7509 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
7512 static int test_preimage_union_map(isl_ctx *ctx)
7514 int i;
7515 isl_union_map *umap1, *umap2;
7516 isl_multi_aff *ma;
7517 int equal;
7519 for (i = 0; i < ARRAY_SIZE(preimage_domain_tests); ++i) {
7520 umap1 = isl_union_map_read_from_str(ctx,
7521 preimage_domain_tests[i].map);
7522 ma = isl_multi_aff_read_from_str(ctx,
7523 preimage_domain_tests[i].ma);
7524 umap2 = isl_union_map_read_from_str(ctx,
7525 preimage_domain_tests[i].res);
7526 umap1 = isl_union_map_preimage_domain_multi_aff(umap1, ma);
7527 equal = isl_union_map_is_equal(umap1, umap2);
7528 isl_union_map_free(umap1);
7529 isl_union_map_free(umap2);
7530 if (equal < 0)
7531 return -1;
7532 if (!equal)
7533 isl_die(ctx, isl_error_unknown, "bad preimage",
7534 return -1);
7537 return 0;
7540 static int test_preimage(isl_ctx *ctx)
7542 if (test_preimage_basic_set(ctx) < 0)
7543 return -1;
7544 if (test_preimage_union_map(ctx) < 0)
7545 return -1;
7547 return 0;
7550 struct {
7551 const char *ma1;
7552 const char *ma;
7553 const char *res;
7554 } pullback_tests[] = {
7555 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
7556 "{ A[a,b] -> C[b + 2a] }" },
7557 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
7558 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
7559 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
7560 "{ A[a] -> C[(a)/6] }" },
7561 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
7562 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
7563 "{ A[a] -> C[(2a)/3] }" },
7564 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
7565 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
7566 "{ A[i,j] -> C[i + j, i + j] }"},
7567 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
7568 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
7569 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
7570 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
7571 "{ [i, j] -> [floor((i)/3), j] }",
7572 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
7575 static int test_pullback(isl_ctx *ctx)
7577 int i;
7578 isl_multi_aff *ma1, *ma2;
7579 isl_multi_aff *ma;
7580 int equal;
7582 for (i = 0; i < ARRAY_SIZE(pullback_tests); ++i) {
7583 ma1 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma1);
7584 ma = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma);
7585 ma2 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].res);
7586 ma1 = isl_multi_aff_pullback_multi_aff(ma1, ma);
7587 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
7588 isl_multi_aff_free(ma1);
7589 isl_multi_aff_free(ma2);
7590 if (equal < 0)
7591 return -1;
7592 if (!equal)
7593 isl_die(ctx, isl_error_unknown, "bad pullback",
7594 return -1);
7597 return 0;
7600 /* Check that negation is printed correctly and that equal expressions
7601 * are correctly identified.
7603 static int test_ast(isl_ctx *ctx)
7605 isl_ast_expr *expr, *expr1, *expr2, *expr3;
7606 char *str;
7607 int ok, equal;
7609 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
7610 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
7611 expr = isl_ast_expr_add(expr1, expr2);
7612 expr2 = isl_ast_expr_copy(expr);
7613 expr = isl_ast_expr_neg(expr);
7614 expr2 = isl_ast_expr_neg(expr2);
7615 equal = isl_ast_expr_is_equal(expr, expr2);
7616 str = isl_ast_expr_to_C_str(expr);
7617 ok = str ? !strcmp(str, "-(A + B)") : -1;
7618 free(str);
7619 isl_ast_expr_free(expr);
7620 isl_ast_expr_free(expr2);
7622 if (ok < 0 || equal < 0)
7623 return -1;
7624 if (!equal)
7625 isl_die(ctx, isl_error_unknown,
7626 "equal expressions not considered equal", return -1);
7627 if (!ok)
7628 isl_die(ctx, isl_error_unknown,
7629 "isl_ast_expr printed incorrectly", return -1);
7631 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
7632 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
7633 expr = isl_ast_expr_add(expr1, expr2);
7634 expr3 = isl_ast_expr_from_id(isl_id_alloc(ctx, "C", NULL));
7635 expr = isl_ast_expr_sub(expr3, expr);
7636 str = isl_ast_expr_to_C_str(expr);
7637 ok = str ? !strcmp(str, "C - (A + B)") : -1;
7638 free(str);
7639 isl_ast_expr_free(expr);
7641 if (ok < 0)
7642 return -1;
7643 if (!ok)
7644 isl_die(ctx, isl_error_unknown,
7645 "isl_ast_expr printed incorrectly", return -1);
7647 return 0;
7650 /* Check that isl_ast_build_expr_from_set returns a valid expression
7651 * for an empty set. Note that isl_ast_build_expr_from_set getting
7652 * called on an empty set probably indicates a bug in the caller.
7654 static int test_ast_build(isl_ctx *ctx)
7656 isl_set *set;
7657 isl_ast_build *build;
7658 isl_ast_expr *expr;
7660 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
7661 build = isl_ast_build_from_context(set);
7663 set = isl_set_empty(isl_space_params_alloc(ctx, 0));
7664 expr = isl_ast_build_expr_from_set(build, set);
7666 isl_ast_expr_free(expr);
7667 isl_ast_build_free(build);
7669 if (!expr)
7670 return -1;
7672 return 0;
7675 /* Internal data structure for before_for and after_for callbacks.
7677 * depth is the current depth
7678 * before is the number of times before_for has been called
7679 * after is the number of times after_for has been called
7681 struct isl_test_codegen_data {
7682 int depth;
7683 int before;
7684 int after;
7687 /* This function is called before each for loop in the AST generated
7688 * from test_ast_gen1.
7690 * Increment the number of calls and the depth.
7691 * Check that the space returned by isl_ast_build_get_schedule_space
7692 * matches the target space of the schedule returned by
7693 * isl_ast_build_get_schedule.
7694 * Return an isl_id that is checked by the corresponding call
7695 * to after_for.
7697 static __isl_give isl_id *before_for(__isl_keep isl_ast_build *build,
7698 void *user)
7700 struct isl_test_codegen_data *data = user;
7701 isl_ctx *ctx;
7702 isl_space *space;
7703 isl_union_map *schedule;
7704 isl_union_set *uset;
7705 isl_set *set;
7706 int empty;
7707 char name[] = "d0";
7709 ctx = isl_ast_build_get_ctx(build);
7711 if (data->before >= 3)
7712 isl_die(ctx, isl_error_unknown,
7713 "unexpected number of for nodes", return NULL);
7714 if (data->depth >= 2)
7715 isl_die(ctx, isl_error_unknown,
7716 "unexpected depth", return NULL);
7718 snprintf(name, sizeof(name), "d%d", data->depth);
7719 data->before++;
7720 data->depth++;
7722 schedule = isl_ast_build_get_schedule(build);
7723 uset = isl_union_map_range(schedule);
7724 if (!uset)
7725 return NULL;
7726 if (isl_union_set_n_set(uset) != 1) {
7727 isl_union_set_free(uset);
7728 isl_die(ctx, isl_error_unknown,
7729 "expecting single range space", return NULL);
7732 space = isl_ast_build_get_schedule_space(build);
7733 set = isl_union_set_extract_set(uset, space);
7734 isl_union_set_free(uset);
7735 empty = isl_set_is_empty(set);
7736 isl_set_free(set);
7738 if (empty < 0)
7739 return NULL;
7740 if (empty)
7741 isl_die(ctx, isl_error_unknown,
7742 "spaces don't match", return NULL);
7744 return isl_id_alloc(ctx, name, NULL);
7747 /* This function is called after each for loop in the AST generated
7748 * from test_ast_gen1.
7750 * Increment the number of calls and decrement the depth.
7751 * Check that the annotation attached to the node matches
7752 * the isl_id returned by the corresponding call to before_for.
7754 static __isl_give isl_ast_node *after_for(__isl_take isl_ast_node *node,
7755 __isl_keep isl_ast_build *build, void *user)
7757 struct isl_test_codegen_data *data = user;
7758 isl_id *id;
7759 const char *name;
7760 int valid;
7762 data->after++;
7763 data->depth--;
7765 if (data->after > data->before)
7766 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
7767 "mismatch in number of for nodes",
7768 return isl_ast_node_free(node));
7770 id = isl_ast_node_get_annotation(node);
7771 if (!id)
7772 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
7773 "missing annotation", return isl_ast_node_free(node));
7775 name = isl_id_get_name(id);
7776 valid = name && atoi(name + 1) == data->depth;
7777 isl_id_free(id);
7779 if (!valid)
7780 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
7781 "wrong annotation", return isl_ast_node_free(node));
7783 return node;
7786 /* Check that the before_each_for and after_each_for callbacks
7787 * are called for each for loop in the generated code,
7788 * that they are called in the right order and that the isl_id
7789 * returned from the before_each_for callback is attached to
7790 * the isl_ast_node passed to the corresponding after_each_for call.
7792 static int test_ast_gen1(isl_ctx *ctx)
7794 const char *str;
7795 isl_set *set;
7796 isl_union_map *schedule;
7797 isl_ast_build *build;
7798 isl_ast_node *tree;
7799 struct isl_test_codegen_data data;
7801 str = "[N] -> { : N >= 10 }";
7802 set = isl_set_read_from_str(ctx, str);
7803 str = "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
7804 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
7805 schedule = isl_union_map_read_from_str(ctx, str);
7807 data.before = 0;
7808 data.after = 0;
7809 data.depth = 0;
7810 build = isl_ast_build_from_context(set);
7811 build = isl_ast_build_set_before_each_for(build,
7812 &before_for, &data);
7813 build = isl_ast_build_set_after_each_for(build,
7814 &after_for, &data);
7815 tree = isl_ast_build_node_from_schedule_map(build, schedule);
7816 isl_ast_build_free(build);
7817 if (!tree)
7818 return -1;
7820 isl_ast_node_free(tree);
7822 if (data.before != 3 || data.after != 3)
7823 isl_die(ctx, isl_error_unknown,
7824 "unexpected number of for nodes", return -1);
7826 return 0;
7829 /* Check that the AST generator handles domains that are integrally disjoint
7830 * but not rationally disjoint.
7832 static int test_ast_gen2(isl_ctx *ctx)
7834 const char *str;
7835 isl_set *set;
7836 isl_union_map *schedule;
7837 isl_union_map *options;
7838 isl_ast_build *build;
7839 isl_ast_node *tree;
7841 str = "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
7842 schedule = isl_union_map_read_from_str(ctx, str);
7843 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
7844 build = isl_ast_build_from_context(set);
7846 str = "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
7847 options = isl_union_map_read_from_str(ctx, str);
7848 build = isl_ast_build_set_options(build, options);
7849 tree = isl_ast_build_node_from_schedule_map(build, schedule);
7850 isl_ast_build_free(build);
7851 if (!tree)
7852 return -1;
7853 isl_ast_node_free(tree);
7855 return 0;
7858 /* Increment *user on each call.
7860 static __isl_give isl_ast_node *count_domains(__isl_take isl_ast_node *node,
7861 __isl_keep isl_ast_build *build, void *user)
7863 int *n = user;
7865 (*n)++;
7867 return node;
7870 /* Test that unrolling tries to minimize the number of instances.
7871 * In particular, for the schedule given below, make sure it generates
7872 * 3 nodes (rather than 101).
7874 static int test_ast_gen3(isl_ctx *ctx)
7876 const char *str;
7877 isl_set *set;
7878 isl_union_map *schedule;
7879 isl_union_map *options;
7880 isl_ast_build *build;
7881 isl_ast_node *tree;
7882 int n_domain = 0;
7884 str = "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
7885 schedule = isl_union_map_read_from_str(ctx, str);
7886 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
7888 str = "{ [i] -> unroll[0] }";
7889 options = isl_union_map_read_from_str(ctx, str);
7891 build = isl_ast_build_from_context(set);
7892 build = isl_ast_build_set_options(build, options);
7893 build = isl_ast_build_set_at_each_domain(build,
7894 &count_domains, &n_domain);
7895 tree = isl_ast_build_node_from_schedule_map(build, schedule);
7896 isl_ast_build_free(build);
7897 if (!tree)
7898 return -1;
7900 isl_ast_node_free(tree);
7902 if (n_domain != 3)
7903 isl_die(ctx, isl_error_unknown,
7904 "unexpected number of for nodes", return -1);
7906 return 0;
7909 /* Check that if the ast_build_exploit_nested_bounds options is set,
7910 * we do not get an outer if node in the generated AST,
7911 * while we do get such an outer if node if the options is not set.
7913 static int test_ast_gen4(isl_ctx *ctx)
7915 const char *str;
7916 isl_set *set;
7917 isl_union_map *schedule;
7918 isl_ast_build *build;
7919 isl_ast_node *tree;
7920 enum isl_ast_node_type type;
7921 int enb;
7923 enb = isl_options_get_ast_build_exploit_nested_bounds(ctx);
7924 str = "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
7926 isl_options_set_ast_build_exploit_nested_bounds(ctx, 1);
7928 schedule = isl_union_map_read_from_str(ctx, str);
7929 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
7930 build = isl_ast_build_from_context(set);
7931 tree = isl_ast_build_node_from_schedule_map(build, schedule);
7932 isl_ast_build_free(build);
7933 if (!tree)
7934 return -1;
7936 type = isl_ast_node_get_type(tree);
7937 isl_ast_node_free(tree);
7939 if (type == isl_ast_node_if)
7940 isl_die(ctx, isl_error_unknown,
7941 "not expecting if node", return -1);
7943 isl_options_set_ast_build_exploit_nested_bounds(ctx, 0);
7945 schedule = isl_union_map_read_from_str(ctx, str);
7946 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
7947 build = isl_ast_build_from_context(set);
7948 tree = isl_ast_build_node_from_schedule_map(build, schedule);
7949 isl_ast_build_free(build);
7950 if (!tree)
7951 return -1;
7953 type = isl_ast_node_get_type(tree);
7954 isl_ast_node_free(tree);
7956 if (type != isl_ast_node_if)
7957 isl_die(ctx, isl_error_unknown,
7958 "expecting if node", return -1);
7960 isl_options_set_ast_build_exploit_nested_bounds(ctx, enb);
7962 return 0;
7965 /* This function is called for each leaf in the AST generated
7966 * from test_ast_gen5.
7968 * We finalize the AST generation by extending the outer schedule
7969 * with a zero-dimensional schedule. If this results in any for loops,
7970 * then this means that we did not pass along enough information
7971 * about the outer schedule to the inner AST generation.
7973 static __isl_give isl_ast_node *create_leaf(__isl_take isl_ast_build *build,
7974 void *user)
7976 isl_union_map *schedule, *extra;
7977 isl_ast_node *tree;
7979 schedule = isl_ast_build_get_schedule(build);
7980 extra = isl_union_map_copy(schedule);
7981 extra = isl_union_map_from_domain(isl_union_map_domain(extra));
7982 schedule = isl_union_map_range_product(schedule, extra);
7983 tree = isl_ast_build_node_from_schedule_map(build, schedule);
7984 isl_ast_build_free(build);
7986 if (!tree)
7987 return NULL;
7989 if (isl_ast_node_get_type(tree) == isl_ast_node_for)
7990 isl_die(isl_ast_node_get_ctx(tree), isl_error_unknown,
7991 "code should not contain any for loop",
7992 return isl_ast_node_free(tree));
7994 return tree;
7997 /* Check that we do not lose any information when going back and
7998 * forth between internal and external schedule.
8000 * In particular, we create an AST where we unroll the only
8001 * non-constant dimension in the schedule. We therefore do
8002 * not expect any for loops in the AST. However, older versions
8003 * of isl would not pass along enough information about the outer
8004 * schedule when performing an inner code generation from a create_leaf
8005 * callback, resulting in the inner code generation producing a for loop.
8007 static int test_ast_gen5(isl_ctx *ctx)
8009 const char *str;
8010 isl_set *set;
8011 isl_union_map *schedule, *options;
8012 isl_ast_build *build;
8013 isl_ast_node *tree;
8015 str = "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
8016 schedule = isl_union_map_read_from_str(ctx, str);
8018 str = "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
8019 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
8020 options = isl_union_map_read_from_str(ctx, str);
8022 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
8023 build = isl_ast_build_from_context(set);
8024 build = isl_ast_build_set_options(build, options);
8025 build = isl_ast_build_set_create_leaf(build, &create_leaf, NULL);
8026 tree = isl_ast_build_node_from_schedule_map(build, schedule);
8027 isl_ast_build_free(build);
8028 isl_ast_node_free(tree);
8029 if (!tree)
8030 return -1;
8032 return 0;
8035 /* Check that the expression
8037 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
8039 * is not combined into
8041 * min(n/2, 0)
8043 * as this would result in n/2 being evaluated in parts of
8044 * the definition domain where n is not a multiple of 2.
8046 static int test_ast_expr(isl_ctx *ctx)
8048 const char *str;
8049 isl_pw_aff *pa;
8050 isl_ast_build *build;
8051 isl_ast_expr *expr;
8052 int min_max;
8053 int is_min;
8055 min_max = isl_options_get_ast_build_detect_min_max(ctx);
8056 isl_options_set_ast_build_detect_min_max(ctx, 1);
8058 str = "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
8059 pa = isl_pw_aff_read_from_str(ctx, str);
8060 build = isl_ast_build_alloc(ctx);
8061 expr = isl_ast_build_expr_from_pw_aff(build, pa);
8062 is_min = isl_ast_expr_get_type(expr) == isl_ast_expr_op &&
8063 isl_ast_expr_get_op_type(expr) == isl_ast_op_min;
8064 isl_ast_build_free(build);
8065 isl_ast_expr_free(expr);
8067 isl_options_set_ast_build_detect_min_max(ctx, min_max);
8069 if (!expr)
8070 return -1;
8071 if (is_min)
8072 isl_die(ctx, isl_error_unknown,
8073 "expressions should not be combined", return -1);
8075 return 0;
8078 static int test_ast_gen(isl_ctx *ctx)
8080 if (test_ast_gen1(ctx) < 0)
8081 return -1;
8082 if (test_ast_gen2(ctx) < 0)
8083 return -1;
8084 if (test_ast_gen3(ctx) < 0)
8085 return -1;
8086 if (test_ast_gen4(ctx) < 0)
8087 return -1;
8088 if (test_ast_gen5(ctx) < 0)
8089 return -1;
8090 if (test_ast_expr(ctx) < 0)
8091 return -1;
8092 return 0;
8095 /* Check if dropping output dimensions from an isl_pw_multi_aff
8096 * works properly.
8098 static int test_pw_multi_aff(isl_ctx *ctx)
8100 const char *str;
8101 isl_pw_multi_aff *pma1, *pma2;
8102 int equal;
8104 str = "{ [i,j] -> [i+j, 4i-j] }";
8105 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
8106 str = "{ [i,j] -> [4i-j] }";
8107 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
8109 pma1 = isl_pw_multi_aff_drop_dims(pma1, isl_dim_out, 0, 1);
8111 equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
8113 isl_pw_multi_aff_free(pma1);
8114 isl_pw_multi_aff_free(pma2);
8115 if (equal < 0)
8116 return -1;
8117 if (!equal)
8118 isl_die(ctx, isl_error_unknown,
8119 "expressions not equal", return -1);
8121 return 0;
8124 /* Check that we can properly parse multi piecewise affine expressions
8125 * where the piecewise affine expressions have different domains.
8127 static int test_multi_pw_aff_1(isl_ctx *ctx)
8129 const char *str;
8130 isl_set *dom, *dom2;
8131 isl_multi_pw_aff *mpa1, *mpa2;
8132 isl_pw_aff *pa;
8133 int equal;
8134 int equal_domain;
8136 mpa1 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [i] }");
8137 dom = isl_set_read_from_str(ctx, "{ [i] : i > 0 }");
8138 mpa1 = isl_multi_pw_aff_intersect_domain(mpa1, dom);
8139 mpa2 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [2i] }");
8140 mpa2 = isl_multi_pw_aff_flat_range_product(mpa1, mpa2);
8141 str = "{ [i] -> [(i : i > 0), 2i] }";
8142 mpa1 = isl_multi_pw_aff_read_from_str(ctx, str);
8144 equal = isl_multi_pw_aff_plain_is_equal(mpa1, mpa2);
8146 pa = isl_multi_pw_aff_get_pw_aff(mpa1, 0);
8147 dom = isl_pw_aff_domain(pa);
8148 pa = isl_multi_pw_aff_get_pw_aff(mpa1, 1);
8149 dom2 = isl_pw_aff_domain(pa);
8150 equal_domain = isl_set_is_equal(dom, dom2);
8152 isl_set_free(dom);
8153 isl_set_free(dom2);
8154 isl_multi_pw_aff_free(mpa1);
8155 isl_multi_pw_aff_free(mpa2);
8157 if (equal < 0)
8158 return -1;
8159 if (!equal)
8160 isl_die(ctx, isl_error_unknown,
8161 "expressions not equal", return -1);
8163 if (equal_domain < 0)
8164 return -1;
8165 if (equal_domain)
8166 isl_die(ctx, isl_error_unknown,
8167 "domains unexpectedly equal", return -1);
8169 return 0;
8172 /* Check that the dimensions in the explicit domain
8173 * of a multi piecewise affine expression are properly
8174 * taken into account.
8176 static int test_multi_pw_aff_2(isl_ctx *ctx)
8178 const char *str;
8179 isl_bool involves1, involves2, involves3, equal;
8180 isl_multi_pw_aff *mpa, *mpa1, *mpa2;
8182 str = "{ A[x,y] -> B[] : x >= y }";
8183 mpa = isl_multi_pw_aff_read_from_str(ctx, str);
8184 involves1 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 2);
8185 mpa1 = isl_multi_pw_aff_copy(mpa);
8187 mpa = isl_multi_pw_aff_insert_dims(mpa, isl_dim_in, 0, 1);
8188 involves2 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 1);
8189 involves3 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 1, 2);
8190 str = "{ [a,x,y] -> B[] : x >= y }";
8191 mpa2 = isl_multi_pw_aff_read_from_str(ctx, str);
8192 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2);
8193 isl_multi_pw_aff_free(mpa2);
8195 mpa = isl_multi_pw_aff_drop_dims(mpa, isl_dim_in, 0, 1);
8196 mpa = isl_multi_pw_aff_set_tuple_name(mpa, isl_dim_in, "A");
8197 if (equal >= 0 && equal)
8198 equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa1);
8199 isl_multi_pw_aff_free(mpa1);
8200 isl_multi_pw_aff_free(mpa);
8202 if (involves1 < 0 || involves2 < 0 || involves3 < 0 || equal < 0)
8203 return -1;
8204 if (!equal)
8205 isl_die(ctx, isl_error_unknown,
8206 "incorrect result of dimension insertion/removal",
8207 return isl_stat_error);
8208 if (!involves1 || involves2 || !involves3)
8209 isl_die(ctx, isl_error_unknown,
8210 "incorrect characterization of involved dimensions",
8211 return isl_stat_error);
8213 return 0;
8216 /* Perform some tests on multi piecewise affine expressions.
8218 static int test_multi_pw_aff(isl_ctx *ctx)
8220 if (test_multi_pw_aff_1(ctx) < 0)
8221 return -1;
8222 if (test_multi_pw_aff_2(ctx) < 0)
8223 return -1;
8224 return 0;
8227 /* This is a regression test for a bug where isl_basic_map_simplify
8228 * would end up in an infinite loop. In particular, we construct
8229 * an empty basic set that is not obviously empty.
8230 * isl_basic_set_is_empty marks the basic set as empty.
8231 * After projecting out i3, the variable can be dropped completely,
8232 * but isl_basic_map_simplify refrains from doing so if the basic set
8233 * is empty and would end up in an infinite loop if it didn't test
8234 * explicitly for empty basic maps in the outer loop.
8236 static int test_simplify_1(isl_ctx *ctx)
8238 const char *str;
8239 isl_basic_set *bset;
8240 int empty;
8242 str = "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
8243 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
8244 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
8245 "i3 >= i2 }";
8246 bset = isl_basic_set_read_from_str(ctx, str);
8247 empty = isl_basic_set_is_empty(bset);
8248 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
8249 isl_basic_set_free(bset);
8250 if (!bset)
8251 return -1;
8252 if (!empty)
8253 isl_die(ctx, isl_error_unknown,
8254 "basic set should be empty", return -1);
8256 return 0;
8259 /* Check that the equality in the set description below
8260 * is simplified away.
8262 static int test_simplify_2(isl_ctx *ctx)
8264 const char *str;
8265 isl_basic_set *bset;
8266 isl_bool universe;
8268 str = "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
8269 bset = isl_basic_set_read_from_str(ctx, str);
8270 universe = isl_basic_set_plain_is_universe(bset);
8271 isl_basic_set_free(bset);
8273 if (universe < 0)
8274 return -1;
8275 if (!universe)
8276 isl_die(ctx, isl_error_unknown,
8277 "equality not simplified away", return -1);
8278 return 0;
8281 /* Some simplification tests.
8283 static int test_simplify(isl_ctx *ctx)
8285 if (test_simplify_1(ctx) < 0)
8286 return -1;
8287 if (test_simplify_2(ctx) < 0)
8288 return -1;
8289 return 0;
8292 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
8293 * with gbr context would fail to disable the use of the shifted tableau
8294 * when transferring equalities for the input to the context, resulting
8295 * in invalid sample values.
8297 static int test_partial_lexmin(isl_ctx *ctx)
8299 const char *str;
8300 isl_basic_set *bset;
8301 isl_basic_map *bmap;
8302 isl_map *map;
8304 str = "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
8305 bmap = isl_basic_map_read_from_str(ctx, str);
8306 str = "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
8307 bset = isl_basic_set_read_from_str(ctx, str);
8308 map = isl_basic_map_partial_lexmin(bmap, bset, NULL);
8309 isl_map_free(map);
8311 if (!map)
8312 return -1;
8314 return 0;
8317 /* Check that the variable compression performed on the existentially
8318 * quantified variables inside isl_basic_set_compute_divs is not confused
8319 * by the implicit equalities among the parameters.
8321 static int test_compute_divs(isl_ctx *ctx)
8323 const char *str;
8324 isl_basic_set *bset;
8325 isl_set *set;
8327 str = "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
8328 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
8329 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
8330 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
8331 bset = isl_basic_set_read_from_str(ctx, str);
8332 set = isl_basic_set_compute_divs(bset);
8333 isl_set_free(set);
8334 if (!set)
8335 return -1;
8337 return 0;
8340 /* Check that isl_schedule_get_map is not confused by a schedule tree
8341 * with divergent filter node parameters, as can result from a call
8342 * to isl_schedule_intersect_domain.
8344 static int test_schedule_tree(isl_ctx *ctx)
8346 const char *str;
8347 isl_union_set *uset;
8348 isl_schedule *sched1, *sched2;
8349 isl_union_map *umap;
8351 uset = isl_union_set_read_from_str(ctx, "{ A[i] }");
8352 sched1 = isl_schedule_from_domain(uset);
8353 uset = isl_union_set_read_from_str(ctx, "{ B[] }");
8354 sched2 = isl_schedule_from_domain(uset);
8356 sched1 = isl_schedule_sequence(sched1, sched2);
8357 str = "[n] -> { A[i] : 0 <= i < n; B[] }";
8358 uset = isl_union_set_read_from_str(ctx, str);
8359 sched1 = isl_schedule_intersect_domain(sched1, uset);
8360 umap = isl_schedule_get_map(sched1);
8361 isl_schedule_free(sched1);
8362 isl_union_map_free(umap);
8363 if (!umap)
8364 return -1;
8366 return 0;
8369 /* Check that a zero-dimensional prefix schedule keeps track
8370 * of the domain and outer filters.
8372 static int test_schedule_tree_prefix(isl_ctx *ctx)
8374 const char *str;
8375 isl_bool equal;
8376 isl_union_set *uset;
8377 isl_union_set_list *filters;
8378 isl_multi_union_pw_aff *mupa, *mupa2;
8379 isl_schedule_node *node;
8381 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8382 uset = isl_union_set_read_from_str(ctx, str);
8383 node = isl_schedule_node_from_domain(uset);
8384 node = isl_schedule_node_child(node, 0);
8386 str = "{ S1[i,j] : i > j }";
8387 uset = isl_union_set_read_from_str(ctx, str);
8388 filters = isl_union_set_list_from_union_set(uset);
8389 str = "{ S1[i,j] : i <= j; S2[i,j] }";
8390 uset = isl_union_set_read_from_str(ctx, str);
8391 filters = isl_union_set_list_add(filters, uset);
8392 node = isl_schedule_node_insert_sequence(node, filters);
8394 node = isl_schedule_node_child(node, 0);
8395 node = isl_schedule_node_child(node, 0);
8396 mupa = isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node);
8397 str = "([] : { S1[i,j] : i > j })";
8398 mupa2 = isl_multi_union_pw_aff_read_from_str(ctx, str);
8399 equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2);
8400 isl_multi_union_pw_aff_free(mupa2);
8401 isl_multi_union_pw_aff_free(mupa);
8402 isl_schedule_node_free(node);
8404 if (equal < 0)
8405 return -1;
8406 if (!equal)
8407 isl_die(ctx, isl_error_unknown, "unexpected prefix schedule",
8408 return -1);
8410 return 0;
8413 /* Check that the reaching domain elements and the prefix schedule
8414 * at a leaf node are the same before and after grouping.
8416 static int test_schedule_tree_group_1(isl_ctx *ctx)
8418 int equal;
8419 const char *str;
8420 isl_id *id;
8421 isl_union_set *uset;
8422 isl_multi_union_pw_aff *mupa;
8423 isl_union_pw_multi_aff *upma1, *upma2;
8424 isl_union_set *domain1, *domain2;
8425 isl_union_map *umap1, *umap2;
8426 isl_schedule_node *node;
8428 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
8429 uset = isl_union_set_read_from_str(ctx, str);
8430 node = isl_schedule_node_from_domain(uset);
8431 node = isl_schedule_node_child(node, 0);
8432 str = "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
8433 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
8434 node = isl_schedule_node_insert_partial_schedule(node, mupa);
8435 node = isl_schedule_node_child(node, 0);
8436 str = "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
8437 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
8438 node = isl_schedule_node_insert_partial_schedule(node, mupa);
8439 node = isl_schedule_node_child(node, 0);
8440 umap1 = isl_schedule_node_get_prefix_schedule_union_map(node);
8441 upma1 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node);
8442 domain1 = isl_schedule_node_get_domain(node);
8443 id = isl_id_alloc(ctx, "group", NULL);
8444 node = isl_schedule_node_parent(node);
8445 node = isl_schedule_node_group(node, id);
8446 node = isl_schedule_node_child(node, 0);
8447 umap2 = isl_schedule_node_get_prefix_schedule_union_map(node);
8448 upma2 = isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node);
8449 domain2 = isl_schedule_node_get_domain(node);
8450 equal = isl_union_pw_multi_aff_plain_is_equal(upma1, upma2);
8451 if (equal >= 0 && equal)
8452 equal = isl_union_set_is_equal(domain1, domain2);
8453 if (equal >= 0 && equal)
8454 equal = isl_union_map_is_equal(umap1, umap2);
8455 isl_union_map_free(umap1);
8456 isl_union_map_free(umap2);
8457 isl_union_set_free(domain1);
8458 isl_union_set_free(domain2);
8459 isl_union_pw_multi_aff_free(upma1);
8460 isl_union_pw_multi_aff_free(upma2);
8461 isl_schedule_node_free(node);
8463 if (equal < 0)
8464 return -1;
8465 if (!equal)
8466 isl_die(ctx, isl_error_unknown,
8467 "expressions not equal", return -1);
8469 return 0;
8472 /* Check that we can have nested groupings and that the union map
8473 * schedule representation is the same before and after the grouping.
8474 * Note that after the grouping, the union map representation contains
8475 * the domain constraints from the ranges of the expansion nodes,
8476 * while they are missing from the union map representation of
8477 * the tree without expansion nodes.
8479 * Also check that the global expansion is as expected.
8481 static int test_schedule_tree_group_2(isl_ctx *ctx)
8483 int equal, equal_expansion;
8484 const char *str;
8485 isl_id *id;
8486 isl_union_set *uset;
8487 isl_union_map *umap1, *umap2;
8488 isl_union_map *expansion1, *expansion2;
8489 isl_union_set_list *filters;
8490 isl_multi_union_pw_aff *mupa;
8491 isl_schedule *schedule;
8492 isl_schedule_node *node;
8494 str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
8495 "S3[i,j] : 0 <= i,j < 10 }";
8496 uset = isl_union_set_read_from_str(ctx, str);
8497 node = isl_schedule_node_from_domain(uset);
8498 node = isl_schedule_node_child(node, 0);
8499 str = "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
8500 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
8501 node = isl_schedule_node_insert_partial_schedule(node, mupa);
8502 node = isl_schedule_node_child(node, 0);
8503 str = "{ S1[i,j] }";
8504 uset = isl_union_set_read_from_str(ctx, str);
8505 filters = isl_union_set_list_from_union_set(uset);
8506 str = "{ S2[i,j]; S3[i,j] }";
8507 uset = isl_union_set_read_from_str(ctx, str);
8508 filters = isl_union_set_list_add(filters, uset);
8509 node = isl_schedule_node_insert_sequence(node, filters);
8510 node = isl_schedule_node_child(node, 1);
8511 node = isl_schedule_node_child(node, 0);
8512 str = "{ S2[i,j] }";
8513 uset = isl_union_set_read_from_str(ctx, str);
8514 filters = isl_union_set_list_from_union_set(uset);
8515 str = "{ S3[i,j] }";
8516 uset = isl_union_set_read_from_str(ctx, str);
8517 filters = isl_union_set_list_add(filters, uset);
8518 node = isl_schedule_node_insert_sequence(node, filters);
8520 schedule = isl_schedule_node_get_schedule(node);
8521 umap1 = isl_schedule_get_map(schedule);
8522 uset = isl_schedule_get_domain(schedule);
8523 umap1 = isl_union_map_intersect_domain(umap1, uset);
8524 isl_schedule_free(schedule);
8526 node = isl_schedule_node_parent(node);
8527 node = isl_schedule_node_parent(node);
8528 id = isl_id_alloc(ctx, "group1", NULL);
8529 node = isl_schedule_node_group(node, id);
8530 node = isl_schedule_node_child(node, 1);
8531 node = isl_schedule_node_child(node, 0);
8532 id = isl_id_alloc(ctx, "group2", NULL);
8533 node = isl_schedule_node_group(node, id);
8535 schedule = isl_schedule_node_get_schedule(node);
8536 umap2 = isl_schedule_get_map(schedule);
8537 isl_schedule_free(schedule);
8539 node = isl_schedule_node_root(node);
8540 node = isl_schedule_node_child(node, 0);
8541 expansion1 = isl_schedule_node_get_subtree_expansion(node);
8542 isl_schedule_node_free(node);
8544 str = "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
8545 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
8546 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
8548 expansion2 = isl_union_map_read_from_str(ctx, str);
8550 equal = isl_union_map_is_equal(umap1, umap2);
8551 equal_expansion = isl_union_map_is_equal(expansion1, expansion2);
8553 isl_union_map_free(umap1);
8554 isl_union_map_free(umap2);
8555 isl_union_map_free(expansion1);
8556 isl_union_map_free(expansion2);
8558 if (equal < 0 || equal_expansion < 0)
8559 return -1;
8560 if (!equal)
8561 isl_die(ctx, isl_error_unknown,
8562 "expressions not equal", return -1);
8563 if (!equal_expansion)
8564 isl_die(ctx, isl_error_unknown,
8565 "unexpected expansion", return -1);
8567 return 0;
8570 /* Some tests for the isl_schedule_node_group function.
8572 static int test_schedule_tree_group(isl_ctx *ctx)
8574 if (test_schedule_tree_group_1(ctx) < 0)
8575 return -1;
8576 if (test_schedule_tree_group_2(ctx) < 0)
8577 return -1;
8578 return 0;
8581 struct {
8582 const char *set;
8583 const char *dual;
8584 } coef_tests[] = {
8585 { "{ rat: [i] : 0 <= i <= 10 }",
8586 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
8587 { "{ rat: [i] : FALSE }",
8588 "{ rat: coefficients[[cst] -> [a]] }" },
8589 { "{ rat: [i] : }",
8590 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
8593 struct {
8594 const char *set;
8595 const char *dual;
8596 } sol_tests[] = {
8597 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
8598 "{ rat: [i] : 0 <= i <= 10 }" },
8599 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
8600 "{ rat: [i] }" },
8601 { "{ rat: coefficients[[cst] -> [a]] }",
8602 "{ rat: [i] : FALSE }" },
8605 /* Test the basic functionality of isl_basic_set_coefficients and
8606 * isl_basic_set_solutions.
8608 static int test_dual(isl_ctx *ctx)
8610 int i;
8612 for (i = 0; i < ARRAY_SIZE(coef_tests); ++i) {
8613 int equal;
8614 isl_basic_set *bset1, *bset2;
8616 bset1 = isl_basic_set_read_from_str(ctx, coef_tests[i].set);
8617 bset2 = isl_basic_set_read_from_str(ctx, coef_tests[i].dual);
8618 bset1 = isl_basic_set_coefficients(bset1);
8619 equal = isl_basic_set_is_equal(bset1, bset2);
8620 isl_basic_set_free(bset1);
8621 isl_basic_set_free(bset2);
8622 if (equal < 0)
8623 return -1;
8624 if (!equal)
8625 isl_die(ctx, isl_error_unknown,
8626 "incorrect dual", return -1);
8629 for (i = 0; i < ARRAY_SIZE(sol_tests); ++i) {
8630 int equal;
8631 isl_basic_set *bset1, *bset2;
8633 bset1 = isl_basic_set_read_from_str(ctx, sol_tests[i].set);
8634 bset2 = isl_basic_set_read_from_str(ctx, sol_tests[i].dual);
8635 bset1 = isl_basic_set_solutions(bset1);
8636 equal = isl_basic_set_is_equal(bset1, bset2);
8637 isl_basic_set_free(bset1);
8638 isl_basic_set_free(bset2);
8639 if (equal < 0)
8640 return -1;
8641 if (!equal)
8642 isl_die(ctx, isl_error_unknown,
8643 "incorrect dual", return -1);
8646 return 0;
8649 struct {
8650 int scale_tile;
8651 int shift_point;
8652 const char *domain;
8653 const char *schedule;
8654 const char *sizes;
8655 const char *tile;
8656 const char *point;
8657 } tile_tests[] = {
8658 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
8659 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8660 "{ [32,32] }",
8661 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
8662 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8664 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
8665 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8666 "{ [32,32] }",
8667 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
8668 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8670 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
8671 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8672 "{ [32,32] }",
8673 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
8674 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
8676 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
8677 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
8678 "{ [32,32] }",
8679 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
8680 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
8684 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
8685 * tile the band and then check if the tile and point bands have the
8686 * expected partial schedule.
8688 static int test_tile(isl_ctx *ctx)
8690 int i;
8691 int scale;
8692 int shift;
8694 scale = isl_options_get_tile_scale_tile_loops(ctx);
8695 shift = isl_options_get_tile_shift_point_loops(ctx);
8697 for (i = 0; i < ARRAY_SIZE(tile_tests); ++i) {
8698 int opt;
8699 int equal;
8700 const char *str;
8701 isl_union_set *domain;
8702 isl_multi_union_pw_aff *mupa, *mupa2;
8703 isl_schedule_node *node;
8704 isl_multi_val *sizes;
8706 opt = tile_tests[i].scale_tile;
8707 isl_options_set_tile_scale_tile_loops(ctx, opt);
8708 opt = tile_tests[i].shift_point;
8709 isl_options_set_tile_shift_point_loops(ctx, opt);
8711 str = tile_tests[i].domain;
8712 domain = isl_union_set_read_from_str(ctx, str);
8713 node = isl_schedule_node_from_domain(domain);
8714 node = isl_schedule_node_child(node, 0);
8715 str = tile_tests[i].schedule;
8716 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
8717 node = isl_schedule_node_insert_partial_schedule(node, mupa);
8718 str = tile_tests[i].sizes;
8719 sizes = isl_multi_val_read_from_str(ctx, str);
8720 node = isl_schedule_node_band_tile(node, sizes);
8722 str = tile_tests[i].tile;
8723 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
8724 mupa2 = isl_schedule_node_band_get_partial_schedule(node);
8725 equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2);
8726 isl_multi_union_pw_aff_free(mupa);
8727 isl_multi_union_pw_aff_free(mupa2);
8729 node = isl_schedule_node_child(node, 0);
8731 str = tile_tests[i].point;
8732 mupa = isl_multi_union_pw_aff_read_from_str(ctx, str);
8733 mupa2 = isl_schedule_node_band_get_partial_schedule(node);
8734 if (equal >= 0 && equal)
8735 equal = isl_multi_union_pw_aff_plain_is_equal(mupa,
8736 mupa2);
8737 isl_multi_union_pw_aff_free(mupa);
8738 isl_multi_union_pw_aff_free(mupa2);
8740 isl_schedule_node_free(node);
8742 if (equal < 0)
8743 return -1;
8744 if (!equal)
8745 isl_die(ctx, isl_error_unknown,
8746 "unexpected result", return -1);
8749 isl_options_set_tile_scale_tile_loops(ctx, scale);
8750 isl_options_set_tile_shift_point_loops(ctx, shift);
8752 return 0;
8755 /* Check that the domain hash of a space is equal to the hash
8756 * of the domain of the space.
8758 static int test_domain_hash(isl_ctx *ctx)
8760 isl_map *map;
8761 isl_space *space;
8762 uint32_t hash1, hash2;
8764 map = isl_map_read_from_str(ctx, "[n] -> { A[B[x] -> C[]] -> D[] }");
8765 space = isl_map_get_space(map);
8766 isl_map_free(map);
8767 hash1 = isl_space_get_domain_hash(space);
8768 space = isl_space_domain(space);
8769 hash2 = isl_space_get_hash(space);
8770 isl_space_free(space);
8772 if (!space)
8773 return -1;
8774 if (hash1 != hash2)
8775 isl_die(ctx, isl_error_unknown,
8776 "domain hash not equal to hash of domain", return -1);
8778 return 0;
8781 /* Check that a universe basic set that is not obviously equal to the universe
8782 * is still recognized as being equal to the universe.
8784 static int test_universe(isl_ctx *ctx)
8786 const char *s;
8787 isl_basic_set *bset;
8788 isl_bool is_univ;
8790 s = "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
8791 bset = isl_basic_set_read_from_str(ctx, s);
8792 is_univ = isl_basic_set_is_universe(bset);
8793 isl_basic_set_free(bset);
8795 if (is_univ < 0)
8796 return -1;
8797 if (!is_univ)
8798 isl_die(ctx, isl_error_unknown,
8799 "not recognized as universe set", return -1);
8801 return 0;
8804 /* Sets for which chambers are computed and checked.
8806 const char *chambers_tests[] = {
8807 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
8808 "z >= 0 and z <= C - y and z <= B - x - y }",
8811 /* Add the domain of "cell" to "cells".
8813 static isl_stat add_cell(__isl_take isl_cell *cell, void *user)
8815 isl_basic_set_list **cells = user;
8816 isl_basic_set *dom;
8818 dom = isl_cell_get_domain(cell);
8819 isl_cell_free(cell);
8820 *cells = isl_basic_set_list_add(*cells, dom);
8822 return *cells ? isl_stat_ok : isl_stat_error;
8825 /* Check that the elements of "list" are pairwise disjoint.
8827 static isl_stat check_pairwise_disjoint(__isl_keep isl_basic_set_list *list)
8829 int i, j, n;
8831 if (!list)
8832 return isl_stat_error;
8834 n = isl_basic_set_list_n_basic_set(list);
8835 for (i = 0; i < n; ++i) {
8836 isl_basic_set *bset_i;
8838 bset_i = isl_basic_set_list_get_basic_set(list, i);
8839 for (j = i + 1; j < n; ++j) {
8840 isl_basic_set *bset_j;
8841 isl_bool disjoint;
8843 bset_j = isl_basic_set_list_get_basic_set(list, j);
8844 disjoint = isl_basic_set_is_disjoint(bset_i, bset_j);
8845 isl_basic_set_free(bset_j);
8846 if (!disjoint)
8847 isl_die(isl_basic_set_list_get_ctx(list),
8848 isl_error_unknown, "not disjoint",
8849 break);
8850 if (disjoint < 0 || !disjoint)
8851 break;
8853 isl_basic_set_free(bset_i);
8854 if (j < n)
8855 return isl_stat_error;
8858 return isl_stat_ok;
8861 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
8862 * are pairwise disjoint.
8864 static int test_chambers(isl_ctx *ctx)
8866 int i;
8868 for (i = 0; i < ARRAY_SIZE(chambers_tests); ++i) {
8869 isl_basic_set *bset;
8870 isl_vertices *vertices;
8871 isl_basic_set_list *cells;
8872 isl_stat ok;
8874 bset = isl_basic_set_read_from_str(ctx, chambers_tests[i]);
8875 vertices = isl_basic_set_compute_vertices(bset);
8876 cells = isl_basic_set_list_alloc(ctx, 0);
8877 if (isl_vertices_foreach_disjoint_cell(vertices, &add_cell,
8878 &cells) < 0)
8879 cells = isl_basic_set_list_free(cells);
8880 ok = check_pairwise_disjoint(cells);
8881 isl_basic_set_list_free(cells);
8882 isl_vertices_free(vertices);
8883 isl_basic_set_free(bset);
8885 if (ok < 0)
8886 return -1;
8889 return 0;
8892 struct {
8893 const char *name;
8894 int (*fn)(isl_ctx *ctx);
8895 } tests [] = {
8896 { "universe", &test_universe },
8897 { "domain hash", &test_domain_hash },
8898 { "dual", &test_dual },
8899 { "dependence analysis", &test_flow },
8900 { "val", &test_val },
8901 { "compute divs", &test_compute_divs },
8902 { "partial lexmin", &test_partial_lexmin },
8903 { "simplify", &test_simplify },
8904 { "curry", &test_curry },
8905 { "piecewise multi affine expressions", &test_pw_multi_aff },
8906 { "multi piecewise affine expressions", &test_multi_pw_aff },
8907 { "conversion", &test_conversion },
8908 { "list", &test_list },
8909 { "align parameters", &test_align_parameters },
8910 { "preimage", &test_preimage },
8911 { "pullback", &test_pullback },
8912 { "AST", &test_ast },
8913 { "AST build", &test_ast_build },
8914 { "AST generation", &test_ast_gen },
8915 { "eliminate", &test_eliminate },
8916 { "residue class", &test_residue_class },
8917 { "div", &test_div },
8918 { "slice", &test_slice },
8919 { "fixed power", &test_fixed_power },
8920 { "sample", &test_sample },
8921 { "output", &test_output },
8922 { "vertices", &test_vertices },
8923 { "chambers", &test_chambers },
8924 { "fixed", &test_fixed },
8925 { "equal", &test_equal },
8926 { "disjoint", &test_disjoint },
8927 { "product", &test_product },
8928 { "dim_max", &test_dim_max },
8929 { "affine", &test_aff },
8930 { "injective", &test_injective },
8931 { "schedule (whole component)", &test_schedule_whole },
8932 { "schedule (incremental)", &test_schedule_incremental },
8933 { "schedule tree", &test_schedule_tree },
8934 { "schedule tree prefix", &test_schedule_tree_prefix },
8935 { "schedule tree grouping", &test_schedule_tree_group },
8936 { "tile", &test_tile },
8937 { "union_pw", &test_union_pw },
8938 { "locus", &test_locus },
8939 { "eval", &test_eval },
8940 { "parse", &test_parse },
8941 { "single-valued", &test_sv },
8942 { "affine hull", &test_affine_hull },
8943 { "simple_hull", &test_simple_hull },
8944 { "coalesce", &test_coalesce },
8945 { "factorize", &test_factorize },
8946 { "subset", &test_subset },
8947 { "subtract", &test_subtract },
8948 { "intersect", &test_intersect },
8949 { "lexmin", &test_lexmin },
8950 { "min", &test_min },
8951 { "gist", &test_gist },
8952 { "piecewise quasi-polynomials", &test_pwqp },
8953 { "lift", &test_lift },
8954 { "bound", &test_bound },
8955 { "union", &test_union },
8956 { "split periods", &test_split_periods },
8957 { "lexicographic order", &test_lex },
8958 { "bijectivity", &test_bijective },
8959 { "dataflow analysis", &test_dep },
8960 { "reading", &test_read },
8961 { "bounded", &test_bounded },
8962 { "construction", &test_construction },
8963 { "dimension manipulation", &test_dim },
8964 { "map application", &test_application },
8965 { "convex hull", &test_convex_hull },
8966 { "transitive closure", &test_closure },
8969 int main(int argc, char **argv)
8971 int i;
8972 struct isl_ctx *ctx;
8973 struct isl_options *options;
8975 options = isl_options_new_with_defaults();
8976 assert(options);
8977 argc = isl_options_parse(options, argc, argv, ISL_ARG_ALL);
8979 ctx = isl_ctx_alloc_with_options(&isl_options_args, options);
8980 for (i = 0; i < ARRAY_SIZE(tests); ++i) {
8981 printf("%s\n", tests[i].name);
8982 if (tests[i].fn(ctx) < 0)
8983 goto error;
8985 isl_ctx_free(ctx);
8986 return 0;
8987 error:
8988 isl_ctx_free(ctx);
8989 return -1;