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_set.h>
29 #include <isl/union_map.h>
30 #include <isl_factorization.h>
31 #include <isl/schedule.h>
32 #include <isl/schedule_node.h>
33 #include <isl_options_private.h>
34 #include <isl/vertices.h>
35 #include <isl/ast_build.h>
38 #include <isl_ast_build_expr.h>
39 #include <isl/options.h>
41 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
45 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
48 char *pattern
= "%s/test_inputs/%s.%s";
50 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
52 filename
= isl_alloc_array(ctx
, char, length
);
57 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
62 void test_parse_map(isl_ctx
*ctx
, const char *str
)
66 map
= isl_map_read_from_str(ctx
, str
);
71 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
76 map
= isl_map_read_from_str(ctx
, str
);
77 map2
= isl_map_read_from_str(ctx
, str2
);
78 equal
= isl_map_is_equal(map
, map2
);
85 isl_die(ctx
, isl_error_unknown
, "maps not equal",
91 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
93 isl_pw_qpolynomial
*pwqp
;
95 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
97 isl_pw_qpolynomial_free(pwqp
);
100 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
104 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
106 isl_pw_aff_free(pwaff
);
109 /* Check that we can read an isl_multi_val from "str" without errors.
111 static int test_parse_multi_val(isl_ctx
*ctx
, const char *str
)
115 mv
= isl_multi_val_read_from_str(ctx
, str
);
116 isl_multi_val_free(mv
);
121 int test_parse(struct isl_ctx
*ctx
)
124 const char *str
, *str2
;
126 if (test_parse_multi_val(ctx
, "{ A[B[2] -> C[5, 7]] }") < 0)
128 if (test_parse_multi_val(ctx
, "[n] -> { [2] }") < 0)
130 if (test_parse_multi_val(ctx
, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0)
133 str
= "{ [i] -> [-i] }";
134 map
= isl_map_read_from_str(ctx
, str
);
138 str
= "{ A[i] -> L[([i/3])] }";
139 map
= isl_map_read_from_str(ctx
, str
);
143 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
144 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
145 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
147 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
148 str2
= "{ [x, y] : 2y >= 6 - x }";
149 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
152 if (test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
153 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
155 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
156 if (test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }",
160 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
161 map
= isl_map_read_from_str(ctx
, str
);
162 str
= "{ [new, old] -> [o0, o1] : "
163 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
164 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
165 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
166 map2
= isl_map_read_from_str(ctx
, str
);
167 assert(isl_map_is_equal(map
, map2
));
171 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
172 map
= isl_map_read_from_str(ctx
, str
);
173 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
174 map2
= isl_map_read_from_str(ctx
, str
);
175 assert(isl_map_is_equal(map
, map2
));
179 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
180 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
181 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
184 str
= "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
185 str2
= "{ [i,j] -> [min(i,j)] }";
186 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
189 str
= "{ [i,j] : i != j }";
190 str2
= "{ [i,j] : i < j or i > j }";
191 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
194 str
= "{ [i,j] : (i+1)*2 >= j }";
195 str2
= "{ [i, j] : j <= 2 + 2i }";
196 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
199 str
= "{ [i] -> [i > 0 ? 4 : 5] }";
200 str2
= "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
201 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
204 str
= "[N=2,M] -> { [i=[(M+N)/4]] }";
205 str2
= "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
206 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
209 str
= "{ [x] : x >= 0 }";
210 str2
= "{ [x] : x-0 >= 0 }";
211 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
214 str
= "{ [i] : ((i > 10)) }";
215 str2
= "{ [i] : i >= 11 }";
216 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
219 str
= "{ [i] -> [0] }";
220 str2
= "{ [i] -> [0 * i] }";
221 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
224 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
225 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
226 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
227 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
229 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : (not false) }",
230 "{ [a] -> [b] : true }") < 0)
233 if (test_parse_map_equal(ctx
, "{ [i] : i/2 <= 5 }",
234 "{ [i] : i <= 10 }") < 0)
237 if (test_parse_map_equal(ctx
, "{Sym=[n] [i] : i <= n }",
238 "[n] -> { [i] : i <= n }") < 0)
241 if (test_parse_map_equal(ctx
, "{ [*] }", "{ [a] }") < 0)
244 if (test_parse_map_equal(ctx
, "{ [i] : 2*floor(i/2) = i }",
245 "{ [i] : exists a : i = 2 a }") < 0)
248 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : a = 5 implies b = 5 }",
249 "{ [a] -> [b] : a != 5 or b = 5 }") < 0)
252 if (test_parse_map_equal(ctx
, "{ [a] -> [a - 1 : a > 0] }",
253 "{ [a] -> [a - 1] : a > 0 }") < 0)
255 if (test_parse_map_equal(ctx
,
256 "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
257 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }") < 0)
259 if (test_parse_map_equal(ctx
,
260 "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
261 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
263 if (test_parse_map_equal(ctx
,
264 "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
265 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
267 if (test_parse_map_equal(ctx
,
268 "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
269 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
271 if (test_parse_map_equal(ctx
,
272 "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
273 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
279 static int test_read(isl_ctx
*ctx
)
283 isl_basic_set
*bset1
, *bset2
;
284 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
287 filename
= get_filename(ctx
, "set", "omega");
289 input
= fopen(filename
, "r");
292 bset1
= isl_basic_set_read_from_file(ctx
, input
);
293 bset2
= isl_basic_set_read_from_str(ctx
, str
);
295 equal
= isl_basic_set_is_equal(bset1
, bset2
);
297 isl_basic_set_free(bset1
);
298 isl_basic_set_free(bset2
);
306 isl_die(ctx
, isl_error_unknown
,
307 "read sets not equal", return -1);
312 static int test_bounded(isl_ctx
*ctx
)
317 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
318 bounded
= isl_set_is_bounded(set
);
324 isl_die(ctx
, isl_error_unknown
,
325 "set not considered bounded", return -1);
327 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
328 bounded
= isl_set_is_bounded(set
);
335 isl_die(ctx
, isl_error_unknown
,
336 "set considered bounded", return -1);
338 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
339 bounded
= isl_set_is_bounded(set
);
345 isl_die(ctx
, isl_error_unknown
,
346 "set considered bounded", return -1);
351 /* Construct the basic set { [i] : 5 <= i <= N } */
352 static int test_construction(isl_ctx
*ctx
)
362 dim
= isl_space_set_alloc(ctx
, 1, 1);
363 bset
= isl_basic_set_universe(isl_space_copy(dim
));
364 ls
= isl_local_space_from_space(dim
);
366 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
367 isl_int_set_si(v
, -1);
368 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
369 isl_int_set_si(v
, 1);
370 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
371 bset
= isl_basic_set_add_constraint(bset
, c
);
373 c
= isl_constraint_alloc_inequality(isl_local_space_copy(ls
));
374 isl_int_set_si(v
, 1);
375 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
376 isl_int_set_si(v
, -5);
377 isl_constraint_set_constant(c
, v
);
378 bset
= isl_basic_set_add_constraint(bset
, c
);
380 isl_local_space_free(ls
);
381 isl_basic_set_free(bset
);
388 static int test_dim(isl_ctx
*ctx
)
391 isl_map
*map1
, *map2
;
394 map1
= isl_map_read_from_str(ctx
,
395 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
396 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
397 map2
= isl_map_read_from_str(ctx
,
398 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
399 equal
= isl_map_is_equal(map1
, map2
);
402 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
403 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
404 if (equal
>= 0 && equal
)
405 equal
= isl_map_is_equal(map1
, map2
);
413 isl_die(ctx
, isl_error_unknown
,
414 "unexpected result", return -1);
416 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
417 map1
= isl_map_read_from_str(ctx
, str
);
418 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
419 map2
= isl_map_read_from_str(ctx
, str
);
420 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
421 equal
= isl_map_is_equal(map1
, map2
);
428 isl_die(ctx
, isl_error_unknown
,
429 "unexpected result", return -1);
435 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
439 { &isl_val_neg
, "0", "0" },
440 { &isl_val_abs
, "0", "0" },
441 { &isl_val_2exp
, "0", "1" },
442 { &isl_val_floor
, "0", "0" },
443 { &isl_val_ceil
, "0", "0" },
444 { &isl_val_neg
, "1", "-1" },
445 { &isl_val_neg
, "-1", "1" },
446 { &isl_val_neg
, "1/2", "-1/2" },
447 { &isl_val_neg
, "-1/2", "1/2" },
448 { &isl_val_neg
, "infty", "-infty" },
449 { &isl_val_neg
, "-infty", "infty" },
450 { &isl_val_neg
, "NaN", "NaN" },
451 { &isl_val_abs
, "1", "1" },
452 { &isl_val_abs
, "-1", "1" },
453 { &isl_val_abs
, "1/2", "1/2" },
454 { &isl_val_abs
, "-1/2", "1/2" },
455 { &isl_val_abs
, "infty", "infty" },
456 { &isl_val_abs
, "-infty", "infty" },
457 { &isl_val_abs
, "NaN", "NaN" },
458 { &isl_val_floor
, "1", "1" },
459 { &isl_val_floor
, "-1", "-1" },
460 { &isl_val_floor
, "1/2", "0" },
461 { &isl_val_floor
, "-1/2", "-1" },
462 { &isl_val_floor
, "infty", "infty" },
463 { &isl_val_floor
, "-infty", "-infty" },
464 { &isl_val_floor
, "NaN", "NaN" },
465 { &isl_val_ceil
, "1", "1" },
466 { &isl_val_ceil
, "-1", "-1" },
467 { &isl_val_ceil
, "1/2", "1" },
468 { &isl_val_ceil
, "-1/2", "0" },
469 { &isl_val_ceil
, "infty", "infty" },
470 { &isl_val_ceil
, "-infty", "-infty" },
471 { &isl_val_ceil
, "NaN", "NaN" },
472 { &isl_val_2exp
, "-3", "1/8" },
473 { &isl_val_2exp
, "-1", "1/2" },
474 { &isl_val_2exp
, "1", "2" },
475 { &isl_val_2exp
, "2", "4" },
476 { &isl_val_2exp
, "3", "8" },
477 { &isl_val_inv
, "1", "1" },
478 { &isl_val_inv
, "2", "1/2" },
479 { &isl_val_inv
, "1/2", "2" },
480 { &isl_val_inv
, "-2", "-1/2" },
481 { &isl_val_inv
, "-1/2", "-2" },
482 { &isl_val_inv
, "0", "NaN" },
483 { &isl_val_inv
, "NaN", "NaN" },
484 { &isl_val_inv
, "infty", "0" },
485 { &isl_val_inv
, "-infty", "0" },
488 /* Perform some basic tests of unary operations on isl_val objects.
490 static int test_un_val(isl_ctx
*ctx
)
494 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
497 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
498 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
499 res
= isl_val_read_from_str(ctx
, val_un_tests
[i
].res
);
500 fn
= val_un_tests
[i
].op
;
502 if (isl_val_is_nan(res
))
503 ok
= isl_val_is_nan(v
);
505 ok
= isl_val_eq(v
, res
);
511 isl_die(ctx
, isl_error_unknown
,
512 "unexpected result", return -1);
519 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
520 __isl_take isl_val
*v2
);
522 ['+'] = { &isl_val_add
},
523 ['-'] = { &isl_val_sub
},
524 ['*'] = { &isl_val_mul
},
525 ['/'] = { &isl_val_div
},
526 ['g'] = { &isl_val_gcd
},
527 ['m'] = { &isl_val_min
},
528 ['M'] = { &isl_val_max
},
536 } val_bin_tests
[] = {
537 { "0", '+', "0", "0" },
538 { "1", '+', "0", "1" },
539 { "1", '+', "1", "2" },
540 { "1", '-', "1", "0" },
541 { "1", '*', "1", "1" },
542 { "1", '/', "1", "1" },
543 { "2", '*', "3", "6" },
544 { "2", '*', "1/2", "1" },
545 { "2", '*', "1/3", "2/3" },
546 { "2/3", '*', "3/5", "2/5" },
547 { "2/3", '*', "7/5", "14/15" },
548 { "2", '/', "1/2", "4" },
549 { "-2", '/', "-1/2", "4" },
550 { "-2", '/', "1/2", "-4" },
551 { "2", '/', "-1/2", "-4" },
552 { "2", '/', "2", "1" },
553 { "2", '/', "3", "2/3" },
554 { "2/3", '/', "5/3", "2/5" },
555 { "2/3", '/', "5/7", "14/15" },
556 { "0", '/', "0", "NaN" },
557 { "42", '/', "0", "NaN" },
558 { "-42", '/', "0", "NaN" },
559 { "infty", '/', "0", "NaN" },
560 { "-infty", '/', "0", "NaN" },
561 { "NaN", '/', "0", "NaN" },
562 { "0", '/', "NaN", "NaN" },
563 { "42", '/', "NaN", "NaN" },
564 { "-42", '/', "NaN", "NaN" },
565 { "infty", '/', "NaN", "NaN" },
566 { "-infty", '/', "NaN", "NaN" },
567 { "NaN", '/', "NaN", "NaN" },
568 { "0", '/', "infty", "0" },
569 { "42", '/', "infty", "0" },
570 { "-42", '/', "infty", "0" },
571 { "infty", '/', "infty", "NaN" },
572 { "-infty", '/', "infty", "NaN" },
573 { "NaN", '/', "infty", "NaN" },
574 { "0", '/', "-infty", "0" },
575 { "42", '/', "-infty", "0" },
576 { "-42", '/', "-infty", "0" },
577 { "infty", '/', "-infty", "NaN" },
578 { "-infty", '/', "-infty", "NaN" },
579 { "NaN", '/', "-infty", "NaN" },
580 { "1", '-', "1/3", "2/3" },
581 { "1/3", '+', "1/2", "5/6" },
582 { "1/2", '+', "1/2", "1" },
583 { "3/4", '-', "1/4", "1/2" },
584 { "1/2", '-', "1/3", "1/6" },
585 { "infty", '+', "42", "infty" },
586 { "infty", '+', "infty", "infty" },
587 { "42", '+', "infty", "infty" },
588 { "infty", '-', "infty", "NaN" },
589 { "infty", '*', "infty", "infty" },
590 { "infty", '*', "-infty", "-infty" },
591 { "-infty", '*', "infty", "-infty" },
592 { "-infty", '*', "-infty", "infty" },
593 { "0", '*', "infty", "NaN" },
594 { "1", '*', "infty", "infty" },
595 { "infty", '*', "0", "NaN" },
596 { "infty", '*', "42", "infty" },
597 { "42", '-', "infty", "-infty" },
598 { "infty", '+', "-infty", "NaN" },
599 { "4", 'g', "6", "2" },
600 { "5", 'g', "6", "1" },
601 { "42", 'm', "3", "3" },
602 { "42", 'M', "3", "42" },
603 { "3", 'm', "42", "3" },
604 { "3", 'M', "42", "42" },
605 { "42", 'm', "infty", "42" },
606 { "42", 'M', "infty", "infty" },
607 { "42", 'm', "-infty", "-infty" },
608 { "42", 'M', "-infty", "42" },
609 { "42", 'm', "NaN", "NaN" },
610 { "42", 'M', "NaN", "NaN" },
611 { "infty", 'm', "-infty", "-infty" },
612 { "infty", 'M', "-infty", "infty" },
615 /* Perform some basic tests of binary operations on isl_val objects.
617 static int test_bin_val(isl_ctx
*ctx
)
620 isl_val
*v1
, *v2
, *res
;
621 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
622 __isl_take isl_val
*v2
);
625 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
626 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
627 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
628 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
629 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
631 if (isl_val_is_nan(res
))
632 ok
= isl_val_is_nan(v1
);
634 ok
= isl_val_eq(v1
, res
);
640 isl_die(ctx
, isl_error_unknown
,
641 "unexpected result", return -1);
647 /* Perform some basic tests on isl_val objects.
649 static int test_val(isl_ctx
*ctx
)
651 if (test_un_val(ctx
) < 0)
653 if (test_bin_val(ctx
) < 0)
658 static int test_div(isl_ctx
*ctx
)
667 struct isl_basic_set
*bset
;
668 struct isl_constraint
*c
;
673 dim
= isl_space_set_alloc(ctx
, 0, 3);
674 bset
= isl_basic_set_universe(isl_space_copy(dim
));
675 ls
= isl_local_space_from_space(dim
);
677 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
678 isl_int_set_si(v
, -1);
679 isl_constraint_set_constant(c
, v
);
680 isl_int_set_si(v
, 1);
681 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
682 isl_int_set_si(v
, 3);
683 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
684 bset
= isl_basic_set_add_constraint(bset
, c
);
686 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
687 isl_int_set_si(v
, 1);
688 isl_constraint_set_constant(c
, v
);
689 isl_int_set_si(v
, -1);
690 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
691 isl_int_set_si(v
, 3);
692 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
693 bset
= isl_basic_set_add_constraint(bset
, c
);
695 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
697 assert(bset
&& bset
->n_div
== 1);
698 isl_local_space_free(ls
);
699 isl_basic_set_free(bset
);
702 dim
= isl_space_set_alloc(ctx
, 0, 3);
703 bset
= isl_basic_set_universe(isl_space_copy(dim
));
704 ls
= isl_local_space_from_space(dim
);
706 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
707 isl_int_set_si(v
, 1);
708 isl_constraint_set_constant(c
, v
);
709 isl_int_set_si(v
, -1);
710 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
711 isl_int_set_si(v
, 3);
712 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
713 bset
= isl_basic_set_add_constraint(bset
, c
);
715 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
716 isl_int_set_si(v
, -1);
717 isl_constraint_set_constant(c
, v
);
718 isl_int_set_si(v
, 1);
719 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
720 isl_int_set_si(v
, 3);
721 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
722 bset
= isl_basic_set_add_constraint(bset
, c
);
724 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
726 assert(bset
&& bset
->n_div
== 1);
727 isl_local_space_free(ls
);
728 isl_basic_set_free(bset
);
731 dim
= isl_space_set_alloc(ctx
, 0, 3);
732 bset
= isl_basic_set_universe(isl_space_copy(dim
));
733 ls
= isl_local_space_from_space(dim
);
735 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
736 isl_int_set_si(v
, 1);
737 isl_constraint_set_constant(c
, v
);
738 isl_int_set_si(v
, -1);
739 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
740 isl_int_set_si(v
, 3);
741 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
742 bset
= isl_basic_set_add_constraint(bset
, c
);
744 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
745 isl_int_set_si(v
, -3);
746 isl_constraint_set_constant(c
, v
);
747 isl_int_set_si(v
, 1);
748 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
749 isl_int_set_si(v
, 4);
750 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
751 bset
= isl_basic_set_add_constraint(bset
, c
);
753 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
755 assert(bset
&& bset
->n_div
== 1);
756 isl_local_space_free(ls
);
757 isl_basic_set_free(bset
);
760 dim
= isl_space_set_alloc(ctx
, 0, 3);
761 bset
= isl_basic_set_universe(isl_space_copy(dim
));
762 ls
= isl_local_space_from_space(dim
);
764 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
765 isl_int_set_si(v
, 2);
766 isl_constraint_set_constant(c
, v
);
767 isl_int_set_si(v
, -1);
768 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
769 isl_int_set_si(v
, 3);
770 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
771 bset
= isl_basic_set_add_constraint(bset
, c
);
773 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
774 isl_int_set_si(v
, -1);
775 isl_constraint_set_constant(c
, v
);
776 isl_int_set_si(v
, 1);
777 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
778 isl_int_set_si(v
, 6);
779 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
780 bset
= isl_basic_set_add_constraint(bset
, c
);
782 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
784 assert(isl_basic_set_is_empty(bset
));
785 isl_local_space_free(ls
);
786 isl_basic_set_free(bset
);
789 dim
= isl_space_set_alloc(ctx
, 0, 3);
790 bset
= isl_basic_set_universe(isl_space_copy(dim
));
791 ls
= isl_local_space_from_space(dim
);
793 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
794 isl_int_set_si(v
, -1);
795 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
796 isl_int_set_si(v
, 3);
797 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
798 bset
= isl_basic_set_add_constraint(bset
, c
);
800 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
801 isl_int_set_si(v
, 1);
802 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
803 isl_int_set_si(v
, -3);
804 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
805 bset
= isl_basic_set_add_constraint(bset
, c
);
807 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
809 assert(bset
&& bset
->n_div
== 0);
810 isl_basic_set_free(bset
);
811 isl_local_space_free(ls
);
814 dim
= isl_space_set_alloc(ctx
, 0, 3);
815 bset
= isl_basic_set_universe(isl_space_copy(dim
));
816 ls
= isl_local_space_from_space(dim
);
818 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
819 isl_int_set_si(v
, -1);
820 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
821 isl_int_set_si(v
, 6);
822 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
823 bset
= isl_basic_set_add_constraint(bset
, c
);
825 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
826 isl_int_set_si(v
, 1);
827 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
828 isl_int_set_si(v
, -3);
829 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
830 bset
= isl_basic_set_add_constraint(bset
, c
);
832 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
834 assert(bset
&& bset
->n_div
== 1);
835 isl_basic_set_free(bset
);
836 isl_local_space_free(ls
);
839 /* This test is a bit tricky. We set up an equality
841 * Normalization of divs creates _two_ divs
844 * Afterwards e0 is removed again because it has coefficient -1
845 * and we end up with the original equality and div again.
846 * Perhaps we can avoid the introduction of this temporary div.
848 dim
= isl_space_set_alloc(ctx
, 0, 4);
849 bset
= isl_basic_set_universe(isl_space_copy(dim
));
850 ls
= isl_local_space_from_space(dim
);
852 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
853 isl_int_set_si(v
, -1);
854 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
855 isl_int_set_si(v
, -3);
856 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
857 isl_int_set_si(v
, -3);
858 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
859 isl_int_set_si(v
, 6);
860 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
861 bset
= isl_basic_set_add_constraint(bset
, c
);
863 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
865 /* Test disabled for now */
867 assert(bset && bset->n_div == 1);
869 isl_local_space_free(ls
);
870 isl_basic_set_free(bset
);
873 dim
= isl_space_set_alloc(ctx
, 0, 5);
874 bset
= isl_basic_set_universe(isl_space_copy(dim
));
875 ls
= isl_local_space_from_space(dim
);
877 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
878 isl_int_set_si(v
, -1);
879 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
880 isl_int_set_si(v
, -3);
881 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
882 isl_int_set_si(v
, -3);
883 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
884 isl_int_set_si(v
, 6);
885 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
886 bset
= isl_basic_set_add_constraint(bset
, c
);
888 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
889 isl_int_set_si(v
, -1);
890 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
891 isl_int_set_si(v
, 1);
892 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
893 isl_int_set_si(v
, 1);
894 isl_constraint_set_constant(c
, v
);
895 bset
= isl_basic_set_add_constraint(bset
, c
);
897 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
899 /* Test disabled for now */
901 assert(bset && bset->n_div == 1);
903 isl_local_space_free(ls
);
904 isl_basic_set_free(bset
);
907 dim
= isl_space_set_alloc(ctx
, 0, 4);
908 bset
= isl_basic_set_universe(isl_space_copy(dim
));
909 ls
= isl_local_space_from_space(dim
);
911 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
912 isl_int_set_si(v
, 1);
913 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
914 isl_int_set_si(v
, -1);
915 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
916 isl_int_set_si(v
, -2);
917 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
918 bset
= isl_basic_set_add_constraint(bset
, c
);
920 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
921 isl_int_set_si(v
, -1);
922 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
923 isl_int_set_si(v
, 3);
924 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
925 isl_int_set_si(v
, 2);
926 isl_constraint_set_constant(c
, v
);
927 bset
= isl_basic_set_add_constraint(bset
, c
);
929 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
931 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
933 assert(!isl_basic_set_is_empty(bset
));
935 isl_local_space_free(ls
);
936 isl_basic_set_free(bset
);
939 dim
= isl_space_set_alloc(ctx
, 0, 3);
940 bset
= isl_basic_set_universe(isl_space_copy(dim
));
941 ls
= isl_local_space_from_space(dim
);
943 c
= isl_constraint_alloc_equality(isl_local_space_copy(ls
));
944 isl_int_set_si(v
, 1);
945 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
946 isl_int_set_si(v
, -2);
947 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
948 bset
= isl_basic_set_add_constraint(bset
, c
);
950 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
952 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
954 isl_local_space_free(ls
);
955 isl_basic_set_free(bset
);
959 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
960 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
961 set
= isl_set_read_from_str(ctx
, str
);
962 set
= isl_set_compute_divs(set
);
967 str
= "{ [i,j] : 2*[i/2] + 3 * [j/4] <= 10 and 2 i = j }";
968 bset
= isl_basic_set_read_from_str(ctx
, str
);
969 n
= isl_basic_set_dim(bset
, isl_dim_div
);
970 isl_basic_set_free(bset
);
974 isl_die(ctx
, isl_error_unknown
,
975 "expecting no existentials", return -1);
977 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
978 set
= isl_set_read_from_str(ctx
, str
);
979 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
980 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
981 empty
= isl_set_is_empty(set
);
986 isl_die(ctx
, isl_error_unknown
,
987 "result not as accurate as expected", return -1);
992 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
996 struct isl_basic_set
*bset1
, *bset2
;
997 struct isl_basic_map
*bmap
;
999 filename
= get_filename(ctx
, name
, "omega");
1001 input
= fopen(filename
, "r");
1004 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1005 bmap
= isl_basic_map_read_from_file(ctx
, input
);
1007 bset1
= isl_basic_set_apply(bset1
, bmap
);
1009 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1011 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1013 isl_basic_set_free(bset1
);
1014 isl_basic_set_free(bset2
);
1020 static int test_application(isl_ctx
*ctx
)
1022 test_application_case(ctx
, "application");
1023 test_application_case(ctx
, "application2");
1028 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
1032 struct isl_basic_set
*bset1
, *bset2
;
1034 filename
= get_filename(ctx
, name
, "polylib");
1036 input
= fopen(filename
, "r");
1039 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1040 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1042 bset1
= isl_basic_set_affine_hull(bset1
);
1044 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1046 isl_basic_set_free(bset1
);
1047 isl_basic_set_free(bset2
);
1053 int test_affine_hull(struct isl_ctx
*ctx
)
1057 isl_basic_set
*bset
, *bset2
;
1061 test_affine_hull_case(ctx
, "affine2");
1062 test_affine_hull_case(ctx
, "affine");
1063 test_affine_hull_case(ctx
, "affine3");
1065 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
1066 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1067 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1068 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1069 set
= isl_set_read_from_str(ctx
, str
);
1070 bset
= isl_set_affine_hull(set
);
1071 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1072 isl_basic_set_free(bset
);
1074 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1077 /* Check that isl_map_affine_hull is not confused by
1078 * the reordering of divs in isl_map_align_divs.
1080 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1081 "32e0 = b and 32e1 = c); "
1082 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1083 set
= isl_set_read_from_str(ctx
, str
);
1084 bset
= isl_set_affine_hull(set
);
1085 isl_basic_set_free(bset
);
1089 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1090 "32e2 = 31 + 31e0 }";
1091 set
= isl_set_read_from_str(ctx
, str
);
1092 bset
= isl_set_affine_hull(set
);
1093 str
= "{ [a] : exists e : a = 32 e }";
1094 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1095 subset
= isl_basic_set_is_subset(bset
, bset2
);
1096 isl_basic_set_free(bset
);
1097 isl_basic_set_free(bset2
);
1101 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1107 static int test_simple_hull(struct isl_ctx
*ctx
)
1111 isl_basic_set
*bset
;
1114 str
= "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x;"
1115 "[y, x] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }";
1116 set
= isl_set_read_from_str(ctx
, str
);
1117 bset
= isl_set_simple_hull(set
);
1118 is_empty
= isl_basic_set_is_empty(bset
);
1119 isl_basic_set_free(bset
);
1121 if (is_empty
== isl_bool_error
)
1124 if (is_empty
== isl_bool_false
)
1125 isl_die(ctx
, isl_error_unknown
, "Empty set should be detected",
1131 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1135 struct isl_basic_set
*bset1
, *bset2
;
1136 struct isl_set
*set
;
1138 filename
= get_filename(ctx
, name
, "polylib");
1140 input
= fopen(filename
, "r");
1143 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1144 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1146 set
= isl_basic_set_union(bset1
, bset2
);
1147 bset1
= isl_set_convex_hull(set
);
1149 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1151 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1153 isl_basic_set_free(bset1
);
1154 isl_basic_set_free(bset2
);
1163 } convex_hull_tests
[] = {
1164 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1165 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1166 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1167 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1168 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1169 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1170 "i2 <= 5 and i2 >= 4; "
1171 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1172 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1173 "i2 <= 5 + i0 and i2 >= i0 }" },
1174 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1175 "{ [x, y] : 1 = 0 }" },
1178 static int test_convex_hull_algo(isl_ctx
*ctx
, int convex
)
1181 int orig_convex
= ctx
->opt
->convex
;
1182 ctx
->opt
->convex
= convex
;
1184 test_convex_hull_case(ctx
, "convex0");
1185 test_convex_hull_case(ctx
, "convex1");
1186 test_convex_hull_case(ctx
, "convex2");
1187 test_convex_hull_case(ctx
, "convex3");
1188 test_convex_hull_case(ctx
, "convex4");
1189 test_convex_hull_case(ctx
, "convex5");
1190 test_convex_hull_case(ctx
, "convex6");
1191 test_convex_hull_case(ctx
, "convex7");
1192 test_convex_hull_case(ctx
, "convex8");
1193 test_convex_hull_case(ctx
, "convex9");
1194 test_convex_hull_case(ctx
, "convex10");
1195 test_convex_hull_case(ctx
, "convex11");
1196 test_convex_hull_case(ctx
, "convex12");
1197 test_convex_hull_case(ctx
, "convex13");
1198 test_convex_hull_case(ctx
, "convex14");
1199 test_convex_hull_case(ctx
, "convex15");
1201 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1202 isl_set
*set1
, *set2
;
1205 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1206 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1207 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1208 equal
= isl_set_is_equal(set1
, set2
);
1215 isl_die(ctx
, isl_error_unknown
,
1216 "unexpected convex hull", return -1);
1219 ctx
->opt
->convex
= orig_convex
;
1224 static int test_convex_hull(isl_ctx
*ctx
)
1226 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
) < 0)
1228 if (test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
) < 0)
1233 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1237 struct isl_basic_set
*bset1
, *bset2
;
1239 filename
= get_filename(ctx
, name
, "polylib");
1241 input
= fopen(filename
, "r");
1244 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1245 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1247 bset1
= isl_basic_set_gist(bset1
, bset2
);
1249 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1251 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1253 isl_basic_set_free(bset1
);
1254 isl_basic_set_free(bset2
);
1262 const char *context
;
1265 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1266 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1267 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1268 "{ [a, b, c] : a <= 15 }" },
1269 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1270 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1271 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1272 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1273 { "{ [m, n, a, b] : a <= 2147 + n }",
1274 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1275 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1276 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1278 "{ [m, n, ku, kl] }" },
1281 static int test_gist(struct isl_ctx
*ctx
)
1285 isl_basic_set
*bset1
, *bset2
;
1286 isl_map
*map1
, *map2
;
1289 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1291 isl_set
*set1
, *set2
, *copy
;
1293 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1294 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1295 copy
= isl_set_copy(set1
);
1296 set1
= isl_set_gist(set1
, set2
);
1297 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1298 equal
= isl_set_is_equal(set1
, set2
);
1301 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1302 equal_input
= isl_set_is_equal(set1
, copy
);
1305 if (equal
< 0 || equal_input
< 0)
1308 isl_die(ctx
, isl_error_unknown
,
1309 "incorrect gist result", return -1);
1311 isl_die(ctx
, isl_error_unknown
,
1312 "gist modified input", return -1);
1315 test_gist_case(ctx
, "gist1");
1317 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1318 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1319 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1320 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1321 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1322 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1323 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1324 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1325 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1326 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1327 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1328 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1329 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1330 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1331 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1332 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1333 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1334 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1335 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1336 bset1
= isl_basic_set_gist(bset1
, bset2
);
1337 assert(bset1
&& bset1
->n_div
== 0);
1338 isl_basic_set_free(bset1
);
1340 /* Check that the integer divisions of the second disjunct
1341 * do not spread to the first disjunct.
1343 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1344 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1345 "(exists (e0 = [(-1 + t1)/16], "
1346 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1347 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1348 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1349 "o0 <= 4294967295 and t1 <= -1)) }";
1350 map1
= isl_map_read_from_str(ctx
, str
);
1351 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1352 map2
= isl_map_read_from_str(ctx
, str
);
1353 map1
= isl_map_gist(map1
, map2
);
1357 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1358 isl_map_free(map1
); return -1);
1359 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1360 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1361 isl_map_free(map1
); return -1);
1367 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1369 isl_set
*set
, *set2
;
1373 set
= isl_set_read_from_str(ctx
, str
);
1374 set
= isl_set_coalesce(set
);
1375 set2
= isl_set_read_from_str(ctx
, str
);
1376 equal
= isl_set_is_equal(set
, set2
);
1377 one
= set
&& set
->n
== 1;
1384 isl_die(ctx
, isl_error_unknown
,
1385 "coalesced set not equal to input", return -1);
1386 if (check_one
&& !one
)
1387 isl_die(ctx
, isl_error_unknown
,
1388 "coalesced set should not be a union", return -1);
1393 /* Inputs for coalescing tests with unbounded wrapping.
1394 * "str" is a string representation of the input set.
1395 * "single_disjunct" is set if we expect the result to consist of
1396 * a single disjunct.
1399 int single_disjunct
;
1401 } coalesce_unbounded_tests
[] = {
1402 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1403 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1404 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1405 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1407 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1408 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1409 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1410 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1413 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1414 * option turned off.
1416 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1422 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1423 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1425 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
1426 const char *str
= coalesce_unbounded_tests
[i
].str
;
1427 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
1428 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
1434 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1439 /* Inputs for coalescing tests.
1440 * "str" is a string representation of the input set.
1441 * "single_disjunct" is set if we expect the result to consist of
1442 * a single disjunct.
1445 int single_disjunct
;
1447 } coalesce_tests
[] = {
1448 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1449 "y >= x & x >= 2 & 5 >= y }" },
1450 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1451 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1452 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1453 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1454 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1455 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1456 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1457 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1458 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1459 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1460 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1461 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1462 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1463 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1464 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1465 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1466 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1467 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1468 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1469 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1470 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1471 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1472 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1473 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1474 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1475 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1476 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1477 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1478 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1479 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1480 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1481 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1482 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1483 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1484 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1485 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1486 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1487 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1488 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1489 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1490 "[o0, o1, o2, o3, o4, o5, o6]] : "
1491 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1492 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1493 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1494 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1495 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1496 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1497 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1498 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1499 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1500 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1501 "o6 >= i3 + i6 - o3 and M >= 0 and "
1502 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1503 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1504 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1505 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1506 "(o0 = 0 and M >= 2 and N >= 3) or "
1507 "(M = 0 and o0 = 0 and N >= 3) }" },
1508 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1509 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1510 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1511 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1512 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1513 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1514 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1515 "(y = 3 and x = 1) }" },
1516 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1517 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1518 "i1 <= M and i3 <= M and i4 <= M) or "
1519 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1520 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1521 "i4 <= -1 + M) }" },
1522 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1523 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1524 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1525 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1526 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1527 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1528 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1529 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1530 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1531 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1532 { 0, "{ [a, b] : exists e : 2e = a and "
1533 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1534 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1535 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1536 "j >= 1 and j' <= i + j - i' and i >= 1; "
1538 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1539 "[i,j] : exists a : j = 3a }" },
1540 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1541 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1543 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1544 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1545 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1546 "c <= 6 + 8a and a >= 3; "
1547 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1548 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1549 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1550 "[x,0] : 3 <= x <= 4 }" },
1551 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1552 "[x,0] : 4 <= x <= 5 }" },
1553 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1554 "[x,0] : 3 <= x <= 5 }" },
1555 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1556 "[x,0] : 3 <= x <= 4 }" },
1557 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1559 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1560 { 1, "{ [0,0]; [1,1] }" },
1561 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
1562 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
1564 "[k, 0, k] : k <= 6 and k >= 1 }" },
1565 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
1566 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
1567 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
1568 { 1, "[n] -> { [1] : n >= 0;"
1569 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
1570 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
1571 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
1572 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
1573 "2e0 <= x and 2e0 <= n);"
1574 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
1576 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
1577 "128e0 >= -134 + 127t1 and t1 >= 2 and "
1578 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
1580 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
1581 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
1583 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
1584 "t1 >= 13 and t1 <= 16);"
1585 "[t1] : t1 <= 15 and t1 >= 12 }" },
1586 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
1587 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
1588 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
1589 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
1590 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
1591 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
1593 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
1594 "(exists (e0 : 3e0 = -2 + c0)) }" },
1595 { 0, "[n, b0, t0] -> "
1596 "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1597 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1598 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
1599 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
1600 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 >= 8 + n and "
1601 "3i4 <= -96 + 3t0 + i0 and 3i4 >= -95 - n + 3t0 + i0 and "
1602 "i8 >= -157 + i0 - 4i4 and i8 >= 0 and "
1603 "i8 <= -33 + i0 - 4i4 and 3i8 <= -91 + 4n - i0)) or "
1604 "(exists (e0 = floor((-32b0 + i4)/1048576), "
1605 "e1 = floor((i8)/32): 1048576e0 = -32b0 + i4 and 32e1 = i8 and "
1606 "n <= 2147483647 and b0 <= 32767 and b0 >= 0 and "
1607 "32b0 <= -2 + n and t0 <= 31 and t0 >= 0 and i0 <= 7 + n and "
1608 "4i4 <= -3 + i0 and 3i4 <= -96 + 3t0 + i0 and "
1609 "3i4 >= -95 - n + 3t0 + i0 and i8 >= -157 + i0 - 4i4 and "
1610 "i8 >= 0 and i8 <= -4 + i0 - 3i4 and i8 <= -41 + i0));"
1611 "[i0, i1, i2, i3, 0, i5, i6, i7, i8, i9, i10, i11, i12] : "
1612 "(exists (e0 = floor((i8)/32): b0 = 0 and 32e0 = i8 and "
1613 "n <= 2147483647 and t0 <= 31 and t0 >= 0 and i0 >= 11 and "
1614 "i0 >= 96 - 3t0 and i0 <= 95 + n - 3t0 and i0 <= 7 + n and "
1615 "i8 >= -40 + i0 and i8 <= -10 + i0)) }" },
1616 { 0, "{ [i0, i1, i2] : "
1617 "(exists (e0, e1 = floor((i0)/32), e2 = floor((i1)/32): "
1618 "32e1 = i0 and 32e2 = i1 and i1 >= -31 + i0 and "
1619 "i1 <= 31 + i0 and i2 >= -30 + i0 and i2 >= -30 + i1 and "
1620 "32e0 >= -30 + i0 and 32e0 >= -30 + i1 and "
1621 "32e0 >= -31 + i2 and 32e0 <= 30 + i2 and 32e0 <= 31 + i1 and "
1622 "32e0 <= 31 + i0)) or "
1624 { 1, "{ [a, b, c] : 2b = 1 + a and 2c = 2 + a; [0, 0, 0] }" },
1627 /* A specialized coalescing test case that would result
1628 * in a segmentation fault or a failed assertion in earlier versions of isl.
1630 static int test_coalesce_special(struct isl_ctx
*ctx
)
1633 isl_map
*map1
, *map2
;
1635 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
1636 "[[S_L309_IN[] -> T11[]] -> ce_imag2[1, o1]] : "
1637 "(y = 201 and o1 <= 239 and o1 >= 212) or "
1638 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 198 and y >= 3 and "
1639 "o1 <= 239 and o1 >= 212)) or "
1640 "(exists (e0 = [(y)/3]: 3e0 = y and y <= 201 and y >= 3 and "
1641 "o1 <= 241 and o1 >= 240));"
1642 "[S_L220_OUT[] -> T7[]] -> "
1643 "[[S_L309_IN[] -> T11[]] -> ce_imag2[0, o1]] : "
1644 "(y = 2 and o1 <= 241 and o1 >= 212) or "
1645 "(exists (e0 = [(-2 + y)/3]: 3e0 = -2 + y and y <= 200 and "
1646 "y >= 5 and o1 <= 241 and o1 >= 212)) }";
1647 map1
= isl_map_read_from_str(ctx
, str
);
1648 map1
= isl_map_align_divs(map1
);
1649 map1
= isl_map_coalesce(map1
);
1650 str
= "[y] -> { [S_L220_OUT[] -> T7[]] -> "
1651 "[[S_L309_IN[] -> T11[]] -> ce_imag2[o0, o1]] : "
1652 "exists (e0 = [(-1 - y + o0)/3]: 3e0 = -1 - y + o0 and "
1653 "y <= 201 and o0 <= 2 and o1 >= 212 and o1 <= 241 and "
1654 "o0 >= 3 - y and o0 <= -2 + y and o0 >= 0) }";
1655 map2
= isl_map_read_from_str(ctx
, str
);
1656 map2
= isl_map_union(map2
, map1
);
1657 map2
= isl_map_align_divs(map2
);
1658 map2
= isl_map_coalesce(map2
);
1666 /* Test the functionality of isl_set_coalesce.
1667 * That is, check that the output is always equal to the input
1668 * and in some cases that the result consists of a single disjunct.
1670 static int test_coalesce(struct isl_ctx
*ctx
)
1674 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
1675 const char *str
= coalesce_tests
[i
].str
;
1676 int check_one
= coalesce_tests
[i
].single_disjunct
;
1677 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
1681 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
1683 if (test_coalesce_special(ctx
) < 0)
1689 static int test_closure(isl_ctx
*ctx
)
1693 isl_map
*up
, *right
;
1694 isl_map
*map
, *map2
;
1697 /* COCOA example 1 */
1698 map
= isl_map_read_from_str(ctx
,
1699 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1700 "1 <= i and i < n and 1 <= j and j < n or "
1701 "i2 = i + 1 and j2 = j - 1 and "
1702 "1 <= i and i < n and 2 <= j and j <= n }");
1703 map
= isl_map_power(map
, &exact
);
1707 /* COCOA example 1 */
1708 map
= isl_map_read_from_str(ctx
,
1709 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1710 "1 <= i and i < n and 1 <= j and j < n or "
1711 "i2 = i + 1 and j2 = j - 1 and "
1712 "1 <= i and i < n and 2 <= j and j <= n }");
1713 map
= isl_map_transitive_closure(map
, &exact
);
1715 map2
= isl_map_read_from_str(ctx
,
1716 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1717 "1 <= i and i < n and 1 <= j and j <= n and "
1718 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1719 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1720 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1721 assert(isl_map_is_equal(map
, map2
));
1725 map
= isl_map_read_from_str(ctx
,
1726 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1727 " 0 <= y and y <= n }");
1728 map
= isl_map_transitive_closure(map
, &exact
);
1729 map2
= isl_map_read_from_str(ctx
,
1730 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1731 " 0 <= y and y <= n }");
1732 assert(isl_map_is_equal(map
, map2
));
1736 /* COCOA example 2 */
1737 map
= isl_map_read_from_str(ctx
,
1738 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1739 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1740 "i2 = i + 2 and j2 = j - 2 and "
1741 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1742 map
= isl_map_transitive_closure(map
, &exact
);
1744 map2
= isl_map_read_from_str(ctx
,
1745 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1746 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1747 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1748 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1749 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1750 assert(isl_map_is_equal(map
, map2
));
1754 /* COCOA Fig.2 left */
1755 map
= isl_map_read_from_str(ctx
,
1756 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1757 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1759 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1760 "j <= 2 i - 3 and j <= n - 2 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
);
1767 /* COCOA Fig.2 right */
1768 map
= isl_map_read_from_str(ctx
,
1769 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1770 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1772 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1773 "j <= 2 i - 4 and j <= n - 3 or "
1774 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1775 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1776 map
= isl_map_power(map
, &exact
);
1780 /* COCOA Fig.2 right */
1781 map
= isl_map_read_from_str(ctx
,
1782 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1783 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1785 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1786 "j <= 2 i - 4 and j <= n - 3 or "
1787 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1788 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1789 map
= isl_map_transitive_closure(map
, &exact
);
1791 map2
= isl_map_read_from_str(ctx
,
1792 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1793 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1794 "j <= n and 3 + i + 2 j <= 3 n and "
1795 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1796 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1797 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1798 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1799 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1800 assert(isl_map_is_equal(map
, map2
));
1804 /* COCOA Fig.1 right */
1805 dom
= isl_set_read_from_str(ctx
,
1806 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1807 "2 x - 3 y + 3 >= 0 }");
1808 right
= isl_map_read_from_str(ctx
,
1809 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1810 up
= isl_map_read_from_str(ctx
,
1811 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1812 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1813 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1814 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1815 up
= isl_map_intersect_range(up
, dom
);
1816 map
= isl_map_union(up
, right
);
1817 map
= isl_map_transitive_closure(map
, &exact
);
1819 map2
= isl_map_read_from_str(ctx
,
1820 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1821 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1822 assert(isl_map_is_equal(map
, map2
));
1826 /* COCOA Theorem 1 counter example */
1827 map
= isl_map_read_from_str(ctx
,
1828 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1829 "i2 = 1 and j2 = j or "
1830 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1831 map
= isl_map_transitive_closure(map
, &exact
);
1835 map
= isl_map_read_from_str(ctx
,
1836 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1837 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1838 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1839 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1840 map
= isl_map_transitive_closure(map
, &exact
);
1844 /* Kelly et al 1996, fig 12 */
1845 map
= isl_map_read_from_str(ctx
,
1846 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1847 "1 <= i,j,j+1 <= n or "
1848 "j = n and j2 = 1 and i2 = i + 1 and "
1849 "1 <= i,i+1 <= n }");
1850 map
= isl_map_transitive_closure(map
, &exact
);
1852 map2
= isl_map_read_from_str(ctx
,
1853 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1854 "1 <= i <= n and i = i2 or "
1855 "1 <= i < i2 <= n and 1 <= j <= n and "
1857 assert(isl_map_is_equal(map
, map2
));
1861 /* Omega's closure4 */
1862 map
= isl_map_read_from_str(ctx
,
1863 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1864 "1 <= x,y <= 10 or "
1865 "x2 = x + 1 and y2 = y and "
1866 "1 <= x <= 20 && 5 <= y <= 15 }");
1867 map
= isl_map_transitive_closure(map
, &exact
);
1871 map
= isl_map_read_from_str(ctx
,
1872 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1873 map
= isl_map_transitive_closure(map
, &exact
);
1875 map2
= isl_map_read_from_str(ctx
,
1876 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1877 assert(isl_map_is_equal(map
, map2
));
1881 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1882 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1883 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1884 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1885 map
= isl_map_read_from_str(ctx
, str
);
1886 map
= isl_map_transitive_closure(map
, &exact
);
1888 map2
= isl_map_read_from_str(ctx
, str
);
1889 assert(isl_map_is_equal(map
, map2
));
1893 str
= "{[0] -> [1]; [2] -> [3]}";
1894 map
= isl_map_read_from_str(ctx
, str
);
1895 map
= isl_map_transitive_closure(map
, &exact
);
1897 map2
= isl_map_read_from_str(ctx
, str
);
1898 assert(isl_map_is_equal(map
, map2
));
1902 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1903 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1904 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1905 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1906 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1907 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1908 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1909 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1910 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1911 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1912 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1913 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1914 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1915 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1916 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1917 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1918 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1919 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1920 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1921 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1922 map
= isl_map_read_from_str(ctx
, str
);
1923 map
= isl_map_transitive_closure(map
, NULL
);
1930 static int test_lex(struct isl_ctx
*ctx
)
1936 dim
= isl_space_set_alloc(ctx
, 0, 0);
1937 map
= isl_map_lex_le(dim
);
1938 empty
= isl_map_is_empty(map
);
1944 isl_die(ctx
, isl_error_unknown
,
1945 "expecting non-empty result", return -1);
1950 static int test_lexmin(struct isl_ctx
*ctx
)
1954 isl_basic_map
*bmap
;
1955 isl_map
*map
, *map2
;
1958 isl_pw_multi_aff
*pma
;
1960 str
= "[p0, p1] -> { [] -> [] : "
1961 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1962 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1963 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1964 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1965 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1966 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1967 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1968 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1969 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1970 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1971 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1972 map
= isl_map_read_from_str(ctx
, str
);
1973 map
= isl_map_lexmin(map
);
1976 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1977 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1978 set
= isl_set_read_from_str(ctx
, str
);
1979 set
= isl_set_lexmax(set
);
1980 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1981 set2
= isl_set_read_from_str(ctx
, str
);
1982 set
= isl_set_intersect(set
, set2
);
1983 assert(!isl_set_is_empty(set
));
1986 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1987 map
= isl_map_read_from_str(ctx
, str
);
1988 map
= isl_map_lexmin(map
);
1989 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1990 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1991 map2
= isl_map_read_from_str(ctx
, str
);
1992 assert(isl_map_is_equal(map
, map2
));
1996 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1997 map
= isl_map_read_from_str(ctx
, str
);
1998 map2
= isl_map_copy(map
);
1999 map
= isl_map_lexmin(map
);
2000 assert(isl_map_is_equal(map
, map2
));
2004 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
2005 map
= isl_map_read_from_str(ctx
, str
);
2006 map
= isl_map_lexmin(map
);
2007 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
2008 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
2009 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
2010 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
2011 map2
= isl_map_read_from_str(ctx
, str
);
2012 assert(isl_map_is_equal(map
, map2
));
2016 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2017 " 8i' <= i and 8i' >= -7 + i }";
2018 bmap
= isl_basic_map_read_from_str(ctx
, str
);
2019 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
2020 map2
= isl_map_from_pw_multi_aff(pma
);
2021 map
= isl_map_from_basic_map(bmap
);
2022 assert(isl_map_is_equal(map
, map2
));
2026 str
= "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
2027 map
= isl_map_read_from_str(ctx
, str
);
2028 map
= isl_map_lexmin(map
);
2029 str
= "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
2030 map2
= isl_map_read_from_str(ctx
, str
);
2031 assert(isl_map_is_equal(map
, map2
));
2035 /* Check that empty pieces are properly combined. */
2036 str
= "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
2037 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
2038 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }";
2039 map
= isl_map_read_from_str(ctx
, str
);
2040 map
= isl_map_lexmin(map
);
2041 str
= "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
2042 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
2044 map2
= isl_map_read_from_str(ctx
, str
);
2045 assert(isl_map_is_equal(map
, map2
));
2049 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
2050 " 8i' <= i and 8i' >= -7 + i }";
2051 set
= isl_set_read_from_str(ctx
, str
);
2052 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
2053 set2
= isl_set_from_pw_multi_aff(pma
);
2054 equal
= isl_set_is_equal(set
, set2
);
2060 isl_die(ctx
, isl_error_unknown
,
2061 "unexpected difference between set and "
2062 "piecewise affine expression", return -1);
2067 /* Check that isl_set_min_val and isl_set_max_val compute the correct
2068 * result on non-convex inputs.
2070 static int test_min(struct isl_ctx
*ctx
)
2077 set
= isl_set_read_from_str(ctx
, "{ [-1]; [1] }");
2078 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x] }");
2079 val
= isl_set_min_val(set
, aff
);
2080 min_ok
= isl_val_is_negone(val
);
2082 val
= isl_set_max_val(set
, aff
);
2083 max_ok
= isl_val_is_one(val
);
2088 if (min_ok
< 0 || max_ok
< 0)
2091 isl_die(ctx
, isl_error_unknown
,
2092 "unexpected minimum", return -1);
2094 isl_die(ctx
, isl_error_unknown
,
2095 "unexpected maximum", return -1);
2105 static isl_stat
collect_must_may(__isl_take isl_map
*dep
, int must
,
2106 void *dep_user
, void *user
)
2108 struct must_may
*mm
= (struct must_may
*)user
;
2111 mm
->must
= isl_map_union(mm
->must
, dep
);
2113 mm
->may
= isl_map_union(mm
->may
, dep
);
2118 static int common_space(void *first
, void *second
)
2120 int depth
= *(int *)first
;
2124 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
2132 map2
= isl_map_read_from_str(map
->ctx
, str
);
2133 equal
= isl_map_is_equal(map
, map2
);
2139 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
2143 equal
= map_is_equal(map
, str
);
2147 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
2148 "result not as expected", return -1);
2152 static int test_dep(struct isl_ctx
*ctx
)
2157 isl_access_info
*ai
;
2164 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2165 map
= isl_map_read_from_str(ctx
, str
);
2166 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2168 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2169 map
= isl_map_read_from_str(ctx
, str
);
2170 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2172 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2173 map
= isl_map_read_from_str(ctx
, str
);
2174 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2176 flow
= isl_access_info_compute_flow(ai
);
2177 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2178 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2179 mm
.may
= isl_map_empty(dim
);
2181 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2183 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
2184 " [1,10,0] -> [2,5,0] }";
2185 assert(map_is_equal(mm
.must
, str
));
2186 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2187 assert(map_is_equal(mm
.may
, str
));
2189 isl_map_free(mm
.must
);
2190 isl_map_free(mm
.may
);
2191 isl_flow_free(flow
);
2194 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2195 map
= isl_map_read_from_str(ctx
, str
);
2196 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2198 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2199 map
= isl_map_read_from_str(ctx
, str
);
2200 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2202 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2203 map
= isl_map_read_from_str(ctx
, str
);
2204 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2206 flow
= isl_access_info_compute_flow(ai
);
2207 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2208 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2209 mm
.may
= isl_map_empty(dim
);
2211 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2213 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2214 assert(map_is_equal(mm
.must
, str
));
2215 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2216 assert(map_is_equal(mm
.may
, str
));
2218 isl_map_free(mm
.must
);
2219 isl_map_free(mm
.may
);
2220 isl_flow_free(flow
);
2223 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2224 map
= isl_map_read_from_str(ctx
, str
);
2225 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2227 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2228 map
= isl_map_read_from_str(ctx
, str
);
2229 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2231 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2232 map
= isl_map_read_from_str(ctx
, str
);
2233 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2235 flow
= isl_access_info_compute_flow(ai
);
2236 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2237 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2238 mm
.may
= isl_map_empty(dim
);
2240 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2242 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
2243 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2244 assert(map_is_equal(mm
.may
, str
));
2245 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2246 assert(map_is_equal(mm
.must
, str
));
2248 isl_map_free(mm
.must
);
2249 isl_map_free(mm
.may
);
2250 isl_flow_free(flow
);
2253 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
2254 map
= isl_map_read_from_str(ctx
, str
);
2255 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2257 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2258 map
= isl_map_read_from_str(ctx
, str
);
2259 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2261 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
2262 map
= isl_map_read_from_str(ctx
, str
);
2263 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2265 flow
= isl_access_info_compute_flow(ai
);
2266 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2267 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2268 mm
.may
= isl_map_empty(dim
);
2270 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2272 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2273 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2274 assert(map_is_equal(mm
.may
, str
));
2275 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2276 assert(map_is_equal(mm
.must
, str
));
2278 isl_map_free(mm
.must
);
2279 isl_map_free(mm
.may
);
2280 isl_flow_free(flow
);
2283 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2284 map
= isl_map_read_from_str(ctx
, str
);
2285 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2287 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2288 map
= isl_map_read_from_str(ctx
, str
);
2289 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2291 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2292 map
= isl_map_read_from_str(ctx
, str
);
2293 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2295 flow
= isl_access_info_compute_flow(ai
);
2296 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2297 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2298 mm
.may
= isl_map_empty(dim
);
2300 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2302 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2303 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2304 assert(map_is_equal(mm
.may
, str
));
2305 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2306 assert(map_is_equal(mm
.must
, str
));
2308 isl_map_free(mm
.must
);
2309 isl_map_free(mm
.may
);
2310 isl_flow_free(flow
);
2315 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2316 map
= isl_map_read_from_str(ctx
, str
);
2317 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
2319 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2320 map
= isl_map_read_from_str(ctx
, str
);
2321 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2323 flow
= isl_access_info_compute_flow(ai
);
2324 dim
= isl_space_alloc(ctx
, 0, 5, 5);
2325 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2326 mm
.may
= isl_map_empty(dim
);
2328 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2330 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
2331 assert(map_is_equal(mm
.must
, str
));
2332 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
2333 assert(map_is_equal(mm
.may
, str
));
2335 isl_map_free(mm
.must
);
2336 isl_map_free(mm
.may
);
2337 isl_flow_free(flow
);
2342 /* Check that the dependence analysis proceeds without errors.
2343 * Earlier versions of isl would break down during the analysis
2344 * due to the use of the wrong spaces.
2346 static int test_flow(isl_ctx
*ctx
)
2349 isl_union_map
*access
, *schedule
;
2350 isl_union_map
*must_dep
, *may_dep
;
2353 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
2354 access
= isl_union_map_read_from_str(ctx
, str
);
2355 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
2356 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
2357 "S2[] -> [1,0,0,0]; "
2358 "S3[] -> [-1,0,0,0] }";
2359 schedule
= isl_union_map_read_from_str(ctx
, str
);
2360 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
2361 isl_union_map_copy(access
), schedule
,
2362 &must_dep
, &may_dep
, NULL
, NULL
);
2363 isl_union_map_free(may_dep
);
2364 isl_union_map_free(must_dep
);
2373 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
2374 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
2375 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
2376 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
2377 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
2378 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
2379 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2380 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2381 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
2384 int test_sv(isl_ctx
*ctx
)
2386 isl_union_map
*umap
;
2390 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
2391 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
2392 sv
= isl_union_map_is_single_valued(umap
);
2393 isl_union_map_free(umap
);
2396 if (sv_tests
[i
].sv
&& !sv
)
2397 isl_die(ctx
, isl_error_internal
,
2398 "map not detected as single valued", return -1);
2399 if (!sv_tests
[i
].sv
&& sv
)
2400 isl_die(ctx
, isl_error_internal
,
2401 "map detected as single valued", return -1);
2410 } bijective_tests
[] = {
2411 { "[N,M]->{[i,j] -> [i]}", 0 },
2412 { "[N,M]->{[i,j] -> [i] : j=i}", 1 },
2413 { "[N,M]->{[i,j] -> [i] : j=0}", 1 },
2414 { "[N,M]->{[i,j] -> [i] : j=N}", 1 },
2415 { "[N,M]->{[i,j] -> [j,i]}", 1 },
2416 { "[N,M]->{[i,j] -> [i+j]}", 0 },
2417 { "[N,M]->{[i,j] -> []}", 0 },
2418 { "[N,M]->{[i,j] -> [i,j,N]}", 1 },
2419 { "[N,M]->{[i,j] -> [2i]}", 0 },
2420 { "[N,M]->{[i,j] -> [i,i]}", 0 },
2421 { "[N,M]->{[i,j] -> [2i,i]}", 0 },
2422 { "[N,M]->{[i,j] -> [2i,j]}", 1 },
2423 { "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1 },
2426 static int test_bijective(struct isl_ctx
*ctx
)
2432 for (i
= 0; i
< ARRAY_SIZE(bijective_tests
); ++i
) {
2433 map
= isl_map_read_from_str(ctx
, bijective_tests
[i
].str
);
2434 bijective
= isl_map_is_bijective(map
);
2438 if (bijective_tests
[i
].bijective
&& !bijective
)
2439 isl_die(ctx
, isl_error_internal
,
2440 "map not detected as bijective", return -1);
2441 if (!bijective_tests
[i
].bijective
&& bijective
)
2442 isl_die(ctx
, isl_error_internal
,
2443 "map detected as bijective", return -1);
2449 /* Inputs for isl_pw_qpolynomial_gist tests.
2450 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
2456 } pwqp_gist_tests
[] = {
2457 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
2458 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
2459 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
2460 "{ [i] -> -1/2 + 1/2 * i }" },
2461 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
2464 static int test_pwqp(struct isl_ctx
*ctx
)
2469 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
2472 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2473 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2475 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
2478 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2479 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2481 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2483 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2485 isl_pw_qpolynomial_free(pwqp1
);
2487 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
2488 str
= pwqp_gist_tests
[i
].pwqp
;
2489 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2490 str
= pwqp_gist_tests
[i
].set
;
2491 set
= isl_set_read_from_str(ctx
, str
);
2492 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2493 str
= pwqp_gist_tests
[i
].gist
;
2494 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2495 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2496 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
2497 isl_pw_qpolynomial_free(pwqp1
);
2502 isl_die(ctx
, isl_error_unknown
,
2503 "unexpected result", return -1);
2506 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
2507 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2508 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
2509 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2511 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2513 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2515 isl_pw_qpolynomial_free(pwqp1
);
2517 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
2518 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2519 str
= "{ [x] -> x }";
2520 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2522 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2524 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2526 isl_pw_qpolynomial_free(pwqp1
);
2528 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
2529 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2530 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2531 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
2532 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2533 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2534 isl_pw_qpolynomial_free(pwqp1
);
2536 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
2537 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2538 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2539 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2540 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
2541 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
2542 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2543 isl_pw_qpolynomial_free(pwqp1
);
2544 isl_pw_qpolynomial_free(pwqp2
);
2548 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2550 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
2551 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2552 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2553 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2554 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
2556 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2557 isl_pw_qpolynomial_free(pwqp1
);
2558 isl_pw_qpolynomial_free(pwqp2
);
2562 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2567 static int test_split_periods(isl_ctx
*ctx
)
2570 isl_pw_qpolynomial
*pwqp
;
2572 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
2573 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
2574 "U >= 0; [U,V] -> U^2 : U >= 100 }";
2575 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2577 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
2579 isl_pw_qpolynomial_free(pwqp
);
2587 static int test_union(isl_ctx
*ctx
)
2590 isl_union_set
*uset1
, *uset2
;
2591 isl_union_map
*umap1
, *umap2
;
2594 str
= "{ [i] : 0 <= i <= 1 }";
2595 uset1
= isl_union_set_read_from_str(ctx
, str
);
2596 str
= "{ [1] -> [0] }";
2597 umap1
= isl_union_map_read_from_str(ctx
, str
);
2599 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
2600 equal
= isl_union_map_is_equal(umap1
, umap2
);
2602 isl_union_map_free(umap1
);
2603 isl_union_map_free(umap2
);
2608 isl_die(ctx
, isl_error_unknown
, "union maps not equal",
2611 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
2612 umap1
= isl_union_map_read_from_str(ctx
, str
);
2613 str
= "{ A[i]; B[i] }";
2614 uset1
= isl_union_set_read_from_str(ctx
, str
);
2616 uset2
= isl_union_map_domain(umap1
);
2618 equal
= isl_union_set_is_equal(uset1
, uset2
);
2620 isl_union_set_free(uset1
);
2621 isl_union_set_free(uset2
);
2626 isl_die(ctx
, isl_error_unknown
, "union sets not equal",
2632 /* Check that computing a bound of a non-zero polynomial over an unbounded
2633 * domain does not produce a rational value.
2634 * Ideally, we want the value to be infinity, but we accept NaN for now.
2635 * We certainly do not want to obtain the value zero.
2637 static int test_bound_unbounded_domain(isl_ctx
*ctx
)
2642 isl_pw_qpolynomial
*pwqp
;
2643 isl_pw_qpolynomial_fold
*pwf
;
2647 str
= "{ [m,n] -> -m * n }";
2648 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2649 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2650 dom
= isl_pw_qpolynomial_fold_domain(isl_pw_qpolynomial_fold_copy(pwf
));
2651 pnt
= isl_set_sample_point(dom
);
2652 v
= isl_pw_qpolynomial_fold_eval(pwf
, pnt
);
2653 is_rat
= isl_val_is_rat(v
);
2659 isl_die(ctx
, isl_error_unknown
,
2660 "unexpected rational value", return -1);
2665 static int test_bound(isl_ctx
*ctx
)
2669 isl_pw_qpolynomial
*pwqp
;
2670 isl_pw_qpolynomial_fold
*pwf
;
2672 if (test_bound_unbounded_domain(ctx
) < 0)
2675 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
2676 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2677 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2678 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
2679 isl_pw_qpolynomial_fold_free(pwf
);
2681 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
2684 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
2685 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2686 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2687 dim
= isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
);
2688 isl_pw_qpolynomial_fold_free(pwf
);
2690 isl_die(ctx
, isl_error_unknown
, "unexpected input dimension",
2696 static int test_lift(isl_ctx
*ctx
)
2699 isl_basic_map
*bmap
;
2700 isl_basic_set
*bset
;
2702 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
2703 bset
= isl_basic_set_read_from_str(ctx
, str
);
2704 bset
= isl_basic_set_lift(bset
);
2705 bmap
= isl_basic_map_from_range(bset
);
2706 bset
= isl_basic_map_domain(bmap
);
2707 isl_basic_set_free(bset
);
2716 } subset_tests
[] = {
2718 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
2719 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
2720 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
2722 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
2723 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
2724 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
2725 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
2726 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
2727 "256e0 <= 255i and 256e0 >= -255 + 255i and "
2728 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
2729 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
2730 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
2731 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
2732 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
2733 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
2734 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
2735 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
2736 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
2737 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
2738 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
2739 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
2740 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
2741 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
2742 "4e0 <= -57 + i0 + i1)) or "
2743 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
2744 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
2745 "4e0 >= -61 + i0 + i1)) or "
2746 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
2749 static int test_subset(isl_ctx
*ctx
)
2752 isl_set
*set1
, *set2
;
2755 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
2756 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
2757 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
2758 subset
= isl_set_is_subset(set1
, set2
);
2763 if (subset
!= subset_tests
[i
].subset
)
2764 isl_die(ctx
, isl_error_unknown
,
2765 "incorrect subset result", return -1);
2772 const char *minuend
;
2773 const char *subtrahend
;
2774 const char *difference
;
2775 } subtract_domain_tests
[] = {
2776 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
2777 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
2778 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
2781 static int test_subtract(isl_ctx
*ctx
)
2784 isl_union_map
*umap1
, *umap2
;
2785 isl_union_pw_multi_aff
*upma1
, *upma2
;
2786 isl_union_set
*uset
;
2789 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2790 umap1
= isl_union_map_read_from_str(ctx
,
2791 subtract_domain_tests
[i
].minuend
);
2792 uset
= isl_union_set_read_from_str(ctx
,
2793 subtract_domain_tests
[i
].subtrahend
);
2794 umap2
= isl_union_map_read_from_str(ctx
,
2795 subtract_domain_tests
[i
].difference
);
2796 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
2797 equal
= isl_union_map_is_equal(umap1
, umap2
);
2798 isl_union_map_free(umap1
);
2799 isl_union_map_free(umap2
);
2803 isl_die(ctx
, isl_error_unknown
,
2804 "incorrect subtract domain result", return -1);
2807 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2808 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
2809 subtract_domain_tests
[i
].minuend
);
2810 uset
= isl_union_set_read_from_str(ctx
,
2811 subtract_domain_tests
[i
].subtrahend
);
2812 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
2813 subtract_domain_tests
[i
].difference
);
2814 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
2815 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
2816 isl_union_pw_multi_aff_free(upma1
);
2817 isl_union_pw_multi_aff_free(upma2
);
2821 isl_die(ctx
, isl_error_unknown
,
2822 "incorrect subtract domain result", return -1);
2828 int test_factorize(isl_ctx
*ctx
)
2831 isl_basic_set
*bset
;
2834 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2835 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2836 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2837 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2838 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2839 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2840 "3i5 >= -2i0 - i2 + 3i4 }";
2841 bset
= isl_basic_set_read_from_str(ctx
, str
);
2842 f
= isl_basic_set_factorizer(bset
);
2843 isl_basic_set_free(bset
);
2844 isl_factorizer_free(f
);
2846 isl_die(ctx
, isl_error_unknown
,
2847 "failed to construct factorizer", return -1);
2849 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2850 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2851 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2852 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2853 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2854 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2855 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2856 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2857 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2858 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2859 bset
= isl_basic_set_read_from_str(ctx
, str
);
2860 f
= isl_basic_set_factorizer(bset
);
2861 isl_basic_set_free(bset
);
2862 isl_factorizer_free(f
);
2864 isl_die(ctx
, isl_error_unknown
,
2865 "failed to construct factorizer", return -1);
2870 static isl_stat
check_injective(__isl_take isl_map
*map
, void *user
)
2872 int *injective
= user
;
2874 *injective
= isl_map_is_injective(map
);
2877 if (*injective
< 0 || !*injective
)
2878 return isl_stat_error
;
2883 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
2884 const char *r
, const char *s
, int tilable
, int parallel
)
2888 isl_union_map
*W
, *R
, *S
;
2889 isl_union_map
*empty
;
2890 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
2891 isl_union_map
*validity
, *proximity
, *coincidence
;
2892 isl_union_map
*schedule
;
2893 isl_union_map
*test
;
2894 isl_union_set
*delta
;
2895 isl_union_set
*domain
;
2899 isl_schedule_constraints
*sc
;
2900 isl_schedule
*sched
;
2901 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
2903 D
= isl_union_set_read_from_str(ctx
, d
);
2904 W
= isl_union_map_read_from_str(ctx
, w
);
2905 R
= isl_union_map_read_from_str(ctx
, r
);
2906 S
= isl_union_map_read_from_str(ctx
, s
);
2908 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
2909 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
2911 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
2912 isl_union_map_compute_flow(isl_union_map_copy(R
),
2913 isl_union_map_copy(W
), empty
,
2914 isl_union_map_copy(S
),
2915 &dep_raw
, NULL
, NULL
, NULL
);
2916 isl_union_map_compute_flow(isl_union_map_copy(W
),
2917 isl_union_map_copy(W
),
2918 isl_union_map_copy(R
),
2919 isl_union_map_copy(S
),
2920 &dep_waw
, &dep_war
, NULL
, NULL
);
2922 dep
= isl_union_map_union(dep_waw
, dep_war
);
2923 dep
= isl_union_map_union(dep
, dep_raw
);
2924 validity
= isl_union_map_copy(dep
);
2925 coincidence
= isl_union_map_copy(dep
);
2926 proximity
= isl_union_map_copy(dep
);
2928 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
2929 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2930 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
2931 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2932 sched
= isl_schedule_constraints_compute_schedule(sc
);
2933 schedule
= isl_schedule_get_map(sched
);
2934 isl_schedule_free(sched
);
2935 isl_union_map_free(W
);
2936 isl_union_map_free(R
);
2937 isl_union_map_free(S
);
2940 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
2942 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
2943 is_complete
= isl_union_set_is_subset(D
, domain
);
2944 isl_union_set_free(D
);
2945 isl_union_set_free(domain
);
2947 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
2948 test
= isl_union_map_apply_range(test
, dep
);
2949 test
= isl_union_map_apply_range(test
, schedule
);
2951 delta
= isl_union_map_deltas(test
);
2952 if (isl_union_set_n_set(delta
) == 0) {
2956 isl_union_set_free(delta
);
2958 delta_set
= isl_set_from_union_set(delta
);
2960 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2961 for (i
= 0; i
< tilable
; ++i
)
2962 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
2963 is_tilable
= isl_set_is_subset(delta_set
, slice
);
2964 isl_set_free(slice
);
2966 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2967 for (i
= 0; i
< parallel
; ++i
)
2968 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
2969 is_parallel
= isl_set_is_subset(delta_set
, slice
);
2970 isl_set_free(slice
);
2972 origin
= isl_set_universe(isl_set_get_space(delta_set
));
2973 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
2974 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
2976 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
2977 delta_set
= isl_set_lexmin(delta_set
);
2979 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
2981 isl_set_free(origin
);
2982 isl_set_free(delta_set
);
2985 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
2986 is_injection
< 0 || is_complete
< 0)
2989 isl_die(ctx
, isl_error_unknown
,
2990 "generated schedule incomplete", return -1);
2992 isl_die(ctx
, isl_error_unknown
,
2993 "generated schedule not injective on each statement",
2996 isl_die(ctx
, isl_error_unknown
,
2997 "negative dependences in generated schedule",
3000 isl_die(ctx
, isl_error_unknown
,
3001 "generated schedule not as tilable as expected",
3004 isl_die(ctx
, isl_error_unknown
,
3005 "generated schedule not as parallel as expected",
3011 /* Compute a schedule for the given instance set, validity constraints,
3012 * proximity constraints and context and return a corresponding union map
3015 static __isl_give isl_union_map
*compute_schedule_with_context(isl_ctx
*ctx
,
3016 const char *domain
, const char *validity
, const char *proximity
,
3017 const char *context
)
3022 isl_union_map
*prox
;
3023 isl_schedule_constraints
*sc
;
3024 isl_schedule
*schedule
;
3025 isl_union_map
*sched
;
3027 con
= isl_set_read_from_str(ctx
, context
);
3028 dom
= isl_union_set_read_from_str(ctx
, domain
);
3029 dep
= isl_union_map_read_from_str(ctx
, validity
);
3030 prox
= isl_union_map_read_from_str(ctx
, proximity
);
3031 sc
= isl_schedule_constraints_on_domain(dom
);
3032 sc
= isl_schedule_constraints_set_context(sc
, con
);
3033 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
3034 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
3035 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3036 sched
= isl_schedule_get_map(schedule
);
3037 isl_schedule_free(schedule
);
3042 /* Compute a schedule for the given instance set, validity constraints and
3043 * proximity constraints and return a corresponding union map representation.
3045 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
3046 const char *domain
, const char *validity
, const char *proximity
)
3048 return compute_schedule_with_context(ctx
, domain
, validity
, proximity
,
3052 /* Check that a schedule can be constructed on the given domain
3053 * with the given validity and proximity constraints.
3055 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
3056 const char *validity
, const char *proximity
)
3058 isl_union_map
*sched
;
3060 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
3064 isl_union_map_free(sched
);
3068 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
3069 const char *validity
, const char *proximity
, const char *expected_sched
)
3071 isl_union_map
*sched1
, *sched2
;
3074 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
3075 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
3077 equal
= isl_union_map_is_equal(sched1
, sched2
);
3078 isl_union_map_free(sched1
);
3079 isl_union_map_free(sched2
);
3084 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
3090 /* Check that the schedule map is properly padded, even after being
3091 * reconstructed from the band forest.
3093 static int test_padded_schedule(isl_ctx
*ctx
)
3097 isl_union_map
*validity
, *proximity
;
3098 isl_schedule_constraints
*sc
;
3099 isl_schedule
*sched
;
3100 isl_union_map
*map1
, *map2
;
3101 isl_band_list
*list
;
3104 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
3105 D
= isl_union_set_read_from_str(ctx
, str
);
3106 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
3107 proximity
= isl_union_map_copy(validity
);
3108 sc
= isl_schedule_constraints_on_domain(D
);
3109 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3110 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3111 sched
= isl_schedule_constraints_compute_schedule(sc
);
3112 map1
= isl_schedule_get_map(sched
);
3113 list
= isl_schedule_get_band_forest(sched
);
3114 isl_band_list_free(list
);
3115 map2
= isl_schedule_get_map(sched
);
3116 isl_schedule_free(sched
);
3117 equal
= isl_union_map_is_equal(map1
, map2
);
3118 isl_union_map_free(map1
);
3119 isl_union_map_free(map2
);
3124 isl_die(ctx
, isl_error_unknown
,
3125 "reconstructed schedule map not the same as original",
3131 /* Check that conditional validity constraints are also taken into
3132 * account across bands.
3133 * In particular, try to make sure that live ranges D[1,0]->C[2,1] and
3134 * D[2,0]->C[3,0] are not local in the outer band of the generated schedule
3135 * and then check that the adjacent order constraint C[2,1]->D[2,0]
3136 * is enforced by the rest of the schedule.
3138 static int test_special_conditional_schedule_constraints(isl_ctx
*ctx
)
3141 isl_union_set
*domain
;
3142 isl_union_map
*validity
, *proximity
, *condition
;
3143 isl_union_map
*sink
, *source
, *dep
;
3144 isl_schedule_constraints
*sc
;
3145 isl_schedule
*schedule
;
3146 isl_union_access_info
*access
;
3147 isl_union_flow
*flow
;
3150 str
= "[n] -> { C[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3151 "A[k] : k >= 1 and k <= -1 + n; "
3152 "B[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k; "
3153 "D[k, i] : k <= -1 + n and i >= 0 and i <= -1 + k }";
3154 domain
= isl_union_set_read_from_str(ctx
, str
);
3155 sc
= isl_schedule_constraints_on_domain(domain
);
3156 str
= "[n] -> { D[k, i] -> C[1 + k, k - i] : "
3157 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3158 "D[k, i] -> C[1 + k, i] : "
3159 "k <= -2 + n and i >= 1 and i <= -1 + k; "
3160 "D[k, 0] -> C[1 + k, k] : k >= 1 and k <= -2 + n; "
3161 "D[k, 0] -> C[1 + k, 0] : k >= 1 and k <= -2 + n }";
3162 validity
= isl_union_map_read_from_str(ctx
, str
);
3163 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
3164 str
= "[n] -> { C[k, i] -> D[k, i] : "
3165 "0 <= i <= -1 + k and k <= -1 + n }";
3166 proximity
= isl_union_map_read_from_str(ctx
, str
);
3167 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
3168 str
= "[n] -> { [D[k, i] -> a[]] -> [C[1 + k, k - i] -> b[]] : "
3169 "i <= -1 + k and i >= 1 and k <= -2 + n; "
3170 "[B[k, i] -> c[]] -> [B[k, 1 + i] -> c[]] : "
3171 "k <= -1 + n and i >= 0 and i <= -2 + k }";
3172 condition
= isl_union_map_read_from_str(ctx
, str
);
3173 str
= "[n] -> { [B[k, i] -> e[]] -> [D[k, i] -> a[]] : "
3174 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3175 "[C[k, i] -> b[]] -> [D[k', -1 + k - i] -> a[]] : "
3176 "i >= 0 and i <= -1 + k and k <= -1 + n and "
3177 "k' <= -1 + n and k' >= k - i and k' >= 1 + k; "
3178 "[C[k, i] -> b[]] -> [D[k, -1 + k - i] -> a[]] : "
3179 "i >= 0 and i <= -1 + k and k <= -1 + n; "
3180 "[B[k, i] -> c[]] -> [A[k'] -> d[]] : "
3181 "k <= -1 + n and i >= 0 and i <= -1 + k and "
3182 "k' >= 1 and k' <= -1 + n and k' >= 1 + k }";
3183 validity
= isl_union_map_read_from_str(ctx
, str
);
3184 sc
= isl_schedule_constraints_set_conditional_validity(sc
, condition
,
3186 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3187 str
= "{ D[2,0] -> [] }";
3188 sink
= isl_union_map_read_from_str(ctx
, str
);
3189 access
= isl_union_access_info_from_sink(sink
);
3190 str
= "{ C[2,1] -> [] }";
3191 source
= isl_union_map_read_from_str(ctx
, str
);
3192 access
= isl_union_access_info_set_must_source(access
, source
);
3193 access
= isl_union_access_info_set_schedule(access
, schedule
);
3194 flow
= isl_union_access_info_compute_flow(access
);
3195 dep
= isl_union_flow_get_must_dependence(flow
);
3196 isl_union_flow_free(flow
);
3197 empty
= isl_union_map_is_empty(dep
);
3198 isl_union_map_free(dep
);
3203 isl_die(ctx
, isl_error_unknown
,
3204 "conditional validity not respected", return -1);
3209 /* Input for testing of schedule construction based on
3210 * conditional constraints.
3212 * domain is the iteration domain
3213 * flow are the flow dependences, which determine the validity and
3214 * proximity constraints
3215 * condition are the conditions on the conditional validity constraints
3216 * conditional_validity are the conditional validity constraints
3217 * outer_band_n is the expected number of members in the outer band
3222 const char *condition
;
3223 const char *conditional_validity
;
3225 } live_range_tests
[] = {
3226 /* Contrived example that illustrates that we need to keep
3227 * track of tagged condition dependences and
3228 * tagged conditional validity dependences
3229 * in isl_sched_edge separately.
3230 * In particular, the conditional validity constraints on A
3231 * cannot be satisfied,
3232 * but they can be ignored because there are no corresponding
3233 * condition constraints. However, we do have an additional
3234 * conditional validity constraint that maps to the same
3235 * dependence relation
3236 * as the condition constraint on B. If we did not make a distinction
3237 * between tagged condition and tagged conditional validity
3238 * dependences, then we
3239 * could end up treating this shared dependence as an condition
3240 * constraint on A, forcing a localization of the conditions,
3241 * which is impossible.
3243 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
3244 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
3245 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
3246 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3247 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
3248 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
3251 /* TACO 2013 Fig. 7 */
3252 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
3253 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3254 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3255 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
3256 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
3257 "0 <= i < n and 0 <= j < n - 1 }",
3258 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
3259 "0 <= i < n and 0 <= j < j' < n;"
3260 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
3261 "0 <= i < i' < n and 0 <= j,j' < n;"
3262 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
3263 "0 <= i,j,j' < n and j < j' }",
3266 /* TACO 2013 Fig. 7, without tags */
3267 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
3268 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3269 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3270 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
3271 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
3272 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
3273 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
3274 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
3277 /* TACO 2013 Fig. 12 */
3278 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
3279 "S3[i,3] : 0 <= i <= 1 }",
3280 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
3281 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
3282 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
3283 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
3284 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
3285 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
3286 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
3287 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
3288 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
3289 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
3290 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
3295 /* Test schedule construction based on conditional constraints.
3296 * In particular, check the number of members in the outer band node
3297 * as an indication of whether tiling is possible or not.
3299 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
3302 isl_union_set
*domain
;
3303 isl_union_map
*condition
;
3304 isl_union_map
*flow
;
3305 isl_union_map
*validity
;
3306 isl_schedule_constraints
*sc
;
3307 isl_schedule
*schedule
;
3308 isl_schedule_node
*node
;
3311 if (test_special_conditional_schedule_constraints(ctx
) < 0)
3314 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
3315 domain
= isl_union_set_read_from_str(ctx
,
3316 live_range_tests
[i
].domain
);
3317 flow
= isl_union_map_read_from_str(ctx
,
3318 live_range_tests
[i
].flow
);
3319 condition
= isl_union_map_read_from_str(ctx
,
3320 live_range_tests
[i
].condition
);
3321 validity
= isl_union_map_read_from_str(ctx
,
3322 live_range_tests
[i
].conditional_validity
);
3323 sc
= isl_schedule_constraints_on_domain(domain
);
3324 sc
= isl_schedule_constraints_set_validity(sc
,
3325 isl_union_map_copy(flow
));
3326 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
3327 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
3328 condition
, validity
);
3329 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3330 node
= isl_schedule_get_root(schedule
);
3332 isl_schedule_node_get_type(node
) != isl_schedule_node_band
)
3333 node
= isl_schedule_node_first_child(node
);
3334 n_member
= isl_schedule_node_band_n_member(node
);
3335 isl_schedule_node_free(node
);
3336 isl_schedule_free(schedule
);
3340 if (n_member
!= live_range_tests
[i
].outer_band_n
)
3341 isl_die(ctx
, isl_error_unknown
,
3342 "unexpected number of members in outer band",
3348 /* Check that the schedule computed for the given instance set and
3349 * dependence relation strongly satisfies the dependences.
3350 * In particular, check that no instance is scheduled before
3351 * or together with an instance on which it depends.
3352 * Earlier versions of isl would produce a schedule that
3353 * only weakly satisfies the dependences.
3355 static int test_strongly_satisfying_schedule(isl_ctx
*ctx
)
3357 const char *domain
, *dep
;
3358 isl_union_map
*D
, *schedule
;
3362 domain
= "{ B[i0, i1] : 0 <= i0 <= 1 and 0 <= i1 <= 11; "
3363 "A[i0] : 0 <= i0 <= 1 }";
3364 dep
= "{ B[i0, i1] -> B[i0, 1 + i1] : 0 <= i0 <= 1 and 0 <= i1 <= 10; "
3365 "B[0, 11] -> A[1]; A[i0] -> B[i0, 0] : 0 <= i0 <= 1 }";
3366 schedule
= compute_schedule(ctx
, domain
, dep
, dep
);
3367 D
= isl_union_map_read_from_str(ctx
, dep
);
3368 D
= isl_union_map_apply_domain(D
, isl_union_map_copy(schedule
));
3369 D
= isl_union_map_apply_range(D
, schedule
);
3370 map
= isl_map_from_union_map(D
);
3371 ge
= isl_map_lex_ge(isl_space_domain(isl_map_get_space(map
)));
3372 map
= isl_map_intersect(map
, ge
);
3373 empty
= isl_map_is_empty(map
);
3379 isl_die(ctx
, isl_error_unknown
,
3380 "dependences not strongly satisfied", return -1);
3385 /* Compute a schedule for input where the instance set constraints
3386 * conflict with the context constraints.
3387 * Earlier versions of isl did not properly handle this situation.
3389 static int test_conflicting_context_schedule(isl_ctx
*ctx
)
3391 isl_union_map
*schedule
;
3392 const char *domain
, *context
;
3394 domain
= "[n] -> { A[] : n >= 0 }";
3395 context
= "[n] -> { : n < 0 }";
3396 schedule
= compute_schedule_with_context(ctx
,
3397 domain
, "{}", "{}", context
);
3398 isl_union_map_free(schedule
);
3406 /* Check that the dependence carrying step is not confused by
3407 * a bound on the coefficient size.
3408 * In particular, force the scheduler to move to a dependence carrying
3409 * step by demanding outer coincidence and bound the size of
3410 * the coefficients. Earlier versions of isl would take this
3411 * bound into account while carrying dependences, breaking
3412 * fundamental assumptions.
3414 static int test_bounded_coefficients_schedule(isl_ctx
*ctx
)
3416 const char *domain
, *dep
;
3419 isl_schedule_constraints
*sc
;
3420 isl_schedule
*schedule
;
3422 domain
= "{ C[i0, i1] : 2 <= i0 <= 3999 and 0 <= i1 <= -1 + i0 }";
3423 dep
= "{ C[i0, i1] -> C[i0, 1 + i1] : i0 <= 3999 and i1 >= 0 and "
3425 "C[i0, -1 + i0] -> C[1 + i0, 0] : i0 <= 3998 and i0 >= 1 }";
3426 I
= isl_union_set_read_from_str(ctx
, domain
);
3427 D
= isl_union_map_read_from_str(ctx
, dep
);
3428 sc
= isl_schedule_constraints_on_domain(I
);
3429 sc
= isl_schedule_constraints_set_validity(sc
, isl_union_map_copy(D
));
3430 sc
= isl_schedule_constraints_set_coincidence(sc
, D
);
3431 isl_options_set_schedule_outer_coincidence(ctx
, 1);
3432 isl_options_set_schedule_max_coefficient(ctx
, 20);
3433 schedule
= isl_schedule_constraints_compute_schedule(sc
);
3434 isl_options_set_schedule_max_coefficient(ctx
, -1);
3435 isl_options_set_schedule_outer_coincidence(ctx
, 0);
3436 isl_schedule_free(schedule
);
3444 int test_schedule(isl_ctx
*ctx
)
3446 const char *D
, *W
, *R
, *V
, *P
, *S
;
3448 /* Handle resulting schedule with zero bands. */
3449 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
3453 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
3454 W
= "{ S1[t,i] -> a[t,i] }";
3455 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
3456 "S1[t,i] -> a[t-1,i+1] }";
3457 S
= "{ S1[t,i] -> [t,i] }";
3458 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3461 /* Fig. 5 of CC2008 */
3462 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
3464 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
3465 "j >= 2 and j <= -1 + N }";
3466 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
3467 "j >= 2 and j <= -1 + N; "
3468 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
3469 "j >= 2 and j <= -1 + N }";
3470 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
3471 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3474 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
3475 W
= "{ S1[i] -> a[i] }";
3476 R
= "{ S2[i] -> a[i+1] }";
3477 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3478 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3481 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
3482 W
= "{ S1[i] -> a[i] }";
3483 R
= "{ S2[i] -> a[9-i] }";
3484 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3485 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3488 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
3489 W
= "{ S1[i] -> a[i] }";
3490 R
= "[N] -> { S2[i] -> a[N-1-i] }";
3491 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3492 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3495 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
3496 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
3497 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
3498 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
3499 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3502 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
3503 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
3504 R
= "{ S2[i,j] -> a[i-1,j] }";
3505 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
3506 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3509 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
3510 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
3511 R
= "{ S2[i,j] -> a[i,j-1] }";
3512 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
3513 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3516 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
3517 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
3518 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
3519 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
3520 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
3521 "S_0[] -> [0, 0, 0] }";
3522 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
3524 ctx
->opt
->schedule_parametric
= 0;
3525 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3527 ctx
->opt
->schedule_parametric
= 1;
3529 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
3530 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
3531 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
3532 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
3533 "S4[i] -> a[i,N] }";
3534 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
3535 "S4[i] -> [4,i,0] }";
3536 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3539 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
3540 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
3542 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
3544 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
3546 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
3547 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3550 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
3551 " S_2[t] : t >= 0 and t <= -1 + N; "
3552 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
3554 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
3555 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
3556 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
3557 "i >= 0 and i <= -1 + N }";
3558 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
3559 "i >= 0 and i <= -1 + N; "
3560 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
3561 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
3562 " S_0[t] -> [0, t, 0] }";
3564 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3566 ctx
->opt
->schedule_parametric
= 0;
3567 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3569 ctx
->opt
->schedule_parametric
= 1;
3571 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
3572 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
3573 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
3576 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
3577 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
3578 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
3579 "j >= 0 and j <= -1 + N; "
3580 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3581 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
3582 "j >= 0 and j <= -1 + N; "
3583 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3584 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
3585 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3588 D
= "{ S_0[i] : i >= 0 }";
3589 W
= "{ S_0[i] -> a[i] : i >= 0 }";
3590 R
= "{ S_0[i] -> a[0] : i >= 0 }";
3591 S
= "{ S_0[i] -> [0, i, 0] }";
3592 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3595 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
3596 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
3597 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
3598 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
3599 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3602 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
3603 "k <= -1 + n and k >= 0 }";
3604 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
3605 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
3606 "k <= -1 + n and k >= 0; "
3607 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
3608 "k <= -1 + n and k >= 0; "
3609 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
3610 "k <= -1 + n and k >= 0 }";
3611 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
3612 ctx
->opt
->schedule_outer_coincidence
= 1;
3613 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3615 ctx
->opt
->schedule_outer_coincidence
= 0;
3617 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
3618 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
3619 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
3620 "Stmt_for_body24[i0, i1, 1, 0]:"
3621 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
3622 "Stmt_for_body7[i0, i1, i2]:"
3623 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
3626 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
3627 "Stmt_for_body24[1, i1, i2, i3]:"
3628 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
3630 "Stmt_for_body24[0, i1, i2, i3] -> "
3631 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
3632 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
3634 "Stmt_for_body24[0, i1, i2, i3] ->"
3635 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
3636 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
3637 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
3638 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
3639 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
3640 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
3641 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
3642 "i1 <= 6 and i1 >= 0;"
3643 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
3644 "Stmt_for_body7[i0, i1, i2] -> "
3645 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
3646 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
3647 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
3648 "Stmt_for_body7[i0, i1, i2] -> "
3649 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
3650 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
3651 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
3653 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
3654 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
3655 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
3657 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3660 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
3661 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
3662 "j >= 1 and j <= 7;"
3663 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
3664 "j >= 1 and j <= 8 }";
3666 S
= "{ S_0[i, j] -> [i + j, j] }";
3667 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3668 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3670 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3672 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
3673 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
3674 "j >= 0 and j <= -1 + i }";
3675 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
3676 "i <= -1 + N and j >= 0;"
3677 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
3680 S
= "{ S_0[i, j] -> [i, j] }";
3681 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3682 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3684 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3686 /* Test both algorithms on a case with only proximity dependences. */
3687 D
= "{ S[i,j] : 0 <= i <= 10 }";
3689 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
3690 S
= "{ S[i, j] -> [j, i] }";
3691 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3692 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3694 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3695 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3698 D
= "{ A[a]; B[] }";
3700 P
= "{ A[a] -> B[] }";
3701 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3704 if (test_padded_schedule(ctx
) < 0)
3707 /* Check that check for progress is not confused by rational
3710 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
3711 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
3713 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
3714 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
3716 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3717 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3719 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3721 /* Check that we allow schedule rows that are only non-trivial
3722 * on some full-dimensional domains.
3724 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
3725 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
3726 "S1[j] -> S2[1] : 0 <= j <= 1 }";
3728 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3729 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3731 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3733 if (test_conditional_schedule_constraints(ctx
) < 0)
3736 if (test_strongly_satisfying_schedule(ctx
) < 0)
3739 if (test_conflicting_context_schedule(ctx
) < 0)
3742 if (test_bounded_coefficients_schedule(ctx
) < 0)
3748 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
3750 isl_union_map
*umap
;
3753 umap
= isl_union_map_read_from_str(ctx
, str
);
3754 test
= isl_union_map_plain_is_injective(umap
);
3755 isl_union_map_free(umap
);
3758 if (test
== injective
)
3761 isl_die(ctx
, isl_error_unknown
,
3762 "map not detected as injective", return -1);
3764 isl_die(ctx
, isl_error_unknown
,
3765 "map detected as injective", return -1);
3768 int test_injective(isl_ctx
*ctx
)
3772 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
3774 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
3776 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
3778 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
3780 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
3782 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
3784 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
3786 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
3789 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
3790 if (test_plain_injective(ctx
, str
, 1))
3792 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
3793 if (test_plain_injective(ctx
, str
, 0))
3799 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
3807 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
3808 equal
= isl_aff_plain_is_equal(aff
, aff2
);
3814 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
3818 equal
= aff_plain_is_equal(aff
, str
);
3822 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
3823 "result not as expected", return -1);
3828 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3829 __isl_take isl_aff
*aff2
);
3831 ['+'] = { &isl_aff_add
},
3832 ['-'] = { &isl_aff_sub
},
3833 ['*'] = { &isl_aff_mul
},
3834 ['/'] = { &isl_aff_div
},
3842 } aff_bin_tests
[] = {
3843 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
3844 "{ [i] -> [2i] }" },
3845 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
3847 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
3848 "{ [i] -> [2i] }" },
3849 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
3850 "{ [i] -> [2i] }" },
3851 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
3852 "{ [i] -> [i/2] }" },
3853 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
3855 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
3856 "{ [i] -> [NaN] }" },
3857 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
3858 "{ [i] -> [NaN] }" },
3859 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
3860 "{ [i] -> [NaN] }" },
3861 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
3862 "{ [i] -> [NaN] }" },
3863 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
3864 "{ [i] -> [NaN] }" },
3865 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
3866 "{ [i] -> [NaN] }" },
3867 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
3868 "{ [i] -> [NaN] }" },
3869 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
3870 "{ [i] -> [NaN] }" },
3871 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
3872 "{ [i] -> [NaN] }" },
3873 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
3874 "{ [i] -> [NaN] }" },
3875 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
3876 "{ [i] -> [NaN] }" },
3877 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
3878 "{ [i] -> [NaN] }" },
3881 /* Perform some basic tests of binary operations on isl_aff objects.
3883 static int test_bin_aff(isl_ctx
*ctx
)
3886 isl_aff
*aff1
, *aff2
, *res
;
3887 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3888 __isl_take isl_aff
*aff2
);
3891 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
3892 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
3893 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
3894 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
3895 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
3896 aff1
= fn(aff1
, aff2
);
3897 if (isl_aff_is_nan(res
))
3898 ok
= isl_aff_is_nan(aff1
);
3900 ok
= isl_aff_plain_is_equal(aff1
, res
);
3906 isl_die(ctx
, isl_error_unknown
,
3907 "unexpected result", return -1);
3914 __isl_give isl_union_pw_multi_aff
*(*fn
)(
3915 __isl_take isl_union_pw_multi_aff
*upma1
,
3916 __isl_take isl_union_pw_multi_aff
*upma2
);
3920 } upma_bin_tests
[] = {
3921 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
3922 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
3923 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
3924 "{ B[x] -> [2] : x >= 0 }",
3925 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
3928 /* Perform some basic tests of binary operations on
3929 * isl_union_pw_multi_aff objects.
3931 static int test_bin_upma(isl_ctx
*ctx
)
3934 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
3937 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
3938 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3939 upma_bin_tests
[i
].arg1
);
3940 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3941 upma_bin_tests
[i
].arg2
);
3942 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
3943 upma_bin_tests
[i
].res
);
3944 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
3945 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
3946 isl_union_pw_multi_aff_free(upma1
);
3947 isl_union_pw_multi_aff_free(res
);
3951 isl_die(ctx
, isl_error_unknown
,
3952 "unexpected result", return -1);
3958 int test_aff(isl_ctx
*ctx
)
3963 isl_local_space
*ls
;
3967 if (test_bin_aff(ctx
) < 0)
3969 if (test_bin_upma(ctx
) < 0)
3972 space
= isl_space_set_alloc(ctx
, 0, 1);
3973 ls
= isl_local_space_from_space(space
);
3974 aff
= isl_aff_zero_on_domain(ls
);
3976 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3977 aff
= isl_aff_scale_down_ui(aff
, 3);
3978 aff
= isl_aff_floor(aff
);
3979 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3980 aff
= isl_aff_scale_down_ui(aff
, 2);
3981 aff
= isl_aff_floor(aff
);
3982 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3985 set
= isl_set_read_from_str(ctx
, str
);
3986 aff
= isl_aff_gist(aff
, set
);
3988 aff
= isl_aff_add_constant_si(aff
, -16);
3989 zero
= isl_aff_plain_is_zero(aff
);
3995 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3997 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
3998 aff
= isl_aff_scale_down_ui(aff
, 64);
3999 aff
= isl_aff_floor(aff
);
4000 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
4008 int test_dim_max(isl_ctx
*ctx
)
4012 isl_set
*set1
, *set2
;
4017 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
4018 set
= isl_set_read_from_str(ctx
, str
);
4019 pwaff
= isl_set_dim_max(set
, 0);
4020 set1
= isl_set_from_pw_aff(pwaff
);
4021 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
4022 set2
= isl_set_read_from_str(ctx
, str
);
4023 equal
= isl_set_is_equal(set1
, set2
);
4029 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4031 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
4032 set
= isl_set_read_from_str(ctx
, str
);
4033 pwaff
= isl_set_dim_max(set
, 0);
4034 set1
= isl_set_from_pw_aff(pwaff
);
4035 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
4036 set2
= isl_set_read_from_str(ctx
, str
);
4037 equal
= isl_set_is_equal(set1
, set2
);
4043 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4045 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
4046 set
= isl_set_read_from_str(ctx
, str
);
4047 pwaff
= isl_set_dim_max(set
, 0);
4048 set1
= isl_set_from_pw_aff(pwaff
);
4049 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
4050 set2
= isl_set_read_from_str(ctx
, str
);
4051 equal
= isl_set_is_equal(set1
, set2
);
4057 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4059 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
4060 "0 <= i < N and 0 <= j < M }";
4061 map
= isl_map_read_from_str(ctx
, str
);
4062 set
= isl_map_range(map
);
4064 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
4065 set1
= isl_set_from_pw_aff(pwaff
);
4066 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
4067 set2
= isl_set_read_from_str(ctx
, str
);
4068 equal
= isl_set_is_equal(set1
, set2
);
4072 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
4073 set1
= isl_set_from_pw_aff(pwaff
);
4074 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
4075 set2
= isl_set_read_from_str(ctx
, str
);
4076 if (equal
>= 0 && equal
)
4077 equal
= isl_set_is_equal(set1
, set2
);
4086 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4088 /* Check that solutions are properly merged. */
4089 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
4090 "c <= -1 + n - 4a - 2b and c >= -2b and "
4091 "4a >= -4 + n and c >= 0 }";
4092 set
= isl_set_read_from_str(ctx
, str
);
4093 pwaff
= isl_set_dim_min(set
, 2);
4094 set1
= isl_set_from_pw_aff(pwaff
);
4095 str
= "[n] -> { [(0)] : n >= 1 }";
4096 set2
= isl_set_read_from_str(ctx
, str
);
4097 equal
= isl_set_is_equal(set1
, set2
);
4104 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4106 /* Check that empty solution lie in the right space. */
4107 str
= "[n] -> { [t,a] : 1 = 0 }";
4108 set
= isl_set_read_from_str(ctx
, str
);
4109 pwaff
= isl_set_dim_max(set
, 0);
4110 set1
= isl_set_from_pw_aff(pwaff
);
4111 str
= "[n] -> { [t] : 1 = 0 }";
4112 set2
= isl_set_read_from_str(ctx
, str
);
4113 equal
= isl_set_is_equal(set1
, set2
);
4120 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4125 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
4127 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
4131 isl_pw_multi_aff
*pma2
;
4137 ctx
= isl_pw_multi_aff_get_ctx(pma
);
4138 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4139 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
4140 isl_pw_multi_aff_free(pma2
);
4145 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
4146 * represented by "str".
4148 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
4153 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
4157 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
4158 "result not as expected", return -1);
4162 /* Basic test for isl_pw_multi_aff_product.
4164 * Check that multiple pieces are properly handled.
4166 static int test_product_pma(isl_ctx
*ctx
)
4170 isl_pw_multi_aff
*pma1
, *pma2
;
4172 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
4173 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4174 str
= "{ C[] -> D[] }";
4175 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4176 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
4177 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
4178 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
4179 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
4180 isl_pw_multi_aff_free(pma1
);
4187 int test_product(isl_ctx
*ctx
)
4191 isl_union_set
*uset1
, *uset2
;
4195 set
= isl_set_read_from_str(ctx
, str
);
4196 set
= isl_set_product(set
, isl_set_copy(set
));
4197 ok
= isl_set_is_wrapping(set
);
4202 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4205 uset1
= isl_union_set_read_from_str(ctx
, str
);
4206 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
4207 str
= "{ [[] -> []] }";
4208 uset2
= isl_union_set_read_from_str(ctx
, str
);
4209 ok
= isl_union_set_is_equal(uset1
, uset2
);
4210 isl_union_set_free(uset1
);
4211 isl_union_set_free(uset2
);
4215 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4217 if (test_product_pma(ctx
) < 0)
4223 /* Check that two sets are not considered disjoint just because
4224 * they have a different set of (named) parameters.
4226 static int test_disjoint(isl_ctx
*ctx
)
4229 isl_set
*set
, *set2
;
4232 str
= "[n] -> { [[]->[]] }";
4233 set
= isl_set_read_from_str(ctx
, str
);
4234 str
= "{ [[]->[]] }";
4235 set2
= isl_set_read_from_str(ctx
, str
);
4236 disjoint
= isl_set_is_disjoint(set
, set2
);
4242 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4247 int test_equal(isl_ctx
*ctx
)
4250 isl_set
*set
, *set2
;
4254 set
= isl_set_read_from_str(ctx
, str
);
4256 set2
= isl_set_read_from_str(ctx
, str
);
4257 equal
= isl_set_is_equal(set
, set2
);
4263 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4268 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
4269 enum isl_dim_type type
, unsigned pos
, int fixed
)
4273 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
4280 isl_die(ctx
, isl_error_unknown
,
4281 "map not detected as fixed", return -1);
4283 isl_die(ctx
, isl_error_unknown
,
4284 "map detected as fixed", return -1);
4287 int test_fixed(isl_ctx
*ctx
)
4292 str
= "{ [i] -> [i] }";
4293 map
= isl_map_read_from_str(ctx
, str
);
4294 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
4296 str
= "{ [i] -> [1] }";
4297 map
= isl_map_read_from_str(ctx
, str
);
4298 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
4300 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
4301 map
= isl_map_read_from_str(ctx
, str
);
4302 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
4304 map
= isl_map_read_from_str(ctx
, str
);
4305 map
= isl_map_neg(map
);
4306 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
4312 struct isl_vertices_test_data
{
4315 const char *vertex
[2];
4316 } vertices_tests
[] = {
4317 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
4318 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
4319 { "{ A[t, i] : t = 14 and i = 1 }",
4320 1, { "{ A[14, 1] }" } },
4323 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
4325 static isl_stat
find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
4327 struct isl_vertices_test_data
*data
= user
;
4330 isl_basic_set
*bset
;
4331 isl_pw_multi_aff
*pma
;
4335 ctx
= isl_vertex_get_ctx(vertex
);
4336 bset
= isl_vertex_get_domain(vertex
);
4337 ma
= isl_vertex_get_expr(vertex
);
4338 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
4340 for (i
= 0; i
< data
->n
; ++i
) {
4341 isl_pw_multi_aff
*pma_i
;
4343 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
4344 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
4345 isl_pw_multi_aff_free(pma_i
);
4347 if (equal
< 0 || equal
)
4351 isl_pw_multi_aff_free(pma
);
4352 isl_vertex_free(vertex
);
4355 return isl_stat_error
;
4357 return equal
? isl_stat_ok
: isl_stat_error
;
4360 int test_vertices(isl_ctx
*ctx
)
4364 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
4365 isl_basic_set
*bset
;
4366 isl_vertices
*vertices
;
4370 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
4371 vertices
= isl_basic_set_compute_vertices(bset
);
4372 n
= isl_vertices_get_n_vertices(vertices
);
4373 if (vertices_tests
[i
].n
!= n
)
4375 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
4376 &vertices_tests
[i
]) < 0)
4378 isl_vertices_free(vertices
);
4379 isl_basic_set_free(bset
);
4384 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
4391 int test_union_pw(isl_ctx
*ctx
)
4395 isl_union_set
*uset
;
4396 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
4398 str
= "{ [x] -> x^2 }";
4399 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
4400 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
4401 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
4402 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
4403 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
4404 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
4405 isl_union_pw_qpolynomial_free(upwqp1
);
4406 isl_union_pw_qpolynomial_free(upwqp2
);
4410 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4415 /* Test that isl_union_pw_qpolynomial_eval picks up the function
4416 * defined over the correct domain space.
4418 static int test_eval(isl_ctx
*ctx
)
4423 isl_union_pw_qpolynomial
*upwqp
;
4427 str
= "{ A[x] -> x^2; B[x] -> -x^2 }";
4428 upwqp
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
4430 set
= isl_set_read_from_str(ctx
, str
);
4431 pnt
= isl_set_sample_point(set
);
4432 v
= isl_union_pw_qpolynomial_eval(upwqp
, pnt
);
4433 cmp
= isl_val_cmp_si(v
, 36);
4439 isl_die(ctx
, isl_error_unknown
, "unexpected value", return -1);
4444 int test_output(isl_ctx
*ctx
)
4452 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
4453 pa
= isl_pw_aff_read_from_str(ctx
, str
);
4455 p
= isl_printer_to_str(ctx
);
4456 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
4457 p
= isl_printer_print_pw_aff(p
, pa
);
4458 s
= isl_printer_get_str(p
);
4459 isl_printer_free(p
);
4460 isl_pw_aff_free(pa
);
4464 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
4469 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
4474 int test_sample(isl_ctx
*ctx
)
4477 isl_basic_set
*bset1
, *bset2
;
4480 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
4481 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
4482 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
4483 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
4484 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
4485 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
4486 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
4487 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
4488 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
4489 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
4490 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
4491 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
4492 "d - 1073741821e and "
4493 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
4494 "3j >= 1 - a + b + 2e and "
4495 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
4496 "3i <= 4 - a + 4b - e and "
4497 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
4498 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
4499 "c <= -1 + a and 3i >= -2 - a + 3e and "
4500 "1073741822e <= 1073741823 - a + 1073741822b + c and "
4501 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
4502 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
4503 "1073741823e >= 1 + 1073741823b - d and "
4504 "3i >= 1073741823b + c - 1073741823e - f and "
4505 "3i >= 1 + 2b + e + 3g }";
4506 bset1
= isl_basic_set_read_from_str(ctx
, str
);
4507 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
4508 empty
= isl_basic_set_is_empty(bset2
);
4509 subset
= isl_basic_set_is_subset(bset2
, bset1
);
4510 isl_basic_set_free(bset1
);
4511 isl_basic_set_free(bset2
);
4512 if (empty
< 0 || subset
< 0)
4515 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
4517 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
4522 int test_fixed_power(isl_ctx
*ctx
)
4530 str
= "{ [i] -> [i + 1] }";
4531 map
= isl_map_read_from_str(ctx
, str
);
4532 isl_int_set_si(exp
, 23);
4533 map
= isl_map_fixed_power(map
, exp
);
4534 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
4543 int test_slice(isl_ctx
*ctx
)
4549 str
= "{ [i] -> [j] }";
4550 map
= isl_map_read_from_str(ctx
, str
);
4551 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
4552 equal
= map_check_equal(map
, "{ [i] -> [i] }");
4557 str
= "{ [i] -> [j] }";
4558 map
= isl_map_read_from_str(ctx
, str
);
4559 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
4560 equal
= map_check_equal(map
, "{ [i] -> [j] }");
4565 str
= "{ [i] -> [j] }";
4566 map
= isl_map_read_from_str(ctx
, str
);
4567 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
4568 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
4573 str
= "{ [i] -> [j] }";
4574 map
= isl_map_read_from_str(ctx
, str
);
4575 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
4576 equal
= map_check_equal(map
, "{ [0] -> [j] }");
4581 str
= "{ [i] -> [j] }";
4582 map
= isl_map_read_from_str(ctx
, str
);
4583 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
4584 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
4589 str
= "{ [i] -> [j] }";
4590 map
= isl_map_read_from_str(ctx
, str
);
4591 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
4592 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
4600 int test_eliminate(isl_ctx
*ctx
)
4606 str
= "{ [i] -> [j] : i = 2j }";
4607 map
= isl_map_read_from_str(ctx
, str
);
4608 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
4609 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
4617 /* Check that isl_set_dim_residue_class detects that the values of j
4618 * in the set below are all odd and that it does not detect any spurious
4621 static int test_residue_class(isl_ctx
*ctx
)
4628 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
4629 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
4630 set
= isl_set_read_from_str(ctx
, str
);
4633 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
4635 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
4636 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
4645 int test_align_parameters(isl_ctx
*ctx
)
4649 isl_multi_aff
*ma1
, *ma2
;
4652 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
4653 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
4655 space
= isl_space_params_alloc(ctx
, 1);
4656 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
4657 ma1
= isl_multi_aff_align_params(ma1
, space
);
4659 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
4660 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
4662 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4664 isl_multi_aff_free(ma1
);
4665 isl_multi_aff_free(ma2
);
4670 isl_die(ctx
, isl_error_unknown
,
4671 "result not as expected", return -1);
4676 static int test_list(isl_ctx
*ctx
)
4678 isl_id
*a
, *b
, *c
, *d
, *id
;
4682 a
= isl_id_alloc(ctx
, "a", NULL
);
4683 b
= isl_id_alloc(ctx
, "b", NULL
);
4684 c
= isl_id_alloc(ctx
, "c", NULL
);
4685 d
= isl_id_alloc(ctx
, "d", NULL
);
4687 list
= isl_id_list_alloc(ctx
, 4);
4688 list
= isl_id_list_add(list
, a
);
4689 list
= isl_id_list_add(list
, b
);
4690 list
= isl_id_list_add(list
, c
);
4691 list
= isl_id_list_add(list
, d
);
4692 list
= isl_id_list_drop(list
, 1, 1);
4694 if (isl_id_list_n_id(list
) != 3) {
4695 isl_id_list_free(list
);
4696 isl_die(ctx
, isl_error_unknown
,
4697 "unexpected number of elements in list", return -1);
4700 id
= isl_id_list_get_id(list
, 0);
4703 id
= isl_id_list_get_id(list
, 1);
4706 id
= isl_id_list_get_id(list
, 2);
4710 isl_id_list_free(list
);
4713 isl_die(ctx
, isl_error_unknown
,
4714 "unexpected elements in list", return -1);
4719 const char *set_conversion_tests
[] = {
4720 "[N] -> { [i] : N - 1 <= 2 i <= N }",
4721 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
4722 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4723 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4724 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
4727 /* Check that converting from isl_set to isl_pw_multi_aff and back
4728 * to isl_set produces the original isl_set.
4730 static int test_set_conversion(isl_ctx
*ctx
)
4734 isl_set
*set1
, *set2
;
4735 isl_pw_multi_aff
*pma
;
4738 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
4739 str
= set_conversion_tests
[i
];
4740 set1
= isl_set_read_from_str(ctx
, str
);
4741 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
4742 set2
= isl_set_from_pw_multi_aff(pma
);
4743 equal
= isl_set_is_equal(set1
, set2
);
4750 isl_die(ctx
, isl_error_unknown
, "bad conversion",
4757 /* Check that converting from isl_map to isl_pw_multi_aff and back
4758 * to isl_map produces the original isl_map.
4760 static int test_map_conversion(isl_ctx
*ctx
)
4763 isl_map
*map1
, *map2
;
4764 isl_pw_multi_aff
*pma
;
4767 str
= "{ [a, b, c, d] -> s0[a, b, e, f] : "
4768 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
4769 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
4770 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
4772 map1
= isl_map_read_from_str(ctx
, str
);
4773 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
4774 map2
= isl_map_from_pw_multi_aff(pma
);
4775 equal
= isl_map_is_equal(map1
, map2
);
4782 isl_die(ctx
, isl_error_unknown
, "bad conversion", return -1);
4787 static int test_conversion(isl_ctx
*ctx
)
4789 if (test_set_conversion(ctx
) < 0)
4791 if (test_map_conversion(ctx
) < 0)
4796 /* Check that isl_basic_map_curry does not modify input.
4798 static int test_curry(isl_ctx
*ctx
)
4801 isl_basic_map
*bmap1
, *bmap2
;
4804 str
= "{ [A[] -> B[]] -> C[] }";
4805 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
4806 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
4807 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
4808 isl_basic_map_free(bmap1
);
4809 isl_basic_map_free(bmap2
);
4814 isl_die(ctx
, isl_error_unknown
,
4815 "curried map should not be equal to original",
4825 } preimage_tests
[] = {
4826 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
4827 "{ A[j,i] -> B[i,j] }",
4828 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
4829 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4830 "{ A[a,b] -> B[a/2,b/6] }",
4831 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
4832 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4833 "{ A[a,b] -> B[a/2,b/6] }",
4834 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
4835 "exists i,j : a = 2 i and b = 6 j }" },
4836 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
4837 "[n] -> { : 0 <= n <= 100 }" },
4838 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4839 "{ A[a] -> B[2a] }",
4840 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
4841 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4842 "{ A[a] -> B[([a/2])] }",
4843 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
4844 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
4845 "{ A[a] -> B[a,a,a/3] }",
4846 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
4847 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
4848 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
4851 static int test_preimage_basic_set(isl_ctx
*ctx
)
4854 isl_basic_set
*bset1
, *bset2
;
4858 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
4859 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
4860 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
4861 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
4862 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
4863 equal
= isl_basic_set_is_equal(bset1
, bset2
);
4864 isl_basic_set_free(bset1
);
4865 isl_basic_set_free(bset2
);
4869 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4880 } preimage_domain_tests
[] = {
4881 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
4882 "{ A[j,i] -> B[i,j] }",
4883 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
4884 { "{ B[i] -> C[i]; D[i] -> E[i] }",
4885 "{ A[i] -> B[i + 1] }",
4886 "{ A[i] -> C[i + 1] }" },
4887 { "{ B[i] -> C[i]; B[i] -> E[i] }",
4888 "{ A[i] -> B[i + 1] }",
4889 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
4890 { "{ B[i] -> C[([i/2])] }",
4891 "{ A[i] -> B[2i] }",
4892 "{ A[i] -> C[i] }" },
4893 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
4894 "{ A[i] -> B[([i/5]), ([i/7])] }",
4895 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
4896 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
4897 "[N] -> { A[] -> B[([N/5])] }",
4898 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
4899 { "{ B[i] -> C[i] : exists a : i = 5 a }",
4900 "{ A[i] -> B[2i] }",
4901 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
4902 { "{ B[i] -> C[i] : exists a : i = 2 a; "
4903 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
4904 "{ A[i] -> B[2i] }",
4905 "{ A[i] -> C[2i] }" },
4908 static int test_preimage_union_map(isl_ctx
*ctx
)
4911 isl_union_map
*umap1
, *umap2
;
4915 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
4916 umap1
= isl_union_map_read_from_str(ctx
,
4917 preimage_domain_tests
[i
].map
);
4918 ma
= isl_multi_aff_read_from_str(ctx
,
4919 preimage_domain_tests
[i
].ma
);
4920 umap2
= isl_union_map_read_from_str(ctx
,
4921 preimage_domain_tests
[i
].res
);
4922 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
4923 equal
= isl_union_map_is_equal(umap1
, umap2
);
4924 isl_union_map_free(umap1
);
4925 isl_union_map_free(umap2
);
4929 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4936 static int test_preimage(isl_ctx
*ctx
)
4938 if (test_preimage_basic_set(ctx
) < 0)
4940 if (test_preimage_union_map(ctx
) < 0)
4950 } pullback_tests
[] = {
4951 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
4952 "{ A[a,b] -> C[b + 2a] }" },
4953 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
4954 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
4955 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
4956 "{ A[a] -> C[(a)/6] }" },
4957 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
4958 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
4959 "{ A[a] -> C[(2a)/3] }" },
4960 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
4961 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
4962 "{ A[i,j] -> C[i + j, i + j] }"},
4963 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
4964 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
4965 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
4966 { "{ [i, j] -> [floor((i)/4) + floor((2*i+j)/5)] }",
4967 "{ [i, j] -> [floor((i)/3), j] }",
4968 "{ [i, j] -> [(floor((i)/12) + floor((j + 2*floor((i)/3))/5))] }" },
4971 static int test_pullback(isl_ctx
*ctx
)
4974 isl_multi_aff
*ma1
, *ma2
;
4978 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
4979 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
4980 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
4981 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
4982 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
4983 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4984 isl_multi_aff_free(ma1
);
4985 isl_multi_aff_free(ma2
);
4989 isl_die(ctx
, isl_error_unknown
, "bad pullback",
4996 /* Check that negation is printed correctly and that equal expressions
4997 * are correctly identified.
4999 static int test_ast(isl_ctx
*ctx
)
5001 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
5005 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
5006 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
5007 expr
= isl_ast_expr_add(expr1
, expr2
);
5008 expr2
= isl_ast_expr_copy(expr
);
5009 expr
= isl_ast_expr_neg(expr
);
5010 expr2
= isl_ast_expr_neg(expr2
);
5011 equal
= isl_ast_expr_is_equal(expr
, expr2
);
5012 str
= isl_ast_expr_to_str(expr
);
5013 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
5015 isl_ast_expr_free(expr
);
5016 isl_ast_expr_free(expr2
);
5018 if (ok
< 0 || equal
< 0)
5021 isl_die(ctx
, isl_error_unknown
,
5022 "equal expressions not considered equal", return -1);
5024 isl_die(ctx
, isl_error_unknown
,
5025 "isl_ast_expr printed incorrectly", return -1);
5027 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
5028 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
5029 expr
= isl_ast_expr_add(expr1
, expr2
);
5030 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
5031 expr
= isl_ast_expr_sub(expr3
, expr
);
5032 str
= isl_ast_expr_to_str(expr
);
5033 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
5035 isl_ast_expr_free(expr
);
5040 isl_die(ctx
, isl_error_unknown
,
5041 "isl_ast_expr printed incorrectly", return -1);
5046 /* Check that isl_ast_build_expr_from_set returns a valid expression
5047 * for an empty set. Note that isl_ast_build_expr_from_set getting
5048 * called on an empty set probably indicates a bug in the caller.
5050 static int test_ast_build(isl_ctx
*ctx
)
5053 isl_ast_build
*build
;
5056 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5057 build
= isl_ast_build_from_context(set
);
5059 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
5060 expr
= isl_ast_build_expr_from_set(build
, set
);
5062 isl_ast_expr_free(expr
);
5063 isl_ast_build_free(build
);
5071 /* Internal data structure for before_for and after_for callbacks.
5073 * depth is the current depth
5074 * before is the number of times before_for has been called
5075 * after is the number of times after_for has been called
5077 struct isl_test_codegen_data
{
5083 /* This function is called before each for loop in the AST generated
5084 * from test_ast_gen1.
5086 * Increment the number of calls and the depth.
5087 * Check that the space returned by isl_ast_build_get_schedule_space
5088 * matches the target space of the schedule returned by
5089 * isl_ast_build_get_schedule.
5090 * Return an isl_id that is checked by the corresponding call
5093 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
5096 struct isl_test_codegen_data
*data
= user
;
5099 isl_union_map
*schedule
;
5100 isl_union_set
*uset
;
5105 ctx
= isl_ast_build_get_ctx(build
);
5107 if (data
->before
>= 3)
5108 isl_die(ctx
, isl_error_unknown
,
5109 "unexpected number of for nodes", return NULL
);
5110 if (data
->depth
>= 2)
5111 isl_die(ctx
, isl_error_unknown
,
5112 "unexpected depth", return NULL
);
5114 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
5118 schedule
= isl_ast_build_get_schedule(build
);
5119 uset
= isl_union_map_range(schedule
);
5122 if (isl_union_set_n_set(uset
) != 1) {
5123 isl_union_set_free(uset
);
5124 isl_die(ctx
, isl_error_unknown
,
5125 "expecting single range space", return NULL
);
5128 space
= isl_ast_build_get_schedule_space(build
);
5129 set
= isl_union_set_extract_set(uset
, space
);
5130 isl_union_set_free(uset
);
5131 empty
= isl_set_is_empty(set
);
5137 isl_die(ctx
, isl_error_unknown
,
5138 "spaces don't match", return NULL
);
5140 return isl_id_alloc(ctx
, name
, NULL
);
5143 /* This function is called after each for loop in the AST generated
5144 * from test_ast_gen1.
5146 * Increment the number of calls and decrement the depth.
5147 * Check that the annotation attached to the node matches
5148 * the isl_id returned by the corresponding call to before_for.
5150 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
5151 __isl_keep isl_ast_build
*build
, void *user
)
5153 struct isl_test_codegen_data
*data
= user
;
5161 if (data
->after
> data
->before
)
5162 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
5163 "mismatch in number of for nodes",
5164 return isl_ast_node_free(node
));
5166 id
= isl_ast_node_get_annotation(node
);
5168 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
5169 "missing annotation", return isl_ast_node_free(node
));
5171 name
= isl_id_get_name(id
);
5172 valid
= name
&& atoi(name
+ 1) == data
->depth
;
5176 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
5177 "wrong annotation", return isl_ast_node_free(node
));
5182 /* Check that the before_each_for and after_each_for callbacks
5183 * are called for each for loop in the generated code,
5184 * that they are called in the right order and that the isl_id
5185 * returned from the before_each_for callback is attached to
5186 * the isl_ast_node passed to the corresponding after_each_for call.
5188 static int test_ast_gen1(isl_ctx
*ctx
)
5192 isl_union_map
*schedule
;
5193 isl_ast_build
*build
;
5195 struct isl_test_codegen_data data
;
5197 str
= "[N] -> { : N >= 10 }";
5198 set
= isl_set_read_from_str(ctx
, str
);
5199 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
5200 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
5201 schedule
= isl_union_map_read_from_str(ctx
, str
);
5206 build
= isl_ast_build_from_context(set
);
5207 build
= isl_ast_build_set_before_each_for(build
,
5208 &before_for
, &data
);
5209 build
= isl_ast_build_set_after_each_for(build
,
5211 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5212 isl_ast_build_free(build
);
5216 isl_ast_node_free(tree
);
5218 if (data
.before
!= 3 || data
.after
!= 3)
5219 isl_die(ctx
, isl_error_unknown
,
5220 "unexpected number of for nodes", return -1);
5225 /* Check that the AST generator handles domains that are integrally disjoint
5226 * but not rationally disjoint.
5228 static int test_ast_gen2(isl_ctx
*ctx
)
5232 isl_union_map
*schedule
;
5233 isl_union_map
*options
;
5234 isl_ast_build
*build
;
5237 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
5238 schedule
= isl_union_map_read_from_str(ctx
, str
);
5239 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5240 build
= isl_ast_build_from_context(set
);
5242 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
5243 options
= isl_union_map_read_from_str(ctx
, str
);
5244 build
= isl_ast_build_set_options(build
, options
);
5245 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5246 isl_ast_build_free(build
);
5249 isl_ast_node_free(tree
);
5254 /* Increment *user on each call.
5256 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
5257 __isl_keep isl_ast_build
*build
, void *user
)
5266 /* Test that unrolling tries to minimize the number of instances.
5267 * In particular, for the schedule given below, make sure it generates
5268 * 3 nodes (rather than 101).
5270 static int test_ast_gen3(isl_ctx
*ctx
)
5274 isl_union_map
*schedule
;
5275 isl_union_map
*options
;
5276 isl_ast_build
*build
;
5280 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
5281 schedule
= isl_union_map_read_from_str(ctx
, str
);
5282 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5284 str
= "{ [i] -> unroll[0] }";
5285 options
= isl_union_map_read_from_str(ctx
, str
);
5287 build
= isl_ast_build_from_context(set
);
5288 build
= isl_ast_build_set_options(build
, options
);
5289 build
= isl_ast_build_set_at_each_domain(build
,
5290 &count_domains
, &n_domain
);
5291 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5292 isl_ast_build_free(build
);
5296 isl_ast_node_free(tree
);
5299 isl_die(ctx
, isl_error_unknown
,
5300 "unexpected number of for nodes", return -1);
5305 /* Check that if the ast_build_exploit_nested_bounds options is set,
5306 * we do not get an outer if node in the generated AST,
5307 * while we do get such an outer if node if the options is not set.
5309 static int test_ast_gen4(isl_ctx
*ctx
)
5313 isl_union_map
*schedule
;
5314 isl_ast_build
*build
;
5316 enum isl_ast_node_type type
;
5319 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
5320 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
5322 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
5324 schedule
= isl_union_map_read_from_str(ctx
, str
);
5325 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5326 build
= isl_ast_build_from_context(set
);
5327 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5328 isl_ast_build_free(build
);
5332 type
= isl_ast_node_get_type(tree
);
5333 isl_ast_node_free(tree
);
5335 if (type
== isl_ast_node_if
)
5336 isl_die(ctx
, isl_error_unknown
,
5337 "not expecting if node", return -1);
5339 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
5341 schedule
= isl_union_map_read_from_str(ctx
, str
);
5342 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5343 build
= isl_ast_build_from_context(set
);
5344 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5345 isl_ast_build_free(build
);
5349 type
= isl_ast_node_get_type(tree
);
5350 isl_ast_node_free(tree
);
5352 if (type
!= isl_ast_node_if
)
5353 isl_die(ctx
, isl_error_unknown
,
5354 "expecting if node", return -1);
5356 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
5361 /* This function is called for each leaf in the AST generated
5362 * from test_ast_gen5.
5364 * We finalize the AST generation by extending the outer schedule
5365 * with a zero-dimensional schedule. If this results in any for loops,
5366 * then this means that we did not pass along enough information
5367 * about the outer schedule to the inner AST generation.
5369 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
5372 isl_union_map
*schedule
, *extra
;
5375 schedule
= isl_ast_build_get_schedule(build
);
5376 extra
= isl_union_map_copy(schedule
);
5377 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
5378 schedule
= isl_union_map_range_product(schedule
, extra
);
5379 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5380 isl_ast_build_free(build
);
5385 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
5386 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
5387 "code should not contain any for loop",
5388 return isl_ast_node_free(tree
));
5393 /* Check that we do not lose any information when going back and
5394 * forth between internal and external schedule.
5396 * In particular, we create an AST where we unroll the only
5397 * non-constant dimension in the schedule. We therefore do
5398 * not expect any for loops in the AST. However, older versions
5399 * of isl would not pass along enough information about the outer
5400 * schedule when performing an inner code generation from a create_leaf
5401 * callback, resulting in the inner code generation producing a for loop.
5403 static int test_ast_gen5(isl_ctx
*ctx
)
5407 isl_union_map
*schedule
, *options
;
5408 isl_ast_build
*build
;
5411 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
5412 schedule
= isl_union_map_read_from_str(ctx
, str
);
5414 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
5415 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
5416 options
= isl_union_map_read_from_str(ctx
, str
);
5418 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
5419 build
= isl_ast_build_from_context(set
);
5420 build
= isl_ast_build_set_options(build
, options
);
5421 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
5422 tree
= isl_ast_build_node_from_schedule_map(build
, schedule
);
5423 isl_ast_build_free(build
);
5424 isl_ast_node_free(tree
);
5431 static int test_ast_gen(isl_ctx
*ctx
)
5433 if (test_ast_gen1(ctx
) < 0)
5435 if (test_ast_gen2(ctx
) < 0)
5437 if (test_ast_gen3(ctx
) < 0)
5439 if (test_ast_gen4(ctx
) < 0)
5441 if (test_ast_gen5(ctx
) < 0)
5446 /* Check if dropping output dimensions from an isl_pw_multi_aff
5449 static int test_pw_multi_aff(isl_ctx
*ctx
)
5452 isl_pw_multi_aff
*pma1
, *pma2
;
5455 str
= "{ [i,j] -> [i+j, 4i-j] }";
5456 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
5457 str
= "{ [i,j] -> [4i-j] }";
5458 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
5460 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
5462 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
5464 isl_pw_multi_aff_free(pma1
);
5465 isl_pw_multi_aff_free(pma2
);
5469 isl_die(ctx
, isl_error_unknown
,
5470 "expressions not equal", return -1);
5475 /* Check that we can properly parse multi piecewise affine expressions
5476 * where the piecewise affine expressions have different domains.
5478 static int test_multi_pw_aff(isl_ctx
*ctx
)
5481 isl_set
*dom
, *dom2
;
5482 isl_multi_pw_aff
*mpa1
, *mpa2
;
5487 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
5488 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
5489 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
5490 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
5491 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
5492 str
= "{ [i] -> [(i : i > 0), 2i] }";
5493 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
5495 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
5497 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
5498 dom
= isl_pw_aff_domain(pa
);
5499 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
5500 dom2
= isl_pw_aff_domain(pa
);
5501 equal_domain
= isl_set_is_equal(dom
, dom2
);
5505 isl_multi_pw_aff_free(mpa1
);
5506 isl_multi_pw_aff_free(mpa2
);
5511 isl_die(ctx
, isl_error_unknown
,
5512 "expressions not equal", return -1);
5514 if (equal_domain
< 0)
5517 isl_die(ctx
, isl_error_unknown
,
5518 "domains unexpectedly equal", return -1);
5523 /* This is a regression test for a bug where isl_basic_map_simplify
5524 * would end up in an infinite loop. In particular, we construct
5525 * an empty basic set that is not obviously empty.
5526 * isl_basic_set_is_empty marks the basic set as empty.
5527 * After projecting out i3, the variable can be dropped completely,
5528 * but isl_basic_map_simplify refrains from doing so if the basic set
5529 * is empty and would end up in an infinite loop if it didn't test
5530 * explicitly for empty basic maps in the outer loop.
5532 static int test_simplify(isl_ctx
*ctx
)
5535 isl_basic_set
*bset
;
5538 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
5539 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
5540 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
5542 bset
= isl_basic_set_read_from_str(ctx
, str
);
5543 empty
= isl_basic_set_is_empty(bset
);
5544 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
5545 isl_basic_set_free(bset
);
5549 isl_die(ctx
, isl_error_unknown
,
5550 "basic set should be empty", return -1);
5555 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
5556 * with gbr context would fail to disable the use of the shifted tableau
5557 * when transferring equalities for the input to the context, resulting
5558 * in invalid sample values.
5560 static int test_partial_lexmin(isl_ctx
*ctx
)
5563 isl_basic_set
*bset
;
5564 isl_basic_map
*bmap
;
5567 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
5568 bmap
= isl_basic_map_read_from_str(ctx
, str
);
5569 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
5570 bset
= isl_basic_set_read_from_str(ctx
, str
);
5571 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
5580 /* Check that the variable compression performed on the existentially
5581 * quantified variables inside isl_basic_set_compute_divs is not confused
5582 * by the implicit equalities among the parameters.
5584 static int test_compute_divs(isl_ctx
*ctx
)
5587 isl_basic_set
*bset
;
5590 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
5591 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
5592 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
5593 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
5594 bset
= isl_basic_set_read_from_str(ctx
, str
);
5595 set
= isl_basic_set_compute_divs(bset
);
5603 /* Check that the reaching domain elements and the prefix schedule
5604 * at a leaf node are the same before and after grouping.
5606 static int test_schedule_tree_group_1(isl_ctx
*ctx
)
5611 isl_union_set
*uset
;
5612 isl_multi_union_pw_aff
*mupa
;
5613 isl_union_pw_multi_aff
*upma1
, *upma2
;
5614 isl_union_set
*domain1
, *domain2
;
5615 isl_union_map
*umap1
, *umap2
;
5616 isl_schedule_node
*node
;
5618 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }";
5619 uset
= isl_union_set_read_from_str(ctx
, str
);
5620 node
= isl_schedule_node_from_domain(uset
);
5621 node
= isl_schedule_node_child(node
, 0);
5622 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [9 - i] }]";
5623 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5624 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
5625 node
= isl_schedule_node_child(node
, 0);
5626 str
= "[{ S1[i,j] -> [j]; S2[i,j] -> [j] }]";
5627 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5628 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
5629 node
= isl_schedule_node_child(node
, 0);
5630 umap1
= isl_schedule_node_get_prefix_schedule_union_map(node
);
5631 upma1
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
5632 domain1
= isl_schedule_node_get_domain(node
);
5633 id
= isl_id_alloc(ctx
, "group", NULL
);
5634 node
= isl_schedule_node_parent(node
);
5635 node
= isl_schedule_node_group(node
, id
);
5636 node
= isl_schedule_node_child(node
, 0);
5637 umap2
= isl_schedule_node_get_prefix_schedule_union_map(node
);
5638 upma2
= isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(node
);
5639 domain2
= isl_schedule_node_get_domain(node
);
5640 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
5641 if (equal
>= 0 && equal
)
5642 equal
= isl_union_set_is_equal(domain1
, domain2
);
5643 if (equal
>= 0 && equal
)
5644 equal
= isl_union_map_is_equal(umap1
, umap2
);
5645 isl_union_map_free(umap1
);
5646 isl_union_map_free(umap2
);
5647 isl_union_set_free(domain1
);
5648 isl_union_set_free(domain2
);
5649 isl_union_pw_multi_aff_free(upma1
);
5650 isl_union_pw_multi_aff_free(upma2
);
5651 isl_schedule_node_free(node
);
5656 isl_die(ctx
, isl_error_unknown
,
5657 "expressions not equal", return -1);
5662 /* Check that we can have nested groupings and that the union map
5663 * schedule representation is the same before and after the grouping.
5664 * Note that after the grouping, the union map representation contains
5665 * the domain constraints from the ranges of the expansion nodes,
5666 * while they are missing from the union map representation of
5667 * the tree without expansion nodes.
5669 * Also check that the global expansion is as expected.
5671 static int test_schedule_tree_group_2(isl_ctx
*ctx
)
5673 int equal
, equal_expansion
;
5676 isl_union_set
*uset
;
5677 isl_union_map
*umap1
, *umap2
;
5678 isl_union_map
*expansion1
, *expansion2
;
5679 isl_union_set_list
*filters
;
5680 isl_multi_union_pw_aff
*mupa
;
5681 isl_schedule
*schedule
;
5682 isl_schedule_node
*node
;
5684 str
= "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10; "
5685 "S3[i,j] : 0 <= i,j < 10 }";
5686 uset
= isl_union_set_read_from_str(ctx
, str
);
5687 node
= isl_schedule_node_from_domain(uset
);
5688 node
= isl_schedule_node_child(node
, 0);
5689 str
= "[{ S1[i,j] -> [i]; S2[i,j] -> [i]; S3[i,j] -> [i] }]";
5690 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5691 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
5692 node
= isl_schedule_node_child(node
, 0);
5693 str
= "{ S1[i,j] }";
5694 uset
= isl_union_set_read_from_str(ctx
, str
);
5695 filters
= isl_union_set_list_from_union_set(uset
);
5696 str
= "{ S2[i,j]; S3[i,j] }";
5697 uset
= isl_union_set_read_from_str(ctx
, str
);
5698 filters
= isl_union_set_list_add(filters
, uset
);
5699 node
= isl_schedule_node_insert_sequence(node
, filters
);
5700 node
= isl_schedule_node_child(node
, 1);
5701 node
= isl_schedule_node_child(node
, 0);
5702 str
= "{ S2[i,j] }";
5703 uset
= isl_union_set_read_from_str(ctx
, str
);
5704 filters
= isl_union_set_list_from_union_set(uset
);
5705 str
= "{ S3[i,j] }";
5706 uset
= isl_union_set_read_from_str(ctx
, str
);
5707 filters
= isl_union_set_list_add(filters
, uset
);
5708 node
= isl_schedule_node_insert_sequence(node
, filters
);
5710 schedule
= isl_schedule_node_get_schedule(node
);
5711 umap1
= isl_schedule_get_map(schedule
);
5712 uset
= isl_schedule_get_domain(schedule
);
5713 umap1
= isl_union_map_intersect_domain(umap1
, uset
);
5714 isl_schedule_free(schedule
);
5716 node
= isl_schedule_node_parent(node
);
5717 node
= isl_schedule_node_parent(node
);
5718 id
= isl_id_alloc(ctx
, "group1", NULL
);
5719 node
= isl_schedule_node_group(node
, id
);
5720 node
= isl_schedule_node_child(node
, 1);
5721 node
= isl_schedule_node_child(node
, 0);
5722 id
= isl_id_alloc(ctx
, "group2", NULL
);
5723 node
= isl_schedule_node_group(node
, id
);
5725 schedule
= isl_schedule_node_get_schedule(node
);
5726 umap2
= isl_schedule_get_map(schedule
);
5727 isl_schedule_free(schedule
);
5729 node
= isl_schedule_node_root(node
);
5730 node
= isl_schedule_node_child(node
, 0);
5731 expansion1
= isl_schedule_node_get_subtree_expansion(node
);
5732 isl_schedule_node_free(node
);
5734 str
= "{ group1[i] -> S1[i,j] : 0 <= i,j < 10; "
5735 "group1[i] -> S2[i,j] : 0 <= i,j < 10; "
5736 "group1[i] -> S3[i,j] : 0 <= i,j < 10 }";
5738 expansion2
= isl_union_map_read_from_str(ctx
, str
);
5740 equal
= isl_union_map_is_equal(umap1
, umap2
);
5741 equal_expansion
= isl_union_map_is_equal(expansion1
, expansion2
);
5743 isl_union_map_free(umap1
);
5744 isl_union_map_free(umap2
);
5745 isl_union_map_free(expansion1
);
5746 isl_union_map_free(expansion2
);
5748 if (equal
< 0 || equal_expansion
< 0)
5751 isl_die(ctx
, isl_error_unknown
,
5752 "expressions not equal", return -1);
5753 if (!equal_expansion
)
5754 isl_die(ctx
, isl_error_unknown
,
5755 "unexpected expansion", return -1);
5760 /* Some tests for the isl_schedule_node_group function.
5762 static int test_schedule_tree_group(isl_ctx
*ctx
)
5764 if (test_schedule_tree_group_1(ctx
) < 0)
5766 if (test_schedule_tree_group_2(ctx
) < 0)
5775 { "{ rat: [i] : 0 <= i <= 10 }",
5776 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
5777 { "{ rat: [i] : FALSE }",
5778 "{ rat: coefficients[[cst] -> [a]] }" },
5780 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
5787 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
5788 "{ rat: [i] : 0 <= i <= 10 }" },
5789 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
5791 { "{ rat: coefficients[[cst] -> [a]] }",
5792 "{ rat: [i] : FALSE }" },
5795 /* Test the basic functionality of isl_basic_set_coefficients and
5796 * isl_basic_set_solutions.
5798 static int test_dual(isl_ctx
*ctx
)
5802 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
5804 isl_basic_set
*bset1
, *bset2
;
5806 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
5807 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
5808 bset1
= isl_basic_set_coefficients(bset1
);
5809 equal
= isl_basic_set_is_equal(bset1
, bset2
);
5810 isl_basic_set_free(bset1
);
5811 isl_basic_set_free(bset2
);
5815 isl_die(ctx
, isl_error_unknown
,
5816 "incorrect dual", return -1);
5819 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
5821 isl_basic_set
*bset1
, *bset2
;
5823 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
5824 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
5825 bset1
= isl_basic_set_solutions(bset1
);
5826 equal
= isl_basic_set_is_equal(bset1
, bset2
);
5827 isl_basic_set_free(bset1
);
5828 isl_basic_set_free(bset2
);
5832 isl_die(ctx
, isl_error_unknown
,
5833 "incorrect dual", return -1);
5843 const char *schedule
;
5848 { 0, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
5849 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5851 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
5852 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5854 { 1, 0, "[n] -> { S[i,j] : 0 <= i,j < n }",
5855 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5857 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
5858 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5860 { 0, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
5861 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5863 "[{ S[i,j] -> [floor(i/32)] }, { S[i,j] -> [floor(j/32)] }]",
5864 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
5866 { 1, 1, "[n] -> { S[i,j] : 0 <= i,j < n }",
5867 "[{ S[i,j] -> [i] }, { S[i,j] -> [j] }]",
5869 "[{ S[i,j] -> [32*floor(i/32)] }, { S[i,j] -> [32*floor(j/32)] }]",
5870 "[{ S[i,j] -> [i%32] }, { S[i,j] -> [j%32] }]",
5874 /* Basic tiling tests. Create a schedule tree with a domain and a band node,
5875 * tile the band and then check if the tile and point bands have the
5876 * expected partial schedule.
5878 static int test_tile(isl_ctx
*ctx
)
5884 scale
= isl_options_get_tile_scale_tile_loops(ctx
);
5885 shift
= isl_options_get_tile_shift_point_loops(ctx
);
5887 for (i
= 0; i
< ARRAY_SIZE(tile_tests
); ++i
) {
5891 isl_union_set
*domain
;
5892 isl_multi_union_pw_aff
*mupa
, *mupa2
;
5893 isl_schedule_node
*node
;
5894 isl_multi_val
*sizes
;
5896 opt
= tile_tests
[i
].scale_tile
;
5897 isl_options_set_tile_scale_tile_loops(ctx
, opt
);
5898 opt
= tile_tests
[i
].shift_point
;
5899 isl_options_set_tile_shift_point_loops(ctx
, opt
);
5901 str
= tile_tests
[i
].domain
;
5902 domain
= isl_union_set_read_from_str(ctx
, str
);
5903 node
= isl_schedule_node_from_domain(domain
);
5904 node
= isl_schedule_node_child(node
, 0);
5905 str
= tile_tests
[i
].schedule
;
5906 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5907 node
= isl_schedule_node_insert_partial_schedule(node
, mupa
);
5908 str
= tile_tests
[i
].sizes
;
5909 sizes
= isl_multi_val_read_from_str(ctx
, str
);
5910 node
= isl_schedule_node_band_tile(node
, sizes
);
5912 str
= tile_tests
[i
].tile
;
5913 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5914 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
5915 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
, mupa2
);
5916 isl_multi_union_pw_aff_free(mupa
);
5917 isl_multi_union_pw_aff_free(mupa2
);
5919 node
= isl_schedule_node_child(node
, 0);
5921 str
= tile_tests
[i
].point
;
5922 mupa
= isl_multi_union_pw_aff_read_from_str(ctx
, str
);
5923 mupa2
= isl_schedule_node_band_get_partial_schedule(node
);
5924 if (equal
>= 0 && equal
)
5925 equal
= isl_multi_union_pw_aff_plain_is_equal(mupa
,
5927 isl_multi_union_pw_aff_free(mupa
);
5928 isl_multi_union_pw_aff_free(mupa2
);
5930 isl_schedule_node_free(node
);
5935 isl_die(ctx
, isl_error_unknown
,
5936 "unexpected result", return -1);
5939 isl_options_set_tile_scale_tile_loops(ctx
, scale
);
5940 isl_options_set_tile_shift_point_loops(ctx
, shift
);
5947 int (*fn
)(isl_ctx
*ctx
);
5949 { "dual", &test_dual
},
5950 { "dependence analysis", &test_flow
},
5951 { "val", &test_val
},
5952 { "compute divs", &test_compute_divs
},
5953 { "partial lexmin", &test_partial_lexmin
},
5954 { "simplify", &test_simplify
},
5955 { "curry", &test_curry
},
5956 { "piecewise multi affine expressions", &test_pw_multi_aff
},
5957 { "multi piecewise affine expressions", &test_multi_pw_aff
},
5958 { "conversion", &test_conversion
},
5959 { "list", &test_list
},
5960 { "align parameters", &test_align_parameters
},
5961 { "preimage", &test_preimage
},
5962 { "pullback", &test_pullback
},
5963 { "AST", &test_ast
},
5964 { "AST build", &test_ast_build
},
5965 { "AST generation", &test_ast_gen
},
5966 { "eliminate", &test_eliminate
},
5967 { "residue class", &test_residue_class
},
5968 { "div", &test_div
},
5969 { "slice", &test_slice
},
5970 { "fixed power", &test_fixed_power
},
5971 { "sample", &test_sample
},
5972 { "output", &test_output
},
5973 { "vertices", &test_vertices
},
5974 { "fixed", &test_fixed
},
5975 { "equal", &test_equal
},
5976 { "disjoint", &test_disjoint
},
5977 { "product", &test_product
},
5978 { "dim_max", &test_dim_max
},
5979 { "affine", &test_aff
},
5980 { "injective", &test_injective
},
5981 { "schedule", &test_schedule
},
5982 { "schedule tree grouping", &test_schedule_tree_group
},
5983 { "tile", &test_tile
},
5984 { "union_pw", &test_union_pw
},
5985 { "eval", &test_eval
},
5986 { "parse", &test_parse
},
5987 { "single-valued", &test_sv
},
5988 { "affine hull", &test_affine_hull
},
5989 { "simple_hull", &test_simple_hull
},
5990 { "coalesce", &test_coalesce
},
5991 { "factorize", &test_factorize
},
5992 { "subset", &test_subset
},
5993 { "subtract", &test_subtract
},
5994 { "lexmin", &test_lexmin
},
5995 { "min", &test_min
},
5996 { "gist", &test_gist
},
5997 { "piecewise quasi-polynomials", &test_pwqp
},
5998 { "lift", &test_lift
},
5999 { "bound", &test_bound
},
6000 { "union", &test_union
},
6001 { "split periods", &test_split_periods
},
6002 { "lexicographic order", &test_lex
},
6003 { "bijectivity", &test_bijective
},
6004 { "dataflow analysis", &test_dep
},
6005 { "reading", &test_read
},
6006 { "bounded", &test_bounded
},
6007 { "construction", &test_construction
},
6008 { "dimension manipulation", &test_dim
},
6009 { "map application", &test_application
},
6010 { "convex hull", &test_convex_hull
},
6011 { "transitive closure", &test_closure
},
6014 int main(int argc
, char **argv
)
6017 struct isl_ctx
*ctx
;
6018 struct isl_options
*options
;
6020 srcdir
= getenv("srcdir");
6023 options
= isl_options_new_with_defaults();
6025 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
6027 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
6028 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
6029 printf("%s\n", tests
[i
].name
);
6030 if (tests
[i
].fn(ctx
) < 0)