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.h>
36 #include <isl/ast_build.h>
39 #include <isl_ast_build_expr.h>
40 #include <isl/options.h>
42 #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 int test_parse(struct isl_ctx
*ctx
)
125 const char *str
, *str2
;
127 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
129 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
131 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
134 str
= "{ [i] -> [-i] }";
135 map
= isl_map_read_from_str(ctx
, str
);
139 str
= "{ A[i] -> L[([i/3])] }";
140 map
= isl_map_read_from_str(ctx
, str
);
144 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
145 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
146 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
148 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
149 str2
= "{ [x, y] : 2y >= 6 - x }";
150 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
153 if (test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
154 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
156 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
157 if (test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }",
161 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
162 map
= isl_map_read_from_str(ctx
, str
);
163 str
= "{ [new, old] -> [o0, o1] : "
164 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
165 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
166 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
167 map2
= isl_map_read_from_str(ctx
, str
);
168 assert(isl_map_is_equal(map
, map2
));
172 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
173 map
= isl_map_read_from_str(ctx
, str
);
174 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
175 map2
= isl_map_read_from_str(ctx
, str
);
176 assert(isl_map_is_equal(map
, map2
));
180 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
181 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
182 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
185 str
= "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
186 str2
= "{ [i,j] -> [min(i,j)] }";
187 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
190 str
= "{ [i,j] : i != j }";
191 str2
= "{ [i,j] : i < j or i > j }";
192 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
195 str
= "{ [i,j] : (i+1)*2 >= j }";
196 str2
= "{ [i, j] : j <= 2 + 2i }";
197 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
200 str
= "{ [i] -> [i > 0 ? 4 : 5] }";
201 str2
= "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
202 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
205 str
= "[N=2,M] -> { [i=[(M+N)/4]] }";
206 str2
= "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
207 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
210 str
= "{ [x] : x >= 0 }";
211 str2
= "{ [x] : x-0 >= 0 }";
212 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
215 str
= "{ [i] : ((i > 10)) }";
216 str2
= "{ [i] : i >= 11 }";
217 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
220 str
= "{ [i] -> [0] }";
221 str2
= "{ [i] -> [0 * i] }";
222 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
225 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
226 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
227 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
228 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
230 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : (not false) }",
231 "{ [a] -> [b] : true }") < 0)
234 if (test_parse_map_equal(ctx
, "{ [i] : i/2 <= 5 }",
235 "{ [i] : i <= 10 }") < 0)
238 if (test_parse_map_equal(ctx
, "{Sym=[n] [i] : i <= n }",
239 "[n] -> { [i] : i <= n }") < 0)
242 if (test_parse_map_equal(ctx
, "{ [*] }", "{ [a] }") < 0)
245 if (test_parse_map_equal(ctx
, "{ [i] : 2*floor(i/2) = i }",
246 "{ [i] : exists a : i = 2 a }") < 0)
249 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : a = 5 implies b = 5 }",
250 "{ [a] -> [b] : a != 5 or b = 5 }") < 0)
253 if (test_parse_map_equal(ctx
, "{ [a] -> [a - 1 : a > 0] }",
254 "{ [a] -> [a - 1] : a > 0 }") < 0)
256 if (test_parse_map_equal(ctx
,
257 "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
258 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }") < 0)
260 if (test_parse_map_equal(ctx
,
261 "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
262 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
264 if (test_parse_map_equal(ctx
,
265 "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
266 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
268 if (test_parse_map_equal(ctx
,
269 "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
270 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
272 if (test_parse_map_equal(ctx
,
273 "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
274 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
280 static int test_read(isl_ctx
*ctx
)
284 isl_basic_set
*bset1
, *bset2
;
285 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
288 filename
= get_filename(ctx
, "set", "omega");
290 input
= fopen(filename
, "r");
293 bset1
= isl_basic_set_read_from_file(ctx
, input
);
294 bset2
= isl_basic_set_read_from_str(ctx
, str
);
296 equal
= isl_basic_set_is_equal(bset1
, bset2
);
298 isl_basic_set_free(bset1
);
299 isl_basic_set_free(bset2
);
307 isl_die(ctx
, isl_error_unknown
,
308 "read sets not equal", return -1);
313 static int test_bounded(isl_ctx
*ctx
)
318 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
319 bounded
= isl_set_is_bounded(set
);
325 isl_die(ctx
, isl_error_unknown
,
326 "set not considered bounded", return -1);
328 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
329 bounded
= isl_set_is_bounded(set
);
336 isl_die(ctx
, isl_error_unknown
,
337 "set considered bounded", return -1);
339 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
340 bounded
= isl_set_is_bounded(set
);
346 isl_die(ctx
, isl_error_unknown
,
347 "set considered bounded", return -1);
352 /* Construct the basic set { [i] : 5 <= i <= N } */
353 static int test_construction(isl_ctx
*ctx
)
363 dim
= isl_space_set_alloc(ctx
, 1, 1);
364 bset
= isl_basic_set_universe(isl_space_copy(dim
));
365 ls
= isl_local_space_from_space(dim
);
367 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
368 isl_int_set_si(v
, -1);
369 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
370 isl_int_set_si(v
, 1);
371 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
372 bset
= isl_basic_set_add_constraint(bset
, c
);
374 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
375 isl_int_set_si(v
, 1);
376 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
377 isl_int_set_si(v
, -5);
378 isl_constraint_set_constant(c
, v
);
379 bset
= isl_basic_set_add_constraint(bset
, c
);
381 isl_local_space_free(ls
);
382 isl_basic_set_free(bset
);
389 static int test_dim(isl_ctx
*ctx
)
392 isl_map
*map1
, *map2
;
395 map1
= isl_map_read_from_str(ctx
,
396 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
397 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
398 map2
= isl_map_read_from_str(ctx
,
399 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
400 equal
= isl_map_is_equal(map1
, map2
);
403 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
404 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
405 if (equal
>= 0 && equal
)
406 equal
= isl_map_is_equal(map1
, map2
);
414 isl_die(ctx
, isl_error_unknown
,
415 "unexpected result", return -1);
417 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
418 map1
= isl_map_read_from_str(ctx
, str
);
419 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
420 map2
= isl_map_read_from_str(ctx
, str
);
421 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
422 equal
= isl_map_is_equal(map1
, map2
);
429 isl_die(ctx
, isl_error_unknown
,
430 "unexpected result", return -1);
436 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
440 { &isl_val_neg
, "0", "0" },
441 { &isl_val_abs
, "0", "0" },
442 { &isl_val_2exp
, "0", "1" },
443 { &isl_val_floor
, "0", "0" },
444 { &isl_val_ceil
, "0", "0" },
445 { &isl_val_neg
, "1", "-1" },
446 { &isl_val_neg
, "-1", "1" },
447 { &isl_val_neg
, "1/2", "-1/2" },
448 { &isl_val_neg
, "-1/2", "1/2" },
449 { &isl_val_neg
, "infty", "-infty" },
450 { &isl_val_neg
, "-infty", "infty" },
451 { &isl_val_neg
, "NaN", "NaN" },
452 { &isl_val_abs
, "1", "1" },
453 { &isl_val_abs
, "-1", "1" },
454 { &isl_val_abs
, "1/2", "1/2" },
455 { &isl_val_abs
, "-1/2", "1/2" },
456 { &isl_val_abs
, "infty", "infty" },
457 { &isl_val_abs
, "-infty", "infty" },
458 { &isl_val_abs
, "NaN", "NaN" },
459 { &isl_val_floor
, "1", "1" },
460 { &isl_val_floor
, "-1", "-1" },
461 { &isl_val_floor
, "1/2", "0" },
462 { &isl_val_floor
, "-1/2", "-1" },
463 { &isl_val_floor
, "infty", "infty" },
464 { &isl_val_floor
, "-infty", "-infty" },
465 { &isl_val_floor
, "NaN", "NaN" },
466 { &isl_val_ceil
, "1", "1" },
467 { &isl_val_ceil
, "-1", "-1" },
468 { &isl_val_ceil
, "1/2", "1" },
469 { &isl_val_ceil
, "-1/2", "0" },
470 { &isl_val_ceil
, "infty", "infty" },
471 { &isl_val_ceil
, "-infty", "-infty" },
472 { &isl_val_ceil
, "NaN", "NaN" },
473 { &isl_val_2exp
, "-3", "1/8" },
474 { &isl_val_2exp
, "-1", "1/2" },
475 { &isl_val_2exp
, "1", "2" },
476 { &isl_val_2exp
, "2", "4" },
477 { &isl_val_2exp
, "3", "8" },
478 { &isl_val_inv
, "1", "1" },
479 { &isl_val_inv
, "2", "1/2" },
480 { &isl_val_inv
, "1/2", "2" },
481 { &isl_val_inv
, "-2", "-1/2" },
482 { &isl_val_inv
, "-1/2", "-2" },
483 { &isl_val_inv
, "0", "NaN" },
484 { &isl_val_inv
, "NaN", "NaN" },
485 { &isl_val_inv
, "infty", "0" },
486 { &isl_val_inv
, "-infty", "0" },
489 /* Perform some basic tests of unary operations on isl_val objects.
491 static int test_un_val(isl_ctx
*ctx
)
495 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
498 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
499 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
500 res
= isl_val_read_from_str(ctx
, val_un_tests
[i
].res
);
501 fn
= val_un_tests
[i
].op
;
503 if (isl_val_is_nan(res
))
504 ok
= isl_val_is_nan(v
);
506 ok
= isl_val_eq(v
, res
);
512 isl_die(ctx
, isl_error_unknown
,
513 "unexpected result", return -1);
520 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
521 __isl_take isl_val
*v2
);
523 ['+'] = { &isl_val_add
},
524 ['-'] = { &isl_val_sub
},
525 ['*'] = { &isl_val_mul
},
526 ['/'] = { &isl_val_div
},
527 ['g'] = { &isl_val_gcd
},
528 ['m'] = { &isl_val_min
},
529 ['M'] = { &isl_val_max
},
537 } val_bin_tests
[] = {
538 { "0", '+', "0", "0" },
539 { "1", '+', "0", "1" },
540 { "1", '+', "1", "2" },
541 { "1", '-', "1", "0" },
542 { "1", '*', "1", "1" },
543 { "1", '/', "1", "1" },
544 { "2", '*', "3", "6" },
545 { "2", '*', "1/2", "1" },
546 { "2", '*', "1/3", "2/3" },
547 { "2/3", '*', "3/5", "2/5" },
548 { "2/3", '*', "7/5", "14/15" },
549 { "2", '/', "1/2", "4" },
550 { "-2", '/', "-1/2", "4" },
551 { "-2", '/', "1/2", "-4" },
552 { "2", '/', "-1/2", "-4" },
553 { "2", '/', "2", "1" },
554 { "2", '/', "3", "2/3" },
555 { "2/3", '/', "5/3", "2/5" },
556 { "2/3", '/', "5/7", "14/15" },
557 { "0", '/', "0", "NaN" },
558 { "42", '/', "0", "NaN" },
559 { "-42", '/', "0", "NaN" },
560 { "infty", '/', "0", "NaN" },
561 { "-infty", '/', "0", "NaN" },
562 { "NaN", '/', "0", "NaN" },
563 { "0", '/', "NaN", "NaN" },
564 { "42", '/', "NaN", "NaN" },
565 { "-42", '/', "NaN", "NaN" },
566 { "infty", '/', "NaN", "NaN" },
567 { "-infty", '/', "NaN", "NaN" },
568 { "NaN", '/', "NaN", "NaN" },
569 { "0", '/', "infty", "0" },
570 { "42", '/', "infty", "0" },
571 { "-42", '/', "infty", "0" },
572 { "infty", '/', "infty", "NaN" },
573 { "-infty", '/', "infty", "NaN" },
574 { "NaN", '/', "infty", "NaN" },
575 { "0", '/', "-infty", "0" },
576 { "42", '/', "-infty", "0" },
577 { "-42", '/', "-infty", "0" },
578 { "infty", '/', "-infty", "NaN" },
579 { "-infty", '/', "-infty", "NaN" },
580 { "NaN", '/', "-infty", "NaN" },
581 { "1", '-', "1/3", "2/3" },
582 { "1/3", '+', "1/2", "5/6" },
583 { "1/2", '+', "1/2", "1" },
584 { "3/4", '-', "1/4", "1/2" },
585 { "1/2", '-', "1/3", "1/6" },
586 { "infty", '+', "42", "infty" },
587 { "infty", '+', "infty", "infty" },
588 { "42", '+', "infty", "infty" },
589 { "infty", '-', "infty", "NaN" },
590 { "infty", '*', "infty", "infty" },
591 { "infty", '*', "-infty", "-infty" },
592 { "-infty", '*', "infty", "-infty" },
593 { "-infty", '*', "-infty", "infty" },
594 { "0", '*', "infty", "NaN" },
595 { "1", '*', "infty", "infty" },
596 { "infty", '*', "0", "NaN" },
597 { "infty", '*', "42", "infty" },
598 { "42", '-', "infty", "-infty" },
599 { "infty", '+', "-infty", "NaN" },
600 { "4", 'g', "6", "2" },
601 { "5", 'g', "6", "1" },
602 { "42", 'm', "3", "3" },
603 { "42", 'M', "3", "42" },
604 { "3", 'm', "42", "3" },
605 { "3", 'M', "42", "42" },
606 { "42", 'm', "infty", "42" },
607 { "42", 'M', "infty", "infty" },
608 { "42", 'm', "-infty", "-infty" },
609 { "42", 'M', "-infty", "42" },
610 { "42", 'm', "NaN", "NaN" },
611 { "42", 'M', "NaN", "NaN" },
612 { "infty", 'm', "-infty", "-infty" },
613 { "infty", 'M', "-infty", "infty" },
616 /* Perform some basic tests of binary operations on isl_val objects.
618 static int test_bin_val(isl_ctx
*ctx
)
621 isl_val
*v1
, *v2
, *res
;
622 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
623 __isl_take isl_val
*v2
);
626 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
627 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
628 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
629 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
630 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
632 if (isl_val_is_nan(res
))
633 ok
= isl_val_is_nan(v1
);
635 ok
= isl_val_eq(v1
, res
);
641 isl_die(ctx
, isl_error_unknown
,
642 "unexpected result", return -1);
648 /* Perform some basic tests on isl_val objects.
650 static int test_val(isl_ctx
*ctx
)
652 if (test_un_val(ctx
) < 0)
654 if (test_bin_val(ctx
) < 0)
659 static int test_div(isl_ctx
*ctx
)
668 struct isl_basic_set
*bset
;
669 struct isl_constraint
*c
;
674 dim
= isl_space_set_alloc(ctx
, 0, 3);
675 bset
= isl_basic_set_universe(isl_space_copy(dim
));
676 ls
= isl_local_space_from_space(dim
);
678 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
679 isl_int_set_si(v
, -1);
680 isl_constraint_set_constant(c
, v
);
681 isl_int_set_si(v
, 1);
682 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
683 isl_int_set_si(v
, 3);
684 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
685 bset
= isl_basic_set_add_constraint(bset
, c
);
687 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
688 isl_int_set_si(v
, 1);
689 isl_constraint_set_constant(c
, v
);
690 isl_int_set_si(v
, -1);
691 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
692 isl_int_set_si(v
, 3);
693 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
694 bset
= isl_basic_set_add_constraint(bset
, c
);
696 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
698 assert(bset
&& bset
->n_div
== 1);
699 isl_local_space_free(ls
);
700 isl_basic_set_free(bset
);
703 dim
= isl_space_set_alloc(ctx
, 0, 3);
704 bset
= isl_basic_set_universe(isl_space_copy(dim
));
705 ls
= isl_local_space_from_space(dim
);
707 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
708 isl_int_set_si(v
, 1);
709 isl_constraint_set_constant(c
, v
);
710 isl_int_set_si(v
, -1);
711 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
712 isl_int_set_si(v
, 3);
713 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
714 bset
= isl_basic_set_add_constraint(bset
, c
);
716 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
717 isl_int_set_si(v
, -1);
718 isl_constraint_set_constant(c
, v
);
719 isl_int_set_si(v
, 1);
720 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
721 isl_int_set_si(v
, 3);
722 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
723 bset
= isl_basic_set_add_constraint(bset
, c
);
725 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
727 assert(bset
&& bset
->n_div
== 1);
728 isl_local_space_free(ls
);
729 isl_basic_set_free(bset
);
732 dim
= isl_space_set_alloc(ctx
, 0, 3);
733 bset
= isl_basic_set_universe(isl_space_copy(dim
));
734 ls
= isl_local_space_from_space(dim
);
736 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
737 isl_int_set_si(v
, 1);
738 isl_constraint_set_constant(c
, v
);
739 isl_int_set_si(v
, -1);
740 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
741 isl_int_set_si(v
, 3);
742 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
743 bset
= isl_basic_set_add_constraint(bset
, c
);
745 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
746 isl_int_set_si(v
, -3);
747 isl_constraint_set_constant(c
, v
);
748 isl_int_set_si(v
, 1);
749 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
750 isl_int_set_si(v
, 4);
751 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
752 bset
= isl_basic_set_add_constraint(bset
, c
);
754 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
756 assert(bset
&& bset
->n_div
== 1);
757 isl_local_space_free(ls
);
758 isl_basic_set_free(bset
);
761 dim
= isl_space_set_alloc(ctx
, 0, 3);
762 bset
= isl_basic_set_universe(isl_space_copy(dim
));
763 ls
= isl_local_space_from_space(dim
);
765 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
766 isl_int_set_si(v
, 2);
767 isl_constraint_set_constant(c
, v
);
768 isl_int_set_si(v
, -1);
769 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
770 isl_int_set_si(v
, 3);
771 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
772 bset
= isl_basic_set_add_constraint(bset
, c
);
774 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
775 isl_int_set_si(v
, -1);
776 isl_constraint_set_constant(c
, v
);
777 isl_int_set_si(v
, 1);
778 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
779 isl_int_set_si(v
, 6);
780 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
781 bset
= isl_basic_set_add_constraint(bset
, c
);
783 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
785 assert(isl_basic_set_is_empty(bset
));
786 isl_local_space_free(ls
);
787 isl_basic_set_free(bset
);
790 dim
= isl_space_set_alloc(ctx
, 0, 3);
791 bset
= isl_basic_set_universe(isl_space_copy(dim
));
792 ls
= isl_local_space_from_space(dim
);
794 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
795 isl_int_set_si(v
, -1);
796 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
797 isl_int_set_si(v
, 3);
798 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
799 bset
= isl_basic_set_add_constraint(bset
, c
);
801 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
802 isl_int_set_si(v
, 1);
803 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
804 isl_int_set_si(v
, -3);
805 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
806 bset
= isl_basic_set_add_constraint(bset
, c
);
808 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
810 assert(bset
&& bset
->n_div
== 0);
811 isl_basic_set_free(bset
);
812 isl_local_space_free(ls
);
815 dim
= isl_space_set_alloc(ctx
, 0, 3);
816 bset
= isl_basic_set_universe(isl_space_copy(dim
));
817 ls
= isl_local_space_from_space(dim
);
819 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
820 isl_int_set_si(v
, -1);
821 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
822 isl_int_set_si(v
, 6);
823 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
824 bset
= isl_basic_set_add_constraint(bset
, c
);
826 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
827 isl_int_set_si(v
, 1);
828 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
829 isl_int_set_si(v
, -3);
830 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
831 bset
= isl_basic_set_add_constraint(bset
, c
);
833 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
835 assert(bset
&& bset
->n_div
== 1);
836 isl_basic_set_free(bset
);
837 isl_local_space_free(ls
);
840 /* This test is a bit tricky. We set up an equality
842 * Normalization of divs creates _two_ divs
845 * Afterwards e0 is removed again because it has coefficient -1
846 * and we end up with the original equality and div again.
847 * Perhaps we can avoid the introduction of this temporary div.
849 dim
= isl_space_set_alloc(ctx
, 0, 4);
850 bset
= isl_basic_set_universe(isl_space_copy(dim
));
851 ls
= isl_local_space_from_space(dim
);
853 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
854 isl_int_set_si(v
, -1);
855 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
856 isl_int_set_si(v
, -3);
857 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
858 isl_int_set_si(v
, -3);
859 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
860 isl_int_set_si(v
, 6);
861 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
862 bset
= isl_basic_set_add_constraint(bset
, c
);
864 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
866 /* Test disabled for now */
868 assert(bset && bset->n_div == 1);
870 isl_local_space_free(ls
);
871 isl_basic_set_free(bset
);
874 dim
= isl_space_set_alloc(ctx
, 0, 5);
875 bset
= isl_basic_set_universe(isl_space_copy(dim
));
876 ls
= isl_local_space_from_space(dim
);
878 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
879 isl_int_set_si(v
, -1);
880 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
881 isl_int_set_si(v
, -3);
882 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
883 isl_int_set_si(v
, -3);
884 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
885 isl_int_set_si(v
, 6);
886 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
887 bset
= isl_basic_set_add_constraint(bset
, c
);
889 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
890 isl_int_set_si(v
, -1);
891 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
892 isl_int_set_si(v
, 1);
893 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
894 isl_int_set_si(v
, 1);
895 isl_constraint_set_constant(c
, v
);
896 bset
= isl_basic_set_add_constraint(bset
, c
);
898 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
900 /* Test disabled for now */
902 assert(bset && bset->n_div == 1);
904 isl_local_space_free(ls
);
905 isl_basic_set_free(bset
);
908 dim
= isl_space_set_alloc(ctx
, 0, 4);
909 bset
= isl_basic_set_universe(isl_space_copy(dim
));
910 ls
= isl_local_space_from_space(dim
);
912 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
913 isl_int_set_si(v
, 1);
914 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
915 isl_int_set_si(v
, -1);
916 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
917 isl_int_set_si(v
, -2);
918 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
919 bset
= isl_basic_set_add_constraint(bset
, c
);
921 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
922 isl_int_set_si(v
, -1);
923 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
924 isl_int_set_si(v
, 3);
925 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
926 isl_int_set_si(v
, 2);
927 isl_constraint_set_constant(c
, v
);
928 bset
= isl_basic_set_add_constraint(bset
, c
);
930 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
932 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
934 assert(!isl_basic_set_is_empty(bset
));
936 isl_local_space_free(ls
);
937 isl_basic_set_free(bset
);
940 dim
= isl_space_set_alloc(ctx
, 0, 3);
941 bset
= isl_basic_set_universe(isl_space_copy(dim
));
942 ls
= isl_local_space_from_space(dim
);
944 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
945 isl_int_set_si(v
, 1);
946 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
947 isl_int_set_si(v
, -2);
948 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
949 bset
= isl_basic_set_add_constraint(bset
, c
);
951 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
953 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
955 isl_local_space_free(ls
);
956 isl_basic_set_free(bset
);
960 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
961 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
962 set
= isl_set_read_from_str(ctx
, str
);
963 set
= isl_set_compute_divs(set
);
968 str
= "{ [i,j] : 2*[i/2] + 3 * [j/4] <= 10 and 2 i = j }";
969 bset
= isl_basic_set_read_from_str(ctx
, str
);
970 n
= isl_basic_set_dim(bset
, isl_dim_div
);
971 isl_basic_set_free(bset
);
975 isl_die(ctx
, isl_error_unknown
,
976 "expecting no existentials", return -1);
978 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
979 set
= isl_set_read_from_str(ctx
, str
);
980 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
981 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
982 empty
= isl_set_is_empty(set
);
987 isl_die(ctx
, isl_error_unknown
,
988 "result not as accurate as expected", return -1);
993 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
997 struct isl_basic_set
*bset1
, *bset2
;
998 struct isl_basic_map
*bmap
;
1000 filename
= get_filename(ctx
, name
, "omega");
1002 input
= fopen(filename
, "r");
1005 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1006 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1008 bset1
= isl_basic_set_apply(bset1
, bmap
);
1010 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1012 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1014 isl_basic_set_free(bset1
);
1015 isl_basic_set_free(bset2
);
1021 static int test_application(isl_ctx
*ctx
)
1023 test_application_case(ctx
, "application");
1024 test_application_case(ctx
, "application2");
1029 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1033 struct isl_basic_set
*bset1
, *bset2
;
1035 filename
= get_filename(ctx
, name
, "polylib");
1037 input
= fopen(filename
, "r");
1040 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1041 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1043 bset1
= isl_basic_set_affine_hull(bset1
);
1045 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1047 isl_basic_set_free(bset1
);
1048 isl_basic_set_free(bset2
);
1054 int test_affine_hull(struct isl_ctx
*ctx
)
1058 isl_basic_set
*bset
, *bset2
;
1062 test_affine_hull_case(ctx
, "affine2");
1063 test_affine_hull_case(ctx
, "affine");
1064 test_affine_hull_case(ctx
, "affine3");
1066 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1067 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1068 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1069 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1070 set
= isl_set_read_from_str(ctx
, str
);
1071 bset
= isl_set_affine_hull(set
);
1072 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1073 isl_basic_set_free(bset
);
1075 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1078 /* Check that isl_map_affine_hull is not confused by
1079 * the reordering of divs in isl_map_align_divs.
1081 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1082 "32e0 = b and 32e1 = c); "
1083 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1084 set
= isl_set_read_from_str(ctx
, str
);
1085 bset
= isl_set_affine_hull(set
);
1086 isl_basic_set_free(bset
);
1090 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1091 "32e2 = 31 + 31e0 }";
1092 set
= isl_set_read_from_str(ctx
, str
);
1093 bset
= isl_set_affine_hull(set
);
1094 str
= "{ [a] : exists e : a = 32 e }";
1095 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1096 subset
= isl_basic_set_is_subset(bset
, bset2
);
1097 isl_basic_set_free(bset
);
1098 isl_basic_set_free(bset2
);
1102 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1108 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1112 struct isl_basic_set
*bset1
, *bset2
;
1113 struct isl_set
*set
;
1115 filename
= get_filename(ctx
, name
, "polylib");
1117 input
= fopen(filename
, "r");
1120 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1121 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1123 set
= isl_basic_set_union(bset1
, bset2
);
1124 bset1
= isl_set_convex_hull(set
);
1126 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1128 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1130 isl_basic_set_free(bset1
);
1131 isl_basic_set_free(bset2
);
1140 } convex_hull_tests
[] = {
1141 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1142 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1143 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1144 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1145 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1146 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1147 "i2 <= 5 and i2 >= 4; "
1148 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1149 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1150 "i2 <= 5 + i0 and i2 >= i0 }" },
1151 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1152 "{ [x, y] : 1 = 0 }" },
1155 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1158 int orig_convex
= ctx
->opt
->convex
;
1159 ctx
->opt
->convex
= convex
;
1161 test_convex_hull_case(ctx
, "convex0");
1162 test_convex_hull_case(ctx
, "convex1");
1163 test_convex_hull_case(ctx
, "convex2");
1164 test_convex_hull_case(ctx
, "convex3");
1165 test_convex_hull_case(ctx
, "convex4");
1166 test_convex_hull_case(ctx
, "convex5");
1167 test_convex_hull_case(ctx
, "convex6");
1168 test_convex_hull_case(ctx
, "convex7");
1169 test_convex_hull_case(ctx
, "convex8");
1170 test_convex_hull_case(ctx
, "convex9");
1171 test_convex_hull_case(ctx
, "convex10");
1172 test_convex_hull_case(ctx
, "convex11");
1173 test_convex_hull_case(ctx
, "convex12");
1174 test_convex_hull_case(ctx
, "convex13");
1175 test_convex_hull_case(ctx
, "convex14");
1176 test_convex_hull_case(ctx
, "convex15");
1178 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1179 isl_set
*set1
, *set2
;
1182 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1183 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1184 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1185 equal
= isl_set_is_equal(set1
, set2
);
1192 isl_die(ctx
, isl_error_unknown
,
1193 "unexpected convex hull", return -1);
1196 ctx
->opt
->convex
= orig_convex
;
1201 static int test_convex_hull(isl_ctx
*ctx
)
1203 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1205 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1210 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1214 struct isl_basic_set
*bset1
, *bset2
;
1216 filename
= get_filename(ctx
, name
, "polylib");
1218 input
= fopen(filename
, "r");
1221 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1222 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1224 bset1
= isl_basic_set_gist(bset1
, bset2
);
1226 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1228 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1230 isl_basic_set_free(bset1
);
1231 isl_basic_set_free(bset2
);
1239 const char *context
;
1242 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1243 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1244 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1245 "{ [a, b, c] : a <= 15 }" },
1246 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1247 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1248 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1249 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1250 { "{ [m, n, a, b] : a <= 2147 + n }",
1251 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1252 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1253 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1255 "{ [m, n, ku, kl] }" },
1258 static int test_gist(struct isl_ctx
*ctx
)
1262 isl_basic_set
*bset1
, *bset2
;
1263 isl_map
*map1
, *map2
;
1266 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1268 isl_set
*set1
, *set2
, *copy
;
1270 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1271 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1272 copy
= isl_set_copy(set1
);
1273 set1
= isl_set_gist(set1
, set2
);
1274 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1275 equal
= isl_set_is_equal(set1
, set2
);
1278 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1279 equal_input
= isl_set_is_equal(set1
, copy
);
1282 if (equal
< 0 || equal_input
< 0)
1285 isl_die(ctx
, isl_error_unknown
,
1286 "incorrect gist result", return -1);
1288 isl_die(ctx
, isl_error_unknown
,
1289 "gist modified input", return -1);
1292 test_gist_case(ctx
, "gist1");
1294 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1295 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1296 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1297 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1298 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1299 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1300 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1301 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1302 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1303 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1304 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1305 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1306 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1307 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1308 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1309 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1310 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1311 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1312 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1313 bset1
= isl_basic_set_gist(bset1
, bset2
);
1314 assert(bset1
&& bset1
->n_div
== 0);
1315 isl_basic_set_free(bset1
);
1317 /* Check that the integer divisions of the second disjunct
1318 * do not spread to the first disjunct.
1320 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1321 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1322 "(exists (e0 = [(-1 + t1)/16], "
1323 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1324 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1325 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1326 "o0 <= 4294967295 and t1 <= -1)) }";
1327 map1
= isl_map_read_from_str(ctx
, str
);
1328 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1329 map2
= isl_map_read_from_str(ctx
, str
);
1330 map1
= isl_map_gist(map1
, map2
);
1334 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1335 isl_map_free(map1
); return -1);
1336 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1337 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1338 isl_map_free(map1
); return -1);
1344 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1346 isl_set
*set
, *set2
;
1350 set
= isl_set_read_from_str(ctx
, str
);
1351 set
= isl_set_coalesce(set
);
1352 set2
= isl_set_read_from_str(ctx
, str
);
1353 equal
= isl_set_is_equal(set
, set2
);
1354 one
= set
&& set
->n
== 1;
1361 isl_die(ctx
, isl_error_unknown
,
1362 "coalesced set not equal to input", return -1);
1363 if (check_one
&& !one
)
1364 isl_die(ctx
, isl_error_unknown
,
1365 "coalesced set should not be a union", return -1);
1370 /* Inputs for coalescing tests with unbounded wrapping.
1371 * "str" is a string representation of the input set.
1372 * "single_disjunct" is set if we expect the result to consist of
1373 * a single disjunct.
1376 int single_disjunct
;
1378 } coalesce_unbounded_tests
[] = {
1379 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1380 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1381 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1382 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1384 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1385 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1386 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1387 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1390 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1391 * option turned off.
1393 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1399 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1400 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1402 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
1403 const char *str
= coalesce_unbounded_tests
[i
].str
;
1404 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
1405 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
1411 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1416 /* Inputs for coalescing tests.
1417 * "str" is a string representation of the input set.
1418 * "single_disjunct" is set if we expect the result to consist of
1419 * a single disjunct.
1422 int single_disjunct
;
1424 } coalesce_tests
[] = {
1425 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1426 "y >= x & x >= 2 & 5 >= y }" },
1427 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1428 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1429 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1430 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1431 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1432 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1433 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1434 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1435 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1436 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1437 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1438 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1439 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1440 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1441 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1442 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1443 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1444 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1445 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1446 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1447 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1448 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1449 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1450 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1451 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1452 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1453 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1454 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1455 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1456 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1457 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1458 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1459 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1460 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1461 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1462 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1463 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1464 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1465 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1466 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1467 "[o0, o1, o2, o3, o4, o5, o6]] : "
1468 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1469 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1470 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1471 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1472 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1473 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1474 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1475 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1476 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1477 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1478 "o6 >= i3 + i6 - o3 and M >= 0 and "
1479 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1480 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1481 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1482 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1483 "(o0 = 0 and M >= 2 and N >= 3) or "
1484 "(M = 0 and o0 = 0 and N >= 3) }" },
1485 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1486 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1487 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1488 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1489 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1490 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1491 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1492 "(y = 3 and x = 1) }" },
1493 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1494 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1495 "i1 <= M and i3 <= M and i4 <= M) or "
1496 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1497 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1498 "i4 <= -1 + M) }" },
1499 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1500 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1501 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1502 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1503 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1504 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1505 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1506 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1507 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1508 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1509 { 0, "{ [a, b] : exists e : 2e = a and "
1510 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1511 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1512 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1513 "j >= 1 and j' <= i + j - i' and i >= 1; "
1515 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1516 "[i,j] : exists a : j = 3a }" },
1517 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1518 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1520 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1521 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1522 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1523 "c <= 6 + 8a and a >= 3; "
1524 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1525 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1526 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1527 "[x,0] : 3 <= x <= 4 }" },
1528 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1529 "[x,0] : 4 <= x <= 5 }" },
1530 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1531 "[x,0] : 3 <= x <= 5 }" },
1532 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1533 "[x,0] : 3 <= x <= 4 }" },
1534 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1536 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1537 { 1, "{ [0,0]; [1,1] }" },
1538 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
1539 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
1541 "[k, 0, k] : k <= 6 and k >= 1 }" },
1542 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
1543 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
1544 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
1545 { 1, "[n] -> { [1] : n >= 0;"
1546 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
1547 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
1548 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
1549 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
1550 "2e0 <= x and 2e0 <= n);"
1551 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
1553 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
1554 "128e0 >= -134 + 127t1 and t1 >= 2 and "
1555 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
1557 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
1558 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
1560 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
1561 "t1 >= 13 and t1 <= 16);"
1562 "[t1] : t1 <= 15 and t1 >= 12 }" },
1563 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
1564 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
1565 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
1566 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
1567 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
1568 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
1570 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
1571 "(exists (e0 : 3e0 = -2 + c0)) }" },
1572 { 0, "[n, b0, t0] -> "
1573 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1574 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1575 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
1576 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
1577 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
1578 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
1579 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
1580 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
1581 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1582 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
1583 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
1584 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
1585 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
1586 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
1587 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
1588 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
1589 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
1590 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
1591 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
1592 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
1593 { 0, "{ [i0, i1, i2] : "
1594 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
1595 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
1596 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
1597 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
1598 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
1599 "32e0 <= 31 + i0)) or "
1603 /* A specialized coalescing test case that would result
1604 * in a segmentation fault or a failed assertion in earlier versions of isl.
1606 static int test_coalesce_special(struct isl_ctx
*ctx
)
1609 isl_map
*map1
, *map2
;
1611 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
1612 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
1613 "(y = 201 and o1 <= 239 and o1 >= 212) or "
1614 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
1615 "o1 <= 239 and o1 >= 212)) or "
1616 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
1617 "o1 <= 241 and o1 >= 240));"
1618 "[S_L220_OUT[] -> T7[]] -> "
1619 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
1620 "(y = 2 and o1 <= 241 and o1 >= 212) or "
1621 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
1622 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
1623 map1
= isl_map_read_from_str(ctx
, str
);
1624 map1
= isl_map_align_divs(map1
);
1625 map1
= isl_map_coalesce(map1
);
1626 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
1627 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
1628 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
1629 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
1630 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
1631 map2
= isl_map_read_from_str(ctx
, str
);
1632 map2
= isl_map_union(map2
, map1
);
1633 map2
= isl_map_align_divs(map2
);
1634 map2
= isl_map_coalesce(map2
);
1642 /* Test the functionality of isl_set_coalesce.
1643 * That is, check that the output is always equal to the input
1644 * and in some cases that the result consists of a single disjunct.
1646 static int test_coalesce(struct isl_ctx
*ctx
)
1650 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
1651 const char *str
= coalesce_tests
[i
].str
;
1652 int check_one
= coalesce_tests
[i
].single_disjunct
;
1653 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
1657 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
1659 if (test_coalesce_special(ctx
) < 0)
1665 static int test_closure(isl_ctx
*ctx
)
1669 isl_map
*up
, *right
;
1670 isl_map
*map
, *map2
;
1673 /* COCOA example 1 */
1674 map
= isl_map_read_from_str(ctx
,
1675 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1676 "1 <= i and i < n and 1 <= j and j < n or "
1677 "i2 = i + 1 and j2 = j - 1 and "
1678 "1 <= i and i < n and 2 <= j and j <= n }");
1679 map
= isl_map_power(map
, &exact
);
1683 /* COCOA example 1 */
1684 map
= isl_map_read_from_str(ctx
,
1685 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1686 "1 <= i and i < n and 1 <= j and j < n or "
1687 "i2 = i + 1 and j2 = j - 1 and "
1688 "1 <= i and i < n and 2 <= j and j <= n }");
1689 map
= isl_map_transitive_closure(map
, &exact
);
1691 map2
= isl_map_read_from_str(ctx
,
1692 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1693 "1 <= i and i < n and 1 <= j and j <= n and "
1694 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1695 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1696 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1697 assert(isl_map_is_equal(map
, map2
));
1701 map
= isl_map_read_from_str(ctx
,
1702 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1703 " 0 <= y and y <= n }");
1704 map
= isl_map_transitive_closure(map
, &exact
);
1705 map2
= isl_map_read_from_str(ctx
,
1706 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1707 " 0 <= y and y <= n }");
1708 assert(isl_map_is_equal(map
, map2
));
1712 /* COCOA example 2 */
1713 map
= isl_map_read_from_str(ctx
,
1714 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1715 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1716 "i2 = i + 2 and j2 = j - 2 and "
1717 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1718 map
= isl_map_transitive_closure(map
, &exact
);
1720 map2
= isl_map_read_from_str(ctx
,
1721 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1722 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1723 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1724 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1725 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1726 assert(isl_map_is_equal(map
, map2
));
1730 /* COCOA Fig.2 left */
1731 map
= isl_map_read_from_str(ctx
,
1732 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1733 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1735 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1736 "j <= 2 i - 3 and j <= n - 2 or "
1737 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1738 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1739 map
= isl_map_transitive_closure(map
, &exact
);
1743 /* COCOA Fig.2 right */
1744 map
= isl_map_read_from_str(ctx
,
1745 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1746 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1748 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1749 "j <= 2 i - 4 and j <= n - 3 or "
1750 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1751 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1752 map
= isl_map_power(map
, &exact
);
1756 /* COCOA Fig.2 right */
1757 map
= isl_map_read_from_str(ctx
,
1758 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1759 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1761 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1762 "j <= 2 i - 4 and j <= n - 3 or "
1763 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1764 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1765 map
= isl_map_transitive_closure(map
, &exact
);
1767 map2
= isl_map_read_from_str(ctx
,
1768 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1769 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1770 "j <= n and 3 + i + 2 j <= 3 n and "
1771 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1772 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1773 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1774 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1775 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1776 assert(isl_map_is_equal(map
, map2
));
1780 /* COCOA Fig.1 right */
1781 dom
= isl_set_read_from_str(ctx
,
1782 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1783 "2 x - 3 y + 3 >= 0 }");
1784 right
= isl_map_read_from_str(ctx
,
1785 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1786 up
= isl_map_read_from_str(ctx
,
1787 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1788 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1789 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1790 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1791 up
= isl_map_intersect_range(up
, dom
);
1792 map
= isl_map_union(up
, right
);
1793 map
= isl_map_transitive_closure(map
, &exact
);
1795 map2
= isl_map_read_from_str(ctx
,
1796 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1797 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1798 assert(isl_map_is_equal(map
, map2
));
1802 /* COCOA Theorem 1 counter example */
1803 map
= isl_map_read_from_str(ctx
,
1804 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1805 "i2 = 1 and j2 = j or "
1806 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1807 map
= isl_map_transitive_closure(map
, &exact
);
1811 map
= isl_map_read_from_str(ctx
,
1812 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1813 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1814 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1815 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1816 map
= isl_map_transitive_closure(map
, &exact
);
1820 /* Kelly et al 1996, fig 12 */
1821 map
= isl_map_read_from_str(ctx
,
1822 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1823 "1 <= i,j,j+1 <= n or "
1824 "j = n and j2 = 1 and i2 = i + 1 and "
1825 "1 <= i,i+1 <= n }");
1826 map
= isl_map_transitive_closure(map
, &exact
);
1828 map2
= isl_map_read_from_str(ctx
,
1829 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1830 "1 <= i <= n and i = i2 or "
1831 "1 <= i < i2 <= n and 1 <= j <= n and "
1833 assert(isl_map_is_equal(map
, map2
));
1837 /* Omega's closure4 */
1838 map
= isl_map_read_from_str(ctx
,
1839 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1840 "1 <= x,y <= 10 or "
1841 "x2 = x + 1 and y2 = y and "
1842 "1 <= x <= 20 && 5 <= y <= 15 }");
1843 map
= isl_map_transitive_closure(map
, &exact
);
1847 map
= isl_map_read_from_str(ctx
,
1848 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1849 map
= isl_map_transitive_closure(map
, &exact
);
1851 map2
= isl_map_read_from_str(ctx
,
1852 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1853 assert(isl_map_is_equal(map
, map2
));
1857 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1858 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1859 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1860 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1861 map
= isl_map_read_from_str(ctx
, str
);
1862 map
= isl_map_transitive_closure(map
, &exact
);
1864 map2
= isl_map_read_from_str(ctx
, str
);
1865 assert(isl_map_is_equal(map
, map2
));
1869 str
= "{[0] -> [1]; [2] -> [3]}";
1870 map
= isl_map_read_from_str(ctx
, str
);
1871 map
= isl_map_transitive_closure(map
, &exact
);
1873 map2
= isl_map_read_from_str(ctx
, str
);
1874 assert(isl_map_is_equal(map
, map2
));
1878 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1879 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1880 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1881 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1882 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1883 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1884 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1885 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1886 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1887 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1888 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1889 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1890 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1891 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1892 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1893 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1894 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1895 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1896 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1897 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1898 map
= isl_map_read_from_str(ctx
, str
);
1899 map
= isl_map_transitive_closure(map
, NULL
);
1906 static int test_lex(struct isl_ctx
*ctx
)
1912 dim
= isl_space_set_alloc(ctx
, 0, 0);
1913 map
= isl_map_lex_le(dim
);
1914 empty
= isl_map_is_empty(map
);
1920 isl_die(ctx
, isl_error_unknown
,
1921 "expecting non-empty result", return -1);
1926 static int test_lexmin(struct isl_ctx
*ctx
)
1930 isl_basic_map
*bmap
;
1931 isl_map
*map
, *map2
;
1934 isl_pw_multi_aff
*pma
;
1936 str
= "[p0, p1] -> { [] -> [] : "
1937 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1938 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1939 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1940 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1941 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1942 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1943 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1944 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1945 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1946 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1947 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1948 map
= isl_map_read_from_str(ctx
, str
);
1949 map
= isl_map_lexmin(map
);
1952 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1953 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1954 set
= isl_set_read_from_str(ctx
, str
);
1955 set
= isl_set_lexmax(set
);
1956 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1957 set2
= isl_set_read_from_str(ctx
, str
);
1958 set
= isl_set_intersect(set
, set2
);
1959 assert(!isl_set_is_empty(set
));
1962 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1963 map
= isl_map_read_from_str(ctx
, str
);
1964 map
= isl_map_lexmin(map
);
1965 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1966 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1967 map2
= isl_map_read_from_str(ctx
, str
);
1968 assert(isl_map_is_equal(map
, map2
));
1972 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1973 map
= isl_map_read_from_str(ctx
, str
);
1974 map2
= isl_map_copy(map
);
1975 map
= isl_map_lexmin(map
);
1976 assert(isl_map_is_equal(map
, map2
));
1980 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1981 map
= isl_map_read_from_str(ctx
, str
);
1982 map
= isl_map_lexmin(map
);
1983 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1984 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1985 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1986 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1987 map2
= isl_map_read_from_str(ctx
, str
);
1988 assert(isl_map_is_equal(map
, map2
));
1992 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1993 " 8i' <= i and 8i' >= -7 + i }";
1994 bmap
= isl_basic_map_read_from_str(ctx
, str
);
1995 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
1996 map2
= isl_map_from_pw_multi_aff(pma
);
1997 map
= isl_map_from_basic_map(bmap
);
1998 assert(isl_map_is_equal(map
, map2
));
2002 str
= "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
2003 map
= isl_map_read_from_str(ctx
, str
);
2004 map
= isl_map_lexmin(map
);
2005 str
= "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
2006 map2
= isl_map_read_from_str(ctx
, str
);
2007 assert(isl_map_is_equal(map
, map2
));
2011 /* Check that empty pieces are properly combined. */
2012 str
= "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2013 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2014 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }";
2015 map
= isl_map_read_from_str(ctx
, str
);
2016 map
= isl_map_lexmin(map
);
2017 str
= "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2018 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2020 map2
= isl_map_read_from_str(ctx
, str
);
2021 assert(isl_map_is_equal(map
, map2
));
2025 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2026 " 8i' <= i and 8i' >= -7 + i }";
2027 set
= isl_set_read_from_str(ctx
, str
);
2028 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
2029 set2
= isl_set_from_pw_multi_aff(pma
);
2030 equal
= isl_set_is_equal(set
, set2
);
2036 isl_die(ctx
, isl_error_unknown
,
2037 "unexpected difference between set and "
2038 "piecewise affine expression", return -1);
2043 /* Check that isl_set_min_val and isl_set_max_val compute the correct
2044 * result on non-convex inputs.
2046 static int test_min(struct isl_ctx
*ctx
)
2053 set
= isl_set_read_from_str(ctx
, "{ [-1]; [1] }");
2054 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x] }");
2055 val
= isl_set_min_val(set
, aff
);
2056 min_ok
= isl_val_is_negone(val
);
2058 val
= isl_set_max_val(set
, aff
);
2059 max_ok
= isl_val_is_one(val
);
2064 if (min_ok
< 0 || max_ok
< 0)
2067 isl_die(ctx
, isl_error_unknown
,
2068 "unexpected minimum", return -1);
2070 isl_die(ctx
, isl_error_unknown
,
2071 "unexpected maximum", return -1);
2081 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
2082 void *dep_user
, void *user
)
2084 struct must_may
*mm
= (struct must_may
*)user
;
2087 mm
->must
= isl_map_union(mm
->must
, dep
);
2089 mm
->may
= isl_map_union(mm
->may
, dep
);
2094 static int common_space(void *first
, void *second
)
2096 int depth
= *(int *)first
;
2100 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
2108 map2
= isl_map_read_from_str(map
->ctx
, str
);
2109 equal
= isl_map_is_equal(map
, map2
);
2115 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
2119 equal
= map_is_equal(map
, str
);
2123 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
2124 "result not as expected", return -1);
2128 static int test_dep(struct isl_ctx
*ctx
)
2133 isl_access_info
*ai
;
2140 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2141 map
= isl_map_read_from_str(ctx
, str
);
2142 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2144 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2145 map
= isl_map_read_from_str(ctx
, str
);
2146 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2148 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2149 map
= isl_map_read_from_str(ctx
, str
);
2150 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2152 flow
= isl_access_info_compute_flow(ai
);
2153 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2154 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2155 mm
.may
= isl_map_empty(dim
);
2157 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2159 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
2160 " [1,10,0] -> [2,5,0] }";
2161 assert(map_is_equal(mm
.must
, str
));
2162 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2163 assert(map_is_equal(mm
.may
, str
));
2165 isl_map_free(mm
.must
);
2166 isl_map_free(mm
.may
);
2167 isl_flow_free(flow
);
2170 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2171 map
= isl_map_read_from_str(ctx
, str
);
2172 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2174 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2175 map
= isl_map_read_from_str(ctx
, str
);
2176 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2178 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2179 map
= isl_map_read_from_str(ctx
, str
);
2180 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2182 flow
= isl_access_info_compute_flow(ai
);
2183 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2184 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2185 mm
.may
= isl_map_empty(dim
);
2187 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2189 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2190 assert(map_is_equal(mm
.must
, str
));
2191 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2192 assert(map_is_equal(mm
.may
, str
));
2194 isl_map_free(mm
.must
);
2195 isl_map_free(mm
.may
);
2196 isl_flow_free(flow
);
2199 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2200 map
= isl_map_read_from_str(ctx
, str
);
2201 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2203 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2204 map
= isl_map_read_from_str(ctx
, str
);
2205 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2207 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2208 map
= isl_map_read_from_str(ctx
, str
);
2209 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2211 flow
= isl_access_info_compute_flow(ai
);
2212 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2213 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2214 mm
.may
= isl_map_empty(dim
);
2216 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2218 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
2219 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2220 assert(map_is_equal(mm
.may
, str
));
2221 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2222 assert(map_is_equal(mm
.must
, str
));
2224 isl_map_free(mm
.must
);
2225 isl_map_free(mm
.may
);
2226 isl_flow_free(flow
);
2229 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
2230 map
= isl_map_read_from_str(ctx
, str
);
2231 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2233 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2234 map
= isl_map_read_from_str(ctx
, str
);
2235 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2237 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
2238 map
= isl_map_read_from_str(ctx
, str
);
2239 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2241 flow
= isl_access_info_compute_flow(ai
);
2242 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2243 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2244 mm
.may
= isl_map_empty(dim
);
2246 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2248 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2249 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2250 assert(map_is_equal(mm
.may
, str
));
2251 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2252 assert(map_is_equal(mm
.must
, str
));
2254 isl_map_free(mm
.must
);
2255 isl_map_free(mm
.may
);
2256 isl_flow_free(flow
);
2259 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2260 map
= isl_map_read_from_str(ctx
, str
);
2261 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2263 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2264 map
= isl_map_read_from_str(ctx
, str
);
2265 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2267 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2268 map
= isl_map_read_from_str(ctx
, str
);
2269 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2271 flow
= isl_access_info_compute_flow(ai
);
2272 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2273 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2274 mm
.may
= isl_map_empty(dim
);
2276 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2278 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2279 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2280 assert(map_is_equal(mm
.may
, str
));
2281 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2282 assert(map_is_equal(mm
.must
, str
));
2284 isl_map_free(mm
.must
);
2285 isl_map_free(mm
.may
);
2286 isl_flow_free(flow
);
2291 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2292 map
= isl_map_read_from_str(ctx
, str
);
2293 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
2295 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2296 map
= isl_map_read_from_str(ctx
, str
);
2297 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2299 flow
= isl_access_info_compute_flow(ai
);
2300 dim
= isl_space_alloc(ctx
, 0, 5, 5);
2301 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2302 mm
.may
= isl_map_empty(dim
);
2304 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2306 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
2307 assert(map_is_equal(mm
.must
, str
));
2308 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
2309 assert(map_is_equal(mm
.may
, str
));
2311 isl_map_free(mm
.must
);
2312 isl_map_free(mm
.may
);
2313 isl_flow_free(flow
);
2318 /* Check that the dependence analysis proceeds without errors.
2319 * Earlier versions of isl would break down during the analysis
2320 * due to the use of the wrong spaces.
2322 static int test_flow(isl_ctx
*ctx
)
2325 isl_union_map
*access
, *schedule
;
2326 isl_union_map
*must_dep
, *may_dep
;
2329 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
2330 access
= isl_union_map_read_from_str(ctx
, str
);
2331 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
2332 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
2333 "S2[] -> [1,0,0,0]; "
2334 "S3[] -> [-1,0,0,0] }";
2335 schedule
= isl_union_map_read_from_str(ctx
, str
);
2336 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
2337 isl_union_map_copy(access
), schedule
,
2338 &must_dep
, &may_dep
, NULL
, NULL
);
2339 isl_union_map_free(may_dep
);
2340 isl_union_map_free(must_dep
);
2349 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
2350 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
2351 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
2352 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
2353 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
2354 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
2355 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2356 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2357 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
2360 int test_sv(isl_ctx
*ctx
)
2362 isl_union_map
*umap
;
2366 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
2367 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
2368 sv
= isl_union_map_is_single_valued(umap
);
2369 isl_union_map_free(umap
);
2372 if (sv_tests
[i
].sv
&& !sv
)
2373 isl_die(ctx
, isl_error_internal
,
2374 "map not detected as single valued", return -1);
2375 if (!sv_tests
[i
].sv
&& sv
)
2376 isl_die(ctx
, isl_error_internal
,
2377 "map detected as single valued", return -1);
2386 } bijective_tests
[] = {
2387 { "[N,M]->{[i,j] -> [i]}", 0 },
2388 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
2389 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
2390 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
2391 { "[N,M]->{[i,j] -> [j,i]}", 1 },
2392 { "[N,M]->{[i,j] -> [i+j]}", 0 },
2393 { "[N,M]->{[i,j] -> []}", 0 },
2394 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
2395 { "[N,M]->{[i,j] -> [2i]}", 0 },
2396 { "[N,M]->{[i,j] -> [i,i]}", 0 },
2397 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
2398 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
2399 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
2402 static int test_bijective(struct isl_ctx
*ctx
)
2408 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
2409 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
2410 bijective
= isl_map_is_bijective(map
);
2414 if (bijective_tests
[i
].bijective
&& !bijective
)
2415 isl_die(ctx
, isl_error_internal
,
2416 "map not detected as bijective", return -1);
2417 if (!bijective_tests
[i
].bijective
&& bijective
)
2418 isl_die(ctx
, isl_error_internal
,
2419 "map detected as bijective", return -1);
2425 /* Inputs for isl_pw_qpolynomial_gist tests.
2426 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
2432 } pwqp_gist_tests
[] = {
2433 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
2434 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
2435 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
2436 "{ [i] -> -1/2 + 1/2 * i }" },
2437 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
2440 static int test_pwqp(struct isl_ctx
*ctx
)
2445 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
2448 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2449 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2451 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
2454 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2455 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2457 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2459 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2461 isl_pw_qpolynomial_free(pwqp1
);
2463 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
2464 str
= pwqp_gist_tests
[i
].pwqp
;
2465 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2466 str
= pwqp_gist_tests
[i
].set
;
2467 set
= isl_set_read_from_str(ctx
, str
);
2468 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2469 str
= pwqp_gist_tests
[i
].gist
;
2470 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2471 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2472 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
2473 isl_pw_qpolynomial_free(pwqp1
);
2478 isl_die(ctx
, isl_error_unknown
,
2479 "unexpected result", return -1);
2482 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
2483 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2484 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
2485 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2487 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2489 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2491 isl_pw_qpolynomial_free(pwqp1
);
2493 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
2494 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2495 str
= "{ [x] -> x }";
2496 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2498 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2500 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2502 isl_pw_qpolynomial_free(pwqp1
);
2504 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
2505 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2506 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2507 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
2508 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2509 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2510 isl_pw_qpolynomial_free(pwqp1
);
2512 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
2513 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2514 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2515 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2516 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
2517 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
2518 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2519 isl_pw_qpolynomial_free(pwqp1
);
2520 isl_pw_qpolynomial_free(pwqp2
);
2524 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2526 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
2527 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2528 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2529 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2530 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
2532 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2533 isl_pw_qpolynomial_free(pwqp1
);
2534 isl_pw_qpolynomial_free(pwqp2
);
2538 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2543 static int test_split_periods(isl_ctx
*ctx
)
2546 isl_pw_qpolynomial
*pwqp
;
2548 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
2549 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
2550 "U >= 0; [U,V] -> U^2 : U >= 100 }";
2551 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2553 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
2555 isl_pw_qpolynomial_free(pwqp
);
2563 static int test_union(isl_ctx
*ctx
)
2566 isl_union_set
*uset1
, *uset2
;
2567 isl_union_map
*umap1
, *umap2
;
2570 str
= "{ [i] : 0 <= i <= 1 }";
2571 uset1
= isl_union_set_read_from_str(ctx
, str
);
2572 str
= "{ [1] -> [0] }";
2573 umap1
= isl_union_map_read_from_str(ctx
, str
);
2575 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
2576 equal
= isl_union_map_is_equal(umap1
, umap2
);
2578 isl_union_map_free(umap1
);
2579 isl_union_map_free(umap2
);
2584 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
2587 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
2588 umap1
= isl_union_map_read_from_str(ctx
, str
);
2589 str
= "{ A[i]; B[i] }";
2590 uset1
= isl_union_set_read_from_str(ctx
, str
);
2592 uset2
= isl_union_map_domain(umap1
);
2594 equal
= isl_union_set_is_equal(uset1
, uset2
);
2596 isl_union_set_free(uset1
);
2597 isl_union_set_free(uset2
);
2602 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
2608 /* Check that computing a bound of a non-zero polynomial over an unbounded
2609 * domain does not produce a rational value.
2610 * In particular, check that the upper bound is infinity.
2612 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
2615 isl_pw_qpolynomial
*pwqp
;
2616 isl_pw_qpolynomial_fold
*pwf
, *pwf2
;
2619 str
= "{ [m,n] -> -m * n }";
2620 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2621 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2623 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2624 pwf2
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2625 equal
= isl_pw_qpolynomial_fold_plain_is_equal(pwf
, pwf2
);
2626 isl_pw_qpolynomial_fold_free(pwf
);
2627 isl_pw_qpolynomial_fold_free(pwf2
);
2632 isl_die(ctx
, isl_error_unknown
,
2633 "expecting infinite polynomial bound", return -1);
2638 static int test_bound(isl_ctx
*ctx
)
2642 isl_pw_qpolynomial
*pwqp
;
2643 isl_pw_qpolynomial_fold
*pwf
;
2645 if (test_bound_unbounded_domain(ctx
) < 0)
2648 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
2649 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2650 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2651 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
2652 isl_pw_qpolynomial_fold_free(pwf
);
2654 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
2657 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
2658 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2659 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2660 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
2661 isl_pw_qpolynomial_fold_free(pwf
);
2663 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
2669 static int test_lift(isl_ctx
*ctx
)
2672 isl_basic_map
*bmap
;
2673 isl_basic_set
*bset
;
2675 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
2676 bset
= isl_basic_set_read_from_str(ctx
, str
);
2677 bset
= isl_basic_set_lift(bset
);
2678 bmap
= isl_basic_map_from_range(bset
);
2679 bset
= isl_basic_map_domain(bmap
);
2680 isl_basic_set_free(bset
);
2689 } subset_tests
[] = {
2691 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
2692 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
2693 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
2695 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
2696 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
2697 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
2698 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
2699 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
2700 "256e0 <= 255i and 256e0 >= -255 + 255i and "
2701 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
2702 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
2703 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
2704 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
2705 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
2706 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
2707 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
2708 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
2709 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
2710 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
2711 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
2712 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
2713 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
2714 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
2715 "4e0 <= -57 + i0 + i1)) or "
2716 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
2717 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
2718 "4e0 >= -61 + i0 + i1)) or "
2719 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
2722 static int test_subset(isl_ctx
*ctx
)
2725 isl_set
*set1
, *set2
;
2728 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
2729 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
2730 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
2731 subset
= isl_set_is_subset(set1
, set2
);
2736 if (subset
!= subset_tests
[i
].subset
)
2737 isl_die(ctx
, isl_error_unknown
,
2738 "incorrect subset result", return -1);
2745 const char *minuend
;
2746 const char *subtrahend
;
2747 const char *difference
;
2748 } subtract_domain_tests
[] = {
2749 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
2750 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
2751 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
2754 static int test_subtract(isl_ctx
*ctx
)
2757 isl_union_map
*umap1
, *umap2
;
2758 isl_union_pw_multi_aff
*upma1
, *upma2
;
2759 isl_union_set
*uset
;
2762 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2763 umap1
= isl_union_map_read_from_str(ctx
,
2764 subtract_domain_tests
[i
].minuend
);
2765 uset
= isl_union_set_read_from_str(ctx
,
2766 subtract_domain_tests
[i
].subtrahend
);
2767 umap2
= isl_union_map_read_from_str(ctx
,
2768 subtract_domain_tests
[i
].difference
);
2769 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
2770 equal
= isl_union_map_is_equal(umap1
, umap2
);
2771 isl_union_map_free(umap1
);
2772 isl_union_map_free(umap2
);
2776 isl_die(ctx
, isl_error_unknown
,
2777 "incorrect subtract domain result", return -1);
2780 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2781 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
2782 subtract_domain_tests
[i
].minuend
);
2783 uset
= isl_union_set_read_from_str(ctx
,
2784 subtract_domain_tests
[i
].subtrahend
);
2785 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
2786 subtract_domain_tests
[i
].difference
);
2787 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
2788 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
2789 isl_union_pw_multi_aff_free(upma1
);
2790 isl_union_pw_multi_aff_free(upma2
);
2794 isl_die(ctx
, isl_error_unknown
,
2795 "incorrect subtract domain result", return -1);
2801 int test_factorize(isl_ctx
*ctx
)
2804 isl_basic_set
*bset
;
2807 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2808 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2809 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2810 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2811 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2812 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2813 "3i5 >= -2i0 - i2 + 3i4 }";
2814 bset
= isl_basic_set_read_from_str(ctx
, str
);
2815 f
= isl_basic_set_factorizer(bset
);
2816 isl_basic_set_free(bset
);
2817 isl_factorizer_free(f
);
2819 isl_die(ctx
, isl_error_unknown
,
2820 "failed to construct factorizer", return -1);
2822 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2823 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2824 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2825 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2826 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2827 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2828 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2829 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2830 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2831 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2832 bset
= isl_basic_set_read_from_str(ctx
, str
);
2833 f
= isl_basic_set_factorizer(bset
);
2834 isl_basic_set_free(bset
);
2835 isl_factorizer_free(f
);
2837 isl_die(ctx
, isl_error_unknown
,
2838 "failed to construct factorizer", return -1);
2843 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
2845 int *injective
= user
;
2847 *injective
= isl_map_is_injective(map
);
2850 if (*injective
< 0 || !*injective
)
2851 return isl_stat_error
;
2856 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
2857 const char *r
, const char *s
, int tilable
, int parallel
)
2861 isl_union_map
*W
, *R
, *S
;
2862 isl_union_map
*empty
;
2863 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
2864 isl_union_map
*validity
, *proximity
, *coincidence
;
2865 isl_union_map
*schedule
;
2866 isl_union_map
*test
;
2867 isl_union_set
*delta
;
2868 isl_union_set
*domain
;
2872 isl_schedule_constraints
*sc
;
2873 isl_schedule
*sched
;
2874 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
2876 D
= isl_union_set_read_from_str(ctx
, d
);
2877 W
= isl_union_map_read_from_str(ctx
, w
);
2878 R
= isl_union_map_read_from_str(ctx
, r
);
2879 S
= isl_union_map_read_from_str(ctx
, s
);
2881 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
2882 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
2884 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
2885 isl_union_map_compute_flow(isl_union_map_copy(R
),
2886 isl_union_map_copy(W
), empty
,
2887 isl_union_map_copy(S
),
2888 &dep_raw
, NULL
, NULL
, NULL
);
2889 isl_union_map_compute_flow(isl_union_map_copy(W
),
2890 isl_union_map_copy(W
),
2891 isl_union_map_copy(R
),
2892 isl_union_map_copy(S
),
2893 &dep_waw
, &dep_war
, NULL
, NULL
);
2895 dep
= isl_union_map_union(dep_waw
, dep_war
);
2896 dep
= isl_union_map_union(dep
, dep_raw
);
2897 validity
= isl_union_map_copy(dep
);
2898 coincidence
= isl_union_map_copy(dep
);
2899 proximity
= isl_union_map_copy(dep
);
2901 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
2902 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2903 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
2904 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2905 sched
= isl_schedule_constraints_compute_schedule(sc
);
2906 schedule
= isl_schedule_get_map(sched
);
2907 isl_schedule_free(sched
);
2908 isl_union_map_free(W
);
2909 isl_union_map_free(R
);
2910 isl_union_map_free(S
);
2913 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
2915 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
2916 is_complete
= isl_union_set_is_subset(D
, domain
);
2917 isl_union_set_free(D
);
2918 isl_union_set_free(domain
);
2920 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
2921 test
= isl_union_map_apply_range(test
, dep
);
2922 test
= isl_union_map_apply_range(test
, schedule
);
2924 delta
= isl_union_map_deltas(test
);
2925 if (isl_union_set_n_set(delta
) == 0) {
2929 isl_union_set_free(delta
);
2931 delta_set
= isl_set_from_union_set(delta
);
2933 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2934 for (i
= 0; i
< tilable
; ++i
)
2935 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
2936 is_tilable
= isl_set_is_subset(delta_set
, slice
);
2937 isl_set_free(slice
);
2939 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2940 for (i
= 0; i
< parallel
; ++i
)
2941 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
2942 is_parallel
= isl_set_is_subset(delta_set
, slice
);
2943 isl_set_free(slice
);
2945 origin
= isl_set_universe(isl_set_get_space(delta_set
));
2946 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
2947 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
2949 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
2950 delta_set
= isl_set_lexmin(delta_set
);
2952 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
2954 isl_set_free(origin
);
2955 isl_set_free(delta_set
);
2958 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
2959 is_injection
< 0 || is_complete
< 0)
2962 isl_die(ctx
, isl_error_unknown
,
2963 "generated schedule incomplete", return -1);
2965 isl_die(ctx
, isl_error_unknown
,
2966 "generated schedule not injective on each statement",
2969 isl_die(ctx
, isl_error_unknown
,
2970 "negative dependences in generated schedule",
2973 isl_die(ctx
, isl_error_unknown
,
2974 "generated schedule not as tilable as expected",
2977 isl_die(ctx
, isl_error_unknown
,
2978 "generated schedule not as parallel as expected",
2984 /* Compute a schedule for the given instance set, validity constraints,
2985 * proximity constraints and context and return a corresponding union map
2988 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
2989 const char *domain
, const char *validity
, const char *proximity
,
2990 const char *context
)
2995 isl_union_map
*prox
;
2996 isl_schedule_constraints
*sc
;
2997 isl_schedule
*schedule
;
2998 isl_union_map
*sched
;
3000 con
= isl_set_read_from_str(ctx
, context
);
3001 dom
= isl_union_set_read_from_str(ctx
, domain
);
3002 dep
= isl_union_map_read_from_str(ctx
, validity
);
3003 prox
= isl_union_map_read_from_str(ctx
, proximity
);
3004 sc
= isl_schedule_constraints_on_domain(dom
);
3005 sc
= isl_schedule_constraints_set_context(sc
, con
);
3006 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
3007 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
3008 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3009 sched
= isl_schedule_get_map(schedule
);
3010 isl_schedule_free(schedule
);
3015 /* Compute a schedule for the given instance set, validity constraints and
3016 * proximity constraints and return a corresponding union map representation.
3018 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
3019 const char *domain
, const char *validity
, const char *proximity
)
3021 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
3025 /* Check that a schedule can be constructed on the given domain
3026 * with the given validity and proximity constraints.
3028 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
3029 const char *validity
, const char *proximity
)
3031 isl_union_map
*sched
;
3033 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
3037 isl_union_map_free(sched
);
3041 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
3042 const char *validity
, const char *proximity
, const char *expected_sched
)
3044 isl_union_map
*sched1
, *sched2
;
3047 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
3048 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
3050 equal
= isl_union_map_is_equal(sched1
, sched2
);
3051 isl_union_map_free(sched1
);
3052 isl_union_map_free(sched2
);
3057 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
3063 /* Check that the schedule map is properly padded, even after being
3064 * reconstructed from the band forest.
3066 static int test_padded_schedule(isl_ctx
*ctx
)
3070 isl_union_map
*validity
, *proximity
;
3071 isl_schedule_constraints
*sc
;
3072 isl_schedule
*sched
;
3073 isl_union_map
*map1
, *map2
;
3074 isl_band_list
*list
;
3077 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
3078 D
= isl_union_set_read_from_str(ctx
, str
);
3079 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
3080 proximity
= isl_union_map_copy(validity
);
3081 sc
= isl_schedule_constraints_on_domain(D
);
3082 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3083 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3084 sched
= isl_schedule_constraints_compute_schedule(sc
);
3085 map1
= isl_schedule_get_map(sched
);
3086 list
= isl_schedule_get_band_forest(sched
);
3087 isl_band_list_free(list
);
3088 map2
= isl_schedule_get_map(sched
);
3089 isl_schedule_free(sched
);
3090 equal
= isl_union_map_is_equal(map1
, map2
);
3091 isl_union_map_free(map1
);
3092 isl_union_map_free(map2
);
3097 isl_die(ctx
, isl_error_unknown
,
3098 "reconstructed schedule map not the same as original",
3104 /* Check that conditional validity constraints are also taken into
3105 * account across bands.
3106 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
3107 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
3108 * and then check that the adjacent order constraint C[2,1]->D[2,0]
3109 * is enforced by the rest of the schedule.
3111 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
3114 isl_union_set
*domain
;
3115 isl_union_map
*validity
, *proximity
, *condition
;
3116 isl_union_map
*sink
, *source
, *dep
;
3117 isl_schedule_constraints
*sc
;
3118 isl_schedule
*schedule
;
3119 isl_union_access_info
*access
;
3120 isl_union_flow
*flow
;
3123 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3124 "A[k] : k >= 1 and k <= -1 + n; "
3125 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3126 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
3127 domain
= isl_union_set_read_from_str(ctx
, str
);
3128 sc
= isl_schedule_constraints_on_domain(domain
);
3129 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
3130 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3131 "D[k, i] -> C[1 + k, i] : "
3132 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3133 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
3134 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
3135 validity
= isl_union_map_read_from_str(ctx
, str
);
3136 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3137 str
= "[n] -> { C[k, i] -> D[k, i] : "
3138 "0 <= i <= -1 + k and k <= -1 + n }";
3139 proximity
= isl_union_map_read_from_str(ctx
, str
);
3140 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3141 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
3142 "i <= -1 + k and i >= 1 and k <= -2 + n; "
3143 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
3144 "k <= -1 + n and i >= 0 and i <= -2 + k }";
3145 condition
= isl_union_map_read_from_str(ctx
, str
);
3146 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
3147 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3148 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
3149 "i >= 0 and i <= -1 + k and k <= -1 + n and "
3150 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
3151 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
3152 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3153 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
3154 "k <= -1 + n and i >= 0 and i <= -1 + k and "
3155 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
3156 validity
= isl_union_map_read_from_str(ctx
, str
);
3157 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
3159 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3160 str
= "{ D[2,0] -> [] }";
3161 sink
= isl_union_map_read_from_str(ctx
, str
);
3162 access
= isl_union_access_info_from_sink(sink
);
3163 str
= "{ C[2,1] -> [] }";
3164 source
= isl_union_map_read_from_str(ctx
, str
);
3165 access
= isl_union_access_info_set_must_source(access
, source
);
3166 access
= isl_union_access_info_set_schedule(access
, schedule
);
3167 flow
= isl_union_access_info_compute_flow(access
);
3168 dep
= isl_union_flow_get_must_dependence(flow
);
3169 isl_union_flow_free(flow
);
3170 empty
= isl_union_map_is_empty(dep
);
3171 isl_union_map_free(dep
);
3176 isl_die(ctx
, isl_error_unknown
,
3177 "conditional validity not respected", return -1);
3182 /* Input for testing of schedule construction based on
3183 * conditional constraints.
3185 * domain is the iteration domain
3186 * flow are the flow dependences, which determine the validity and
3187 * proximity constraints
3188 * condition are the conditions on the conditional validity constraints
3189 * conditional_validity are the conditional validity constraints
3190 * outer_band_n is the expected number of members in the outer band
3195 const char *condition
;
3196 const char *conditional_validity
;
3198 } live_range_tests
[] = {
3199 /* Contrived example that illustrates that we need to keep
3200 * track of tagged condition dependences and
3201 * tagged conditional validity dependences
3202 * in isl_sched_edge separately.
3203 * In particular, the conditional validity constraints on A
3204 * cannot be satisfied,
3205 * but they can be ignored because there are no corresponding
3206 * condition constraints. However, we do have an additional
3207 * conditional validity constraint that maps to the same
3208 * dependence relation
3209 * as the condition constraint on B. If we did not make a distinction
3210 * between tagged condition and tagged conditional validity
3211 * dependences, then we
3212 * could end up treating this shared dependence as an condition
3213 * constraint on A, forcing a localization of the conditions,
3214 * which is impossible.
3216 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
3217 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
3218 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
3219 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3220 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3221 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
3224 /* TACO 2013 Fig. 7 */
3225 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
3226 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3227 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3228 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
3229 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
3230 "0 <= i < n and 0 <= j < n - 1 }",
3231 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
3232 "0 <= i < n and 0 <= j < j' < n;"
3233 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
3234 "0 <= i < i' < n and 0 <= j,j' < n;"
3235 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
3236 "0 <= i,j,j' < n and j < j' }",
3239 /* TACO 2013 Fig. 7, without tags */
3240 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
3241 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3242 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3243 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3244 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3245 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
3246 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
3247 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
3250 /* TACO 2013 Fig. 12 */
3251 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
3252 "S3[i,3] : 0 <= i <= 1 }",
3253 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
3254 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
3255 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
3256 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
3257 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
3258 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
3259 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
3260 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
3261 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
3262 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
3263 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
3268 /* Test schedule construction based on conditional constraints.
3269 * In particular, check the number of members in the outer band node
3270 * as an indication of whether tiling is possible or not.
3272 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
3275 isl_union_set
*domain
;
3276 isl_union_map
*condition
;
3277 isl_union_map
*flow
;
3278 isl_union_map
*validity
;
3279 isl_schedule_constraints
*sc
;
3280 isl_schedule
*schedule
;
3281 isl_schedule_node
*node
;
3284 if (test_special_conditional_schedule_constraints(ctx
) < 0)
3287 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
3288 domain
= isl_union_set_read_from_str(ctx
,
3289 live_range_tests
[i
].domain
);
3290 flow
= isl_union_map_read_from_str(ctx
,
3291 live_range_tests
[i
].flow
);
3292 condition
= isl_union_map_read_from_str(ctx
,
3293 live_range_tests
[i
].condition
);
3294 validity
= isl_union_map_read_from_str(ctx
,
3295 live_range_tests
[i
].conditional_validity
);
3296 sc
= isl_schedule_constraints_on_domain(domain
);
3297 sc
= isl_schedule_constraints_set_validity(sc
,
3298 isl_union_map_copy(flow
));
3299 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
3300 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
3301 condition
, validity
);
3302 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3303 node
= isl_schedule_get_root(schedule
);
3305 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
3306 node
= isl_schedule_node_first_child(node
);
3307 n_member
= isl_schedule_node_band_n_member(node
);
3308 isl_schedule_node_free(node
);
3309 isl_schedule_free(schedule
);
3313 if (n_member
!= live_range_tests
[i
].outer_band_n
)
3314 isl_die(ctx
, isl_error_unknown
,
3315 "unexpected number of members in outer band",
3321 /* Check that the schedule computed for the given instance set and
3322 * dependence relation strongly satisfies the dependences.
3323 * In particular, check that no instance is scheduled before
3324 * or together with an instance on which it depends.
3325 * Earlier versions of isl would produce a schedule that
3326 * only weakly satisfies the dependences.
3328 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
3330 const char *domain
, *dep
;
3331 isl_union_map
*D
, *schedule
;
3335 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
3336 "A[i0] : 0 <= i0 <= 1 }";
3337 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
3338 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
3339 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
3340 D
= isl_union_map_read_from_str(ctx
, dep
);
3341 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
3342 D
= isl_union_map_apply_range(D
, schedule
);
3343 map
= isl_map_from_union_map(D
);
3344 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
3345 map
= isl_map_intersect(map
, ge
);
3346 empty
= isl_map_is_empty(map
);
3352 isl_die(ctx
, isl_error_unknown
,
3353 "dependences not strongly satisfied", return -1);
3358 /* Compute a schedule for input where the instance set constraints
3359 * conflict with the context constraints.
3360 * Earlier versions of isl did not properly handle this situation.
3362 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
3364 isl_union_map
*schedule
;
3365 const char *domain
, *context
;
3367 domain
= "[n] -> { A[] : n >= 0 }";
3368 context
= "[n] -> { : n < 0 }";
3369 schedule
= compute_schedule_with_context(ctx
,
3370 domain
, "{}", "{}", context
);
3371 isl_union_map_free(schedule
);
3379 /* Check that the dependence carrying step is not confused by
3380 * a bound on the coefficient size.
3381 * In particular, force the scheduler to move to a dependence carrying
3382 * step by demanding outer coincidence and bound the size of
3383 * the coefficients. Earlier versions of isl would take this
3384 * bound into account while carrying dependences, breaking
3385 * fundamental assumptions.
3387 static int test_bounded_coefficients_schedule(isl_ctx
*ctx
)
3389 const char *domain
, *dep
;
3392 isl_schedule_constraints
*sc
;
3393 isl_schedule
*schedule
;
3395 domain
= "{ C[i0, i1] : 2 <= i0 <= 3999 and 0 <= i1 <= -1 + i0 }";
3396 dep
= "{ C[i0, i1] -> C[i0, 1 + i1] : i0 <= 3999 and i1 >= 0 and "
3398 "C[i0, -1 + i0] -> C[1 + i0, 0] : i0 <= 3998 and i0 >= 1 }";
3399 I
= isl_union_set_read_from_str(ctx
, domain
);
3400 D
= isl_union_map_read_from_str(ctx
, dep
);
3401 sc
= isl_schedule_constraints_on_domain(I
);
3402 sc
= isl_schedule_constraints_set_validity(sc
, isl_union_map_copy(D
));
3403 sc
= isl_schedule_constraints_set_coincidence(sc
, D
);
3404 isl_options_set_schedule_outer_coincidence(ctx
, 1);
3405 isl_options_set_schedule_max_coefficient(ctx
, 20);
3406 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3407 isl_options_set_schedule_max_coefficient(ctx
, -1);
3408 isl_options_set_schedule_outer_coincidence(ctx
, 0);
3409 isl_schedule_free(schedule
);
3417 int test_schedule(isl_ctx
*ctx
)
3419 const char *D
, *W
, *R
, *V
, *P
, *S
;
3421 /* Handle resulting schedule with zero bands. */
3422 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
3426 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
3427 W
= "{ S1[t,i] -> a[t,i] }";
3428 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
3429 "S1[t,i] -> a[t-1,i+1] }";
3430 S
= "{ S1[t,i] -> [t,i] }";
3431 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3434 /* Fig. 5 of CC2008 */
3435 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
3437 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
3438 "j >= 2 and j <= -1 + N }";
3439 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
3440 "j >= 2 and j <= -1 + N; "
3441 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
3442 "j >= 2 and j <= -1 + N }";
3443 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
3444 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3447 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
3448 W
= "{ S1[i] -> a[i] }";
3449 R
= "{ S2[i] -> a[i+1] }";
3450 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3451 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3454 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
3455 W
= "{ S1[i] -> a[i] }";
3456 R
= "{ S2[i] -> a[9-i] }";
3457 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3458 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3461 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
3462 W
= "{ S1[i] -> a[i] }";
3463 R
= "[N] -> { S2[i] -> a[N-1-i] }";
3464 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3465 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3468 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
3469 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
3470 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
3471 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
3472 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3475 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
3476 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
3477 R
= "{ S2[i,j] -> a[i-1,j] }";
3478 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
3479 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3482 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
3483 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
3484 R
= "{ S2[i,j] -> a[i,j-1] }";
3485 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
3486 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3489 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
3490 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
3491 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
3492 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
3493 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
3494 "S_0[] -> [0, 0, 0] }";
3495 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
3497 ctx
->opt
->schedule_parametric
= 0;
3498 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3500 ctx
->opt
->schedule_parametric
= 1;
3502 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
3503 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
3504 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
3505 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
3506 "S4[i] -> a[i,N] }";
3507 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
3508 "S4[i] -> [4,i,0] }";
3509 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3512 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
3513 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
3515 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
3517 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
3519 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
3520 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3523 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
3524 " S_2[t] : t >= 0 and t <= -1 + N; "
3525 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
3527 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
3528 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
3529 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
3530 "i >= 0 and i <= -1 + N }";
3531 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
3532 "i >= 0 and i <= -1 + N; "
3533 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
3534 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
3535 " S_0[t] -> [0, t, 0] }";
3537 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3539 ctx
->opt
->schedule_parametric
= 0;
3540 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3542 ctx
->opt
->schedule_parametric
= 1;
3544 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
3545 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
3546 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
3549 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
3550 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
3551 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
3552 "j >= 0 and j <= -1 + N; "
3553 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3554 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
3555 "j >= 0 and j <= -1 + N; "
3556 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3557 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
3558 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3561 D
= "{ S_0[i] : i >= 0 }";
3562 W
= "{ S_0[i] -> a[i] : i >= 0 }";
3563 R
= "{ S_0[i] -> a[0] : i >= 0 }";
3564 S
= "{ S_0[i] -> [0, i, 0] }";
3565 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3568 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
3569 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
3570 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
3571 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
3572 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3575 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
3576 "k <= -1 + n and k >= 0 }";
3577 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
3578 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
3579 "k <= -1 + n and k >= 0; "
3580 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
3581 "k <= -1 + n and k >= 0; "
3582 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
3583 "k <= -1 + n and k >= 0 }";
3584 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
3585 ctx
->opt
->schedule_outer_coincidence
= 1;
3586 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3588 ctx
->opt
->schedule_outer_coincidence
= 0;
3590 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
3591 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
3592 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
3593 "Stmt_for_body24[i0, i1, 1, 0]:"
3594 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
3595 "Stmt_for_body7[i0, i1, i2]:"
3596 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
3599 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
3600 "Stmt_for_body24[1, i1, i2, i3]:"
3601 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
3603 "Stmt_for_body24[0, i1, i2, i3] -> "
3604 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
3605 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
3607 "Stmt_for_body24[0, i1, i2, i3] ->"
3608 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
3609 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
3610 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
3611 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
3612 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
3613 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
3614 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
3615 "i1 <= 6 and i1 >= 0;"
3616 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
3617 "Stmt_for_body7[i0, i1, i2] -> "
3618 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
3619 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
3620 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
3621 "Stmt_for_body7[i0, i1, i2] -> "
3622 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
3623 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
3624 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
3626 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
3627 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
3628 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
3630 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3633 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
3634 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
3635 "j >= 1 and j <= 7;"
3636 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
3637 "j >= 1 and j <= 8 }";
3639 S
= "{ S_0[i, j] -> [i + j, j] }";
3640 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3641 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3643 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3645 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
3646 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
3647 "j >= 0 and j <= -1 + i }";
3648 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
3649 "i <= -1 + N and j >= 0;"
3650 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
3653 S
= "{ S_0[i, j] -> [i, j] }";
3654 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3655 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3657 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3659 /* Test both algorithms on a case with only proximity dependences. */
3660 D
= "{ S[i,j] : 0 <= i <= 10 }";
3662 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
3663 S
= "{ S[i, j] -> [j, i] }";
3664 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3665 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3667 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3668 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3671 D
= "{ A[a]; B[] }";
3673 P
= "{ A[a] -> B[] }";
3674 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3677 if (test_padded_schedule(ctx
) < 0)
3680 /* Check that check for progress is not confused by rational
3683 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
3684 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
3686 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
3687 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
3689 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3690 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3692 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3694 /* Check that we allow schedule rows that are only non-trivial
3695 * on some full-dimensional domains.
3697 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
3698 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
3699 "S1[j] -> S2[1] : 0 <= j <= 1 }";
3701 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3702 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3704 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3706 if (test_conditional_schedule_constraints(ctx
) < 0)
3709 if (test_strongly_satisfying_schedule(ctx
) < 0)
3712 if (test_conflicting_context_schedule(ctx
) < 0)
3715 if (test_bounded_coefficients_schedule(ctx
) < 0)
3721 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
3723 isl_union_map
*umap
;
3726 umap
= isl_union_map_read_from_str(ctx
, str
);
3727 test
= isl_union_map_plain_is_injective(umap
);
3728 isl_union_map_free(umap
);
3731 if (test
== injective
)
3734 isl_die(ctx
, isl_error_unknown
,
3735 "map not detected as injective", return -1);
3737 isl_die(ctx
, isl_error_unknown
,
3738 "map detected as injective", return -1);
3741 int test_injective(isl_ctx
*ctx
)
3745 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
3747 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
3749 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
3751 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
3753 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
3755 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
3757 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
3759 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
3762 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
3763 if (test_plain_injective(ctx
, str
, 1))
3765 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
3766 if (test_plain_injective(ctx
, str
, 0))
3772 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
3780 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
3781 equal
= isl_aff_plain_is_equal(aff
, aff2
);
3787 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
3791 equal
= aff_plain_is_equal(aff
, str
);
3795 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
3796 "result not as expected", return -1);
3801 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3802 __isl_take isl_aff
*aff2
);
3804 ['+'] = { &isl_aff_add
},
3805 ['-'] = { &isl_aff_sub
},
3806 ['*'] = { &isl_aff_mul
},
3807 ['/'] = { &isl_aff_div
},
3815 } aff_bin_tests
[] = {
3816 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
3817 "{ [i] -> [2i] }" },
3818 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
3820 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
3821 "{ [i] -> [2i] }" },
3822 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
3823 "{ [i] -> [2i] }" },
3824 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
3825 "{ [i] -> [i/2] }" },
3826 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
3828 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
3829 "{ [i] -> [NaN] }" },
3830 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
3831 "{ [i] -> [NaN] }" },
3832 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
3833 "{ [i] -> [NaN] }" },
3834 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
3835 "{ [i] -> [NaN] }" },
3836 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
3837 "{ [i] -> [NaN] }" },
3838 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
3839 "{ [i] -> [NaN] }" },
3840 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
3841 "{ [i] -> [NaN] }" },
3842 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
3843 "{ [i] -> [NaN] }" },
3844 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
3845 "{ [i] -> [NaN] }" },
3846 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
3847 "{ [i] -> [NaN] }" },
3848 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
3849 "{ [i] -> [NaN] }" },
3850 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
3851 "{ [i] -> [NaN] }" },
3854 /* Perform some basic tests of binary operations on isl_aff objects.
3856 static int test_bin_aff(isl_ctx
*ctx
)
3859 isl_aff
*aff1
, *aff2
, *res
;
3860 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3861 __isl_take isl_aff
*aff2
);
3864 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
3865 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
3866 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
3867 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
3868 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
3869 aff1
= fn(aff1
, aff2
);
3870 if (isl_aff_is_nan(res
))
3871 ok
= isl_aff_is_nan(aff1
);
3873 ok
= isl_aff_plain_is_equal(aff1
, res
);
3879 isl_die(ctx
, isl_error_unknown
,
3880 "unexpected result", return -1);
3887 __isl_give isl_union_pw_multi_aff
*(*fn
)(
3888 __isl_take isl_union_pw_multi_aff
*upma1
,
3889 __isl_take isl_union_pw_multi_aff
*upma2
);
3893 } upma_bin_tests
[] = {
3894 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
3895 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
3896 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
3897 "{ B[x] -> [2] : x >= 0 }",
3898 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
3901 /* Perform some basic tests of binary operations on
3902 * isl_union_pw_multi_aff objects.
3904 static int test_bin_upma(isl_ctx
*ctx
)
3907 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
3910 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
3911 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3912 upma_bin_tests
[i
].arg1
);
3913 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3914 upma_bin_tests
[i
].arg2
);
3915 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
3916 upma_bin_tests
[i
].res
);
3917 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
3918 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
3919 isl_union_pw_multi_aff_free(upma1
);
3920 isl_union_pw_multi_aff_free(res
);
3924 isl_die(ctx
, isl_error_unknown
,
3925 "unexpected result", return -1);
3931 int test_aff(isl_ctx
*ctx
)
3936 isl_local_space
*ls
;
3940 if (test_bin_aff(ctx
) < 0)
3942 if (test_bin_upma(ctx
) < 0)
3945 space
= isl_space_set_alloc(ctx
, 0, 1);
3946 ls
= isl_local_space_from_space(space
);
3947 aff
= isl_aff_zero_on_domain(ls
);
3949 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3950 aff
= isl_aff_scale_down_ui(aff
, 3);
3951 aff
= isl_aff_floor(aff
);
3952 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3953 aff
= isl_aff_scale_down_ui(aff
, 2);
3954 aff
= isl_aff_floor(aff
);
3955 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3958 set
= isl_set_read_from_str(ctx
, str
);
3959 aff
= isl_aff_gist(aff
, set
);
3961 aff
= isl_aff_add_constant_si(aff
, -16);
3962 zero
= isl_aff_plain_is_zero(aff
);
3968 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3970 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
3971 aff
= isl_aff_scale_down_ui(aff
, 64);
3972 aff
= isl_aff_floor(aff
);
3973 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
3981 int test_dim_max(isl_ctx
*ctx
)
3985 isl_set
*set1
, *set2
;
3990 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
3991 set
= isl_set_read_from_str(ctx
, str
);
3992 pwaff
= isl_set_dim_max(set
, 0);
3993 set1
= isl_set_from_pw_aff(pwaff
);
3994 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
3995 set2
= isl_set_read_from_str(ctx
, str
);
3996 equal
= isl_set_is_equal(set1
, set2
);
4002 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4004 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
4005 set
= isl_set_read_from_str(ctx
, str
);
4006 pwaff
= isl_set_dim_max(set
, 0);
4007 set1
= isl_set_from_pw_aff(pwaff
);
4008 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
4009 set2
= isl_set_read_from_str(ctx
, str
);
4010 equal
= isl_set_is_equal(set1
, set2
);
4016 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4018 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
4019 set
= isl_set_read_from_str(ctx
, str
);
4020 pwaff
= isl_set_dim_max(set
, 0);
4021 set1
= isl_set_from_pw_aff(pwaff
);
4022 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
4023 set2
= isl_set_read_from_str(ctx
, str
);
4024 equal
= isl_set_is_equal(set1
, set2
);
4030 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4032 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
4033 "0 <= i < N and 0 <= j < M }";
4034 map
= isl_map_read_from_str(ctx
, str
);
4035 set
= isl_map_range(map
);
4037 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
4038 set1
= isl_set_from_pw_aff(pwaff
);
4039 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
4040 set2
= isl_set_read_from_str(ctx
, str
);
4041 equal
= isl_set_is_equal(set1
, set2
);
4045 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
4046 set1
= isl_set_from_pw_aff(pwaff
);
4047 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
4048 set2
= isl_set_read_from_str(ctx
, str
);
4049 if (equal
>= 0 && equal
)
4050 equal
= isl_set_is_equal(set1
, set2
);
4059 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4061 /* Check that solutions are properly merged. */
4062 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
4063 "c <= -1 + n - 4a - 2b and c >= -2b and "
4064 "4a >= -4 + n and c >= 0 }";
4065 set
= isl_set_read_from_str(ctx
, str
);
4066 pwaff
= isl_set_dim_min(set
, 2);
4067 set1
= isl_set_from_pw_aff(pwaff
);
4068 str
= "[n] -> { [(0)] : n >= 1 }";
4069 set2
= isl_set_read_from_str(ctx
, str
);
4070 equal
= isl_set_is_equal(set1
, set2
);
4077 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4079 /* Check that empty solution lie in the right space. */
4080 str
= "[n] -> { [t,a] : 1 = 0 }";
4081 set
= isl_set_read_from_str(ctx
, str
);
4082 pwaff
= isl_set_dim_max(set
, 0);
4083 set1
= isl_set_from_pw_aff(pwaff
);
4084 str
= "[n] -> { [t] : 1 = 0 }";
4085 set2
= isl_set_read_from_str(ctx
, str
);
4086 equal
= isl_set_is_equal(set1
, set2
);
4093 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4098 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
4100 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
4104 isl_pw_multi_aff
*pma2
;
4110 ctx
= isl_pw_multi_aff_get_ctx(pma
);
4111 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4112 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
4113 isl_pw_multi_aff_free(pma2
);
4118 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
4119 * represented by "str".
4121 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
4126 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
4130 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
4131 "result not as expected", return -1);
4135 /* Basic test for isl_pw_multi_aff_product.
4137 * Check that multiple pieces are properly handled.
4139 static int test_product_pma(isl_ctx
*ctx
)
4143 isl_pw_multi_aff
*pma1
, *pma2
;
4145 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
4146 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4147 str
= "{ C[] -> D[] }";
4148 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4149 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
4150 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
4151 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
4152 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
4153 isl_pw_multi_aff_free(pma1
);
4160 int test_product(isl_ctx
*ctx
)
4164 isl_union_set
*uset1
, *uset2
;
4168 set
= isl_set_read_from_str(ctx
, str
);
4169 set
= isl_set_product(set
, isl_set_copy(set
));
4170 ok
= isl_set_is_wrapping(set
);
4175 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4178 uset1
= isl_union_set_read_from_str(ctx
, str
);
4179 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
4180 str
= "{ [[] -> []] }";
4181 uset2
= isl_union_set_read_from_str(ctx
, str
);
4182 ok
= isl_union_set_is_equal(uset1
, uset2
);
4183 isl_union_set_free(uset1
);
4184 isl_union_set_free(uset2
);
4188 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4190 if (test_product_pma(ctx
) < 0)
4196 /* Check that two sets are not considered disjoint just because
4197 * they have a different set of (named) parameters.
4199 static int test_disjoint(isl_ctx
*ctx
)
4202 isl_set
*set
, *set2
;
4205 str
= "[n] -> { [[]->[]] }";
4206 set
= isl_set_read_from_str(ctx
, str
);
4207 str
= "{ [[]->[]] }";
4208 set2
= isl_set_read_from_str(ctx
, str
);
4209 disjoint
= isl_set_is_disjoint(set
, set2
);
4215 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4220 int test_equal(isl_ctx
*ctx
)
4223 isl_set
*set
, *set2
;
4227 set
= isl_set_read_from_str(ctx
, str
);
4229 set2
= isl_set_read_from_str(ctx
, str
);
4230 equal
= isl_set_is_equal(set
, set2
);
4236 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4241 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
4242 enum isl_dim_type type
, unsigned pos
, int fixed
)
4246 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
4253 isl_die(ctx
, isl_error_unknown
,
4254 "map not detected as fixed", return -1);
4256 isl_die(ctx
, isl_error_unknown
,
4257 "map detected as fixed", return -1);
4260 int test_fixed(isl_ctx
*ctx
)
4265 str
= "{ [i] -> [i] }";
4266 map
= isl_map_read_from_str(ctx
, str
);
4267 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
4269 str
= "{ [i] -> [1] }";
4270 map
= isl_map_read_from_str(ctx
, str
);
4271 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
4273 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
4274 map
= isl_map_read_from_str(ctx
, str
);
4275 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
4277 map
= isl_map_read_from_str(ctx
, str
);
4278 map
= isl_map_neg(map
);
4279 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
4285 struct isl_vertices_test_data
{
4288 const char *vertex
[2];
4289 } vertices_tests
[] = {
4290 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
4291 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
4292 { "{ A[t, i] : t = 14 and i = 1 }",
4293 1, { "{ A[14, 1] }" } },
4296 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
4298 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
4300 struct isl_vertices_test_data
*data
= user
;
4303 isl_basic_set
*bset
;
4304 isl_pw_multi_aff
*pma
;
4308 ctx
= isl_vertex_get_ctx(vertex
);
4309 bset
= isl_vertex_get_domain(vertex
);
4310 ma
= isl_vertex_get_expr(vertex
);
4311 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
4313 for (i
= 0; i
< data
->n
; ++i
) {
4314 isl_pw_multi_aff
*pma_i
;
4316 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
4317 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
4318 isl_pw_multi_aff_free(pma_i
);
4320 if (equal
< 0 || equal
)
4324 isl_pw_multi_aff_free(pma
);
4325 isl_vertex_free(vertex
);
4328 return isl_stat_error
;
4330 return equal
? isl_stat_ok
: isl_stat_error
;
4333 int test_vertices(isl_ctx
*ctx
)
4337 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
4338 isl_basic_set
*bset
;
4339 isl_vertices
*vertices
;
4343 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
4344 vertices
= isl_basic_set_compute_vertices(bset
);
4345 n
= isl_vertices_get_n_vertices(vertices
);
4346 if (vertices_tests
[i
].n
!= n
)
4348 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
4349 &vertices_tests
[i
]) < 0)
4351 isl_vertices_free(vertices
);
4352 isl_basic_set_free(bset
);
4357 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
4364 int test_union_pw(isl_ctx
*ctx
)
4368 isl_union_set
*uset
;
4369 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
4371 str
= "{ [x] -> x^2 }";
4372 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
4373 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
4374 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
4375 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
4376 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
4377 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
4378 isl_union_pw_qpolynomial_free(upwqp1
);
4379 isl_union_pw_qpolynomial_free(upwqp2
);
4383 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4388 /* Test that isl_union_pw_qpolynomial_eval picks up the function
4389 * defined over the correct domain space.
4391 static int test_eval(isl_ctx
*ctx
)
4396 isl_union_pw_qpolynomial
*upwqp
;
4400 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
4401 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
4403 set
= isl_set_read_from_str(ctx
, str
);
4404 pnt
= isl_set_sample_point(set
);
4405 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
4406 cmp
= isl_val_cmp_si(v
, 36);
4412 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
4417 int test_output(isl_ctx
*ctx
)
4425 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
4426 pa
= isl_pw_aff_read_from_str(ctx
, str
);
4428 p
= isl_printer_to_str(ctx
);
4429 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
4430 p
= isl_printer_print_pw_aff(p
, pa
);
4431 s
= isl_printer_get_str(p
);
4432 isl_printer_free(p
);
4433 isl_pw_aff_free(pa
);
4437 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
4442 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4447 int test_sample(isl_ctx
*ctx
)
4450 isl_basic_set
*bset1
, *bset2
;
4453 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
4454 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
4455 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
4456 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
4457 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
4458 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
4459 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
4460 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
4461 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
4462 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
4463 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
4464 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
4465 "d - 1073741821e and "
4466 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
4467 "3j >= 1 - a + b + 2e and "
4468 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
4469 "3i <= 4 - a + 4b - e and "
4470 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
4471 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
4472 "c <= -1 + a and 3i >= -2 - a + 3e and "
4473 "1073741822e <= 1073741823 - a + 1073741822b + c and "
4474 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
4475 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
4476 "1073741823e >= 1 + 1073741823b - d and "
4477 "3i >= 1073741823b + c - 1073741823e - f and "
4478 "3i >= 1 + 2b + e + 3g }";
4479 bset1
= isl_basic_set_read_from_str(ctx
, str
);
4480 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
4481 empty
= isl_basic_set_is_empty(bset2
);
4482 subset
= isl_basic_set_is_subset(bset2
, bset1
);
4483 isl_basic_set_free(bset1
);
4484 isl_basic_set_free(bset2
);
4485 if (empty
< 0 || subset
< 0)
4488 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
4490 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
4495 int test_fixed_power(isl_ctx
*ctx
)
4503 str
= "{ [i] -> [i + 1] }";
4504 map
= isl_map_read_from_str(ctx
, str
);
4505 isl_int_set_si(exp
, 23);
4506 map
= isl_map_fixed_power(map
, exp
);
4507 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
4516 int test_slice(isl_ctx
*ctx
)
4522 str
= "{ [i] -> [j] }";
4523 map
= isl_map_read_from_str(ctx
, str
);
4524 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
4525 equal
= map_check_equal(map
, "{ [i] -> [i] }");
4530 str
= "{ [i] -> [j] }";
4531 map
= isl_map_read_from_str(ctx
, str
);
4532 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
4533 equal
= map_check_equal(map
, "{ [i] -> [j] }");
4538 str
= "{ [i] -> [j] }";
4539 map
= isl_map_read_from_str(ctx
, str
);
4540 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
4541 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
4546 str
= "{ [i] -> [j] }";
4547 map
= isl_map_read_from_str(ctx
, str
);
4548 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
4549 equal
= map_check_equal(map
, "{ [0] -> [j] }");
4554 str
= "{ [i] -> [j] }";
4555 map
= isl_map_read_from_str(ctx
, str
);
4556 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
4557 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
4562 str
= "{ [i] -> [j] }";
4563 map
= isl_map_read_from_str(ctx
, str
);
4564 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
4565 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
4573 int test_eliminate(isl_ctx
*ctx
)
4579 str
= "{ [i] -> [j] : i = 2j }";
4580 map
= isl_map_read_from_str(ctx
, str
);
4581 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
4582 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
4590 /* Check that isl_set_dim_residue_class detects that the values of j
4591 * in the set below are all odd and that it does not detect any spurious
4594 static int test_residue_class(isl_ctx
*ctx
)
4601 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
4602 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
4603 set
= isl_set_read_from_str(ctx
, str
);
4606 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
4608 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
4609 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
4618 int test_align_parameters(isl_ctx
*ctx
)
4622 isl_multi_aff
*ma1
, *ma2
;
4625 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
4626 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
4628 space
= isl_space_params_alloc(ctx
, 1);
4629 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
4630 ma1
= isl_multi_aff_align_params(ma1
, space
);
4632 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
4633 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
4635 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4637 isl_multi_aff_free(ma1
);
4638 isl_multi_aff_free(ma2
);
4643 isl_die(ctx
, isl_error_unknown
,
4644 "result not as expected", return -1);
4649 static int test_list(isl_ctx
*ctx
)
4651 isl_id
*a
, *b
, *c
, *d
, *id
;
4655 a
= isl_id_alloc(ctx
, "a", NULL
);
4656 b
= isl_id_alloc(ctx
, "b", NULL
);
4657 c
= isl_id_alloc(ctx
, "c", NULL
);
4658 d
= isl_id_alloc(ctx
, "d", NULL
);
4660 list
= isl_id_list_alloc(ctx
, 4);
4661 list
= isl_id_list_add(list
, a
);
4662 list
= isl_id_list_add(list
, b
);
4663 list
= isl_id_list_add(list
, c
);
4664 list
= isl_id_list_add(list
, d
);
4665 list
= isl_id_list_drop(list
, 1, 1);
4667 if (isl_id_list_n_id(list
) != 3) {
4668 isl_id_list_free(list
);
4669 isl_die(ctx
, isl_error_unknown
,
4670 "unexpected number of elements in list", return -1);
4673 id
= isl_id_list_get_id(list
, 0);
4676 id
= isl_id_list_get_id(list
, 1);
4679 id
= isl_id_list_get_id(list
, 2);
4683 isl_id_list_free(list
);
4686 isl_die(ctx
, isl_error_unknown
,
4687 "unexpected elements in list", return -1);
4692 const char *set_conversion_tests
[] = {
4693 "[N] -> { [i] : N - 1 <= 2 i <= N }",
4694 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
4695 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4696 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4697 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
4700 /* Check that converting from isl_set to isl_pw_multi_aff and back
4701 * to isl_set produces the original isl_set.
4703 static int test_set_conversion(isl_ctx
*ctx
)
4707 isl_set
*set1
, *set2
;
4708 isl_pw_multi_aff
*pma
;
4711 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
4712 str
= set_conversion_tests
[i
];
4713 set1
= isl_set_read_from_str(ctx
, str
);
4714 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
4715 set2
= isl_set_from_pw_multi_aff(pma
);
4716 equal
= isl_set_is_equal(set1
, set2
);
4723 isl_die(ctx
, isl_error_unknown
, "bad conversion",
4730 /* Check that converting from isl_map to isl_pw_multi_aff and back
4731 * to isl_map produces the original isl_map.
4733 static int test_map_conversion(isl_ctx
*ctx
)
4736 isl_map
*map1
, *map2
;
4737 isl_pw_multi_aff
*pma
;
4740 str
= "{ [a, b, c, d] -> s0[a, b, e, f] : "
4741 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
4742 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
4743 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
4745 map1
= isl_map_read_from_str(ctx
, str
);
4746 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
4747 map2
= isl_map_from_pw_multi_aff(pma
);
4748 equal
= isl_map_is_equal(map1
, map2
);
4755 isl_die(ctx
, isl_error_unknown
, "bad conversion", return -1);
4760 static int test_conversion(isl_ctx
*ctx
)
4762 if (test_set_conversion(ctx
) < 0)
4764 if (test_map_conversion(ctx
) < 0)
4769 /* Check that isl_basic_map_curry does not modify input.
4771 static int test_curry(isl_ctx
*ctx
)
4774 isl_basic_map
*bmap1
, *bmap2
;
4777 str
= "{ [A[] -> B[]] -> C[] }";
4778 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
4779 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
4780 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
4781 isl_basic_map_free(bmap1
);
4782 isl_basic_map_free(bmap2
);
4787 isl_die(ctx
, isl_error_unknown
,
4788 "curried map should not be equal to original",
4798 } preimage_tests
[] = {
4799 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
4800 "{ A[j,i] -> B[i,j] }",
4801 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
4802 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4803 "{ A[a,b] -> B[a/2,b/6] }",
4804 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
4805 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4806 "{ A[a,b] -> B[a/2,b/6] }",
4807 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
4808 "exists i,j : a = 2 i and b = 6 j }" },
4809 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
4810 "[n] -> { : 0 <= n <= 100 }" },
4811 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4812 "{ A[a] -> B[2a] }",
4813 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
4814 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4815 "{ A[a] -> B[([a/2])] }",
4816 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
4817 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
4818 "{ A[a] -> B[a,a,a/3] }",
4819 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
4820 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
4821 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
4824 static int test_preimage_basic_set(isl_ctx
*ctx
)
4827 isl_basic_set
*bset1
, *bset2
;
4831 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
4832 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
4833 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
4834 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
4835 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
4836 equal
= isl_basic_set_is_equal(bset1
, bset2
);
4837 isl_basic_set_free(bset1
);
4838 isl_basic_set_free(bset2
);
4842 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4853 } preimage_domain_tests
[] = {
4854 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
4855 "{ A[j,i] -> B[i,j] }",
4856 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
4857 { "{ B[i] -> C[i]; D[i] -> E[i] }",
4858 "{ A[i] -> B[i + 1] }",
4859 "{ A[i] -> C[i + 1] }" },
4860 { "{ B[i] -> C[i]; B[i] -> E[i] }",
4861 "{ A[i] -> B[i + 1] }",
4862 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
4863 { "{ B[i] -> C[([i/2])] }",
4864 "{ A[i] -> B[2i] }",
4865 "{ A[i] -> C[i] }" },
4866 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
4867 "{ A[i] -> B[([i/5]), ([i/7])] }",
4868 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
4869 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
4870 "[N] -> { A[] -> B[([N/5])] }",
4871 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
4872 { "{ B[i] -> C[i] : exists a : i = 5 a }",
4873 "{ A[i] -> B[2i] }",
4874 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
4875 { "{ B[i] -> C[i] : exists a : i = 2 a; "
4876 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
4877 "{ A[i] -> B[2i] }",
4878 "{ A[i] -> C[2i] }" },
4881 static int test_preimage_union_map(isl_ctx
*ctx
)
4884 isl_union_map
*umap1
, *umap2
;
4888 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
4889 umap1
= isl_union_map_read_from_str(ctx
,
4890 preimage_domain_tests
[i
].map
);
4891 ma
= isl_multi_aff_read_from_str(ctx
,
4892 preimage_domain_tests
[i
].ma
);
4893 umap2
= isl_union_map_read_from_str(ctx
,
4894 preimage_domain_tests
[i
].res
);
4895 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
4896 equal
= isl_union_map_is_equal(umap1
, umap2
);
4897 isl_union_map_free(umap1
);
4898 isl_union_map_free(umap2
);
4902 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4909 static int test_preimage(isl_ctx
*ctx
)
4911 if (test_preimage_basic_set(ctx
) < 0)
4913 if (test_preimage_union_map(ctx
) < 0)
4923 } pullback_tests
[] = {
4924 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
4925 "{ A[a,b] -> C[b + 2a] }" },
4926 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
4927 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
4928 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
4929 "{ A[a] -> C[(a)/6] }" },
4930 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
4931 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
4932 "{ A[a] -> C[(2a)/3] }" },
4933 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
4934 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
4935 "{ A[i,j] -> C[i + j, i + j] }"},
4936 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
4937 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
4938 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
4939 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
4940 "{ [i, j] -> [floor((i)/3), j] }",
4941 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
4944 static int test_pullback(isl_ctx
*ctx
)
4947 isl_multi_aff
*ma1
, *ma2
;
4951 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
4952 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
4953 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
4954 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
4955 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
4956 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4957 isl_multi_aff_free(ma1
);
4958 isl_multi_aff_free(ma2
);
4962 isl_die(ctx
, isl_error_unknown
, "bad pullback",
4969 /* Check that negation is printed correctly and that equal expressions
4970 * are correctly identified.
4972 static int test_ast(isl_ctx
*ctx
)
4974 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
4978 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4979 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4980 expr
= isl_ast_expr_add(expr1
, expr2
);
4981 expr2
= isl_ast_expr_copy(expr
);
4982 expr
= isl_ast_expr_neg(expr
);
4983 expr2
= isl_ast_expr_neg(expr2
);
4984 equal
= isl_ast_expr_is_equal(expr
, expr2
);
4985 str
= isl_ast_expr_to_str(expr
);
4986 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
4988 isl_ast_expr_free(expr
);
4989 isl_ast_expr_free(expr2
);
4991 if (ok
< 0 || equal
< 0)
4994 isl_die(ctx
, isl_error_unknown
,
4995 "equal expressions not considered equal", return -1);
4997 isl_die(ctx
, isl_error_unknown
,
4998 "isl_ast_expr printed incorrectly", return -1);
5000 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
5001 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
5002 expr
= isl_ast_expr_add(expr1
, expr2
);
5003 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
5004 expr
= isl_ast_expr_sub(expr3
, expr
);
5005 str
= isl_ast_expr_to_str(expr
);
5006 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
5008 isl_ast_expr_free(expr
);
5013 isl_die(ctx
, isl_error_unknown
,
5014 "isl_ast_expr printed incorrectly", return -1);
5019 /* Check that isl_ast_build_expr_from_set returns a valid expression
5020 * for an empty set. Note that isl_ast_build_expr_from_set getting
5021 * called on an empty set probably indicates a bug in the caller.
5023 static int test_ast_build(isl_ctx
*ctx
)
5026 isl_ast_build
*build
;
5029 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5030 build
= isl_ast_build_from_context(set
);
5032 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
5033 expr
= isl_ast_build_expr_from_set(build
, set
);
5035 isl_ast_expr_free(expr
);
5036 isl_ast_build_free(build
);
5044 /* Internal data structure for before_for and after_for callbacks.
5046 * depth is the current depth
5047 * before is the number of times before_for has been called
5048 * after is the number of times after_for has been called
5050 struct isl_test_codegen_data
{
5056 /* This function is called before each for loop in the AST generated
5057 * from test_ast_gen1.
5059 * Increment the number of calls and the depth.
5060 * Check that the space returned by isl_ast_build_get_schedule_space
5061 * matches the target space of the schedule returned by
5062 * isl_ast_build_get_schedule.
5063 * Return an isl_id that is checked by the corresponding call
5066 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
5069 struct isl_test_codegen_data
*data
= user
;
5072 isl_union_map
*schedule
;
5073 isl_union_set
*uset
;
5078 ctx
= isl_ast_build_get_ctx(build
);
5080 if (data
->before
>= 3)
5081 isl_die(ctx
, isl_error_unknown
,
5082 "unexpected number of for nodes", return NULL
);
5083 if (data
->depth
>= 2)
5084 isl_die(ctx
, isl_error_unknown
,
5085 "unexpected depth", return NULL
);
5087 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
5091 schedule
= isl_ast_build_get_schedule(build
);
5092 uset
= isl_union_map_range(schedule
);
5095 if (isl_union_set_n_set(uset
) != 1) {
5096 isl_union_set_free(uset
);
5097 isl_die(ctx
, isl_error_unknown
,
5098 "expecting single range space", return NULL
);
5101 space
= isl_ast_build_get_schedule_space(build
);
5102 set
= isl_union_set_extract_set(uset
, space
);
5103 isl_union_set_free(uset
);
5104 empty
= isl_set_is_empty(set
);
5110 isl_die(ctx
, isl_error_unknown
,
5111 "spaces don't match", return NULL
);
5113 return isl_id_alloc(ctx
, name
, NULL
);
5116 /* This function is called after each for loop in the AST generated
5117 * from test_ast_gen1.
5119 * Increment the number of calls and decrement the depth.
5120 * Check that the annotation attached to the node matches
5121 * the isl_id returned by the corresponding call to before_for.
5123 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
5124 __isl_keep isl_ast_build
*build
, void *user
)
5126 struct isl_test_codegen_data
*data
= user
;
5134 if (data
->after
> data
->before
)
5135 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
5136 "mismatch in number of for nodes",
5137 return isl_ast_node_free(node
));
5139 id
= isl_ast_node_get_annotation(node
);
5141 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
5142 "missing annotation", return isl_ast_node_free(node
));
5144 name
= isl_id_get_name(id
);
5145 valid
= name
&& atoi(name
+ 1) == data
->depth
;
5149 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
5150 "wrong annotation", return isl_ast_node_free(node
));
5155 /* Check that the before_each_for and after_each_for callbacks
5156 * are called for each for loop in the generated code,
5157 * that they are called in the right order and that the isl_id
5158 * returned from the before_each_for callback is attached to
5159 * the isl_ast_node passed to the corresponding after_each_for call.
5161 static int test_ast_gen1(isl_ctx
*ctx
)
5165 isl_union_map
*schedule
;
5166 isl_ast_build
*build
;
5168 struct isl_test_codegen_data data
;
5170 str
= "[N] -> { : N >= 10 }";
5171 set
= isl_set_read_from_str(ctx
, str
);
5172 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
5173 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
5174 schedule
= isl_union_map_read_from_str(ctx
, str
);
5179 build
= isl_ast_build_from_context(set
);
5180 build
= isl_ast_build_set_before_each_for(build
,
5181 &before_for
, &data
);
5182 build
= isl_ast_build_set_after_each_for(build
,
5184 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5185 isl_ast_build_free(build
);
5189 isl_ast_node_free(tree
);
5191 if (data
.before
!= 3 || data
.after
!= 3)
5192 isl_die(ctx
, isl_error_unknown
,
5193 "unexpected number of for nodes", return -1);
5198 /* Check that the AST generator handles domains that are integrally disjoint
5199 * but not rationally disjoint.
5201 static int test_ast_gen2(isl_ctx
*ctx
)
5205 isl_union_map
*schedule
;
5206 isl_union_map
*options
;
5207 isl_ast_build
*build
;
5210 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
5211 schedule
= isl_union_map_read_from_str(ctx
, str
);
5212 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5213 build
= isl_ast_build_from_context(set
);
5215 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
5216 options
= isl_union_map_read_from_str(ctx
, str
);
5217 build
= isl_ast_build_set_options(build
, options
);
5218 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5219 isl_ast_build_free(build
);
5222 isl_ast_node_free(tree
);
5227 /* Increment *user on each call.
5229 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
5230 __isl_keep isl_ast_build
*build
, void *user
)
5239 /* Test that unrolling tries to minimize the number of instances.
5240 * In particular, for the schedule given below, make sure it generates
5241 * 3 nodes (rather than 101).
5243 static int test_ast_gen3(isl_ctx
*ctx
)
5247 isl_union_map
*schedule
;
5248 isl_union_map
*options
;
5249 isl_ast_build
*build
;
5253 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
5254 schedule
= isl_union_map_read_from_str(ctx
, str
);
5255 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5257 str
= "{ [i] -> unroll[0] }";
5258 options
= isl_union_map_read_from_str(ctx
, str
);
5260 build
= isl_ast_build_from_context(set
);
5261 build
= isl_ast_build_set_options(build
, options
);
5262 build
= isl_ast_build_set_at_each_domain(build
,
5263 &count_domains
, &n_domain
);
5264 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5265 isl_ast_build_free(build
);
5269 isl_ast_node_free(tree
);
5272 isl_die(ctx
, isl_error_unknown
,
5273 "unexpected number of for nodes", return -1);
5278 /* Check that if the ast_build_exploit_nested_bounds options is set,
5279 * we do not get an outer if node in the generated AST,
5280 * while we do get such an outer if node if the options is not set.
5282 static int test_ast_gen4(isl_ctx
*ctx
)
5286 isl_union_map
*schedule
;
5287 isl_ast_build
*build
;
5289 enum isl_ast_node_type type
;
5292 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
5293 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
5295 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
5297 schedule
= isl_union_map_read_from_str(ctx
, str
);
5298 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5299 build
= isl_ast_build_from_context(set
);
5300 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5301 isl_ast_build_free(build
);
5305 type
= isl_ast_node_get_type(tree
);
5306 isl_ast_node_free(tree
);
5308 if (type
== isl_ast_node_if
)
5309 isl_die(ctx
, isl_error_unknown
,
5310 "not expecting if node", return -1);
5312 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
5314 schedule
= isl_union_map_read_from_str(ctx
, str
);
5315 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5316 build
= isl_ast_build_from_context(set
);
5317 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5318 isl_ast_build_free(build
);
5322 type
= isl_ast_node_get_type(tree
);
5323 isl_ast_node_free(tree
);
5325 if (type
!= isl_ast_node_if
)
5326 isl_die(ctx
, isl_error_unknown
,
5327 "expecting if node", return -1);
5329 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
5334 /* This function is called for each leaf in the AST generated
5335 * from test_ast_gen5.
5337 * We finalize the AST generation by extending the outer schedule
5338 * with a zero-dimensional schedule. If this results in any for loops,
5339 * then this means that we did not pass along enough information
5340 * about the outer schedule to the inner AST generation.
5342 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
5345 isl_union_map
*schedule
, *extra
;
5348 schedule
= isl_ast_build_get_schedule(build
);
5349 extra
= isl_union_map_copy(schedule
);
5350 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
5351 schedule
= isl_union_map_range_product(schedule
, extra
);
5352 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5353 isl_ast_build_free(build
);
5358 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
5359 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
5360 "code should not contain any for loop",
5361 return isl_ast_node_free(tree
));
5366 /* Check that we do not lose any information when going back and
5367 * forth between internal and external schedule.
5369 * In particular, we create an AST where we unroll the only
5370 * non-constant dimension in the schedule. We therefore do
5371 * not expect any for loops in the AST. However, older versions
5372 * of isl would not pass along enough information about the outer
5373 * schedule when performing an inner code generation from a create_leaf
5374 * callback, resulting in the inner code generation producing a for loop.
5376 static int test_ast_gen5(isl_ctx
*ctx
)
5380 isl_union_map
*schedule
, *options
;
5381 isl_ast_build
*build
;
5384 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
5385 schedule
= isl_union_map_read_from_str(ctx
, str
);
5387 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
5388 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
5389 options
= isl_union_map_read_from_str(ctx
, str
);
5391 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5392 build
= isl_ast_build_from_context(set
);
5393 build
= isl_ast_build_set_options(build
, options
);
5394 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
5395 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5396 isl_ast_build_free(build
);
5397 isl_ast_node_free(tree
);
5404 static int test_ast_gen(isl_ctx
*ctx
)
5406 if (test_ast_gen1(ctx
) < 0)
5408 if (test_ast_gen2(ctx
) < 0)
5410 if (test_ast_gen3(ctx
) < 0)
5412 if (test_ast_gen4(ctx
) < 0)
5414 if (test_ast_gen5(ctx
) < 0)
5419 /* Check if dropping output dimensions from an isl_pw_multi_aff
5422 static int test_pw_multi_aff(isl_ctx
*ctx
)
5425 isl_pw_multi_aff
*pma1
, *pma2
;
5428 str
= "{ [i,j] -> [i+j, 4i-j] }";
5429 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
5430 str
= "{ [i,j] -> [4i-j] }";
5431 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
5433 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
5435 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
5437 isl_pw_multi_aff_free(pma1
);
5438 isl_pw_multi_aff_free(pma2
);
5442 isl_die(ctx
, isl_error_unknown
,
5443 "expressions not equal", return -1);
5448 /* Check that we can properly parse multi piecewise affine expressions
5449 * where the piecewise affine expressions have different domains.
5451 static int test_multi_pw_aff(isl_ctx
*ctx
)
5454 isl_set
*dom
, *dom2
;
5455 isl_multi_pw_aff
*mpa1
, *mpa2
;
5460 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
5461 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
5462 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
5463 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
5464 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
5465 str
= "{ [i] -> [(i : i > 0), 2i] }";
5466 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
5468 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
5470 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
5471 dom
= isl_pw_aff_domain(pa
);
5472 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
5473 dom2
= isl_pw_aff_domain(pa
);
5474 equal_domain
= isl_set_is_equal(dom
, dom2
);
5478 isl_multi_pw_aff_free(mpa1
);
5479 isl_multi_pw_aff_free(mpa2
);
5484 isl_die(ctx
, isl_error_unknown
,
5485 "expressions not equal", return -1);
5487 if (equal_domain
< 0)
5490 isl_die(ctx
, isl_error_unknown
,
5491 "domains unexpectedly equal", return -1);
5496 /* This is a regression test for a bug where isl_basic_map_simplify
5497 * would end up in an infinite loop. In particular, we construct
5498 * an empty basic set that is not obviously empty.
5499 * isl_basic_set_is_empty marks the basic set as empty.
5500 * After projecting out i3, the variable can be dropped completely,
5501 * but isl_basic_map_simplify refrains from doing so if the basic set
5502 * is empty and would end up in an infinite loop if it didn't test
5503 * explicitly for empty basic maps in the outer loop.
5505 static int test_simplify(isl_ctx
*ctx
)
5508 isl_basic_set
*bset
;
5511 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
5512 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
5513 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
5515 bset
= isl_basic_set_read_from_str(ctx
, str
);
5516 empty
= isl_basic_set_is_empty(bset
);
5517 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
5518 isl_basic_set_free(bset
);
5522 isl_die(ctx
, isl_error_unknown
,
5523 "basic set should be empty", return -1);
5528 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
5529 * with gbr context would fail to disable the use of the shifted tableau
5530 * when transferring equalities for the input to the context, resulting
5531 * in invalid sample values.
5533 static int test_partial_lexmin(isl_ctx
*ctx
)
5536 isl_basic_set
*bset
;
5537 isl_basic_map
*bmap
;
5540 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
5541 bmap
= isl_basic_map_read_from_str(ctx
, str
);
5542 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
5543 bset
= isl_basic_set_read_from_str(ctx
, str
);
5544 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
5553 /* Check that the variable compression performed on the existentially
5554 * quantified variables inside isl_basic_set_compute_divs is not confused
5555 * by the implicit equalities among the parameters.
5557 static int test_compute_divs(isl_ctx
*ctx
)
5560 isl_basic_set
*bset
;
5563 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
5564 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
5565 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
5566 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
5567 bset
= isl_basic_set_read_from_str(ctx
, str
);
5568 set
= isl_basic_set_compute_divs(bset
);
5576 /* Check that the reaching domain elements and the prefix schedule
5577 * at a leaf node are the same before and after grouping.
5579 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
5584 isl_union_set
*uset
;
5585 isl_multi_union_pw_aff
*mupa
;
5586 isl_union_pw_multi_aff
*upma1
, *upma2
;
5587 isl_union_set
*domain1
, *domain2
;
5588 isl_union_map
*umap1
, *umap2
;
5589 isl_schedule_node
*node
;
5591 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
5592 uset
= isl_union_set_read_from_str(ctx
, str
);
5593 node
= isl_schedule_node_from_domain(uset
);
5594 node
= isl_schedule_node_child(node
, 0);
5595 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
5596 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5597 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
5598 node
= isl_schedule_node_child(node
, 0);
5599 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
5600 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5601 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
5602 node
= isl_schedule_node_child(node
, 0);
5603 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
5604 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
5605 domain1
= isl_schedule_node_get_domain(node
);
5606 id
= isl_id_alloc(ctx
, "group", NULL
);
5607 node
= isl_schedule_node_parent(node
);
5608 node
= isl_schedule_node_group(node
, id
);
5609 node
= isl_schedule_node_child(node
, 0);
5610 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
5611 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
5612 domain2
= isl_schedule_node_get_domain(node
);
5613 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
5614 if (equal
>= 0 && equal
)
5615 equal
= isl_union_set_is_equal(domain1
, domain2
);
5616 if (equal
>= 0 && equal
)
5617 equal
= isl_union_map_is_equal(umap1
, umap2
);
5618 isl_union_map_free(umap1
);
5619 isl_union_map_free(umap2
);
5620 isl_union_set_free(domain1
);
5621 isl_union_set_free(domain2
);
5622 isl_union_pw_multi_aff_free(upma1
);
5623 isl_union_pw_multi_aff_free(upma2
);
5624 isl_schedule_node_free(node
);
5629 isl_die(ctx
, isl_error_unknown
,
5630 "expressions not equal", return -1);
5635 /* Check that we can have nested groupings and that the union map
5636 * schedule representation is the same before and after the grouping.
5637 * Note that after the grouping, the union map representation contains
5638 * the domain constraints from the ranges of the expansion nodes,
5639 * while they are missing from the union map representation of
5640 * the tree without expansion nodes.
5642 * Also check that the global expansion is as expected.
5644 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
5646 int equal
, equal_expansion
;
5649 isl_union_set
*uset
;
5650 isl_union_map
*umap1
, *umap2
;
5651 isl_union_map
*expansion1
, *expansion2
;
5652 isl_union_set_list
*filters
;
5653 isl_multi_union_pw_aff
*mupa
;
5654 isl_schedule
*schedule
;
5655 isl_schedule_node
*node
;
5657 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
5658 "S3[i,j] : 0 <= i,j < 10 }";
5659 uset
= isl_union_set_read_from_str(ctx
, str
);
5660 node
= isl_schedule_node_from_domain(uset
);
5661 node
= isl_schedule_node_child(node
, 0);
5662 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
5663 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5664 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
5665 node
= isl_schedule_node_child(node
, 0);
5666 str
= "{ S1[i,j] }";
5667 uset
= isl_union_set_read_from_str(ctx
, str
);
5668 filters
= isl_union_set_list_from_union_set(uset
);
5669 str
= "{ S2[i,j]; S3[i,j] }";
5670 uset
= isl_union_set_read_from_str(ctx
, str
);
5671 filters
= isl_union_set_list_add(filters
, uset
);
5672 node
= isl_schedule_node_insert_sequence(node
, filters
);
5673 node
= isl_schedule_node_child(node
, 1);
5674 node
= isl_schedule_node_child(node
, 0);
5675 str
= "{ S2[i,j] }";
5676 uset
= isl_union_set_read_from_str(ctx
, str
);
5677 filters
= isl_union_set_list_from_union_set(uset
);
5678 str
= "{ S3[i,j] }";
5679 uset
= isl_union_set_read_from_str(ctx
, str
);
5680 filters
= isl_union_set_list_add(filters
, uset
);
5681 node
= isl_schedule_node_insert_sequence(node
, filters
);
5683 schedule
= isl_schedule_node_get_schedule(node
);
5684 umap1
= isl_schedule_get_map(schedule
);
5685 uset
= isl_schedule_get_domain(schedule
);
5686 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
5687 isl_schedule_free(schedule
);
5689 node
= isl_schedule_node_parent(node
);
5690 node
= isl_schedule_node_parent(node
);
5691 id
= isl_id_alloc(ctx
, "group1", NULL
);
5692 node
= isl_schedule_node_group(node
, id
);
5693 node
= isl_schedule_node_child(node
, 1);
5694 node
= isl_schedule_node_child(node
, 0);
5695 id
= isl_id_alloc(ctx
, "group2", NULL
);
5696 node
= isl_schedule_node_group(node
, id
);
5698 schedule
= isl_schedule_node_get_schedule(node
);
5699 umap2
= isl_schedule_get_map(schedule
);
5700 isl_schedule_free(schedule
);
5702 node
= isl_schedule_node_root(node
);
5703 node
= isl_schedule_node_child(node
, 0);
5704 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
5705 isl_schedule_node_free(node
);
5707 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
5708 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
5709 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
5711 expansion2
= isl_union_map_read_from_str(ctx
, str
);
5713 equal
= isl_union_map_is_equal(umap1
, umap2
);
5714 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
5716 isl_union_map_free(umap1
);
5717 isl_union_map_free(umap2
);
5718 isl_union_map_free(expansion1
);
5719 isl_union_map_free(expansion2
);
5721 if (equal
< 0 || equal_expansion
< 0)
5724 isl_die(ctx
, isl_error_unknown
,
5725 "expressions not equal", return -1);
5726 if (!equal_expansion
)
5727 isl_die(ctx
, isl_error_unknown
,
5728 "unexpected expansion", return -1);
5733 /* Some tests for the isl_schedule_node_group function.
5735 static int test_schedule_tree_group(isl_ctx
*ctx
)
5737 if (test_schedule_tree_group_1(ctx
) < 0)
5739 if (test_schedule_tree_group_2(ctx
) < 0)
5748 { "{ rat: [i] : 0 <= i <= 10 }",
5749 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
5750 { "{ rat: [i] : FALSE }",
5751 "{ rat: coefficients[[cst] -> [a]] }" },
5753 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
5760 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
5761 "{ rat: [i] : 0 <= i <= 10 }" },
5762 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
5764 { "{ rat: coefficients[[cst] -> [a]] }",
5765 "{ rat: [i] : FALSE }" },
5768 /* Test the basic functionality of isl_basic_set_coefficients and
5769 * isl_basic_set_solutions.
5771 static int test_dual(isl_ctx
*ctx
)
5775 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
5777 isl_basic_set
*bset1
, *bset2
;
5779 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
5780 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
5781 bset1
= isl_basic_set_coefficients(bset1
);
5782 equal
= isl_basic_set_is_equal(bset1
, bset2
);
5783 isl_basic_set_free(bset1
);
5784 isl_basic_set_free(bset2
);
5788 isl_die(ctx
, isl_error_unknown
,
5789 "incorrect dual", return -1);
5792 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
5794 isl_basic_set
*bset1
, *bset2
;
5796 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
5797 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
5798 bset1
= isl_basic_set_solutions(bset1
);
5799 equal
= isl_basic_set_is_equal(bset1
, bset2
);
5800 isl_basic_set_free(bset1
);
5801 isl_basic_set_free(bset2
);
5805 isl_die(ctx
, isl_error_unknown
,
5806 "incorrect dual", return -1);
5816 const char *schedule
;
5821 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
5822 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5824 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
5825 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5827 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
5828 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5830 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
5831 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5833 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
5834 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5836 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
5837 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
5839 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
5840 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5842 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
5843 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
5847 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
5848 * tile the band and then check if the tile and point bands have the
5849 * expected partial schedule.
5851 static int test_tile(isl_ctx
*ctx
)
5857 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
5858 shift
= isl_options_get_tile_shift_point_loops(ctx
);
5860 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
5864 isl_union_set
*domain
;
5865 isl_multi_union_pw_aff
*mupa
, *mupa2
;
5866 isl_schedule_node
*node
;
5867 isl_multi_val
*sizes
;
5869 opt
= tile_tests
[i
].scale_tile
;
5870 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
5871 opt
= tile_tests
[i
].shift_point
;
5872 isl_options_set_tile_shift_point_loops(ctx
, opt
);
5874 str
= tile_tests
[i
].domain
;
5875 domain
= isl_union_set_read_from_str(ctx
, str
);
5876 node
= isl_schedule_node_from_domain(domain
);
5877 node
= isl_schedule_node_child(node
, 0);
5878 str
= tile_tests
[i
].schedule
;
5879 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5880 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
5881 str
= tile_tests
[i
].sizes
;
5882 sizes
= isl_multi_val_read_from_str(ctx
, str
);
5883 node
= isl_schedule_node_band_tile(node
, sizes
);
5885 str
= tile_tests
[i
].tile
;
5886 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5887 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
5888 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
5889 isl_multi_union_pw_aff_free(mupa
);
5890 isl_multi_union_pw_aff_free(mupa2
);
5892 node
= isl_schedule_node_child(node
, 0);
5894 str
= tile_tests
[i
].point
;
5895 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5896 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
5897 if (equal
>= 0 && equal
)
5898 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
5900 isl_multi_union_pw_aff_free(mupa
);
5901 isl_multi_union_pw_aff_free(mupa2
);
5903 isl_schedule_node_free(node
);
5908 isl_die(ctx
, isl_error_unknown
,
5909 "unexpected result", return -1);
5912 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
5913 isl_options_set_tile_shift_point_loops(ctx
, shift
);
5918 /* Check that the domain hash of a space is equal to the hash
5919 * of the domain of the space.
5921 static int test_domain_hash(isl_ctx
*ctx
)
5925 uint32_t hash1
, hash2
;
5927 map
= isl_map_read_from_str(ctx
, "[n] -> { A[B[x] -> C[]] -> D[] }");
5928 space
= isl_map_get_space(map
);
5930 hash1
= isl_space_get_domain_hash(space
);
5931 space
= isl_space_domain(space
);
5932 hash2
= isl_space_get_hash(space
);
5933 isl_space_free(space
);
5938 isl_die(ctx
, isl_error_unknown
,
5939 "domain hash not equal to hash of domain", return -1);
5946 int (*fn
)(isl_ctx
*ctx
);
5948 { "domain hash", &test_domain_hash
},
5949 { "dual", &test_dual
},
5950 { "dependence analysis", &test_flow
},
5951 { "val", &test_val
},
5952 { "compute divs", &test_compute_divs
},
5953 { "partial lexmin", &test_partial_lexmin
},
5954 { "simplify", &test_simplify
},
5955 { "curry", &test_curry
},
5956 { "piecewise multi affine expressions", &test_pw_multi_aff
},
5957 { "multi piecewise affine expressions", &test_multi_pw_aff
},
5958 { "conversion", &test_conversion
},
5959 { "list", &test_list
},
5960 { "align parameters", &test_align_parameters
},
5961 { "preimage", &test_preimage
},
5962 { "pullback", &test_pullback
},
5963 { "AST", &test_ast
},
5964 { "AST build", &test_ast_build
},
5965 { "AST generation", &test_ast_gen
},
5966 { "eliminate", &test_eliminate
},
5967 { "residue class", &test_residue_class
},
5968 { "div", &test_div
},
5969 { "slice", &test_slice
},
5970 { "fixed power", &test_fixed_power
},
5971 { "sample", &test_sample
},
5972 { "output", &test_output
},
5973 { "vertices", &test_vertices
},
5974 { "fixed", &test_fixed
},
5975 { "equal", &test_equal
},
5976 { "disjoint", &test_disjoint
},
5977 { "product", &test_product
},
5978 { "dim_max", &test_dim_max
},
5979 { "affine", &test_aff
},
5980 { "injective", &test_injective
},
5981 { "schedule", &test_schedule
},
5982 { "schedule tree grouping", &test_schedule_tree_group
},
5983 { "tile", &test_tile
},
5984 { "union_pw", &test_union_pw
},
5985 { "eval", &test_eval
},
5986 { "parse", &test_parse
},
5987 { "single-valued", &test_sv
},
5988 { "affine hull", &test_affine_hull
},
5989 { "coalesce", &test_coalesce
},
5990 { "factorize", &test_factorize
},
5991 { "subset", &test_subset
},
5992 { "subtract", &test_subtract
},
5993 { "lexmin", &test_lexmin
},
5994 { "min", &test_min
},
5995 { "gist", &test_gist
},
5996 { "piecewise quasi-polynomials", &test_pwqp
},
5997 { "lift", &test_lift
},
5998 { "bound", &test_bound
},
5999 { "union", &test_union
},
6000 { "split periods", &test_split_periods
},
6001 { "lexicographic order", &test_lex
},
6002 { "bijectivity", &test_bijective
},
6003 { "dataflow analysis", &test_dep
},
6004 { "reading", &test_read
},
6005 { "bounded", &test_bounded
},
6006 { "construction", &test_construction
},
6007 { "dimension manipulation", &test_dim
},
6008 { "map application", &test_application
},
6009 { "convex hull", &test_convex_hull
},
6010 { "transitive closure", &test_closure
},
6013 int main(int argc
, char **argv
)
6016 struct isl_ctx
*ctx
;
6017 struct isl_options
*options
;
6019 srcdir
= getenv("srcdir");
6022 options
= isl_options_new_with_defaults();
6024 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
6026 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
6027 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
6028 printf("%s\n", tests
[i
].name
);
6029 if (tests
[i
].fn(ctx
) < 0)