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>
26 #include <isl_constraint_private.h>
27 #include <isl/polynomial.h>
28 #include <isl/union_map.h>
29 #include <isl_factorization.h>
30 #include <isl/schedule.h>
31 #include <isl/schedule_node.h>
32 #include <isl_options_private.h>
33 #include <isl/vertices.h>
34 #include <isl/ast_build.h>
37 #include <isl_ast_build_expr.h>
38 #include <isl/options.h>
40 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
44 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
47 char *pattern
= "%s/test_inputs/%s.%s";
49 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
51 filename
= isl_alloc_array(ctx
, char, length
);
56 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
61 void test_parse_map(isl_ctx
*ctx
, const char *str
)
65 map
= isl_map_read_from_str(ctx
, str
);
70 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
75 map
= isl_map_read_from_str(ctx
, str
);
76 map2
= isl_map_read_from_str(ctx
, str2
);
77 equal
= isl_map_is_equal(map
, map2
);
84 isl_die(ctx
, isl_error_unknown
, "maps not equal",
90 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
92 isl_pw_qpolynomial
*pwqp
;
94 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
96 isl_pw_qpolynomial_free(pwqp
);
99 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
103 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
105 isl_pw_aff_free(pwaff
);
108 /* Check that we can read an isl_multi_val from "str" without errors.
110 static int test_parse_multi_val(isl_ctx
*ctx
, const char *str
)
114 mv
= isl_multi_val_read_from_str(ctx
, str
);
115 isl_multi_val_free(mv
);
120 int test_parse(struct isl_ctx
*ctx
)
123 const char *str
, *str2
;
125 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
127 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
129 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
132 str
= "{ [i] -> [-i] }";
133 map
= isl_map_read_from_str(ctx
, str
);
137 str
= "{ A[i] -> L[([i/3])] }";
138 map
= isl_map_read_from_str(ctx
, str
);
142 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
143 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
144 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
146 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
147 str2
= "{ [x, y] : 2y >= 6 - x }";
148 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
151 if (test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
152 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
154 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
155 if (test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }",
159 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
160 map
= isl_map_read_from_str(ctx
, str
);
161 str
= "{ [new, old] -> [o0, o1] : "
162 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
163 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
164 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
165 map2
= isl_map_read_from_str(ctx
, str
);
166 assert(isl_map_is_equal(map
, map2
));
170 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
171 map
= isl_map_read_from_str(ctx
, str
);
172 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
173 map2
= isl_map_read_from_str(ctx
, str
);
174 assert(isl_map_is_equal(map
, map2
));
178 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
179 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
180 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
183 str
= "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
184 str2
= "{ [i,j] -> [min(i,j)] }";
185 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
188 str
= "{ [i,j] : i != j }";
189 str2
= "{ [i,j] : i < j or i > j }";
190 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
193 str
= "{ [i,j] : (i+1)*2 >= j }";
194 str2
= "{ [i, j] : j <= 2 + 2i }";
195 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
198 str
= "{ [i] -> [i > 0 ? 4 : 5] }";
199 str2
= "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
200 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
203 str
= "[N=2,M] -> { [i=[(M+N)/4]] }";
204 str2
= "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
205 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
208 str
= "{ [x] : x >= 0 }";
209 str2
= "{ [x] : x-0 >= 0 }";
210 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
213 str
= "{ [i] : ((i > 10)) }";
214 str2
= "{ [i] : i >= 11 }";
215 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
218 str
= "{ [i] -> [0] }";
219 str2
= "{ [i] -> [0 * i] }";
220 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
223 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
224 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
225 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
226 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
228 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : (not false) }",
229 "{ [a] -> [b] : true }") < 0)
232 if (test_parse_map_equal(ctx
, "{ [i] : i/2 <= 5 }",
233 "{ [i] : i <= 10 }") < 0)
236 if (test_parse_map_equal(ctx
, "{Sym=[n] [i] : i <= n }",
237 "[n] -> { [i] : i <= n }") < 0)
240 if (test_parse_map_equal(ctx
, "{ [*] }", "{ [a] }") < 0)
243 if (test_parse_map_equal(ctx
, "{ [i] : 2*floor(i/2) = i }",
244 "{ [i] : exists a : i = 2 a }") < 0)
247 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : a = 5 implies b = 5 }",
248 "{ [a] -> [b] : a != 5 or b = 5 }") < 0)
251 if (test_parse_map_equal(ctx
, "{ [a] -> [a - 1 : a > 0] }",
252 "{ [a] -> [a - 1] : a > 0 }") < 0)
254 if (test_parse_map_equal(ctx
,
255 "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
256 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }") < 0)
258 if (test_parse_map_equal(ctx
,
259 "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
260 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
262 if (test_parse_map_equal(ctx
,
263 "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
264 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
266 if (test_parse_map_equal(ctx
,
267 "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
268 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
270 if (test_parse_map_equal(ctx
,
271 "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
272 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
278 static int test_read(isl_ctx
*ctx
)
282 isl_basic_set
*bset1
, *bset2
;
283 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
286 filename
= get_filename(ctx
, "set", "omega");
288 input
= fopen(filename
, "r");
291 bset1
= isl_basic_set_read_from_file(ctx
, input
);
292 bset2
= isl_basic_set_read_from_str(ctx
, str
);
294 equal
= isl_basic_set_is_equal(bset1
, bset2
);
296 isl_basic_set_free(bset1
);
297 isl_basic_set_free(bset2
);
305 isl_die(ctx
, isl_error_unknown
,
306 "read sets not equal", return -1);
311 static int test_bounded(isl_ctx
*ctx
)
316 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
317 bounded
= isl_set_is_bounded(set
);
323 isl_die(ctx
, isl_error_unknown
,
324 "set not considered bounded", return -1);
326 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
327 bounded
= isl_set_is_bounded(set
);
334 isl_die(ctx
, isl_error_unknown
,
335 "set considered bounded", return -1);
337 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
338 bounded
= isl_set_is_bounded(set
);
344 isl_die(ctx
, isl_error_unknown
,
345 "set considered bounded", return -1);
350 /* Construct the basic set { [i] : 5 <= i <= N } */
351 static int test_construction(isl_ctx
*ctx
)
361 dim
= isl_space_set_alloc(ctx
, 1, 1);
362 bset
= isl_basic_set_universe(isl_space_copy(dim
));
363 ls
= isl_local_space_from_space(dim
);
365 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
366 isl_int_set_si(v
, -1);
367 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
368 isl_int_set_si(v
, 1);
369 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
370 bset
= isl_basic_set_add_constraint(bset
, c
);
372 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
373 isl_int_set_si(v
, 1);
374 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
375 isl_int_set_si(v
, -5);
376 isl_constraint_set_constant(c
, v
);
377 bset
= isl_basic_set_add_constraint(bset
, c
);
379 isl_local_space_free(ls
);
380 isl_basic_set_free(bset
);
387 static int test_dim(isl_ctx
*ctx
)
390 isl_map
*map1
, *map2
;
393 map1
= isl_map_read_from_str(ctx
,
394 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
395 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
396 map2
= isl_map_read_from_str(ctx
,
397 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
398 equal
= isl_map_is_equal(map1
, map2
);
401 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
402 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
403 if (equal
>= 0 && equal
)
404 equal
= isl_map_is_equal(map1
, map2
);
412 isl_die(ctx
, isl_error_unknown
,
413 "unexpected result", return -1);
415 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
416 map1
= isl_map_read_from_str(ctx
, str
);
417 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
418 map2
= isl_map_read_from_str(ctx
, str
);
419 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
420 equal
= isl_map_is_equal(map1
, map2
);
427 isl_die(ctx
, isl_error_unknown
,
428 "unexpected result", return -1);
434 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
438 { &isl_val_neg
, "0", "0" },
439 { &isl_val_abs
, "0", "0" },
440 { &isl_val_2exp
, "0", "1" },
441 { &isl_val_floor
, "0", "0" },
442 { &isl_val_ceil
, "0", "0" },
443 { &isl_val_neg
, "1", "-1" },
444 { &isl_val_neg
, "-1", "1" },
445 { &isl_val_neg
, "1/2", "-1/2" },
446 { &isl_val_neg
, "-1/2", "1/2" },
447 { &isl_val_neg
, "infty", "-infty" },
448 { &isl_val_neg
, "-infty", "infty" },
449 { &isl_val_neg
, "NaN", "NaN" },
450 { &isl_val_abs
, "1", "1" },
451 { &isl_val_abs
, "-1", "1" },
452 { &isl_val_abs
, "1/2", "1/2" },
453 { &isl_val_abs
, "-1/2", "1/2" },
454 { &isl_val_abs
, "infty", "infty" },
455 { &isl_val_abs
, "-infty", "infty" },
456 { &isl_val_abs
, "NaN", "NaN" },
457 { &isl_val_floor
, "1", "1" },
458 { &isl_val_floor
, "-1", "-1" },
459 { &isl_val_floor
, "1/2", "0" },
460 { &isl_val_floor
, "-1/2", "-1" },
461 { &isl_val_floor
, "infty", "infty" },
462 { &isl_val_floor
, "-infty", "-infty" },
463 { &isl_val_floor
, "NaN", "NaN" },
464 { &isl_val_ceil
, "1", "1" },
465 { &isl_val_ceil
, "-1", "-1" },
466 { &isl_val_ceil
, "1/2", "1" },
467 { &isl_val_ceil
, "-1/2", "0" },
468 { &isl_val_ceil
, "infty", "infty" },
469 { &isl_val_ceil
, "-infty", "-infty" },
470 { &isl_val_ceil
, "NaN", "NaN" },
471 { &isl_val_2exp
, "-3", "1/8" },
472 { &isl_val_2exp
, "-1", "1/2" },
473 { &isl_val_2exp
, "1", "2" },
474 { &isl_val_2exp
, "2", "4" },
475 { &isl_val_2exp
, "3", "8" },
476 { &isl_val_inv
, "1", "1" },
477 { &isl_val_inv
, "2", "1/2" },
478 { &isl_val_inv
, "1/2", "2" },
479 { &isl_val_inv
, "-2", "-1/2" },
480 { &isl_val_inv
, "-1/2", "-2" },
481 { &isl_val_inv
, "0", "NaN" },
482 { &isl_val_inv
, "NaN", "NaN" },
483 { &isl_val_inv
, "infty", "0" },
484 { &isl_val_inv
, "-infty", "0" },
487 /* Perform some basic tests of unary operations on isl_val objects.
489 static int test_un_val(isl_ctx
*ctx
)
493 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
496 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
497 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
498 res
= isl_val_read_from_str(ctx
, val_un_tests
[i
].res
);
499 fn
= val_un_tests
[i
].op
;
501 if (isl_val_is_nan(res
))
502 ok
= isl_val_is_nan(v
);
504 ok
= isl_val_eq(v
, res
);
510 isl_die(ctx
, isl_error_unknown
,
511 "unexpected result", return -1);
518 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
519 __isl_take isl_val
*v2
);
521 ['+'] = { &isl_val_add
},
522 ['-'] = { &isl_val_sub
},
523 ['*'] = { &isl_val_mul
},
524 ['/'] = { &isl_val_div
},
525 ['g'] = { &isl_val_gcd
},
526 ['m'] = { &isl_val_min
},
527 ['M'] = { &isl_val_max
},
535 } val_bin_tests
[] = {
536 { "0", '+', "0", "0" },
537 { "1", '+', "0", "1" },
538 { "1", '+', "1", "2" },
539 { "1", '-', "1", "0" },
540 { "1", '*', "1", "1" },
541 { "1", '/', "1", "1" },
542 { "2", '*', "3", "6" },
543 { "2", '*', "1/2", "1" },
544 { "2", '*', "1/3", "2/3" },
545 { "2/3", '*', "3/5", "2/5" },
546 { "2/3", '*', "7/5", "14/15" },
547 { "2", '/', "1/2", "4" },
548 { "-2", '/', "-1/2", "4" },
549 { "-2", '/', "1/2", "-4" },
550 { "2", '/', "-1/2", "-4" },
551 { "2", '/', "2", "1" },
552 { "2", '/', "3", "2/3" },
553 { "2/3", '/', "5/3", "2/5" },
554 { "2/3", '/', "5/7", "14/15" },
555 { "0", '/', "0", "NaN" },
556 { "42", '/', "0", "NaN" },
557 { "-42", '/', "0", "NaN" },
558 { "infty", '/', "0", "NaN" },
559 { "-infty", '/', "0", "NaN" },
560 { "NaN", '/', "0", "NaN" },
561 { "0", '/', "NaN", "NaN" },
562 { "42", '/', "NaN", "NaN" },
563 { "-42", '/', "NaN", "NaN" },
564 { "infty", '/', "NaN", "NaN" },
565 { "-infty", '/', "NaN", "NaN" },
566 { "NaN", '/', "NaN", "NaN" },
567 { "0", '/', "infty", "0" },
568 { "42", '/', "infty", "0" },
569 { "-42", '/', "infty", "0" },
570 { "infty", '/', "infty", "NaN" },
571 { "-infty", '/', "infty", "NaN" },
572 { "NaN", '/', "infty", "NaN" },
573 { "0", '/', "-infty", "0" },
574 { "42", '/', "-infty", "0" },
575 { "-42", '/', "-infty", "0" },
576 { "infty", '/', "-infty", "NaN" },
577 { "-infty", '/', "-infty", "NaN" },
578 { "NaN", '/', "-infty", "NaN" },
579 { "1", '-', "1/3", "2/3" },
580 { "1/3", '+', "1/2", "5/6" },
581 { "1/2", '+', "1/2", "1" },
582 { "3/4", '-', "1/4", "1/2" },
583 { "1/2", '-', "1/3", "1/6" },
584 { "infty", '+', "42", "infty" },
585 { "infty", '+', "infty", "infty" },
586 { "42", '+', "infty", "infty" },
587 { "infty", '-', "infty", "NaN" },
588 { "infty", '*', "infty", "infty" },
589 { "infty", '*', "-infty", "-infty" },
590 { "-infty", '*', "infty", "-infty" },
591 { "-infty", '*', "-infty", "infty" },
592 { "0", '*', "infty", "NaN" },
593 { "1", '*', "infty", "infty" },
594 { "infty", '*', "0", "NaN" },
595 { "infty", '*', "42", "infty" },
596 { "42", '-', "infty", "-infty" },
597 { "infty", '+', "-infty", "NaN" },
598 { "4", 'g', "6", "2" },
599 { "5", 'g', "6", "1" },
600 { "42", 'm', "3", "3" },
601 { "42", 'M', "3", "42" },
602 { "3", 'm', "42", "3" },
603 { "3", 'M', "42", "42" },
604 { "42", 'm', "infty", "42" },
605 { "42", 'M', "infty", "infty" },
606 { "42", 'm', "-infty", "-infty" },
607 { "42", 'M', "-infty", "42" },
608 { "42", 'm', "NaN", "NaN" },
609 { "42", 'M', "NaN", "NaN" },
610 { "infty", 'm', "-infty", "-infty" },
611 { "infty", 'M', "-infty", "infty" },
614 /* Perform some basic tests of binary operations on isl_val objects.
616 static int test_bin_val(isl_ctx
*ctx
)
619 isl_val
*v1
, *v2
, *res
;
620 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
621 __isl_take isl_val
*v2
);
624 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
625 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
626 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
627 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
628 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
630 if (isl_val_is_nan(res
))
631 ok
= isl_val_is_nan(v1
);
633 ok
= isl_val_eq(v1
, res
);
639 isl_die(ctx
, isl_error_unknown
,
640 "unexpected result", return -1);
646 /* Perform some basic tests on isl_val objects.
648 static int test_val(isl_ctx
*ctx
)
650 if (test_un_val(ctx
) < 0)
652 if (test_bin_val(ctx
) < 0)
657 static int test_div(isl_ctx
*ctx
)
666 struct isl_basic_set
*bset
;
667 struct isl_constraint
*c
;
672 dim
= isl_space_set_alloc(ctx
, 0, 3);
673 bset
= isl_basic_set_universe(isl_space_copy(dim
));
674 ls
= isl_local_space_from_space(dim
);
676 c
= isl_equality_alloc(isl_local_space_copy(ls
));
677 isl_int_set_si(v
, -1);
678 isl_constraint_set_constant(c
, v
);
679 isl_int_set_si(v
, 1);
680 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
681 isl_int_set_si(v
, 3);
682 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
683 bset
= isl_basic_set_add_constraint(bset
, c
);
685 c
= isl_equality_alloc(isl_local_space_copy(ls
));
686 isl_int_set_si(v
, 1);
687 isl_constraint_set_constant(c
, v
);
688 isl_int_set_si(v
, -1);
689 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
690 isl_int_set_si(v
, 3);
691 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
692 bset
= isl_basic_set_add_constraint(bset
, c
);
694 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
696 assert(bset
&& bset
->n_div
== 1);
697 isl_local_space_free(ls
);
698 isl_basic_set_free(bset
);
701 dim
= isl_space_set_alloc(ctx
, 0, 3);
702 bset
= isl_basic_set_universe(isl_space_copy(dim
));
703 ls
= isl_local_space_from_space(dim
);
705 c
= isl_equality_alloc(isl_local_space_copy(ls
));
706 isl_int_set_si(v
, 1);
707 isl_constraint_set_constant(c
, v
);
708 isl_int_set_si(v
, -1);
709 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
710 isl_int_set_si(v
, 3);
711 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
712 bset
= isl_basic_set_add_constraint(bset
, c
);
714 c
= isl_equality_alloc(isl_local_space_copy(ls
));
715 isl_int_set_si(v
, -1);
716 isl_constraint_set_constant(c
, v
);
717 isl_int_set_si(v
, 1);
718 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
719 isl_int_set_si(v
, 3);
720 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
721 bset
= isl_basic_set_add_constraint(bset
, c
);
723 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
725 assert(bset
&& bset
->n_div
== 1);
726 isl_local_space_free(ls
);
727 isl_basic_set_free(bset
);
730 dim
= isl_space_set_alloc(ctx
, 0, 3);
731 bset
= isl_basic_set_universe(isl_space_copy(dim
));
732 ls
= isl_local_space_from_space(dim
);
734 c
= isl_equality_alloc(isl_local_space_copy(ls
));
735 isl_int_set_si(v
, 1);
736 isl_constraint_set_constant(c
, v
);
737 isl_int_set_si(v
, -1);
738 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
739 isl_int_set_si(v
, 3);
740 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
741 bset
= isl_basic_set_add_constraint(bset
, c
);
743 c
= isl_equality_alloc(isl_local_space_copy(ls
));
744 isl_int_set_si(v
, -3);
745 isl_constraint_set_constant(c
, v
);
746 isl_int_set_si(v
, 1);
747 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
748 isl_int_set_si(v
, 4);
749 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
750 bset
= isl_basic_set_add_constraint(bset
, c
);
752 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
754 assert(bset
&& bset
->n_div
== 1);
755 isl_local_space_free(ls
);
756 isl_basic_set_free(bset
);
759 dim
= isl_space_set_alloc(ctx
, 0, 3);
760 bset
= isl_basic_set_universe(isl_space_copy(dim
));
761 ls
= isl_local_space_from_space(dim
);
763 c
= isl_equality_alloc(isl_local_space_copy(ls
));
764 isl_int_set_si(v
, 2);
765 isl_constraint_set_constant(c
, v
);
766 isl_int_set_si(v
, -1);
767 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
768 isl_int_set_si(v
, 3);
769 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
770 bset
= isl_basic_set_add_constraint(bset
, c
);
772 c
= isl_equality_alloc(isl_local_space_copy(ls
));
773 isl_int_set_si(v
, -1);
774 isl_constraint_set_constant(c
, v
);
775 isl_int_set_si(v
, 1);
776 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
777 isl_int_set_si(v
, 6);
778 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
779 bset
= isl_basic_set_add_constraint(bset
, c
);
781 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
783 assert(isl_basic_set_is_empty(bset
));
784 isl_local_space_free(ls
);
785 isl_basic_set_free(bset
);
788 dim
= isl_space_set_alloc(ctx
, 0, 3);
789 bset
= isl_basic_set_universe(isl_space_copy(dim
));
790 ls
= isl_local_space_from_space(dim
);
792 c
= isl_equality_alloc(isl_local_space_copy(ls
));
793 isl_int_set_si(v
, -1);
794 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
795 isl_int_set_si(v
, 3);
796 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
797 bset
= isl_basic_set_add_constraint(bset
, c
);
799 c
= isl_equality_alloc(isl_local_space_copy(ls
));
800 isl_int_set_si(v
, 1);
801 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
802 isl_int_set_si(v
, -3);
803 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
804 bset
= isl_basic_set_add_constraint(bset
, c
);
806 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
808 assert(bset
&& bset
->n_div
== 0);
809 isl_basic_set_free(bset
);
810 isl_local_space_free(ls
);
813 dim
= isl_space_set_alloc(ctx
, 0, 3);
814 bset
= isl_basic_set_universe(isl_space_copy(dim
));
815 ls
= isl_local_space_from_space(dim
);
817 c
= isl_equality_alloc(isl_local_space_copy(ls
));
818 isl_int_set_si(v
, -1);
819 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
820 isl_int_set_si(v
, 6);
821 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
822 bset
= isl_basic_set_add_constraint(bset
, c
);
824 c
= isl_equality_alloc(isl_local_space_copy(ls
));
825 isl_int_set_si(v
, 1);
826 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
827 isl_int_set_si(v
, -3);
828 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
829 bset
= isl_basic_set_add_constraint(bset
, c
);
831 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
833 assert(bset
&& bset
->n_div
== 1);
834 isl_basic_set_free(bset
);
835 isl_local_space_free(ls
);
838 /* This test is a bit tricky. We set up an equality
840 * Normalization of divs creates _two_ divs
843 * Afterwards e0 is removed again because it has coefficient -1
844 * and we end up with the original equality and div again.
845 * Perhaps we can avoid the introduction of this temporary div.
847 dim
= isl_space_set_alloc(ctx
, 0, 4);
848 bset
= isl_basic_set_universe(isl_space_copy(dim
));
849 ls
= isl_local_space_from_space(dim
);
851 c
= isl_equality_alloc(isl_local_space_copy(ls
));
852 isl_int_set_si(v
, -1);
853 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
854 isl_int_set_si(v
, -3);
855 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
856 isl_int_set_si(v
, -3);
857 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
858 isl_int_set_si(v
, 6);
859 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
860 bset
= isl_basic_set_add_constraint(bset
, c
);
862 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
864 /* Test disabled for now */
866 assert(bset && bset->n_div == 1);
868 isl_local_space_free(ls
);
869 isl_basic_set_free(bset
);
872 dim
= isl_space_set_alloc(ctx
, 0, 5);
873 bset
= isl_basic_set_universe(isl_space_copy(dim
));
874 ls
= isl_local_space_from_space(dim
);
876 c
= isl_equality_alloc(isl_local_space_copy(ls
));
877 isl_int_set_si(v
, -1);
878 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
879 isl_int_set_si(v
, -3);
880 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
881 isl_int_set_si(v
, -3);
882 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
883 isl_int_set_si(v
, 6);
884 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
885 bset
= isl_basic_set_add_constraint(bset
, c
);
887 c
= isl_equality_alloc(isl_local_space_copy(ls
));
888 isl_int_set_si(v
, -1);
889 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
890 isl_int_set_si(v
, 1);
891 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
892 isl_int_set_si(v
, 1);
893 isl_constraint_set_constant(c
, v
);
894 bset
= isl_basic_set_add_constraint(bset
, c
);
896 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
898 /* Test disabled for now */
900 assert(bset && bset->n_div == 1);
902 isl_local_space_free(ls
);
903 isl_basic_set_free(bset
);
906 dim
= isl_space_set_alloc(ctx
, 0, 4);
907 bset
= isl_basic_set_universe(isl_space_copy(dim
));
908 ls
= isl_local_space_from_space(dim
);
910 c
= isl_equality_alloc(isl_local_space_copy(ls
));
911 isl_int_set_si(v
, 1);
912 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
913 isl_int_set_si(v
, -1);
914 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
915 isl_int_set_si(v
, -2);
916 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
917 bset
= isl_basic_set_add_constraint(bset
, c
);
919 c
= isl_equality_alloc(isl_local_space_copy(ls
));
920 isl_int_set_si(v
, -1);
921 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
922 isl_int_set_si(v
, 3);
923 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
924 isl_int_set_si(v
, 2);
925 isl_constraint_set_constant(c
, v
);
926 bset
= isl_basic_set_add_constraint(bset
, c
);
928 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
930 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
932 assert(!isl_basic_set_is_empty(bset
));
934 isl_local_space_free(ls
);
935 isl_basic_set_free(bset
);
938 dim
= isl_space_set_alloc(ctx
, 0, 3);
939 bset
= isl_basic_set_universe(isl_space_copy(dim
));
940 ls
= isl_local_space_from_space(dim
);
942 c
= isl_equality_alloc(isl_local_space_copy(ls
));
943 isl_int_set_si(v
, 1);
944 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
945 isl_int_set_si(v
, -2);
946 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
947 bset
= isl_basic_set_add_constraint(bset
, c
);
949 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
951 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
953 isl_local_space_free(ls
);
954 isl_basic_set_free(bset
);
958 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
959 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
960 set
= isl_set_read_from_str(ctx
, str
);
961 set
= isl_set_compute_divs(set
);
966 str
= "{ [i,j] : 2*[i/2] + 3 * [j/4] <= 10 and 2 i = j }";
967 bset
= isl_basic_set_read_from_str(ctx
, str
);
968 n
= isl_basic_set_dim(bset
, isl_dim_div
);
969 isl_basic_set_free(bset
);
973 isl_die(ctx
, isl_error_unknown
,
974 "expecting no existentials", return -1);
976 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
977 set
= isl_set_read_from_str(ctx
, str
);
978 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
979 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
980 empty
= isl_set_is_empty(set
);
985 isl_die(ctx
, isl_error_unknown
,
986 "result not as accurate as expected", return -1);
991 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
995 struct isl_basic_set
*bset1
, *bset2
;
996 struct isl_basic_map
*bmap
;
998 filename
= get_filename(ctx
, name
, "omega");
1000 input
= fopen(filename
, "r");
1003 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1004 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1006 bset1
= isl_basic_set_apply(bset1
, bmap
);
1008 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1010 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1012 isl_basic_set_free(bset1
);
1013 isl_basic_set_free(bset2
);
1019 static int test_application(isl_ctx
*ctx
)
1021 test_application_case(ctx
, "application");
1022 test_application_case(ctx
, "application2");
1027 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1031 struct isl_basic_set
*bset1
, *bset2
;
1033 filename
= get_filename(ctx
, name
, "polylib");
1035 input
= fopen(filename
, "r");
1038 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1039 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1041 bset1
= isl_basic_set_affine_hull(bset1
);
1043 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1045 isl_basic_set_free(bset1
);
1046 isl_basic_set_free(bset2
);
1052 int test_affine_hull(struct isl_ctx
*ctx
)
1056 isl_basic_set
*bset
, *bset2
;
1060 test_affine_hull_case(ctx
, "affine2");
1061 test_affine_hull_case(ctx
, "affine");
1062 test_affine_hull_case(ctx
, "affine3");
1064 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1065 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1066 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1067 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1068 set
= isl_set_read_from_str(ctx
, str
);
1069 bset
= isl_set_affine_hull(set
);
1070 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1071 isl_basic_set_free(bset
);
1073 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1076 /* Check that isl_map_affine_hull is not confused by
1077 * the reordering of divs in isl_map_align_divs.
1079 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1080 "32e0 = b and 32e1 = c); "
1081 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1082 set
= isl_set_read_from_str(ctx
, str
);
1083 bset
= isl_set_affine_hull(set
);
1084 isl_basic_set_free(bset
);
1088 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1089 "32e2 = 31 + 31e0 }";
1090 set
= isl_set_read_from_str(ctx
, str
);
1091 bset
= isl_set_affine_hull(set
);
1092 str
= "{ [a] : exists e : a = 32 e }";
1093 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1094 subset
= isl_basic_set_is_subset(bset
, bset2
);
1095 isl_basic_set_free(bset
);
1096 isl_basic_set_free(bset2
);
1100 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1106 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1110 struct isl_basic_set
*bset1
, *bset2
;
1111 struct isl_set
*set
;
1113 filename
= get_filename(ctx
, name
, "polylib");
1115 input
= fopen(filename
, "r");
1118 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1119 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1121 set
= isl_basic_set_union(bset1
, bset2
);
1122 bset1
= isl_set_convex_hull(set
);
1124 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1126 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1128 isl_basic_set_free(bset1
);
1129 isl_basic_set_free(bset2
);
1138 } convex_hull_tests
[] = {
1139 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1140 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1141 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1142 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1143 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1144 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1145 "i2 <= 5 and i2 >= 4; "
1146 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1147 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1148 "i2 <= 5 + i0 and i2 >= i0 }" },
1149 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1150 "{ [x, y] : 1 = 0 }" },
1153 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1156 int orig_convex
= ctx
->opt
->convex
;
1157 ctx
->opt
->convex
= convex
;
1159 test_convex_hull_case(ctx
, "convex0");
1160 test_convex_hull_case(ctx
, "convex1");
1161 test_convex_hull_case(ctx
, "convex2");
1162 test_convex_hull_case(ctx
, "convex3");
1163 test_convex_hull_case(ctx
, "convex4");
1164 test_convex_hull_case(ctx
, "convex5");
1165 test_convex_hull_case(ctx
, "convex6");
1166 test_convex_hull_case(ctx
, "convex7");
1167 test_convex_hull_case(ctx
, "convex8");
1168 test_convex_hull_case(ctx
, "convex9");
1169 test_convex_hull_case(ctx
, "convex10");
1170 test_convex_hull_case(ctx
, "convex11");
1171 test_convex_hull_case(ctx
, "convex12");
1172 test_convex_hull_case(ctx
, "convex13");
1173 test_convex_hull_case(ctx
, "convex14");
1174 test_convex_hull_case(ctx
, "convex15");
1176 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1177 isl_set
*set1
, *set2
;
1180 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1181 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1182 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1183 equal
= isl_set_is_equal(set1
, set2
);
1190 isl_die(ctx
, isl_error_unknown
,
1191 "unexpected convex hull", return -1);
1194 ctx
->opt
->convex
= orig_convex
;
1199 static int test_convex_hull(isl_ctx
*ctx
)
1201 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1203 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1208 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1212 struct isl_basic_set
*bset1
, *bset2
;
1214 filename
= get_filename(ctx
, name
, "polylib");
1216 input
= fopen(filename
, "r");
1219 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1220 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1222 bset1
= isl_basic_set_gist(bset1
, bset2
);
1224 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1226 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1228 isl_basic_set_free(bset1
);
1229 isl_basic_set_free(bset2
);
1237 const char *context
;
1240 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1241 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1242 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1243 "{ [a, b, c] : a <= 15 }" },
1244 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1245 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1246 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1247 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1248 { "{ [m, n, a, b] : a <= 2147 + n }",
1249 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1250 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1251 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1253 "{ [m, n, ku, kl] }" },
1256 static int test_gist(struct isl_ctx
*ctx
)
1260 isl_basic_set
*bset1
, *bset2
;
1261 isl_map
*map1
, *map2
;
1264 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1266 isl_set
*set1
, *set2
, *copy
;
1268 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1269 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1270 copy
= isl_set_copy(set1
);
1271 set1
= isl_set_gist(set1
, set2
);
1272 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1273 equal
= isl_set_is_equal(set1
, set2
);
1276 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1277 equal_input
= isl_set_is_equal(set1
, copy
);
1280 if (equal
< 0 || equal_input
< 0)
1283 isl_die(ctx
, isl_error_unknown
,
1284 "incorrect gist result", return -1);
1286 isl_die(ctx
, isl_error_unknown
,
1287 "gist modified input", return -1);
1290 test_gist_case(ctx
, "gist1");
1292 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1293 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1294 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1295 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1296 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1297 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1298 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1299 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1300 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1301 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1302 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1303 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1304 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1305 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1306 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1307 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1308 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1309 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1310 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1311 bset1
= isl_basic_set_gist(bset1
, bset2
);
1312 assert(bset1
&& bset1
->n_div
== 0);
1313 isl_basic_set_free(bset1
);
1315 /* Check that the integer divisions of the second disjunct
1316 * do not spread to the first disjunct.
1318 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1319 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1320 "(exists (e0 = [(-1 + t1)/16], "
1321 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1322 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1323 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1324 "o0 <= 4294967295 and t1 <= -1)) }";
1325 map1
= isl_map_read_from_str(ctx
, str
);
1326 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1327 map2
= isl_map_read_from_str(ctx
, str
);
1328 map1
= isl_map_gist(map1
, map2
);
1332 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1333 isl_map_free(map1
); return -1);
1334 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1335 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1336 isl_map_free(map1
); return -1);
1342 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1344 isl_set
*set
, *set2
;
1348 set
= isl_set_read_from_str(ctx
, str
);
1349 set
= isl_set_coalesce(set
);
1350 set2
= isl_set_read_from_str(ctx
, str
);
1351 equal
= isl_set_is_equal(set
, set2
);
1352 one
= set
&& set
->n
== 1;
1359 isl_die(ctx
, isl_error_unknown
,
1360 "coalesced set not equal to input", return -1);
1361 if (check_one
&& !one
)
1362 isl_die(ctx
, isl_error_unknown
,
1363 "coalesced set should not be a union", return -1);
1368 /* Inputs for coalescing tests with unbounded wrapping.
1369 * "str" is a string representation of the input set.
1370 * "single_disjunct" is set if we expect the result to consist of
1371 * a single disjunct.
1374 int single_disjunct
;
1376 } coalesce_unbounded_tests
[] = {
1377 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1378 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1379 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1380 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1382 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1383 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1384 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1385 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1388 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1389 * option turned off.
1391 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1397 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1398 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1400 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
1401 const char *str
= coalesce_unbounded_tests
[i
].str
;
1402 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
1403 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
1409 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1414 /* Inputs for coalescing tests.
1415 * "str" is a string representation of the input set.
1416 * "single_disjunct" is set if we expect the result to consist of
1417 * a single disjunct.
1420 int single_disjunct
;
1422 } coalesce_tests
[] = {
1423 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1424 "y >= x & x >= 2 & 5 >= y }" },
1425 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1426 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1427 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1428 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1429 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1430 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1431 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1432 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1433 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1434 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1435 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1436 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1437 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1438 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1439 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1440 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1441 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1442 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1443 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1444 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1445 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1446 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1447 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1448 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1449 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1450 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1451 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1452 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1453 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1454 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1455 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1456 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1457 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1458 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1459 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1460 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1461 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1462 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1463 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1464 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1465 "[o0, o1, o2, o3, o4, o5, o6]] : "
1466 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1467 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1468 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1469 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1470 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1471 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1472 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1473 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1474 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1475 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1476 "o6 >= i3 + i6 - o3 and M >= 0 and "
1477 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1478 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1479 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1480 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1481 "(o0 = 0 and M >= 2 and N >= 3) or "
1482 "(M = 0 and o0 = 0 and N >= 3) }" },
1483 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1484 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1485 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1486 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1487 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1488 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1489 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1490 "(y = 3 and x = 1) }" },
1491 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1492 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1493 "i1 <= M and i3 <= M and i4 <= M) or "
1494 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1495 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1496 "i4 <= -1 + M) }" },
1497 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1498 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1499 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1500 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1501 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1502 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1503 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1504 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1505 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1506 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1507 { 0, "{ [a, b] : exists e : 2e = a and "
1508 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1509 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1510 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1511 "j >= 1 and j' <= i + j - i' and i >= 1; "
1513 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1514 "[i,j] : exists a : j = 3a }" },
1515 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1516 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1518 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1519 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1520 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1521 "c <= 6 + 8a and a >= 3; "
1522 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1523 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1524 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1525 "[x,0] : 3 <= x <= 4 }" },
1526 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1527 "[x,0] : 4 <= x <= 5 }" },
1528 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1529 "[x,0] : 3 <= x <= 5 }" },
1530 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1531 "[x,0] : 3 <= x <= 4 }" },
1532 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1534 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1535 { 1, "{ [0,0]; [1,1] }" },
1536 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
1537 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
1539 "[k, 0, k] : k <= 6 and k >= 1 }" },
1540 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
1541 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
1542 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
1543 { 1, "[n] -> { [1] : n >= 0;"
1544 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
1545 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
1546 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
1547 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
1548 "2e0 <= x and 2e0 <= n);"
1549 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
1551 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
1552 "128e0 >= -134 + 127t1 and t1 >= 2 and "
1553 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
1555 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
1556 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
1558 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
1559 "t1 >= 13 and t1 <= 16);"
1560 "[t1] : t1 <= 15 and t1 >= 12 }" },
1561 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
1562 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
1563 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
1564 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
1565 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
1566 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
1568 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
1569 "(exists (e0 : 3e0 = -2 + c0)) }" },
1570 { 0, "[n, b0, t0] -> "
1571 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1572 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1573 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
1574 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
1575 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
1576 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
1577 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
1578 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
1579 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1580 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
1581 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
1582 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
1583 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
1584 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
1585 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
1586 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
1587 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
1588 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
1589 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
1590 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
1591 { 0, "{ [i0, i1, i2] : "
1592 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
1593 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
1594 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
1595 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
1596 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
1597 "32e0 <= 31 + i0)) or "
1601 /* A specialized coalescing test case that would result
1602 * in a segmentation fault or a failed assertion in earlier versions of isl.
1604 static int test_coalesce_special(struct isl_ctx
*ctx
)
1607 isl_map
*map1
, *map2
;
1609 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
1610 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
1611 "(y = 201 and o1 <= 239 and o1 >= 212) or "
1612 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
1613 "o1 <= 239 and o1 >= 212)) or "
1614 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
1615 "o1 <= 241 and o1 >= 240));"
1616 "[S_L220_OUT[] -> T7[]] -> "
1617 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
1618 "(y = 2 and o1 <= 241 and o1 >= 212) or "
1619 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
1620 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
1621 map1
= isl_map_read_from_str(ctx
, str
);
1622 map1
= isl_map_align_divs(map1
);
1623 map1
= isl_map_coalesce(map1
);
1624 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
1625 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
1626 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
1627 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
1628 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
1629 map2
= isl_map_read_from_str(ctx
, str
);
1630 map2
= isl_map_union(map2
, map1
);
1631 map2
= isl_map_align_divs(map2
);
1632 map2
= isl_map_coalesce(map2
);
1640 /* Test the functionality of isl_set_coalesce.
1641 * That is, check that the output is always equal to the input
1642 * and in some cases that the result consists of a single disjunct.
1644 static int test_coalesce(struct isl_ctx
*ctx
)
1648 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
1649 const char *str
= coalesce_tests
[i
].str
;
1650 int check_one
= coalesce_tests
[i
].single_disjunct
;
1651 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
1655 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
1657 if (test_coalesce_special(ctx
) < 0)
1663 static int test_closure(isl_ctx
*ctx
)
1667 isl_map
*up
, *right
;
1668 isl_map
*map
, *map2
;
1671 /* COCOA example 1 */
1672 map
= isl_map_read_from_str(ctx
,
1673 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1674 "1 <= i and i < n and 1 <= j and j < n or "
1675 "i2 = i + 1 and j2 = j - 1 and "
1676 "1 <= i and i < n and 2 <= j and j <= n }");
1677 map
= isl_map_power(map
, &exact
);
1681 /* COCOA example 1 */
1682 map
= isl_map_read_from_str(ctx
,
1683 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1684 "1 <= i and i < n and 1 <= j and j < n or "
1685 "i2 = i + 1 and j2 = j - 1 and "
1686 "1 <= i and i < n and 2 <= j and j <= n }");
1687 map
= isl_map_transitive_closure(map
, &exact
);
1689 map2
= isl_map_read_from_str(ctx
,
1690 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1691 "1 <= i and i < n and 1 <= j and j <= n and "
1692 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1693 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1694 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1695 assert(isl_map_is_equal(map
, map2
));
1699 map
= isl_map_read_from_str(ctx
,
1700 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1701 " 0 <= y and y <= n }");
1702 map
= isl_map_transitive_closure(map
, &exact
);
1703 map2
= isl_map_read_from_str(ctx
,
1704 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1705 " 0 <= y and y <= n }");
1706 assert(isl_map_is_equal(map
, map2
));
1710 /* COCOA example 2 */
1711 map
= isl_map_read_from_str(ctx
,
1712 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1713 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1714 "i2 = i + 2 and j2 = j - 2 and "
1715 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1716 map
= isl_map_transitive_closure(map
, &exact
);
1718 map2
= isl_map_read_from_str(ctx
,
1719 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1720 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1721 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1722 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1723 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1724 assert(isl_map_is_equal(map
, map2
));
1728 /* COCOA Fig.2 left */
1729 map
= isl_map_read_from_str(ctx
,
1730 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1731 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1733 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1734 "j <= 2 i - 3 and j <= n - 2 or "
1735 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1736 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1737 map
= isl_map_transitive_closure(map
, &exact
);
1741 /* COCOA Fig.2 right */
1742 map
= isl_map_read_from_str(ctx
,
1743 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1744 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1746 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1747 "j <= 2 i - 4 and j <= n - 3 or "
1748 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1749 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1750 map
= isl_map_power(map
, &exact
);
1754 /* COCOA Fig.2 right */
1755 map
= isl_map_read_from_str(ctx
,
1756 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1757 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1759 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1760 "j <= 2 i - 4 and j <= n - 3 or "
1761 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1762 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1763 map
= isl_map_transitive_closure(map
, &exact
);
1765 map2
= isl_map_read_from_str(ctx
,
1766 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1767 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1768 "j <= n and 3 + i + 2 j <= 3 n and "
1769 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1770 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1771 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1772 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1773 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1774 assert(isl_map_is_equal(map
, map2
));
1778 /* COCOA Fig.1 right */
1779 dom
= isl_set_read_from_str(ctx
,
1780 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1781 "2 x - 3 y + 3 >= 0 }");
1782 right
= isl_map_read_from_str(ctx
,
1783 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1784 up
= isl_map_read_from_str(ctx
,
1785 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1786 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1787 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1788 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1789 up
= isl_map_intersect_range(up
, dom
);
1790 map
= isl_map_union(up
, right
);
1791 map
= isl_map_transitive_closure(map
, &exact
);
1793 map2
= isl_map_read_from_str(ctx
,
1794 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1795 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1796 assert(isl_map_is_equal(map
, map2
));
1800 /* COCOA Theorem 1 counter example */
1801 map
= isl_map_read_from_str(ctx
,
1802 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1803 "i2 = 1 and j2 = j or "
1804 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1805 map
= isl_map_transitive_closure(map
, &exact
);
1809 map
= isl_map_read_from_str(ctx
,
1810 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1811 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1812 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1813 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1814 map
= isl_map_transitive_closure(map
, &exact
);
1818 /* Kelly et al 1996, fig 12 */
1819 map
= isl_map_read_from_str(ctx
,
1820 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1821 "1 <= i,j,j+1 <= n or "
1822 "j = n and j2 = 1 and i2 = i + 1 and "
1823 "1 <= i,i+1 <= n }");
1824 map
= isl_map_transitive_closure(map
, &exact
);
1826 map2
= isl_map_read_from_str(ctx
,
1827 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1828 "1 <= i <= n and i = i2 or "
1829 "1 <= i < i2 <= n and 1 <= j <= n and "
1831 assert(isl_map_is_equal(map
, map2
));
1835 /* Omega's closure4 */
1836 map
= isl_map_read_from_str(ctx
,
1837 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1838 "1 <= x,y <= 10 or "
1839 "x2 = x + 1 and y2 = y and "
1840 "1 <= x <= 20 && 5 <= y <= 15 }");
1841 map
= isl_map_transitive_closure(map
, &exact
);
1845 map
= isl_map_read_from_str(ctx
,
1846 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1847 map
= isl_map_transitive_closure(map
, &exact
);
1849 map2
= isl_map_read_from_str(ctx
,
1850 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1851 assert(isl_map_is_equal(map
, map2
));
1855 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1856 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1857 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1858 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1859 map
= isl_map_read_from_str(ctx
, str
);
1860 map
= isl_map_transitive_closure(map
, &exact
);
1862 map2
= isl_map_read_from_str(ctx
, str
);
1863 assert(isl_map_is_equal(map
, map2
));
1867 str
= "{[0] -> [1]; [2] -> [3]}";
1868 map
= isl_map_read_from_str(ctx
, str
);
1869 map
= isl_map_transitive_closure(map
, &exact
);
1871 map2
= isl_map_read_from_str(ctx
, str
);
1872 assert(isl_map_is_equal(map
, map2
));
1876 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1877 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1878 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1879 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1880 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1881 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1882 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1883 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1884 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1885 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1886 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1887 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1888 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1889 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1890 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1891 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1892 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1893 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1894 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1895 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1896 map
= isl_map_read_from_str(ctx
, str
);
1897 map
= isl_map_transitive_closure(map
, NULL
);
1904 static int test_lex(struct isl_ctx
*ctx
)
1910 dim
= isl_space_set_alloc(ctx
, 0, 0);
1911 map
= isl_map_lex_le(dim
);
1912 empty
= isl_map_is_empty(map
);
1918 isl_die(ctx
, isl_error_unknown
,
1919 "expecting non-empty result", return -1);
1924 static int test_lexmin(struct isl_ctx
*ctx
)
1928 isl_basic_map
*bmap
;
1929 isl_map
*map
, *map2
;
1932 isl_pw_multi_aff
*pma
;
1934 str
= "[p0, p1] -> { [] -> [] : "
1935 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1936 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1937 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1938 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1939 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1940 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1941 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1942 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1943 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1944 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1945 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1946 map
= isl_map_read_from_str(ctx
, str
);
1947 map
= isl_map_lexmin(map
);
1950 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1951 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1952 set
= isl_set_read_from_str(ctx
, str
);
1953 set
= isl_set_lexmax(set
);
1954 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1955 set2
= isl_set_read_from_str(ctx
, str
);
1956 set
= isl_set_intersect(set
, set2
);
1957 assert(!isl_set_is_empty(set
));
1960 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1961 map
= isl_map_read_from_str(ctx
, str
);
1962 map
= isl_map_lexmin(map
);
1963 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1964 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1965 map2
= isl_map_read_from_str(ctx
, str
);
1966 assert(isl_map_is_equal(map
, map2
));
1970 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1971 map
= isl_map_read_from_str(ctx
, str
);
1972 map2
= isl_map_copy(map
);
1973 map
= isl_map_lexmin(map
);
1974 assert(isl_map_is_equal(map
, map2
));
1978 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1979 map
= isl_map_read_from_str(ctx
, str
);
1980 map
= isl_map_lexmin(map
);
1981 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1982 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1983 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1984 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1985 map2
= isl_map_read_from_str(ctx
, str
);
1986 assert(isl_map_is_equal(map
, map2
));
1990 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1991 " 8i' <= i and 8i' >= -7 + i }";
1992 bmap
= isl_basic_map_read_from_str(ctx
, str
);
1993 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
1994 map2
= isl_map_from_pw_multi_aff(pma
);
1995 map
= isl_map_from_basic_map(bmap
);
1996 assert(isl_map_is_equal(map
, map2
));
2000 str
= "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
2001 map
= isl_map_read_from_str(ctx
, str
);
2002 map
= isl_map_lexmin(map
);
2003 str
= "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
2004 map2
= isl_map_read_from_str(ctx
, str
);
2005 assert(isl_map_is_equal(map
, map2
));
2009 /* Check that empty pieces are properly combined. */
2010 str
= "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2011 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2012 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }";
2013 map
= isl_map_read_from_str(ctx
, str
);
2014 map
= isl_map_lexmin(map
);
2015 str
= "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2016 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2018 map2
= isl_map_read_from_str(ctx
, str
);
2019 assert(isl_map_is_equal(map
, map2
));
2023 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2024 " 8i' <= i and 8i' >= -7 + i }";
2025 set
= isl_set_read_from_str(ctx
, str
);
2026 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
2027 set2
= isl_set_from_pw_multi_aff(pma
);
2028 equal
= isl_set_is_equal(set
, set2
);
2034 isl_die(ctx
, isl_error_unknown
,
2035 "unexpected difference between set and "
2036 "piecewise affine expression", return -1);
2041 /* Check that isl_set_min_val and isl_set_max_val compute the correct
2042 * result on non-convex inputs.
2044 static int test_min(struct isl_ctx
*ctx
)
2051 set
= isl_set_read_from_str(ctx
, "{ [-1]; [1] }");
2052 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x] }");
2053 val
= isl_set_min_val(set
, aff
);
2054 min_ok
= isl_val_is_negone(val
);
2056 val
= isl_set_max_val(set
, aff
);
2057 max_ok
= isl_val_is_one(val
);
2062 if (min_ok
< 0 || max_ok
< 0)
2065 isl_die(ctx
, isl_error_unknown
,
2066 "unexpected minimum", return -1);
2068 isl_die(ctx
, isl_error_unknown
,
2069 "unexpected maximum", return -1);
2079 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
2080 void *dep_user
, void *user
)
2082 struct must_may
*mm
= (struct must_may
*)user
;
2085 mm
->must
= isl_map_union(mm
->must
, dep
);
2087 mm
->may
= isl_map_union(mm
->may
, dep
);
2092 static int common_space(void *first
, void *second
)
2094 int depth
= *(int *)first
;
2098 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
2106 map2
= isl_map_read_from_str(map
->ctx
, str
);
2107 equal
= isl_map_is_equal(map
, map2
);
2113 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
2117 equal
= map_is_equal(map
, str
);
2121 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
2122 "result not as expected", return -1);
2126 static int test_dep(struct isl_ctx
*ctx
)
2131 isl_access_info
*ai
;
2138 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2139 map
= isl_map_read_from_str(ctx
, str
);
2140 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2142 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2143 map
= isl_map_read_from_str(ctx
, str
);
2144 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2146 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2147 map
= isl_map_read_from_str(ctx
, str
);
2148 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2150 flow
= isl_access_info_compute_flow(ai
);
2151 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2152 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2153 mm
.may
= isl_map_empty(dim
);
2155 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2157 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
2158 " [1,10,0] -> [2,5,0] }";
2159 assert(map_is_equal(mm
.must
, str
));
2160 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2161 assert(map_is_equal(mm
.may
, str
));
2163 isl_map_free(mm
.must
);
2164 isl_map_free(mm
.may
);
2165 isl_flow_free(flow
);
2168 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2169 map
= isl_map_read_from_str(ctx
, str
);
2170 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2172 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2173 map
= isl_map_read_from_str(ctx
, str
);
2174 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2176 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2177 map
= isl_map_read_from_str(ctx
, str
);
2178 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2180 flow
= isl_access_info_compute_flow(ai
);
2181 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2182 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2183 mm
.may
= isl_map_empty(dim
);
2185 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2187 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2188 assert(map_is_equal(mm
.must
, str
));
2189 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2190 assert(map_is_equal(mm
.may
, str
));
2192 isl_map_free(mm
.must
);
2193 isl_map_free(mm
.may
);
2194 isl_flow_free(flow
);
2197 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2198 map
= isl_map_read_from_str(ctx
, str
);
2199 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2201 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2202 map
= isl_map_read_from_str(ctx
, str
);
2203 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2205 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2206 map
= isl_map_read_from_str(ctx
, str
);
2207 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2209 flow
= isl_access_info_compute_flow(ai
);
2210 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2211 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2212 mm
.may
= isl_map_empty(dim
);
2214 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2216 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
2217 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2218 assert(map_is_equal(mm
.may
, str
));
2219 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2220 assert(map_is_equal(mm
.must
, str
));
2222 isl_map_free(mm
.must
);
2223 isl_map_free(mm
.may
);
2224 isl_flow_free(flow
);
2227 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
2228 map
= isl_map_read_from_str(ctx
, str
);
2229 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2231 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2232 map
= isl_map_read_from_str(ctx
, str
);
2233 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2235 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
2236 map
= isl_map_read_from_str(ctx
, str
);
2237 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2239 flow
= isl_access_info_compute_flow(ai
);
2240 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2241 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2242 mm
.may
= isl_map_empty(dim
);
2244 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2246 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2247 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2248 assert(map_is_equal(mm
.may
, str
));
2249 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2250 assert(map_is_equal(mm
.must
, str
));
2252 isl_map_free(mm
.must
);
2253 isl_map_free(mm
.may
);
2254 isl_flow_free(flow
);
2257 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2258 map
= isl_map_read_from_str(ctx
, str
);
2259 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2261 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2262 map
= isl_map_read_from_str(ctx
, str
);
2263 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2265 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2266 map
= isl_map_read_from_str(ctx
, str
);
2267 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2269 flow
= isl_access_info_compute_flow(ai
);
2270 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2271 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2272 mm
.may
= isl_map_empty(dim
);
2274 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2276 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2277 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2278 assert(map_is_equal(mm
.may
, str
));
2279 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2280 assert(map_is_equal(mm
.must
, str
));
2282 isl_map_free(mm
.must
);
2283 isl_map_free(mm
.may
);
2284 isl_flow_free(flow
);
2289 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2290 map
= isl_map_read_from_str(ctx
, str
);
2291 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
2293 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2294 map
= isl_map_read_from_str(ctx
, str
);
2295 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2297 flow
= isl_access_info_compute_flow(ai
);
2298 dim
= isl_space_alloc(ctx
, 0, 5, 5);
2299 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2300 mm
.may
= isl_map_empty(dim
);
2302 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2304 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
2305 assert(map_is_equal(mm
.must
, str
));
2306 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
2307 assert(map_is_equal(mm
.may
, str
));
2309 isl_map_free(mm
.must
);
2310 isl_map_free(mm
.may
);
2311 isl_flow_free(flow
);
2316 /* Check that the dependence analysis proceeds without errors.
2317 * Earlier versions of isl would break down during the analysis
2318 * due to the use of the wrong spaces.
2320 static int test_flow(isl_ctx
*ctx
)
2323 isl_union_map
*access
, *schedule
;
2324 isl_union_map
*must_dep
, *may_dep
;
2327 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
2328 access
= isl_union_map_read_from_str(ctx
, str
);
2329 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
2330 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
2331 "S2[] -> [1,0,0,0]; "
2332 "S3[] -> [-1,0,0,0] }";
2333 schedule
= isl_union_map_read_from_str(ctx
, str
);
2334 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
2335 isl_union_map_copy(access
), schedule
,
2336 &must_dep
, &may_dep
, NULL
, NULL
);
2337 isl_union_map_free(may_dep
);
2338 isl_union_map_free(must_dep
);
2347 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
2348 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
2349 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
2350 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
2351 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
2352 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
2353 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2354 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2355 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
2358 int test_sv(isl_ctx
*ctx
)
2360 isl_union_map
*umap
;
2364 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
2365 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
2366 sv
= isl_union_map_is_single_valued(umap
);
2367 isl_union_map_free(umap
);
2370 if (sv_tests
[i
].sv
&& !sv
)
2371 isl_die(ctx
, isl_error_internal
,
2372 "map not detected as single valued", return -1);
2373 if (!sv_tests
[i
].sv
&& sv
)
2374 isl_die(ctx
, isl_error_internal
,
2375 "map detected as single valued", return -1);
2384 } bijective_tests
[] = {
2385 { "[N,M]->{[i,j] -> [i]}", 0 },
2386 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
2387 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
2388 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
2389 { "[N,M]->{[i,j] -> [j,i]}", 1 },
2390 { "[N,M]->{[i,j] -> [i+j]}", 0 },
2391 { "[N,M]->{[i,j] -> []}", 0 },
2392 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
2393 { "[N,M]->{[i,j] -> [2i]}", 0 },
2394 { "[N,M]->{[i,j] -> [i,i]}", 0 },
2395 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
2396 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
2397 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
2400 static int test_bijective(struct isl_ctx
*ctx
)
2406 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
2407 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
2408 bijective
= isl_map_is_bijective(map
);
2412 if (bijective_tests
[i
].bijective
&& !bijective
)
2413 isl_die(ctx
, isl_error_internal
,
2414 "map not detected as bijective", return -1);
2415 if (!bijective_tests
[i
].bijective
&& bijective
)
2416 isl_die(ctx
, isl_error_internal
,
2417 "map detected as bijective", return -1);
2423 /* Inputs for isl_pw_qpolynomial_gist tests.
2424 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
2430 } pwqp_gist_tests
[] = {
2431 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
2432 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
2433 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
2434 "{ [i] -> -1/2 + 1/2 * i }" },
2435 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
2438 static int test_pwqp(struct isl_ctx
*ctx
)
2443 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
2446 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2447 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2449 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
2452 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2453 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2455 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2457 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2459 isl_pw_qpolynomial_free(pwqp1
);
2461 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
2462 str
= pwqp_gist_tests
[i
].pwqp
;
2463 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2464 str
= pwqp_gist_tests
[i
].set
;
2465 set
= isl_set_read_from_str(ctx
, str
);
2466 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2467 str
= pwqp_gist_tests
[i
].gist
;
2468 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2469 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2470 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
2471 isl_pw_qpolynomial_free(pwqp1
);
2476 isl_die(ctx
, isl_error_unknown
,
2477 "unexpected result", return -1);
2480 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
2481 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2482 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
2483 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2485 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2487 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2489 isl_pw_qpolynomial_free(pwqp1
);
2491 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
2492 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2493 str
= "{ [x] -> x }";
2494 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2496 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2498 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2500 isl_pw_qpolynomial_free(pwqp1
);
2502 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
2503 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2504 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2505 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
2506 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2507 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2508 isl_pw_qpolynomial_free(pwqp1
);
2510 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
2511 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2512 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2513 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2514 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
2515 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
2516 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2517 isl_pw_qpolynomial_free(pwqp1
);
2518 isl_pw_qpolynomial_free(pwqp2
);
2522 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2524 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
2525 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2526 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2527 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2528 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
2530 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2531 isl_pw_qpolynomial_free(pwqp1
);
2532 isl_pw_qpolynomial_free(pwqp2
);
2536 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2541 static int test_split_periods(isl_ctx
*ctx
)
2544 isl_pw_qpolynomial
*pwqp
;
2546 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
2547 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
2548 "U >= 0; [U,V] -> U^2 : U >= 100 }";
2549 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2551 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
2553 isl_pw_qpolynomial_free(pwqp
);
2561 static int test_union(isl_ctx
*ctx
)
2564 isl_union_set
*uset1
, *uset2
;
2565 isl_union_map
*umap1
, *umap2
;
2568 str
= "{ [i] : 0 <= i <= 1 }";
2569 uset1
= isl_union_set_read_from_str(ctx
, str
);
2570 str
= "{ [1] -> [0] }";
2571 umap1
= isl_union_map_read_from_str(ctx
, str
);
2573 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
2574 equal
= isl_union_map_is_equal(umap1
, umap2
);
2576 isl_union_map_free(umap1
);
2577 isl_union_map_free(umap2
);
2582 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
2585 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
2586 umap1
= isl_union_map_read_from_str(ctx
, str
);
2587 str
= "{ A[i]; B[i] }";
2588 uset1
= isl_union_set_read_from_str(ctx
, str
);
2590 uset2
= isl_union_map_domain(umap1
);
2592 equal
= isl_union_set_is_equal(uset1
, uset2
);
2594 isl_union_set_free(uset1
);
2595 isl_union_set_free(uset2
);
2600 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
2606 /* Check that computing a bound of a non-zero polynomial over an unbounded
2607 * domain does not produce a rational value.
2608 * Ideally, we want the value to be infinity, but we accept NaN for now.
2609 * We certainly do not want to obtain the value zero.
2611 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
2616 isl_pw_qpolynomial
*pwqp
;
2617 isl_pw_qpolynomial_fold
*pwf
;
2621 str
= "{ [m,n] -> -m * n }";
2622 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2623 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2624 dom
= isl_pw_qpolynomial_fold_domain(isl_pw_qpolynomial_fold_copy(pwf
));
2625 pnt
= isl_set_sample_point(dom
);
2626 v
= isl_pw_qpolynomial_fold_eval(pwf
, pnt
);
2627 is_rat
= isl_val_is_rat(v
);
2633 isl_die(ctx
, isl_error_unknown
,
2634 "unexpected rational value", return -1);
2639 static int test_bound(isl_ctx
*ctx
)
2643 isl_pw_qpolynomial
*pwqp
;
2644 isl_pw_qpolynomial_fold
*pwf
;
2646 if (test_bound_unbounded_domain(ctx
) < 0)
2649 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
2650 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2651 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2652 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
2653 isl_pw_qpolynomial_fold_free(pwf
);
2655 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
2658 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
2659 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2660 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2661 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
2662 isl_pw_qpolynomial_fold_free(pwf
);
2664 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
2670 static int test_lift(isl_ctx
*ctx
)
2673 isl_basic_map
*bmap
;
2674 isl_basic_set
*bset
;
2676 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
2677 bset
= isl_basic_set_read_from_str(ctx
, str
);
2678 bset
= isl_basic_set_lift(bset
);
2679 bmap
= isl_basic_map_from_range(bset
);
2680 bset
= isl_basic_map_domain(bmap
);
2681 isl_basic_set_free(bset
);
2690 } subset_tests
[] = {
2692 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
2693 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
2694 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
2696 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
2697 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
2698 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
2699 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
2700 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
2701 "256e0 <= 255i and 256e0 >= -255 + 255i and "
2702 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
2703 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
2704 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
2705 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
2706 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
2707 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
2708 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
2709 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
2710 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
2711 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
2712 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
2713 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
2714 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
2715 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
2716 "4e0 <= -57 + i0 + i1)) or "
2717 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
2718 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
2719 "4e0 >= -61 + i0 + i1)) or "
2720 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
2723 static int test_subset(isl_ctx
*ctx
)
2726 isl_set
*set1
, *set2
;
2729 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
2730 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
2731 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
2732 subset
= isl_set_is_subset(set1
, set2
);
2737 if (subset
!= subset_tests
[i
].subset
)
2738 isl_die(ctx
, isl_error_unknown
,
2739 "incorrect subset result", return -1);
2746 const char *minuend
;
2747 const char *subtrahend
;
2748 const char *difference
;
2749 } subtract_domain_tests
[] = {
2750 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
2751 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
2752 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
2755 static int test_subtract(isl_ctx
*ctx
)
2758 isl_union_map
*umap1
, *umap2
;
2759 isl_union_pw_multi_aff
*upma1
, *upma2
;
2760 isl_union_set
*uset
;
2763 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2764 umap1
= isl_union_map_read_from_str(ctx
,
2765 subtract_domain_tests
[i
].minuend
);
2766 uset
= isl_union_set_read_from_str(ctx
,
2767 subtract_domain_tests
[i
].subtrahend
);
2768 umap2
= isl_union_map_read_from_str(ctx
,
2769 subtract_domain_tests
[i
].difference
);
2770 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
2771 equal
= isl_union_map_is_equal(umap1
, umap2
);
2772 isl_union_map_free(umap1
);
2773 isl_union_map_free(umap2
);
2777 isl_die(ctx
, isl_error_unknown
,
2778 "incorrect subtract domain result", return -1);
2781 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2782 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
2783 subtract_domain_tests
[i
].minuend
);
2784 uset
= isl_union_set_read_from_str(ctx
,
2785 subtract_domain_tests
[i
].subtrahend
);
2786 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
2787 subtract_domain_tests
[i
].difference
);
2788 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
2789 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
2790 isl_union_pw_multi_aff_free(upma1
);
2791 isl_union_pw_multi_aff_free(upma2
);
2795 isl_die(ctx
, isl_error_unknown
,
2796 "incorrect subtract domain result", return -1);
2802 int test_factorize(isl_ctx
*ctx
)
2805 isl_basic_set
*bset
;
2808 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2809 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2810 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2811 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2812 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2813 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2814 "3i5 >= -2i0 - i2 + 3i4 }";
2815 bset
= isl_basic_set_read_from_str(ctx
, str
);
2816 f
= isl_basic_set_factorizer(bset
);
2817 isl_basic_set_free(bset
);
2818 isl_factorizer_free(f
);
2820 isl_die(ctx
, isl_error_unknown
,
2821 "failed to construct factorizer", return -1);
2823 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2824 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2825 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2826 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2827 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2828 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2829 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2830 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2831 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2832 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2833 bset
= isl_basic_set_read_from_str(ctx
, str
);
2834 f
= isl_basic_set_factorizer(bset
);
2835 isl_basic_set_free(bset
);
2836 isl_factorizer_free(f
);
2838 isl_die(ctx
, isl_error_unknown
,
2839 "failed to construct factorizer", return -1);
2844 static int check_injective(__isl_take isl_map
*map
, void *user
)
2846 int *injective
= user
;
2848 *injective
= isl_map_is_injective(map
);
2851 if (*injective
< 0 || !*injective
)
2857 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
2858 const char *r
, const char *s
, int tilable
, int parallel
)
2862 isl_union_map
*W
, *R
, *S
;
2863 isl_union_map
*empty
;
2864 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
2865 isl_union_map
*validity
, *proximity
, *coincidence
;
2866 isl_union_map
*schedule
;
2867 isl_union_map
*test
;
2868 isl_union_set
*delta
;
2869 isl_union_set
*domain
;
2873 isl_schedule_constraints
*sc
;
2874 isl_schedule
*sched
;
2875 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
2877 D
= isl_union_set_read_from_str(ctx
, d
);
2878 W
= isl_union_map_read_from_str(ctx
, w
);
2879 R
= isl_union_map_read_from_str(ctx
, r
);
2880 S
= isl_union_map_read_from_str(ctx
, s
);
2882 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
2883 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
2885 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
2886 isl_union_map_compute_flow(isl_union_map_copy(R
),
2887 isl_union_map_copy(W
), empty
,
2888 isl_union_map_copy(S
),
2889 &dep_raw
, NULL
, NULL
, NULL
);
2890 isl_union_map_compute_flow(isl_union_map_copy(W
),
2891 isl_union_map_copy(W
),
2892 isl_union_map_copy(R
),
2893 isl_union_map_copy(S
),
2894 &dep_waw
, &dep_war
, NULL
, NULL
);
2896 dep
= isl_union_map_union(dep_waw
, dep_war
);
2897 dep
= isl_union_map_union(dep
, dep_raw
);
2898 validity
= isl_union_map_copy(dep
);
2899 coincidence
= isl_union_map_copy(dep
);
2900 proximity
= isl_union_map_copy(dep
);
2902 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
2903 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2904 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
2905 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2906 sched
= isl_schedule_constraints_compute_schedule(sc
);
2907 schedule
= isl_schedule_get_map(sched
);
2908 isl_schedule_free(sched
);
2909 isl_union_map_free(W
);
2910 isl_union_map_free(R
);
2911 isl_union_map_free(S
);
2914 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
2916 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
2917 is_complete
= isl_union_set_is_subset(D
, domain
);
2918 isl_union_set_free(D
);
2919 isl_union_set_free(domain
);
2921 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
2922 test
= isl_union_map_apply_range(test
, dep
);
2923 test
= isl_union_map_apply_range(test
, schedule
);
2925 delta
= isl_union_map_deltas(test
);
2926 if (isl_union_set_n_set(delta
) == 0) {
2930 isl_union_set_free(delta
);
2932 delta_set
= isl_set_from_union_set(delta
);
2934 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2935 for (i
= 0; i
< tilable
; ++i
)
2936 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
2937 is_tilable
= isl_set_is_subset(delta_set
, slice
);
2938 isl_set_free(slice
);
2940 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2941 for (i
= 0; i
< parallel
; ++i
)
2942 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
2943 is_parallel
= isl_set_is_subset(delta_set
, slice
);
2944 isl_set_free(slice
);
2946 origin
= isl_set_universe(isl_set_get_space(delta_set
));
2947 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
2948 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
2950 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
2951 delta_set
= isl_set_lexmin(delta_set
);
2953 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
2955 isl_set_free(origin
);
2956 isl_set_free(delta_set
);
2959 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
2960 is_injection
< 0 || is_complete
< 0)
2963 isl_die(ctx
, isl_error_unknown
,
2964 "generated schedule incomplete", return -1);
2966 isl_die(ctx
, isl_error_unknown
,
2967 "generated schedule not injective on each statement",
2970 isl_die(ctx
, isl_error_unknown
,
2971 "negative dependences in generated schedule",
2974 isl_die(ctx
, isl_error_unknown
,
2975 "generated schedule not as tilable as expected",
2978 isl_die(ctx
, isl_error_unknown
,
2979 "generated schedule not as parallel as expected",
2985 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
2986 const char *domain
, const char *validity
, const char *proximity
)
2990 isl_union_map
*prox
;
2991 isl_schedule_constraints
*sc
;
2992 isl_schedule
*schedule
;
2993 isl_union_map
*sched
;
2995 dom
= isl_union_set_read_from_str(ctx
, domain
);
2996 dep
= isl_union_map_read_from_str(ctx
, validity
);
2997 prox
= isl_union_map_read_from_str(ctx
, proximity
);
2998 sc
= isl_schedule_constraints_on_domain(dom
);
2999 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
3000 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
3001 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3002 sched
= isl_schedule_get_map(schedule
);
3003 isl_schedule_free(schedule
);
3008 /* Check that a schedule can be constructed on the given domain
3009 * with the given validity and proximity constraints.
3011 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
3012 const char *validity
, const char *proximity
)
3014 isl_union_map
*sched
;
3016 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
3020 isl_union_map_free(sched
);
3024 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
3025 const char *validity
, const char *proximity
, const char *expected_sched
)
3027 isl_union_map
*sched1
, *sched2
;
3030 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
3031 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
3033 equal
= isl_union_map_is_equal(sched1
, sched2
);
3034 isl_union_map_free(sched1
);
3035 isl_union_map_free(sched2
);
3040 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
3046 /* Check that the schedule map is properly padded, even after being
3047 * reconstructed from the band forest.
3049 static int test_padded_schedule(isl_ctx
*ctx
)
3053 isl_union_map
*validity
, *proximity
;
3054 isl_schedule_constraints
*sc
;
3055 isl_schedule
*sched
;
3056 isl_union_map
*map1
, *map2
;
3057 isl_band_list
*list
;
3060 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
3061 D
= isl_union_set_read_from_str(ctx
, str
);
3062 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
3063 proximity
= isl_union_map_copy(validity
);
3064 sc
= isl_schedule_constraints_on_domain(D
);
3065 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3066 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3067 sched
= isl_schedule_constraints_compute_schedule(sc
);
3068 map1
= isl_schedule_get_map(sched
);
3069 list
= isl_schedule_get_band_forest(sched
);
3070 isl_band_list_free(list
);
3071 map2
= isl_schedule_get_map(sched
);
3072 isl_schedule_free(sched
);
3073 equal
= isl_union_map_is_equal(map1
, map2
);
3074 isl_union_map_free(map1
);
3075 isl_union_map_free(map2
);
3080 isl_die(ctx
, isl_error_unknown
,
3081 "reconstructed schedule map not the same as original",
3087 /* Check that conditional validity constraints are also taken into
3088 * account across bands.
3089 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
3090 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
3091 * and then check that the adjacent order constraint C[2,1]->D[2,0]
3092 * is enforced by the rest of the schedule.
3094 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
3097 isl_union_set
*domain
;
3098 isl_union_map
*validity
, *proximity
, *condition
;
3099 isl_union_map
*sink
, *source
, *dep
;
3100 isl_schedule_constraints
*sc
;
3101 isl_schedule
*schedule
;
3102 isl_union_access_info
*access
;
3103 isl_union_flow
*flow
;
3106 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3107 "A[k] : k >= 1 and k <= -1 + n; "
3108 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3109 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
3110 domain
= isl_union_set_read_from_str(ctx
, str
);
3111 sc
= isl_schedule_constraints_on_domain(domain
);
3112 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
3113 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3114 "D[k, i] -> C[1 + k, i] : "
3115 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3116 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
3117 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
3118 validity
= isl_union_map_read_from_str(ctx
, str
);
3119 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3120 str
= "[n] -> { C[k, i] -> D[k, i] : "
3121 "0 <= i <= -1 + k and k <= -1 + n }";
3122 proximity
= isl_union_map_read_from_str(ctx
, str
);
3123 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3124 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
3125 "i <= -1 + k and i >= 1 and k <= -2 + n; "
3126 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
3127 "k <= -1 + n and i >= 0 and i <= -2 + k }";
3128 condition
= isl_union_map_read_from_str(ctx
, str
);
3129 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
3130 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3131 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
3132 "i >= 0 and i <= -1 + k and k <= -1 + n and "
3133 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
3134 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
3135 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3136 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
3137 "k <= -1 + n and i >= 0 and i <= -1 + k and "
3138 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
3139 validity
= isl_union_map_read_from_str(ctx
, str
);
3140 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
3142 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3143 str
= "{ D[2,0] -> [] }";
3144 sink
= isl_union_map_read_from_str(ctx
, str
);
3145 access
= isl_union_access_info_from_sink(sink
);
3146 str
= "{ C[2,1] -> [] }";
3147 source
= isl_union_map_read_from_str(ctx
, str
);
3148 access
= isl_union_access_info_set_must_source(access
, source
);
3149 access
= isl_union_access_info_set_schedule(access
, schedule
);
3150 flow
= isl_union_access_info_compute_flow(access
);
3151 dep
= isl_union_flow_get_must_dependence(flow
);
3152 isl_union_flow_free(flow
);
3153 empty
= isl_union_map_is_empty(dep
);
3154 isl_union_map_free(dep
);
3159 isl_die(ctx
, isl_error_unknown
,
3160 "conditional validity not respected", return -1);
3165 /* Input for testing of schedule construction based on
3166 * conditional constraints.
3168 * domain is the iteration domain
3169 * flow are the flow dependences, which determine the validity and
3170 * proximity constraints
3171 * condition are the conditions on the conditional validity constraints
3172 * conditional_validity are the conditional validity constraints
3173 * outer_band_n is the expected number of members in the outer band
3178 const char *condition
;
3179 const char *conditional_validity
;
3181 } live_range_tests
[] = {
3182 /* Contrived example that illustrates that we need to keep
3183 * track of tagged condition dependences and
3184 * tagged conditional validity dependences
3185 * in isl_sched_edge separately.
3186 * In particular, the conditional validity constraints on A
3187 * cannot be satisfied,
3188 * but they can be ignored because there are no corresponding
3189 * condition constraints. However, we do have an additional
3190 * conditional validity constraint that maps to the same
3191 * dependence relation
3192 * as the condition constraint on B. If we did not make a distinction
3193 * between tagged condition and tagged conditional validity
3194 * dependences, then we
3195 * could end up treating this shared dependence as an condition
3196 * constraint on A, forcing a localization of the conditions,
3197 * which is impossible.
3199 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
3200 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
3201 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
3202 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3203 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3204 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
3207 /* TACO 2013 Fig. 7 */
3208 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
3209 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3210 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3211 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
3212 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
3213 "0 <= i < n and 0 <= j < n - 1 }",
3214 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
3215 "0 <= i < n and 0 <= j < j' < n;"
3216 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
3217 "0 <= i < i' < n and 0 <= j,j' < n;"
3218 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
3219 "0 <= i,j,j' < n and j < j' }",
3222 /* TACO 2013 Fig. 7, without tags */
3223 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
3224 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3225 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
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] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
3229 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
3230 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
3233 /* TACO 2013 Fig. 12 */
3234 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
3235 "S3[i,3] : 0 <= i <= 1 }",
3236 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
3237 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
3238 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
3239 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
3240 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
3241 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
3242 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
3243 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
3244 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
3245 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
3246 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
3251 /* Test schedule construction based on conditional constraints.
3252 * In particular, check the number of members in the outer band node
3253 * as an indication of whether tiling is possible or not.
3255 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
3258 isl_union_set
*domain
;
3259 isl_union_map
*condition
;
3260 isl_union_map
*flow
;
3261 isl_union_map
*validity
;
3262 isl_schedule_constraints
*sc
;
3263 isl_schedule
*schedule
;
3264 isl_schedule_node
*node
;
3267 if (test_special_conditional_schedule_constraints(ctx
) < 0)
3270 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
3271 domain
= isl_union_set_read_from_str(ctx
,
3272 live_range_tests
[i
].domain
);
3273 flow
= isl_union_map_read_from_str(ctx
,
3274 live_range_tests
[i
].flow
);
3275 condition
= isl_union_map_read_from_str(ctx
,
3276 live_range_tests
[i
].condition
);
3277 validity
= isl_union_map_read_from_str(ctx
,
3278 live_range_tests
[i
].conditional_validity
);
3279 sc
= isl_schedule_constraints_on_domain(domain
);
3280 sc
= isl_schedule_constraints_set_validity(sc
,
3281 isl_union_map_copy(flow
));
3282 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
3283 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
3284 condition
, validity
);
3285 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3286 node
= isl_schedule_get_root(schedule
);
3288 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
3289 node
= isl_schedule_node_first_child(node
);
3290 n_member
= isl_schedule_node_band_n_member(node
);
3291 isl_schedule_node_free(node
);
3292 isl_schedule_free(schedule
);
3296 if (n_member
!= live_range_tests
[i
].outer_band_n
)
3297 isl_die(ctx
, isl_error_unknown
,
3298 "unexpected number of members in outer band",
3304 int test_schedule(isl_ctx
*ctx
)
3306 const char *D
, *W
, *R
, *V
, *P
, *S
;
3308 /* Handle resulting schedule with zero bands. */
3309 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
3313 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
3314 W
= "{ S1[t,i] -> a[t,i] }";
3315 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
3316 "S1[t,i] -> a[t-1,i+1] }";
3317 S
= "{ S1[t,i] -> [t,i] }";
3318 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3321 /* Fig. 5 of CC2008 */
3322 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
3324 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
3325 "j >= 2 and j <= -1 + N }";
3326 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
3327 "j >= 2 and j <= -1 + N; "
3328 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
3329 "j >= 2 and j <= -1 + N }";
3330 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
3331 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3334 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
3335 W
= "{ S1[i] -> a[i] }";
3336 R
= "{ S2[i] -> a[i+1] }";
3337 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3338 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3341 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
3342 W
= "{ S1[i] -> a[i] }";
3343 R
= "{ S2[i] -> a[9-i] }";
3344 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3345 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3348 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
3349 W
= "{ S1[i] -> a[i] }";
3350 R
= "[N] -> { S2[i] -> a[N-1-i] }";
3351 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3352 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3355 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
3356 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
3357 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
3358 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
3359 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3362 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
3363 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
3364 R
= "{ S2[i,j] -> a[i-1,j] }";
3365 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
3366 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3369 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
3370 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
3371 R
= "{ S2[i,j] -> a[i,j-1] }";
3372 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
3373 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3376 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
3377 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
3378 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
3379 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
3380 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
3381 "S_0[] -> [0, 0, 0] }";
3382 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
3384 ctx
->opt
->schedule_parametric
= 0;
3385 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3387 ctx
->opt
->schedule_parametric
= 1;
3389 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
3390 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
3391 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
3392 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
3393 "S4[i] -> a[i,N] }";
3394 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
3395 "S4[i] -> [4,i,0] }";
3396 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3399 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
3400 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
3402 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
3404 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
3406 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
3407 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3410 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
3411 " S_2[t] : t >= 0 and t <= -1 + N; "
3412 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
3414 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
3415 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
3416 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
3417 "i >= 0 and i <= -1 + N }";
3418 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
3419 "i >= 0 and i <= -1 + N; "
3420 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
3421 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
3422 " S_0[t] -> [0, t, 0] }";
3424 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3426 ctx
->opt
->schedule_parametric
= 0;
3427 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3429 ctx
->opt
->schedule_parametric
= 1;
3431 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
3432 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
3433 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
3436 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
3437 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
3438 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
3439 "j >= 0 and j <= -1 + N; "
3440 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3441 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
3442 "j >= 0 and j <= -1 + N; "
3443 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3444 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
3445 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3448 D
= "{ S_0[i] : i >= 0 }";
3449 W
= "{ S_0[i] -> a[i] : i >= 0 }";
3450 R
= "{ S_0[i] -> a[0] : i >= 0 }";
3451 S
= "{ S_0[i] -> [0, i, 0] }";
3452 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3455 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
3456 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
3457 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
3458 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
3459 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3462 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
3463 "k <= -1 + n and k >= 0 }";
3464 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
3465 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
3466 "k <= -1 + n and k >= 0; "
3467 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
3468 "k <= -1 + n and k >= 0; "
3469 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
3470 "k <= -1 + n and k >= 0 }";
3471 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
3472 ctx
->opt
->schedule_outer_coincidence
= 1;
3473 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3475 ctx
->opt
->schedule_outer_coincidence
= 0;
3477 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
3478 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
3479 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
3480 "Stmt_for_body24[i0, i1, 1, 0]:"
3481 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
3482 "Stmt_for_body7[i0, i1, i2]:"
3483 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
3486 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
3487 "Stmt_for_body24[1, i1, i2, i3]:"
3488 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
3490 "Stmt_for_body24[0, i1, i2, i3] -> "
3491 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
3492 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
3494 "Stmt_for_body24[0, i1, i2, i3] ->"
3495 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
3496 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
3497 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
3498 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
3499 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
3500 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
3501 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
3502 "i1 <= 6 and i1 >= 0;"
3503 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
3504 "Stmt_for_body7[i0, i1, i2] -> "
3505 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
3506 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
3507 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
3508 "Stmt_for_body7[i0, i1, i2] -> "
3509 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
3510 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
3511 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
3513 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
3514 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
3515 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
3517 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3520 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
3521 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
3522 "j >= 1 and j <= 7;"
3523 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
3524 "j >= 1 and j <= 8 }";
3526 S
= "{ S_0[i, j] -> [i + j, j] }";
3527 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3528 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3530 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3532 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
3533 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
3534 "j >= 0 and j <= -1 + i }";
3535 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
3536 "i <= -1 + N and j >= 0;"
3537 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
3540 S
= "{ S_0[i, j] -> [i, j] }";
3541 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3542 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3544 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3546 /* Test both algorithms on a case with only proximity dependences. */
3547 D
= "{ S[i,j] : 0 <= i <= 10 }";
3549 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
3550 S
= "{ S[i, j] -> [j, i] }";
3551 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3552 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3554 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3555 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3558 D
= "{ A[a]; B[] }";
3560 P
= "{ A[a] -> B[] }";
3561 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3564 if (test_padded_schedule(ctx
) < 0)
3567 /* Check that check for progress is not confused by rational
3570 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
3571 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
3573 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
3574 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
3576 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3577 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3579 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3581 /* Check that we allow schedule rows that are only non-trivial
3582 * on some full-dimensional domains.
3584 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
3585 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
3586 "S1[j] -> S2[1] : 0 <= j <= 1 }";
3588 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3589 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3591 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3593 if (test_conditional_schedule_constraints(ctx
) < 0)
3599 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
3601 isl_union_map
*umap
;
3604 umap
= isl_union_map_read_from_str(ctx
, str
);
3605 test
= isl_union_map_plain_is_injective(umap
);
3606 isl_union_map_free(umap
);
3609 if (test
== injective
)
3612 isl_die(ctx
, isl_error_unknown
,
3613 "map not detected as injective", return -1);
3615 isl_die(ctx
, isl_error_unknown
,
3616 "map detected as injective", return -1);
3619 int test_injective(isl_ctx
*ctx
)
3623 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
3625 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
3627 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
3629 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
3631 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
3633 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
3635 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
3637 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
3640 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
3641 if (test_plain_injective(ctx
, str
, 1))
3643 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
3644 if (test_plain_injective(ctx
, str
, 0))
3650 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
3658 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
3659 equal
= isl_aff_plain_is_equal(aff
, aff2
);
3665 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
3669 equal
= aff_plain_is_equal(aff
, str
);
3673 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
3674 "result not as expected", return -1);
3679 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3680 __isl_take isl_aff
*aff2
);
3682 ['+'] = { &isl_aff_add
},
3683 ['-'] = { &isl_aff_sub
},
3684 ['*'] = { &isl_aff_mul
},
3685 ['/'] = { &isl_aff_div
},
3693 } aff_bin_tests
[] = {
3694 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
3695 "{ [i] -> [2i] }" },
3696 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
3698 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
3699 "{ [i] -> [2i] }" },
3700 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
3701 "{ [i] -> [2i] }" },
3702 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
3703 "{ [i] -> [i/2] }" },
3704 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
3706 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
3707 "{ [i] -> [NaN] }" },
3708 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
3709 "{ [i] -> [NaN] }" },
3710 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
3711 "{ [i] -> [NaN] }" },
3712 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
3713 "{ [i] -> [NaN] }" },
3714 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
3715 "{ [i] -> [NaN] }" },
3716 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
3717 "{ [i] -> [NaN] }" },
3718 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
3719 "{ [i] -> [NaN] }" },
3720 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
3721 "{ [i] -> [NaN] }" },
3722 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
3723 "{ [i] -> [NaN] }" },
3724 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
3725 "{ [i] -> [NaN] }" },
3726 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
3727 "{ [i] -> [NaN] }" },
3728 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
3729 "{ [i] -> [NaN] }" },
3732 /* Perform some basic tests of binary operations on isl_aff objects.
3734 static int test_bin_aff(isl_ctx
*ctx
)
3737 isl_aff
*aff1
, *aff2
, *res
;
3738 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3739 __isl_take isl_aff
*aff2
);
3742 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
3743 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
3744 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
3745 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
3746 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
3747 aff1
= fn(aff1
, aff2
);
3748 if (isl_aff_is_nan(res
))
3749 ok
= isl_aff_is_nan(aff1
);
3751 ok
= isl_aff_plain_is_equal(aff1
, res
);
3757 isl_die(ctx
, isl_error_unknown
,
3758 "unexpected result", return -1);
3765 __isl_give isl_union_pw_multi_aff
*(*fn
)(
3766 __isl_take isl_union_pw_multi_aff
*upma1
,
3767 __isl_take isl_union_pw_multi_aff
*upma2
);
3771 } upma_bin_tests
[] = {
3772 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
3773 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
3774 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
3775 "{ B[x] -> [2] : x >= 0 }",
3776 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
3779 /* Perform some basic tests of binary operations on
3780 * isl_union_pw_multi_aff objects.
3782 static int test_bin_upma(isl_ctx
*ctx
)
3785 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
3788 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
3789 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3790 upma_bin_tests
[i
].arg1
);
3791 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3792 upma_bin_tests
[i
].arg2
);
3793 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
3794 upma_bin_tests
[i
].res
);
3795 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
3796 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
3797 isl_union_pw_multi_aff_free(upma1
);
3798 isl_union_pw_multi_aff_free(res
);
3802 isl_die(ctx
, isl_error_unknown
,
3803 "unexpected result", return -1);
3809 int test_aff(isl_ctx
*ctx
)
3814 isl_local_space
*ls
;
3818 if (test_bin_aff(ctx
) < 0)
3820 if (test_bin_upma(ctx
) < 0)
3823 space
= isl_space_set_alloc(ctx
, 0, 1);
3824 ls
= isl_local_space_from_space(space
);
3825 aff
= isl_aff_zero_on_domain(ls
);
3827 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3828 aff
= isl_aff_scale_down_ui(aff
, 3);
3829 aff
= isl_aff_floor(aff
);
3830 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3831 aff
= isl_aff_scale_down_ui(aff
, 2);
3832 aff
= isl_aff_floor(aff
);
3833 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3836 set
= isl_set_read_from_str(ctx
, str
);
3837 aff
= isl_aff_gist(aff
, set
);
3839 aff
= isl_aff_add_constant_si(aff
, -16);
3840 zero
= isl_aff_plain_is_zero(aff
);
3846 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3848 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
3849 aff
= isl_aff_scale_down_ui(aff
, 64);
3850 aff
= isl_aff_floor(aff
);
3851 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
3859 int test_dim_max(isl_ctx
*ctx
)
3863 isl_set
*set1
, *set2
;
3868 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
3869 set
= isl_set_read_from_str(ctx
, str
);
3870 pwaff
= isl_set_dim_max(set
, 0);
3871 set1
= isl_set_from_pw_aff(pwaff
);
3872 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
3873 set2
= isl_set_read_from_str(ctx
, str
);
3874 equal
= isl_set_is_equal(set1
, set2
);
3880 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3882 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
3883 set
= isl_set_read_from_str(ctx
, str
);
3884 pwaff
= isl_set_dim_max(set
, 0);
3885 set1
= isl_set_from_pw_aff(pwaff
);
3886 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3887 set2
= isl_set_read_from_str(ctx
, str
);
3888 equal
= isl_set_is_equal(set1
, set2
);
3894 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3896 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
3897 set
= isl_set_read_from_str(ctx
, str
);
3898 pwaff
= isl_set_dim_max(set
, 0);
3899 set1
= isl_set_from_pw_aff(pwaff
);
3900 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3901 set2
= isl_set_read_from_str(ctx
, str
);
3902 equal
= isl_set_is_equal(set1
, set2
);
3908 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3910 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
3911 "0 <= i < N and 0 <= j < M }";
3912 map
= isl_map_read_from_str(ctx
, str
);
3913 set
= isl_map_range(map
);
3915 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
3916 set1
= isl_set_from_pw_aff(pwaff
);
3917 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
3918 set2
= isl_set_read_from_str(ctx
, str
);
3919 equal
= isl_set_is_equal(set1
, set2
);
3923 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
3924 set1
= isl_set_from_pw_aff(pwaff
);
3925 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
3926 set2
= isl_set_read_from_str(ctx
, str
);
3927 if (equal
>= 0 && equal
)
3928 equal
= isl_set_is_equal(set1
, set2
);
3937 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3939 /* Check that solutions are properly merged. */
3940 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
3941 "c <= -1 + n - 4a - 2b and c >= -2b and "
3942 "4a >= -4 + n and c >= 0 }";
3943 set
= isl_set_read_from_str(ctx
, str
);
3944 pwaff
= isl_set_dim_min(set
, 2);
3945 set1
= isl_set_from_pw_aff(pwaff
);
3946 str
= "[n] -> { [(0)] : n >= 1 }";
3947 set2
= isl_set_read_from_str(ctx
, str
);
3948 equal
= isl_set_is_equal(set1
, set2
);
3955 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3957 /* Check that empty solution lie in the right space. */
3958 str
= "[n] -> { [t,a] : 1 = 0 }";
3959 set
= isl_set_read_from_str(ctx
, str
);
3960 pwaff
= isl_set_dim_max(set
, 0);
3961 set1
= isl_set_from_pw_aff(pwaff
);
3962 str
= "[n] -> { [t] : 1 = 0 }";
3963 set2
= isl_set_read_from_str(ctx
, str
);
3964 equal
= isl_set_is_equal(set1
, set2
);
3971 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3976 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
3978 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
3982 isl_pw_multi_aff
*pma2
;
3988 ctx
= isl_pw_multi_aff_get_ctx(pma
);
3989 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3990 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
3991 isl_pw_multi_aff_free(pma2
);
3996 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
3997 * represented by "str".
3999 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
4004 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
4008 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
4009 "result not as expected", return -1);
4013 /* Basic test for isl_pw_multi_aff_product.
4015 * Check that multiple pieces are properly handled.
4017 static int test_product_pma(isl_ctx
*ctx
)
4021 isl_pw_multi_aff
*pma1
, *pma2
;
4023 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
4024 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4025 str
= "{ C[] -> D[] }";
4026 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4027 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
4028 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
4029 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
4030 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
4031 isl_pw_multi_aff_free(pma1
);
4038 int test_product(isl_ctx
*ctx
)
4042 isl_union_set
*uset1
, *uset2
;
4046 set
= isl_set_read_from_str(ctx
, str
);
4047 set
= isl_set_product(set
, isl_set_copy(set
));
4048 ok
= isl_set_is_wrapping(set
);
4053 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4056 uset1
= isl_union_set_read_from_str(ctx
, str
);
4057 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
4058 str
= "{ [[] -> []] }";
4059 uset2
= isl_union_set_read_from_str(ctx
, str
);
4060 ok
= isl_union_set_is_equal(uset1
, uset2
);
4061 isl_union_set_free(uset1
);
4062 isl_union_set_free(uset2
);
4066 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4068 if (test_product_pma(ctx
) < 0)
4074 /* Check that two sets are not considered disjoint just because
4075 * they have a different set of (named) parameters.
4077 static int test_disjoint(isl_ctx
*ctx
)
4080 isl_set
*set
, *set2
;
4083 str
= "[n] -> { [[]->[]] }";
4084 set
= isl_set_read_from_str(ctx
, str
);
4085 str
= "{ [[]->[]] }";
4086 set2
= isl_set_read_from_str(ctx
, str
);
4087 disjoint
= isl_set_is_disjoint(set
, set2
);
4093 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4098 int test_equal(isl_ctx
*ctx
)
4101 isl_set
*set
, *set2
;
4105 set
= isl_set_read_from_str(ctx
, str
);
4107 set2
= isl_set_read_from_str(ctx
, str
);
4108 equal
= isl_set_is_equal(set
, set2
);
4114 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4119 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
4120 enum isl_dim_type type
, unsigned pos
, int fixed
)
4124 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
4131 isl_die(ctx
, isl_error_unknown
,
4132 "map not detected as fixed", return -1);
4134 isl_die(ctx
, isl_error_unknown
,
4135 "map detected as fixed", return -1);
4138 int test_fixed(isl_ctx
*ctx
)
4143 str
= "{ [i] -> [i] }";
4144 map
= isl_map_read_from_str(ctx
, str
);
4145 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
4147 str
= "{ [i] -> [1] }";
4148 map
= isl_map_read_from_str(ctx
, str
);
4149 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
4151 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
4152 map
= isl_map_read_from_str(ctx
, str
);
4153 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
4155 map
= isl_map_read_from_str(ctx
, str
);
4156 map
= isl_map_neg(map
);
4157 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
4163 struct isl_vertices_test_data
{
4166 const char *vertex
[2];
4167 } vertices_tests
[] = {
4168 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
4169 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
4170 { "{ A[t, i] : t = 14 and i = 1 }",
4171 1, { "{ A[14, 1] }" } },
4174 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
4176 static int find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
4178 struct isl_vertices_test_data
*data
= user
;
4181 isl_basic_set
*bset
;
4182 isl_pw_multi_aff
*pma
;
4186 ctx
= isl_vertex_get_ctx(vertex
);
4187 bset
= isl_vertex_get_domain(vertex
);
4188 ma
= isl_vertex_get_expr(vertex
);
4189 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
4191 for (i
= 0; i
< data
->n
; ++i
) {
4192 isl_pw_multi_aff
*pma_i
;
4194 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
4195 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
4196 isl_pw_multi_aff_free(pma_i
);
4198 if (equal
< 0 || equal
)
4202 isl_pw_multi_aff_free(pma
);
4203 isl_vertex_free(vertex
);
4208 return equal
? 0 : - 1;
4211 int test_vertices(isl_ctx
*ctx
)
4215 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
4216 isl_basic_set
*bset
;
4217 isl_vertices
*vertices
;
4221 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
4222 vertices
= isl_basic_set_compute_vertices(bset
);
4223 n
= isl_vertices_get_n_vertices(vertices
);
4224 if (vertices_tests
[i
].n
!= n
)
4226 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
4227 &vertices_tests
[i
]) < 0)
4229 isl_vertices_free(vertices
);
4230 isl_basic_set_free(bset
);
4235 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
4242 int test_union_pw(isl_ctx
*ctx
)
4246 isl_union_set
*uset
;
4247 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
4249 str
= "{ [x] -> x^2 }";
4250 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
4251 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
4252 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
4253 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
4254 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
4255 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
4256 isl_union_pw_qpolynomial_free(upwqp1
);
4257 isl_union_pw_qpolynomial_free(upwqp2
);
4261 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4266 int test_output(isl_ctx
*ctx
)
4274 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
4275 pa
= isl_pw_aff_read_from_str(ctx
, str
);
4277 p
= isl_printer_to_str(ctx
);
4278 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
4279 p
= isl_printer_print_pw_aff(p
, pa
);
4280 s
= isl_printer_get_str(p
);
4281 isl_printer_free(p
);
4282 isl_pw_aff_free(pa
);
4286 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
4291 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4296 int test_sample(isl_ctx
*ctx
)
4299 isl_basic_set
*bset1
, *bset2
;
4302 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
4303 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
4304 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
4305 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
4306 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
4307 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
4308 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
4309 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
4310 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
4311 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
4312 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
4313 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
4314 "d - 1073741821e and "
4315 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
4316 "3j >= 1 - a + b + 2e and "
4317 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
4318 "3i <= 4 - a + 4b - e and "
4319 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
4320 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
4321 "c <= -1 + a and 3i >= -2 - a + 3e and "
4322 "1073741822e <= 1073741823 - a + 1073741822b + c and "
4323 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
4324 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
4325 "1073741823e >= 1 + 1073741823b - d and "
4326 "3i >= 1073741823b + c - 1073741823e - f and "
4327 "3i >= 1 + 2b + e + 3g }";
4328 bset1
= isl_basic_set_read_from_str(ctx
, str
);
4329 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
4330 empty
= isl_basic_set_is_empty(bset2
);
4331 subset
= isl_basic_set_is_subset(bset2
, bset1
);
4332 isl_basic_set_free(bset1
);
4333 isl_basic_set_free(bset2
);
4334 if (empty
< 0 || subset
< 0)
4337 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
4339 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
4344 int test_fixed_power(isl_ctx
*ctx
)
4352 str
= "{ [i] -> [i + 1] }";
4353 map
= isl_map_read_from_str(ctx
, str
);
4354 isl_int_set_si(exp
, 23);
4355 map
= isl_map_fixed_power(map
, exp
);
4356 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
4365 int test_slice(isl_ctx
*ctx
)
4371 str
= "{ [i] -> [j] }";
4372 map
= isl_map_read_from_str(ctx
, str
);
4373 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
4374 equal
= map_check_equal(map
, "{ [i] -> [i] }");
4379 str
= "{ [i] -> [j] }";
4380 map
= isl_map_read_from_str(ctx
, str
);
4381 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
4382 equal
= map_check_equal(map
, "{ [i] -> [j] }");
4387 str
= "{ [i] -> [j] }";
4388 map
= isl_map_read_from_str(ctx
, str
);
4389 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
4390 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
4395 str
= "{ [i] -> [j] }";
4396 map
= isl_map_read_from_str(ctx
, str
);
4397 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
4398 equal
= map_check_equal(map
, "{ [0] -> [j] }");
4403 str
= "{ [i] -> [j] }";
4404 map
= isl_map_read_from_str(ctx
, str
);
4405 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
4406 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
4411 str
= "{ [i] -> [j] }";
4412 map
= isl_map_read_from_str(ctx
, str
);
4413 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
4414 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
4422 int test_eliminate(isl_ctx
*ctx
)
4428 str
= "{ [i] -> [j] : i = 2j }";
4429 map
= isl_map_read_from_str(ctx
, str
);
4430 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
4431 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
4439 /* Check that isl_set_dim_residue_class detects that the values of j
4440 * in the set below are all odd and that it does not detect any spurious
4443 static int test_residue_class(isl_ctx
*ctx
)
4450 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
4451 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
4452 set
= isl_set_read_from_str(ctx
, str
);
4455 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
4457 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
4458 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
4467 int test_align_parameters(isl_ctx
*ctx
)
4471 isl_multi_aff
*ma1
, *ma2
;
4474 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
4475 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
4477 space
= isl_space_params_alloc(ctx
, 1);
4478 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
4479 ma1
= isl_multi_aff_align_params(ma1
, space
);
4481 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
4482 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
4484 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4486 isl_multi_aff_free(ma1
);
4487 isl_multi_aff_free(ma2
);
4492 isl_die(ctx
, isl_error_unknown
,
4493 "result not as expected", return -1);
4498 static int test_list(isl_ctx
*ctx
)
4500 isl_id
*a
, *b
, *c
, *d
, *id
;
4504 a
= isl_id_alloc(ctx
, "a", NULL
);
4505 b
= isl_id_alloc(ctx
, "b", NULL
);
4506 c
= isl_id_alloc(ctx
, "c", NULL
);
4507 d
= isl_id_alloc(ctx
, "d", NULL
);
4509 list
= isl_id_list_alloc(ctx
, 4);
4510 list
= isl_id_list_add(list
, a
);
4511 list
= isl_id_list_add(list
, b
);
4512 list
= isl_id_list_add(list
, c
);
4513 list
= isl_id_list_add(list
, d
);
4514 list
= isl_id_list_drop(list
, 1, 1);
4516 if (isl_id_list_n_id(list
) != 3) {
4517 isl_id_list_free(list
);
4518 isl_die(ctx
, isl_error_unknown
,
4519 "unexpected number of elements in list", return -1);
4522 id
= isl_id_list_get_id(list
, 0);
4525 id
= isl_id_list_get_id(list
, 1);
4528 id
= isl_id_list_get_id(list
, 2);
4532 isl_id_list_free(list
);
4535 isl_die(ctx
, isl_error_unknown
,
4536 "unexpected elements in list", return -1);
4541 const char *set_conversion_tests
[] = {
4542 "[N] -> { [i] : N - 1 <= 2 i <= N }",
4543 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
4544 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4545 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4546 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
4549 /* Check that converting from isl_set to isl_pw_multi_aff and back
4550 * to isl_set produces the original isl_set.
4552 static int test_set_conversion(isl_ctx
*ctx
)
4556 isl_set
*set1
, *set2
;
4557 isl_pw_multi_aff
*pma
;
4560 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
4561 str
= set_conversion_tests
[i
];
4562 set1
= isl_set_read_from_str(ctx
, str
);
4563 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
4564 set2
= isl_set_from_pw_multi_aff(pma
);
4565 equal
= isl_set_is_equal(set1
, set2
);
4572 isl_die(ctx
, isl_error_unknown
, "bad conversion",
4579 /* Check that converting from isl_map to isl_pw_multi_aff and back
4580 * to isl_map produces the original isl_map.
4582 static int test_map_conversion(isl_ctx
*ctx
)
4585 isl_map
*map1
, *map2
;
4586 isl_pw_multi_aff
*pma
;
4589 str
= "{ [a, b, c, d] -> s0[a, b, e, f] : "
4590 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
4591 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
4592 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
4594 map1
= isl_map_read_from_str(ctx
, str
);
4595 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
4596 map2
= isl_map_from_pw_multi_aff(pma
);
4597 equal
= isl_map_is_equal(map1
, map2
);
4604 isl_die(ctx
, isl_error_unknown
, "bad conversion", return -1);
4609 static int test_conversion(isl_ctx
*ctx
)
4611 if (test_set_conversion(ctx
) < 0)
4613 if (test_map_conversion(ctx
) < 0)
4618 /* Check that isl_basic_map_curry does not modify input.
4620 static int test_curry(isl_ctx
*ctx
)
4623 isl_basic_map
*bmap1
, *bmap2
;
4626 str
= "{ [A[] -> B[]] -> C[] }";
4627 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
4628 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
4629 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
4630 isl_basic_map_free(bmap1
);
4631 isl_basic_map_free(bmap2
);
4636 isl_die(ctx
, isl_error_unknown
,
4637 "curried map should not be equal to original",
4647 } preimage_tests
[] = {
4648 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
4649 "{ A[j,i] -> B[i,j] }",
4650 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
4651 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4652 "{ A[a,b] -> B[a/2,b/6] }",
4653 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
4654 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4655 "{ A[a,b] -> B[a/2,b/6] }",
4656 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
4657 "exists i,j : a = 2 i and b = 6 j }" },
4658 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
4659 "[n] -> { : 0 <= n <= 100 }" },
4660 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4661 "{ A[a] -> B[2a] }",
4662 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
4663 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4664 "{ A[a] -> B[([a/2])] }",
4665 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
4666 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
4667 "{ A[a] -> B[a,a,a/3] }",
4668 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
4669 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
4670 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
4673 static int test_preimage_basic_set(isl_ctx
*ctx
)
4676 isl_basic_set
*bset1
, *bset2
;
4680 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
4681 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
4682 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
4683 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
4684 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
4685 equal
= isl_basic_set_is_equal(bset1
, bset2
);
4686 isl_basic_set_free(bset1
);
4687 isl_basic_set_free(bset2
);
4691 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4702 } preimage_domain_tests
[] = {
4703 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
4704 "{ A[j,i] -> B[i,j] }",
4705 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
4706 { "{ B[i] -> C[i]; D[i] -> E[i] }",
4707 "{ A[i] -> B[i + 1] }",
4708 "{ A[i] -> C[i + 1] }" },
4709 { "{ B[i] -> C[i]; B[i] -> E[i] }",
4710 "{ A[i] -> B[i + 1] }",
4711 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
4712 { "{ B[i] -> C[([i/2])] }",
4713 "{ A[i] -> B[2i] }",
4714 "{ A[i] -> C[i] }" },
4715 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
4716 "{ A[i] -> B[([i/5]), ([i/7])] }",
4717 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
4718 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
4719 "[N] -> { A[] -> B[([N/5])] }",
4720 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
4721 { "{ B[i] -> C[i] : exists a : i = 5 a }",
4722 "{ A[i] -> B[2i] }",
4723 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
4724 { "{ B[i] -> C[i] : exists a : i = 2 a; "
4725 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
4726 "{ A[i] -> B[2i] }",
4727 "{ A[i] -> C[2i] }" },
4730 static int test_preimage_union_map(isl_ctx
*ctx
)
4733 isl_union_map
*umap1
, *umap2
;
4737 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
4738 umap1
= isl_union_map_read_from_str(ctx
,
4739 preimage_domain_tests
[i
].map
);
4740 ma
= isl_multi_aff_read_from_str(ctx
,
4741 preimage_domain_tests
[i
].ma
);
4742 umap2
= isl_union_map_read_from_str(ctx
,
4743 preimage_domain_tests
[i
].res
);
4744 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
4745 equal
= isl_union_map_is_equal(umap1
, umap2
);
4746 isl_union_map_free(umap1
);
4747 isl_union_map_free(umap2
);
4751 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4758 static int test_preimage(isl_ctx
*ctx
)
4760 if (test_preimage_basic_set(ctx
) < 0)
4762 if (test_preimage_union_map(ctx
) < 0)
4772 } pullback_tests
[] = {
4773 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
4774 "{ A[a,b] -> C[b + 2a] }" },
4775 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
4776 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
4777 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
4778 "{ A[a] -> C[(a)/6] }" },
4779 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
4780 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
4781 "{ A[a] -> C[(2a)/3] }" },
4782 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
4783 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
4784 "{ A[i,j] -> C[i + j, i + j] }"},
4785 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
4786 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
4787 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
4788 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
4789 "{ [i, j] -> [floor((i)/3), j] }",
4790 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
4793 static int test_pullback(isl_ctx
*ctx
)
4796 isl_multi_aff
*ma1
, *ma2
;
4800 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
4801 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
4802 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
4803 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
4804 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
4805 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4806 isl_multi_aff_free(ma1
);
4807 isl_multi_aff_free(ma2
);
4811 isl_die(ctx
, isl_error_unknown
, "bad pullback",
4818 /* Check that negation is printed correctly and that equal expressions
4819 * are correctly identified.
4821 static int test_ast(isl_ctx
*ctx
)
4823 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
4827 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4828 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4829 expr
= isl_ast_expr_add(expr1
, expr2
);
4830 expr2
= isl_ast_expr_copy(expr
);
4831 expr
= isl_ast_expr_neg(expr
);
4832 expr2
= isl_ast_expr_neg(expr2
);
4833 equal
= isl_ast_expr_is_equal(expr
, expr2
);
4834 str
= isl_ast_expr_to_str(expr
);
4835 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
4837 isl_ast_expr_free(expr
);
4838 isl_ast_expr_free(expr2
);
4840 if (ok
< 0 || equal
< 0)
4843 isl_die(ctx
, isl_error_unknown
,
4844 "equal expressions not considered equal", return -1);
4846 isl_die(ctx
, isl_error_unknown
,
4847 "isl_ast_expr printed incorrectly", return -1);
4849 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4850 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4851 expr
= isl_ast_expr_add(expr1
, expr2
);
4852 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
4853 expr
= isl_ast_expr_sub(expr3
, expr
);
4854 str
= isl_ast_expr_to_str(expr
);
4855 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
4857 isl_ast_expr_free(expr
);
4862 isl_die(ctx
, isl_error_unknown
,
4863 "isl_ast_expr printed incorrectly", return -1);
4868 /* Check that isl_ast_build_expr_from_set returns a valid expression
4869 * for an empty set. Note that isl_ast_build_expr_from_set getting
4870 * called on an empty set probably indicates a bug in the caller.
4872 static int test_ast_build(isl_ctx
*ctx
)
4875 isl_ast_build
*build
;
4878 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4879 build
= isl_ast_build_from_context(set
);
4881 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
4882 expr
= isl_ast_build_expr_from_set(build
, set
);
4884 isl_ast_expr_free(expr
);
4885 isl_ast_build_free(build
);
4893 /* Internal data structure for before_for and after_for callbacks.
4895 * depth is the current depth
4896 * before is the number of times before_for has been called
4897 * after is the number of times after_for has been called
4899 struct isl_test_codegen_data
{
4905 /* This function is called before each for loop in the AST generated
4906 * from test_ast_gen1.
4908 * Increment the number of calls and the depth.
4909 * Check that the space returned by isl_ast_build_get_schedule_space
4910 * matches the target space of the schedule returned by
4911 * isl_ast_build_get_schedule.
4912 * Return an isl_id that is checked by the corresponding call
4915 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
4918 struct isl_test_codegen_data
*data
= user
;
4921 isl_union_map
*schedule
;
4922 isl_union_set
*uset
;
4927 ctx
= isl_ast_build_get_ctx(build
);
4929 if (data
->before
>= 3)
4930 isl_die(ctx
, isl_error_unknown
,
4931 "unexpected number of for nodes", return NULL
);
4932 if (data
->depth
>= 2)
4933 isl_die(ctx
, isl_error_unknown
,
4934 "unexpected depth", return NULL
);
4936 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
4940 schedule
= isl_ast_build_get_schedule(build
);
4941 uset
= isl_union_map_range(schedule
);
4944 if (isl_union_set_n_set(uset
) != 1) {
4945 isl_union_set_free(uset
);
4946 isl_die(ctx
, isl_error_unknown
,
4947 "expecting single range space", return NULL
);
4950 space
= isl_ast_build_get_schedule_space(build
);
4951 set
= isl_union_set_extract_set(uset
, space
);
4952 isl_union_set_free(uset
);
4953 empty
= isl_set_is_empty(set
);
4959 isl_die(ctx
, isl_error_unknown
,
4960 "spaces don't match", return NULL
);
4962 return isl_id_alloc(ctx
, name
, NULL
);
4965 /* This function is called after each for loop in the AST generated
4966 * from test_ast_gen1.
4968 * Increment the number of calls and decrement the depth.
4969 * Check that the annotation attached to the node matches
4970 * the isl_id returned by the corresponding call to before_for.
4972 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
4973 __isl_keep isl_ast_build
*build
, void *user
)
4975 struct isl_test_codegen_data
*data
= user
;
4983 if (data
->after
> data
->before
)
4984 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4985 "mismatch in number of for nodes",
4986 return isl_ast_node_free(node
));
4988 id
= isl_ast_node_get_annotation(node
);
4990 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4991 "missing annotation", return isl_ast_node_free(node
));
4993 name
= isl_id_get_name(id
);
4994 valid
= name
&& atoi(name
+ 1) == data
->depth
;
4998 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4999 "wrong annotation", return isl_ast_node_free(node
));
5004 /* Check that the before_each_for and after_each_for callbacks
5005 * are called for each for loop in the generated code,
5006 * that they are called in the right order and that the isl_id
5007 * returned from the before_each_for callback is attached to
5008 * the isl_ast_node passed to the corresponding after_each_for call.
5010 static int test_ast_gen1(isl_ctx
*ctx
)
5014 isl_union_map
*schedule
;
5015 isl_ast_build
*build
;
5017 struct isl_test_codegen_data data
;
5019 str
= "[N] -> { : N >= 10 }";
5020 set
= isl_set_read_from_str(ctx
, str
);
5021 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
5022 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
5023 schedule
= isl_union_map_read_from_str(ctx
, str
);
5028 build
= isl_ast_build_from_context(set
);
5029 build
= isl_ast_build_set_before_each_for(build
,
5030 &before_for
, &data
);
5031 build
= isl_ast_build_set_after_each_for(build
,
5033 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5034 isl_ast_build_free(build
);
5038 isl_ast_node_free(tree
);
5040 if (data
.before
!= 3 || data
.after
!= 3)
5041 isl_die(ctx
, isl_error_unknown
,
5042 "unexpected number of for nodes", return -1);
5047 /* Check that the AST generator handles domains that are integrally disjoint
5048 * but not ratinoally disjoint.
5050 static int test_ast_gen2(isl_ctx
*ctx
)
5054 isl_union_map
*schedule
;
5055 isl_union_map
*options
;
5056 isl_ast_build
*build
;
5059 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
5060 schedule
= isl_union_map_read_from_str(ctx
, str
);
5061 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5062 build
= isl_ast_build_from_context(set
);
5064 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
5065 options
= isl_union_map_read_from_str(ctx
, str
);
5066 build
= isl_ast_build_set_options(build
, options
);
5067 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5068 isl_ast_build_free(build
);
5071 isl_ast_node_free(tree
);
5076 /* Increment *user on each call.
5078 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
5079 __isl_keep isl_ast_build
*build
, void *user
)
5088 /* Test that unrolling tries to minimize the number of instances.
5089 * In particular, for the schedule given below, make sure it generates
5090 * 3 nodes (rather than 101).
5092 static int test_ast_gen3(isl_ctx
*ctx
)
5096 isl_union_map
*schedule
;
5097 isl_union_map
*options
;
5098 isl_ast_build
*build
;
5102 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
5103 schedule
= isl_union_map_read_from_str(ctx
, str
);
5104 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5106 str
= "{ [i] -> unroll[0] }";
5107 options
= isl_union_map_read_from_str(ctx
, str
);
5109 build
= isl_ast_build_from_context(set
);
5110 build
= isl_ast_build_set_options(build
, options
);
5111 build
= isl_ast_build_set_at_each_domain(build
,
5112 &count_domains
, &n_domain
);
5113 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5114 isl_ast_build_free(build
);
5118 isl_ast_node_free(tree
);
5121 isl_die(ctx
, isl_error_unknown
,
5122 "unexpected number of for nodes", return -1);
5127 /* Check that if the ast_build_exploit_nested_bounds options is set,
5128 * we do not get an outer if node in the generated AST,
5129 * while we do get such an outer if node if the options is not set.
5131 static int test_ast_gen4(isl_ctx
*ctx
)
5135 isl_union_map
*schedule
;
5136 isl_ast_build
*build
;
5138 enum isl_ast_node_type type
;
5141 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
5142 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
5144 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
5146 schedule
= isl_union_map_read_from_str(ctx
, str
);
5147 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5148 build
= isl_ast_build_from_context(set
);
5149 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5150 isl_ast_build_free(build
);
5154 type
= isl_ast_node_get_type(tree
);
5155 isl_ast_node_free(tree
);
5157 if (type
== isl_ast_node_if
)
5158 isl_die(ctx
, isl_error_unknown
,
5159 "not expecting if node", return -1);
5161 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
5163 schedule
= isl_union_map_read_from_str(ctx
, str
);
5164 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5165 build
= isl_ast_build_from_context(set
);
5166 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5167 isl_ast_build_free(build
);
5171 type
= isl_ast_node_get_type(tree
);
5172 isl_ast_node_free(tree
);
5174 if (type
!= isl_ast_node_if
)
5175 isl_die(ctx
, isl_error_unknown
,
5176 "expecting if node", return -1);
5178 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
5183 /* This function is called for each leaf in the AST generated
5184 * from test_ast_gen5.
5186 * We finalize the AST generation by extending the outer schedule
5187 * with a zero-dimensional schedule. If this results in any for loops,
5188 * then this means that we did not pass along enough information
5189 * about the outer schedule to the inner AST generation.
5191 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
5194 isl_union_map
*schedule
, *extra
;
5197 schedule
= isl_ast_build_get_schedule(build
);
5198 extra
= isl_union_map_copy(schedule
);
5199 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
5200 schedule
= isl_union_map_range_product(schedule
, extra
);
5201 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5202 isl_ast_build_free(build
);
5207 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
5208 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
5209 "code should not contain any for loop",
5210 return isl_ast_node_free(tree
));
5215 /* Check that we do not lose any information when going back and
5216 * forth between internal and external schedule.
5218 * In particular, we create an AST where we unroll the only
5219 * non-constant dimension in the schedule. We therefore do
5220 * not expect any for loops in the AST. However, older versions
5221 * of isl would not pass along enough information about the outer
5222 * schedule when performing an inner code generation from a create_leaf
5223 * callback, resulting in the inner code generation producing a for loop.
5225 static int test_ast_gen5(isl_ctx
*ctx
)
5229 isl_union_map
*schedule
, *options
;
5230 isl_ast_build
*build
;
5233 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
5234 schedule
= isl_union_map_read_from_str(ctx
, str
);
5236 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
5237 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
5238 options
= isl_union_map_read_from_str(ctx
, str
);
5240 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5241 build
= isl_ast_build_from_context(set
);
5242 build
= isl_ast_build_set_options(build
, options
);
5243 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
5244 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5245 isl_ast_build_free(build
);
5246 isl_ast_node_free(tree
);
5253 static int test_ast_gen(isl_ctx
*ctx
)
5255 if (test_ast_gen1(ctx
) < 0)
5257 if (test_ast_gen2(ctx
) < 0)
5259 if (test_ast_gen3(ctx
) < 0)
5261 if (test_ast_gen4(ctx
) < 0)
5263 if (test_ast_gen5(ctx
) < 0)
5268 /* Check if dropping output dimensions from an isl_pw_multi_aff
5271 static int test_pw_multi_aff(isl_ctx
*ctx
)
5274 isl_pw_multi_aff
*pma1
, *pma2
;
5277 str
= "{ [i,j] -> [i+j, 4i-j] }";
5278 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
5279 str
= "{ [i,j] -> [4i-j] }";
5280 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
5282 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
5284 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
5286 isl_pw_multi_aff_free(pma1
);
5287 isl_pw_multi_aff_free(pma2
);
5291 isl_die(ctx
, isl_error_unknown
,
5292 "expressions not equal", return -1);
5297 /* Check that we can properly parse multi piecewise affine expressions
5298 * where the piecewise affine expressions have different domains.
5300 static int test_multi_pw_aff(isl_ctx
*ctx
)
5303 isl_set
*dom
, *dom2
;
5304 isl_multi_pw_aff
*mpa1
, *mpa2
;
5309 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
5310 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
5311 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
5312 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
5313 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
5314 str
= "{ [i] -> [(i : i > 0), 2i] }";
5315 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
5317 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
5319 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
5320 dom
= isl_pw_aff_domain(pa
);
5321 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
5322 dom2
= isl_pw_aff_domain(pa
);
5323 equal_domain
= isl_set_is_equal(dom
, dom2
);
5327 isl_multi_pw_aff_free(mpa1
);
5328 isl_multi_pw_aff_free(mpa2
);
5333 isl_die(ctx
, isl_error_unknown
,
5334 "expressions not equal", return -1);
5336 if (equal_domain
< 0)
5339 isl_die(ctx
, isl_error_unknown
,
5340 "domains unexpectedly equal", return -1);
5345 /* This is a regression test for a bug where isl_basic_map_simplify
5346 * would end up in an infinite loop. In particular, we construct
5347 * an empty basic set that is not obviously empty.
5348 * isl_basic_set_is_empty marks the basic set as empty.
5349 * After projecting out i3, the variable can be dropped completely,
5350 * but isl_basic_map_simplify refrains from doing so if the basic set
5351 * is empty and would end up in an infinite loop if it didn't test
5352 * explicitly for empty basic maps in the outer loop.
5354 static int test_simplify(isl_ctx
*ctx
)
5357 isl_basic_set
*bset
;
5360 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
5361 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
5362 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
5364 bset
= isl_basic_set_read_from_str(ctx
, str
);
5365 empty
= isl_basic_set_is_empty(bset
);
5366 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
5367 isl_basic_set_free(bset
);
5371 isl_die(ctx
, isl_error_unknown
,
5372 "basic set should be empty", return -1);
5377 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
5378 * with gbr context would fail to disable the use of the shifted tableau
5379 * when transferring equalities for the input to the context, resulting
5380 * in invalid sample values.
5382 static int test_partial_lexmin(isl_ctx
*ctx
)
5385 isl_basic_set
*bset
;
5386 isl_basic_map
*bmap
;
5389 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
5390 bmap
= isl_basic_map_read_from_str(ctx
, str
);
5391 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
5392 bset
= isl_basic_set_read_from_str(ctx
, str
);
5393 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
5402 /* Check that the variable compression performed on the existentially
5403 * quantified variables inside isl_basic_set_compute_divs is not confused
5404 * by the implicit equalities among the parameters.
5406 static int test_compute_divs(isl_ctx
*ctx
)
5409 isl_basic_set
*bset
;
5412 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
5413 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
5414 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
5415 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
5416 bset
= isl_basic_set_read_from_str(ctx
, str
);
5417 set
= isl_basic_set_compute_divs(bset
);
5425 /* Check that the reaching domain elements and the prefix schedule
5426 * at a leaf node are the same before and after grouping.
5428 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
5433 isl_union_set
*uset
;
5434 isl_multi_union_pw_aff
*mupa
;
5435 isl_union_pw_multi_aff
*upma1
, *upma2
;
5436 isl_union_set
*domain1
, *domain2
;
5437 isl_union_map
*umap1
, *umap2
;
5438 isl_schedule_node
*node
;
5440 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
5441 uset
= isl_union_set_read_from_str(ctx
, str
);
5442 node
= isl_schedule_node_from_domain(uset
);
5443 node
= isl_schedule_node_child(node
, 0);
5444 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
5445 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5446 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
5447 node
= isl_schedule_node_child(node
, 0);
5448 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
5449 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5450 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
5451 node
= isl_schedule_node_child(node
, 0);
5452 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
5453 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
5454 domain1
= isl_schedule_node_get_domain(node
);
5455 id
= isl_id_alloc(ctx
, "group", NULL
);
5456 node
= isl_schedule_node_parent(node
);
5457 node
= isl_schedule_node_group(node
, id
);
5458 node
= isl_schedule_node_child(node
, 0);
5459 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
5460 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
5461 domain2
= isl_schedule_node_get_domain(node
);
5462 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
5463 if (equal
>= 0 && equal
)
5464 equal
= isl_union_set_is_equal(domain1
, domain2
);
5465 if (equal
>= 0 && equal
)
5466 equal
= isl_union_map_is_equal(umap1
, umap2
);
5467 isl_union_map_free(umap1
);
5468 isl_union_map_free(umap2
);
5469 isl_union_set_free(domain1
);
5470 isl_union_set_free(domain2
);
5471 isl_union_pw_multi_aff_free(upma1
);
5472 isl_union_pw_multi_aff_free(upma2
);
5473 isl_schedule_node_free(node
);
5478 isl_die(ctx
, isl_error_unknown
,
5479 "expressions not equal", return -1);
5484 /* Check that we can have nested groupings and that the union map
5485 * schedule representation is the same before and after the grouping.
5486 * Note that after the grouping, the union map representation contains
5487 * the domain constraints from the ranges of the expansion nodes,
5488 * while they are missing from the union map representation of
5489 * the tree without expansion nodes.
5491 * Also check that the global expansion is as expected.
5493 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
5495 int equal
, equal_expansion
;
5498 isl_union_set
*uset
;
5499 isl_union_map
*umap1
, *umap2
;
5500 isl_union_map
*expansion1
, *expansion2
;
5501 isl_union_set_list
*filters
;
5502 isl_multi_union_pw_aff
*mupa
;
5503 isl_schedule
*schedule
;
5504 isl_schedule_node
*node
;
5506 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
5507 "S3[i,j] : 0 <= i,j < 10 }";
5508 uset
= isl_union_set_read_from_str(ctx
, str
);
5509 node
= isl_schedule_node_from_domain(uset
);
5510 node
= isl_schedule_node_child(node
, 0);
5511 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
5512 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5513 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
5514 node
= isl_schedule_node_child(node
, 0);
5515 str
= "{ S1[i,j] }";
5516 uset
= isl_union_set_read_from_str(ctx
, str
);
5517 filters
= isl_union_set_list_from_union_set(uset
);
5518 str
= "{ S2[i,j]; S3[i,j] }";
5519 uset
= isl_union_set_read_from_str(ctx
, str
);
5520 filters
= isl_union_set_list_add(filters
, uset
);
5521 node
= isl_schedule_node_insert_sequence(node
, filters
);
5522 node
= isl_schedule_node_child(node
, 1);
5523 node
= isl_schedule_node_child(node
, 0);
5524 str
= "{ S2[i,j] }";
5525 uset
= isl_union_set_read_from_str(ctx
, str
);
5526 filters
= isl_union_set_list_from_union_set(uset
);
5527 str
= "{ S3[i,j] }";
5528 uset
= isl_union_set_read_from_str(ctx
, str
);
5529 filters
= isl_union_set_list_add(filters
, uset
);
5530 node
= isl_schedule_node_insert_sequence(node
, filters
);
5532 schedule
= isl_schedule_node_get_schedule(node
);
5533 umap1
= isl_schedule_get_map(schedule
);
5534 uset
= isl_schedule_get_domain(schedule
);
5535 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
5536 isl_schedule_free(schedule
);
5538 node
= isl_schedule_node_parent(node
);
5539 node
= isl_schedule_node_parent(node
);
5540 id
= isl_id_alloc(ctx
, "group1", NULL
);
5541 node
= isl_schedule_node_group(node
, id
);
5542 node
= isl_schedule_node_child(node
, 1);
5543 node
= isl_schedule_node_child(node
, 0);
5544 id
= isl_id_alloc(ctx
, "group2", NULL
);
5545 node
= isl_schedule_node_group(node
, id
);
5547 schedule
= isl_schedule_node_get_schedule(node
);
5548 umap2
= isl_schedule_get_map(schedule
);
5549 isl_schedule_free(schedule
);
5551 node
= isl_schedule_node_root(node
);
5552 node
= isl_schedule_node_child(node
, 0);
5553 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
5554 isl_schedule_node_free(node
);
5556 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
5557 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
5558 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
5560 expansion2
= isl_union_map_read_from_str(ctx
, str
);
5562 equal
= isl_union_map_is_equal(umap1
, umap2
);
5563 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
5565 isl_union_map_free(umap1
);
5566 isl_union_map_free(umap2
);
5567 isl_union_map_free(expansion1
);
5568 isl_union_map_free(expansion2
);
5570 if (equal
< 0 || equal_expansion
< 0)
5573 isl_die(ctx
, isl_error_unknown
,
5574 "expressions not equal", return -1);
5575 if (!equal_expansion
)
5576 isl_die(ctx
, isl_error_unknown
,
5577 "unexpected expansion", return -1);
5582 /* Some tests for the isl_schedule_node_group function.
5584 static int test_schedule_tree_group(isl_ctx
*ctx
)
5586 if (test_schedule_tree_group_1(ctx
) < 0)
5588 if (test_schedule_tree_group_2(ctx
) < 0)
5597 { "{ rat: [i] : 0 <= i <= 10 }",
5598 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
5599 { "{ rat: [i] : FALSE }",
5600 "{ rat: coefficients[[cst] -> [a]] }" },
5602 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
5609 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
5610 "{ rat: [i] : 0 <= i <= 10 }" },
5611 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
5613 { "{ rat: coefficients[[cst] -> [a]] }",
5614 "{ rat: [i] : FALSE }" },
5617 /* Test the basic functionality of isl_basic_set_coefficients and
5618 * isl_basic_set_solutions.
5620 static int test_dual(isl_ctx
*ctx
)
5624 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
5626 isl_basic_set
*bset1
, *bset2
;
5628 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
5629 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
5630 bset1
= isl_basic_set_coefficients(bset1
);
5631 equal
= isl_basic_set_is_equal(bset1
, bset2
);
5632 isl_basic_set_free(bset1
);
5633 isl_basic_set_free(bset2
);
5637 isl_die(ctx
, isl_error_unknown
,
5638 "incorrect dual", return -1);
5641 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
5643 isl_basic_set
*bset1
, *bset2
;
5645 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
5646 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
5647 bset1
= isl_basic_set_solutions(bset1
);
5648 equal
= isl_basic_set_is_equal(bset1
, bset2
);
5649 isl_basic_set_free(bset1
);
5650 isl_basic_set_free(bset2
);
5654 isl_die(ctx
, isl_error_unknown
,
5655 "incorrect dual", return -1);
5665 const char *schedule
;
5670 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
5671 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5673 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
5674 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5676 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
5677 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5679 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
5680 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5682 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
5683 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5685 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
5686 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
5688 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
5689 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5691 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
5692 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
5696 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
5697 * tile the band and then check if the tile and point bands have the
5698 * expected partial schedule.
5700 static int test_tile(isl_ctx
*ctx
)
5706 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
5707 shift
= isl_options_get_tile_shift_point_loops(ctx
);
5709 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
5713 isl_union_set
*domain
;
5714 isl_multi_union_pw_aff
*mupa
, *mupa2
;
5715 isl_schedule_node
*node
;
5716 isl_multi_val
*sizes
;
5718 opt
= tile_tests
[i
].scale_tile
;
5719 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
5720 opt
= tile_tests
[i
].shift_point
;
5721 isl_options_set_tile_shift_point_loops(ctx
, opt
);
5723 str
= tile_tests
[i
].domain
;
5724 domain
= isl_union_set_read_from_str(ctx
, str
);
5725 node
= isl_schedule_node_from_domain(domain
);
5726 node
= isl_schedule_node_child(node
, 0);
5727 str
= tile_tests
[i
].schedule
;
5728 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5729 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
5730 str
= tile_tests
[i
].sizes
;
5731 sizes
= isl_multi_val_read_from_str(ctx
, str
);
5732 node
= isl_schedule_node_band_tile(node
, sizes
);
5734 str
= tile_tests
[i
].tile
;
5735 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5736 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
5737 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
5738 isl_multi_union_pw_aff_free(mupa
);
5739 isl_multi_union_pw_aff_free(mupa2
);
5741 node
= isl_schedule_node_child(node
, 0);
5743 str
= tile_tests
[i
].point
;
5744 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5745 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
5746 if (equal
>= 0 && equal
)
5747 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
5749 isl_multi_union_pw_aff_free(mupa
);
5750 isl_multi_union_pw_aff_free(mupa2
);
5752 isl_schedule_node_free(node
);
5757 isl_die(ctx
, isl_error_unknown
,
5758 "unexpected result", return -1);
5761 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
5762 isl_options_set_tile_shift_point_loops(ctx
, shift
);
5769 int (*fn
)(isl_ctx
*ctx
);
5771 { "dual", &test_dual
},
5772 { "dependence analysis", &test_flow
},
5773 { "val", &test_val
},
5774 { "compute divs", &test_compute_divs
},
5775 { "partial lexmin", &test_partial_lexmin
},
5776 { "simplify", &test_simplify
},
5777 { "curry", &test_curry
},
5778 { "piecewise multi affine expressions", &test_pw_multi_aff
},
5779 { "multi piecewise affine expressions", &test_multi_pw_aff
},
5780 { "conversion", &test_conversion
},
5781 { "list", &test_list
},
5782 { "align parameters", &test_align_parameters
},
5783 { "preimage", &test_preimage
},
5784 { "pullback", &test_pullback
},
5785 { "AST", &test_ast
},
5786 { "AST build", &test_ast_build
},
5787 { "AST generation", &test_ast_gen
},
5788 { "eliminate", &test_eliminate
},
5789 { "residue class", &test_residue_class
},
5790 { "div", &test_div
},
5791 { "slice", &test_slice
},
5792 { "fixed power", &test_fixed_power
},
5793 { "sample", &test_sample
},
5794 { "output", &test_output
},
5795 { "vertices", &test_vertices
},
5796 { "fixed", &test_fixed
},
5797 { "equal", &test_equal
},
5798 { "disjoint", &test_disjoint
},
5799 { "product", &test_product
},
5800 { "dim_max", &test_dim_max
},
5801 { "affine", &test_aff
},
5802 { "injective", &test_injective
},
5803 { "schedule", &test_schedule
},
5804 { "schedule tree grouping", &test_schedule_tree_group
},
5805 { "tile", &test_tile
},
5806 { "union_pw", &test_union_pw
},
5807 { "parse", &test_parse
},
5808 { "single-valued", &test_sv
},
5809 { "affine hull", &test_affine_hull
},
5810 { "coalesce", &test_coalesce
},
5811 { "factorize", &test_factorize
},
5812 { "subset", &test_subset
},
5813 { "subtract", &test_subtract
},
5814 { "lexmin", &test_lexmin
},
5815 { "min", &test_min
},
5816 { "gist", &test_gist
},
5817 { "piecewise quasi-polynomials", &test_pwqp
},
5818 { "lift", &test_lift
},
5819 { "bound", &test_bound
},
5820 { "union", &test_union
},
5821 { "split periods", &test_split_periods
},
5822 { "lexicographic order", &test_lex
},
5823 { "bijectivity", &test_bijective
},
5824 { "dataflow analysis", &test_dep
},
5825 { "reading", &test_read
},
5826 { "bounded", &test_bounded
},
5827 { "construction", &test_construction
},
5828 { "dimension manipulation", &test_dim
},
5829 { "map application", &test_application
},
5830 { "convex hull", &test_convex_hull
},
5831 { "transitive closure", &test_closure
},
5834 int main(int argc
, char **argv
)
5837 struct isl_ctx
*ctx
;
5838 struct isl_options
*options
;
5840 srcdir
= getenv("srcdir");
5843 options
= isl_options_new_with_defaults();
5845 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
5847 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
5848 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
5849 printf("%s\n", tests
[i
].name
);
5850 if (tests
[i
].fn(ctx
) < 0)