doc/SubmittingPatches: explain how to submit patch revisions
[isl.git] / isl_test.c
blobd1928100e1d0aa2a860d75fdbe70ddbe461a9156
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
6 * Use of this software is governed by the MIT license
8 * Written by Sven Verdoolaege, K.U.Leuven, Departement
9 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
10 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
11 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
12 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
15 #include <assert.h>
16 #include <stdio.h>
17 #include <limits.h>
18 #include <isl_ctx_private.h>
19 #include <isl_map_private.h>
20 #include <isl_aff_private.h>
21 #include <isl/set.h>
22 #include <isl/flow.h>
23 #include <isl_constraint_private.h>
24 #include <isl/polynomial.h>
25 #include <isl/union_map.h>
26 #include <isl_factorization.h>
27 #include <isl/schedule.h>
28 #include <isl_options_private.h>
29 #include <isl/vertices.h>
30 #include <isl/ast_build.h>
31 #include <isl/val.h>
32 #include <isl/ilp.h>
34 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
36 static char *srcdir;
38 static char *get_filename(isl_ctx *ctx, const char *name, const char *suffix) {
39 char *filename;
40 int length;
41 char *pattern = "%s/test_inputs/%s.%s";
43 length = strlen(pattern) - 6 + strlen(srcdir) + strlen(name)
44 + strlen(suffix) + 1;
45 filename = isl_alloc_array(ctx, char, length);
47 if (!filename)
48 return NULL;
50 sprintf(filename, pattern, srcdir, name, suffix);
52 return filename;
55 void test_parse_map(isl_ctx *ctx, const char *str)
57 isl_map *map;
59 map = isl_map_read_from_str(ctx, str);
60 assert(map);
61 isl_map_free(map);
64 int test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
66 isl_map *map, *map2;
67 int equal;
69 map = isl_map_read_from_str(ctx, str);
70 map2 = isl_map_read_from_str(ctx, str2);
71 equal = isl_map_is_equal(map, map2);
72 isl_map_free(map);
73 isl_map_free(map2);
75 if (equal < 0)
76 return -1;
77 if (!equal)
78 isl_die(ctx, isl_error_unknown, "maps not equal",
79 return -1);
81 return 0;
84 void test_parse_pwqp(isl_ctx *ctx, const char *str)
86 isl_pw_qpolynomial *pwqp;
88 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
89 assert(pwqp);
90 isl_pw_qpolynomial_free(pwqp);
93 static void test_parse_pwaff(isl_ctx *ctx, const char *str)
95 isl_pw_aff *pwaff;
97 pwaff = isl_pw_aff_read_from_str(ctx, str);
98 assert(pwaff);
99 isl_pw_aff_free(pwaff);
102 int test_parse(struct isl_ctx *ctx)
104 isl_map *map, *map2;
105 const char *str, *str2;
107 str = "{ [i] -> [-i] }";
108 map = isl_map_read_from_str(ctx, str);
109 assert(map);
110 isl_map_free(map);
112 str = "{ A[i] -> L[([i/3])] }";
113 map = isl_map_read_from_str(ctx, str);
114 assert(map);
115 isl_map_free(map);
117 test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
118 test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : "
119 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
121 str = "{ [x,y] : [([x/2]+y)/3] >= 1 }";
122 str2 = "{ [x, y] : 2y >= 6 - x }";
123 if (test_parse_map_equal(ctx, str, str2) < 0)
124 return -1;
126 if (test_parse_map_equal(ctx, "{ [x,y] : x <= min(y, 2*y+3) }",
127 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
128 return -1;
129 str = "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
130 if (test_parse_map_equal(ctx, "{ [x,y] : x >= min(y, 2*y+3) }",
131 str) < 0)
132 return -1;
134 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
135 map = isl_map_read_from_str(ctx, str);
136 str = "{ [new, old] -> [o0, o1] : "
137 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
138 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
139 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
140 map2 = isl_map_read_from_str(ctx, str);
141 assert(isl_map_is_equal(map, map2));
142 isl_map_free(map);
143 isl_map_free(map2);
145 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
146 map = isl_map_read_from_str(ctx, str);
147 str = "{[new,old] -> [(new+1)%2,(old+1)%2]}";
148 map2 = isl_map_read_from_str(ctx, str);
149 assert(isl_map_is_equal(map, map2));
150 isl_map_free(map);
151 isl_map_free(map2);
153 str = "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
154 str2 = "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
155 if (test_parse_map_equal(ctx, str, str2) < 0)
156 return -1;
158 str = "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
159 str2 = "{ [i,j] -> [min(i,j)] }";
160 if (test_parse_map_equal(ctx, str, str2) < 0)
161 return -1;
163 str = "{ [i,j] : i != j }";
164 str2 = "{ [i,j] : i < j or i > j }";
165 if (test_parse_map_equal(ctx, str, str2) < 0)
166 return -1;
168 str = "{ [i,j] : (i+1)*2 >= j }";
169 str2 = "{ [i, j] : j <= 2 + 2i }";
170 if (test_parse_map_equal(ctx, str, str2) < 0)
171 return -1;
173 str = "{ [i] -> [i > 0 ? 4 : 5] }";
174 str2 = "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
175 if (test_parse_map_equal(ctx, str, str2) < 0)
176 return -1;
178 str = "[N=2,M] -> { [i=[(M+N)/4]] }";
179 str2 = "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
180 if (test_parse_map_equal(ctx, str, str2) < 0)
181 return -1;
183 str = "{ [x] : x >= 0 }";
184 str2 = "{ [x] : x-0 >= 0 }";
185 if (test_parse_map_equal(ctx, str, str2) < 0)
186 return -1;
188 str = "{ [i] : ((i > 10)) }";
189 str2 = "{ [i] : i >= 11 }";
190 if (test_parse_map_equal(ctx, str, str2) < 0)
191 return -1;
193 str = "{ [i] -> [0] }";
194 str2 = "{ [i] -> [0 * i] }";
195 if (test_parse_map_equal(ctx, str, str2) < 0)
196 return -1;
198 test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
199 test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
200 test_parse_pwaff(ctx, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
201 test_parse_pwqp(ctx, "{ [x] -> ([(x)/2] * [(x)/3]) }");
203 if (test_parse_map_equal(ctx, "{ [a] -> [b] : (not false) }",
204 "{ [a] -> [b] : true }") < 0)
205 return -1;
207 if (test_parse_map_equal(ctx, "{ [i] : i/2 <= 5 }",
208 "{ [i] : i <= 10 }") < 0)
209 return -1;
211 if (test_parse_map_equal(ctx, "{Sym=[n] [i] : i <= n }",
212 "[n] -> { [i] : i <= n }") < 0)
213 return -1;
215 if (test_parse_map_equal(ctx, "{ [*] }", "{ [a] }") < 0)
216 return -1;
218 if (test_parse_map_equal(ctx, "{ [i] : 2*floor(i/2) = i }",
219 "{ [i] : exists a : i = 2 a }") < 0)
220 return -1;
222 if (test_parse_map_equal(ctx, "{ [a] -> [b] : a = 5 implies b = 5 }",
223 "{ [a] -> [b] : a != 5 or b = 5 }") < 0)
224 return -1;
226 if (test_parse_map_equal(ctx, "{ [a] -> [a - 1 : a > 0] }",
227 "{ [a] -> [a - 1] : a > 0 }") < 0)
228 return -1;
229 if (test_parse_map_equal(ctx,
230 "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
231 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }") < 0)
232 return -1;
233 if (test_parse_map_equal(ctx,
234 "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
235 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
236 return -1;
237 if (test_parse_map_equal(ctx,
238 "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
239 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
240 return -1;
241 if (test_parse_map_equal(ctx,
242 "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
243 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
244 return -1;
245 if (test_parse_map_equal(ctx,
246 "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
247 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
248 return -1;
250 return 0;
253 void test_read(struct isl_ctx *ctx)
255 char *filename;
256 FILE *input;
257 struct isl_basic_set *bset1, *bset2;
258 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
260 filename = get_filename(ctx, "set", "omega");
261 assert(filename);
262 input = fopen(filename, "r");
263 assert(input);
265 bset1 = isl_basic_set_read_from_file(ctx, input);
266 bset2 = isl_basic_set_read_from_str(ctx, str);
268 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
270 isl_basic_set_free(bset1);
271 isl_basic_set_free(bset2);
272 free(filename);
274 fclose(input);
277 void test_bounded(struct isl_ctx *ctx)
279 isl_set *set;
280 int bounded;
282 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }");
283 bounded = isl_set_is_bounded(set);
284 assert(bounded);
285 isl_set_free(set);
287 set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }");
288 bounded = isl_set_is_bounded(set);
289 assert(!bounded);
290 isl_set_free(set);
292 set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }");
293 bounded = isl_set_is_bounded(set);
294 assert(!bounded);
295 isl_set_free(set);
298 /* Construct the basic set { [i] : 5 <= i <= N } */
299 void test_construction(struct isl_ctx *ctx)
301 isl_int v;
302 isl_space *dim;
303 isl_local_space *ls;
304 struct isl_basic_set *bset;
305 struct isl_constraint *c;
307 isl_int_init(v);
309 dim = isl_space_set_alloc(ctx, 1, 1);
310 bset = isl_basic_set_universe(isl_space_copy(dim));
311 ls = isl_local_space_from_space(dim);
313 c = isl_inequality_alloc(isl_local_space_copy(ls));
314 isl_int_set_si(v, -1);
315 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
316 isl_int_set_si(v, 1);
317 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
318 bset = isl_basic_set_add_constraint(bset, c);
320 c = isl_inequality_alloc(isl_local_space_copy(ls));
321 isl_int_set_si(v, 1);
322 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
323 isl_int_set_si(v, -5);
324 isl_constraint_set_constant(c, v);
325 bset = isl_basic_set_add_constraint(bset, c);
327 isl_local_space_free(ls);
328 isl_basic_set_free(bset);
330 isl_int_clear(v);
333 void test_dim(struct isl_ctx *ctx)
335 const char *str;
336 isl_map *map1, *map2;
338 map1 = isl_map_read_from_str(ctx,
339 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
340 map1 = isl_map_add_dims(map1, isl_dim_in, 1);
341 map2 = isl_map_read_from_str(ctx,
342 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
343 assert(isl_map_is_equal(map1, map2));
344 isl_map_free(map2);
346 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
347 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }");
348 assert(isl_map_is_equal(map1, map2));
350 isl_map_free(map1);
351 isl_map_free(map2);
353 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
354 map1 = isl_map_read_from_str(ctx, str);
355 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
356 map2 = isl_map_read_from_str(ctx, str);
357 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
358 assert(isl_map_is_equal(map1, map2));
360 isl_map_free(map1);
361 isl_map_free(map2);
364 struct {
365 __isl_give isl_val *(*op)(__isl_take isl_val *v);
366 const char *arg;
367 const char *res;
368 } val_un_tests[] = {
369 { &isl_val_neg, "0", "0" },
370 { &isl_val_abs, "0", "0" },
371 { &isl_val_2exp, "0", "1" },
372 { &isl_val_floor, "0", "0" },
373 { &isl_val_ceil, "0", "0" },
374 { &isl_val_neg, "1", "-1" },
375 { &isl_val_neg, "-1", "1" },
376 { &isl_val_neg, "1/2", "-1/2" },
377 { &isl_val_neg, "-1/2", "1/2" },
378 { &isl_val_neg, "infty", "-infty" },
379 { &isl_val_neg, "-infty", "infty" },
380 { &isl_val_neg, "NaN", "NaN" },
381 { &isl_val_abs, "1", "1" },
382 { &isl_val_abs, "-1", "1" },
383 { &isl_val_abs, "1/2", "1/2" },
384 { &isl_val_abs, "-1/2", "1/2" },
385 { &isl_val_abs, "infty", "infty" },
386 { &isl_val_abs, "-infty", "infty" },
387 { &isl_val_abs, "NaN", "NaN" },
388 { &isl_val_floor, "1", "1" },
389 { &isl_val_floor, "-1", "-1" },
390 { &isl_val_floor, "1/2", "0" },
391 { &isl_val_floor, "-1/2", "-1" },
392 { &isl_val_floor, "infty", "infty" },
393 { &isl_val_floor, "-infty", "-infty" },
394 { &isl_val_floor, "NaN", "NaN" },
395 { &isl_val_ceil, "1", "1" },
396 { &isl_val_ceil, "-1", "-1" },
397 { &isl_val_ceil, "1/2", "1" },
398 { &isl_val_ceil, "-1/2", "0" },
399 { &isl_val_ceil, "infty", "infty" },
400 { &isl_val_ceil, "-infty", "-infty" },
401 { &isl_val_ceil, "NaN", "NaN" },
402 { &isl_val_2exp, "-3", "1/8" },
403 { &isl_val_2exp, "-1", "1/2" },
404 { &isl_val_2exp, "1", "2" },
405 { &isl_val_2exp, "2", "4" },
406 { &isl_val_2exp, "3", "8" },
409 /* Perform some basic tests of unary operations on isl_val objects.
411 static int test_un_val(isl_ctx *ctx)
413 int i;
414 isl_val *v, *res;
415 __isl_give isl_val *(*fn)(__isl_take isl_val *v);
416 int ok;
418 for (i = 0; i < ARRAY_SIZE(val_un_tests); ++i) {
419 v = isl_val_read_from_str(ctx, val_un_tests[i].arg);
420 res = isl_val_read_from_str(ctx, val_un_tests[i].res);
421 fn = val_un_tests[i].op;
422 v = fn(v);
423 if (isl_val_is_nan(res))
424 ok = isl_val_is_nan(v);
425 else
426 ok = isl_val_eq(v, res);
427 isl_val_free(v);
428 isl_val_free(res);
429 if (ok < 0)
430 return -1;
431 if (!ok)
432 isl_die(ctx, isl_error_unknown,
433 "unexpected result", return -1);
436 return 0;
439 struct {
440 __isl_give isl_val *(*fn)(__isl_take isl_val *v1,
441 __isl_take isl_val *v2);
442 } val_bin_op[] = {
443 ['+'] = { &isl_val_add },
444 ['-'] = { &isl_val_sub },
445 ['*'] = { &isl_val_mul },
446 ['/'] = { &isl_val_div },
447 ['g'] = { &isl_val_gcd },
448 ['m'] = { &isl_val_min },
449 ['M'] = { &isl_val_max },
452 struct {
453 const char *arg1;
454 unsigned char op;
455 const char *arg2;
456 const char *res;
457 } val_bin_tests[] = {
458 { "0", '+', "0", "0" },
459 { "1", '+', "0", "1" },
460 { "1", '+', "1", "2" },
461 { "1", '-', "1", "0" },
462 { "1", '*', "1", "1" },
463 { "1", '/', "1", "1" },
464 { "2", '*', "3", "6" },
465 { "2", '*', "1/2", "1" },
466 { "2", '*', "1/3", "2/3" },
467 { "2/3", '*', "3/5", "2/5" },
468 { "2/3", '*', "7/5", "14/15" },
469 { "2", '/', "1/2", "4" },
470 { "-2", '/', "-1/2", "4" },
471 { "-2", '/', "1/2", "-4" },
472 { "2", '/', "-1/2", "-4" },
473 { "2", '/', "2", "1" },
474 { "2", '/', "3", "2/3" },
475 { "2/3", '/', "5/3", "2/5" },
476 { "2/3", '/', "5/7", "14/15" },
477 { "0", '/', "0", "NaN" },
478 { "42", '/', "0", "NaN" },
479 { "-42", '/', "0", "NaN" },
480 { "infty", '/', "0", "NaN" },
481 { "-infty", '/', "0", "NaN" },
482 { "NaN", '/', "0", "NaN" },
483 { "0", '/', "NaN", "NaN" },
484 { "42", '/', "NaN", "NaN" },
485 { "-42", '/', "NaN", "NaN" },
486 { "infty", '/', "NaN", "NaN" },
487 { "-infty", '/', "NaN", "NaN" },
488 { "NaN", '/', "NaN", "NaN" },
489 { "0", '/', "infty", "0" },
490 { "42", '/', "infty", "0" },
491 { "-42", '/', "infty", "0" },
492 { "infty", '/', "infty", "NaN" },
493 { "-infty", '/', "infty", "NaN" },
494 { "NaN", '/', "infty", "NaN" },
495 { "0", '/', "-infty", "0" },
496 { "42", '/', "-infty", "0" },
497 { "-42", '/', "-infty", "0" },
498 { "infty", '/', "-infty", "NaN" },
499 { "-infty", '/', "-infty", "NaN" },
500 { "NaN", '/', "-infty", "NaN" },
501 { "1", '-', "1/3", "2/3" },
502 { "1/3", '+', "1/2", "5/6" },
503 { "1/2", '+', "1/2", "1" },
504 { "3/4", '-', "1/4", "1/2" },
505 { "1/2", '-', "1/3", "1/6" },
506 { "infty", '+', "42", "infty" },
507 { "infty", '+', "infty", "infty" },
508 { "42", '+', "infty", "infty" },
509 { "infty", '-', "infty", "NaN" },
510 { "infty", '*', "infty", "infty" },
511 { "infty", '*', "-infty", "-infty" },
512 { "-infty", '*', "infty", "-infty" },
513 { "-infty", '*', "-infty", "infty" },
514 { "0", '*', "infty", "NaN" },
515 { "1", '*', "infty", "infty" },
516 { "infty", '*', "0", "NaN" },
517 { "infty", '*', "42", "infty" },
518 { "42", '-', "infty", "-infty" },
519 { "infty", '+', "-infty", "NaN" },
520 { "4", 'g', "6", "2" },
521 { "5", 'g', "6", "1" },
522 { "42", 'm', "3", "3" },
523 { "42", 'M', "3", "42" },
524 { "3", 'm', "42", "3" },
525 { "3", 'M', "42", "42" },
526 { "42", 'm', "infty", "42" },
527 { "42", 'M', "infty", "infty" },
528 { "42", 'm', "-infty", "-infty" },
529 { "42", 'M', "-infty", "42" },
530 { "42", 'm', "NaN", "NaN" },
531 { "42", 'M', "NaN", "NaN" },
532 { "infty", 'm', "-infty", "-infty" },
533 { "infty", 'M', "-infty", "infty" },
536 /* Perform some basic tests of binary operations on isl_val objects.
538 static int test_bin_val(isl_ctx *ctx)
540 int i;
541 isl_val *v1, *v2, *res;
542 __isl_give isl_val *(*fn)(__isl_take isl_val *v1,
543 __isl_take isl_val *v2);
544 int ok;
546 for (i = 0; i < ARRAY_SIZE(val_bin_tests); ++i) {
547 v1 = isl_val_read_from_str(ctx, val_bin_tests[i].arg1);
548 v2 = isl_val_read_from_str(ctx, val_bin_tests[i].arg2);
549 res = isl_val_read_from_str(ctx, val_bin_tests[i].res);
550 fn = val_bin_op[val_bin_tests[i].op].fn;
551 v1 = fn(v1, v2);
552 if (isl_val_is_nan(res))
553 ok = isl_val_is_nan(v1);
554 else
555 ok = isl_val_eq(v1, res);
556 isl_val_free(v1);
557 isl_val_free(res);
558 if (ok < 0)
559 return -1;
560 if (!ok)
561 isl_die(ctx, isl_error_unknown,
562 "unexpected result", return -1);
565 return 0;
568 /* Perform some basic tests on isl_val objects.
570 static int test_val(isl_ctx *ctx)
572 if (test_un_val(ctx) < 0)
573 return -1;
574 if (test_bin_val(ctx) < 0)
575 return -1;
576 return 0;
579 static int test_div(isl_ctx *ctx)
581 unsigned n;
582 const char *str;
583 int empty;
584 isl_int v;
585 isl_space *dim;
586 isl_set *set;
587 isl_local_space *ls;
588 struct isl_basic_set *bset;
589 struct isl_constraint *c;
591 isl_int_init(v);
593 /* test 1 */
594 dim = isl_space_set_alloc(ctx, 0, 3);
595 bset = isl_basic_set_universe(isl_space_copy(dim));
596 ls = isl_local_space_from_space(dim);
598 c = isl_equality_alloc(isl_local_space_copy(ls));
599 isl_int_set_si(v, -1);
600 isl_constraint_set_constant(c, v);
601 isl_int_set_si(v, 1);
602 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
603 isl_int_set_si(v, 3);
604 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
605 bset = isl_basic_set_add_constraint(bset, c);
607 c = isl_equality_alloc(isl_local_space_copy(ls));
608 isl_int_set_si(v, 1);
609 isl_constraint_set_constant(c, v);
610 isl_int_set_si(v, -1);
611 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
612 isl_int_set_si(v, 3);
613 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
614 bset = isl_basic_set_add_constraint(bset, c);
616 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
618 assert(bset && bset->n_div == 1);
619 isl_local_space_free(ls);
620 isl_basic_set_free(bset);
622 /* test 2 */
623 dim = isl_space_set_alloc(ctx, 0, 3);
624 bset = isl_basic_set_universe(isl_space_copy(dim));
625 ls = isl_local_space_from_space(dim);
627 c = isl_equality_alloc(isl_local_space_copy(ls));
628 isl_int_set_si(v, 1);
629 isl_constraint_set_constant(c, v);
630 isl_int_set_si(v, -1);
631 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
632 isl_int_set_si(v, 3);
633 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
634 bset = isl_basic_set_add_constraint(bset, c);
636 c = isl_equality_alloc(isl_local_space_copy(ls));
637 isl_int_set_si(v, -1);
638 isl_constraint_set_constant(c, v);
639 isl_int_set_si(v, 1);
640 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
641 isl_int_set_si(v, 3);
642 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
643 bset = isl_basic_set_add_constraint(bset, c);
645 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
647 assert(bset && bset->n_div == 1);
648 isl_local_space_free(ls);
649 isl_basic_set_free(bset);
651 /* test 3 */
652 dim = isl_space_set_alloc(ctx, 0, 3);
653 bset = isl_basic_set_universe(isl_space_copy(dim));
654 ls = isl_local_space_from_space(dim);
656 c = isl_equality_alloc(isl_local_space_copy(ls));
657 isl_int_set_si(v, 1);
658 isl_constraint_set_constant(c, v);
659 isl_int_set_si(v, -1);
660 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
661 isl_int_set_si(v, 3);
662 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
663 bset = isl_basic_set_add_constraint(bset, c);
665 c = isl_equality_alloc(isl_local_space_copy(ls));
666 isl_int_set_si(v, -3);
667 isl_constraint_set_constant(c, v);
668 isl_int_set_si(v, 1);
669 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
670 isl_int_set_si(v, 4);
671 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
672 bset = isl_basic_set_add_constraint(bset, c);
674 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
676 assert(bset && bset->n_div == 1);
677 isl_local_space_free(ls);
678 isl_basic_set_free(bset);
680 /* test 4 */
681 dim = isl_space_set_alloc(ctx, 0, 3);
682 bset = isl_basic_set_universe(isl_space_copy(dim));
683 ls = isl_local_space_from_space(dim);
685 c = isl_equality_alloc(isl_local_space_copy(ls));
686 isl_int_set_si(v, 2);
687 isl_constraint_set_constant(c, v);
688 isl_int_set_si(v, -1);
689 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
690 isl_int_set_si(v, 3);
691 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
692 bset = isl_basic_set_add_constraint(bset, c);
694 c = isl_equality_alloc(isl_local_space_copy(ls));
695 isl_int_set_si(v, -1);
696 isl_constraint_set_constant(c, v);
697 isl_int_set_si(v, 1);
698 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
699 isl_int_set_si(v, 6);
700 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
701 bset = isl_basic_set_add_constraint(bset, c);
703 bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 2);
705 assert(isl_basic_set_is_empty(bset));
706 isl_local_space_free(ls);
707 isl_basic_set_free(bset);
709 /* test 5 */
710 dim = isl_space_set_alloc(ctx, 0, 3);
711 bset = isl_basic_set_universe(isl_space_copy(dim));
712 ls = isl_local_space_from_space(dim);
714 c = isl_equality_alloc(isl_local_space_copy(ls));
715 isl_int_set_si(v, -1);
716 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
717 isl_int_set_si(v, 3);
718 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
719 bset = isl_basic_set_add_constraint(bset, c);
721 c = isl_equality_alloc(isl_local_space_copy(ls));
722 isl_int_set_si(v, 1);
723 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
724 isl_int_set_si(v, -3);
725 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
726 bset = isl_basic_set_add_constraint(bset, c);
728 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
730 assert(bset && bset->n_div == 0);
731 isl_basic_set_free(bset);
732 isl_local_space_free(ls);
734 /* test 6 */
735 dim = isl_space_set_alloc(ctx, 0, 3);
736 bset = isl_basic_set_universe(isl_space_copy(dim));
737 ls = isl_local_space_from_space(dim);
739 c = isl_equality_alloc(isl_local_space_copy(ls));
740 isl_int_set_si(v, -1);
741 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
742 isl_int_set_si(v, 6);
743 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
744 bset = isl_basic_set_add_constraint(bset, c);
746 c = isl_equality_alloc(isl_local_space_copy(ls));
747 isl_int_set_si(v, 1);
748 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
749 isl_int_set_si(v, -3);
750 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
751 bset = isl_basic_set_add_constraint(bset, c);
753 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
755 assert(bset && bset->n_div == 1);
756 isl_basic_set_free(bset);
757 isl_local_space_free(ls);
759 /* test 7 */
760 /* This test is a bit tricky. We set up an equality
761 * a + 3b + 3c = 6 e0
762 * Normalization of divs creates _two_ divs
763 * a = 3 e0
764 * c - b - e0 = 2 e1
765 * Afterwards e0 is removed again because it has coefficient -1
766 * and we end up with the original equality and div again.
767 * Perhaps we can avoid the introduction of this temporary div.
769 dim = isl_space_set_alloc(ctx, 0, 4);
770 bset = isl_basic_set_universe(isl_space_copy(dim));
771 ls = isl_local_space_from_space(dim);
773 c = isl_equality_alloc(isl_local_space_copy(ls));
774 isl_int_set_si(v, -1);
775 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
776 isl_int_set_si(v, -3);
777 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
778 isl_int_set_si(v, -3);
779 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
780 isl_int_set_si(v, 6);
781 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
782 bset = isl_basic_set_add_constraint(bset, c);
784 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
786 /* Test disabled for now */
788 assert(bset && bset->n_div == 1);
790 isl_local_space_free(ls);
791 isl_basic_set_free(bset);
793 /* test 8 */
794 dim = isl_space_set_alloc(ctx, 0, 5);
795 bset = isl_basic_set_universe(isl_space_copy(dim));
796 ls = isl_local_space_from_space(dim);
798 c = isl_equality_alloc(isl_local_space_copy(ls));
799 isl_int_set_si(v, -1);
800 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
801 isl_int_set_si(v, -3);
802 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
803 isl_int_set_si(v, -3);
804 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
805 isl_int_set_si(v, 6);
806 isl_constraint_set_coefficient(c, isl_dim_set, 4, v);
807 bset = isl_basic_set_add_constraint(bset, c);
809 c = isl_equality_alloc(isl_local_space_copy(ls));
810 isl_int_set_si(v, -1);
811 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
812 isl_int_set_si(v, 1);
813 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
814 isl_int_set_si(v, 1);
815 isl_constraint_set_constant(c, v);
816 bset = isl_basic_set_add_constraint(bset, c);
818 bset = isl_basic_set_project_out(bset, isl_dim_set, 4, 1);
820 /* Test disabled for now */
822 assert(bset && bset->n_div == 1);
824 isl_local_space_free(ls);
825 isl_basic_set_free(bset);
827 /* test 9 */
828 dim = isl_space_set_alloc(ctx, 0, 4);
829 bset = isl_basic_set_universe(isl_space_copy(dim));
830 ls = isl_local_space_from_space(dim);
832 c = isl_equality_alloc(isl_local_space_copy(ls));
833 isl_int_set_si(v, 1);
834 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
835 isl_int_set_si(v, -1);
836 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
837 isl_int_set_si(v, -2);
838 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
839 bset = isl_basic_set_add_constraint(bset, c);
841 c = isl_equality_alloc(isl_local_space_copy(ls));
842 isl_int_set_si(v, -1);
843 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
844 isl_int_set_si(v, 3);
845 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
846 isl_int_set_si(v, 2);
847 isl_constraint_set_constant(c, v);
848 bset = isl_basic_set_add_constraint(bset, c);
850 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 2);
852 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
854 assert(!isl_basic_set_is_empty(bset));
856 isl_local_space_free(ls);
857 isl_basic_set_free(bset);
859 /* test 10 */
860 dim = isl_space_set_alloc(ctx, 0, 3);
861 bset = isl_basic_set_universe(isl_space_copy(dim));
862 ls = isl_local_space_from_space(dim);
864 c = isl_equality_alloc(isl_local_space_copy(ls));
865 isl_int_set_si(v, 1);
866 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
867 isl_int_set_si(v, -2);
868 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
869 bset = isl_basic_set_add_constraint(bset, c);
871 bset = isl_basic_set_project_out(bset, isl_dim_set, 2, 1);
873 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
875 isl_local_space_free(ls);
876 isl_basic_set_free(bset);
878 isl_int_clear(v);
880 str = "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
881 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
882 set = isl_set_read_from_str(ctx, str);
883 set = isl_set_compute_divs(set);
884 isl_set_free(set);
885 if (!set)
886 return -1;
888 str = "{ [i,j] : 2*[i/2] + 3 * [j/4] <= 10 and 2 i = j }";
889 bset = isl_basic_set_read_from_str(ctx, str);
890 n = isl_basic_set_dim(bset, isl_dim_div);
891 isl_basic_set_free(bset);
892 if (!bset)
893 return -1;
894 if (n != 0)
895 isl_die(ctx, isl_error_unknown,
896 "expecting no existentials", return -1);
898 str = "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
899 set = isl_set_read_from_str(ctx, str);
900 set = isl_set_remove_divs_involving_dims(set, isl_dim_set, 0, 2);
901 set = isl_set_fix_si(set, isl_dim_set, 2, -3);
902 empty = isl_set_is_empty(set);
903 isl_set_free(set);
904 if (empty < 0)
905 return -1;
906 if (!empty)
907 isl_die(ctx, isl_error_unknown,
908 "result not as accurate as expected", return -1);
910 return 0;
913 void test_application_case(struct isl_ctx *ctx, const char *name)
915 char *filename;
916 FILE *input;
917 struct isl_basic_set *bset1, *bset2;
918 struct isl_basic_map *bmap;
920 filename = get_filename(ctx, name, "omega");
921 assert(filename);
922 input = fopen(filename, "r");
923 assert(input);
925 bset1 = isl_basic_set_read_from_file(ctx, input);
926 bmap = isl_basic_map_read_from_file(ctx, input);
928 bset1 = isl_basic_set_apply(bset1, bmap);
930 bset2 = isl_basic_set_read_from_file(ctx, input);
932 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
934 isl_basic_set_free(bset1);
935 isl_basic_set_free(bset2);
936 free(filename);
938 fclose(input);
941 void test_application(struct isl_ctx *ctx)
943 test_application_case(ctx, "application");
944 test_application_case(ctx, "application2");
947 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
949 char *filename;
950 FILE *input;
951 struct isl_basic_set *bset1, *bset2;
953 filename = get_filename(ctx, name, "polylib");
954 assert(filename);
955 input = fopen(filename, "r");
956 assert(input);
958 bset1 = isl_basic_set_read_from_file(ctx, input);
959 bset2 = isl_basic_set_read_from_file(ctx, input);
961 bset1 = isl_basic_set_affine_hull(bset1);
963 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
965 isl_basic_set_free(bset1);
966 isl_basic_set_free(bset2);
967 free(filename);
969 fclose(input);
972 int test_affine_hull(struct isl_ctx *ctx)
974 const char *str;
975 isl_set *set;
976 isl_basic_set *bset, *bset2;
977 int n;
978 int subset;
980 test_affine_hull_case(ctx, "affine2");
981 test_affine_hull_case(ctx, "affine");
982 test_affine_hull_case(ctx, "affine3");
984 str = "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
985 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
986 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
987 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
988 set = isl_set_read_from_str(ctx, str);
989 bset = isl_set_affine_hull(set);
990 n = isl_basic_set_dim(bset, isl_dim_div);
991 isl_basic_set_free(bset);
992 if (n != 0)
993 isl_die(ctx, isl_error_unknown, "not expecting any divs",
994 return -1);
996 /* Check that isl_map_affine_hull is not confused by
997 * the reordering of divs in isl_map_align_divs.
999 str = "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1000 "32e0 = b and 32e1 = c); "
1001 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1002 set = isl_set_read_from_str(ctx, str);
1003 bset = isl_set_affine_hull(set);
1004 isl_basic_set_free(bset);
1005 if (!bset)
1006 return -1;
1008 str = "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1009 "32e2 = 31 + 31e0 }";
1010 set = isl_set_read_from_str(ctx, str);
1011 bset = isl_set_affine_hull(set);
1012 str = "{ [a] : exists e : a = 32 e }";
1013 bset2 = isl_basic_set_read_from_str(ctx, str);
1014 subset = isl_basic_set_is_subset(bset, bset2);
1015 isl_basic_set_free(bset);
1016 isl_basic_set_free(bset2);
1017 if (subset < 0)
1018 return -1;
1019 if (!subset)
1020 isl_die(ctx, isl_error_unknown, "not as accurate as expected",
1021 return -1);
1023 return 0;
1026 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
1028 char *filename;
1029 FILE *input;
1030 struct isl_basic_set *bset1, *bset2;
1031 struct isl_set *set;
1033 filename = get_filename(ctx, name, "polylib");
1034 assert(filename);
1035 input = fopen(filename, "r");
1036 assert(input);
1038 bset1 = isl_basic_set_read_from_file(ctx, input);
1039 bset2 = isl_basic_set_read_from_file(ctx, input);
1041 set = isl_basic_set_union(bset1, bset2);
1042 bset1 = isl_set_convex_hull(set);
1044 bset2 = isl_basic_set_read_from_file(ctx, input);
1046 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1048 isl_basic_set_free(bset1);
1049 isl_basic_set_free(bset2);
1050 free(filename);
1052 fclose(input);
1055 void test_convex_hull_algo(struct isl_ctx *ctx, int convex)
1057 const char *str1, *str2;
1058 isl_set *set1, *set2;
1059 int orig_convex = ctx->opt->convex;
1060 ctx->opt->convex = convex;
1062 test_convex_hull_case(ctx, "convex0");
1063 test_convex_hull_case(ctx, "convex1");
1064 test_convex_hull_case(ctx, "convex2");
1065 test_convex_hull_case(ctx, "convex3");
1066 test_convex_hull_case(ctx, "convex4");
1067 test_convex_hull_case(ctx, "convex5");
1068 test_convex_hull_case(ctx, "convex6");
1069 test_convex_hull_case(ctx, "convex7");
1070 test_convex_hull_case(ctx, "convex8");
1071 test_convex_hull_case(ctx, "convex9");
1072 test_convex_hull_case(ctx, "convex10");
1073 test_convex_hull_case(ctx, "convex11");
1074 test_convex_hull_case(ctx, "convex12");
1075 test_convex_hull_case(ctx, "convex13");
1076 test_convex_hull_case(ctx, "convex14");
1077 test_convex_hull_case(ctx, "convex15");
1079 str1 = "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1080 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1081 "(i0 = 0 and i1 = 0 and i2 = 0) }";
1082 str2 = "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
1083 set1 = isl_set_read_from_str(ctx, str1);
1084 set2 = isl_set_read_from_str(ctx, str2);
1085 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
1086 assert(isl_set_is_equal(set1, set2));
1087 isl_set_free(set1);
1088 isl_set_free(set2);
1090 ctx->opt->convex = orig_convex;
1093 void test_convex_hull(struct isl_ctx *ctx)
1095 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM);
1096 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP);
1099 void test_gist_case(struct isl_ctx *ctx, const char *name)
1101 char *filename;
1102 FILE *input;
1103 struct isl_basic_set *bset1, *bset2;
1105 filename = get_filename(ctx, name, "polylib");
1106 assert(filename);
1107 input = fopen(filename, "r");
1108 assert(input);
1110 bset1 = isl_basic_set_read_from_file(ctx, input);
1111 bset2 = isl_basic_set_read_from_file(ctx, input);
1113 bset1 = isl_basic_set_gist(bset1, bset2);
1115 bset2 = isl_basic_set_read_from_file(ctx, input);
1117 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
1119 isl_basic_set_free(bset1);
1120 isl_basic_set_free(bset2);
1121 free(filename);
1123 fclose(input);
1126 static int test_gist(struct isl_ctx *ctx)
1128 const char *str;
1129 isl_basic_set *bset1, *bset2;
1130 isl_map *map1, *map2;
1132 test_gist_case(ctx, "gist1");
1134 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
1135 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1136 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1137 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1138 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1139 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1140 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1141 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1142 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1143 bset1 = isl_basic_set_read_from_str(ctx, str);
1144 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1145 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1146 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1147 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1148 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1149 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1150 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1151 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1152 bset2 = isl_basic_set_read_from_str(ctx, str);
1153 bset1 = isl_basic_set_gist(bset1, bset2);
1154 assert(bset1 && bset1->n_div == 0);
1155 isl_basic_set_free(bset1);
1157 /* Check that the integer divisions of the second disjunct
1158 * do not spread to the first disjunct.
1160 str = "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1161 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1162 "(exists (e0 = [(-1 + t1)/16], "
1163 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1164 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1165 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1166 "o0 <= 4294967295 and t1 <= -1)) }";
1167 map1 = isl_map_read_from_str(ctx, str);
1168 str = "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1169 map2 = isl_map_read_from_str(ctx, str);
1170 map1 = isl_map_gist(map1, map2);
1171 if (!map1)
1172 return -1;
1173 if (map1->n != 1)
1174 isl_die(ctx, isl_error_unknown, "expecting single disjunct",
1175 isl_map_free(map1); return -1);
1176 if (isl_basic_map_dim(map1->p[0], isl_dim_div) != 1)
1177 isl_die(ctx, isl_error_unknown, "expecting single div",
1178 isl_map_free(map1); return -1);
1179 isl_map_free(map1);
1181 return 0;
1184 int test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
1186 isl_set *set, *set2;
1187 int equal;
1188 int one;
1190 set = isl_set_read_from_str(ctx, str);
1191 set = isl_set_coalesce(set);
1192 set2 = isl_set_read_from_str(ctx, str);
1193 equal = isl_set_is_equal(set, set2);
1194 one = set && set->n == 1;
1195 isl_set_free(set);
1196 isl_set_free(set2);
1198 if (equal < 0)
1199 return -1;
1200 if (!equal)
1201 isl_die(ctx, isl_error_unknown,
1202 "coalesced set not equal to input", return -1);
1203 if (check_one && !one)
1204 isl_die(ctx, isl_error_unknown,
1205 "coalesced set should not be a union", return -1);
1207 return 0;
1210 int test_coalesce_unbounded_wrapping(isl_ctx *ctx)
1212 int r = 0;
1213 int bounded;
1215 bounded = isl_options_get_coalesce_bounded_wrapping(ctx);
1216 isl_options_set_coalesce_bounded_wrapping(ctx, 0);
1218 if (test_coalesce_set(ctx,
1219 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1220 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1221 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1222 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1223 "-10 <= y <= 0}", 1) < 0)
1224 goto error;
1225 if (test_coalesce_set(ctx,
1226 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
1227 goto error;
1228 if (test_coalesce_set(ctx,
1229 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
1230 goto error;
1232 if (0) {
1233 error:
1234 r = -1;
1237 isl_options_set_coalesce_bounded_wrapping(ctx, bounded);
1239 return r;
1242 /* Inputs for coalescing tests.
1243 * "str" is a string representation of the input set.
1244 * "single_disjunct" is set if we expect the result to consist of
1245 * a single disjunct.
1247 struct {
1248 int single_disjunct;
1249 const char *str;
1250 } coalesce_tests[] = {
1251 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1252 "y >= x & x >= 2 & 5 >= y }" },
1253 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1254 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1255 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1256 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1257 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1258 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1259 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1260 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1261 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1262 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1263 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1264 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1265 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1266 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1267 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1268 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1269 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1270 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1271 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1272 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1273 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1274 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1275 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1276 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1277 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1278 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1279 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1280 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1281 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1282 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1283 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1284 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1285 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1286 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1287 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1288 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1289 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1290 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1291 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1292 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1293 "[o0, o1, o2, o3, o4, o5, o6]] : "
1294 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1295 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1296 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1297 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1298 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1299 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1300 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1301 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1302 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1303 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1304 "o6 >= i3 + i6 - o3 and M >= 0 and "
1305 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1306 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1307 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1308 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1309 "(o0 = 0 and M >= 2 and N >= 3) or "
1310 "(M = 0 and o0 = 0 and N >= 3) }" },
1311 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1312 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1313 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1314 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1315 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1316 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1317 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1318 "(y = 3 and x = 1) }" },
1319 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1320 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1321 "i1 <= M and i3 <= M and i4 <= M) or "
1322 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1323 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1324 "i4 <= -1 + M) }" },
1325 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1326 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1327 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1328 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1329 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1330 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1331 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1332 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1333 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1334 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1335 { 0, "{ [a, b] : exists e : 2e = a and "
1336 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1337 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1338 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1339 "j >= 1 and j' <= i + j - i' and i >= 1; "
1340 "[1, 1, 1, 1] }" },
1341 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1342 "[i,j] : exists a : j = 3a }" },
1343 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1344 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1345 "a >= 3) or "
1346 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1347 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1348 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1349 "c <= 6 + 8a and a >= 3; "
1350 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1351 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1352 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1353 "[x,0] : 3 <= x <= 4 }" },
1354 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1355 "[x,0] : 4 <= x <= 5 }" },
1356 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1357 "[x,0] : 3 <= x <= 5 }" },
1358 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1359 "[x,0] : 3 <= x <= 4 }" },
1360 { 1 , "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1361 "i1 <= 0; "
1362 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1365 /* Test the functionality of isl_set_coalesce.
1366 * That is, check that the output is always equal to the input
1367 * and in some cases that the result consists of a single disjunct.
1369 static int test_coalesce(struct isl_ctx *ctx)
1371 int i;
1373 for (i = 0; i < ARRAY_SIZE(coalesce_tests); ++i) {
1374 const char *str = coalesce_tests[i].str;
1375 int check_one = coalesce_tests[i].single_disjunct;
1376 if (test_coalesce_set(ctx, str, check_one) < 0)
1377 return -1;
1380 if (test_coalesce_unbounded_wrapping(ctx) < 0)
1381 return -1;
1383 return 0;
1386 void test_closure(struct isl_ctx *ctx)
1388 const char *str;
1389 isl_set *dom;
1390 isl_map *up, *right;
1391 isl_map *map, *map2;
1392 int exact;
1394 /* COCOA example 1 */
1395 map = isl_map_read_from_str(ctx,
1396 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1397 "1 <= i and i < n and 1 <= j and j < n or "
1398 "i2 = i + 1 and j2 = j - 1 and "
1399 "1 <= i and i < n and 2 <= j and j <= n }");
1400 map = isl_map_power(map, &exact);
1401 assert(exact);
1402 isl_map_free(map);
1404 /* COCOA example 1 */
1405 map = isl_map_read_from_str(ctx,
1406 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1407 "1 <= i and i < n and 1 <= j and j < n or "
1408 "i2 = i + 1 and j2 = j - 1 and "
1409 "1 <= i and i < n and 2 <= j and j <= n }");
1410 map = isl_map_transitive_closure(map, &exact);
1411 assert(exact);
1412 map2 = isl_map_read_from_str(ctx,
1413 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1414 "1 <= i and i < n and 1 <= j and j <= n and "
1415 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1416 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1417 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1418 assert(isl_map_is_equal(map, map2));
1419 isl_map_free(map2);
1420 isl_map_free(map);
1422 map = isl_map_read_from_str(ctx,
1423 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1424 " 0 <= y and y <= n }");
1425 map = isl_map_transitive_closure(map, &exact);
1426 map2 = isl_map_read_from_str(ctx,
1427 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1428 " 0 <= y and y <= n }");
1429 assert(isl_map_is_equal(map, map2));
1430 isl_map_free(map2);
1431 isl_map_free(map);
1433 /* COCOA example 2 */
1434 map = isl_map_read_from_str(ctx,
1435 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1436 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1437 "i2 = i + 2 and j2 = j - 2 and "
1438 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1439 map = isl_map_transitive_closure(map, &exact);
1440 assert(exact);
1441 map2 = isl_map_read_from_str(ctx,
1442 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1443 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1444 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1445 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1446 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1447 assert(isl_map_is_equal(map, map2));
1448 isl_map_free(map);
1449 isl_map_free(map2);
1451 /* COCOA Fig.2 left */
1452 map = isl_map_read_from_str(ctx,
1453 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1454 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1455 "j <= n or "
1456 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1457 "j <= 2 i - 3 and j <= n - 2 or "
1458 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1459 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1460 map = isl_map_transitive_closure(map, &exact);
1461 assert(exact);
1462 isl_map_free(map);
1464 /* COCOA Fig.2 right */
1465 map = isl_map_read_from_str(ctx,
1466 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1467 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1468 "j <= n or "
1469 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1470 "j <= 2 i - 4 and j <= n - 3 or "
1471 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1472 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1473 map = isl_map_power(map, &exact);
1474 assert(exact);
1475 isl_map_free(map);
1477 /* COCOA Fig.2 right */
1478 map = isl_map_read_from_str(ctx,
1479 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1480 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1481 "j <= n or "
1482 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1483 "j <= 2 i - 4 and j <= n - 3 or "
1484 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1485 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1486 map = isl_map_transitive_closure(map, &exact);
1487 assert(exact);
1488 map2 = isl_map_read_from_str(ctx,
1489 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1490 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1491 "j <= n and 3 + i + 2 j <= 3 n and "
1492 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1493 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1494 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1495 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1496 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1497 assert(isl_map_is_equal(map, map2));
1498 isl_map_free(map2);
1499 isl_map_free(map);
1501 /* COCOA Fig.1 right */
1502 dom = isl_set_read_from_str(ctx,
1503 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1504 "2 x - 3 y + 3 >= 0 }");
1505 right = isl_map_read_from_str(ctx,
1506 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1507 up = isl_map_read_from_str(ctx,
1508 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1509 right = isl_map_intersect_domain(right, isl_set_copy(dom));
1510 right = isl_map_intersect_range(right, isl_set_copy(dom));
1511 up = isl_map_intersect_domain(up, isl_set_copy(dom));
1512 up = isl_map_intersect_range(up, dom);
1513 map = isl_map_union(up, right);
1514 map = isl_map_transitive_closure(map, &exact);
1515 assert(exact);
1516 map2 = isl_map_read_from_str(ctx,
1517 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1518 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1519 assert(isl_map_is_equal(map, map2));
1520 isl_map_free(map2);
1521 isl_map_free(map);
1523 /* COCOA Theorem 1 counter example */
1524 map = isl_map_read_from_str(ctx,
1525 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1526 "i2 = 1 and j2 = j or "
1527 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1528 map = isl_map_transitive_closure(map, &exact);
1529 assert(exact);
1530 isl_map_free(map);
1532 map = isl_map_read_from_str(ctx,
1533 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1534 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1535 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1536 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1537 map = isl_map_transitive_closure(map, &exact);
1538 assert(exact);
1539 isl_map_free(map);
1541 /* Kelly et al 1996, fig 12 */
1542 map = isl_map_read_from_str(ctx,
1543 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1544 "1 <= i,j,j+1 <= n or "
1545 "j = n and j2 = 1 and i2 = i + 1 and "
1546 "1 <= i,i+1 <= n }");
1547 map = isl_map_transitive_closure(map, &exact);
1548 assert(exact);
1549 map2 = isl_map_read_from_str(ctx,
1550 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1551 "1 <= i <= n and i = i2 or "
1552 "1 <= i < i2 <= n and 1 <= j <= n and "
1553 "1 <= j2 <= n }");
1554 assert(isl_map_is_equal(map, map2));
1555 isl_map_free(map2);
1556 isl_map_free(map);
1558 /* Omega's closure4 */
1559 map = isl_map_read_from_str(ctx,
1560 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1561 "1 <= x,y <= 10 or "
1562 "x2 = x + 1 and y2 = y and "
1563 "1 <= x <= 20 && 5 <= y <= 15 }");
1564 map = isl_map_transitive_closure(map, &exact);
1565 assert(exact);
1566 isl_map_free(map);
1568 map = isl_map_read_from_str(ctx,
1569 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1570 map = isl_map_transitive_closure(map, &exact);
1571 assert(!exact);
1572 map2 = isl_map_read_from_str(ctx,
1573 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1574 assert(isl_map_is_equal(map, map2));
1575 isl_map_free(map);
1576 isl_map_free(map2);
1578 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1579 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1580 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1581 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1582 map = isl_map_read_from_str(ctx, str);
1583 map = isl_map_transitive_closure(map, &exact);
1584 assert(exact);
1585 map2 = isl_map_read_from_str(ctx, str);
1586 assert(isl_map_is_equal(map, map2));
1587 isl_map_free(map);
1588 isl_map_free(map2);
1590 str = "{[0] -> [1]; [2] -> [3]}";
1591 map = isl_map_read_from_str(ctx, str);
1592 map = isl_map_transitive_closure(map, &exact);
1593 assert(exact);
1594 map2 = isl_map_read_from_str(ctx, str);
1595 assert(isl_map_is_equal(map, map2));
1596 isl_map_free(map);
1597 isl_map_free(map2);
1599 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1600 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1601 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1602 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1603 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1604 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1605 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1606 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1607 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1608 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1609 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1610 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1611 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1612 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1613 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1614 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1615 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1616 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1617 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1618 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1619 map = isl_map_read_from_str(ctx, str);
1620 map = isl_map_transitive_closure(map, NULL);
1621 assert(map);
1622 isl_map_free(map);
1625 void test_lex(struct isl_ctx *ctx)
1627 isl_space *dim;
1628 isl_map *map;
1630 dim = isl_space_set_alloc(ctx, 0, 0);
1631 map = isl_map_lex_le(dim);
1632 assert(!isl_map_is_empty(map));
1633 isl_map_free(map);
1636 static int test_lexmin(struct isl_ctx *ctx)
1638 int equal;
1639 const char *str;
1640 isl_basic_map *bmap;
1641 isl_map *map, *map2;
1642 isl_set *set;
1643 isl_set *set2;
1644 isl_pw_multi_aff *pma;
1646 str = "[p0, p1] -> { [] -> [] : "
1647 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1648 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1649 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1650 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1651 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1652 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1653 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1654 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1655 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1656 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1657 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1658 map = isl_map_read_from_str(ctx, str);
1659 map = isl_map_lexmin(map);
1660 isl_map_free(map);
1662 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1663 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1664 set = isl_set_read_from_str(ctx, str);
1665 set = isl_set_lexmax(set);
1666 str = "[C] -> { [obj,a,b,c] : C = 8 }";
1667 set2 = isl_set_read_from_str(ctx, str);
1668 set = isl_set_intersect(set, set2);
1669 assert(!isl_set_is_empty(set));
1670 isl_set_free(set);
1672 str = "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1673 map = isl_map_read_from_str(ctx, str);
1674 map = isl_map_lexmin(map);
1675 str = "{ [x] -> [5] : 6 <= x <= 8; "
1676 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1677 map2 = isl_map_read_from_str(ctx, str);
1678 assert(isl_map_is_equal(map, map2));
1679 isl_map_free(map);
1680 isl_map_free(map2);
1682 str = "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1683 map = isl_map_read_from_str(ctx, str);
1684 map2 = isl_map_copy(map);
1685 map = isl_map_lexmin(map);
1686 assert(isl_map_is_equal(map, map2));
1687 isl_map_free(map);
1688 isl_map_free(map2);
1690 str = "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1691 map = isl_map_read_from_str(ctx, str);
1692 map = isl_map_lexmin(map);
1693 str = "{ [x] -> [y] : (4y = x and x >= 0) or "
1694 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1695 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1696 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1697 map2 = isl_map_read_from_str(ctx, str);
1698 assert(isl_map_is_equal(map, map2));
1699 isl_map_free(map);
1700 isl_map_free(map2);
1702 str = "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1703 " 8i' <= i and 8i' >= -7 + i }";
1704 bmap = isl_basic_map_read_from_str(ctx, str);
1705 pma = isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap));
1706 map2 = isl_map_from_pw_multi_aff(pma);
1707 map = isl_map_from_basic_map(bmap);
1708 assert(isl_map_is_equal(map, map2));
1709 isl_map_free(map);
1710 isl_map_free(map2);
1712 str = "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1713 map = isl_map_read_from_str(ctx, str);
1714 map = isl_map_lexmin(map);
1715 str = "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1716 map2 = isl_map_read_from_str(ctx, str);
1717 assert(isl_map_is_equal(map, map2));
1718 isl_map_free(map);
1719 isl_map_free(map2);
1721 /* Check that empty pieces are properly combined. */
1722 str = "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
1723 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
1724 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }";
1725 map = isl_map_read_from_str(ctx, str);
1726 map = isl_map_lexmin(map);
1727 str = "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
1728 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
1729 "x >= 4 }";
1730 map2 = isl_map_read_from_str(ctx, str);
1731 assert(isl_map_is_equal(map, map2));
1732 isl_map_free(map);
1733 isl_map_free(map2);
1735 str = "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1736 " 8i' <= i and 8i' >= -7 + i }";
1737 set = isl_set_read_from_str(ctx, str);
1738 pma = isl_set_lexmin_pw_multi_aff(isl_set_copy(set));
1739 set2 = isl_set_from_pw_multi_aff(pma);
1740 equal = isl_set_is_equal(set, set2);
1741 isl_set_free(set);
1742 isl_set_free(set2);
1743 if (equal < 0)
1744 return -1;
1745 if (!equal)
1746 isl_die(ctx, isl_error_unknown,
1747 "unexpected difference between set and "
1748 "piecewise affine expression", return -1);
1750 return 0;
1753 /* Check that isl_set_min_val and isl_set_max_val compute the correct
1754 * result on non-convex inputs.
1756 static int test_min(struct isl_ctx *ctx)
1758 isl_set *set;
1759 isl_aff *aff;
1760 isl_val *val;
1761 int min_ok, max_ok;
1763 set = isl_set_read_from_str(ctx, "{ [-1]; [1] }");
1764 aff = isl_aff_read_from_str(ctx, "{ [x] -> [x] }");
1765 val = isl_set_min_val(set, aff);
1766 min_ok = isl_val_is_negone(val);
1767 isl_val_free(val);
1768 val = isl_set_max_val(set, aff);
1769 max_ok = isl_val_is_one(val);
1770 isl_val_free(val);
1771 isl_aff_free(aff);
1772 isl_set_free(set);
1774 if (min_ok < 0 || max_ok < 0)
1775 return -1;
1776 if (!min_ok)
1777 isl_die(ctx, isl_error_unknown,
1778 "unexpected minimum", return -1);
1779 if (!max_ok)
1780 isl_die(ctx, isl_error_unknown,
1781 "unexpected maximum", return -1);
1783 return 0;
1786 struct must_may {
1787 isl_map *must;
1788 isl_map *may;
1791 static int collect_must_may(__isl_take isl_map *dep, int must,
1792 void *dep_user, void *user)
1794 struct must_may *mm = (struct must_may *)user;
1796 if (must)
1797 mm->must = isl_map_union(mm->must, dep);
1798 else
1799 mm->may = isl_map_union(mm->may, dep);
1801 return 0;
1804 static int common_space(void *first, void *second)
1806 int depth = *(int *)first;
1807 return 2 * depth;
1810 static int map_is_equal(__isl_keep isl_map *map, const char *str)
1812 isl_map *map2;
1813 int equal;
1815 if (!map)
1816 return -1;
1818 map2 = isl_map_read_from_str(map->ctx, str);
1819 equal = isl_map_is_equal(map, map2);
1820 isl_map_free(map2);
1822 return equal;
1825 static int map_check_equal(__isl_keep isl_map *map, const char *str)
1827 int equal;
1829 equal = map_is_equal(map, str);
1830 if (equal < 0)
1831 return -1;
1832 if (!equal)
1833 isl_die(isl_map_get_ctx(map), isl_error_unknown,
1834 "result not as expected", return -1);
1835 return 0;
1838 void test_dep(struct isl_ctx *ctx)
1840 const char *str;
1841 isl_space *dim;
1842 isl_map *map;
1843 isl_access_info *ai;
1844 isl_flow *flow;
1845 int depth;
1846 struct must_may mm;
1848 depth = 3;
1850 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1851 map = isl_map_read_from_str(ctx, str);
1852 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1854 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1855 map = isl_map_read_from_str(ctx, str);
1856 ai = isl_access_info_add_source(ai, map, 1, &depth);
1858 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1859 map = isl_map_read_from_str(ctx, str);
1860 ai = isl_access_info_add_source(ai, map, 1, &depth);
1862 flow = isl_access_info_compute_flow(ai);
1863 dim = isl_space_alloc(ctx, 0, 3, 3);
1864 mm.must = isl_map_empty(isl_space_copy(dim));
1865 mm.may = isl_map_empty(dim);
1867 isl_flow_foreach(flow, collect_must_may, &mm);
1869 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1870 " [1,10,0] -> [2,5,0] }";
1871 assert(map_is_equal(mm.must, str));
1872 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1873 assert(map_is_equal(mm.may, str));
1875 isl_map_free(mm.must);
1876 isl_map_free(mm.may);
1877 isl_flow_free(flow);
1880 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1881 map = isl_map_read_from_str(ctx, str);
1882 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1884 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1885 map = isl_map_read_from_str(ctx, str);
1886 ai = isl_access_info_add_source(ai, map, 1, &depth);
1888 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1889 map = isl_map_read_from_str(ctx, str);
1890 ai = isl_access_info_add_source(ai, map, 0, &depth);
1892 flow = isl_access_info_compute_flow(ai);
1893 dim = isl_space_alloc(ctx, 0, 3, 3);
1894 mm.must = isl_map_empty(isl_space_copy(dim));
1895 mm.may = isl_map_empty(dim);
1897 isl_flow_foreach(flow, collect_must_may, &mm);
1899 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1900 assert(map_is_equal(mm.must, str));
1901 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1902 assert(map_is_equal(mm.may, str));
1904 isl_map_free(mm.must);
1905 isl_map_free(mm.may);
1906 isl_flow_free(flow);
1909 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1910 map = isl_map_read_from_str(ctx, str);
1911 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1913 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1914 map = isl_map_read_from_str(ctx, str);
1915 ai = isl_access_info_add_source(ai, map, 0, &depth);
1917 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1918 map = isl_map_read_from_str(ctx, str);
1919 ai = isl_access_info_add_source(ai, map, 0, &depth);
1921 flow = isl_access_info_compute_flow(ai);
1922 dim = isl_space_alloc(ctx, 0, 3, 3);
1923 mm.must = isl_map_empty(isl_space_copy(dim));
1924 mm.may = isl_map_empty(dim);
1926 isl_flow_foreach(flow, collect_must_may, &mm);
1928 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1929 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1930 assert(map_is_equal(mm.may, str));
1931 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1932 assert(map_is_equal(mm.must, str));
1934 isl_map_free(mm.must);
1935 isl_map_free(mm.may);
1936 isl_flow_free(flow);
1939 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1940 map = isl_map_read_from_str(ctx, str);
1941 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1943 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1944 map = isl_map_read_from_str(ctx, str);
1945 ai = isl_access_info_add_source(ai, map, 0, &depth);
1947 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1948 map = isl_map_read_from_str(ctx, str);
1949 ai = isl_access_info_add_source(ai, map, 0, &depth);
1951 flow = isl_access_info_compute_flow(ai);
1952 dim = isl_space_alloc(ctx, 0, 3, 3);
1953 mm.must = isl_map_empty(isl_space_copy(dim));
1954 mm.may = isl_map_empty(dim);
1956 isl_flow_foreach(flow, collect_must_may, &mm);
1958 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1959 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1960 assert(map_is_equal(mm.may, str));
1961 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1962 assert(map_is_equal(mm.must, str));
1964 isl_map_free(mm.must);
1965 isl_map_free(mm.may);
1966 isl_flow_free(flow);
1969 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1970 map = isl_map_read_from_str(ctx, str);
1971 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1973 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1974 map = isl_map_read_from_str(ctx, str);
1975 ai = isl_access_info_add_source(ai, map, 0, &depth);
1977 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1978 map = isl_map_read_from_str(ctx, str);
1979 ai = isl_access_info_add_source(ai, map, 0, &depth);
1981 flow = isl_access_info_compute_flow(ai);
1982 dim = isl_space_alloc(ctx, 0, 3, 3);
1983 mm.must = isl_map_empty(isl_space_copy(dim));
1984 mm.may = isl_map_empty(dim);
1986 isl_flow_foreach(flow, collect_must_may, &mm);
1988 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1989 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1990 assert(map_is_equal(mm.may, str));
1991 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1992 assert(map_is_equal(mm.must, str));
1994 isl_map_free(mm.must);
1995 isl_map_free(mm.may);
1996 isl_flow_free(flow);
1999 depth = 5;
2001 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2002 map = isl_map_read_from_str(ctx, str);
2003 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
2005 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2006 map = isl_map_read_from_str(ctx, str);
2007 ai = isl_access_info_add_source(ai, map, 1, &depth);
2009 flow = isl_access_info_compute_flow(ai);
2010 dim = isl_space_alloc(ctx, 0, 5, 5);
2011 mm.must = isl_map_empty(isl_space_copy(dim));
2012 mm.may = isl_map_empty(dim);
2014 isl_flow_foreach(flow, collect_must_may, &mm);
2016 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
2017 assert(map_is_equal(mm.must, str));
2018 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
2019 assert(map_is_equal(mm.may, str));
2021 isl_map_free(mm.must);
2022 isl_map_free(mm.may);
2023 isl_flow_free(flow);
2026 int test_sv(isl_ctx *ctx)
2028 const char *str;
2029 isl_map *map;
2030 isl_union_map *umap;
2031 int sv;
2033 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
2034 map = isl_map_read_from_str(ctx, str);
2035 sv = isl_map_is_single_valued(map);
2036 isl_map_free(map);
2037 if (sv < 0)
2038 return -1;
2039 if (!sv)
2040 isl_die(ctx, isl_error_internal,
2041 "map not detected as single valued", return -1);
2043 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
2044 map = isl_map_read_from_str(ctx, str);
2045 sv = isl_map_is_single_valued(map);
2046 isl_map_free(map);
2047 if (sv < 0)
2048 return -1;
2049 if (sv)
2050 isl_die(ctx, isl_error_internal,
2051 "map detected as single valued", return -1);
2053 str = "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
2054 umap = isl_union_map_read_from_str(ctx, str);
2055 sv = isl_union_map_is_single_valued(umap);
2056 isl_union_map_free(umap);
2057 if (sv < 0)
2058 return -1;
2059 if (!sv)
2060 isl_die(ctx, isl_error_internal,
2061 "map not detected as single valued", return -1);
2063 str = "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
2064 umap = isl_union_map_read_from_str(ctx, str);
2065 sv = isl_union_map_is_single_valued(umap);
2066 isl_union_map_free(umap);
2067 if (sv < 0)
2068 return -1;
2069 if (sv)
2070 isl_die(ctx, isl_error_internal,
2071 "map detected as single valued", return -1);
2073 return 0;
2076 void test_bijective_case(struct isl_ctx *ctx, const char *str, int bijective)
2078 isl_map *map;
2080 map = isl_map_read_from_str(ctx, str);
2081 if (bijective)
2082 assert(isl_map_is_bijective(map));
2083 else
2084 assert(!isl_map_is_bijective(map));
2085 isl_map_free(map);
2088 void test_bijective(struct isl_ctx *ctx)
2090 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i]}", 0);
2091 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=i}", 1);
2092 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=0}", 1);
2093 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=N}", 1);
2094 test_bijective_case(ctx, "[N,M]->{[i,j] -> [j,i]}", 1);
2095 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i+j]}", 0);
2096 test_bijective_case(ctx, "[N,M]->{[i,j] -> []}", 0);
2097 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,j,N]}", 1);
2098 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i]}", 0);
2099 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,i]}", 0);
2100 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,i]}", 0);
2101 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,j]}", 1);
2102 test_bijective_case(ctx, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
2105 static int test_pwqp(struct isl_ctx *ctx)
2107 const char *str;
2108 isl_set *set;
2109 isl_pw_qpolynomial *pwqp1, *pwqp2;
2110 int equal;
2112 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2113 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2115 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
2116 isl_dim_in, 1, 1);
2118 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2119 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2121 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2123 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2125 isl_pw_qpolynomial_free(pwqp1);
2127 str = "{ [i] -> i }";
2128 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2129 str = "{ [k] : exists a : k = 2a }";
2130 set = isl_set_read_from_str(ctx, str);
2131 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
2132 str = "{ [i] -> i }";
2133 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2135 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2137 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2139 isl_pw_qpolynomial_free(pwqp1);
2141 str = "{ [i] -> i + [ (i + [i/3])/2 ] }";
2142 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2143 str = "{ [10] }";
2144 set = isl_set_read_from_str(ctx, str);
2145 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
2146 str = "{ [i] -> 16 }";
2147 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2149 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2151 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2153 isl_pw_qpolynomial_free(pwqp1);
2155 str = "{ [i] -> ([(i)/2]) }";
2156 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2157 str = "{ [k] : exists a : k = 2a+1 }";
2158 set = isl_set_read_from_str(ctx, str);
2159 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
2160 str = "{ [i] -> -1/2 + 1/2 * i }";
2161 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2163 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2165 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2167 isl_pw_qpolynomial_free(pwqp1);
2169 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
2170 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2171 str = "{ [i] -> ([(2 * [i/2])/5]) }";
2172 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2174 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2176 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2178 isl_pw_qpolynomial_free(pwqp1);
2180 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
2181 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2182 str = "{ [x] -> x }";
2183 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2185 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2187 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2189 isl_pw_qpolynomial_free(pwqp1);
2191 str = "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
2192 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2193 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2194 pwqp1 = isl_pw_qpolynomial_coalesce(pwqp1);
2195 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
2196 assert(isl_pw_qpolynomial_is_zero(pwqp1));
2197 isl_pw_qpolynomial_free(pwqp1);
2199 str = "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
2200 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2201 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2202 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2203 set = isl_set_read_from_str(ctx, "{ [a,b,a] }");
2204 pwqp1 = isl_pw_qpolynomial_intersect_domain(pwqp1, set);
2205 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
2206 isl_pw_qpolynomial_free(pwqp1);
2207 isl_pw_qpolynomial_free(pwqp2);
2208 if (equal < 0)
2209 return -1;
2210 if (!equal)
2211 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2213 str = "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
2214 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
2215 str = "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2216 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
2217 pwqp1 = isl_pw_qpolynomial_fix_val(pwqp1, isl_dim_set, 1,
2218 isl_val_one(ctx));
2219 equal = isl_pw_qpolynomial_plain_is_equal(pwqp1, pwqp2);
2220 isl_pw_qpolynomial_free(pwqp1);
2221 isl_pw_qpolynomial_free(pwqp2);
2222 if (equal < 0)
2223 return -1;
2224 if (!equal)
2225 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
2227 return 0;
2230 void test_split_periods(isl_ctx *ctx)
2232 const char *str;
2233 isl_pw_qpolynomial *pwqp;
2235 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
2236 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
2237 "U >= 0; [U,V] -> U^2 : U >= 100 }";
2238 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
2240 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
2241 assert(pwqp);
2243 isl_pw_qpolynomial_free(pwqp);
2246 void test_union(isl_ctx *ctx)
2248 const char *str;
2249 isl_union_set *uset1, *uset2;
2250 isl_union_map *umap1, *umap2;
2252 str = "{ [i] : 0 <= i <= 1 }";
2253 uset1 = isl_union_set_read_from_str(ctx, str);
2254 str = "{ [1] -> [0] }";
2255 umap1 = isl_union_map_read_from_str(ctx, str);
2257 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
2258 assert(isl_union_map_is_equal(umap1, umap2));
2260 isl_union_map_free(umap1);
2261 isl_union_map_free(umap2);
2263 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
2264 umap1 = isl_union_map_read_from_str(ctx, str);
2265 str = "{ A[i]; B[i] }";
2266 uset1 = isl_union_set_read_from_str(ctx, str);
2268 uset2 = isl_union_map_domain(umap1);
2270 assert(isl_union_set_is_equal(uset1, uset2));
2272 isl_union_set_free(uset1);
2273 isl_union_set_free(uset2);
2276 void test_bound(isl_ctx *ctx)
2278 const char *str;
2279 isl_pw_qpolynomial *pwqp;
2280 isl_pw_qpolynomial_fold *pwf;
2282 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
2283 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
2284 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
2285 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in) == 4);
2286 isl_pw_qpolynomial_fold_free(pwf);
2288 str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
2289 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
2290 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
2291 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in) == 1);
2292 isl_pw_qpolynomial_fold_free(pwf);
2295 void test_lift(isl_ctx *ctx)
2297 const char *str;
2298 isl_basic_map *bmap;
2299 isl_basic_set *bset;
2301 str = "{ [i0] : exists e0 : i0 = 4e0 }";
2302 bset = isl_basic_set_read_from_str(ctx, str);
2303 bset = isl_basic_set_lift(bset);
2304 bmap = isl_basic_map_from_range(bset);
2305 bset = isl_basic_map_domain(bmap);
2306 isl_basic_set_free(bset);
2309 struct {
2310 const char *set1;
2311 const char *set2;
2312 int subset;
2313 } subset_tests[] = {
2314 { "{ [112, 0] }",
2315 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
2316 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
2317 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
2318 { "{ [65] }",
2319 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
2320 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
2321 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
2322 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
2323 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
2324 "256e0 <= 255i and 256e0 >= -255 + 255i and "
2325 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
2326 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
2327 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
2328 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
2329 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
2330 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
2331 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
2332 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
2333 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
2334 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
2335 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
2336 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
2337 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
2338 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
2339 "4e0 <= -57 + i0 + i1)) or "
2340 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
2341 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
2342 "4e0 >= -61 + i0 + i1)) or "
2343 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
2346 static int test_subset(isl_ctx *ctx)
2348 int i;
2349 isl_set *set1, *set2;
2350 int subset;
2352 for (i = 0; i < ARRAY_SIZE(subset_tests); ++i) {
2353 set1 = isl_set_read_from_str(ctx, subset_tests[i].set1);
2354 set2 = isl_set_read_from_str(ctx, subset_tests[i].set2);
2355 subset = isl_set_is_subset(set1, set2);
2356 isl_set_free(set1);
2357 isl_set_free(set2);
2358 if (subset < 0)
2359 return -1;
2360 if (subset != subset_tests[i].subset)
2361 isl_die(ctx, isl_error_unknown,
2362 "incorrect subset result", return -1);
2365 return 0;
2368 struct {
2369 const char *minuend;
2370 const char *subtrahend;
2371 const char *difference;
2372 } subtract_domain_tests[] = {
2373 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
2374 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
2375 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
2378 static int test_subtract(isl_ctx *ctx)
2380 int i;
2381 isl_union_map *umap1, *umap2;
2382 isl_union_set *uset;
2383 int equal;
2385 for (i = 0; i < ARRAY_SIZE(subtract_domain_tests); ++i) {
2386 umap1 = isl_union_map_read_from_str(ctx,
2387 subtract_domain_tests[i].minuend);
2388 uset = isl_union_set_read_from_str(ctx,
2389 subtract_domain_tests[i].subtrahend);
2390 umap2 = isl_union_map_read_from_str(ctx,
2391 subtract_domain_tests[i].difference);
2392 umap1 = isl_union_map_subtract_domain(umap1, uset);
2393 equal = isl_union_map_is_equal(umap1, umap2);
2394 isl_union_map_free(umap1);
2395 isl_union_map_free(umap2);
2396 if (equal < 0)
2397 return -1;
2398 if (!equal)
2399 isl_die(ctx, isl_error_unknown,
2400 "incorrect subtract domain result", return -1);
2403 return 0;
2406 int test_factorize(isl_ctx *ctx)
2408 const char *str;
2409 isl_basic_set *bset;
2410 isl_factorizer *f;
2412 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2413 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2414 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2415 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2416 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2417 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2418 "3i5 >= -2i0 - i2 + 3i4 }";
2419 bset = isl_basic_set_read_from_str(ctx, str);
2420 f = isl_basic_set_factorizer(bset);
2421 isl_basic_set_free(bset);
2422 isl_factorizer_free(f);
2423 if (!f)
2424 isl_die(ctx, isl_error_unknown,
2425 "failed to construct factorizer", return -1);
2427 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2428 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2429 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2430 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2431 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2432 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2433 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2434 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2435 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2436 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2437 bset = isl_basic_set_read_from_str(ctx, str);
2438 f = isl_basic_set_factorizer(bset);
2439 isl_basic_set_free(bset);
2440 isl_factorizer_free(f);
2441 if (!f)
2442 isl_die(ctx, isl_error_unknown,
2443 "failed to construct factorizer", return -1);
2445 return 0;
2448 static int check_injective(__isl_take isl_map *map, void *user)
2450 int *injective = user;
2452 *injective = isl_map_is_injective(map);
2453 isl_map_free(map);
2455 if (*injective < 0 || !*injective)
2456 return -1;
2458 return 0;
2461 int test_one_schedule(isl_ctx *ctx, const char *d, const char *w,
2462 const char *r, const char *s, int tilable, int parallel)
2464 int i;
2465 isl_union_set *D;
2466 isl_union_map *W, *R, *S;
2467 isl_union_map *empty;
2468 isl_union_map *dep_raw, *dep_war, *dep_waw, *dep;
2469 isl_union_map *validity, *proximity, *coincidence;
2470 isl_union_map *schedule;
2471 isl_union_map *test;
2472 isl_union_set *delta;
2473 isl_union_set *domain;
2474 isl_set *delta_set;
2475 isl_set *slice;
2476 isl_set *origin;
2477 isl_schedule_constraints *sc;
2478 isl_schedule *sched;
2479 int is_nonneg, is_parallel, is_tilable, is_injection, is_complete;
2481 D = isl_union_set_read_from_str(ctx, d);
2482 W = isl_union_map_read_from_str(ctx, w);
2483 R = isl_union_map_read_from_str(ctx, r);
2484 S = isl_union_map_read_from_str(ctx, s);
2486 W = isl_union_map_intersect_domain(W, isl_union_set_copy(D));
2487 R = isl_union_map_intersect_domain(R, isl_union_set_copy(D));
2489 empty = isl_union_map_empty(isl_union_map_get_space(S));
2490 isl_union_map_compute_flow(isl_union_map_copy(R),
2491 isl_union_map_copy(W), empty,
2492 isl_union_map_copy(S),
2493 &dep_raw, NULL, NULL, NULL);
2494 isl_union_map_compute_flow(isl_union_map_copy(W),
2495 isl_union_map_copy(W),
2496 isl_union_map_copy(R),
2497 isl_union_map_copy(S),
2498 &dep_waw, &dep_war, NULL, NULL);
2500 dep = isl_union_map_union(dep_waw, dep_war);
2501 dep = isl_union_map_union(dep, dep_raw);
2502 validity = isl_union_map_copy(dep);
2503 coincidence = isl_union_map_copy(dep);
2504 proximity = isl_union_map_copy(dep);
2506 sc = isl_schedule_constraints_on_domain(isl_union_set_copy(D));
2507 sc = isl_schedule_constraints_set_validity(sc, validity);
2508 sc = isl_schedule_constraints_set_coincidence(sc, coincidence);
2509 sc = isl_schedule_constraints_set_proximity(sc, proximity);
2510 sched = isl_schedule_constraints_compute_schedule(sc);
2511 schedule = isl_schedule_get_map(sched);
2512 isl_schedule_free(sched);
2513 isl_union_map_free(W);
2514 isl_union_map_free(R);
2515 isl_union_map_free(S);
2517 is_injection = 1;
2518 isl_union_map_foreach_map(schedule, &check_injective, &is_injection);
2520 domain = isl_union_map_domain(isl_union_map_copy(schedule));
2521 is_complete = isl_union_set_is_subset(D, domain);
2522 isl_union_set_free(D);
2523 isl_union_set_free(domain);
2525 test = isl_union_map_reverse(isl_union_map_copy(schedule));
2526 test = isl_union_map_apply_range(test, dep);
2527 test = isl_union_map_apply_range(test, schedule);
2529 delta = isl_union_map_deltas(test);
2530 if (isl_union_set_n_set(delta) == 0) {
2531 is_tilable = 1;
2532 is_parallel = 1;
2533 is_nonneg = 1;
2534 isl_union_set_free(delta);
2535 } else {
2536 delta_set = isl_set_from_union_set(delta);
2538 slice = isl_set_universe(isl_set_get_space(delta_set));
2539 for (i = 0; i < tilable; ++i)
2540 slice = isl_set_lower_bound_si(slice, isl_dim_set, i, 0);
2541 is_tilable = isl_set_is_subset(delta_set, slice);
2542 isl_set_free(slice);
2544 slice = isl_set_universe(isl_set_get_space(delta_set));
2545 for (i = 0; i < parallel; ++i)
2546 slice = isl_set_fix_si(slice, isl_dim_set, i, 0);
2547 is_parallel = isl_set_is_subset(delta_set, slice);
2548 isl_set_free(slice);
2550 origin = isl_set_universe(isl_set_get_space(delta_set));
2551 for (i = 0; i < isl_set_dim(origin, isl_dim_set); ++i)
2552 origin = isl_set_fix_si(origin, isl_dim_set, i, 0);
2554 delta_set = isl_set_union(delta_set, isl_set_copy(origin));
2555 delta_set = isl_set_lexmin(delta_set);
2557 is_nonneg = isl_set_is_equal(delta_set, origin);
2559 isl_set_free(origin);
2560 isl_set_free(delta_set);
2563 if (is_nonneg < 0 || is_parallel < 0 || is_tilable < 0 ||
2564 is_injection < 0 || is_complete < 0)
2565 return -1;
2566 if (!is_complete)
2567 isl_die(ctx, isl_error_unknown,
2568 "generated schedule incomplete", return -1);
2569 if (!is_injection)
2570 isl_die(ctx, isl_error_unknown,
2571 "generated schedule not injective on each statement",
2572 return -1);
2573 if (!is_nonneg)
2574 isl_die(ctx, isl_error_unknown,
2575 "negative dependences in generated schedule",
2576 return -1);
2577 if (!is_tilable)
2578 isl_die(ctx, isl_error_unknown,
2579 "generated schedule not as tilable as expected",
2580 return -1);
2581 if (!is_parallel)
2582 isl_die(ctx, isl_error_unknown,
2583 "generated schedule not as parallel as expected",
2584 return -1);
2586 return 0;
2589 static __isl_give isl_union_map *compute_schedule(isl_ctx *ctx,
2590 const char *domain, const char *validity, const char *proximity)
2592 isl_union_set *dom;
2593 isl_union_map *dep;
2594 isl_union_map *prox;
2595 isl_schedule_constraints *sc;
2596 isl_schedule *schedule;
2597 isl_union_map *sched;
2599 dom = isl_union_set_read_from_str(ctx, domain);
2600 dep = isl_union_map_read_from_str(ctx, validity);
2601 prox = isl_union_map_read_from_str(ctx, proximity);
2602 sc = isl_schedule_constraints_on_domain(dom);
2603 sc = isl_schedule_constraints_set_validity(sc, dep);
2604 sc = isl_schedule_constraints_set_proximity(sc, prox);
2605 schedule = isl_schedule_constraints_compute_schedule(sc);
2606 sched = isl_schedule_get_map(schedule);
2607 isl_schedule_free(schedule);
2609 return sched;
2612 /* Check that a schedule can be constructed on the given domain
2613 * with the given validity and proximity constraints.
2615 static int test_has_schedule(isl_ctx *ctx, const char *domain,
2616 const char *validity, const char *proximity)
2618 isl_union_map *sched;
2620 sched = compute_schedule(ctx, domain, validity, proximity);
2621 if (!sched)
2622 return -1;
2624 isl_union_map_free(sched);
2625 return 0;
2628 int test_special_schedule(isl_ctx *ctx, const char *domain,
2629 const char *validity, const char *proximity, const char *expected_sched)
2631 isl_union_map *sched1, *sched2;
2632 int equal;
2634 sched1 = compute_schedule(ctx, domain, validity, proximity);
2635 sched2 = isl_union_map_read_from_str(ctx, expected_sched);
2637 equal = isl_union_map_is_equal(sched1, sched2);
2638 isl_union_map_free(sched1);
2639 isl_union_map_free(sched2);
2641 if (equal < 0)
2642 return -1;
2643 if (!equal)
2644 isl_die(ctx, isl_error_unknown, "unexpected schedule",
2645 return -1);
2647 return 0;
2650 /* Check that the schedule map is properly padded, even after being
2651 * reconstructed from the band forest.
2653 static int test_padded_schedule(isl_ctx *ctx)
2655 const char *str;
2656 isl_union_set *D;
2657 isl_union_map *validity, *proximity;
2658 isl_schedule_constraints *sc;
2659 isl_schedule *sched;
2660 isl_union_map *map1, *map2;
2661 isl_band_list *list;
2662 int equal;
2664 str = "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
2665 D = isl_union_set_read_from_str(ctx, str);
2666 validity = isl_union_map_empty(isl_union_set_get_space(D));
2667 proximity = isl_union_map_copy(validity);
2668 sc = isl_schedule_constraints_on_domain(D);
2669 sc = isl_schedule_constraints_set_validity(sc, validity);
2670 sc = isl_schedule_constraints_set_proximity(sc, proximity);
2671 sched = isl_schedule_constraints_compute_schedule(sc);
2672 map1 = isl_schedule_get_map(sched);
2673 list = isl_schedule_get_band_forest(sched);
2674 isl_band_list_free(list);
2675 map2 = isl_schedule_get_map(sched);
2676 isl_schedule_free(sched);
2677 equal = isl_union_map_is_equal(map1, map2);
2678 isl_union_map_free(map1);
2679 isl_union_map_free(map2);
2681 if (equal < 0)
2682 return -1;
2683 if (!equal)
2684 isl_die(ctx, isl_error_unknown,
2685 "reconstructed schedule map not the same as original",
2686 return -1);
2688 return 0;
2691 /* Input for testing of schedule construction based on
2692 * conditional constraints.
2694 * domain is the iteration domain
2695 * flow are the flow dependences, which determine the validity and
2696 * proximity constraints
2697 * condition are the conditions on the conditional validity constraints
2698 * conditional_validity are the conditional validity constraints
2699 * outer_band_n is the expected number of members in the outer band
2701 struct {
2702 const char *domain;
2703 const char *flow;
2704 const char *condition;
2705 const char *conditional_validity;
2706 int outer_band_n;
2707 } live_range_tests[] = {
2708 /* Contrived example that illustrates that we need to keep
2709 * track of tagged condition dependences and
2710 * tagged conditional validity dependences
2711 * in isl_sched_edge separately.
2712 * In particular, the conditional validity constraints on A
2713 * cannot be satisfied,
2714 * but they can be ignored because there are no corresponding
2715 * condition constraints. However, we do have an additional
2716 * conditional validity constraint that maps to the same
2717 * dependence relation
2718 * as the condition constraint on B. If we did not make a distinction
2719 * between tagged condition and tagged conditional validity
2720 * dependences, then we
2721 * could end up treating this shared dependence as an condition
2722 * constraint on A, forcing a localization of the conditions,
2723 * which is impossible.
2725 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
2726 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
2727 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
2728 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2729 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2730 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
2733 /* TACO 2013 Fig. 7 */
2734 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2735 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2736 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2737 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
2738 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
2739 "0 <= i < n and 0 <= j < n - 1 }",
2740 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
2741 "0 <= i < n and 0 <= j < j' < n;"
2742 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
2743 "0 <= i < i' < n and 0 <= j,j' < n;"
2744 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
2745 "0 <= i,j,j' < n and j < j' }",
2748 /* TACO 2013 Fig. 7, without tags */
2749 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2750 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2751 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2752 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2753 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2754 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
2755 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
2756 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
2759 /* TACO 2013 Fig. 12 */
2760 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
2761 "S3[i,3] : 0 <= i <= 1 }",
2762 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
2763 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
2764 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
2765 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
2766 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2767 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
2768 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2769 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
2770 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
2771 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
2772 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
2777 /* Test schedule construction based on conditional constraints.
2778 * In particular, check the number of members in the outer band
2779 * as an indication of whether tiling is possible or not.
2781 static int test_conditional_schedule_constraints(isl_ctx *ctx)
2783 int i;
2784 isl_union_set *domain;
2785 isl_union_map *condition;
2786 isl_union_map *flow;
2787 isl_union_map *validity;
2788 isl_schedule_constraints *sc;
2789 isl_schedule *schedule;
2790 isl_band_list *list;
2791 isl_band *band;
2792 int n_member;
2794 for (i = 0; i < ARRAY_SIZE(live_range_tests); ++i) {
2795 domain = isl_union_set_read_from_str(ctx,
2796 live_range_tests[i].domain);
2797 flow = isl_union_map_read_from_str(ctx,
2798 live_range_tests[i].flow);
2799 condition = isl_union_map_read_from_str(ctx,
2800 live_range_tests[i].condition);
2801 validity = isl_union_map_read_from_str(ctx,
2802 live_range_tests[i].conditional_validity);
2803 sc = isl_schedule_constraints_on_domain(domain);
2804 sc = isl_schedule_constraints_set_validity(sc,
2805 isl_union_map_copy(flow));
2806 sc = isl_schedule_constraints_set_proximity(sc, flow);
2807 sc = isl_schedule_constraints_set_conditional_validity(sc,
2808 condition, validity);
2809 schedule = isl_schedule_constraints_compute_schedule(sc);
2810 list = isl_schedule_get_band_forest(schedule);
2811 band = isl_band_list_get_band(list, 0);
2812 n_member = isl_band_n_member(band);
2813 isl_band_free(band);
2814 isl_band_list_free(list);
2815 isl_schedule_free(schedule);
2817 if (!schedule)
2818 return -1;
2819 if (n_member != live_range_tests[i].outer_band_n)
2820 isl_die(ctx, isl_error_unknown,
2821 "unexpected number of members in outer band",
2822 return -1);
2824 return 0;
2827 int test_schedule(isl_ctx *ctx)
2829 const char *D, *W, *R, *V, *P, *S;
2831 /* Handle resulting schedule with zero bands. */
2832 if (test_one_schedule(ctx, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
2833 return -1;
2835 /* Jacobi */
2836 D = "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2837 W = "{ S1[t,i] -> a[t,i] }";
2838 R = "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2839 "S1[t,i] -> a[t-1,i+1] }";
2840 S = "{ S1[t,i] -> [t,i] }";
2841 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2842 return -1;
2844 /* Fig. 5 of CC2008 */
2845 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2846 "j <= -1 + N }";
2847 W = "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2848 "j >= 2 and j <= -1 + N }";
2849 R = "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2850 "j >= 2 and j <= -1 + N; "
2851 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2852 "j >= 2 and j <= -1 + N }";
2853 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2854 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2855 return -1;
2857 D = "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2858 W = "{ S1[i] -> a[i] }";
2859 R = "{ S2[i] -> a[i+1] }";
2860 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2861 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2862 return -1;
2864 D = "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2865 W = "{ S1[i] -> a[i] }";
2866 R = "{ S2[i] -> a[9-i] }";
2867 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2868 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2869 return -1;
2871 D = "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2872 W = "{ S1[i] -> a[i] }";
2873 R = "[N] -> { S2[i] -> a[N-1-i] }";
2874 S = "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2875 if (test_one_schedule(ctx, D, W, R, S, 1, 1) < 0)
2876 return -1;
2878 D = "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2879 W = "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2880 R = "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2881 S = "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2882 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2883 return -1;
2885 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2886 W = "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2887 R = "{ S2[i,j] -> a[i-1,j] }";
2888 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2889 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2890 return -1;
2892 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2893 W = "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2894 R = "{ S2[i,j] -> a[i,j-1] }";
2895 S = "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2896 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2897 return -1;
2899 D = "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2900 W = "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2901 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2902 R = "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2903 S = "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2904 "S_0[] -> [0, 0, 0] }";
2905 if (test_one_schedule(ctx, D, W, R, S, 1, 0) < 0)
2906 return -1;
2907 ctx->opt->schedule_parametric = 0;
2908 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2909 return -1;
2910 ctx->opt->schedule_parametric = 1;
2912 D = "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2913 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2914 W = "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2915 R = "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2916 "S4[i] -> a[i,N] }";
2917 S = "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2918 "S4[i] -> [4,i,0] }";
2919 if (test_one_schedule(ctx, D, W, R, S, 2, 0) < 0)
2920 return -1;
2922 D = "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2923 W = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2924 "j <= N }";
2925 R = "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2926 "j <= N; "
2927 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2928 "j <= N }";
2929 S = "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2930 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2931 return -1;
2933 D = "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2934 " S_2[t] : t >= 0 and t <= -1 + N; "
2935 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2936 "i <= -1 + N }";
2937 W = "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2938 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2939 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2940 "i >= 0 and i <= -1 + N }";
2941 R = "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2942 "i >= 0 and i <= -1 + N; "
2943 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2944 S = "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2945 " S_0[t] -> [0, t, 0] }";
2947 if (test_one_schedule(ctx, D, W, R, S, 2, 1) < 0)
2948 return -1;
2949 ctx->opt->schedule_parametric = 0;
2950 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2951 return -1;
2952 ctx->opt->schedule_parametric = 1;
2954 D = "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2955 S = "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2956 if (test_one_schedule(ctx, D, "{}", "{}", S, 2, 2) < 0)
2957 return -1;
2959 D = "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2960 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2961 W = "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2962 "j >= 0 and j <= -1 + N; "
2963 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2964 R = "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2965 "j >= 0 and j <= -1 + N; "
2966 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2967 S = "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2968 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2969 return -1;
2971 D = "{ S_0[i] : i >= 0 }";
2972 W = "{ S_0[i] -> a[i] : i >= 0 }";
2973 R = "{ S_0[i] -> a[0] : i >= 0 }";
2974 S = "{ S_0[i] -> [0, i, 0] }";
2975 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2976 return -1;
2978 D = "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
2979 W = "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
2980 R = "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
2981 S = "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
2982 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2983 return -1;
2985 D = "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
2986 "k <= -1 + n and k >= 0 }";
2987 W = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
2988 R = "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
2989 "k <= -1 + n and k >= 0; "
2990 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
2991 "k <= -1 + n and k >= 0; "
2992 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
2993 "k <= -1 + n and k >= 0 }";
2994 S = "[n] -> { S_0[j, k] -> [2, j, k] }";
2995 ctx->opt->schedule_outer_coincidence = 1;
2996 if (test_one_schedule(ctx, D, W, R, S, 0, 0) < 0)
2997 return -1;
2998 ctx->opt->schedule_outer_coincidence = 0;
3000 D = "{Stmt_for_body24[i0, i1, i2, i3]:"
3001 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
3002 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
3003 "Stmt_for_body24[i0, i1, 1, 0]:"
3004 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
3005 "Stmt_for_body7[i0, i1, i2]:"
3006 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
3007 "i2 <= 7 }";
3009 V = "{Stmt_for_body24[0, i1, i2, i3] -> "
3010 "Stmt_for_body24[1, i1, i2, i3]:"
3011 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
3012 "i2 >= 1;"
3013 "Stmt_for_body24[0, i1, i2, i3] -> "
3014 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
3015 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
3016 "i3 >= 0;"
3017 "Stmt_for_body24[0, i1, i2, i3] ->"
3018 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
3019 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
3020 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
3021 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
3022 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
3023 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
3024 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
3025 "i1 <= 6 and i1 >= 0;"
3026 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
3027 "Stmt_for_body7[i0, i1, i2] -> "
3028 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
3029 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
3030 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
3031 "Stmt_for_body7[i0, i1, i2] -> "
3032 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
3033 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
3034 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
3035 P = V;
3036 S = "{ Stmt_for_body24[i0, i1, i2, i3] -> "
3037 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
3038 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
3040 if (test_special_schedule(ctx, D, V, P, S) < 0)
3041 return -1;
3043 D = "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
3044 V = "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
3045 "j >= 1 and j <= 7;"
3046 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
3047 "j >= 1 and j <= 8 }";
3048 P = "{ }";
3049 S = "{ S_0[i, j] -> [i + j, j] }";
3050 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
3051 if (test_special_schedule(ctx, D, V, P, S) < 0)
3052 return -1;
3053 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
3055 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
3056 D = "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
3057 "j >= 0 and j <= -1 + i }";
3058 V = "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
3059 "i <= -1 + N and j >= 0;"
3060 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
3061 "i <= -2 + N }";
3062 P = "{ }";
3063 S = "{ S_0[i, j] -> [i, j] }";
3064 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
3065 if (test_special_schedule(ctx, D, V, P, S) < 0)
3066 return -1;
3067 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
3069 /* Test both algorithms on a case with only proximity dependences. */
3070 D = "{ S[i,j] : 0 <= i <= 10 }";
3071 V = "{ }";
3072 P = "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
3073 S = "{ S[i, j] -> [j, i] }";
3074 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
3075 if (test_special_schedule(ctx, D, V, P, S) < 0)
3076 return -1;
3077 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
3078 if (test_special_schedule(ctx, D, V, P, S) < 0)
3079 return -1;
3081 D = "{ A[a]; B[] }";
3082 V = "{}";
3083 P = "{ A[a] -> B[] }";
3084 if (test_has_schedule(ctx, D, V, P) < 0)
3085 return -1;
3087 if (test_padded_schedule(ctx) < 0)
3088 return -1;
3090 /* Check that check for progress is not confused by rational
3091 * solution.
3093 D = "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
3094 V = "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
3095 "i0 <= -2 + N; "
3096 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
3097 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
3098 P = "{}";
3099 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_FEAUTRIER;
3100 if (test_has_schedule(ctx, D, V, P) < 0)
3101 return -1;
3102 ctx->opt->schedule_algorithm = ISL_SCHEDULE_ALGORITHM_ISL;
3104 if (test_conditional_schedule_constraints(ctx) < 0)
3105 return -1;
3107 return 0;
3110 int test_plain_injective(isl_ctx *ctx, const char *str, int injective)
3112 isl_union_map *umap;
3113 int test;
3115 umap = isl_union_map_read_from_str(ctx, str);
3116 test = isl_union_map_plain_is_injective(umap);
3117 isl_union_map_free(umap);
3118 if (test < 0)
3119 return -1;
3120 if (test == injective)
3121 return 0;
3122 if (injective)
3123 isl_die(ctx, isl_error_unknown,
3124 "map not detected as injective", return -1);
3125 else
3126 isl_die(ctx, isl_error_unknown,
3127 "map detected as injective", return -1);
3130 int test_injective(isl_ctx *ctx)
3132 const char *str;
3134 if (test_plain_injective(ctx, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
3135 return -1;
3136 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> B[0]}", 1))
3137 return -1;
3138 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[1]}", 1))
3139 return -1;
3140 if (test_plain_injective(ctx, "{S[] -> A[0]; T[] -> A[0]}", 0))
3141 return -1;
3142 if (test_plain_injective(ctx, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
3143 return -1;
3144 if (test_plain_injective(ctx, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
3145 return -1;
3146 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
3147 return -1;
3148 if (test_plain_injective(ctx, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
3149 return -1;
3151 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
3152 if (test_plain_injective(ctx, str, 1))
3153 return -1;
3154 str = "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
3155 if (test_plain_injective(ctx, str, 0))
3156 return -1;
3158 return 0;
3161 static int aff_plain_is_equal(__isl_keep isl_aff *aff, const char *str)
3163 isl_aff *aff2;
3164 int equal;
3166 if (!aff)
3167 return -1;
3169 aff2 = isl_aff_read_from_str(isl_aff_get_ctx(aff), str);
3170 equal = isl_aff_plain_is_equal(aff, aff2);
3171 isl_aff_free(aff2);
3173 return equal;
3176 static int aff_check_plain_equal(__isl_keep isl_aff *aff, const char *str)
3178 int equal;
3180 equal = aff_plain_is_equal(aff, str);
3181 if (equal < 0)
3182 return -1;
3183 if (!equal)
3184 isl_die(isl_aff_get_ctx(aff), isl_error_unknown,
3185 "result not as expected", return -1);
3186 return 0;
3189 struct {
3190 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
3191 __isl_take isl_aff *aff2);
3192 } aff_bin_op[] = {
3193 ['+'] = { &isl_aff_add },
3194 ['-'] = { &isl_aff_sub },
3195 ['*'] = { &isl_aff_mul },
3198 struct {
3199 const char *arg1;
3200 unsigned char op;
3201 const char *arg2;
3202 const char *res;
3203 } aff_bin_tests[] = {
3204 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
3205 "{ [i] -> [2i] }" },
3206 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
3207 "{ [i] -> [0] }" },
3208 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
3209 "{ [i] -> [2i] }" },
3210 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
3211 "{ [i] -> [2i] }" },
3212 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
3213 "{ [i] -> [NaN] }" },
3214 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
3215 "{ [i] -> [NaN] }" },
3216 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
3217 "{ [i] -> [NaN] }" },
3218 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
3219 "{ [i] -> [NaN] }" },
3220 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
3221 "{ [i] -> [NaN] }" },
3222 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
3223 "{ [i] -> [NaN] }" },
3224 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
3225 "{ [i] -> [NaN] }" },
3226 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
3227 "{ [i] -> [NaN] }" },
3230 /* Perform some basic tests of binary operations on isl_aff objects.
3232 static int test_bin_aff(isl_ctx *ctx)
3234 int i;
3235 isl_aff *aff1, *aff2, *res;
3236 __isl_give isl_aff *(*fn)(__isl_take isl_aff *aff1,
3237 __isl_take isl_aff *aff2);
3238 int ok;
3240 for (i = 0; i < ARRAY_SIZE(aff_bin_tests); ++i) {
3241 aff1 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg1);
3242 aff2 = isl_aff_read_from_str(ctx, aff_bin_tests[i].arg2);
3243 res = isl_aff_read_from_str(ctx, aff_bin_tests[i].res);
3244 fn = aff_bin_op[aff_bin_tests[i].op].fn;
3245 aff1 = fn(aff1, aff2);
3246 if (isl_aff_is_nan(res))
3247 ok = isl_aff_is_nan(aff1);
3248 else
3249 ok = isl_aff_plain_is_equal(aff1, res);
3250 isl_aff_free(aff1);
3251 isl_aff_free(res);
3252 if (ok < 0)
3253 return -1;
3254 if (!ok)
3255 isl_die(ctx, isl_error_unknown,
3256 "unexpected result", return -1);
3259 return 0;
3262 int test_aff(isl_ctx *ctx)
3264 const char *str;
3265 isl_set *set;
3266 isl_space *space;
3267 isl_local_space *ls;
3268 isl_aff *aff;
3269 int zero, equal;
3271 if (test_bin_aff(ctx) < 0)
3272 return -1;
3274 space = isl_space_set_alloc(ctx, 0, 1);
3275 ls = isl_local_space_from_space(space);
3276 aff = isl_aff_zero_on_domain(ls);
3278 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
3279 aff = isl_aff_scale_down_ui(aff, 3);
3280 aff = isl_aff_floor(aff);
3281 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
3282 aff = isl_aff_scale_down_ui(aff, 2);
3283 aff = isl_aff_floor(aff);
3284 aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1);
3286 str = "{ [10] }";
3287 set = isl_set_read_from_str(ctx, str);
3288 aff = isl_aff_gist(aff, set);
3290 aff = isl_aff_add_constant_si(aff, -16);
3291 zero = isl_aff_plain_is_zero(aff);
3292 isl_aff_free(aff);
3294 if (zero < 0)
3295 return -1;
3296 if (!zero)
3297 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3299 aff = isl_aff_read_from_str(ctx, "{ [-1] }");
3300 aff = isl_aff_scale_down_ui(aff, 64);
3301 aff = isl_aff_floor(aff);
3302 equal = aff_check_plain_equal(aff, "{ [-1] }");
3303 isl_aff_free(aff);
3304 if (equal < 0)
3305 return -1;
3307 return 0;
3310 int test_dim_max(isl_ctx *ctx)
3312 int equal;
3313 const char *str;
3314 isl_set *set1, *set2;
3315 isl_set *set;
3316 isl_map *map;
3317 isl_pw_aff *pwaff;
3319 str = "[N] -> { [i] : 0 <= i <= min(N,10) }";
3320 set = isl_set_read_from_str(ctx, str);
3321 pwaff = isl_set_dim_max(set, 0);
3322 set1 = isl_set_from_pw_aff(pwaff);
3323 str = "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
3324 set2 = isl_set_read_from_str(ctx, str);
3325 equal = isl_set_is_equal(set1, set2);
3326 isl_set_free(set1);
3327 isl_set_free(set2);
3328 if (equal < 0)
3329 return -1;
3330 if (!equal)
3331 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3333 str = "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
3334 set = isl_set_read_from_str(ctx, str);
3335 pwaff = isl_set_dim_max(set, 0);
3336 set1 = isl_set_from_pw_aff(pwaff);
3337 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3338 set2 = isl_set_read_from_str(ctx, str);
3339 equal = isl_set_is_equal(set1, set2);
3340 isl_set_free(set1);
3341 isl_set_free(set2);
3342 if (equal < 0)
3343 return -1;
3344 if (!equal)
3345 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3347 str = "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
3348 set = isl_set_read_from_str(ctx, str);
3349 pwaff = isl_set_dim_max(set, 0);
3350 set1 = isl_set_from_pw_aff(pwaff);
3351 str = "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3352 set2 = isl_set_read_from_str(ctx, str);
3353 equal = isl_set_is_equal(set1, set2);
3354 isl_set_free(set1);
3355 isl_set_free(set2);
3356 if (equal < 0)
3357 return -1;
3358 if (!equal)
3359 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3361 str = "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
3362 "0 <= i < N and 0 <= j < M }";
3363 map = isl_map_read_from_str(ctx, str);
3364 set = isl_map_range(map);
3366 pwaff = isl_set_dim_max(isl_set_copy(set), 0);
3367 set1 = isl_set_from_pw_aff(pwaff);
3368 str = "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
3369 set2 = isl_set_read_from_str(ctx, str);
3370 equal = isl_set_is_equal(set1, set2);
3371 isl_set_free(set1);
3372 isl_set_free(set2);
3374 pwaff = isl_set_dim_max(isl_set_copy(set), 3);
3375 set1 = isl_set_from_pw_aff(pwaff);
3376 str = "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
3377 set2 = isl_set_read_from_str(ctx, str);
3378 if (equal >= 0 && equal)
3379 equal = isl_set_is_equal(set1, set2);
3380 isl_set_free(set1);
3381 isl_set_free(set2);
3383 isl_set_free(set);
3385 if (equal < 0)
3386 return -1;
3387 if (!equal)
3388 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3390 /* Check that solutions are properly merged. */
3391 str = "[n] -> { [a, b, c] : c >= -4a - 2b and "
3392 "c <= -1 + n - 4a - 2b and c >= -2b and "
3393 "4a >= -4 + n and c >= 0 }";
3394 set = isl_set_read_from_str(ctx, str);
3395 pwaff = isl_set_dim_min(set, 2);
3396 set1 = isl_set_from_pw_aff(pwaff);
3397 str = "[n] -> { [(0)] : n >= 1 }";
3398 set2 = isl_set_read_from_str(ctx, str);
3399 equal = isl_set_is_equal(set1, set2);
3400 isl_set_free(set1);
3401 isl_set_free(set2);
3403 if (equal < 0)
3404 return -1;
3405 if (!equal)
3406 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3408 /* Check that empty solution lie in the right space. */
3409 str = "[n] -> { [t,a] : 1 = 0 }";
3410 set = isl_set_read_from_str(ctx, str);
3411 pwaff = isl_set_dim_max(set, 0);
3412 set1 = isl_set_from_pw_aff(pwaff);
3413 str = "[n] -> { [t] : 1 = 0 }";
3414 set2 = isl_set_read_from_str(ctx, str);
3415 equal = isl_set_is_equal(set1, set2);
3416 isl_set_free(set1);
3417 isl_set_free(set2);
3419 if (equal < 0)
3420 return -1;
3421 if (!equal)
3422 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3424 return 0;
3427 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
3429 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff *pma,
3430 const char *str)
3432 isl_ctx *ctx;
3433 isl_pw_multi_aff *pma2;
3434 int equal;
3436 if (!pma)
3437 return -1;
3439 ctx = isl_pw_multi_aff_get_ctx(pma);
3440 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
3441 equal = isl_pw_multi_aff_plain_is_equal(pma, pma2);
3442 isl_pw_multi_aff_free(pma2);
3444 return equal;
3447 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
3448 * represented by "str".
3450 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff *pma,
3451 const char *str)
3453 int equal;
3455 equal = pw_multi_aff_plain_is_equal(pma, str);
3456 if (equal < 0)
3457 return -1;
3458 if (!equal)
3459 isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_unknown,
3460 "result not as expected", return -1);
3461 return 0;
3464 /* Basic test for isl_pw_multi_aff_product.
3466 * Check that multiple pieces are properly handled.
3468 static int test_product_pma(isl_ctx *ctx)
3470 int equal;
3471 const char *str;
3472 isl_pw_multi_aff *pma1, *pma2;
3474 str = "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
3475 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
3476 str = "{ C[] -> D[] }";
3477 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
3478 pma1 = isl_pw_multi_aff_product(pma1, pma2);
3479 str = "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
3480 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
3481 equal = pw_multi_aff_check_plain_equal(pma1, str);
3482 isl_pw_multi_aff_free(pma1);
3483 if (equal < 0)
3484 return -1;
3486 return 0;
3489 int test_product(isl_ctx *ctx)
3491 const char *str;
3492 isl_set *set;
3493 isl_union_set *uset1, *uset2;
3494 int ok;
3496 str = "{ A[i] }";
3497 set = isl_set_read_from_str(ctx, str);
3498 set = isl_set_product(set, isl_set_copy(set));
3499 ok = isl_set_is_wrapping(set);
3500 isl_set_free(set);
3501 if (ok < 0)
3502 return -1;
3503 if (!ok)
3504 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3506 str = "{ [] }";
3507 uset1 = isl_union_set_read_from_str(ctx, str);
3508 uset1 = isl_union_set_product(uset1, isl_union_set_copy(uset1));
3509 str = "{ [[] -> []] }";
3510 uset2 = isl_union_set_read_from_str(ctx, str);
3511 ok = isl_union_set_is_equal(uset1, uset2);
3512 isl_union_set_free(uset1);
3513 isl_union_set_free(uset2);
3514 if (ok < 0)
3515 return -1;
3516 if (!ok)
3517 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3519 if (test_product_pma(ctx) < 0)
3520 return -1;
3522 return 0;
3525 /* Check that two sets are not considered disjoint just because
3526 * they have a different set of (named) parameters.
3528 static int test_disjoint(isl_ctx *ctx)
3530 const char *str;
3531 isl_set *set, *set2;
3532 int disjoint;
3534 str = "[n] -> { [[]->[]] }";
3535 set = isl_set_read_from_str(ctx, str);
3536 str = "{ [[]->[]] }";
3537 set2 = isl_set_read_from_str(ctx, str);
3538 disjoint = isl_set_is_disjoint(set, set2);
3539 isl_set_free(set);
3540 isl_set_free(set2);
3541 if (disjoint < 0)
3542 return -1;
3543 if (disjoint)
3544 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3546 return 0;
3549 int test_equal(isl_ctx *ctx)
3551 const char *str;
3552 isl_set *set, *set2;
3553 int equal;
3555 str = "{ S_6[i] }";
3556 set = isl_set_read_from_str(ctx, str);
3557 str = "{ S_7[i] }";
3558 set2 = isl_set_read_from_str(ctx, str);
3559 equal = isl_set_is_equal(set, set2);
3560 isl_set_free(set);
3561 isl_set_free(set2);
3562 if (equal < 0)
3563 return -1;
3564 if (equal)
3565 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3567 return 0;
3570 static int test_plain_fixed(isl_ctx *ctx, __isl_take isl_map *map,
3571 enum isl_dim_type type, unsigned pos, int fixed)
3573 int test;
3575 test = isl_map_plain_is_fixed(map, type, pos, NULL);
3576 isl_map_free(map);
3577 if (test < 0)
3578 return -1;
3579 if (test == fixed)
3580 return 0;
3581 if (fixed)
3582 isl_die(ctx, isl_error_unknown,
3583 "map not detected as fixed", return -1);
3584 else
3585 isl_die(ctx, isl_error_unknown,
3586 "map detected as fixed", return -1);
3589 int test_fixed(isl_ctx *ctx)
3591 const char *str;
3592 isl_map *map;
3594 str = "{ [i] -> [i] }";
3595 map = isl_map_read_from_str(ctx, str);
3596 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 0))
3597 return -1;
3598 str = "{ [i] -> [1] }";
3599 map = isl_map_read_from_str(ctx, str);
3600 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
3601 return -1;
3602 str = "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
3603 map = isl_map_read_from_str(ctx, str);
3604 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
3605 return -1;
3606 map = isl_map_read_from_str(ctx, str);
3607 map = isl_map_neg(map);
3608 if (test_plain_fixed(ctx, map, isl_dim_out, 0, 1))
3609 return -1;
3611 return 0;
3614 struct isl_vertices_test_data {
3615 const char *set;
3616 int n;
3617 const char *vertex[2];
3618 } vertices_tests[] = {
3619 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
3620 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
3621 { "{ A[t, i] : t = 14 and i = 1 }",
3622 1, { "{ A[14, 1] }" } },
3625 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
3627 static int find_vertex(__isl_take isl_vertex *vertex, void *user)
3629 struct isl_vertices_test_data *data = user;
3630 isl_ctx *ctx;
3631 isl_multi_aff *ma;
3632 isl_basic_set *bset;
3633 isl_pw_multi_aff *pma;
3634 int i;
3635 int equal;
3637 ctx = isl_vertex_get_ctx(vertex);
3638 bset = isl_vertex_get_domain(vertex);
3639 ma = isl_vertex_get_expr(vertex);
3640 pma = isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset), ma);
3642 for (i = 0; i < data->n; ++i) {
3643 isl_pw_multi_aff *pma_i;
3645 pma_i = isl_pw_multi_aff_read_from_str(ctx, data->vertex[i]);
3646 equal = isl_pw_multi_aff_plain_is_equal(pma, pma_i);
3647 isl_pw_multi_aff_free(pma_i);
3649 if (equal < 0 || equal)
3650 break;
3653 isl_pw_multi_aff_free(pma);
3654 isl_vertex_free(vertex);
3656 if (equal < 0)
3657 return -1;
3659 return equal ? 0 : - 1;
3662 int test_vertices(isl_ctx *ctx)
3664 int i;
3666 for (i = 0; i < ARRAY_SIZE(vertices_tests); ++i) {
3667 isl_basic_set *bset;
3668 isl_vertices *vertices;
3669 int ok = 1;
3670 int n;
3672 bset = isl_basic_set_read_from_str(ctx, vertices_tests[i].set);
3673 vertices = isl_basic_set_compute_vertices(bset);
3674 n = isl_vertices_get_n_vertices(vertices);
3675 if (vertices_tests[i].n != n)
3676 ok = 0;
3677 if (isl_vertices_foreach_vertex(vertices, &find_vertex,
3678 &vertices_tests[i]) < 0)
3679 ok = 0;
3680 isl_vertices_free(vertices);
3681 isl_basic_set_free(bset);
3683 if (!vertices)
3684 return -1;
3685 if (!ok)
3686 isl_die(ctx, isl_error_unknown, "unexpected vertices",
3687 return -1);
3690 return 0;
3693 int test_union_pw(isl_ctx *ctx)
3695 int equal;
3696 const char *str;
3697 isl_union_set *uset;
3698 isl_union_pw_qpolynomial *upwqp1, *upwqp2;
3700 str = "{ [x] -> x^2 }";
3701 upwqp1 = isl_union_pw_qpolynomial_read_from_str(ctx, str);
3702 upwqp2 = isl_union_pw_qpolynomial_copy(upwqp1);
3703 uset = isl_union_pw_qpolynomial_domain(upwqp1);
3704 upwqp1 = isl_union_pw_qpolynomial_copy(upwqp2);
3705 upwqp1 = isl_union_pw_qpolynomial_intersect_domain(upwqp1, uset);
3706 equal = isl_union_pw_qpolynomial_plain_is_equal(upwqp1, upwqp2);
3707 isl_union_pw_qpolynomial_free(upwqp1);
3708 isl_union_pw_qpolynomial_free(upwqp2);
3709 if (equal < 0)
3710 return -1;
3711 if (!equal)
3712 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3714 return 0;
3717 int test_output(isl_ctx *ctx)
3719 char *s;
3720 const char *str;
3721 isl_pw_aff *pa;
3722 isl_printer *p;
3723 int equal;
3725 str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
3726 pa = isl_pw_aff_read_from_str(ctx, str);
3728 p = isl_printer_to_str(ctx);
3729 p = isl_printer_set_output_format(p, ISL_FORMAT_C);
3730 p = isl_printer_print_pw_aff(p, pa);
3731 s = isl_printer_get_str(p);
3732 isl_printer_free(p);
3733 isl_pw_aff_free(pa);
3734 if (!s)
3735 equal = -1;
3736 else
3737 equal = !strcmp(s, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
3738 free(s);
3739 if (equal < 0)
3740 return -1;
3741 if (!equal)
3742 isl_die(ctx, isl_error_unknown, "unexpected result", return -1);
3744 return 0;
3747 int test_sample(isl_ctx *ctx)
3749 const char *str;
3750 isl_basic_set *bset1, *bset2;
3751 int empty, subset;
3753 str = "{ [a, b, c, d, e, f, g, h, i, j, k] : "
3754 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
3755 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
3756 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
3757 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
3758 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
3759 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
3760 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
3761 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
3762 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
3763 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
3764 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
3765 "d - 1073741821e and "
3766 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
3767 "3j >= 1 - a + b + 2e and "
3768 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
3769 "3i <= 4 - a + 4b - e and "
3770 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
3771 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
3772 "c <= -1 + a and 3i >= -2 - a + 3e and "
3773 "1073741822e <= 1073741823 - a + 1073741822b + c and "
3774 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
3775 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
3776 "1073741823e >= 1 + 1073741823b - d and "
3777 "3i >= 1073741823b + c - 1073741823e - f and "
3778 "3i >= 1 + 2b + e + 3g }";
3779 bset1 = isl_basic_set_read_from_str(ctx, str);
3780 bset2 = isl_basic_set_sample(isl_basic_set_copy(bset1));
3781 empty = isl_basic_set_is_empty(bset2);
3782 subset = isl_basic_set_is_subset(bset2, bset1);
3783 isl_basic_set_free(bset1);
3784 isl_basic_set_free(bset2);
3785 if (empty < 0 || subset < 0)
3786 return -1;
3787 if (empty)
3788 isl_die(ctx, isl_error_unknown, "point not found", return -1);
3789 if (!subset)
3790 isl_die(ctx, isl_error_unknown, "bad point found", return -1);
3792 return 0;
3795 int test_fixed_power(isl_ctx *ctx)
3797 const char *str;
3798 isl_map *map;
3799 isl_int exp;
3800 int equal;
3802 isl_int_init(exp);
3803 str = "{ [i] -> [i + 1] }";
3804 map = isl_map_read_from_str(ctx, str);
3805 isl_int_set_si(exp, 23);
3806 map = isl_map_fixed_power(map, exp);
3807 equal = map_check_equal(map, "{ [i] -> [i + 23] }");
3808 isl_int_clear(exp);
3809 isl_map_free(map);
3810 if (equal < 0)
3811 return -1;
3813 return 0;
3816 int test_slice(isl_ctx *ctx)
3818 const char *str;
3819 isl_map *map;
3820 int equal;
3822 str = "{ [i] -> [j] }";
3823 map = isl_map_read_from_str(ctx, str);
3824 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_out, 0);
3825 equal = map_check_equal(map, "{ [i] -> [i] }");
3826 isl_map_free(map);
3827 if (equal < 0)
3828 return -1;
3830 str = "{ [i] -> [j] }";
3831 map = isl_map_read_from_str(ctx, str);
3832 map = isl_map_equate(map, isl_dim_in, 0, isl_dim_in, 0);
3833 equal = map_check_equal(map, "{ [i] -> [j] }");
3834 isl_map_free(map);
3835 if (equal < 0)
3836 return -1;
3838 str = "{ [i] -> [j] }";
3839 map = isl_map_read_from_str(ctx, str);
3840 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_out, 0);
3841 equal = map_check_equal(map, "{ [i] -> [-i] }");
3842 isl_map_free(map);
3843 if (equal < 0)
3844 return -1;
3846 str = "{ [i] -> [j] }";
3847 map = isl_map_read_from_str(ctx, str);
3848 map = isl_map_oppose(map, isl_dim_in, 0, isl_dim_in, 0);
3849 equal = map_check_equal(map, "{ [0] -> [j] }");
3850 isl_map_free(map);
3851 if (equal < 0)
3852 return -1;
3854 str = "{ [i] -> [j] }";
3855 map = isl_map_read_from_str(ctx, str);
3856 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_out, 0);
3857 equal = map_check_equal(map, "{ [i] -> [j] : i > j }");
3858 isl_map_free(map);
3859 if (equal < 0)
3860 return -1;
3862 str = "{ [i] -> [j] }";
3863 map = isl_map_read_from_str(ctx, str);
3864 map = isl_map_order_gt(map, isl_dim_in, 0, isl_dim_in, 0);
3865 equal = map_check_equal(map, "{ [i] -> [j] : false }");
3866 isl_map_free(map);
3867 if (equal < 0)
3868 return -1;
3870 return 0;
3873 int test_eliminate(isl_ctx *ctx)
3875 const char *str;
3876 isl_map *map;
3877 int equal;
3879 str = "{ [i] -> [j] : i = 2j }";
3880 map = isl_map_read_from_str(ctx, str);
3881 map = isl_map_eliminate(map, isl_dim_out, 0, 1);
3882 equal = map_check_equal(map, "{ [i] -> [j] : exists a : i = 2a }");
3883 isl_map_free(map);
3884 if (equal < 0)
3885 return -1;
3887 return 0;
3890 /* Check that isl_set_dim_residue_class detects that the values of j
3891 * in the set below are all odd and that it does not detect any spurious
3892 * strides.
3894 static int test_residue_class(isl_ctx *ctx)
3896 const char *str;
3897 isl_set *set;
3898 isl_int m, r;
3899 int res;
3901 str = "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
3902 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
3903 set = isl_set_read_from_str(ctx, str);
3904 isl_int_init(m);
3905 isl_int_init(r);
3906 res = isl_set_dim_residue_class(set, 1, &m, &r);
3907 if (res >= 0 &&
3908 (isl_int_cmp_si(m, 2) != 0 || isl_int_cmp_si(r, 1) != 0))
3909 isl_die(ctx, isl_error_unknown, "incorrect residue class",
3910 res = -1);
3911 isl_int_clear(r);
3912 isl_int_clear(m);
3913 isl_set_free(set);
3915 return res;
3918 int test_align_parameters(isl_ctx *ctx)
3920 const char *str;
3921 isl_space *space;
3922 isl_multi_aff *ma1, *ma2;
3923 int equal;
3925 str = "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
3926 ma1 = isl_multi_aff_read_from_str(ctx, str);
3928 space = isl_space_params_alloc(ctx, 1);
3929 space = isl_space_set_dim_name(space, isl_dim_param, 0, "N");
3930 ma1 = isl_multi_aff_align_params(ma1, space);
3932 str = "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
3933 ma2 = isl_multi_aff_read_from_str(ctx, str);
3935 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
3937 isl_multi_aff_free(ma1);
3938 isl_multi_aff_free(ma2);
3940 if (equal < 0)
3941 return -1;
3942 if (!equal)
3943 isl_die(ctx, isl_error_unknown,
3944 "result not as expected", return -1);
3946 return 0;
3949 static int test_list(isl_ctx *ctx)
3951 isl_id *a, *b, *c, *d, *id;
3952 isl_id_list *list;
3953 int ok;
3955 a = isl_id_alloc(ctx, "a", NULL);
3956 b = isl_id_alloc(ctx, "b", NULL);
3957 c = isl_id_alloc(ctx, "c", NULL);
3958 d = isl_id_alloc(ctx, "d", NULL);
3960 list = isl_id_list_alloc(ctx, 4);
3961 list = isl_id_list_add(list, a);
3962 list = isl_id_list_add(list, b);
3963 list = isl_id_list_add(list, c);
3964 list = isl_id_list_add(list, d);
3965 list = isl_id_list_drop(list, 1, 1);
3967 if (isl_id_list_n_id(list) != 3) {
3968 isl_id_list_free(list);
3969 isl_die(ctx, isl_error_unknown,
3970 "unexpected number of elements in list", return -1);
3973 id = isl_id_list_get_id(list, 0);
3974 ok = id == a;
3975 isl_id_free(id);
3976 id = isl_id_list_get_id(list, 1);
3977 ok = ok && id == c;
3978 isl_id_free(id);
3979 id = isl_id_list_get_id(list, 2);
3980 ok = ok && id == d;
3981 isl_id_free(id);
3983 isl_id_list_free(list);
3985 if (!ok)
3986 isl_die(ctx, isl_error_unknown,
3987 "unexpected elements in list", return -1);
3989 return 0;
3992 const char *set_conversion_tests[] = {
3993 "[N] -> { [i] : N - 1 <= 2 i <= N }",
3994 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
3995 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
3996 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
3999 /* Check that converting from isl_set to isl_pw_multi_aff and back
4000 * to isl_set produces the original isl_set.
4002 static int test_set_conversion(isl_ctx *ctx)
4004 int i;
4005 const char *str;
4006 isl_set *set1, *set2;
4007 isl_pw_multi_aff *pma;
4008 int equal;
4010 for (i = 0; i < ARRAY_SIZE(set_conversion_tests); ++i) {
4011 str = set_conversion_tests[i];
4012 set1 = isl_set_read_from_str(ctx, str);
4013 pma = isl_pw_multi_aff_from_set(isl_set_copy(set1));
4014 set2 = isl_set_from_pw_multi_aff(pma);
4015 equal = isl_set_is_equal(set1, set2);
4016 isl_set_free(set1);
4017 isl_set_free(set2);
4019 if (equal < 0)
4020 return -1;
4021 if (!equal)
4022 isl_die(ctx, isl_error_unknown, "bad conversion",
4023 return -1);
4026 return 0;
4029 /* Check that converting from isl_map to isl_pw_multi_aff and back
4030 * to isl_map produces the original isl_map.
4032 static int test_map_conversion(isl_ctx *ctx)
4034 const char *str;
4035 isl_map *map1, *map2;
4036 isl_pw_multi_aff *pma;
4037 int equal;
4039 str = "{ [a, b, c, d] -> s0[a, b, e, f] : "
4040 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
4041 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
4042 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
4043 "9e <= -2 - 2a) }";
4044 map1 = isl_map_read_from_str(ctx, str);
4045 pma = isl_pw_multi_aff_from_map(isl_map_copy(map1));
4046 map2 = isl_map_from_pw_multi_aff(pma);
4047 equal = isl_map_is_equal(map1, map2);
4048 isl_map_free(map1);
4049 isl_map_free(map2);
4051 if (equal < 0)
4052 return -1;
4053 if (!equal)
4054 isl_die(ctx, isl_error_unknown, "bad conversion", return -1);
4056 return 0;
4059 static int test_conversion(isl_ctx *ctx)
4061 if (test_set_conversion(ctx) < 0)
4062 return -1;
4063 if (test_map_conversion(ctx) < 0)
4064 return -1;
4065 return 0;
4068 /* Check that isl_basic_map_curry does not modify input.
4070 static int test_curry(isl_ctx *ctx)
4072 const char *str;
4073 isl_basic_map *bmap1, *bmap2;
4074 int equal;
4076 str = "{ [A[] -> B[]] -> C[] }";
4077 bmap1 = isl_basic_map_read_from_str(ctx, str);
4078 bmap2 = isl_basic_map_curry(isl_basic_map_copy(bmap1));
4079 equal = isl_basic_map_is_equal(bmap1, bmap2);
4080 isl_basic_map_free(bmap1);
4081 isl_basic_map_free(bmap2);
4083 if (equal < 0)
4084 return -1;
4085 if (equal)
4086 isl_die(ctx, isl_error_unknown,
4087 "curried map should not be equal to original",
4088 return -1);
4090 return 0;
4093 struct {
4094 const char *set;
4095 const char *ma;
4096 const char *res;
4097 } preimage_tests[] = {
4098 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
4099 "{ A[j,i] -> B[i,j] }",
4100 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
4101 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4102 "{ A[a,b] -> B[a/2,b/6] }",
4103 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
4104 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4105 "{ A[a,b] -> B[a/2,b/6] }",
4106 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
4107 "exists i,j : a = 2 i and b = 6 j }" },
4108 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
4109 "[n] -> { : 0 <= n <= 100 }" },
4110 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4111 "{ A[a] -> B[2a] }",
4112 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
4113 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4114 "{ A[a] -> B[([a/2])] }",
4115 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
4116 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
4117 "{ A[a] -> B[a,a,a/3] }",
4118 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
4119 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
4120 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
4123 static int test_preimage_basic_set(isl_ctx *ctx)
4125 int i;
4126 isl_basic_set *bset1, *bset2;
4127 isl_multi_aff *ma;
4128 int equal;
4130 for (i = 0; i < ARRAY_SIZE(preimage_tests); ++i) {
4131 bset1 = isl_basic_set_read_from_str(ctx, preimage_tests[i].set);
4132 ma = isl_multi_aff_read_from_str(ctx, preimage_tests[i].ma);
4133 bset2 = isl_basic_set_read_from_str(ctx, preimage_tests[i].res);
4134 bset1 = isl_basic_set_preimage_multi_aff(bset1, ma);
4135 equal = isl_basic_set_is_equal(bset1, bset2);
4136 isl_basic_set_free(bset1);
4137 isl_basic_set_free(bset2);
4138 if (equal < 0)
4139 return -1;
4140 if (!equal)
4141 isl_die(ctx, isl_error_unknown, "bad preimage",
4142 return -1);
4145 return 0;
4148 struct {
4149 const char *map;
4150 const char *ma;
4151 const char *res;
4152 } preimage_domain_tests[] = {
4153 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
4154 "{ A[j,i] -> B[i,j] }",
4155 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
4156 { "{ B[i] -> C[i]; D[i] -> E[i] }",
4157 "{ A[i] -> B[i + 1] }",
4158 "{ A[i] -> C[i + 1] }" },
4159 { "{ B[i] -> C[i]; B[i] -> E[i] }",
4160 "{ A[i] -> B[i + 1] }",
4161 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
4162 { "{ B[i] -> C[([i/2])] }",
4163 "{ A[i] -> B[2i] }",
4164 "{ A[i] -> C[i] }" },
4165 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
4166 "{ A[i] -> B[([i/5]), ([i/7])] }",
4167 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
4168 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
4169 "[N] -> { A[] -> B[([N/5])] }",
4170 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
4171 { "{ B[i] -> C[i] : exists a : i = 5 a }",
4172 "{ A[i] -> B[2i] }",
4173 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
4174 { "{ B[i] -> C[i] : exists a : i = 2 a; "
4175 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
4176 "{ A[i] -> B[2i] }",
4177 "{ A[i] -> C[2i] }" },
4180 static int test_preimage_union_map(isl_ctx *ctx)
4182 int i;
4183 isl_union_map *umap1, *umap2;
4184 isl_multi_aff *ma;
4185 int equal;
4187 for (i = 0; i < ARRAY_SIZE(preimage_domain_tests); ++i) {
4188 umap1 = isl_union_map_read_from_str(ctx,
4189 preimage_domain_tests[i].map);
4190 ma = isl_multi_aff_read_from_str(ctx,
4191 preimage_domain_tests[i].ma);
4192 umap2 = isl_union_map_read_from_str(ctx,
4193 preimage_domain_tests[i].res);
4194 umap1 = isl_union_map_preimage_domain_multi_aff(umap1, ma);
4195 equal = isl_union_map_is_equal(umap1, umap2);
4196 isl_union_map_free(umap1);
4197 isl_union_map_free(umap2);
4198 if (equal < 0)
4199 return -1;
4200 if (!equal)
4201 isl_die(ctx, isl_error_unknown, "bad preimage",
4202 return -1);
4205 return 0;
4208 static int test_preimage(isl_ctx *ctx)
4210 if (test_preimage_basic_set(ctx) < 0)
4211 return -1;
4212 if (test_preimage_union_map(ctx) < 0)
4213 return -1;
4215 return 0;
4218 struct {
4219 const char *ma1;
4220 const char *ma;
4221 const char *res;
4222 } pullback_tests[] = {
4223 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
4224 "{ A[a,b] -> C[b + 2a] }" },
4225 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
4226 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
4227 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
4228 "{ A[a] -> C[(a)/6] }" },
4229 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
4230 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
4231 "{ A[a] -> C[(2a)/3] }" },
4232 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
4233 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
4234 "{ A[i,j] -> C[i + j, i + j] }"},
4235 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
4236 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
4237 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
4240 static int test_pullback(isl_ctx *ctx)
4242 int i;
4243 isl_multi_aff *ma1, *ma2;
4244 isl_multi_aff *ma;
4245 int equal;
4247 for (i = 0; i < ARRAY_SIZE(pullback_tests); ++i) {
4248 ma1 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma1);
4249 ma = isl_multi_aff_read_from_str(ctx, pullback_tests[i].ma);
4250 ma2 = isl_multi_aff_read_from_str(ctx, pullback_tests[i].res);
4251 ma1 = isl_multi_aff_pullback_multi_aff(ma1, ma);
4252 equal = isl_multi_aff_plain_is_equal(ma1, ma2);
4253 isl_multi_aff_free(ma1);
4254 isl_multi_aff_free(ma2);
4255 if (equal < 0)
4256 return -1;
4257 if (!equal)
4258 isl_die(ctx, isl_error_unknown, "bad pullback",
4259 return -1);
4262 return 0;
4265 /* Check that negation is printed correctly.
4267 static int test_ast(isl_ctx *ctx)
4269 isl_ast_expr *expr, *expr1, *expr2, *expr3;
4270 char *str;
4271 int ok;
4273 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
4274 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
4275 expr = isl_ast_expr_add(expr1, expr2);
4276 expr = isl_ast_expr_neg(expr);
4277 str = isl_ast_expr_to_str(expr);
4278 ok = str ? !strcmp(str, "-(A + B)") : -1;
4279 free(str);
4280 isl_ast_expr_free(expr);
4282 if (ok < 0)
4283 return -1;
4284 if (!ok)
4285 isl_die(ctx, isl_error_unknown,
4286 "isl_ast_expr printed incorrectly", return -1);
4288 expr1 = isl_ast_expr_from_id(isl_id_alloc(ctx, "A", NULL));
4289 expr2 = isl_ast_expr_from_id(isl_id_alloc(ctx, "B", NULL));
4290 expr = isl_ast_expr_add(expr1, expr2);
4291 expr3 = isl_ast_expr_from_id(isl_id_alloc(ctx, "C", NULL));
4292 expr = isl_ast_expr_sub(expr3, expr);
4293 str = isl_ast_expr_to_str(expr);
4294 ok = str ? !strcmp(str, "C - (A + B)") : -1;
4295 free(str);
4296 isl_ast_expr_free(expr);
4298 if (ok < 0)
4299 return -1;
4300 if (!ok)
4301 isl_die(ctx, isl_error_unknown,
4302 "isl_ast_expr printed incorrectly", return -1);
4304 return 0;
4307 /* Internal data structure for before_for and after_for callbacks.
4309 * depth is the current depth
4310 * before is the number of times before_for has been called
4311 * after is the number of times after_for has been called
4313 struct isl_test_codegen_data {
4314 int depth;
4315 int before;
4316 int after;
4319 /* This function is called before each for loop in the AST generated
4320 * from test_ast_gen1.
4322 * Increment the number of calls and the depth.
4323 * Check that the space returned by isl_ast_build_get_schedule_space
4324 * matches the target space of the schedule returned by
4325 * isl_ast_build_get_schedule.
4326 * Return an isl_id that is checked by the corresponding call
4327 * to after_for.
4329 static __isl_give isl_id *before_for(__isl_keep isl_ast_build *build,
4330 void *user)
4332 struct isl_test_codegen_data *data = user;
4333 isl_ctx *ctx;
4334 isl_space *space;
4335 isl_union_map *schedule;
4336 isl_union_set *uset;
4337 isl_set *set;
4338 int empty;
4339 char name[] = "d0";
4341 ctx = isl_ast_build_get_ctx(build);
4343 if (data->before >= 3)
4344 isl_die(ctx, isl_error_unknown,
4345 "unexpected number of for nodes", return NULL);
4346 if (data->depth >= 2)
4347 isl_die(ctx, isl_error_unknown,
4348 "unexpected depth", return NULL);
4350 snprintf(name, sizeof(name), "d%d", data->depth);
4351 data->before++;
4352 data->depth++;
4354 schedule = isl_ast_build_get_schedule(build);
4355 uset = isl_union_map_range(schedule);
4356 if (!uset)
4357 return NULL;
4358 if (isl_union_set_n_set(uset) != 1) {
4359 isl_union_set_free(uset);
4360 isl_die(ctx, isl_error_unknown,
4361 "expecting single range space", return NULL);
4364 space = isl_ast_build_get_schedule_space(build);
4365 set = isl_union_set_extract_set(uset, space);
4366 isl_union_set_free(uset);
4367 empty = isl_set_is_empty(set);
4368 isl_set_free(set);
4370 if (empty < 0)
4371 return NULL;
4372 if (empty)
4373 isl_die(ctx, isl_error_unknown,
4374 "spaces don't match", return NULL);
4376 return isl_id_alloc(ctx, name, NULL);
4379 /* This function is called after each for loop in the AST generated
4380 * from test_ast_gen1.
4382 * Increment the number of calls and decrement the depth.
4383 * Check that the annotation attached to the node matches
4384 * the isl_id returned by the corresponding call to before_for.
4386 static __isl_give isl_ast_node *after_for(__isl_take isl_ast_node *node,
4387 __isl_keep isl_ast_build *build, void *user)
4389 struct isl_test_codegen_data *data = user;
4390 isl_id *id;
4391 const char *name;
4392 int valid;
4394 data->after++;
4395 data->depth--;
4397 if (data->after > data->before)
4398 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
4399 "mismatch in number of for nodes",
4400 return isl_ast_node_free(node));
4402 id = isl_ast_node_get_annotation(node);
4403 if (!id)
4404 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
4405 "missing annotation", return isl_ast_node_free(node));
4407 name = isl_id_get_name(id);
4408 valid = name && atoi(name + 1) == data->depth;
4409 isl_id_free(id);
4411 if (!valid)
4412 isl_die(isl_ast_node_get_ctx(node), isl_error_unknown,
4413 "wrong annotation", return isl_ast_node_free(node));
4415 return node;
4418 /* Check that the before_each_for and after_each_for callbacks
4419 * are called for each for loop in the generated code,
4420 * that they are called in the right order and that the isl_id
4421 * returned from the before_each_for callback is attached to
4422 * the isl_ast_node passed to the corresponding after_each_for call.
4424 static int test_ast_gen1(isl_ctx *ctx)
4426 const char *str;
4427 isl_set *set;
4428 isl_union_map *schedule;
4429 isl_ast_build *build;
4430 isl_ast_node *tree;
4431 struct isl_test_codegen_data data;
4433 str = "[N] -> { : N >= 10 }";
4434 set = isl_set_read_from_str(ctx, str);
4435 str = "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
4436 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
4437 schedule = isl_union_map_read_from_str(ctx, str);
4439 data.before = 0;
4440 data.after = 0;
4441 data.depth = 0;
4442 build = isl_ast_build_from_context(set);
4443 build = isl_ast_build_set_before_each_for(build,
4444 &before_for, &data);
4445 build = isl_ast_build_set_after_each_for(build,
4446 &after_for, &data);
4447 tree = isl_ast_build_ast_from_schedule(build, schedule);
4448 isl_ast_build_free(build);
4449 if (!tree)
4450 return -1;
4452 isl_ast_node_free(tree);
4454 if (data.before != 3 || data.after != 3)
4455 isl_die(ctx, isl_error_unknown,
4456 "unexpected number of for nodes", return -1);
4458 return 0;
4461 /* Check that the AST generator handles domains that are integrally disjoint
4462 * but not ratinoally disjoint.
4464 static int test_ast_gen2(isl_ctx *ctx)
4466 const char *str;
4467 isl_set *set;
4468 isl_union_map *schedule;
4469 isl_union_map *options;
4470 isl_ast_build *build;
4471 isl_ast_node *tree;
4473 str = "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
4474 schedule = isl_union_map_read_from_str(ctx, str);
4475 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
4476 build = isl_ast_build_from_context(set);
4478 str = "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
4479 options = isl_union_map_read_from_str(ctx, str);
4480 build = isl_ast_build_set_options(build, options);
4481 tree = isl_ast_build_ast_from_schedule(build, schedule);
4482 isl_ast_build_free(build);
4483 if (!tree)
4484 return -1;
4485 isl_ast_node_free(tree);
4487 return 0;
4490 /* Increment *user on each call.
4492 static __isl_give isl_ast_node *count_domains(__isl_take isl_ast_node *node,
4493 __isl_keep isl_ast_build *build, void *user)
4495 int *n = user;
4497 (*n)++;
4499 return node;
4502 /* Test that unrolling tries to minimize the number of instances.
4503 * In particular, for the schedule given below, make sure it generates
4504 * 3 nodes (rather than 101).
4506 static int test_ast_gen3(isl_ctx *ctx)
4508 const char *str;
4509 isl_set *set;
4510 isl_union_map *schedule;
4511 isl_union_map *options;
4512 isl_ast_build *build;
4513 isl_ast_node *tree;
4514 int n_domain = 0;
4516 str = "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
4517 schedule = isl_union_map_read_from_str(ctx, str);
4518 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
4520 str = "{ [i] -> unroll[0] }";
4521 options = isl_union_map_read_from_str(ctx, str);
4523 build = isl_ast_build_from_context(set);
4524 build = isl_ast_build_set_options(build, options);
4525 build = isl_ast_build_set_at_each_domain(build,
4526 &count_domains, &n_domain);
4527 tree = isl_ast_build_ast_from_schedule(build, schedule);
4528 isl_ast_build_free(build);
4529 if (!tree)
4530 return -1;
4532 isl_ast_node_free(tree);
4534 if (n_domain != 3)
4535 isl_die(ctx, isl_error_unknown,
4536 "unexpected number of for nodes", return -1);
4538 return 0;
4541 /* Check that if the ast_build_exploit_nested_bounds options is set,
4542 * we do not get an outer if node in the generated AST,
4543 * while we do get such an outer if node if the options is not set.
4545 static int test_ast_gen4(isl_ctx *ctx)
4547 const char *str;
4548 isl_set *set;
4549 isl_union_map *schedule;
4550 isl_ast_build *build;
4551 isl_ast_node *tree;
4552 enum isl_ast_node_type type;
4553 int enb;
4555 enb = isl_options_get_ast_build_exploit_nested_bounds(ctx);
4556 str = "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
4558 isl_options_set_ast_build_exploit_nested_bounds(ctx, 1);
4560 schedule = isl_union_map_read_from_str(ctx, str);
4561 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
4562 build = isl_ast_build_from_context(set);
4563 tree = isl_ast_build_ast_from_schedule(build, schedule);
4564 isl_ast_build_free(build);
4565 if (!tree)
4566 return -1;
4568 type = isl_ast_node_get_type(tree);
4569 isl_ast_node_free(tree);
4571 if (type == isl_ast_node_if)
4572 isl_die(ctx, isl_error_unknown,
4573 "not expecting if node", return -1);
4575 isl_options_set_ast_build_exploit_nested_bounds(ctx, 0);
4577 schedule = isl_union_map_read_from_str(ctx, str);
4578 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
4579 build = isl_ast_build_from_context(set);
4580 tree = isl_ast_build_ast_from_schedule(build, schedule);
4581 isl_ast_build_free(build);
4582 if (!tree)
4583 return -1;
4585 type = isl_ast_node_get_type(tree);
4586 isl_ast_node_free(tree);
4588 if (type != isl_ast_node_if)
4589 isl_die(ctx, isl_error_unknown,
4590 "expecting if node", return -1);
4592 isl_options_set_ast_build_exploit_nested_bounds(ctx, enb);
4594 return 0;
4597 /* This function is called for each leaf in the AST generated
4598 * from test_ast_gen5.
4600 * We finalize the AST generation by extending the outer schedule
4601 * with a zero-dimensional schedule. If this results in any for loops,
4602 * then this means that we did not pass along enough information
4603 * about the outer schedule to the inner AST generation.
4605 static __isl_give isl_ast_node *create_leaf(__isl_take isl_ast_build *build,
4606 void *user)
4608 isl_union_map *schedule, *extra;
4609 isl_ast_node *tree;
4611 schedule = isl_ast_build_get_schedule(build);
4612 extra = isl_union_map_copy(schedule);
4613 extra = isl_union_map_from_domain(isl_union_map_domain(extra));
4614 schedule = isl_union_map_range_product(schedule, extra);
4615 tree = isl_ast_build_ast_from_schedule(build, schedule);
4616 isl_ast_build_free(build);
4618 if (!tree)
4619 return NULL;
4621 if (isl_ast_node_get_type(tree) == isl_ast_node_for)
4622 isl_die(isl_ast_node_get_ctx(tree), isl_error_unknown,
4623 "code should not contain any for loop",
4624 return isl_ast_node_free(tree));
4626 return tree;
4629 /* Check that we do not lose any information when going back and
4630 * forth between internal and external schedule.
4632 * In particular, we create an AST where we unroll the only
4633 * non-constant dimension in the schedule. We therefore do
4634 * not expect any for loops in the AST. However, older versions
4635 * of isl would not pass along enough information about the outer
4636 * schedule when performing an inner code generation from a create_leaf
4637 * callback, resulting in the inner code generation producing a for loop.
4639 static int test_ast_gen5(isl_ctx *ctx)
4641 const char *str;
4642 isl_set *set;
4643 isl_union_map *schedule, *options;
4644 isl_ast_build *build;
4645 isl_ast_node *tree;
4647 str = "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
4648 schedule = isl_union_map_read_from_str(ctx, str);
4650 str = "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
4651 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
4652 options = isl_union_map_read_from_str(ctx, str);
4654 set = isl_set_universe(isl_space_params_alloc(ctx, 0));
4655 build = isl_ast_build_from_context(set);
4656 build = isl_ast_build_set_options(build, options);
4657 build = isl_ast_build_set_create_leaf(build, &create_leaf, NULL);
4658 tree = isl_ast_build_ast_from_schedule(build, schedule);
4659 isl_ast_build_free(build);
4660 isl_ast_node_free(tree);
4661 if (!tree)
4662 return -1;
4664 return 0;
4667 static int test_ast_gen(isl_ctx *ctx)
4669 if (test_ast_gen1(ctx) < 0)
4670 return -1;
4671 if (test_ast_gen2(ctx) < 0)
4672 return -1;
4673 if (test_ast_gen3(ctx) < 0)
4674 return -1;
4675 if (test_ast_gen4(ctx) < 0)
4676 return -1;
4677 if (test_ast_gen5(ctx) < 0)
4678 return -1;
4679 return 0;
4682 /* Check if dropping output dimensions from an isl_pw_multi_aff
4683 * works properly.
4685 static int test_pw_multi_aff(isl_ctx *ctx)
4687 const char *str;
4688 isl_pw_multi_aff *pma1, *pma2;
4689 int equal;
4691 str = "{ [i,j] -> [i+j, 4i-j] }";
4692 pma1 = isl_pw_multi_aff_read_from_str(ctx, str);
4693 str = "{ [i,j] -> [4i-j] }";
4694 pma2 = isl_pw_multi_aff_read_from_str(ctx, str);
4696 pma1 = isl_pw_multi_aff_drop_dims(pma1, isl_dim_out, 0, 1);
4698 equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2);
4700 isl_pw_multi_aff_free(pma1);
4701 isl_pw_multi_aff_free(pma2);
4702 if (equal < 0)
4703 return -1;
4704 if (!equal)
4705 isl_die(ctx, isl_error_unknown,
4706 "expressions not equal", return -1);
4708 return 0;
4711 /* Check that we can properly parse multi piecewise affine expressions
4712 * where the piecewise affine expressions have different domains.
4714 static int test_multi_pw_aff(isl_ctx *ctx)
4716 const char *str;
4717 isl_set *dom, *dom2;
4718 isl_multi_pw_aff *mpa1, *mpa2;
4719 isl_pw_aff *pa;
4720 int equal;
4721 int equal_domain;
4723 mpa1 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [i] }");
4724 dom = isl_set_read_from_str(ctx, "{ [i] : i > 0 }");
4725 mpa1 = isl_multi_pw_aff_intersect_domain(mpa1, dom);
4726 mpa2 = isl_multi_pw_aff_read_from_str(ctx, "{ [i] -> [2i] }");
4727 mpa2 = isl_multi_pw_aff_flat_range_product(mpa1, mpa2);
4728 str = "{ [i] -> [(i : i > 0), 2i] }";
4729 mpa1 = isl_multi_pw_aff_read_from_str(ctx, str);
4731 equal = isl_multi_pw_aff_plain_is_equal(mpa1, mpa2);
4733 pa = isl_multi_pw_aff_get_pw_aff(mpa1, 0);
4734 dom = isl_pw_aff_domain(pa);
4735 pa = isl_multi_pw_aff_get_pw_aff(mpa1, 1);
4736 dom2 = isl_pw_aff_domain(pa);
4737 equal_domain = isl_set_is_equal(dom, dom2);
4739 isl_set_free(dom);
4740 isl_set_free(dom2);
4741 isl_multi_pw_aff_free(mpa1);
4742 isl_multi_pw_aff_free(mpa2);
4744 if (equal < 0)
4745 return -1;
4746 if (!equal)
4747 isl_die(ctx, isl_error_unknown,
4748 "expressions not equal", return -1);
4750 if (equal_domain < 0)
4751 return -1;
4752 if (equal_domain)
4753 isl_die(ctx, isl_error_unknown,
4754 "domains unexpectedly equal", return -1);
4756 return 0;
4759 /* This is a regression test for a bug where isl_basic_map_simplify
4760 * would end up in an infinite loop. In particular, we construct
4761 * an empty basic set that is not obviously empty.
4762 * isl_basic_set_is_empty marks the basic set as empty.
4763 * After projecting out i3, the variable can be dropped completely,
4764 * but isl_basic_map_simplify refrains from doing so if the basic set
4765 * is empty and would end up in an infinite loop if it didn't test
4766 * explicitly for empty basic maps in the outer loop.
4768 static int test_simplify(isl_ctx *ctx)
4770 const char *str;
4771 isl_basic_set *bset;
4772 int empty;
4774 str = "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
4775 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
4776 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
4777 "i3 >= i2 }";
4778 bset = isl_basic_set_read_from_str(ctx, str);
4779 empty = isl_basic_set_is_empty(bset);
4780 bset = isl_basic_set_project_out(bset, isl_dim_set, 3, 1);
4781 isl_basic_set_free(bset);
4782 if (!bset)
4783 return -1;
4784 if (!empty)
4785 isl_die(ctx, isl_error_unknown,
4786 "basic set should be empty", return -1);
4788 return 0;
4791 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
4792 * with gbr context would fail to disable the use of the shifted tableau
4793 * when transferring equalities for the input to the context, resulting
4794 * in invalid sample values.
4796 static int test_partial_lexmin(isl_ctx *ctx)
4798 const char *str;
4799 isl_basic_set *bset;
4800 isl_basic_map *bmap;
4801 isl_map *map;
4803 str = "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
4804 bmap = isl_basic_map_read_from_str(ctx, str);
4805 str = "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
4806 bset = isl_basic_set_read_from_str(ctx, str);
4807 map = isl_basic_map_partial_lexmin(bmap, bset, NULL);
4808 isl_map_free(map);
4810 if (!map)
4811 return -1;
4813 return 0;
4816 /* Check that the variable compression performed on the existentially
4817 * quantified variables inside isl_basic_set_compute_divs is not confused
4818 * by the implicit equalities among the parameters.
4820 static int test_compute_divs(isl_ctx *ctx)
4822 const char *str;
4823 isl_basic_set *bset;
4824 isl_set *set;
4826 str = "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
4827 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
4828 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
4829 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
4830 bset = isl_basic_set_read_from_str(ctx, str);
4831 set = isl_basic_set_compute_divs(bset);
4832 isl_set_free(set);
4833 if (!set)
4834 return -1;
4836 return 0;
4839 struct {
4840 const char *name;
4841 int (*fn)(isl_ctx *ctx);
4842 } tests [] = {
4843 { "val", &test_val },
4844 { "compute divs", &test_compute_divs },
4845 { "partial lexmin", &test_partial_lexmin },
4846 { "simplify", &test_simplify },
4847 { "curry", &test_curry },
4848 { "piecewise multi affine expressions", &test_pw_multi_aff },
4849 { "multi piecewise affine expressions", &test_multi_pw_aff },
4850 { "conversion", &test_conversion },
4851 { "list", &test_list },
4852 { "align parameters", &test_align_parameters },
4853 { "preimage", &test_preimage },
4854 { "pullback", &test_pullback },
4855 { "AST", &test_ast },
4856 { "AST generation", &test_ast_gen },
4857 { "eliminate", &test_eliminate },
4858 { "residue class", &test_residue_class },
4859 { "div", &test_div },
4860 { "slice", &test_slice },
4861 { "fixed power", &test_fixed_power },
4862 { "sample", &test_sample },
4863 { "output", &test_output },
4864 { "vertices", &test_vertices },
4865 { "fixed", &test_fixed },
4866 { "equal", &test_equal },
4867 { "disjoint", &test_disjoint },
4868 { "product", &test_product },
4869 { "dim_max", &test_dim_max },
4870 { "affine", &test_aff },
4871 { "injective", &test_injective },
4872 { "schedule", &test_schedule },
4873 { "union_pw", &test_union_pw },
4874 { "parse", &test_parse },
4875 { "single-valued", &test_sv },
4876 { "affine hull", &test_affine_hull },
4877 { "coalesce", &test_coalesce },
4878 { "factorize", &test_factorize },
4879 { "subset", &test_subset },
4880 { "subtract", &test_subtract },
4881 { "lexmin", &test_lexmin },
4882 { "min", &test_min },
4883 { "gist", &test_gist },
4884 { "piecewise quasi-polynomials", &test_pwqp },
4887 int main()
4889 int i;
4890 struct isl_ctx *ctx;
4892 srcdir = getenv("srcdir");
4893 assert(srcdir);
4895 ctx = isl_ctx_alloc();
4896 for (i = 0; i < ARRAY_SIZE(tests); ++i) {
4897 printf("%s\n", tests[i].name);
4898 if (tests[i].fn(ctx) < 0)
4899 goto error;
4901 test_lift(ctx);
4902 test_bound(ctx);
4903 test_union(ctx);
4904 test_split_periods(ctx);
4905 test_lex(ctx);
4906 test_bijective(ctx);
4907 test_dep(ctx);
4908 test_read(ctx);
4909 test_bounded(ctx);
4910 test_construction(ctx);
4911 test_dim(ctx);
4912 test_application(ctx);
4913 test_convex_hull(ctx);
4914 test_closure(ctx);
4915 isl_ctx_free(ctx);
4916 return 0;
4917 error:
4918 isl_ctx_free(ctx);
4919 return -1;