2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
5 * Copyright 2014 INRIA Rocquencourt
7 * Use of this software is governed by the MIT license
9 * Written by Sven Verdoolaege, K.U.Leuven, Departement
10 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
11 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
12 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
14 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
15 * B.P. 105 - 78153 Le Chesnay, France
21 #include <isl_ctx_private.h>
22 #include <isl_map_private.h>
23 #include <isl_aff_private.h>
24 #include <isl_space_private.h>
27 #include <isl_constraint_private.h>
28 #include <isl/polynomial.h>
29 #include <isl/union_set.h>
30 #include <isl/union_map.h>
31 #include <isl_factorization.h>
32 #include <isl/schedule.h>
33 #include <isl/schedule_node.h>
34 #include <isl_options_private.h>
35 #include <isl_vertices_private.h>
36 #include <isl/ast_build.h>
39 #include <isl_ast_build_expr.h>
40 #include <isl/options.h>
42 #include "isl_srcdir.c"
44 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
46 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
49 char *pattern
= "%s/test_inputs/%s.%s";
51 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
53 filename
= isl_alloc_array(ctx
, char, length
);
58 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
63 void test_parse_map(isl_ctx
*ctx
, const char *str
)
67 map
= isl_map_read_from_str(ctx
, str
);
72 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
77 map
= isl_map_read_from_str(ctx
, str
);
78 map2
= isl_map_read_from_str(ctx
, str2
);
79 equal
= isl_map_is_equal(map
, map2
);
86 isl_die(ctx
, isl_error_unknown
, "maps not equal",
92 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
94 isl_pw_qpolynomial
*pwqp
;
96 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
98 isl_pw_qpolynomial_free(pwqp
);
101 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
105 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
107 isl_pw_aff_free(pwaff
);
110 /* Check that we can read an isl_multi_val from "str" without errors.
112 static int test_parse_multi_val(isl_ctx
*ctx
, const char *str
)
116 mv
= isl_multi_val_read_from_str(ctx
, str
);
117 isl_multi_val_free(mv
);
122 /* Pairs of binary relation representations that should represent
123 * the same binary relations.
128 } parse_map_equal_tests
[] = {
129 { "{ [x,y] : [([x/2]+y)/3] >= 1 }",
130 "{ [x, y] : 2y >= 6 - x }" },
131 { "{ [x,y] : x <= min(y, 2*y+3) }",
132 "{ [x,y] : x <= y, 2*y + 3 }" },
133 { "{ [x,y] : x >= min(y, 2*y+3) }",
134 "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }" },
135 { "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }",
136 "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }" },
137 { "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }",
138 "{ [i,j] -> [min(i,j)] }" },
139 { "{ [i,j] : i != j }",
140 "{ [i,j] : i < j or i > j }" },
141 { "{ [i,j] : (i+1)*2 >= j }",
142 "{ [i, j] : j <= 2 + 2i }" },
143 { "{ [i] -> [i > 0 ? 4 : 5] }",
144 "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }" },
145 { "[N=2,M] -> { [i=[(M+N)/4]] }",
146 "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }" },
147 { "{ [x] : x >= 0 }",
148 "{ [x] : x-0 >= 0 }" },
149 { "{ [i] : ((i > 10)) }",
150 "{ [i] : i >= 11 }" },
152 "{ [i] -> [0 * i] }" },
153 { "{ [a] -> [b] : (not false) }",
154 "{ [a] -> [b] : true }" },
155 { "{ [i] : i/2 <= 5 }",
156 "{ [i] : i <= 10 }" },
157 { "{Sym=[n] [i] : i <= n }",
158 "[n] -> { [i] : i <= n }" },
161 { "{ [i] : 2*floor(i/2) = i }",
162 "{ [i] : exists a : i = 2 a }" },
163 { "{ [a] -> [b] : a = 5 implies b = 5 }",
164 "{ [a] -> [b] : a != 5 or b = 5 }" },
165 { "{ [a] -> [a - 1 : a > 0] }",
166 "{ [a] -> [a - 1] : a > 0 }" },
167 { "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
168 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }" },
169 { "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
170 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
171 { "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
172 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
173 { "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
174 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
175 { "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
176 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }" },
177 { "{ [a,b] -> [i,j] : a,b << i,j }",
178 "{ [a,b] -> [i,j] : a < i or (a = i and b < j) }" },
179 { "{ [a,b] -> [i,j] : a,b <<= i,j }",
180 "{ [a,b] -> [i,j] : a < i or (a = i and b <= j) }" },
181 { "{ [a,b] -> [i,j] : a,b >> i,j }",
182 "{ [a,b] -> [i,j] : a > i or (a = i and b > j) }" },
183 { "{ [a,b] -> [i,j] : a,b >>= i,j }",
184 "{ [a,b] -> [i,j] : a > i or (a = i and b >= j) }" },
185 { "{ [n] -> [i] : exists (a, b, c: 8b <= i - 32a and "
186 "8b >= -7 + i - 32 a and b >= 0 and b <= 3 and "
187 "8c < n - 32a and i < n and c >= 0 and "
188 "c <= 3 and c >= -4a) }",
189 "{ [n] -> [i] : 0 <= i < n }" },
190 { "{ [x] -> [] : exists (a, b: 0 <= a <= 1 and 0 <= b <= 3 and "
191 "2b <= x - 8a and 2b >= -1 + x - 8a) }",
192 "{ [x] -> [] : 0 <= x <= 15 }" },
193 { "{ [x] -> [x] : }",
197 int test_parse(struct isl_ctx
*ctx
)
201 const char *str
, *str2
;
203 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
205 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
207 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
210 str
= "{ [i] -> [-i] }";
211 map
= isl_map_read_from_str(ctx
, str
);
215 str
= "{ A[i] -> L[([i/3])] }";
216 map
= isl_map_read_from_str(ctx
, str
);
220 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
221 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
222 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
224 for (i
= 0; i
< ARRAY_SIZE(parse_map_equal_tests
); ++i
) {
225 str
= parse_map_equal_tests
[i
].map1
;
226 str2
= parse_map_equal_tests
[i
].map2
;
227 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
231 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
232 map
= isl_map_read_from_str(ctx
, str
);
233 str
= "{ [new, old] -> [o0, o1] : "
234 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
235 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
236 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
237 map2
= isl_map_read_from_str(ctx
, str
);
238 assert(isl_map_is_equal(map
, map2
));
242 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
243 map
= isl_map_read_from_str(ctx
, str
);
244 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
245 map2
= isl_map_read_from_str(ctx
, str
);
246 assert(isl_map_is_equal(map
, map2
));
250 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
251 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
252 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
253 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
254 test_parse_pwaff(ctx
, "{ [] -> [(100)] }");
259 static int test_read(isl_ctx
*ctx
)
263 isl_basic_set
*bset1
, *bset2
;
264 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
267 filename
= get_filename(ctx
, "set", "omega");
269 input
= fopen(filename
, "r");
272 bset1
= isl_basic_set_read_from_file(ctx
, input
);
273 bset2
= isl_basic_set_read_from_str(ctx
, str
);
275 equal
= isl_basic_set_is_equal(bset1
, bset2
);
277 isl_basic_set_free(bset1
);
278 isl_basic_set_free(bset2
);
286 isl_die(ctx
, isl_error_unknown
,
287 "read sets not equal", return -1);
292 static int test_bounded(isl_ctx
*ctx
)
297 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
298 bounded
= isl_set_is_bounded(set
);
304 isl_die(ctx
, isl_error_unknown
,
305 "set not considered bounded", return -1);
307 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
308 bounded
= isl_set_is_bounded(set
);
315 isl_die(ctx
, isl_error_unknown
,
316 "set considered bounded", return -1);
318 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
319 bounded
= isl_set_is_bounded(set
);
325 isl_die(ctx
, isl_error_unknown
,
326 "set considered bounded", return -1);
331 /* Construct the basic set { [i] : 5 <= i <= N } */
332 static int test_construction_1(isl_ctx
*ctx
)
342 dim
= isl_space_set_alloc(ctx
, 1, 1);
343 bset
= isl_basic_set_universe(isl_space_copy(dim
));
344 ls
= isl_local_space_from_space(dim
);
346 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
347 isl_int_set_si(v
, -1);
348 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
349 isl_int_set_si(v
, 1);
350 c
= isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
351 bset
= isl_basic_set_add_constraint(bset
, c
);
353 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
354 isl_int_set_si(v
, 1);
355 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
356 isl_int_set_si(v
, -5);
357 c
= isl_constraint_set_constant(c
, v
);
358 bset
= isl_basic_set_add_constraint(bset
, c
);
360 isl_local_space_free(ls
);
361 isl_basic_set_free(bset
);
368 /* Construct the basic set { [x] : -100 <= x <= 100 }
369 * using isl_basic_set_{lower,upper}_bound_val and
370 * check that it is equal the same basic set parsed from a string.
372 static int test_construction_2(isl_ctx
*ctx
)
377 isl_basic_set
*bset1
, *bset2
;
379 v
= isl_val_int_from_si(ctx
, 100);
380 space
= isl_space_set_alloc(ctx
, 0, 1);
381 bset1
= isl_basic_set_universe(space
);
382 bset1
= isl_basic_set_upper_bound_val(bset1
, isl_dim_set
, 0,
384 bset1
= isl_basic_set_lower_bound_val(bset1
, isl_dim_set
, 0,
386 bset2
= isl_basic_set_read_from_str(ctx
, "{ [x] : -100 <= x <= 100 }");
387 equal
= isl_basic_set_is_equal(bset1
, bset2
);
388 isl_basic_set_free(bset1
);
389 isl_basic_set_free(bset2
);
394 isl_die(ctx
, isl_error_unknown
,
395 "failed construction", return -1);
400 /* Basic tests for constructing basic sets.
402 static int test_construction(isl_ctx
*ctx
)
404 if (test_construction_1(ctx
) < 0)
406 if (test_construction_2(ctx
) < 0)
411 static int test_dim(isl_ctx
*ctx
)
414 isl_map
*map1
, *map2
;
417 map1
= isl_map_read_from_str(ctx
,
418 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
419 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
420 map2
= isl_map_read_from_str(ctx
,
421 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
422 equal
= isl_map_is_equal(map1
, map2
);
425 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
426 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
427 if (equal
>= 0 && equal
)
428 equal
= isl_map_is_equal(map1
, map2
);
436 isl_die(ctx
, isl_error_unknown
,
437 "unexpected result", return -1);
439 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
440 map1
= isl_map_read_from_str(ctx
, str
);
441 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
442 map2
= isl_map_read_from_str(ctx
, str
);
443 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
444 equal
= isl_map_is_equal(map1
, map2
);
451 isl_die(ctx
, isl_error_unknown
,
452 "unexpected result", return -1);
458 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
462 { &isl_val_neg
, "0", "0" },
463 { &isl_val_abs
, "0", "0" },
464 { &isl_val_2exp
, "0", "1" },
465 { &isl_val_floor
, "0", "0" },
466 { &isl_val_ceil
, "0", "0" },
467 { &isl_val_neg
, "1", "-1" },
468 { &isl_val_neg
, "-1", "1" },
469 { &isl_val_neg
, "1/2", "-1/2" },
470 { &isl_val_neg
, "-1/2", "1/2" },
471 { &isl_val_neg
, "infty", "-infty" },
472 { &isl_val_neg
, "-infty", "infty" },
473 { &isl_val_neg
, "NaN", "NaN" },
474 { &isl_val_abs
, "1", "1" },
475 { &isl_val_abs
, "-1", "1" },
476 { &isl_val_abs
, "1/2", "1/2" },
477 { &isl_val_abs
, "-1/2", "1/2" },
478 { &isl_val_abs
, "infty", "infty" },
479 { &isl_val_abs
, "-infty", "infty" },
480 { &isl_val_abs
, "NaN", "NaN" },
481 { &isl_val_floor
, "1", "1" },
482 { &isl_val_floor
, "-1", "-1" },
483 { &isl_val_floor
, "1/2", "0" },
484 { &isl_val_floor
, "-1/2", "-1" },
485 { &isl_val_floor
, "infty", "infty" },
486 { &isl_val_floor
, "-infty", "-infty" },
487 { &isl_val_floor
, "NaN", "NaN" },
488 { &isl_val_ceil
, "1", "1" },
489 { &isl_val_ceil
, "-1", "-1" },
490 { &isl_val_ceil
, "1/2", "1" },
491 { &isl_val_ceil
, "-1/2", "0" },
492 { &isl_val_ceil
, "infty", "infty" },
493 { &isl_val_ceil
, "-infty", "-infty" },
494 { &isl_val_ceil
, "NaN", "NaN" },
495 { &isl_val_2exp
, "-3", "1/8" },
496 { &isl_val_2exp
, "-1", "1/2" },
497 { &isl_val_2exp
, "1", "2" },
498 { &isl_val_2exp
, "2", "4" },
499 { &isl_val_2exp
, "3", "8" },
500 { &isl_val_inv
, "1", "1" },
501 { &isl_val_inv
, "2", "1/2" },
502 { &isl_val_inv
, "1/2", "2" },
503 { &isl_val_inv
, "-2", "-1/2" },
504 { &isl_val_inv
, "-1/2", "-2" },
505 { &isl_val_inv
, "0", "NaN" },
506 { &isl_val_inv
, "NaN", "NaN" },
507 { &isl_val_inv
, "infty", "0" },
508 { &isl_val_inv
, "-infty", "0" },
511 /* Perform some basic tests of unary operations on isl_val objects.
513 static int test_un_val(isl_ctx
*ctx
)
517 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
520 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
521 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
522 res
= isl_val_read_from_str(ctx
, val_un_tests
[i
].res
);
523 fn
= val_un_tests
[i
].op
;
525 if (isl_val_is_nan(res
))
526 ok
= isl_val_is_nan(v
);
528 ok
= isl_val_eq(v
, res
);
534 isl_die(ctx
, isl_error_unknown
,
535 "unexpected result", return -1);
542 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
543 __isl_take isl_val
*v2
);
545 ['+'] = { &isl_val_add
},
546 ['-'] = { &isl_val_sub
},
547 ['*'] = { &isl_val_mul
},
548 ['/'] = { &isl_val_div
},
549 ['g'] = { &isl_val_gcd
},
550 ['m'] = { &isl_val_min
},
551 ['M'] = { &isl_val_max
},
559 } val_bin_tests
[] = {
560 { "0", '+', "0", "0" },
561 { "1", '+', "0", "1" },
562 { "1", '+', "1", "2" },
563 { "1", '-', "1", "0" },
564 { "1", '*', "1", "1" },
565 { "1", '/', "1", "1" },
566 { "2", '*', "3", "6" },
567 { "2", '*', "1/2", "1" },
568 { "2", '*', "1/3", "2/3" },
569 { "2/3", '*', "3/5", "2/5" },
570 { "2/3", '*', "7/5", "14/15" },
571 { "2", '/', "1/2", "4" },
572 { "-2", '/', "-1/2", "4" },
573 { "-2", '/', "1/2", "-4" },
574 { "2", '/', "-1/2", "-4" },
575 { "2", '/', "2", "1" },
576 { "2", '/', "3", "2/3" },
577 { "2/3", '/', "5/3", "2/5" },
578 { "2/3", '/', "5/7", "14/15" },
579 { "0", '/', "0", "NaN" },
580 { "42", '/', "0", "NaN" },
581 { "-42", '/', "0", "NaN" },
582 { "infty", '/', "0", "NaN" },
583 { "-infty", '/', "0", "NaN" },
584 { "NaN", '/', "0", "NaN" },
585 { "0", '/', "NaN", "NaN" },
586 { "42", '/', "NaN", "NaN" },
587 { "-42", '/', "NaN", "NaN" },
588 { "infty", '/', "NaN", "NaN" },
589 { "-infty", '/', "NaN", "NaN" },
590 { "NaN", '/', "NaN", "NaN" },
591 { "0", '/', "infty", "0" },
592 { "42", '/', "infty", "0" },
593 { "-42", '/', "infty", "0" },
594 { "infty", '/', "infty", "NaN" },
595 { "-infty", '/', "infty", "NaN" },
596 { "NaN", '/', "infty", "NaN" },
597 { "0", '/', "-infty", "0" },
598 { "42", '/', "-infty", "0" },
599 { "-42", '/', "-infty", "0" },
600 { "infty", '/', "-infty", "NaN" },
601 { "-infty", '/', "-infty", "NaN" },
602 { "NaN", '/', "-infty", "NaN" },
603 { "1", '-', "1/3", "2/3" },
604 { "1/3", '+', "1/2", "5/6" },
605 { "1/2", '+', "1/2", "1" },
606 { "3/4", '-', "1/4", "1/2" },
607 { "1/2", '-', "1/3", "1/6" },
608 { "infty", '+', "42", "infty" },
609 { "infty", '+', "infty", "infty" },
610 { "42", '+', "infty", "infty" },
611 { "infty", '-', "infty", "NaN" },
612 { "infty", '*', "infty", "infty" },
613 { "infty", '*', "-infty", "-infty" },
614 { "-infty", '*', "infty", "-infty" },
615 { "-infty", '*', "-infty", "infty" },
616 { "0", '*', "infty", "NaN" },
617 { "1", '*', "infty", "infty" },
618 { "infty", '*', "0", "NaN" },
619 { "infty", '*', "42", "infty" },
620 { "42", '-', "infty", "-infty" },
621 { "infty", '+', "-infty", "NaN" },
622 { "4", 'g', "6", "2" },
623 { "5", 'g', "6", "1" },
624 { "42", 'm', "3", "3" },
625 { "42", 'M', "3", "42" },
626 { "3", 'm', "42", "3" },
627 { "3", 'M', "42", "42" },
628 { "42", 'm', "infty", "42" },
629 { "42", 'M', "infty", "infty" },
630 { "42", 'm', "-infty", "-infty" },
631 { "42", 'M', "-infty", "42" },
632 { "42", 'm', "NaN", "NaN" },
633 { "42", 'M', "NaN", "NaN" },
634 { "infty", 'm', "-infty", "-infty" },
635 { "infty", 'M', "-infty", "infty" },
638 /* Perform some basic tests of binary operations on isl_val objects.
640 static int test_bin_val(isl_ctx
*ctx
)
643 isl_val
*v1
, *v2
, *res
;
644 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
645 __isl_take isl_val
*v2
);
648 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
649 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
650 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
651 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
652 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
654 if (isl_val_is_nan(res
))
655 ok
= isl_val_is_nan(v1
);
657 ok
= isl_val_eq(v1
, res
);
663 isl_die(ctx
, isl_error_unknown
,
664 "unexpected result", return -1);
670 /* Perform some basic tests on isl_val objects.
672 static int test_val(isl_ctx
*ctx
)
674 if (test_un_val(ctx
) < 0)
676 if (test_bin_val(ctx
) < 0)
681 /* Sets described using existentially quantified variables that
682 * can also be described without.
684 static const char *elimination_tests
[] = {
685 "{ [i,j] : 2 * [i/2] + 3 * [j/4] <= 10 and 2 i = j }",
686 "{ [m, w] : exists a : w - 2m - 5 <= 3a <= m - 2w }",
687 "{ [m, w] : exists a : w >= 0 and a < m and -1 + w <= a <= 2m - w }",
690 /* Check that redundant existentially quantified variables are
693 static int test_elimination(isl_ctx
*ctx
)
699 for (i
= 0; i
< ARRAY_SIZE(elimination_tests
); ++i
) {
700 bset
= isl_basic_set_read_from_str(ctx
, elimination_tests
[i
]);
701 n
= isl_basic_set_dim(bset
, isl_dim_div
);
702 isl_basic_set_free(bset
);
706 isl_die(ctx
, isl_error_unknown
,
707 "expecting no existentials", return -1);
713 static int test_div(isl_ctx
*ctx
)
721 struct isl_basic_set
*bset
;
722 struct isl_constraint
*c
;
727 dim
= isl_space_set_alloc(ctx
, 0, 3);
728 bset
= isl_basic_set_universe(isl_space_copy(dim
));
729 ls
= isl_local_space_from_space(dim
);
731 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
732 isl_int_set_si(v
, -1);
733 c
= isl_constraint_set_constant(c
, v
);
734 isl_int_set_si(v
, 1);
735 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
736 isl_int_set_si(v
, 3);
737 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
738 bset
= isl_basic_set_add_constraint(bset
, c
);
740 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
741 isl_int_set_si(v
, 1);
742 c
= isl_constraint_set_constant(c
, v
);
743 isl_int_set_si(v
, -1);
744 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
745 isl_int_set_si(v
, 3);
746 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
747 bset
= isl_basic_set_add_constraint(bset
, c
);
749 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
751 assert(bset
&& bset
->n_div
== 1);
752 isl_local_space_free(ls
);
753 isl_basic_set_free(bset
);
756 dim
= isl_space_set_alloc(ctx
, 0, 3);
757 bset
= isl_basic_set_universe(isl_space_copy(dim
));
758 ls
= isl_local_space_from_space(dim
);
760 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
761 isl_int_set_si(v
, 1);
762 c
= isl_constraint_set_constant(c
, v
);
763 isl_int_set_si(v
, -1);
764 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
765 isl_int_set_si(v
, 3);
766 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
767 bset
= isl_basic_set_add_constraint(bset
, c
);
769 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
770 isl_int_set_si(v
, -1);
771 c
= isl_constraint_set_constant(c
, v
);
772 isl_int_set_si(v
, 1);
773 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
774 isl_int_set_si(v
, 3);
775 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
776 bset
= isl_basic_set_add_constraint(bset
, c
);
778 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
780 assert(bset
&& bset
->n_div
== 1);
781 isl_local_space_free(ls
);
782 isl_basic_set_free(bset
);
785 dim
= isl_space_set_alloc(ctx
, 0, 3);
786 bset
= isl_basic_set_universe(isl_space_copy(dim
));
787 ls
= isl_local_space_from_space(dim
);
789 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
790 isl_int_set_si(v
, 1);
791 c
= isl_constraint_set_constant(c
, v
);
792 isl_int_set_si(v
, -1);
793 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
794 isl_int_set_si(v
, 3);
795 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
796 bset
= isl_basic_set_add_constraint(bset
, c
);
798 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
799 isl_int_set_si(v
, -3);
800 c
= isl_constraint_set_constant(c
, v
);
801 isl_int_set_si(v
, 1);
802 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
803 isl_int_set_si(v
, 4);
804 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
805 bset
= isl_basic_set_add_constraint(bset
, c
);
807 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
809 assert(bset
&& bset
->n_div
== 1);
810 isl_local_space_free(ls
);
811 isl_basic_set_free(bset
);
814 dim
= isl_space_set_alloc(ctx
, 0, 3);
815 bset
= isl_basic_set_universe(isl_space_copy(dim
));
816 ls
= isl_local_space_from_space(dim
);
818 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
819 isl_int_set_si(v
, 2);
820 c
= isl_constraint_set_constant(c
, v
);
821 isl_int_set_si(v
, -1);
822 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
823 isl_int_set_si(v
, 3);
824 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
825 bset
= isl_basic_set_add_constraint(bset
, c
);
827 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
828 isl_int_set_si(v
, -1);
829 c
= isl_constraint_set_constant(c
, v
);
830 isl_int_set_si(v
, 1);
831 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
832 isl_int_set_si(v
, 6);
833 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
834 bset
= isl_basic_set_add_constraint(bset
, c
);
836 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
838 assert(isl_basic_set_is_empty(bset
));
839 isl_local_space_free(ls
);
840 isl_basic_set_free(bset
);
843 dim
= isl_space_set_alloc(ctx
, 0, 3);
844 bset
= isl_basic_set_universe(isl_space_copy(dim
));
845 ls
= isl_local_space_from_space(dim
);
847 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
848 isl_int_set_si(v
, -1);
849 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
850 isl_int_set_si(v
, 3);
851 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
852 bset
= isl_basic_set_add_constraint(bset
, c
);
854 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
855 isl_int_set_si(v
, 1);
856 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
857 isl_int_set_si(v
, -3);
858 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
859 bset
= isl_basic_set_add_constraint(bset
, c
);
861 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
863 assert(bset
&& bset
->n_div
== 0);
864 isl_basic_set_free(bset
);
865 isl_local_space_free(ls
);
868 dim
= isl_space_set_alloc(ctx
, 0, 3);
869 bset
= isl_basic_set_universe(isl_space_copy(dim
));
870 ls
= isl_local_space_from_space(dim
);
872 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
873 isl_int_set_si(v
, -1);
874 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
875 isl_int_set_si(v
, 6);
876 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
877 bset
= isl_basic_set_add_constraint(bset
, c
);
879 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
880 isl_int_set_si(v
, 1);
881 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
882 isl_int_set_si(v
, -3);
883 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
884 bset
= isl_basic_set_add_constraint(bset
, c
);
886 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
888 assert(bset
&& bset
->n_div
== 1);
889 isl_basic_set_free(bset
);
890 isl_local_space_free(ls
);
893 /* This test is a bit tricky. We set up an equality
895 * Normalization of divs creates _two_ divs
898 * Afterwards e0 is removed again because it has coefficient -1
899 * and we end up with the original equality and div again.
900 * Perhaps we can avoid the introduction of this temporary div.
902 dim
= isl_space_set_alloc(ctx
, 0, 4);
903 bset
= isl_basic_set_universe(isl_space_copy(dim
));
904 ls
= isl_local_space_from_space(dim
);
906 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
907 isl_int_set_si(v
, -1);
908 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
909 isl_int_set_si(v
, -3);
910 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
911 isl_int_set_si(v
, -3);
912 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
913 isl_int_set_si(v
, 6);
914 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
915 bset
= isl_basic_set_add_constraint(bset
, c
);
917 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
919 /* Test disabled for now */
921 assert(bset && bset->n_div == 1);
923 isl_local_space_free(ls
);
924 isl_basic_set_free(bset
);
927 dim
= isl_space_set_alloc(ctx
, 0, 5);
928 bset
= isl_basic_set_universe(isl_space_copy(dim
));
929 ls
= isl_local_space_from_space(dim
);
931 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
932 isl_int_set_si(v
, -1);
933 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
934 isl_int_set_si(v
, -3);
935 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
936 isl_int_set_si(v
, -3);
937 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
938 isl_int_set_si(v
, 6);
939 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
940 bset
= isl_basic_set_add_constraint(bset
, c
);
942 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
943 isl_int_set_si(v
, -1);
944 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
945 isl_int_set_si(v
, 1);
946 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
947 isl_int_set_si(v
, 1);
948 c
= isl_constraint_set_constant(c
, v
);
949 bset
= isl_basic_set_add_constraint(bset
, c
);
951 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
953 /* Test disabled for now */
955 assert(bset && bset->n_div == 1);
957 isl_local_space_free(ls
);
958 isl_basic_set_free(bset
);
961 dim
= isl_space_set_alloc(ctx
, 0, 4);
962 bset
= isl_basic_set_universe(isl_space_copy(dim
));
963 ls
= isl_local_space_from_space(dim
);
965 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
966 isl_int_set_si(v
, 1);
967 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
968 isl_int_set_si(v
, -1);
969 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
970 isl_int_set_si(v
, -2);
971 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
972 bset
= isl_basic_set_add_constraint(bset
, c
);
974 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
975 isl_int_set_si(v
, -1);
976 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
977 isl_int_set_si(v
, 3);
978 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
979 isl_int_set_si(v
, 2);
980 c
= isl_constraint_set_constant(c
, v
);
981 bset
= isl_basic_set_add_constraint(bset
, c
);
983 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
985 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
987 assert(!isl_basic_set_is_empty(bset
));
989 isl_local_space_free(ls
);
990 isl_basic_set_free(bset
);
993 dim
= isl_space_set_alloc(ctx
, 0, 3);
994 bset
= isl_basic_set_universe(isl_space_copy(dim
));
995 ls
= isl_local_space_from_space(dim
);
997 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
998 isl_int_set_si(v
, 1);
999 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
1000 isl_int_set_si(v
, -2);
1001 c
= isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
1002 bset
= isl_basic_set_add_constraint(bset
, c
);
1004 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
1006 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
1008 isl_local_space_free(ls
);
1009 isl_basic_set_free(bset
);
1013 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
1014 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
1015 set
= isl_set_read_from_str(ctx
, str
);
1016 set
= isl_set_compute_divs(set
);
1021 if (test_elimination(ctx
) < 0)
1024 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
1025 set
= isl_set_read_from_str(ctx
, str
);
1026 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
1027 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
1028 empty
= isl_set_is_empty(set
);
1033 isl_die(ctx
, isl_error_unknown
,
1034 "result not as accurate as expected", return -1);
1039 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
1043 struct isl_basic_set
*bset1
, *bset2
;
1044 struct isl_basic_map
*bmap
;
1046 filename
= get_filename(ctx
, name
, "omega");
1048 input
= fopen(filename
, "r");
1051 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1052 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1054 bset1
= isl_basic_set_apply(bset1
, bmap
);
1056 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1058 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1060 isl_basic_set_free(bset1
);
1061 isl_basic_set_free(bset2
);
1067 static int test_application(isl_ctx
*ctx
)
1069 test_application_case(ctx
, "application");
1070 test_application_case(ctx
, "application2");
1075 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1079 struct isl_basic_set
*bset1
, *bset2
;
1081 filename
= get_filename(ctx
, name
, "polylib");
1083 input
= fopen(filename
, "r");
1086 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1087 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1089 bset1
= isl_basic_set_affine_hull(bset1
);
1091 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1093 isl_basic_set_free(bset1
);
1094 isl_basic_set_free(bset2
);
1100 int test_affine_hull(struct isl_ctx
*ctx
)
1104 isl_basic_set
*bset
, *bset2
;
1108 test_affine_hull_case(ctx
, "affine2");
1109 test_affine_hull_case(ctx
, "affine");
1110 test_affine_hull_case(ctx
, "affine3");
1112 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1113 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1114 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1115 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1116 set
= isl_set_read_from_str(ctx
, str
);
1117 bset
= isl_set_affine_hull(set
);
1118 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1119 isl_basic_set_free(bset
);
1121 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1124 /* Check that isl_map_affine_hull is not confused by
1125 * the reordering of divs in isl_map_align_divs.
1127 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1128 "32e0 = b and 32e1 = c); "
1129 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1130 set
= isl_set_read_from_str(ctx
, str
);
1131 bset
= isl_set_affine_hull(set
);
1132 isl_basic_set_free(bset
);
1136 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1137 "32e2 = 31 + 31e0 }";
1138 set
= isl_set_read_from_str(ctx
, str
);
1139 bset
= isl_set_affine_hull(set
);
1140 str
= "{ [a] : exists e : a = 32 e }";
1141 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1142 subset
= isl_basic_set_is_subset(bset
, bset2
);
1143 isl_basic_set_free(bset
);
1144 isl_basic_set_free(bset2
);
1148 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1154 /* Pairs of maps and the corresponding expected results of
1155 * isl_map_plain_unshifted_simple_hull.
1160 } plain_unshifted_simple_hull_tests
[] = {
1161 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1162 "{ [i] -> [j] : i >= 1 }" },
1163 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1164 "(j mod 4 = 2 and k mod 6 = n) }",
1165 "{ [n] -> [i,j,k] : j mod 4 = 2 }" },
1168 /* Basic tests for isl_map_plain_unshifted_simple_hull.
1170 static int test_plain_unshifted_simple_hull(isl_ctx
*ctx
)
1174 isl_basic_map
*hull
, *expected
;
1177 for (i
= 0; i
< ARRAY_SIZE(plain_unshifted_simple_hull_tests
); ++i
) {
1179 str
= plain_unshifted_simple_hull_tests
[i
].map
;
1180 map
= isl_map_read_from_str(ctx
, str
);
1181 str
= plain_unshifted_simple_hull_tests
[i
].hull
;
1182 expected
= isl_basic_map_read_from_str(ctx
, str
);
1183 hull
= isl_map_plain_unshifted_simple_hull(map
);
1184 equal
= isl_basic_map_is_equal(hull
, expected
);
1185 isl_basic_map_free(hull
);
1186 isl_basic_map_free(expected
);
1190 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1197 /* Pairs of sets and the corresponding expected results of
1198 * isl_set_unshifted_simple_hull.
1203 } unshifted_simple_hull_tests
[] = {
1204 { "{ [0,x,y] : x <= -1; [1,x,y] : x <= y <= -x; [2,x,y] : x <= 1 }",
1205 "{ [t,x,y] : 0 <= t <= 2 and x <= 1 }" },
1208 /* Basic tests for isl_set_unshifted_simple_hull.
1210 static int test_unshifted_simple_hull(isl_ctx
*ctx
)
1214 isl_basic_set
*hull
, *expected
;
1217 for (i
= 0; i
< ARRAY_SIZE(unshifted_simple_hull_tests
); ++i
) {
1219 str
= unshifted_simple_hull_tests
[i
].set
;
1220 set
= isl_set_read_from_str(ctx
, str
);
1221 str
= unshifted_simple_hull_tests
[i
].hull
;
1222 expected
= isl_basic_set_read_from_str(ctx
, str
);
1223 hull
= isl_set_unshifted_simple_hull(set
);
1224 equal
= isl_basic_set_is_equal(hull
, expected
);
1225 isl_basic_set_free(hull
);
1226 isl_basic_set_free(expected
);
1230 isl_die(ctx
, isl_error_unknown
, "unexpected hull",
1237 static int test_simple_hull(struct isl_ctx
*ctx
)
1241 isl_basic_set
*bset
;
1244 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1245 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1246 set
= isl_set_read_from_str(ctx
, str
);
1247 bset
= isl_set_simple_hull(set
);
1248 is_empty
= isl_basic_set_is_empty(bset
);
1249 isl_basic_set_free(bset
);
1251 if (is_empty
== isl_bool_error
)
1254 if (is_empty
== isl_bool_false
)
1255 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1258 if (test_plain_unshifted_simple_hull(ctx
) < 0)
1260 if (test_unshifted_simple_hull(ctx
) < 0)
1266 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1270 struct isl_basic_set
*bset1
, *bset2
;
1271 struct isl_set
*set
;
1273 filename
= get_filename(ctx
, name
, "polylib");
1275 input
= fopen(filename
, "r");
1278 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1279 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1281 set
= isl_basic_set_union(bset1
, bset2
);
1282 bset1
= isl_set_convex_hull(set
);
1284 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1286 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1288 isl_basic_set_free(bset1
);
1289 isl_basic_set_free(bset2
);
1298 } convex_hull_tests
[] = {
1299 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1300 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1301 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1302 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1303 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1304 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1305 "i2 <= 5 and i2 >= 4; "
1306 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1307 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1308 "i2 <= 5 + i0 and i2 >= i0 }" },
1309 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1310 "{ [x, y] : 1 = 0 }" },
1311 { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; "
1312 "[x, y, 0] : x >= 0 and y < 0 }",
1313 "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" },
1316 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1319 int orig_convex
= ctx
->opt
->convex
;
1320 ctx
->opt
->convex
= convex
;
1322 test_convex_hull_case(ctx
, "convex0");
1323 test_convex_hull_case(ctx
, "convex1");
1324 test_convex_hull_case(ctx
, "convex2");
1325 test_convex_hull_case(ctx
, "convex3");
1326 test_convex_hull_case(ctx
, "convex4");
1327 test_convex_hull_case(ctx
, "convex5");
1328 test_convex_hull_case(ctx
, "convex6");
1329 test_convex_hull_case(ctx
, "convex7");
1330 test_convex_hull_case(ctx
, "convex8");
1331 test_convex_hull_case(ctx
, "convex9");
1332 test_convex_hull_case(ctx
, "convex10");
1333 test_convex_hull_case(ctx
, "convex11");
1334 test_convex_hull_case(ctx
, "convex12");
1335 test_convex_hull_case(ctx
, "convex13");
1336 test_convex_hull_case(ctx
, "convex14");
1337 test_convex_hull_case(ctx
, "convex15");
1339 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1340 isl_set
*set1
, *set2
;
1343 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1344 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1345 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1346 equal
= isl_set_is_equal(set1
, set2
);
1353 isl_die(ctx
, isl_error_unknown
,
1354 "unexpected convex hull", return -1);
1357 ctx
->opt
->convex
= orig_convex
;
1362 static int test_convex_hull(isl_ctx
*ctx
)
1364 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1366 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1371 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1375 struct isl_basic_set
*bset1
, *bset2
;
1377 filename
= get_filename(ctx
, name
, "polylib");
1379 input
= fopen(filename
, "r");
1382 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1383 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1385 bset1
= isl_basic_set_gist(bset1
, bset2
);
1387 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1389 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1391 isl_basic_set_free(bset1
);
1392 isl_basic_set_free(bset2
);
1398 /* Inputs to isl_map_plain_gist_basic_map, along with the expected output.
1402 const char *context
;
1404 } plain_gist_tests
[] = {
1405 { "{ [i] -> [j] : i >= 1 and j >= 1 or i >= 2 and j <= 10 }",
1406 "{ [i] -> [j] : i >= 1 }",
1407 "{ [i] -> [j] : j >= 1 or i >= 2 and j <= 10 }" },
1408 { "{ [n] -> [i,j,k] : (i mod 3 = 2 and j mod 4 = 2) or "
1409 "(j mod 4 = 2 and k mod 6 = n) }",
1410 "{ [n] -> [i,j,k] : j mod 4 = 2 }",
1411 "{ [n] -> [i,j,k] : (i mod 3 = 2) or (k mod 6 = n) }" },
1412 { "{ [i] -> [j] : i > j and (exists a,b : i <= 2a + 5b <= 2) }",
1413 "{ [i] -> [j] : i > j }",
1414 "{ [i] -> [j] : exists a,b : i <= 2a + 5b <= 2 }" },
1417 /* Basic tests for isl_map_plain_gist_basic_map.
1419 static int test_plain_gist(isl_ctx
*ctx
)
1423 for (i
= 0; i
< ARRAY_SIZE(plain_gist_tests
); ++i
) {
1426 isl_map
*map
, *gist
;
1427 isl_basic_map
*context
;
1429 map
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].map
);
1430 str
= plain_gist_tests
[i
].context
;
1431 context
= isl_basic_map_read_from_str(ctx
, str
);
1432 map
= isl_map_plain_gist_basic_map(map
, context
);
1433 gist
= isl_map_read_from_str(ctx
, plain_gist_tests
[i
].gist
);
1434 equal
= isl_map_is_equal(map
, gist
);
1440 isl_die(ctx
, isl_error_unknown
,
1441 "incorrect gist result", return -1);
1449 const char *context
;
1452 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1453 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1454 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1455 "{ [a, b, c] : a <= 15 }" },
1456 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1457 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1458 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1459 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1460 { "{ [m, n, a, b] : a <= 2147 + n }",
1461 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1462 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1463 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1465 "{ [m, n, ku, kl] }" },
1466 { "{ [a, a, b] : a >= 10 }",
1467 "{ [a, b, c] : c >= a and c <= b and c >= 2 }",
1468 "{ [a, a, b] : a >= 10 }" },
1469 { "{ [i, j] : i >= 0 and i + j >= 0 }", "{ [i, j] : i <= 0 }",
1470 "{ [0, j] : j >= 0 }" },
1471 /* Check that no constraints on i6 are introduced in the gist */
1472 { "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1473 "20e0 <= 1530 - 4t1 - 5i4 and 20e0 >= 1511 - 4t1 - 5i4 and "
1474 "5e0 <= 381 - t1 and i4 <= 1) }",
1475 "[t1] -> { [i4, i6] : exists (e0 = floor((-t1 + i6)/5): "
1476 "5e0 = -t1 + i6 and i6 <= 6 and i6 >= 3) }",
1477 "[t1] -> { [i4, i6] : exists (e0 = floor((1530 - 4t1 - 5i4)/20): "
1478 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 <= 1530 - 4t1 - 5i4 and "
1479 "20e0 >= 1511 - 4t1 - 5i4) }" },
1480 /* Check that no constraints on i6 are introduced in the gist */
1481 { "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((1 + i4)/2), "
1482 "e1 = floor((1530 - 4t1 - 5i4)/20), "
1483 "e2 = floor((-4t1 - 5i4 + 10*floor((1 + i4)/2))/20), "
1484 "e3 = floor((-1 + i4)/2): t2 = 0 and 2e3 = -1 + i4 and "
1485 "20e2 >= -19 - 4t1 - 5i4 + 10e0 and 5e2 <= 1 - t1 and "
1486 "2e0 <= 1 + i4 and 2e0 >= i4 and "
1487 "20e1 <= 1530 - 4t1 - 5i4 and "
1488 "20e1 >= 1511 - 4t1 - 5i4 and i4 <= 1 and "
1489 "5e1 <= 381 - t1 and 20e2 <= -4t1 - 5i4 + 10e0) }",
1490 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((-17 + i4)/2), "
1491 "e1 = floor((-t1 + i6)/5): 5e1 = -t1 + i6 and "
1492 "2e0 <= -17 + i4 and 2e0 >= -18 + i4 and "
1493 "10e0 <= -91 + 5i4 + 4i6 and "
1494 "10e0 >= -105 + 5i4 + 4i6) }",
1495 "[t1, t2] -> { [i4, i5, i6] : exists (e0 = floor((381 - t1)/5), "
1496 "e1 = floor((-1 + i4)/2): t2 = 0 and 2e1 = -1 + i4 and "
1497 "i4 <= 1 and 5e0 <= 381 - t1 and 20e0 >= 1511 - 4t1 - 5i4) }" },
1498 { "{ [0, 0, q, p] : -5 <= q <= 5 and p >= 0 }",
1499 "{ [a, b, q, p] : b >= 1 + a }",
1500 "{ [a, b, q, p] : false }" },
1501 { "[n] -> { [x] : x = n && x mod 32 = 0 }",
1502 "[n] -> { [x] : x mod 32 = 0 }",
1503 "[n] -> { [x = n] }" },
1504 { "{ [x] : x mod 6 = 0 }", "{ [x] : x mod 3 = 0 }",
1505 "{ [x] : x mod 2 = 0 }" },
1506 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10000 = 0 }",
1507 "{ [x] : x mod 128 = 0 }" },
1508 { "{ [x] : x mod 3200 = 0 }", "{ [x] : x mod 10 = 0 }",
1509 "{ [x] : x mod 3200 = 0 }" },
1510 { "{ [a, b, c] : a mod 2 = 0 and a = c }",
1511 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1512 "{ [a, b, c = a] }" },
1513 { "{ [a, b, c] : a mod 6 = 0 and a = c }",
1514 "{ [a, b, c] : b mod 2 = 0 and b = c }",
1515 "{ [a, b, c = a] : a mod 3 = 0 }" },
1516 { "{ [x] : 0 <= x <= 4 or 6 <= x <= 9 }",
1517 "{ [x] : 1 <= x <= 3 or 7 <= x <= 8 }",
1519 { "{ [x,y] : x < 0 and 0 <= y <= 4 or x >= -2 and -x <= y <= 10 + x }",
1520 "{ [x,y] : 1 <= y <= 3 }",
1524 /* Check that isl_set_gist behaves as expected.
1526 * For the test cases in gist_tests, besides checking that the result
1527 * is as expected, also check that applying the gist operation does
1528 * not modify the input set (an earlier version of isl would do that) and
1529 * that the test case is consistent, i.e., that the gist has the same
1530 * intersection with the context as the input set.
1532 static int test_gist(struct isl_ctx
*ctx
)
1536 isl_basic_set
*bset1
, *bset2
;
1537 isl_map
*map1
, *map2
;
1540 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1541 int equal_input
, equal_intersection
;
1542 isl_set
*set1
, *set2
, *copy
, *context
;
1544 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1545 context
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1546 copy
= isl_set_copy(set1
);
1547 set1
= isl_set_gist(set1
, isl_set_copy(context
));
1548 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1549 equal
= isl_set_is_equal(set1
, set2
);
1551 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1552 equal_input
= isl_set_is_equal(set1
, copy
);
1554 set1
= isl_set_intersect(set1
, isl_set_copy(context
));
1555 set2
= isl_set_intersect(set2
, context
);
1556 equal_intersection
= isl_set_is_equal(set1
, set2
);
1559 if (equal
< 0 || equal_input
< 0 || equal_intersection
< 0)
1562 isl_die(ctx
, isl_error_unknown
,
1563 "incorrect gist result", return -1);
1565 isl_die(ctx
, isl_error_unknown
,
1566 "gist modified input", return -1);
1568 isl_die(ctx
, isl_error_unknown
,
1569 "inconsistent gist test case", return -1);
1572 test_gist_case(ctx
, "gist1");
1574 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1575 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1576 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1577 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1578 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1579 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1580 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1581 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1582 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1583 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1584 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1585 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1586 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1587 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1588 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1589 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1590 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1591 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1592 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1593 bset1
= isl_basic_set_gist(bset1
, bset2
);
1594 assert(bset1
&& bset1
->n_div
== 0);
1595 isl_basic_set_free(bset1
);
1597 /* Check that the integer divisions of the second disjunct
1598 * do not spread to the first disjunct.
1600 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1601 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1602 "(exists (e0 = [(-1 + t1)/16], "
1603 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1604 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1605 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1606 "o0 <= 4294967295 and t1 <= -1)) }";
1607 map1
= isl_map_read_from_str(ctx
, str
);
1608 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1609 map2
= isl_map_read_from_str(ctx
, str
);
1610 map1
= isl_map_gist(map1
, map2
);
1614 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1615 isl_map_free(map1
); return -1);
1616 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1617 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1618 isl_map_free(map1
); return -1);
1621 if (test_plain_gist(ctx
) < 0)
1627 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1629 isl_set
*set
, *set2
;
1633 set
= isl_set_read_from_str(ctx
, str
);
1634 set
= isl_set_coalesce(set
);
1635 set2
= isl_set_read_from_str(ctx
, str
);
1636 equal
= isl_set_is_equal(set
, set2
);
1637 one
= set
&& set
->n
== 1;
1644 isl_die(ctx
, isl_error_unknown
,
1645 "coalesced set not equal to input", return -1);
1646 if (check_one
&& !one
)
1647 isl_die(ctx
, isl_error_unknown
,
1648 "coalesced set should not be a union", return -1);
1653 /* Inputs for coalescing tests with unbounded wrapping.
1654 * "str" is a string representation of the input set.
1655 * "single_disjunct" is set if we expect the result to consist of
1656 * a single disjunct.
1659 int single_disjunct
;
1661 } coalesce_unbounded_tests
[] = {
1662 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1663 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1664 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1665 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1667 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1668 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1669 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1670 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1673 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1674 * option turned off.
1676 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1682 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1683 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1685 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
1686 const char *str
= coalesce_unbounded_tests
[i
].str
;
1687 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
1688 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
1694 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1699 /* Inputs for coalescing tests.
1700 * "str" is a string representation of the input set.
1701 * "single_disjunct" is set if we expect the result to consist of
1702 * a single disjunct.
1705 int single_disjunct
;
1707 } coalesce_tests
[] = {
1708 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1709 "y >= x & x >= 2 & 5 >= y }" },
1710 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1711 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1712 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1713 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1714 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1715 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1716 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1717 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1718 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1719 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1720 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1721 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1722 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1723 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1724 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1725 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1726 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1727 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1728 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1729 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1730 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1731 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1732 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1733 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1734 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1735 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1736 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1737 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1738 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1739 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1740 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1741 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1742 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1743 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1744 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1745 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1746 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1747 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1748 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1749 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1750 "[o0, o1, o2, o3, o4, o5, o6]] : "
1751 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1752 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1753 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1754 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1755 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1756 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1757 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1758 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1759 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1760 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1761 "o6 >= i3 + i6 - o3 and M >= 0 and "
1762 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1763 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1764 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1765 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1766 "(o0 = 0 and M >= 2 and N >= 3) or "
1767 "(M = 0 and o0 = 0 and N >= 3) }" },
1768 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1769 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1770 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1771 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1772 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1773 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1774 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1775 "(y = 3 and x = 1) }" },
1776 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1777 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1778 "i1 <= M and i3 <= M and i4 <= M) or "
1779 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1780 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1781 "i4 <= -1 + M) }" },
1782 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1783 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1784 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1785 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1786 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1787 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1788 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1789 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1790 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1791 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1792 { 0, "{ [a, b] : exists e : 2e = a and "
1793 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1794 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1795 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1796 "j >= 1 and j' <= i + j - i' and i >= 1; "
1798 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1799 "[i,j] : exists a : j = 3a }" },
1800 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1801 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1803 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1804 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1805 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1806 "c <= 6 + 8a and a >= 3; "
1807 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1808 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1809 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1810 "[x,0] : 3 <= x <= 4 }" },
1811 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1812 "[x,0] : 4 <= x <= 5 }" },
1813 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1814 "[x,0] : 3 <= x <= 5 }" },
1815 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1816 "[x,0] : 3 <= x <= 4 }" },
1817 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1819 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1820 { 1, "{ [0,0]; [1,1] }" },
1821 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
1822 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
1824 "[k, 0, k] : k <= 6 and k >= 1 }" },
1825 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
1826 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
1827 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
1828 { 1, "[n] -> { [1] : n >= 0;"
1829 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
1830 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
1831 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
1832 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
1833 "2e0 <= x and 2e0 <= n);"
1834 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
1836 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
1837 "128e0 >= -134 + 127t1 and t1 >= 2 and "
1838 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
1840 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
1841 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
1843 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
1844 "t1 >= 13 and t1 <= 16);"
1845 "[t1] : t1 <= 15 and t1 >= 12 }" },
1846 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
1847 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
1848 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
1849 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
1850 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
1851 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
1853 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
1854 "(exists (e0 : 3e0 = -2 + c0)) }" },
1855 { 0, "[n, b0, t0] -> "
1856 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1857 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1858 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
1859 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
1860 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
1861 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
1862 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
1863 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
1864 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1865 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
1866 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
1867 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
1868 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
1869 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
1870 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
1871 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
1872 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
1873 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
1874 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
1875 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
1876 { 0, "{ [i0, i1, i2] : "
1877 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
1878 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
1879 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
1880 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
1881 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
1882 "32e0 <= 31 + i0)) or "
1884 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
1885 { 1, "{ [a, a, b, c] : 32*floor((a)/32) = a and 2*floor((b)/2) = b and "
1886 "2*floor((c)/2) = c and 0 <= a <= 192;"
1887 "[224, 224, b, c] : 2*floor((b)/2) = b and 2*floor((c)/2) = c }"
1889 { 1, "[n] -> { [a,b] : (exists e : 1 <= a <= 7e and 9e <= b <= n) or "
1890 "(0 <= a <= b <= n) }" },
1891 { 1, "{ [a, b] : 0 <= a <= 2 and b >= 0 and "
1892 "((0 < b <= 13) or (2*floor((a + b)/2) >= -5 + a + 2b)) }" },
1893 { 1, "{ [a] : (2 <= a <= 5) or (a mod 2 = 1 and 1 <= a <= 5) }" },
1894 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
1895 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
1896 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
1897 "b = 3 and 9e0 <= -19 + 2c)) }" },
1898 { 1, "{ [a, b, c] : (b = -1 + a and 0 < a <= 3 and "
1899 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
1900 "(a = 4 and b = 3 and "
1901 "9*floor((-16 + 2c)/9) <= -19 + 2c) }" },
1902 { 0, "{ [a, b, c] : (b <= 2 and b <= -2 + a) or "
1903 "(b = -1 + a and 0 < a <= 3 and "
1904 "9*floor((-4a + 2c)/9) <= -3 - 4a + 2c) or "
1905 "(exists (e0 = floor((-16 + 2c)/9): a = 4 and "
1906 "b = 3 and 9e0 <= -19 + 2c)) }" },
1907 { 1, "{ [y, x] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
1909 { 1, "{ [x, y] : (x - y) mod 3 = 2 and 2 <= y <= 200 and 0 <= x <= 2;"
1911 { 1, "{ [1, y] : -1 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
1912 { 1, "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }" },
1913 { 1, "{ [x, y] : 0 <= x <= 10 and x - 4*floor(x/4) <= 1 and y <= 0; "
1914 "[x, y] : 0 <= x <= 10 and x - 4*floor(x/4) > 1 and y <= 0; "
1915 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) <= 1 and 0 < y; "
1916 "[x, y] : 0 <= x <= 10 and x - 5*floor(x/5) > 1 and 0 < y }" },
1917 { 1, "{ [x, 0] : 0 <= x <= 10 and x mod 2 = 0; "
1918 "[x, 0] : 0 <= x <= 10 and x mod 2 = 1; "
1919 "[x, y] : 0 <= x <= 10 and 1 <= y <= 10 }" },
1920 { 1, "{ [a] : a <= 8 and "
1921 "(a mod 10 = 7 or a mod 10 = 8 or a mod 10 = 9) }" },
1922 { 1, "{ [x, y] : 2y = -x and x <= 0 or "
1923 "x <= -1 and 2y <= -x - 1 and 2y >= x - 1 }" },
1924 { 0, "{ [x, y] : 2y = -x and x <= 0 or "
1925 "x <= -2 and 2y <= -x - 1 and 2y >= x - 1 }" },
1926 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
1927 "(a < 0 and 3*floor((a)/3) < a) }" },
1928 { 1, "{ [a] : (a <= 0 and 3*floor((a)/3) = a) or "
1929 "(a < -1 and 3*floor((a)/3) < a) }" },
1930 { 1, "{ [a, b] : a <= 1024 and b >= 0 and "
1931 "((-31 - a + b <= 32*floor((-1 - a)/32) <= -33 + b and "
1932 "32*floor((-1 - a)/32) <= -16 + b + 16*floor((-1 - a)/16))"
1933 "or (2 <= a <= 15 and b < a)) }" },
1934 { 1, "{ [a] : a > 0 and ((16*floor((a)/16) < a and "
1935 "32*floor((a)/32) < a) or a <= 15) }" },
1936 { 1, "{ [a, b, c, d] : (-a + d) mod 64 = 0 and a <= 8 and b <= 1 and "
1937 "10 - a <= c <= 3 and d >= 5 and 9 - 64b <= d <= 70;"
1938 "[a, b = 1, c, d] : (-a + d) mod 64 = 0 and a <= 8 and c >= 4 and "
1939 "10 - a <= c <= 5 and 5 <= d <= 73 - c }" },
1940 { 1, "[n, m] -> { S_0[i] : (-n + i) mod 3 = 0 and m >= 3 + n and "
1941 "i >= n and 3*floor((2 + n + 2m)/3) <= n + 3m - i; "
1942 "S_0[n] : n <= m <= 2 + n }" },
1943 { 1, "{ [a, b] : exists (e0: 0 <= a <= 1 and b >= 0 and "
1944 "2e0 >= -5 + a + 2b and 2e0 >= -1 + a + b and "
1946 "[a, b] : exists (e0: 0 <= a <= 1 and 2e0 >= -5 + a + 2b and "
1947 "2e0 >= -1 - a + b and 2e0 <= -a + b and "
1948 "2e0 < -a + 2b) }" },
1949 { 1, "{ [i, j, i - 8j] : 8 <= i <= 63 and -7 + i <= 8j <= i; "
1950 "[i, 0, i] : 0 <= i <= 7 }" },
1953 /* A specialized coalescing test case that would result
1954 * in a segmentation fault or a failed assertion in earlier versions of isl.
1956 static int test_coalesce_special(struct isl_ctx
*ctx
)
1959 isl_map
*map1
, *map2
;
1961 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
1962 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
1963 "(y = 201 and o1 <= 239 and o1 >= 212) or "
1964 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
1965 "o1 <= 239 and o1 >= 212)) or "
1966 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
1967 "o1 <= 241 and o1 >= 240));"
1968 "[S_L220_OUT[] -> T7[]] -> "
1969 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
1970 "(y = 2 and o1 <= 241 and o1 >= 212) or "
1971 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
1972 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
1973 map1
= isl_map_read_from_str(ctx
, str
);
1974 map1
= isl_map_align_divs_internal(map1
);
1975 map1
= isl_map_coalesce(map1
);
1976 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
1977 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
1978 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
1979 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
1980 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
1981 map2
= isl_map_read_from_str(ctx
, str
);
1982 map2
= isl_map_union(map2
, map1
);
1983 map2
= isl_map_align_divs_internal(map2
);
1984 map2
= isl_map_coalesce(map2
);
1992 /* A specialized coalescing test case that would result in an assertion
1993 * in an earlier version of isl.
1994 * The explicit call to isl_basic_set_union prevents the implicit
1995 * equality constraints in the first basic map from being detected prior
1996 * to the call to isl_set_coalesce, at least at the point
1997 * where this test case was introduced.
1999 static int test_coalesce_special2(struct isl_ctx
*ctx
)
2002 isl_basic_set
*bset1
, *bset2
;
2005 str
= "{ [x, y] : x, y >= 0 and x + 2y <= 1 and 2x + y <= 1 }";
2006 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2007 str
= "{ [x,0] : -1 <= x <= 1 and x mod 2 = 1 }" ;
2008 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2009 set
= isl_basic_set_union(bset1
, bset2
);
2010 set
= isl_set_coalesce(set
);
2018 /* Check that calling isl_set_coalesce does not leave other sets
2019 * that may share some information with the input to isl_set_coalesce
2020 * in an inconsistent state.
2021 * In particular, older versions of isl would modify all copies
2022 * of the basic sets in the isl_set_coalesce input in a way
2023 * that could leave them in an inconsistent state.
2024 * The result of printing any other set containing one of these
2025 * basic sets would then result in an invalid set description.
2027 static int test_coalesce_special3(isl_ctx
*ctx
)
2031 isl_set
*set1
, *set2
;
2034 set1
= isl_set_read_from_str(ctx
, "{ [0, 0, 0] }");
2035 str
= "{ [a, b, a + b] : a >= 0 and b >= 0 and 0 < a + b }";
2036 set2
= isl_set_read_from_str(ctx
, str
);
2037 set1
= isl_set_union(set1
, isl_set_copy(set2
));
2038 set1
= isl_set_coalesce(set1
);
2041 p
= isl_printer_to_str(ctx
);
2042 p
= isl_printer_print_set(p
, set2
);
2044 s
= isl_printer_get_str(p
);
2045 isl_printer_free(p
);
2046 set1
= isl_set_read_from_str(ctx
, s
);
2056 /* Test the functionality of isl_set_coalesce.
2057 * That is, check that the output is always equal to the input
2058 * and in some cases that the result consists of a single disjunct.
2060 static int test_coalesce(struct isl_ctx
*ctx
)
2064 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
2065 const char *str
= coalesce_tests
[i
].str
;
2066 int check_one
= coalesce_tests
[i
].single_disjunct
;
2067 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
2071 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
2073 if (test_coalesce_special(ctx
) < 0)
2075 if (test_coalesce_special2(ctx
) < 0)
2077 if (test_coalesce_special3(ctx
) < 0)
2083 /* Construct a representation of the graph on the right of Figure 1
2084 * in "Computing the Transitive Closure of a Union of
2085 * Affine Integer Tuple Relations".
2087 static __isl_give isl_map
*cocoa_fig_1_right_graph(isl_ctx
*ctx
)
2090 isl_map
*up
, *right
;
2092 dom
= isl_set_read_from_str(ctx
,
2093 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
2094 "2 x - 3 y + 3 >= 0 }");
2095 right
= isl_map_read_from_str(ctx
,
2096 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
2097 up
= isl_map_read_from_str(ctx
,
2098 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
2099 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
2100 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
2101 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
2102 up
= isl_map_intersect_range(up
, dom
);
2103 return isl_map_union(up
, right
);
2106 /* Construct a representation of the power of the graph
2107 * on the right of Figure 1 in "Computing the Transitive Closure of
2108 * a Union of Affine Integer Tuple Relations".
2110 static __isl_give isl_map
*cocoa_fig_1_right_power(isl_ctx
*ctx
)
2112 return isl_map_read_from_str(ctx
,
2113 "{ [1] -> [[0,0] -> [0,1]]; [2] -> [[0,0] -> [1,1]]; "
2114 " [1] -> [[0,1] -> [1,1]]; [1] -> [[2,2] -> [3,2]]; "
2115 " [2] -> [[2,2] -> [3,3]]; [1] -> [[3,2] -> [3,3]] }");
2118 /* Construct a representation of the transitive closure of the graph
2119 * on the right of Figure 1 in "Computing the Transitive Closure of
2120 * a Union of Affine Integer Tuple Relations".
2122 static __isl_give isl_map
*cocoa_fig_1_right_tc(isl_ctx
*ctx
)
2124 return isl_set_unwrap(isl_map_range(cocoa_fig_1_right_power(ctx
)));
2127 static int test_closure(isl_ctx
*ctx
)
2130 isl_map
*map
, *map2
;
2133 /* COCOA example 1 */
2134 map
= isl_map_read_from_str(ctx
,
2135 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2136 "1 <= i and i < n and 1 <= j and j < n or "
2137 "i2 = i + 1 and j2 = j - 1 and "
2138 "1 <= i and i < n and 2 <= j and j <= n }");
2139 map
= isl_map_power(map
, &exact
);
2143 /* COCOA example 1 */
2144 map
= isl_map_read_from_str(ctx
,
2145 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
2146 "1 <= i and i < n and 1 <= j and j < n or "
2147 "i2 = i + 1 and j2 = j - 1 and "
2148 "1 <= i and i < n and 2 <= j and j <= n }");
2149 map
= isl_map_transitive_closure(map
, &exact
);
2151 map2
= isl_map_read_from_str(ctx
,
2152 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2153 "1 <= i and i < n and 1 <= j and j <= n and "
2154 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2155 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
2156 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
2157 assert(isl_map_is_equal(map
, map2
));
2161 map
= isl_map_read_from_str(ctx
,
2162 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
2163 " 0 <= y and y <= n }");
2164 map
= isl_map_transitive_closure(map
, &exact
);
2165 map2
= isl_map_read_from_str(ctx
,
2166 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
2167 " 0 <= y and y <= n }");
2168 assert(isl_map_is_equal(map
, map2
));
2172 /* COCOA example 2 */
2173 map
= isl_map_read_from_str(ctx
,
2174 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
2175 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
2176 "i2 = i + 2 and j2 = j - 2 and "
2177 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
2178 map
= isl_map_transitive_closure(map
, &exact
);
2180 map2
= isl_map_read_from_str(ctx
,
2181 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
2182 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
2183 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
2184 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
2185 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
2186 assert(isl_map_is_equal(map
, map2
));
2190 /* COCOA Fig.2 left */
2191 map
= isl_map_read_from_str(ctx
,
2192 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
2193 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
2195 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
2196 "j <= 2 i - 3 and j <= n - 2 or "
2197 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2198 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2199 map
= isl_map_transitive_closure(map
, &exact
);
2203 /* COCOA Fig.2 right */
2204 map
= isl_map_read_from_str(ctx
,
2205 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2206 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2208 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2209 "j <= 2 i - 4 and j <= n - 3 or "
2210 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2211 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2212 map
= isl_map_power(map
, &exact
);
2216 /* COCOA Fig.2 right */
2217 map
= isl_map_read_from_str(ctx
,
2218 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
2219 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
2221 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
2222 "j <= 2 i - 4 and j <= n - 3 or "
2223 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
2224 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
2225 map
= isl_map_transitive_closure(map
, &exact
);
2227 map2
= isl_map_read_from_str(ctx
,
2228 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
2229 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
2230 "j <= n and 3 + i + 2 j <= 3 n and "
2231 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
2232 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
2233 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
2234 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
2235 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
2236 assert(isl_map_is_equal(map
, map2
));
2240 map
= cocoa_fig_1_right_graph(ctx
);
2241 map
= isl_map_transitive_closure(map
, &exact
);
2243 map2
= cocoa_fig_1_right_tc(ctx
);
2244 assert(isl_map_is_equal(map
, map2
));
2248 map
= cocoa_fig_1_right_graph(ctx
);
2249 map
= isl_map_power(map
, &exact
);
2250 map2
= cocoa_fig_1_right_power(ctx
);
2251 equal
= isl_map_is_equal(map
, map2
);
2257 isl_die(ctx
, isl_error_unknown
, "power not exact", return -1);
2259 isl_die(ctx
, isl_error_unknown
, "unexpected power", return -1);
2261 /* COCOA Theorem 1 counter example */
2262 map
= isl_map_read_from_str(ctx
,
2263 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
2264 "i2 = 1 and j2 = j or "
2265 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
2266 map
= isl_map_transitive_closure(map
, &exact
);
2270 map
= isl_map_read_from_str(ctx
,
2271 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
2272 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
2273 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
2274 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
2275 map
= isl_map_transitive_closure(map
, &exact
);
2279 /* Kelly et al 1996, fig 12 */
2280 map
= isl_map_read_from_str(ctx
,
2281 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
2282 "1 <= i,j,j+1 <= n or "
2283 "j = n and j2 = 1 and i2 = i + 1 and "
2284 "1 <= i,i+1 <= n }");
2285 map
= isl_map_transitive_closure(map
, &exact
);
2287 map2
= isl_map_read_from_str(ctx
,
2288 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
2289 "1 <= i <= n and i = i2 or "
2290 "1 <= i < i2 <= n and 1 <= j <= n and "
2292 assert(isl_map_is_equal(map
, map2
));
2296 /* Omega's closure4 */
2297 map
= isl_map_read_from_str(ctx
,
2298 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
2299 "1 <= x,y <= 10 or "
2300 "x2 = x + 1 and y2 = y and "
2301 "1 <= x <= 20 && 5 <= y <= 15 }");
2302 map
= isl_map_transitive_closure(map
, &exact
);
2306 map
= isl_map_read_from_str(ctx
,
2307 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
2308 map
= isl_map_transitive_closure(map
, &exact
);
2310 map2
= isl_map_read_from_str(ctx
,
2311 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
2312 assert(isl_map_is_equal(map
, map2
));
2316 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
2317 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
2318 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
2319 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
2320 map
= isl_map_read_from_str(ctx
, str
);
2321 map
= isl_map_transitive_closure(map
, &exact
);
2323 map2
= isl_map_read_from_str(ctx
, str
);
2324 assert(isl_map_is_equal(map
, map2
));
2328 str
= "{[0] -> [1]; [2] -> [3]}";
2329 map
= isl_map_read_from_str(ctx
, str
);
2330 map
= isl_map_transitive_closure(map
, &exact
);
2332 map2
= isl_map_read_from_str(ctx
, str
);
2333 assert(isl_map_is_equal(map
, map2
));
2337 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
2338 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
2339 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
2340 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2341 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2342 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
2343 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
2344 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
2345 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2346 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2347 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
2348 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
2349 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
2350 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2351 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
2352 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
2353 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
2354 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
2355 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
2356 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
2357 map
= isl_map_read_from_str(ctx
, str
);
2358 map
= isl_map_transitive_closure(map
, NULL
);
2365 static int test_lex(struct isl_ctx
*ctx
)
2371 dim
= isl_space_set_alloc(ctx
, 0, 0);
2372 map
= isl_map_lex_le(dim
);
2373 empty
= isl_map_is_empty(map
);
2379 isl_die(ctx
, isl_error_unknown
,
2380 "expecting non-empty result", return -1);
2385 /* Inputs for isl_map_lexmin tests.
2386 * "map" is the input and "lexmin" is the expected result.
2391 } lexmin_tests
[] = {
2392 { "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }",
2393 "{ [x] -> [5] : 6 <= x <= 8; "
2394 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }" },
2395 { "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }",
2396 "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }" },
2397 { "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }",
2398 "{ [x] -> [y] : (4y = x and x >= 0) or "
2399 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2400 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2401 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }" },
2402 { "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }",
2403 "{ T[a] -> S[b, c] : 2b = a and 2c = a }" },
2404 /* Check that empty pieces are properly combined. */
2405 { "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2406 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2407 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }",
2408 "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2409 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2411 { "{ [i, k, j] -> [a, b, c, d] : 8*floor((b)/8) = b and k <= 255 and "
2412 "a <= 255 and c <= 255 and d <= 255 - j and "
2413 "255 - j <= 7d <= 7 - i and 240d <= 239 + a and "
2414 "247d <= 247 + k - j and 247d <= 247 + k - b and "
2415 "247d <= 247 + i and 248 - b <= 248d <= c and "
2416 "254d >= i - a + b and 254d >= -a + b and "
2417 "255d >= -i + a - b and 1792d >= -63736 + 257b }",
2419 "[-127762 + i + 502j, -62992 + 248j, 63240 - 248j, 255 - j] : "
2420 "k <= 255 and 7j >= 1778 + i and 246j >= 62738 - k and "
2421 "247j >= 62738 - i and 509j <= 129795 + i and "
2422 "742j >= 188724 - i; "
2423 "[0, k, j] -> [1, 0, 248, 1] : k <= 255 and 248 <= j <= 254, k }" },
2424 { "{ [a] -> [b] : 0 <= b <= 255 and -509 + a <= 512b < a and "
2425 "16*floor((8 + b)/16) <= 7 + b; "
2427 "{ [a] -> [b = 1] : a >= 510 or a <= 0; "
2428 "[a] -> [b = 0] : 0 < a <= 509 }" },
2429 { "{ rat: [i] : 1 <= 2i <= 9 }", "{ rat: [i] : 2i = 1 }" },
2430 { "{ rat: [i] : 1 <= 2i <= 9 or i >= 10 }", "{ rat: [i] : 2i = 1 }" },
2433 static int test_lexmin(struct isl_ctx
*ctx
)
2438 isl_basic_map
*bmap
;
2439 isl_map
*map
, *map2
;
2442 isl_pw_multi_aff
*pma
;
2444 str
= "[p0, p1] -> { [] -> [] : "
2445 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
2446 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
2447 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
2448 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
2449 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
2450 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
2451 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
2452 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
2453 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
2454 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
2455 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
2456 map
= isl_map_read_from_str(ctx
, str
);
2457 map
= isl_map_lexmin(map
);
2460 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
2461 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
2462 set
= isl_set_read_from_str(ctx
, str
);
2463 set
= isl_set_lexmax(set
);
2464 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
2465 set2
= isl_set_read_from_str(ctx
, str
);
2466 set
= isl_set_intersect(set
, set2
);
2467 assert(!isl_set_is_empty(set
));
2470 for (i
= 0; i
< ARRAY_SIZE(lexmin_tests
); ++i
) {
2471 map
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].map
);
2472 map
= isl_map_lexmin(map
);
2473 map2
= isl_map_read_from_str(ctx
, lexmin_tests
[i
].lexmin
);
2474 equal
= isl_map_is_equal(map
, map2
);
2481 isl_die(ctx
, isl_error_unknown
,
2482 "unexpected result", return -1);
2485 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2486 " 8i' <= i and 8i' >= -7 + i }";
2487 bmap
= isl_basic_map_read_from_str(ctx
, str
);
2488 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
2489 map2
= isl_map_from_pw_multi_aff(pma
);
2490 map
= isl_map_from_basic_map(bmap
);
2491 assert(isl_map_is_equal(map
, map2
));
2495 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2496 " 8i' <= i and 8i' >= -7 + i }";
2497 set
= isl_set_read_from_str(ctx
, str
);
2498 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
2499 set2
= isl_set_from_pw_multi_aff(pma
);
2500 equal
= isl_set_is_equal(set
, set2
);
2506 isl_die(ctx
, isl_error_unknown
,
2507 "unexpected difference between set and "
2508 "piecewise affine expression", return -1);
2513 /* A specialized isl_set_min_val test case that would return the wrong result
2514 * in earlier versions of isl.
2515 * The explicit call to isl_basic_set_union prevents the second basic set
2516 * from being determined to be empty prior to the call to isl_set_min_val,
2517 * at least at the point where this test case was introduced.
2519 static int test_min_special(isl_ctx
*ctx
)
2522 isl_basic_set
*bset1
, *bset2
;
2528 str
= "{ [a, b] : a >= 2 and b >= 0 and 14 - a <= b <= 9 }";
2529 bset1
= isl_basic_set_read_from_str(ctx
, str
);
2530 str
= "{ [a, b] : 1 <= a, b and a + b <= 1 }";
2531 bset2
= isl_basic_set_read_from_str(ctx
, str
);
2532 set
= isl_basic_set_union(bset1
, bset2
);
2533 obj
= isl_aff_read_from_str(ctx
, "{ [a, b] -> [a] }");
2535 res
= isl_set_min_val(set
, obj
);
2536 ok
= isl_val_cmp_si(res
, 5) == 0;
2545 isl_die(ctx
, isl_error_unknown
, "unexpected minimum",
2551 /* A specialized isl_set_min_val test case that would return an error
2552 * in earlier versions of isl.
2554 static int test_min_special2(isl_ctx
*ctx
)
2557 isl_basic_set
*bset
;
2561 str
= "{ [i, j, k] : 2j = i and 2k = i + 1 and i >= 2 }";
2562 bset
= isl_basic_set_read_from_str(ctx
, str
);
2564 obj
= isl_aff_read_from_str(ctx
, "{ [i, j, k] -> [i] }");
2566 res
= isl_basic_set_max_val(bset
, obj
);
2568 isl_basic_set_free(bset
);
2581 __isl_give isl_val
*(*fn
)(__isl_keep isl_set
*set
,
2582 __isl_keep isl_aff
*obj
);
2585 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_min_val
, "-1" },
2586 { "{ [-1]; [1] }", "{ [x] -> [x] }", &isl_set_max_val
, "1" },
2587 { "{ [a, b] : 0 <= a, b <= 100 and b mod 2 = 0}",
2588 "{ [a, b] -> [floor((b - 2*floor((-a)/4))/5)] }",
2589 &isl_set_max_val
, "30" },
2593 /* Perform basic isl_set_min_val and isl_set_max_val tests.
2594 * In particular, check the results on non-convex inputs.
2596 static int test_min(struct isl_ctx
*ctx
)
2604 for (i
= 0; i
< ARRAY_SIZE(opt_tests
); ++i
) {
2605 set
= isl_set_read_from_str(ctx
, opt_tests
[i
].set
);
2606 obj
= isl_aff_read_from_str(ctx
, opt_tests
[i
].obj
);
2607 res
= isl_val_read_from_str(ctx
, opt_tests
[i
].res
);
2608 val
= opt_tests
[i
].fn(set
, obj
);
2609 ok
= isl_val_eq(res
, val
);
2618 isl_die(ctx
, isl_error_unknown
,
2619 "unexpected optimum", return -1);
2622 if (test_min_special(ctx
) < 0)
2624 if (test_min_special2(ctx
) < 0)
2635 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
2636 void *dep_user
, void *user
)
2638 struct must_may
*mm
= (struct must_may
*)user
;
2641 mm
->must
= isl_map_union(mm
->must
, dep
);
2643 mm
->may
= isl_map_union(mm
->may
, dep
);
2648 static int common_space(void *first
, void *second
)
2650 int depth
= *(int *)first
;
2654 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
2662 map2
= isl_map_read_from_str(map
->ctx
, str
);
2663 equal
= isl_map_is_equal(map
, map2
);
2669 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
2673 equal
= map_is_equal(map
, str
);
2677 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
2678 "result not as expected", return -1);
2682 static int test_dep(struct isl_ctx
*ctx
)
2687 isl_access_info
*ai
;
2694 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2695 map
= isl_map_read_from_str(ctx
, str
);
2696 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2698 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2699 map
= isl_map_read_from_str(ctx
, str
);
2700 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2702 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2703 map
= isl_map_read_from_str(ctx
, str
);
2704 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2706 flow
= isl_access_info_compute_flow(ai
);
2707 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2708 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2709 mm
.may
= isl_map_empty(dim
);
2711 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2713 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
2714 " [1,10,0] -> [2,5,0] }";
2715 assert(map_is_equal(mm
.must
, str
));
2716 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2717 assert(map_is_equal(mm
.may
, str
));
2719 isl_map_free(mm
.must
);
2720 isl_map_free(mm
.may
);
2721 isl_flow_free(flow
);
2724 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2725 map
= isl_map_read_from_str(ctx
, str
);
2726 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2728 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2729 map
= isl_map_read_from_str(ctx
, str
);
2730 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2732 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2733 map
= isl_map_read_from_str(ctx
, str
);
2734 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2736 flow
= isl_access_info_compute_flow(ai
);
2737 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2738 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2739 mm
.may
= isl_map_empty(dim
);
2741 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2743 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2744 assert(map_is_equal(mm
.must
, str
));
2745 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2746 assert(map_is_equal(mm
.may
, str
));
2748 isl_map_free(mm
.must
);
2749 isl_map_free(mm
.may
);
2750 isl_flow_free(flow
);
2753 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2754 map
= isl_map_read_from_str(ctx
, str
);
2755 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2757 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2758 map
= isl_map_read_from_str(ctx
, str
);
2759 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2761 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2762 map
= isl_map_read_from_str(ctx
, str
);
2763 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2765 flow
= isl_access_info_compute_flow(ai
);
2766 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2767 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2768 mm
.may
= isl_map_empty(dim
);
2770 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2772 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
2773 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2774 assert(map_is_equal(mm
.may
, str
));
2775 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2776 assert(map_is_equal(mm
.must
, str
));
2778 isl_map_free(mm
.must
);
2779 isl_map_free(mm
.may
);
2780 isl_flow_free(flow
);
2783 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
2784 map
= isl_map_read_from_str(ctx
, str
);
2785 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2787 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2788 map
= isl_map_read_from_str(ctx
, str
);
2789 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2791 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
2792 map
= isl_map_read_from_str(ctx
, str
);
2793 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2795 flow
= isl_access_info_compute_flow(ai
);
2796 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2797 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2798 mm
.may
= isl_map_empty(dim
);
2800 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2802 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2803 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2804 assert(map_is_equal(mm
.may
, str
));
2805 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2806 assert(map_is_equal(mm
.must
, str
));
2808 isl_map_free(mm
.must
);
2809 isl_map_free(mm
.may
);
2810 isl_flow_free(flow
);
2813 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2814 map
= isl_map_read_from_str(ctx
, str
);
2815 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2817 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2818 map
= isl_map_read_from_str(ctx
, str
);
2819 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2821 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2822 map
= isl_map_read_from_str(ctx
, str
);
2823 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2825 flow
= isl_access_info_compute_flow(ai
);
2826 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2827 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2828 mm
.may
= isl_map_empty(dim
);
2830 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2832 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2833 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2834 assert(map_is_equal(mm
.may
, str
));
2835 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2836 assert(map_is_equal(mm
.must
, str
));
2838 isl_map_free(mm
.must
);
2839 isl_map_free(mm
.may
);
2840 isl_flow_free(flow
);
2845 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2846 map
= isl_map_read_from_str(ctx
, str
);
2847 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
2849 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2850 map
= isl_map_read_from_str(ctx
, str
);
2851 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2853 flow
= isl_access_info_compute_flow(ai
);
2854 dim
= isl_space_alloc(ctx
, 0, 5, 5);
2855 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2856 mm
.may
= isl_map_empty(dim
);
2858 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2860 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
2861 assert(map_is_equal(mm
.must
, str
));
2862 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
2863 assert(map_is_equal(mm
.may
, str
));
2865 isl_map_free(mm
.must
);
2866 isl_map_free(mm
.may
);
2867 isl_flow_free(flow
);
2872 /* Check that the dependence analysis proceeds without errors.
2873 * Earlier versions of isl would break down during the analysis
2874 * due to the use of the wrong spaces.
2876 static int test_flow(isl_ctx
*ctx
)
2879 isl_union_map
*access
, *schedule
;
2880 isl_union_map
*must_dep
, *may_dep
;
2883 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
2884 access
= isl_union_map_read_from_str(ctx
, str
);
2885 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
2886 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
2887 "S2[] -> [1,0,0,0]; "
2888 "S3[] -> [-1,0,0,0] }";
2889 schedule
= isl_union_map_read_from_str(ctx
, str
);
2890 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
2891 isl_union_map_copy(access
), schedule
,
2892 &must_dep
, &may_dep
, NULL
, NULL
);
2893 isl_union_map_free(may_dep
);
2894 isl_union_map_free(must_dep
);
2903 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
2904 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
2905 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
2906 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
2907 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
2908 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
2909 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2910 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2911 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
2914 int test_sv(isl_ctx
*ctx
)
2916 isl_union_map
*umap
;
2920 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
2921 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
2922 sv
= isl_union_map_is_single_valued(umap
);
2923 isl_union_map_free(umap
);
2926 if (sv_tests
[i
].sv
&& !sv
)
2927 isl_die(ctx
, isl_error_internal
,
2928 "map not detected as single valued", return -1);
2929 if (!sv_tests
[i
].sv
&& sv
)
2930 isl_die(ctx
, isl_error_internal
,
2931 "map detected as single valued", return -1);
2940 } bijective_tests
[] = {
2941 { "[N,M]->{[i,j] -> [i]}", 0 },
2942 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
2943 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
2944 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
2945 { "[N,M]->{[i,j] -> [j,i]}", 1 },
2946 { "[N,M]->{[i,j] -> [i+j]}", 0 },
2947 { "[N,M]->{[i,j] -> []}", 0 },
2948 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
2949 { "[N,M]->{[i,j] -> [2i]}", 0 },
2950 { "[N,M]->{[i,j] -> [i,i]}", 0 },
2951 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
2952 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
2953 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
2956 static int test_bijective(struct isl_ctx
*ctx
)
2962 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
2963 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
2964 bijective
= isl_map_is_bijective(map
);
2968 if (bijective_tests
[i
].bijective
&& !bijective
)
2969 isl_die(ctx
, isl_error_internal
,
2970 "map not detected as bijective", return -1);
2971 if (!bijective_tests
[i
].bijective
&& bijective
)
2972 isl_die(ctx
, isl_error_internal
,
2973 "map detected as bijective", return -1);
2979 /* Inputs for isl_pw_qpolynomial_gist tests.
2980 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
2986 } pwqp_gist_tests
[] = {
2987 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
2988 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
2989 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
2990 "{ [i] -> -1/2 + 1/2 * i }" },
2991 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
2994 static int test_pwqp(struct isl_ctx
*ctx
)
2999 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
3002 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3003 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3005 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
3008 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
3009 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3011 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3013 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3015 isl_pw_qpolynomial_free(pwqp1
);
3017 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
3018 str
= pwqp_gist_tests
[i
].pwqp
;
3019 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3020 str
= pwqp_gist_tests
[i
].set
;
3021 set
= isl_set_read_from_str(ctx
, str
);
3022 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
3023 str
= pwqp_gist_tests
[i
].gist
;
3024 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3025 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3026 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
3027 isl_pw_qpolynomial_free(pwqp1
);
3032 isl_die(ctx
, isl_error_unknown
,
3033 "unexpected result", return -1);
3036 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
3037 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3038 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
3039 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3041 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3043 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3045 isl_pw_qpolynomial_free(pwqp1
);
3047 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
3048 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3049 str
= "{ [x] -> x }";
3050 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3052 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3054 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3056 isl_pw_qpolynomial_free(pwqp1
);
3058 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
3059 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3060 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3061 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
3062 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
3063 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
3064 isl_pw_qpolynomial_free(pwqp1
);
3066 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
3067 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3068 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3069 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3070 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
3071 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
3072 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3073 isl_pw_qpolynomial_free(pwqp1
);
3074 isl_pw_qpolynomial_free(pwqp2
);
3078 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3080 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
3081 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3082 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
3083 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3084 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
3086 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
3087 isl_pw_qpolynomial_free(pwqp1
);
3088 isl_pw_qpolynomial_free(pwqp2
);
3092 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3097 static int test_split_periods(isl_ctx
*ctx
)
3100 isl_pw_qpolynomial
*pwqp
;
3102 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
3103 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
3104 "U >= 0; [U,V] -> U^2 : U >= 100 }";
3105 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3107 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
3109 isl_pw_qpolynomial_free(pwqp
);
3117 static int test_union(isl_ctx
*ctx
)
3120 isl_union_set
*uset1
, *uset2
;
3121 isl_union_map
*umap1
, *umap2
;
3124 str
= "{ [i] : 0 <= i <= 1 }";
3125 uset1
= isl_union_set_read_from_str(ctx
, str
);
3126 str
= "{ [1] -> [0] }";
3127 umap1
= isl_union_map_read_from_str(ctx
, str
);
3129 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
3130 equal
= isl_union_map_is_equal(umap1
, umap2
);
3132 isl_union_map_free(umap1
);
3133 isl_union_map_free(umap2
);
3138 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
3141 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
3142 umap1
= isl_union_map_read_from_str(ctx
, str
);
3143 str
= "{ A[i]; B[i] }";
3144 uset1
= isl_union_set_read_from_str(ctx
, str
);
3146 uset2
= isl_union_map_domain(umap1
);
3148 equal
= isl_union_set_is_equal(uset1
, uset2
);
3150 isl_union_set_free(uset1
);
3151 isl_union_set_free(uset2
);
3156 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
3162 /* Check that computing a bound of a non-zero polynomial over an unbounded
3163 * domain does not produce a rational value.
3164 * In particular, check that the upper bound is infinity.
3166 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
3169 isl_pw_qpolynomial
*pwqp
;
3170 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
3173 str
= "{ [m,n] -> -m * n }";
3174 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3175 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3177 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3178 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3179 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
3180 isl_pw_qpolynomial_fold_free(pwf
);
3181 isl_pw_qpolynomial_fold_free(pwf2
);
3186 isl_die(ctx
, isl_error_unknown
,
3187 "expecting infinite polynomial bound", return -1);
3192 static int test_bound(isl_ctx
*ctx
)
3196 isl_pw_qpolynomial
*pwqp
;
3197 isl_pw_qpolynomial_fold
*pwf
;
3199 if (test_bound_unbounded_domain(ctx
) < 0)
3202 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
3203 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3204 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3205 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3206 isl_pw_qpolynomial_fold_free(pwf
);
3208 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3211 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
3212 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
3213 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
3214 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
3215 isl_pw_qpolynomial_fold_free(pwf
);
3217 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
3223 static int test_lift(isl_ctx
*ctx
)
3226 isl_basic_map
*bmap
;
3227 isl_basic_set
*bset
;
3229 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
3230 bset
= isl_basic_set_read_from_str(ctx
, str
);
3231 bset
= isl_basic_set_lift(bset
);
3232 bmap
= isl_basic_map_from_range(bset
);
3233 bset
= isl_basic_map_domain(bmap
);
3234 isl_basic_set_free(bset
);
3243 } subset_tests
[] = {
3245 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
3246 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
3247 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
3249 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
3250 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
3251 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
3252 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
3253 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
3254 "256e0 <= 255i and 256e0 >= -255 + 255i and "
3255 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
3256 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
3257 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
3258 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
3259 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
3260 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
3261 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
3262 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
3263 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
3264 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
3265 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
3266 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
3267 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
3268 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
3269 "4e0 <= -57 + i0 + i1)) or "
3270 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
3271 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
3272 "4e0 >= -61 + i0 + i1)) or "
3273 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
3274 { "[a, b] -> { : a = 0 and b = -1 }", "[b, a] -> { : b >= -10 }", 1 },
3277 static int test_subset(isl_ctx
*ctx
)
3280 isl_set
*set1
, *set2
;
3283 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
3284 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
3285 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
3286 subset
= isl_set_is_subset(set1
, set2
);
3291 if (subset
!= subset_tests
[i
].subset
)
3292 isl_die(ctx
, isl_error_unknown
,
3293 "incorrect subset result", return -1);
3300 const char *minuend
;
3301 const char *subtrahend
;
3302 const char *difference
;
3303 } subtract_domain_tests
[] = {
3304 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
3305 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
3306 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
3309 static int test_subtract(isl_ctx
*ctx
)
3312 isl_union_map
*umap1
, *umap2
;
3313 isl_union_pw_multi_aff
*upma1
, *upma2
;
3314 isl_union_set
*uset
;
3317 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3318 umap1
= isl_union_map_read_from_str(ctx
,
3319 subtract_domain_tests
[i
].minuend
);
3320 uset
= isl_union_set_read_from_str(ctx
,
3321 subtract_domain_tests
[i
].subtrahend
);
3322 umap2
= isl_union_map_read_from_str(ctx
,
3323 subtract_domain_tests
[i
].difference
);
3324 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
3325 equal
= isl_union_map_is_equal(umap1
, umap2
);
3326 isl_union_map_free(umap1
);
3327 isl_union_map_free(umap2
);
3331 isl_die(ctx
, isl_error_unknown
,
3332 "incorrect subtract domain result", return -1);
3335 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
3336 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3337 subtract_domain_tests
[i
].minuend
);
3338 uset
= isl_union_set_read_from_str(ctx
,
3339 subtract_domain_tests
[i
].subtrahend
);
3340 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3341 subtract_domain_tests
[i
].difference
);
3342 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
3343 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
3344 isl_union_pw_multi_aff_free(upma1
);
3345 isl_union_pw_multi_aff_free(upma2
);
3349 isl_die(ctx
, isl_error_unknown
,
3350 "incorrect subtract domain result", return -1);
3356 /* Check that intersecting the empty basic set with another basic set
3357 * does not increase the number of constraints. In particular,
3358 * the empty basic set should maintain its canonical representation.
3360 static int test_intersect(isl_ctx
*ctx
)
3363 isl_basic_set
*bset1
, *bset2
;
3365 bset1
= isl_basic_set_read_from_str(ctx
, "{ [a,b,c] : 1 = 0 }");
3366 bset2
= isl_basic_set_read_from_str(ctx
, "{ [1,2,3] }");
3367 n1
= isl_basic_set_n_constraint(bset1
);
3368 bset1
= isl_basic_set_intersect(bset1
, bset2
);
3369 n2
= isl_basic_set_n_constraint(bset1
);
3370 isl_basic_set_free(bset1
);
3374 isl_die(ctx
, isl_error_unknown
,
3375 "number of constraints of empty set changed",
3381 int test_factorize(isl_ctx
*ctx
)
3384 isl_basic_set
*bset
;
3387 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
3388 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
3389 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
3390 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
3391 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
3392 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
3393 "3i5 >= -2i0 - i2 + 3i4 }";
3394 bset
= isl_basic_set_read_from_str(ctx
, str
);
3395 f
= isl_basic_set_factorizer(bset
);
3396 isl_basic_set_free(bset
);
3397 isl_factorizer_free(f
);
3399 isl_die(ctx
, isl_error_unknown
,
3400 "failed to construct factorizer", return -1);
3402 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
3403 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
3404 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
3405 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
3406 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
3407 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
3408 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
3409 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
3410 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
3411 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
3412 bset
= isl_basic_set_read_from_str(ctx
, str
);
3413 f
= isl_basic_set_factorizer(bset
);
3414 isl_basic_set_free(bset
);
3415 isl_factorizer_free(f
);
3417 isl_die(ctx
, isl_error_unknown
,
3418 "failed to construct factorizer", return -1);
3423 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
3425 int *injective
= user
;
3427 *injective
= isl_map_is_injective(map
);
3430 if (*injective
< 0 || !*injective
)
3431 return isl_stat_error
;
3436 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
3437 const char *r
, const char *s
, int tilable
, int parallel
)
3441 isl_union_map
*W
, *R
, *S
;
3442 isl_union_map
*empty
;
3443 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
3444 isl_union_map
*validity
, *proximity
, *coincidence
;
3445 isl_union_map
*schedule
;
3446 isl_union_map
*test
;
3447 isl_union_set
*delta
;
3448 isl_union_set
*domain
;
3452 isl_schedule_constraints
*sc
;
3453 isl_schedule
*sched
;
3454 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
3456 D
= isl_union_set_read_from_str(ctx
, d
);
3457 W
= isl_union_map_read_from_str(ctx
, w
);
3458 R
= isl_union_map_read_from_str(ctx
, r
);
3459 S
= isl_union_map_read_from_str(ctx
, s
);
3461 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
3462 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
3464 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
3465 isl_union_map_compute_flow(isl_union_map_copy(R
),
3466 isl_union_map_copy(W
), empty
,
3467 isl_union_map_copy(S
),
3468 &dep_raw
, NULL
, NULL
, NULL
);
3469 isl_union_map_compute_flow(isl_union_map_copy(W
),
3470 isl_union_map_copy(W
),
3471 isl_union_map_copy(R
),
3472 isl_union_map_copy(S
),
3473 &dep_waw
, &dep_war
, NULL
, NULL
);
3475 dep
= isl_union_map_union(dep_waw
, dep_war
);
3476 dep
= isl_union_map_union(dep
, dep_raw
);
3477 validity
= isl_union_map_copy(dep
);
3478 coincidence
= isl_union_map_copy(dep
);
3479 proximity
= isl_union_map_copy(dep
);
3481 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
3482 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3483 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
3484 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3485 sched
= isl_schedule_constraints_compute_schedule(sc
);
3486 schedule
= isl_schedule_get_map(sched
);
3487 isl_schedule_free(sched
);
3488 isl_union_map_free(W
);
3489 isl_union_map_free(R
);
3490 isl_union_map_free(S
);
3493 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
3495 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
3496 is_complete
= isl_union_set_is_subset(D
, domain
);
3497 isl_union_set_free(D
);
3498 isl_union_set_free(domain
);
3500 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
3501 test
= isl_union_map_apply_range(test
, dep
);
3502 test
= isl_union_map_apply_range(test
, schedule
);
3504 delta
= isl_union_map_deltas(test
);
3505 if (isl_union_set_n_set(delta
) == 0) {
3509 isl_union_set_free(delta
);
3511 delta_set
= isl_set_from_union_set(delta
);
3513 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3514 for (i
= 0; i
< tilable
; ++i
)
3515 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
3516 is_tilable
= isl_set_is_subset(delta_set
, slice
);
3517 isl_set_free(slice
);
3519 slice
= isl_set_universe(isl_set_get_space(delta_set
));
3520 for (i
= 0; i
< parallel
; ++i
)
3521 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
3522 is_parallel
= isl_set_is_subset(delta_set
, slice
);
3523 isl_set_free(slice
);
3525 origin
= isl_set_universe(isl_set_get_space(delta_set
));
3526 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
3527 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
3529 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
3530 delta_set
= isl_set_lexmin(delta_set
);
3532 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
3534 isl_set_free(origin
);
3535 isl_set_free(delta_set
);
3538 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
3539 is_injection
< 0 || is_complete
< 0)
3542 isl_die(ctx
, isl_error_unknown
,
3543 "generated schedule incomplete", return -1);
3545 isl_die(ctx
, isl_error_unknown
,
3546 "generated schedule not injective on each statement",
3549 isl_die(ctx
, isl_error_unknown
,
3550 "negative dependences in generated schedule",
3553 isl_die(ctx
, isl_error_unknown
,
3554 "generated schedule not as tilable as expected",
3557 isl_die(ctx
, isl_error_unknown
,
3558 "generated schedule not as parallel as expected",
3564 /* Compute a schedule for the given instance set, validity constraints,
3565 * proximity constraints and context and return a corresponding union map
3568 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
3569 const char *domain
, const char *validity
, const char *proximity
,
3570 const char *context
)
3575 isl_union_map
*prox
;
3576 isl_schedule_constraints
*sc
;
3577 isl_schedule
*schedule
;
3578 isl_union_map
*sched
;
3580 con
= isl_set_read_from_str(ctx
, context
);
3581 dom
= isl_union_set_read_from_str(ctx
, domain
);
3582 dep
= isl_union_map_read_from_str(ctx
, validity
);
3583 prox
= isl_union_map_read_from_str(ctx
, proximity
);
3584 sc
= isl_schedule_constraints_on_domain(dom
);
3585 sc
= isl_schedule_constraints_set_context(sc
, con
);
3586 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
3587 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
3588 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3589 sched
= isl_schedule_get_map(schedule
);
3590 isl_schedule_free(schedule
);
3595 /* Compute a schedule for the given instance set, validity constraints and
3596 * proximity constraints and return a corresponding union map representation.
3598 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
3599 const char *domain
, const char *validity
, const char *proximity
)
3601 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
3605 /* Check that a schedule can be constructed on the given domain
3606 * with the given validity and proximity constraints.
3608 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
3609 const char *validity
, const char *proximity
)
3611 isl_union_map
*sched
;
3613 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
3617 isl_union_map_free(sched
);
3621 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
3622 const char *validity
, const char *proximity
, const char *expected_sched
)
3624 isl_union_map
*sched1
, *sched2
;
3627 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
3628 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
3630 equal
= isl_union_map_is_equal(sched1
, sched2
);
3631 isl_union_map_free(sched1
);
3632 isl_union_map_free(sched2
);
3637 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
3643 /* Check that the schedule map is properly padded, even after being
3644 * reconstructed from the band forest.
3646 static int test_padded_schedule(isl_ctx
*ctx
)
3650 isl_union_map
*validity
, *proximity
;
3651 isl_schedule_constraints
*sc
;
3652 isl_schedule
*sched
;
3653 isl_union_map
*map1
, *map2
;
3654 isl_band_list
*list
;
3657 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
3658 D
= isl_union_set_read_from_str(ctx
, str
);
3659 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
3660 proximity
= isl_union_map_copy(validity
);
3661 sc
= isl_schedule_constraints_on_domain(D
);
3662 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3663 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3664 sched
= isl_schedule_constraints_compute_schedule(sc
);
3665 map1
= isl_schedule_get_map(sched
);
3666 list
= isl_schedule_get_band_forest(sched
);
3667 isl_band_list_free(list
);
3668 map2
= isl_schedule_get_map(sched
);
3669 isl_schedule_free(sched
);
3670 equal
= isl_union_map_is_equal(map1
, map2
);
3671 isl_union_map_free(map1
);
3672 isl_union_map_free(map2
);
3677 isl_die(ctx
, isl_error_unknown
,
3678 "reconstructed schedule map not the same as original",
3684 /* Check that conditional validity constraints are also taken into
3685 * account across bands.
3686 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
3687 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
3688 * and then check that the adjacent order constraint C[2,1]->D[2,0]
3689 * is enforced by the rest of the schedule.
3691 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
3694 isl_union_set
*domain
;
3695 isl_union_map
*validity
, *proximity
, *condition
;
3696 isl_union_map
*sink
, *source
, *dep
;
3697 isl_schedule_constraints
*sc
;
3698 isl_schedule
*schedule
;
3699 isl_union_access_info
*access
;
3700 isl_union_flow
*flow
;
3703 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3704 "A[k] : k >= 1 and k <= -1 + n; "
3705 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3706 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
3707 domain
= isl_union_set_read_from_str(ctx
, str
);
3708 sc
= isl_schedule_constraints_on_domain(domain
);
3709 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
3710 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3711 "D[k, i] -> C[1 + k, i] : "
3712 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3713 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
3714 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
3715 validity
= isl_union_map_read_from_str(ctx
, str
);
3716 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3717 str
= "[n] -> { C[k, i] -> D[k, i] : "
3718 "0 <= i <= -1 + k and k <= -1 + n }";
3719 proximity
= isl_union_map_read_from_str(ctx
, str
);
3720 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3721 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
3722 "i <= -1 + k and i >= 1 and k <= -2 + n; "
3723 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
3724 "k <= -1 + n and i >= 0 and i <= -2 + k }";
3725 condition
= isl_union_map_read_from_str(ctx
, str
);
3726 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
3727 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3728 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
3729 "i >= 0 and i <= -1 + k and k <= -1 + n and "
3730 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
3731 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
3732 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3733 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
3734 "k <= -1 + n and i >= 0 and i <= -1 + k and "
3735 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
3736 validity
= isl_union_map_read_from_str(ctx
, str
);
3737 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
3739 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3740 str
= "{ D[2,0] -> [] }";
3741 sink
= isl_union_map_read_from_str(ctx
, str
);
3742 access
= isl_union_access_info_from_sink(sink
);
3743 str
= "{ C[2,1] -> [] }";
3744 source
= isl_union_map_read_from_str(ctx
, str
);
3745 access
= isl_union_access_info_set_must_source(access
, source
);
3746 access
= isl_union_access_info_set_schedule(access
, schedule
);
3747 flow
= isl_union_access_info_compute_flow(access
);
3748 dep
= isl_union_flow_get_must_dependence(flow
);
3749 isl_union_flow_free(flow
);
3750 empty
= isl_union_map_is_empty(dep
);
3751 isl_union_map_free(dep
);
3756 isl_die(ctx
, isl_error_unknown
,
3757 "conditional validity not respected", return -1);
3762 /* Check that the test for violated conditional validity constraints
3763 * is not confused by domain compression.
3764 * In particular, earlier versions of isl would apply
3765 * a schedule on the compressed domains to the original domains,
3766 * resulting in a failure to detect that the default schedule
3767 * violates the conditional validity constraints.
3769 static int test_special_conditional_schedule_constraints_2(isl_ctx
*ctx
)
3773 isl_union_set
*domain
;
3774 isl_union_map
*validity
, *condition
;
3775 isl_schedule_constraints
*sc
;
3776 isl_schedule
*schedule
;
3777 isl_union_map
*umap
;
3780 str
= "{ A[0, i] : 0 <= i <= 10; B[1, i] : 0 <= i <= 10 }";
3781 domain
= isl_union_set_read_from_str(ctx
, str
);
3782 sc
= isl_schedule_constraints_on_domain(domain
);
3783 str
= "{ B[1, i] -> A[0, i + 1] }";
3784 condition
= isl_union_map_read_from_str(ctx
, str
);
3785 str
= "{ A[0, i] -> B[1, i - 1] }";
3786 validity
= isl_union_map_read_from_str(ctx
, str
);
3787 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
3788 isl_union_map_copy(validity
));
3789 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3790 umap
= isl_schedule_get_map(schedule
);
3791 isl_schedule_free(schedule
);
3792 validity
= isl_union_map_apply_domain(validity
,
3793 isl_union_map_copy(umap
));
3794 validity
= isl_union_map_apply_range(validity
, umap
);
3795 map
= isl_map_from_union_map(validity
);
3796 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
3797 map
= isl_map_intersect(map
, ge
);
3798 empty
= isl_map_is_empty(map
);
3804 isl_die(ctx
, isl_error_unknown
,
3805 "conditional validity constraints not satisfied",
3811 /* Input for testing of schedule construction based on
3812 * conditional constraints.
3814 * domain is the iteration domain
3815 * flow are the flow dependences, which determine the validity and
3816 * proximity constraints
3817 * condition are the conditions on the conditional validity constraints
3818 * conditional_validity are the conditional validity constraints
3819 * outer_band_n is the expected number of members in the outer band
3824 const char *condition
;
3825 const char *conditional_validity
;
3827 } live_range_tests
[] = {
3828 /* Contrived example that illustrates that we need to keep
3829 * track of tagged condition dependences and
3830 * tagged conditional validity dependences
3831 * in isl_sched_edge separately.
3832 * In particular, the conditional validity constraints on A
3833 * cannot be satisfied,
3834 * but they can be ignored because there are no corresponding
3835 * condition constraints. However, we do have an additional
3836 * conditional validity constraint that maps to the same
3837 * dependence relation
3838 * as the condition constraint on B. If we did not make a distinction
3839 * between tagged condition and tagged conditional validity
3840 * dependences, then we
3841 * could end up treating this shared dependence as an condition
3842 * constraint on A, forcing a localization of the conditions,
3843 * which is impossible.
3845 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
3846 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
3847 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
3848 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3849 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3850 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
3853 /* TACO 2013 Fig. 7 */
3854 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
3855 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3856 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3857 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
3858 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
3859 "0 <= i < n and 0 <= j < n - 1 }",
3860 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
3861 "0 <= i < n and 0 <= j < j' < n;"
3862 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
3863 "0 <= i < i' < n and 0 <= j,j' < n;"
3864 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
3865 "0 <= i,j,j' < n and j < j' }",
3868 /* TACO 2013 Fig. 7, without tags */
3869 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
3870 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3871 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3872 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3873 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3874 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
3875 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
3876 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
3879 /* TACO 2013 Fig. 12 */
3880 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
3881 "S3[i,3] : 0 <= i <= 1 }",
3882 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
3883 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
3884 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
3885 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
3886 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
3887 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
3888 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
3889 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
3890 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
3891 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
3892 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
3897 /* Test schedule construction based on conditional constraints.
3898 * In particular, check the number of members in the outer band node
3899 * as an indication of whether tiling is possible or not.
3901 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
3904 isl_union_set
*domain
;
3905 isl_union_map
*condition
;
3906 isl_union_map
*flow
;
3907 isl_union_map
*validity
;
3908 isl_schedule_constraints
*sc
;
3909 isl_schedule
*schedule
;
3910 isl_schedule_node
*node
;
3913 if (test_special_conditional_schedule_constraints(ctx
) < 0)
3915 if (test_special_conditional_schedule_constraints_2(ctx
) < 0)
3918 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
3919 domain
= isl_union_set_read_from_str(ctx
,
3920 live_range_tests
[i
].domain
);
3921 flow
= isl_union_map_read_from_str(ctx
,
3922 live_range_tests
[i
].flow
);
3923 condition
= isl_union_map_read_from_str(ctx
,
3924 live_range_tests
[i
].condition
);
3925 validity
= isl_union_map_read_from_str(ctx
,
3926 live_range_tests
[i
].conditional_validity
);
3927 sc
= isl_schedule_constraints_on_domain(domain
);
3928 sc
= isl_schedule_constraints_set_validity(sc
,
3929 isl_union_map_copy(flow
));
3930 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
3931 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
3932 condition
, validity
);
3933 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3934 node
= isl_schedule_get_root(schedule
);
3936 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
3937 node
= isl_schedule_node_first_child(node
);
3938 n_member
= isl_schedule_node_band_n_member(node
);
3939 isl_schedule_node_free(node
);
3940 isl_schedule_free(schedule
);
3944 if (n_member
!= live_range_tests
[i
].outer_band_n
)
3945 isl_die(ctx
, isl_error_unknown
,
3946 "unexpected number of members in outer band",
3952 /* Check that the schedule computed for the given instance set and
3953 * dependence relation strongly satisfies the dependences.
3954 * In particular, check that no instance is scheduled before
3955 * or together with an instance on which it depends.
3956 * Earlier versions of isl would produce a schedule that
3957 * only weakly satisfies the dependences.
3959 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
3961 const char *domain
, *dep
;
3962 isl_union_map
*D
, *schedule
;
3966 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
3967 "A[i0] : 0 <= i0 <= 1 }";
3968 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
3969 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
3970 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
3971 D
= isl_union_map_read_from_str(ctx
, dep
);
3972 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
3973 D
= isl_union_map_apply_range(D
, schedule
);
3974 map
= isl_map_from_union_map(D
);
3975 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
3976 map
= isl_map_intersect(map
, ge
);
3977 empty
= isl_map_is_empty(map
);
3983 isl_die(ctx
, isl_error_unknown
,
3984 "dependences not strongly satisfied", return -1);
3989 /* Compute a schedule for input where the instance set constraints
3990 * conflict with the context constraints.
3991 * Earlier versions of isl did not properly handle this situation.
3993 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
3995 isl_union_map
*schedule
;
3996 const char *domain
, *context
;
3998 domain
= "[n] -> { A[] : n >= 0 }";
3999 context
= "[n] -> { : n < 0 }";
4000 schedule
= compute_schedule_with_context(ctx
,
4001 domain
, "{}", "{}", context
);
4002 isl_union_map_free(schedule
);
4010 /* Check that the dependence carrying step is not confused by
4011 * a bound on the coefficient size.
4012 * In particular, force the scheduler to move to a dependence carrying
4013 * step by demanding outer coincidence and bound the size of
4014 * the coefficients. Earlier versions of isl would take this
4015 * bound into account while carrying dependences, breaking
4016 * fundamental assumptions.
4017 * On the other hand, the dependence carrying step now tries
4018 * to prevent loop coalescing by default, so check that indeed
4019 * no loop coalescing occurs by comparing the computed schedule
4020 * to the expected non-coalescing schedule.
4022 static int test_bounded_coefficients_schedule(isl_ctx
*ctx
)
4024 const char *domain
, *dep
;
4027 isl_schedule_constraints
*sc
;
4028 isl_schedule
*schedule
;
4029 isl_union_map
*sched1
, *sched2
;
4032 domain
= "{ C[i0, i1] : 2 <= i0 <= 3999 and 0 <= i1 <= -1 + i0 }";
4033 dep
= "{ C[i0, i1] -> C[i0, 1 + i1] : i0 <= 3999 and i1 >= 0 and "
4035 "C[i0, -1 + i0] -> C[1 + i0, 0] : i0 <= 3998 and i0 >= 1 }";
4036 I
= isl_union_set_read_from_str(ctx
, domain
);
4037 D
= isl_union_map_read_from_str(ctx
, dep
);
4038 sc
= isl_schedule_constraints_on_domain(I
);
4039 sc
= isl_schedule_constraints_set_validity(sc
, isl_union_map_copy(D
));
4040 sc
= isl_schedule_constraints_set_coincidence(sc
, D
);
4041 isl_options_set_schedule_outer_coincidence(ctx
, 1);
4042 isl_options_set_schedule_max_coefficient(ctx
, 20);
4043 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4044 isl_options_set_schedule_max_coefficient(ctx
, -1);
4045 isl_options_set_schedule_outer_coincidence(ctx
, 0);
4046 sched1
= isl_schedule_get_map(schedule
);
4047 isl_schedule_free(schedule
);
4049 sched2
= isl_union_map_read_from_str(ctx
, "{ C[x,y] -> [x,y] }");
4050 equal
= isl_union_map_is_equal(sched1
, sched2
);
4051 isl_union_map_free(sched1
);
4052 isl_union_map_free(sched2
);
4057 isl_die(ctx
, isl_error_unknown
,
4058 "unexpected schedule", return -1);
4063 /* Check that the bounds on the coefficients are respected.
4064 * This function checks for a particular output schedule,
4065 * but the exact output is not important, only that it does
4066 * not contain any coefficients greater than 4.
4067 * It is, however, easier to check for a particular output.
4068 * This test is only run for the whole component scheduler
4069 * because the incremental scheduler produces a slightly different schedule.
4071 static int test_bounded_coefficients_schedule_whole(isl_ctx
*ctx
)
4073 const char *domain
, *dep
, *str
;
4076 isl_schedule_constraints
*sc
;
4077 isl_schedule
*schedule
;
4078 isl_union_map
*sched1
, *sched2
;
4081 domain
= "{ S_4[i, j, k] : 0 <= i < j <= 10 and 0 <= k <= 100; "
4082 "S_2[i, j] : 0 <= i < j <= 10; S_6[i, j] : 0 <= i < j <= 10 }";
4083 dep
= "{ S_2[0, j] -> S_4[0, j, 0] : 0 < j <= 10; "
4084 "S_4[0, j, 100] -> S_6[0, j] : 0 < j <= 10 }";
4085 I
= isl_union_set_read_from_str(ctx
, domain
);
4086 D
= isl_union_map_read_from_str(ctx
, dep
);
4087 sc
= isl_schedule_constraints_on_domain(I
);
4088 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4089 isl_options_set_schedule_max_constant_term(ctx
, 10);
4090 isl_options_set_schedule_max_coefficient(ctx
, 4);
4091 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4092 isl_options_set_schedule_max_coefficient(ctx
, -1);
4093 isl_options_set_schedule_max_constant_term(ctx
, -1);
4094 sched1
= isl_schedule_get_map(schedule
);
4095 isl_schedule_free(schedule
);
4097 str
= "{ S_4[i, j, k] -> [i, j, 10 - k, 1]; "
4098 "S_2[i, j] -> [0, i, j, 0]; S_6[i, j] -> [0, 10 + i, j, 2] }";
4099 sched2
= isl_union_map_read_from_str(ctx
, str
);
4100 equal
= isl_union_map_is_equal(sched1
, sched2
);
4101 isl_union_map_free(sched1
);
4102 isl_union_map_free(sched2
);
4107 isl_die(ctx
, isl_error_unknown
,
4108 "unexpected schedule", return -1);
4113 /* Check that a set of schedule constraints that only allow for
4114 * a coalescing schedule still produces a schedule even if the user
4115 * request a non-coalescing schedule. Earlier versions of isl
4116 * would not handle this case correctly.
4118 static int test_coalescing_schedule(isl_ctx
*ctx
)
4120 const char *domain
, *dep
;
4123 isl_schedule_constraints
*sc
;
4124 isl_schedule
*schedule
;
4125 int treat_coalescing
;
4127 domain
= "{ S[a, b] : 0 <= a <= 1 and 0 <= b <= 1 }";
4128 dep
= "{ S[a, b] -> S[a + b, 1 - b] }";
4129 I
= isl_union_set_read_from_str(ctx
, domain
);
4130 D
= isl_union_map_read_from_str(ctx
, dep
);
4131 sc
= isl_schedule_constraints_on_domain(I
);
4132 sc
= isl_schedule_constraints_set_validity(sc
, D
);
4133 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4134 isl_options_set_schedule_treat_coalescing(ctx
, 1);
4135 schedule
= isl_schedule_constraints_compute_schedule(sc
);
4136 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4137 isl_schedule_free(schedule
);
4143 /* Check that the scheduler does not perform any needless
4144 * compound skewing. Earlier versions of isl would compute
4145 * schedules in terms of transformed schedule coefficients and
4146 * would not accurately keep track of the sum of the original
4147 * schedule coefficients. It could then produce the schedule
4148 * S[t,i,j,k] -> [t, 2t + i, 2t + i + j, 2t + i + j + k]
4149 * for the input below instead of the schedule below.
4151 static int test_skewing_schedule(isl_ctx
*ctx
)
4153 const char *D
, *V
, *P
, *S
;
4155 D
= "[n] -> { S[t,i,j,k] : 0 <= t,i,j,k < n }";
4156 V
= "[n] -> { S[t,i,j,k] -> S[t+1,a,b,c] : 0 <= t,i,j,k,a,b,c < n and "
4157 "-2 <= a-i <= 2 and -1 <= a-i + b-j <= 1 and "
4158 "-1 <= a-i + b-j + c-k <= 1 }";
4160 S
= "{ S[t,i,j,k] -> [t, 2t + i, t + i + j, 2t + k] }";
4162 return test_special_schedule(ctx
, D
, V
, P
, S
);
4165 int test_schedule(isl_ctx
*ctx
)
4167 const char *D
, *W
, *R
, *V
, *P
, *S
;
4168 int max_coincidence
;
4169 int treat_coalescing
;
4171 /* Handle resulting schedule with zero bands. */
4172 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
4176 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
4177 W
= "{ S1[t,i] -> a[t,i] }";
4178 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
4179 "S1[t,i] -> a[t-1,i+1] }";
4180 S
= "{ S1[t,i] -> [t,i] }";
4181 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4184 /* Fig. 5 of CC2008 */
4185 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
4187 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
4188 "j >= 2 and j <= -1 + N }";
4189 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
4190 "j >= 2 and j <= -1 + N; "
4191 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
4192 "j >= 2 and j <= -1 + N }";
4193 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4194 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4197 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
4198 W
= "{ S1[i] -> a[i] }";
4199 R
= "{ S2[i] -> a[i+1] }";
4200 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4201 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4204 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
4205 W
= "{ S1[i] -> a[i] }";
4206 R
= "{ S2[i] -> a[9-i] }";
4207 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4208 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4211 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
4212 W
= "{ S1[i] -> a[i] }";
4213 R
= "[N] -> { S2[i] -> a[N-1-i] }";
4214 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
4215 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
4218 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
4219 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
4220 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
4221 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
4222 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4225 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4226 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
4227 R
= "{ S2[i,j] -> a[i-1,j] }";
4228 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4229 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4232 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
4233 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
4234 R
= "{ S2[i,j] -> a[i,j-1] }";
4235 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
4236 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4239 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
4240 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
4241 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
4242 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
4243 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
4244 "S_0[] -> [0, 0, 0] }";
4245 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
4247 ctx
->opt
->schedule_parametric
= 0;
4248 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4250 ctx
->opt
->schedule_parametric
= 1;
4252 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
4253 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
4254 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
4255 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
4256 "S4[i] -> a[i,N] }";
4257 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
4258 "S4[i] -> [4,i,0] }";
4259 max_coincidence
= isl_options_get_schedule_maximize_coincidence(ctx
);
4260 isl_options_set_schedule_maximize_coincidence(ctx
, 0);
4261 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
4263 isl_options_set_schedule_maximize_coincidence(ctx
, max_coincidence
);
4265 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
4266 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4268 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
4270 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
4272 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
4273 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4276 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
4277 " S_2[t] : t >= 0 and t <= -1 + N; "
4278 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
4280 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
4281 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
4282 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
4283 "i >= 0 and i <= -1 + N }";
4284 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
4285 "i >= 0 and i <= -1 + N; "
4286 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
4287 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
4288 " S_0[t] -> [0, t, 0] }";
4290 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
4292 ctx
->opt
->schedule_parametric
= 0;
4293 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4295 ctx
->opt
->schedule_parametric
= 1;
4297 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
4298 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
4299 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
4302 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
4303 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
4304 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
4305 "j >= 0 and j <= -1 + N; "
4306 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4307 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
4308 "j >= 0 and j <= -1 + N; "
4309 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
4310 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
4311 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4314 D
= "{ S_0[i] : i >= 0 }";
4315 W
= "{ S_0[i] -> a[i] : i >= 0 }";
4316 R
= "{ S_0[i] -> a[0] : i >= 0 }";
4317 S
= "{ S_0[i] -> [0, i, 0] }";
4318 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4321 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
4322 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
4323 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
4324 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
4325 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4328 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
4329 "k <= -1 + n and k >= 0 }";
4330 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
4331 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
4332 "k <= -1 + n and k >= 0; "
4333 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
4334 "k <= -1 + n and k >= 0; "
4335 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
4336 "k <= -1 + n and k >= 0 }";
4337 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
4338 ctx
->opt
->schedule_outer_coincidence
= 1;
4339 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
4341 ctx
->opt
->schedule_outer_coincidence
= 0;
4343 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
4344 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
4345 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
4346 "Stmt_for_body24[i0, i1, 1, 0]:"
4347 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
4348 "Stmt_for_body7[i0, i1, i2]:"
4349 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
4352 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
4353 "Stmt_for_body24[1, i1, i2, i3]:"
4354 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
4356 "Stmt_for_body24[0, i1, i2, i3] -> "
4357 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
4358 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
4360 "Stmt_for_body24[0, i1, i2, i3] ->"
4361 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
4362 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
4363 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
4364 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
4365 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
4366 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
4367 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
4368 "i1 <= 6 and i1 >= 0;"
4369 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
4370 "Stmt_for_body7[i0, i1, i2] -> "
4371 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
4372 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
4373 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
4374 "Stmt_for_body7[i0, i1, i2] -> "
4375 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
4376 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
4377 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
4380 treat_coalescing
= isl_options_get_schedule_treat_coalescing(ctx
);
4381 isl_options_set_schedule_treat_coalescing(ctx
, 0);
4382 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4384 isl_options_set_schedule_treat_coalescing(ctx
, treat_coalescing
);
4386 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
4387 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
4388 "j >= 1 and j <= 7;"
4389 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
4390 "j >= 1 and j <= 8 }";
4392 S
= "{ S_0[i, j] -> [i + j, i] }";
4393 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4394 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4396 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4398 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
4399 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
4400 "j >= 0 and j <= -1 + i }";
4401 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
4402 "i <= -1 + N and j >= 0;"
4403 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
4406 S
= "{ S_0[i, j] -> [i, j] }";
4407 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4408 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4410 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4412 /* Test both algorithms on a case with only proximity dependences. */
4413 D
= "{ S[i,j] : 0 <= i <= 10 }";
4415 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
4416 S
= "{ S[i, j] -> [j, i] }";
4417 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4418 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4420 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4421 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
4424 D
= "{ A[a]; B[] }";
4426 P
= "{ A[a] -> B[] }";
4427 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4430 if (test_padded_schedule(ctx
) < 0)
4433 /* Check that check for progress is not confused by rational
4436 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
4437 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
4439 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
4440 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
4442 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4443 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4445 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4447 /* Check that we allow schedule rows that are only non-trivial
4448 * on some full-dimensional domains.
4450 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
4451 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
4452 "S1[j] -> S2[1] : 0 <= j <= 1 }";
4454 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
4455 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
4457 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
4459 if (test_conditional_schedule_constraints(ctx
) < 0)
4462 if (test_strongly_satisfying_schedule(ctx
) < 0)
4465 if (test_conflicting_context_schedule(ctx
) < 0)
4468 if (test_bounded_coefficients_schedule(ctx
) < 0)
4470 if (test_coalescing_schedule(ctx
) < 0)
4472 if (test_skewing_schedule(ctx
) < 0)
4478 /* Perform scheduling tests using the whole component scheduler.
4480 static int test_schedule_whole(isl_ctx
*ctx
)
4485 whole
= isl_options_get_schedule_whole_component(ctx
);
4486 isl_options_set_schedule_whole_component(ctx
, 1);
4487 r
= test_schedule(ctx
);
4489 r
= test_bounded_coefficients_schedule_whole(ctx
);
4490 isl_options_set_schedule_whole_component(ctx
, whole
);
4495 /* Perform scheduling tests using the incremental scheduler.
4497 static int test_schedule_incremental(isl_ctx
*ctx
)
4502 whole
= isl_options_get_schedule_whole_component(ctx
);
4503 isl_options_set_schedule_whole_component(ctx
, 0);
4504 r
= test_schedule(ctx
);
4505 isl_options_set_schedule_whole_component(ctx
, whole
);
4510 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
4512 isl_union_map
*umap
;
4515 umap
= isl_union_map_read_from_str(ctx
, str
);
4516 test
= isl_union_map_plain_is_injective(umap
);
4517 isl_union_map_free(umap
);
4520 if (test
== injective
)
4523 isl_die(ctx
, isl_error_unknown
,
4524 "map not detected as injective", return -1);
4526 isl_die(ctx
, isl_error_unknown
,
4527 "map detected as injective", return -1);
4530 int test_injective(isl_ctx
*ctx
)
4534 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
4536 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
4538 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
4540 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
4542 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
4544 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
4546 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
4548 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
4551 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
4552 if (test_plain_injective(ctx
, str
, 1))
4554 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
4555 if (test_plain_injective(ctx
, str
, 0))
4561 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
4569 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
4570 equal
= isl_aff_plain_is_equal(aff
, aff2
);
4576 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
4580 equal
= aff_plain_is_equal(aff
, str
);
4584 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
4585 "result not as expected", return -1);
4590 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
4591 __isl_take isl_aff
*aff2
);
4593 ['+'] = { &isl_aff_add
},
4594 ['-'] = { &isl_aff_sub
},
4595 ['*'] = { &isl_aff_mul
},
4596 ['/'] = { &isl_aff_div
},
4604 } aff_bin_tests
[] = {
4605 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
4606 "{ [i] -> [2i] }" },
4607 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
4609 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
4610 "{ [i] -> [2i] }" },
4611 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
4612 "{ [i] -> [2i] }" },
4613 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
4614 "{ [i] -> [i/2] }" },
4615 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
4617 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
4618 "{ [i] -> [NaN] }" },
4619 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
4620 "{ [i] -> [NaN] }" },
4621 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
4622 "{ [i] -> [NaN] }" },
4623 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
4624 "{ [i] -> [NaN] }" },
4625 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
4626 "{ [i] -> [NaN] }" },
4627 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
4628 "{ [i] -> [NaN] }" },
4629 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
4630 "{ [i] -> [NaN] }" },
4631 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
4632 "{ [i] -> [NaN] }" },
4633 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
4634 "{ [i] -> [NaN] }" },
4635 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
4636 "{ [i] -> [NaN] }" },
4637 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
4638 "{ [i] -> [NaN] }" },
4639 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
4640 "{ [i] -> [NaN] }" },
4643 /* Perform some basic tests of binary operations on isl_aff objects.
4645 static int test_bin_aff(isl_ctx
*ctx
)
4648 isl_aff
*aff1
, *aff2
, *res
;
4649 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
4650 __isl_take isl_aff
*aff2
);
4653 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
4654 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
4655 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
4656 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
4657 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
4658 aff1
= fn(aff1
, aff2
);
4659 if (isl_aff_is_nan(res
))
4660 ok
= isl_aff_is_nan(aff1
);
4662 ok
= isl_aff_plain_is_equal(aff1
, res
);
4668 isl_die(ctx
, isl_error_unknown
,
4669 "unexpected result", return -1);
4676 __isl_give isl_pw_aff
*(*fn
)(__isl_take isl_pw_aff
*pa1
,
4677 __isl_take isl_pw_aff
*pa2
);
4678 } pw_aff_bin_op
[] = {
4679 ['m'] = { &isl_pw_aff_min
},
4680 ['M'] = { &isl_pw_aff_max
},
4683 /* Inputs for binary isl_pw_aff operation tests.
4684 * "arg1" and "arg2" are the two arguments, "op" identifies the operation
4685 * defined by pw_aff_bin_op, and "res" is the expected result.
4692 } pw_aff_bin_tests
[] = {
4693 { "{ [i] -> [i] }", 'm', "{ [i] -> [i] }",
4695 { "{ [i] -> [i] }", 'M', "{ [i] -> [i] }",
4697 { "{ [i] -> [i] }", 'm', "{ [i] -> [0] }",
4698 "{ [i] -> [i] : i <= 0; [i] -> [0] : i > 0 }" },
4699 { "{ [i] -> [i] }", 'M', "{ [i] -> [0] }",
4700 "{ [i] -> [i] : i >= 0; [i] -> [0] : i < 0 }" },
4701 { "{ [i] -> [i] }", 'm', "{ [i] -> [NaN] }",
4702 "{ [i] -> [NaN] }" },
4703 { "{ [i] -> [NaN] }", 'm', "{ [i] -> [i] }",
4704 "{ [i] -> [NaN] }" },
4707 /* Perform some basic tests of binary operations on isl_pw_aff objects.
4709 static int test_bin_pw_aff(isl_ctx
*ctx
)
4713 isl_pw_aff
*pa1
, *pa2
, *res
;
4715 for (i
= 0; i
< ARRAY_SIZE(pw_aff_bin_tests
); ++i
) {
4716 pa1
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg1
);
4717 pa2
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].arg2
);
4718 res
= isl_pw_aff_read_from_str(ctx
, pw_aff_bin_tests
[i
].res
);
4719 pa1
= pw_aff_bin_op
[pw_aff_bin_tests
[i
].op
].fn(pa1
, pa2
);
4720 if (isl_pw_aff_involves_nan(res
))
4721 ok
= isl_pw_aff_involves_nan(pa1
);
4723 ok
= isl_pw_aff_plain_is_equal(pa1
, res
);
4724 isl_pw_aff_free(pa1
);
4725 isl_pw_aff_free(res
);
4729 isl_die(ctx
, isl_error_unknown
,
4730 "unexpected result", return -1);
4737 __isl_give isl_union_pw_multi_aff
*(*fn
)(
4738 __isl_take isl_union_pw_multi_aff
*upma1
,
4739 __isl_take isl_union_pw_multi_aff
*upma2
);
4743 } upma_bin_tests
[] = {
4744 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
4745 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
4746 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
4747 "{ B[x] -> [2] : x >= 0 }",
4748 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
4749 { &isl_union_pw_multi_aff_pullback_union_pw_multi_aff
,
4750 "{ A[] -> B[0]; C[x] -> B[1] : x < 10; C[y] -> B[2] : y >= 10 }",
4751 "{ D[i] -> A[] : i < 0; D[i] -> C[i + 5] : i >= 0 }",
4752 "{ D[i] -> B[0] : i < 0; D[i] -> B[1] : 0 <= i < 5; "
4753 "D[i] -> B[2] : i >= 5 }" },
4754 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
4755 "{ B[x] -> C[2] : x > 0 }",
4756 "{ B[x] -> A[1] : x <= 0; B[x] -> C[2] : x > 0 }" },
4757 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
4758 "{ B[x] -> A[2] : x >= 0 }",
4759 "{ B[x] -> A[1] : x < 0; B[x] -> A[2] : x > 0; B[0] -> A[3] }" },
4762 /* Perform some basic tests of binary operations on
4763 * isl_union_pw_multi_aff objects.
4765 static int test_bin_upma(isl_ctx
*ctx
)
4768 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
4771 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
4772 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4773 upma_bin_tests
[i
].arg1
);
4774 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4775 upma_bin_tests
[i
].arg2
);
4776 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
4777 upma_bin_tests
[i
].res
);
4778 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
4779 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
4780 isl_union_pw_multi_aff_free(upma1
);
4781 isl_union_pw_multi_aff_free(res
);
4785 isl_die(ctx
, isl_error_unknown
,
4786 "unexpected result", return -1);
4793 __isl_give isl_union_pw_multi_aff
*(*fn
)(
4794 __isl_take isl_union_pw_multi_aff
*upma1
,
4795 __isl_take isl_union_pw_multi_aff
*upma2
);
4798 } upma_bin_fail_tests
[] = {
4799 { &isl_union_pw_multi_aff_union_add
, "{ B[x] -> A[1] : x <= 0 }",
4800 "{ B[x] -> C[2] : x >= 0 }" },
4803 /* Perform some basic tests of binary operations on
4804 * isl_union_pw_multi_aff objects that are expected to fail.
4806 static int test_bin_upma_fail(isl_ctx
*ctx
)
4809 isl_union_pw_multi_aff
*upma1
, *upma2
;
4812 on_error
= isl_options_get_on_error(ctx
);
4813 isl_options_set_on_error(ctx
, ISL_ON_ERROR_CONTINUE
);
4814 n
= ARRAY_SIZE(upma_bin_fail_tests
);
4815 for (i
= 0; i
< n
; ++i
) {
4816 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
4817 upma_bin_fail_tests
[i
].arg1
);
4818 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
4819 upma_bin_fail_tests
[i
].arg2
);
4820 upma1
= upma_bin_fail_tests
[i
].fn(upma1
, upma2
);
4821 isl_union_pw_multi_aff_free(upma1
);
4825 isl_options_set_on_error(ctx
, on_error
);
4827 isl_die(ctx
, isl_error_unknown
,
4828 "operation not expected to succeed", return -1);
4833 int test_aff(isl_ctx
*ctx
)
4838 isl_local_space
*ls
;
4842 if (test_bin_aff(ctx
) < 0)
4844 if (test_bin_pw_aff(ctx
) < 0)
4846 if (test_bin_upma(ctx
) < 0)
4848 if (test_bin_upma_fail(ctx
) < 0)
4851 space
= isl_space_set_alloc(ctx
, 0, 1);
4852 ls
= isl_local_space_from_space(space
);
4853 aff
= isl_aff_zero_on_domain(ls
);
4855 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
4856 aff
= isl_aff_scale_down_ui(aff
, 3);
4857 aff
= isl_aff_floor(aff
);
4858 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
4859 aff
= isl_aff_scale_down_ui(aff
, 2);
4860 aff
= isl_aff_floor(aff
);
4861 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
4864 set
= isl_set_read_from_str(ctx
, str
);
4865 aff
= isl_aff_gist(aff
, set
);
4867 aff
= isl_aff_add_constant_si(aff
, -16);
4868 zero
= isl_aff_plain_is_zero(aff
);
4874 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4876 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
4877 aff
= isl_aff_scale_down_ui(aff
, 64);
4878 aff
= isl_aff_floor(aff
);
4879 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
4887 /* Check that the computation below results in a single expression.
4888 * One or two expressions may result depending on which constraint
4889 * ends up being considered as redundant with respect to the other
4890 * constraints after the projection that is performed internally
4891 * by isl_set_dim_min.
4893 static int test_dim_max_1(isl_ctx
*ctx
)
4900 str
= "[n] -> { [a, b] : n >= 0 and 4a >= -4 + n and b >= 0 and "
4901 "-4a <= b <= 3 and b < n - 4a }";
4902 set
= isl_set_read_from_str(ctx
, str
);
4903 pa
= isl_set_dim_min(set
, 0);
4904 n
= isl_pw_aff_n_piece(pa
);
4905 isl_pw_aff_free(pa
);
4910 isl_die(ctx
, isl_error_unknown
, "expecting single expression",
4916 int test_dim_max(isl_ctx
*ctx
)
4920 isl_set
*set1
, *set2
;
4925 if (test_dim_max_1(ctx
) < 0)
4928 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
4929 set
= isl_set_read_from_str(ctx
, str
);
4930 pwaff
= isl_set_dim_max(set
, 0);
4931 set1
= isl_set_from_pw_aff(pwaff
);
4932 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
4933 set2
= isl_set_read_from_str(ctx
, str
);
4934 equal
= isl_set_is_equal(set1
, set2
);
4940 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4942 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
4943 set
= isl_set_read_from_str(ctx
, str
);
4944 pwaff
= isl_set_dim_max(set
, 0);
4945 set1
= isl_set_from_pw_aff(pwaff
);
4946 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
4947 set2
= isl_set_read_from_str(ctx
, str
);
4948 equal
= isl_set_is_equal(set1
, set2
);
4954 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4956 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
4957 set
= isl_set_read_from_str(ctx
, str
);
4958 pwaff
= isl_set_dim_max(set
, 0);
4959 set1
= isl_set_from_pw_aff(pwaff
);
4960 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
4961 set2
= isl_set_read_from_str(ctx
, str
);
4962 equal
= isl_set_is_equal(set1
, set2
);
4968 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4970 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
4971 "0 <= i < N and 0 <= j < M }";
4972 map
= isl_map_read_from_str(ctx
, str
);
4973 set
= isl_map_range(map
);
4975 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
4976 set1
= isl_set_from_pw_aff(pwaff
);
4977 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
4978 set2
= isl_set_read_from_str(ctx
, str
);
4979 equal
= isl_set_is_equal(set1
, set2
);
4983 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
4984 set1
= isl_set_from_pw_aff(pwaff
);
4985 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
4986 set2
= isl_set_read_from_str(ctx
, str
);
4987 if (equal
>= 0 && equal
)
4988 equal
= isl_set_is_equal(set1
, set2
);
4997 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4999 /* Check that solutions are properly merged. */
5000 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
5001 "c <= -1 + n - 4a - 2b and c >= -2b and "
5002 "4a >= -4 + n and c >= 0 }";
5003 set
= isl_set_read_from_str(ctx
, str
);
5004 pwaff
= isl_set_dim_min(set
, 2);
5005 set1
= isl_set_from_pw_aff(pwaff
);
5006 str
= "[n] -> { [(0)] : n >= 1 }";
5007 set2
= isl_set_read_from_str(ctx
, str
);
5008 equal
= isl_set_is_equal(set1
, set2
);
5015 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5017 /* Check that empty solution lie in the right space. */
5018 str
= "[n] -> { [t,a] : 1 = 0 }";
5019 set
= isl_set_read_from_str(ctx
, str
);
5020 pwaff
= isl_set_dim_max(set
, 0);
5021 set1
= isl_set_from_pw_aff(pwaff
);
5022 str
= "[n] -> { [t] : 1 = 0 }";
5023 set2
= isl_set_read_from_str(ctx
, str
);
5024 equal
= isl_set_is_equal(set1
, set2
);
5031 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5036 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
5038 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
5042 isl_pw_multi_aff
*pma2
;
5048 ctx
= isl_pw_multi_aff_get_ctx(pma
);
5049 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
5050 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
5051 isl_pw_multi_aff_free(pma2
);
5056 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
5057 * represented by "str".
5059 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
5064 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
5068 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
5069 "result not as expected", return -1);
5073 /* Basic test for isl_pw_multi_aff_product.
5075 * Check that multiple pieces are properly handled.
5077 static int test_product_pma(isl_ctx
*ctx
)
5081 isl_pw_multi_aff
*pma1
, *pma2
;
5083 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
5084 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
5085 str
= "{ C[] -> D[] }";
5086 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
5087 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
5088 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
5089 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
5090 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
5091 isl_pw_multi_aff_free(pma1
);
5098 int test_product(isl_ctx
*ctx
)
5102 isl_union_set
*uset1
, *uset2
;
5106 set
= isl_set_read_from_str(ctx
, str
);
5107 set
= isl_set_product(set
, isl_set_copy(set
));
5108 ok
= isl_set_is_wrapping(set
);
5113 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5116 uset1
= isl_union_set_read_from_str(ctx
, str
);
5117 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
5118 str
= "{ [[] -> []] }";
5119 uset2
= isl_union_set_read_from_str(ctx
, str
);
5120 ok
= isl_union_set_is_equal(uset1
, uset2
);
5121 isl_union_set_free(uset1
);
5122 isl_union_set_free(uset2
);
5126 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5128 if (test_product_pma(ctx
) < 0)
5134 /* Check that two sets are not considered disjoint just because
5135 * they have a different set of (named) parameters.
5137 static int test_disjoint(isl_ctx
*ctx
)
5140 isl_set
*set
, *set2
;
5143 str
= "[n] -> { [[]->[]] }";
5144 set
= isl_set_read_from_str(ctx
, str
);
5145 str
= "{ [[]->[]] }";
5146 set2
= isl_set_read_from_str(ctx
, str
);
5147 disjoint
= isl_set_is_disjoint(set
, set2
);
5153 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5158 /* Inputs for isl_pw_multi_aff_is_equal tests.
5159 * "f1" and "f2" are the two function that need to be compared.
5160 * "equal" is the expected result.
5166 } pma_equal_tests
[] = {
5167 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 1 }",
5168 "[N] -> { [0] : 0 <= N <= 1 }" },
5169 { 1, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
5170 "[N] -> { [0] : 0 <= N <= 1; [1] : N = 2 }" },
5171 { 0, "[N] -> { [floor(N/2)] : 0 <= N <= 2 }",
5172 "[N] -> { [0] : 0 <= N <= 1 }" },
5173 { 0, "{ [NaN] }", "{ [NaN] }" },
5176 int test_equal(isl_ctx
*ctx
)
5180 isl_set
*set
, *set2
;
5184 set
= isl_set_read_from_str(ctx
, str
);
5186 set2
= isl_set_read_from_str(ctx
, str
);
5187 equal
= isl_set_is_equal(set
, set2
);
5193 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5195 for (i
= 0; i
< ARRAY_SIZE(pma_equal_tests
); ++i
) {
5196 int expected
= pma_equal_tests
[i
].equal
;
5197 isl_pw_multi_aff
*f1
, *f2
;
5199 f1
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f1
);
5200 f2
= isl_pw_multi_aff_read_from_str(ctx
, pma_equal_tests
[i
].f2
);
5201 equal
= isl_pw_multi_aff_is_equal(f1
, f2
);
5202 isl_pw_multi_aff_free(f1
);
5203 isl_pw_multi_aff_free(f2
);
5206 if (equal
!= expected
)
5207 isl_die(ctx
, isl_error_unknown
,
5208 "unexpected equality result", return -1);
5214 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
5215 enum isl_dim_type type
, unsigned pos
, int fixed
)
5219 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
5226 isl_die(ctx
, isl_error_unknown
,
5227 "map not detected as fixed", return -1);
5229 isl_die(ctx
, isl_error_unknown
,
5230 "map detected as fixed", return -1);
5233 int test_fixed(isl_ctx
*ctx
)
5238 str
= "{ [i] -> [i] }";
5239 map
= isl_map_read_from_str(ctx
, str
);
5240 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
5242 str
= "{ [i] -> [1] }";
5243 map
= isl_map_read_from_str(ctx
, str
);
5244 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
5246 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
5247 map
= isl_map_read_from_str(ctx
, str
);
5248 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
5250 map
= isl_map_read_from_str(ctx
, str
);
5251 map
= isl_map_neg(map
);
5252 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
5258 struct isl_vertices_test_data
{
5261 const char *vertex
[6];
5262 } vertices_tests
[] = {
5263 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
5264 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
5265 { "{ A[t, i] : t = 14 and i = 1 }",
5266 1, { "{ A[14, 1] }" } },
5267 { "[n, m] -> { [a, b, c] : b <= a and a <= n and b > 0 and c >= b and "
5268 "c <= m and m <= n and m > 0 }",
5270 "[n, m] -> { [n, m, m] : 0 < m <= n }",
5271 "[n, m] -> { [n, 1, m] : 0 < m <= n }",
5272 "[n, m] -> { [n, 1, 1] : 0 < m <= n }",
5273 "[n, m] -> { [m, m, m] : 0 < m <= n }",
5274 "[n, m] -> { [1, 1, m] : 0 < m <= n }",
5275 "[n, m] -> { [1, 1, 1] : 0 < m <= n }"
5279 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
5281 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
5283 struct isl_vertices_test_data
*data
= user
;
5286 isl_basic_set
*bset
;
5287 isl_pw_multi_aff
*pma
;
5291 ctx
= isl_vertex_get_ctx(vertex
);
5292 bset
= isl_vertex_get_domain(vertex
);
5293 ma
= isl_vertex_get_expr(vertex
);
5294 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
5296 for (i
= 0; i
< data
->n
; ++i
) {
5297 isl_pw_multi_aff
*pma_i
;
5299 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
5300 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
5301 isl_pw_multi_aff_free(pma_i
);
5303 if (equal
< 0 || equal
)
5307 isl_pw_multi_aff_free(pma
);
5308 isl_vertex_free(vertex
);
5311 return isl_stat_error
;
5313 return equal
? isl_stat_ok
: isl_stat_error
;
5316 int test_vertices(isl_ctx
*ctx
)
5320 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
5321 isl_basic_set
*bset
;
5322 isl_vertices
*vertices
;
5326 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
5327 vertices
= isl_basic_set_compute_vertices(bset
);
5328 n
= isl_vertices_get_n_vertices(vertices
);
5329 if (vertices_tests
[i
].n
!= n
)
5331 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
5332 &vertices_tests
[i
]) < 0)
5334 isl_vertices_free(vertices
);
5335 isl_basic_set_free(bset
);
5340 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
5347 int test_union_pw(isl_ctx
*ctx
)
5351 isl_union_set
*uset
;
5352 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
5354 str
= "{ [x] -> x^2 }";
5355 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
5356 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
5357 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
5358 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
5359 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
5360 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
5361 isl_union_pw_qpolynomial_free(upwqp1
);
5362 isl_union_pw_qpolynomial_free(upwqp2
);
5366 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5371 /* Test that isl_union_pw_qpolynomial_eval picks up the function
5372 * defined over the correct domain space.
5374 static int test_eval_1(isl_ctx
*ctx
)
5379 isl_union_pw_qpolynomial
*upwqp
;
5383 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
5384 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
5386 set
= isl_set_read_from_str(ctx
, str
);
5387 pnt
= isl_set_sample_point(set
);
5388 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
5389 cmp
= isl_val_cmp_si(v
, 36);
5395 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
5400 /* Check that isl_qpolynomial_eval handles getting called on a void point.
5402 static int test_eval_2(isl_ctx
*ctx
)
5407 isl_qpolynomial
*qp
;
5411 str
= "{ A[x] -> [x] }";
5412 qp
= isl_qpolynomial_from_aff(isl_aff_read_from_str(ctx
, str
));
5413 str
= "{ A[x] : false }";
5414 set
= isl_set_read_from_str(ctx
, str
);
5415 pnt
= isl_set_sample_point(set
);
5416 v
= isl_qpolynomial_eval(qp
, pnt
);
5417 ok
= isl_val_is_nan(v
);
5423 isl_die(ctx
, isl_error_unknown
, "expecting NaN", return -1);
5428 /* Perform basic polynomial evaluation tests.
5430 static int test_eval(isl_ctx
*ctx
)
5432 if (test_eval_1(ctx
) < 0)
5434 if (test_eval_2(ctx
) < 0)
5439 /* Descriptions of sets that are tested for reparsing after printing.
5441 const char *output_tests
[] = {
5442 "{ [1, y] : 0 <= y <= 1; [x, -x] : 0 <= x <= 1 }",
5445 /* Check that printing a set and reparsing a set from the printed output
5446 * results in the same set.
5448 static int test_output_set(isl_ctx
*ctx
)
5452 isl_set
*set1
, *set2
;
5455 for (i
= 0; i
< ARRAY_SIZE(output_tests
); ++i
) {
5456 set1
= isl_set_read_from_str(ctx
, output_tests
[i
]);
5457 str
= isl_set_to_str(set1
);
5458 set2
= isl_set_read_from_str(ctx
, str
);
5460 equal
= isl_set_is_equal(set1
, set2
);
5466 isl_die(ctx
, isl_error_unknown
,
5467 "parsed output not the same", return -1);
5473 int test_output(isl_ctx
*ctx
)
5481 if (test_output_set(ctx
) < 0)
5484 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
5485 pa
= isl_pw_aff_read_from_str(ctx
, str
);
5487 p
= isl_printer_to_str(ctx
);
5488 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
5489 p
= isl_printer_print_pw_aff(p
, pa
);
5490 s
= isl_printer_get_str(p
);
5491 isl_printer_free(p
);
5492 isl_pw_aff_free(pa
);
5496 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
5501 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
5506 int test_sample(isl_ctx
*ctx
)
5509 isl_basic_set
*bset1
, *bset2
;
5512 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
5513 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
5514 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
5515 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
5516 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
5517 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
5518 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
5519 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
5520 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
5521 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
5522 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
5523 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
5524 "d - 1073741821e and "
5525 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
5526 "3j >= 1 - a + b + 2e and "
5527 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
5528 "3i <= 4 - a + 4b - e and "
5529 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
5530 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
5531 "c <= -1 + a and 3i >= -2 - a + 3e and "
5532 "1073741822e <= 1073741823 - a + 1073741822b + c and "
5533 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
5534 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
5535 "1073741823e >= 1 + 1073741823b - d and "
5536 "3i >= 1073741823b + c - 1073741823e - f and "
5537 "3i >= 1 + 2b + e + 3g }";
5538 bset1
= isl_basic_set_read_from_str(ctx
, str
);
5539 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
5540 empty
= isl_basic_set_is_empty(bset2
);
5541 subset
= isl_basic_set_is_subset(bset2
, bset1
);
5542 isl_basic_set_free(bset1
);
5543 isl_basic_set_free(bset2
);
5544 if (empty
< 0 || subset
< 0)
5547 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
5549 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
5554 int test_fixed_power(isl_ctx
*ctx
)
5562 str
= "{ [i] -> [i + 1] }";
5563 map
= isl_map_read_from_str(ctx
, str
);
5564 isl_int_set_si(exp
, 23);
5565 map
= isl_map_fixed_power(map
, exp
);
5566 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
5575 int test_slice(isl_ctx
*ctx
)
5581 str
= "{ [i] -> [j] }";
5582 map
= isl_map_read_from_str(ctx
, str
);
5583 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
5584 equal
= map_check_equal(map
, "{ [i] -> [i] }");
5589 str
= "{ [i] -> [j] }";
5590 map
= isl_map_read_from_str(ctx
, str
);
5591 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
5592 equal
= map_check_equal(map
, "{ [i] -> [j] }");
5597 str
= "{ [i] -> [j] }";
5598 map
= isl_map_read_from_str(ctx
, str
);
5599 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
5600 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
5605 str
= "{ [i] -> [j] }";
5606 map
= isl_map_read_from_str(ctx
, str
);
5607 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
5608 equal
= map_check_equal(map
, "{ [0] -> [j] }");
5613 str
= "{ [i] -> [j] }";
5614 map
= isl_map_read_from_str(ctx
, str
);
5615 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
5616 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
5621 str
= "{ [i] -> [j] }";
5622 map
= isl_map_read_from_str(ctx
, str
);
5623 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
5624 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
5632 int test_eliminate(isl_ctx
*ctx
)
5638 str
= "{ [i] -> [j] : i = 2j }";
5639 map
= isl_map_read_from_str(ctx
, str
);
5640 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
5641 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
5649 /* Check that isl_set_dim_residue_class detects that the values of j
5650 * in the set below are all odd and that it does not detect any spurious
5653 static int test_residue_class(isl_ctx
*ctx
)
5660 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
5661 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
5662 set
= isl_set_read_from_str(ctx
, str
);
5665 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
5667 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
5668 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
5669 res
= isl_stat_error
);
5677 int test_align_parameters(isl_ctx
*ctx
)
5681 isl_multi_aff
*ma1
, *ma2
;
5684 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
5685 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
5687 space
= isl_space_params_alloc(ctx
, 1);
5688 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
5689 ma1
= isl_multi_aff_align_params(ma1
, space
);
5691 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
5692 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
5694 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
5696 isl_multi_aff_free(ma1
);
5697 isl_multi_aff_free(ma2
);
5702 isl_die(ctx
, isl_error_unknown
,
5703 "result not as expected", return -1);
5708 static int test_list(isl_ctx
*ctx
)
5710 isl_id
*a
, *b
, *c
, *d
, *id
;
5714 a
= isl_id_alloc(ctx
, "a", NULL
);
5715 b
= isl_id_alloc(ctx
, "b", NULL
);
5716 c
= isl_id_alloc(ctx
, "c", NULL
);
5717 d
= isl_id_alloc(ctx
, "d", NULL
);
5719 list
= isl_id_list_alloc(ctx
, 4);
5720 list
= isl_id_list_add(list
, b
);
5721 list
= isl_id_list_insert(list
, 0, a
);
5722 list
= isl_id_list_add(list
, c
);
5723 list
= isl_id_list_add(list
, d
);
5724 list
= isl_id_list_drop(list
, 1, 1);
5726 if (isl_id_list_n_id(list
) != 3) {
5727 isl_id_list_free(list
);
5728 isl_die(ctx
, isl_error_unknown
,
5729 "unexpected number of elements in list", return -1);
5732 id
= isl_id_list_get_id(list
, 0);
5735 id
= isl_id_list_get_id(list
, 1);
5738 id
= isl_id_list_get_id(list
, 2);
5742 isl_id_list_free(list
);
5745 isl_die(ctx
, isl_error_unknown
,
5746 "unexpected elements in list", return -1);
5751 const char *set_conversion_tests
[] = {
5752 "[N] -> { [i] : N - 1 <= 2 i <= N }",
5753 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
5754 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
5755 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
5756 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
5757 "[a, b] -> { [c, d] : (4*floor((-a + c)/4) = -a + c and "
5758 "32*floor((-b + d)/32) = -b + d and 5 <= c <= 8 and "
5759 "-3 + c <= d <= 28 + c) }",
5762 /* Check that converting from isl_set to isl_pw_multi_aff and back
5763 * to isl_set produces the original isl_set.
5765 static int test_set_conversion(isl_ctx
*ctx
)
5769 isl_set
*set1
, *set2
;
5770 isl_pw_multi_aff
*pma
;
5773 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
5774 str
= set_conversion_tests
[i
];
5775 set1
= isl_set_read_from_str(ctx
, str
);
5776 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
5777 set2
= isl_set_from_pw_multi_aff(pma
);
5778 equal
= isl_set_is_equal(set1
, set2
);
5785 isl_die(ctx
, isl_error_unknown
, "bad conversion",
5792 const char *conversion_tests
[] = {
5793 "{ [a, b, c, d] -> s0[a, b, e, f] : "
5794 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
5795 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
5796 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
5798 "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): "
5799 "5e0 = -a - b + c and c >= -a and c <= 4 - a) }",
5800 "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }",
5803 /* Check that converting from isl_map to isl_pw_multi_aff and back
5804 * to isl_map produces the original isl_map.
5806 static int test_map_conversion(isl_ctx
*ctx
)
5809 isl_map
*map1
, *map2
;
5810 isl_pw_multi_aff
*pma
;
5813 for (i
= 0; i
< ARRAY_SIZE(conversion_tests
); ++i
) {
5814 map1
= isl_map_read_from_str(ctx
, conversion_tests
[i
]);
5815 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
5816 map2
= isl_map_from_pw_multi_aff(pma
);
5817 equal
= isl_map_is_equal(map1
, map2
);
5824 isl_die(ctx
, isl_error_unknown
, "bad conversion",
5831 static int test_conversion(isl_ctx
*ctx
)
5833 if (test_set_conversion(ctx
) < 0)
5835 if (test_map_conversion(ctx
) < 0)
5840 /* Check that isl_basic_map_curry does not modify input.
5842 static int test_curry(isl_ctx
*ctx
)
5845 isl_basic_map
*bmap1
, *bmap2
;
5848 str
= "{ [A[] -> B[]] -> C[] }";
5849 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
5850 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
5851 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
5852 isl_basic_map_free(bmap1
);
5853 isl_basic_map_free(bmap2
);
5858 isl_die(ctx
, isl_error_unknown
,
5859 "curried map should not be equal to original",
5869 } preimage_tests
[] = {
5870 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
5871 "{ A[j,i] -> B[i,j] }",
5872 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
5873 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
5874 "{ A[a,b] -> B[a/2,b/6] }",
5875 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
5876 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
5877 "{ A[a,b] -> B[a/2,b/6] }",
5878 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
5879 "exists i,j : a = 2 i and b = 6 j }" },
5880 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
5881 "[n] -> { : 0 <= n <= 100 }" },
5882 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
5883 "{ A[a] -> B[2a] }",
5884 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
5885 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
5886 "{ A[a] -> B[([a/2])] }",
5887 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
5888 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
5889 "{ A[a] -> B[a,a,a/3] }",
5890 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
5891 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
5892 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
5895 static int test_preimage_basic_set(isl_ctx
*ctx
)
5898 isl_basic_set
*bset1
, *bset2
;
5902 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
5903 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
5904 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
5905 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
5906 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
5907 equal
= isl_basic_set_is_equal(bset1
, bset2
);
5908 isl_basic_set_free(bset1
);
5909 isl_basic_set_free(bset2
);
5913 isl_die(ctx
, isl_error_unknown
, "bad preimage",
5924 } preimage_domain_tests
[] = {
5925 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
5926 "{ A[j,i] -> B[i,j] }",
5927 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
5928 { "{ B[i] -> C[i]; D[i] -> E[i] }",
5929 "{ A[i] -> B[i + 1] }",
5930 "{ A[i] -> C[i + 1] }" },
5931 { "{ B[i] -> C[i]; B[i] -> E[i] }",
5932 "{ A[i] -> B[i + 1] }",
5933 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
5934 { "{ B[i] -> C[([i/2])] }",
5935 "{ A[i] -> B[2i] }",
5936 "{ A[i] -> C[i] }" },
5937 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
5938 "{ A[i] -> B[([i/5]), ([i/7])] }",
5939 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
5940 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
5941 "[N] -> { A[] -> B[([N/5])] }",
5942 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
5943 { "{ B[i] -> C[i] : exists a : i = 5 a }",
5944 "{ A[i] -> B[2i] }",
5945 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
5946 { "{ B[i] -> C[i] : exists a : i = 2 a; "
5947 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
5948 "{ A[i] -> B[2i] }",
5949 "{ A[i] -> C[2i] }" },
5950 { "{ A[i] -> B[i] }", "{ C[i] -> A[(i + floor(i/3))/2] }",
5951 "{ C[i] -> B[j] : 2j = i + floor(i/3) }" },
5954 static int test_preimage_union_map(isl_ctx
*ctx
)
5957 isl_union_map
*umap1
, *umap2
;
5961 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
5962 umap1
= isl_union_map_read_from_str(ctx
,
5963 preimage_domain_tests
[i
].map
);
5964 ma
= isl_multi_aff_read_from_str(ctx
,
5965 preimage_domain_tests
[i
].ma
);
5966 umap2
= isl_union_map_read_from_str(ctx
,
5967 preimage_domain_tests
[i
].res
);
5968 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
5969 equal
= isl_union_map_is_equal(umap1
, umap2
);
5970 isl_union_map_free(umap1
);
5971 isl_union_map_free(umap2
);
5975 isl_die(ctx
, isl_error_unknown
, "bad preimage",
5982 static int test_preimage(isl_ctx
*ctx
)
5984 if (test_preimage_basic_set(ctx
) < 0)
5986 if (test_preimage_union_map(ctx
) < 0)
5996 } pullback_tests
[] = {
5997 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
5998 "{ A[a,b] -> C[b + 2a] }" },
5999 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
6000 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
6001 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
6002 "{ A[a] -> C[(a)/6] }" },
6003 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
6004 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
6005 "{ A[a] -> C[(2a)/3] }" },
6006 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
6007 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
6008 "{ A[i,j] -> C[i + j, i + j] }"},
6009 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
6010 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
6011 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
6012 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
6013 "{ [i, j] -> [floor((i)/3), j] }",
6014 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
6017 static int test_pullback(isl_ctx
*ctx
)
6020 isl_multi_aff
*ma1
, *ma2
;
6024 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
6025 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
6026 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
6027 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
6028 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
6029 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
6030 isl_multi_aff_free(ma1
);
6031 isl_multi_aff_free(ma2
);
6035 isl_die(ctx
, isl_error_unknown
, "bad pullback",
6042 /* Check that negation is printed correctly and that equal expressions
6043 * are correctly identified.
6045 static int test_ast(isl_ctx
*ctx
)
6047 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
6051 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
6052 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
6053 expr
= isl_ast_expr_add(expr1
, expr2
);
6054 expr2
= isl_ast_expr_copy(expr
);
6055 expr
= isl_ast_expr_neg(expr
);
6056 expr2
= isl_ast_expr_neg(expr2
);
6057 equal
= isl_ast_expr_is_equal(expr
, expr2
);
6058 str
= isl_ast_expr_to_C_str(expr
);
6059 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
6061 isl_ast_expr_free(expr
);
6062 isl_ast_expr_free(expr2
);
6064 if (ok
< 0 || equal
< 0)
6067 isl_die(ctx
, isl_error_unknown
,
6068 "equal expressions not considered equal", return -1);
6070 isl_die(ctx
, isl_error_unknown
,
6071 "isl_ast_expr printed incorrectly", return -1);
6073 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
6074 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
6075 expr
= isl_ast_expr_add(expr1
, expr2
);
6076 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
6077 expr
= isl_ast_expr_sub(expr3
, expr
);
6078 str
= isl_ast_expr_to_C_str(expr
);
6079 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
6081 isl_ast_expr_free(expr
);
6086 isl_die(ctx
, isl_error_unknown
,
6087 "isl_ast_expr printed incorrectly", return -1);
6092 /* Check that isl_ast_build_expr_from_set returns a valid expression
6093 * for an empty set. Note that isl_ast_build_expr_from_set getting
6094 * called on an empty set probably indicates a bug in the caller.
6096 static int test_ast_build(isl_ctx
*ctx
)
6099 isl_ast_build
*build
;
6102 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6103 build
= isl_ast_build_from_context(set
);
6105 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
6106 expr
= isl_ast_build_expr_from_set(build
, set
);
6108 isl_ast_expr_free(expr
);
6109 isl_ast_build_free(build
);
6117 /* Internal data structure for before_for and after_for callbacks.
6119 * depth is the current depth
6120 * before is the number of times before_for has been called
6121 * after is the number of times after_for has been called
6123 struct isl_test_codegen_data
{
6129 /* This function is called before each for loop in the AST generated
6130 * from test_ast_gen1.
6132 * Increment the number of calls and the depth.
6133 * Check that the space returned by isl_ast_build_get_schedule_space
6134 * matches the target space of the schedule returned by
6135 * isl_ast_build_get_schedule.
6136 * Return an isl_id that is checked by the corresponding call
6139 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
6142 struct isl_test_codegen_data
*data
= user
;
6145 isl_union_map
*schedule
;
6146 isl_union_set
*uset
;
6151 ctx
= isl_ast_build_get_ctx(build
);
6153 if (data
->before
>= 3)
6154 isl_die(ctx
, isl_error_unknown
,
6155 "unexpected number of for nodes", return NULL
);
6156 if (data
->depth
>= 2)
6157 isl_die(ctx
, isl_error_unknown
,
6158 "unexpected depth", return NULL
);
6160 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
6164 schedule
= isl_ast_build_get_schedule(build
);
6165 uset
= isl_union_map_range(schedule
);
6168 if (isl_union_set_n_set(uset
) != 1) {
6169 isl_union_set_free(uset
);
6170 isl_die(ctx
, isl_error_unknown
,
6171 "expecting single range space", return NULL
);
6174 space
= isl_ast_build_get_schedule_space(build
);
6175 set
= isl_union_set_extract_set(uset
, space
);
6176 isl_union_set_free(uset
);
6177 empty
= isl_set_is_empty(set
);
6183 isl_die(ctx
, isl_error_unknown
,
6184 "spaces don't match", return NULL
);
6186 return isl_id_alloc(ctx
, name
, NULL
);
6189 /* This function is called after each for loop in the AST generated
6190 * from test_ast_gen1.
6192 * Increment the number of calls and decrement the depth.
6193 * Check that the annotation attached to the node matches
6194 * the isl_id returned by the corresponding call to before_for.
6196 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
6197 __isl_keep isl_ast_build
*build
, void *user
)
6199 struct isl_test_codegen_data
*data
= user
;
6207 if (data
->after
> data
->before
)
6208 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
6209 "mismatch in number of for nodes",
6210 return isl_ast_node_free(node
));
6212 id
= isl_ast_node_get_annotation(node
);
6214 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
6215 "missing annotation", return isl_ast_node_free(node
));
6217 name
= isl_id_get_name(id
);
6218 valid
= name
&& atoi(name
+ 1) == data
->depth
;
6222 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
6223 "wrong annotation", return isl_ast_node_free(node
));
6228 /* Check that the before_each_for and after_each_for callbacks
6229 * are called for each for loop in the generated code,
6230 * that they are called in the right order and that the isl_id
6231 * returned from the before_each_for callback is attached to
6232 * the isl_ast_node passed to the corresponding after_each_for call.
6234 static int test_ast_gen1(isl_ctx
*ctx
)
6238 isl_union_map
*schedule
;
6239 isl_ast_build
*build
;
6241 struct isl_test_codegen_data data
;
6243 str
= "[N] -> { : N >= 10 }";
6244 set
= isl_set_read_from_str(ctx
, str
);
6245 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
6246 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
6247 schedule
= isl_union_map_read_from_str(ctx
, str
);
6252 build
= isl_ast_build_from_context(set
);
6253 build
= isl_ast_build_set_before_each_for(build
,
6254 &before_for
, &data
);
6255 build
= isl_ast_build_set_after_each_for(build
,
6257 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6258 isl_ast_build_free(build
);
6262 isl_ast_node_free(tree
);
6264 if (data
.before
!= 3 || data
.after
!= 3)
6265 isl_die(ctx
, isl_error_unknown
,
6266 "unexpected number of for nodes", return -1);
6271 /* Check that the AST generator handles domains that are integrally disjoint
6272 * but not rationally disjoint.
6274 static int test_ast_gen2(isl_ctx
*ctx
)
6278 isl_union_map
*schedule
;
6279 isl_union_map
*options
;
6280 isl_ast_build
*build
;
6283 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
6284 schedule
= isl_union_map_read_from_str(ctx
, str
);
6285 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6286 build
= isl_ast_build_from_context(set
);
6288 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
6289 options
= isl_union_map_read_from_str(ctx
, str
);
6290 build
= isl_ast_build_set_options(build
, options
);
6291 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6292 isl_ast_build_free(build
);
6295 isl_ast_node_free(tree
);
6300 /* Increment *user on each call.
6302 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
6303 __isl_keep isl_ast_build
*build
, void *user
)
6312 /* Test that unrolling tries to minimize the number of instances.
6313 * In particular, for the schedule given below, make sure it generates
6314 * 3 nodes (rather than 101).
6316 static int test_ast_gen3(isl_ctx
*ctx
)
6320 isl_union_map
*schedule
;
6321 isl_union_map
*options
;
6322 isl_ast_build
*build
;
6326 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
6327 schedule
= isl_union_map_read_from_str(ctx
, str
);
6328 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6330 str
= "{ [i] -> unroll[0] }";
6331 options
= isl_union_map_read_from_str(ctx
, str
);
6333 build
= isl_ast_build_from_context(set
);
6334 build
= isl_ast_build_set_options(build
, options
);
6335 build
= isl_ast_build_set_at_each_domain(build
,
6336 &count_domains
, &n_domain
);
6337 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6338 isl_ast_build_free(build
);
6342 isl_ast_node_free(tree
);
6345 isl_die(ctx
, isl_error_unknown
,
6346 "unexpected number of for nodes", return -1);
6351 /* Check that if the ast_build_exploit_nested_bounds options is set,
6352 * we do not get an outer if node in the generated AST,
6353 * while we do get such an outer if node if the options is not set.
6355 static int test_ast_gen4(isl_ctx
*ctx
)
6359 isl_union_map
*schedule
;
6360 isl_ast_build
*build
;
6362 enum isl_ast_node_type type
;
6365 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
6366 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
6368 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
6370 schedule
= isl_union_map_read_from_str(ctx
, str
);
6371 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6372 build
= isl_ast_build_from_context(set
);
6373 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6374 isl_ast_build_free(build
);
6378 type
= isl_ast_node_get_type(tree
);
6379 isl_ast_node_free(tree
);
6381 if (type
== isl_ast_node_if
)
6382 isl_die(ctx
, isl_error_unknown
,
6383 "not expecting if node", return -1);
6385 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
6387 schedule
= isl_union_map_read_from_str(ctx
, str
);
6388 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6389 build
= isl_ast_build_from_context(set
);
6390 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6391 isl_ast_build_free(build
);
6395 type
= isl_ast_node_get_type(tree
);
6396 isl_ast_node_free(tree
);
6398 if (type
!= isl_ast_node_if
)
6399 isl_die(ctx
, isl_error_unknown
,
6400 "expecting if node", return -1);
6402 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
6407 /* This function is called for each leaf in the AST generated
6408 * from test_ast_gen5.
6410 * We finalize the AST generation by extending the outer schedule
6411 * with a zero-dimensional schedule. If this results in any for loops,
6412 * then this means that we did not pass along enough information
6413 * about the outer schedule to the inner AST generation.
6415 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
6418 isl_union_map
*schedule
, *extra
;
6421 schedule
= isl_ast_build_get_schedule(build
);
6422 extra
= isl_union_map_copy(schedule
);
6423 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
6424 schedule
= isl_union_map_range_product(schedule
, extra
);
6425 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6426 isl_ast_build_free(build
);
6431 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
6432 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
6433 "code should not contain any for loop",
6434 return isl_ast_node_free(tree
));
6439 /* Check that we do not lose any information when going back and
6440 * forth between internal and external schedule.
6442 * In particular, we create an AST where we unroll the only
6443 * non-constant dimension in the schedule. We therefore do
6444 * not expect any for loops in the AST. However, older versions
6445 * of isl would not pass along enough information about the outer
6446 * schedule when performing an inner code generation from a create_leaf
6447 * callback, resulting in the inner code generation producing a for loop.
6449 static int test_ast_gen5(isl_ctx
*ctx
)
6453 isl_union_map
*schedule
, *options
;
6454 isl_ast_build
*build
;
6457 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
6458 schedule
= isl_union_map_read_from_str(ctx
, str
);
6460 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
6461 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
6462 options
= isl_union_map_read_from_str(ctx
, str
);
6464 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
6465 build
= isl_ast_build_from_context(set
);
6466 build
= isl_ast_build_set_options(build
, options
);
6467 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
6468 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
6469 isl_ast_build_free(build
);
6470 isl_ast_node_free(tree
);
6477 /* Check that the expression
6479 * [n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
6481 * is not combined into
6485 * as this would result in n/2 being evaluated in parts of
6486 * the definition domain where n is not a multiple of 2.
6488 static int test_ast_expr(isl_ctx
*ctx
)
6492 isl_ast_build
*build
;
6497 min_max
= isl_options_get_ast_build_detect_min_max(ctx
);
6498 isl_options_set_ast_build_detect_min_max(ctx
, 1);
6500 str
= "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
6501 pa
= isl_pw_aff_read_from_str(ctx
, str
);
6502 build
= isl_ast_build_alloc(ctx
);
6503 expr
= isl_ast_build_expr_from_pw_aff(build
, pa
);
6504 is_min
= isl_ast_expr_get_type(expr
) == isl_ast_expr_op
&&
6505 isl_ast_expr_get_op_type(expr
) == isl_ast_op_min
;
6506 isl_ast_build_free(build
);
6507 isl_ast_expr_free(expr
);
6509 isl_options_set_ast_build_detect_min_max(ctx
, min_max
);
6514 isl_die(ctx
, isl_error_unknown
,
6515 "expressions should not be combined", return -1);
6520 static int test_ast_gen(isl_ctx
*ctx
)
6522 if (test_ast_gen1(ctx
) < 0)
6524 if (test_ast_gen2(ctx
) < 0)
6526 if (test_ast_gen3(ctx
) < 0)
6528 if (test_ast_gen4(ctx
) < 0)
6530 if (test_ast_gen5(ctx
) < 0)
6532 if (test_ast_expr(ctx
) < 0)
6537 /* Check if dropping output dimensions from an isl_pw_multi_aff
6540 static int test_pw_multi_aff(isl_ctx
*ctx
)
6543 isl_pw_multi_aff
*pma1
, *pma2
;
6546 str
= "{ [i,j] -> [i+j, 4i-j] }";
6547 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6548 str
= "{ [i,j] -> [4i-j] }";
6549 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
6551 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
6553 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
6555 isl_pw_multi_aff_free(pma1
);
6556 isl_pw_multi_aff_free(pma2
);
6560 isl_die(ctx
, isl_error_unknown
,
6561 "expressions not equal", return -1);
6566 /* Check that we can properly parse multi piecewise affine expressions
6567 * where the piecewise affine expressions have different domains.
6569 static int test_multi_pw_aff(isl_ctx
*ctx
)
6572 isl_set
*dom
, *dom2
;
6573 isl_multi_pw_aff
*mpa1
, *mpa2
;
6578 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
6579 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
6580 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
6581 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
6582 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
6583 str
= "{ [i] -> [(i : i > 0), 2i] }";
6584 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
6586 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
6588 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
6589 dom
= isl_pw_aff_domain(pa
);
6590 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
6591 dom2
= isl_pw_aff_domain(pa
);
6592 equal_domain
= isl_set_is_equal(dom
, dom2
);
6596 isl_multi_pw_aff_free(mpa1
);
6597 isl_multi_pw_aff_free(mpa2
);
6602 isl_die(ctx
, isl_error_unknown
,
6603 "expressions not equal", return -1);
6605 if (equal_domain
< 0)
6608 isl_die(ctx
, isl_error_unknown
,
6609 "domains unexpectedly equal", return -1);
6614 /* This is a regression test for a bug where isl_basic_map_simplify
6615 * would end up in an infinite loop. In particular, we construct
6616 * an empty basic set that is not obviously empty.
6617 * isl_basic_set_is_empty marks the basic set as empty.
6618 * After projecting out i3, the variable can be dropped completely,
6619 * but isl_basic_map_simplify refrains from doing so if the basic set
6620 * is empty and would end up in an infinite loop if it didn't test
6621 * explicitly for empty basic maps in the outer loop.
6623 static int test_simplify_1(isl_ctx
*ctx
)
6626 isl_basic_set
*bset
;
6629 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
6630 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
6631 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
6633 bset
= isl_basic_set_read_from_str(ctx
, str
);
6634 empty
= isl_basic_set_is_empty(bset
);
6635 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
6636 isl_basic_set_free(bset
);
6640 isl_die(ctx
, isl_error_unknown
,
6641 "basic set should be empty", return -1);
6646 /* Check that the equality in the set description below
6647 * is simplified away.
6649 static int test_simplify_2(isl_ctx
*ctx
)
6652 isl_basic_set
*bset
;
6655 str
= "{ [a] : exists e0, e1: 32e1 = 31 + 31a + 31e0 }";
6656 bset
= isl_basic_set_read_from_str(ctx
, str
);
6657 universe
= isl_basic_set_plain_is_universe(bset
);
6658 isl_basic_set_free(bset
);
6663 isl_die(ctx
, isl_error_unknown
,
6664 "equality not simplified away", return -1);
6668 /* Some simplification tests.
6670 static int test_simplify(isl_ctx
*ctx
)
6672 if (test_simplify_1(ctx
) < 0)
6674 if (test_simplify_2(ctx
) < 0)
6679 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
6680 * with gbr context would fail to disable the use of the shifted tableau
6681 * when transferring equalities for the input to the context, resulting
6682 * in invalid sample values.
6684 static int test_partial_lexmin(isl_ctx
*ctx
)
6687 isl_basic_set
*bset
;
6688 isl_basic_map
*bmap
;
6691 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
6692 bmap
= isl_basic_map_read_from_str(ctx
, str
);
6693 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
6694 bset
= isl_basic_set_read_from_str(ctx
, str
);
6695 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
6704 /* Check that the variable compression performed on the existentially
6705 * quantified variables inside isl_basic_set_compute_divs is not confused
6706 * by the implicit equalities among the parameters.
6708 static int test_compute_divs(isl_ctx
*ctx
)
6711 isl_basic_set
*bset
;
6714 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
6715 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
6716 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
6717 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
6718 bset
= isl_basic_set_read_from_str(ctx
, str
);
6719 set
= isl_basic_set_compute_divs(bset
);
6727 /* Check that the reaching domain elements and the prefix schedule
6728 * at a leaf node are the same before and after grouping.
6730 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
6735 isl_union_set
*uset
;
6736 isl_multi_union_pw_aff
*mupa
;
6737 isl_union_pw_multi_aff
*upma1
, *upma2
;
6738 isl_union_set
*domain1
, *domain2
;
6739 isl_union_map
*umap1
, *umap2
;
6740 isl_schedule_node
*node
;
6742 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
6743 uset
= isl_union_set_read_from_str(ctx
, str
);
6744 node
= isl_schedule_node_from_domain(uset
);
6745 node
= isl_schedule_node_child(node
, 0);
6746 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
6747 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6748 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
6749 node
= isl_schedule_node_child(node
, 0);
6750 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
6751 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6752 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
6753 node
= isl_schedule_node_child(node
, 0);
6754 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
6755 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
6756 domain1
= isl_schedule_node_get_domain(node
);
6757 id
= isl_id_alloc(ctx
, "group", NULL
);
6758 node
= isl_schedule_node_parent(node
);
6759 node
= isl_schedule_node_group(node
, id
);
6760 node
= isl_schedule_node_child(node
, 0);
6761 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
6762 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
6763 domain2
= isl_schedule_node_get_domain(node
);
6764 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
6765 if (equal
>= 0 && equal
)
6766 equal
= isl_union_set_is_equal(domain1
, domain2
);
6767 if (equal
>= 0 && equal
)
6768 equal
= isl_union_map_is_equal(umap1
, umap2
);
6769 isl_union_map_free(umap1
);
6770 isl_union_map_free(umap2
);
6771 isl_union_set_free(domain1
);
6772 isl_union_set_free(domain2
);
6773 isl_union_pw_multi_aff_free(upma1
);
6774 isl_union_pw_multi_aff_free(upma2
);
6775 isl_schedule_node_free(node
);
6780 isl_die(ctx
, isl_error_unknown
,
6781 "expressions not equal", return -1);
6786 /* Check that we can have nested groupings and that the union map
6787 * schedule representation is the same before and after the grouping.
6788 * Note that after the grouping, the union map representation contains
6789 * the domain constraints from the ranges of the expansion nodes,
6790 * while they are missing from the union map representation of
6791 * the tree without expansion nodes.
6793 * Also check that the global expansion is as expected.
6795 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
6797 int equal
, equal_expansion
;
6800 isl_union_set
*uset
;
6801 isl_union_map
*umap1
, *umap2
;
6802 isl_union_map
*expansion1
, *expansion2
;
6803 isl_union_set_list
*filters
;
6804 isl_multi_union_pw_aff
*mupa
;
6805 isl_schedule
*schedule
;
6806 isl_schedule_node
*node
;
6808 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
6809 "S3[i,j] : 0 <= i,j < 10 }";
6810 uset
= isl_union_set_read_from_str(ctx
, str
);
6811 node
= isl_schedule_node_from_domain(uset
);
6812 node
= isl_schedule_node_child(node
, 0);
6813 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
6814 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
6815 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
6816 node
= isl_schedule_node_child(node
, 0);
6817 str
= "{ S1[i,j] }";
6818 uset
= isl_union_set_read_from_str(ctx
, str
);
6819 filters
= isl_union_set_list_from_union_set(uset
);
6820 str
= "{ S2[i,j]; S3[i,j] }";
6821 uset
= isl_union_set_read_from_str(ctx
, str
);
6822 filters
= isl_union_set_list_add(filters
, uset
);
6823 node
= isl_schedule_node_insert_sequence(node
, filters
);
6824 node
= isl_schedule_node_child(node
, 1);
6825 node
= isl_schedule_node_child(node
, 0);
6826 str
= "{ S2[i,j] }";
6827 uset
= isl_union_set_read_from_str(ctx
, str
);
6828 filters
= isl_union_set_list_from_union_set(uset
);
6829 str
= "{ S3[i,j] }";
6830 uset
= isl_union_set_read_from_str(ctx
, str
);
6831 filters
= isl_union_set_list_add(filters
, uset
);
6832 node
= isl_schedule_node_insert_sequence(node
, filters
);
6834 schedule
= isl_schedule_node_get_schedule(node
);
6835 umap1
= isl_schedule_get_map(schedule
);
6836 uset
= isl_schedule_get_domain(schedule
);
6837 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
6838 isl_schedule_free(schedule
);
6840 node
= isl_schedule_node_parent(node
);
6841 node
= isl_schedule_node_parent(node
);
6842 id
= isl_id_alloc(ctx
, "group1", NULL
);
6843 node
= isl_schedule_node_group(node
, id
);
6844 node
= isl_schedule_node_child(node
, 1);
6845 node
= isl_schedule_node_child(node
, 0);
6846 id
= isl_id_alloc(ctx
, "group2", NULL
);
6847 node
= isl_schedule_node_group(node
, id
);
6849 schedule
= isl_schedule_node_get_schedule(node
);
6850 umap2
= isl_schedule_get_map(schedule
);
6851 isl_schedule_free(schedule
);
6853 node
= isl_schedule_node_root(node
);
6854 node
= isl_schedule_node_child(node
, 0);
6855 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
6856 isl_schedule_node_free(node
);
6858 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
6859 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
6860 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
6862 expansion2
= isl_union_map_read_from_str(ctx
, str
);
6864 equal
= isl_union_map_is_equal(umap1
, umap2
);
6865 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
6867 isl_union_map_free(umap1
);
6868 isl_union_map_free(umap2
);
6869 isl_union_map_free(expansion1
);
6870 isl_union_map_free(expansion2
);
6872 if (equal
< 0 || equal_expansion
< 0)
6875 isl_die(ctx
, isl_error_unknown
,
6876 "expressions not equal", return -1);
6877 if (!equal_expansion
)
6878 isl_die(ctx
, isl_error_unknown
,
6879 "unexpected expansion", return -1);
6884 /* Some tests for the isl_schedule_node_group function.
6886 static int test_schedule_tree_group(isl_ctx
*ctx
)
6888 if (test_schedule_tree_group_1(ctx
) < 0)
6890 if (test_schedule_tree_group_2(ctx
) < 0)
6899 { "{ rat: [i] : 0 <= i <= 10 }",
6900 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
6901 { "{ rat: [i] : FALSE }",
6902 "{ rat: coefficients[[cst] -> [a]] }" },
6904 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
6911 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
6912 "{ rat: [i] : 0 <= i <= 10 }" },
6913 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
6915 { "{ rat: coefficients[[cst] -> [a]] }",
6916 "{ rat: [i] : FALSE }" },
6919 /* Test the basic functionality of isl_basic_set_coefficients and
6920 * isl_basic_set_solutions.
6922 static int test_dual(isl_ctx
*ctx
)
6926 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
6928 isl_basic_set
*bset1
, *bset2
;
6930 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
6931 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
6932 bset1
= isl_basic_set_coefficients(bset1
);
6933 equal
= isl_basic_set_is_equal(bset1
, bset2
);
6934 isl_basic_set_free(bset1
);
6935 isl_basic_set_free(bset2
);
6939 isl_die(ctx
, isl_error_unknown
,
6940 "incorrect dual", return -1);
6943 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
6945 isl_basic_set
*bset1
, *bset2
;
6947 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
6948 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
6949 bset1
= isl_basic_set_solutions(bset1
);
6950 equal
= isl_basic_set_is_equal(bset1
, bset2
);
6951 isl_basic_set_free(bset1
);
6952 isl_basic_set_free(bset2
);
6956 isl_die(ctx
, isl_error_unknown
,
6957 "incorrect dual", return -1);
6967 const char *schedule
;
6972 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
6973 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6975 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
6976 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6978 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
6979 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6981 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
6982 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6984 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
6985 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6987 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
6988 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
6990 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
6991 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
6993 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
6994 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
6998 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
6999 * tile the band and then check if the tile and point bands have the
7000 * expected partial schedule.
7002 static int test_tile(isl_ctx
*ctx
)
7008 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
7009 shift
= isl_options_get_tile_shift_point_loops(ctx
);
7011 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
7015 isl_union_set
*domain
;
7016 isl_multi_union_pw_aff
*mupa
, *mupa2
;
7017 isl_schedule_node
*node
;
7018 isl_multi_val
*sizes
;
7020 opt
= tile_tests
[i
].scale_tile
;
7021 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
7022 opt
= tile_tests
[i
].shift_point
;
7023 isl_options_set_tile_shift_point_loops(ctx
, opt
);
7025 str
= tile_tests
[i
].domain
;
7026 domain
= isl_union_set_read_from_str(ctx
, str
);
7027 node
= isl_schedule_node_from_domain(domain
);
7028 node
= isl_schedule_node_child(node
, 0);
7029 str
= tile_tests
[i
].schedule
;
7030 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
7031 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
7032 str
= tile_tests
[i
].sizes
;
7033 sizes
= isl_multi_val_read_from_str(ctx
, str
);
7034 node
= isl_schedule_node_band_tile(node
, sizes
);
7036 str
= tile_tests
[i
].tile
;
7037 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
7038 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
7039 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
7040 isl_multi_union_pw_aff_free(mupa
);
7041 isl_multi_union_pw_aff_free(mupa2
);
7043 node
= isl_schedule_node_child(node
, 0);
7045 str
= tile_tests
[i
].point
;
7046 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
7047 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
7048 if (equal
>= 0 && equal
)
7049 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
7051 isl_multi_union_pw_aff_free(mupa
);
7052 isl_multi_union_pw_aff_free(mupa2
);
7054 isl_schedule_node_free(node
);
7059 isl_die(ctx
, isl_error_unknown
,
7060 "unexpected result", return -1);
7063 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
7064 isl_options_set_tile_shift_point_loops(ctx
, shift
);
7069 /* Check that the domain hash of a space is equal to the hash
7070 * of the domain of the space.
7072 static int test_domain_hash(isl_ctx
*ctx
)
7076 uint32_t hash1
, hash2
;
7078 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
7079 space
= isl_map_get_space(map
);
7081 hash1
= isl_space_get_domain_hash(space
);
7082 space
= isl_space_domain(space
);
7083 hash2
= isl_space_get_hash(space
);
7084 isl_space_free(space
);
7089 isl_die(ctx
, isl_error_unknown
,
7090 "domain hash not equal to hash of domain", return -1);
7095 /* Check that a universe basic set that is not obviously equal to the universe
7096 * is still recognized as being equal to the universe.
7098 static int test_universe(isl_ctx
*ctx
)
7101 isl_basic_set
*bset
;
7104 s
= "{ [] : exists x, y : 3y <= 2x and y >= -3 + 2x and 2y >= 2 - x }";
7105 bset
= isl_basic_set_read_from_str(ctx
, s
);
7106 is_univ
= isl_basic_set_is_universe(bset
);
7107 isl_basic_set_free(bset
);
7112 isl_die(ctx
, isl_error_unknown
,
7113 "not recognized as universe set", return -1);
7118 /* Sets for which chambers are computed and checked.
7120 const char *chambers_tests
[] = {
7121 "[A, B, C] -> { [x, y, z] : x >= 0 and y >= 0 and y <= A - x and "
7122 "z >= 0 and z <= C - y and z <= B - x - y }",
7125 /* Add the domain of "cell" to "cells".
7127 static isl_stat
add_cell(__isl_take isl_cell
*cell
, void *user
)
7129 isl_basic_set_list
**cells
= user
;
7132 dom
= isl_cell_get_domain(cell
);
7133 isl_cell_free(cell
);
7134 *cells
= isl_basic_set_list_add(*cells
, dom
);
7136 return *cells
? isl_stat_ok
: isl_stat_error
;
7139 /* Check that the elements of "list" are pairwise disjoint.
7141 static isl_stat
check_pairwise_disjoint(__isl_keep isl_basic_set_list
*list
)
7146 return isl_stat_error
;
7148 n
= isl_basic_set_list_n_basic_set(list
);
7149 for (i
= 0; i
< n
; ++i
) {
7150 isl_basic_set
*bset_i
;
7152 bset_i
= isl_basic_set_list_get_basic_set(list
, i
);
7153 for (j
= i
+ 1; j
< n
; ++j
) {
7154 isl_basic_set
*bset_j
;
7157 bset_j
= isl_basic_set_list_get_basic_set(list
, j
);
7158 disjoint
= isl_basic_set_is_disjoint(bset_i
, bset_j
);
7159 isl_basic_set_free(bset_j
);
7161 isl_die(isl_basic_set_list_get_ctx(list
),
7162 isl_error_unknown
, "not disjoint",
7164 if (disjoint
< 0 || !disjoint
)
7167 isl_basic_set_free(bset_i
);
7169 return isl_stat_error
;
7175 /* Check that the chambers computed by isl_vertices_foreach_disjoint_cell
7176 * are pairwise disjoint.
7178 static int test_chambers(isl_ctx
*ctx
)
7182 for (i
= 0; i
< ARRAY_SIZE(chambers_tests
); ++i
) {
7183 isl_basic_set
*bset
;
7184 isl_vertices
*vertices
;
7185 isl_basic_set_list
*cells
;
7188 bset
= isl_basic_set_read_from_str(ctx
, chambers_tests
[i
]);
7189 vertices
= isl_basic_set_compute_vertices(bset
);
7190 cells
= isl_basic_set_list_alloc(ctx
, 0);
7191 if (isl_vertices_foreach_disjoint_cell(vertices
, &add_cell
,
7193 cells
= isl_basic_set_list_free(cells
);
7194 ok
= check_pairwise_disjoint(cells
);
7195 isl_basic_set_list_free(cells
);
7196 isl_vertices_free(vertices
);
7197 isl_basic_set_free(bset
);
7208 int (*fn
)(isl_ctx
*ctx
);
7210 { "universe", &test_universe
},
7211 { "domain hash", &test_domain_hash
},
7212 { "dual", &test_dual
},
7213 { "dependence analysis", &test_flow
},
7214 { "val", &test_val
},
7215 { "compute divs", &test_compute_divs
},
7216 { "partial lexmin", &test_partial_lexmin
},
7217 { "simplify", &test_simplify
},
7218 { "curry", &test_curry
},
7219 { "piecewise multi affine expressions", &test_pw_multi_aff
},
7220 { "multi piecewise affine expressions", &test_multi_pw_aff
},
7221 { "conversion", &test_conversion
},
7222 { "list", &test_list
},
7223 { "align parameters", &test_align_parameters
},
7224 { "preimage", &test_preimage
},
7225 { "pullback", &test_pullback
},
7226 { "AST", &test_ast
},
7227 { "AST build", &test_ast_build
},
7228 { "AST generation", &test_ast_gen
},
7229 { "eliminate", &test_eliminate
},
7230 { "residue class", &test_residue_class
},
7231 { "div", &test_div
},
7232 { "slice", &test_slice
},
7233 { "fixed power", &test_fixed_power
},
7234 { "sample", &test_sample
},
7235 { "output", &test_output
},
7236 { "vertices", &test_vertices
},
7237 { "chambers", &test_chambers
},
7238 { "fixed", &test_fixed
},
7239 { "equal", &test_equal
},
7240 { "disjoint", &test_disjoint
},
7241 { "product", &test_product
},
7242 { "dim_max", &test_dim_max
},
7243 { "affine", &test_aff
},
7244 { "injective", &test_injective
},
7245 { "schedule (whole component)", &test_schedule_whole
},
7246 { "schedule (incremental)", &test_schedule_incremental
},
7247 { "schedule tree grouping", &test_schedule_tree_group
},
7248 { "tile", &test_tile
},
7249 { "union_pw", &test_union_pw
},
7250 { "eval", &test_eval
},
7251 { "parse", &test_parse
},
7252 { "single-valued", &test_sv
},
7253 { "affine hull", &test_affine_hull
},
7254 { "simple_hull", &test_simple_hull
},
7255 { "coalesce", &test_coalesce
},
7256 { "factorize", &test_factorize
},
7257 { "subset", &test_subset
},
7258 { "subtract", &test_subtract
},
7259 { "intersect", &test_intersect
},
7260 { "lexmin", &test_lexmin
},
7261 { "min", &test_min
},
7262 { "gist", &test_gist
},
7263 { "piecewise quasi-polynomials", &test_pwqp
},
7264 { "lift", &test_lift
},
7265 { "bound", &test_bound
},
7266 { "union", &test_union
},
7267 { "split periods", &test_split_periods
},
7268 { "lexicographic order", &test_lex
},
7269 { "bijectivity", &test_bijective
},
7270 { "dataflow analysis", &test_dep
},
7271 { "reading", &test_read
},
7272 { "bounded", &test_bounded
},
7273 { "construction", &test_construction
},
7274 { "dimension manipulation", &test_dim
},
7275 { "map application", &test_application
},
7276 { "convex hull", &test_convex_hull
},
7277 { "transitive closure", &test_closure
},
7280 int main(int argc
, char **argv
)
7283 struct isl_ctx
*ctx
;
7284 struct isl_options
*options
;
7286 options
= isl_options_new_with_defaults();
7288 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
7290 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
7291 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
7292 printf("%s\n", tests
[i
].name
);
7293 if (tests
[i
].fn(ctx
) < 0)