2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
6 * Use of this software is governed by the MIT license
8 * Written by Sven Verdoolaege, K.U.Leuven, Departement
9 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
10 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
11 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
12 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
18 #include <isl_ctx_private.h>
19 #include <isl_map_private.h>
20 #include <isl_aff_private.h>
23 #include <isl_constraint_private.h>
24 #include <isl/polynomial.h>
25 #include <isl/union_map.h>
26 #include <isl_factorization.h>
27 #include <isl/schedule.h>
28 #include <isl_options_private.h>
29 #include <isl/vertices.h>
30 #include <isl/ast_build.h>
33 #include <isl_ast_build_expr.h>
35 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
39 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
42 char *pattern
= "%s/test_inputs/%s.%s";
44 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
46 filename
= isl_alloc_array(ctx
, char, length
);
51 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
56 void test_parse_map(isl_ctx
*ctx
, const char *str
)
60 map
= isl_map_read_from_str(ctx
, str
);
65 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
70 map
= isl_map_read_from_str(ctx
, str
);
71 map2
= isl_map_read_from_str(ctx
, str2
);
72 equal
= isl_map_is_equal(map
, map2
);
79 isl_die(ctx
, isl_error_unknown
, "maps not equal",
85 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
87 isl_pw_qpolynomial
*pwqp
;
89 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
91 isl_pw_qpolynomial_free(pwqp
);
94 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
98 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
100 isl_pw_aff_free(pwaff
);
103 int test_parse(struct isl_ctx
*ctx
)
106 const char *str
, *str2
;
108 str
= "{ [i] -> [-i] }";
109 map
= isl_map_read_from_str(ctx
, str
);
113 str
= "{ A[i] -> L[([i/3])] }";
114 map
= isl_map_read_from_str(ctx
, str
);
118 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
119 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
120 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
122 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
123 str2
= "{ [x, y] : 2y >= 6 - x }";
124 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
127 if (test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
128 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
130 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
131 if (test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }",
135 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
136 map
= isl_map_read_from_str(ctx
, str
);
137 str
= "{ [new, old] -> [o0, o1] : "
138 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
139 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
140 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
141 map2
= isl_map_read_from_str(ctx
, str
);
142 assert(isl_map_is_equal(map
, map2
));
146 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
147 map
= isl_map_read_from_str(ctx
, str
);
148 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
149 map2
= isl_map_read_from_str(ctx
, str
);
150 assert(isl_map_is_equal(map
, map2
));
154 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
155 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
156 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
159 str
= "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
160 str2
= "{ [i,j] -> [min(i,j)] }";
161 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
164 str
= "{ [i,j] : i != j }";
165 str2
= "{ [i,j] : i < j or i > j }";
166 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
169 str
= "{ [i,j] : (i+1)*2 >= j }";
170 str2
= "{ [i, j] : j <= 2 + 2i }";
171 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
174 str
= "{ [i] -> [i > 0 ? 4 : 5] }";
175 str2
= "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
176 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
179 str
= "[N=2,M] -> { [i=[(M+N)/4]] }";
180 str2
= "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
181 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
184 str
= "{ [x] : x >= 0 }";
185 str2
= "{ [x] : x-0 >= 0 }";
186 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
189 str
= "{ [i] : ((i > 10)) }";
190 str2
= "{ [i] : i >= 11 }";
191 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
194 str
= "{ [i] -> [0] }";
195 str2
= "{ [i] -> [0 * i] }";
196 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
199 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
200 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
201 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
202 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
204 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : (not false) }",
205 "{ [a] -> [b] : true }") < 0)
208 if (test_parse_map_equal(ctx
, "{ [i] : i/2 <= 5 }",
209 "{ [i] : i <= 10 }") < 0)
212 if (test_parse_map_equal(ctx
, "{Sym=[n] [i] : i <= n }",
213 "[n] -> { [i] : i <= n }") < 0)
216 if (test_parse_map_equal(ctx
, "{ [*] }", "{ [a] }") < 0)
219 if (test_parse_map_equal(ctx
, "{ [i] : 2*floor(i/2) = i }",
220 "{ [i] : exists a : i = 2 a }") < 0)
223 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : a = 5 implies b = 5 }",
224 "{ [a] -> [b] : a != 5 or b = 5 }") < 0)
227 if (test_parse_map_equal(ctx
, "{ [a] -> [a - 1 : a > 0] }",
228 "{ [a] -> [a - 1] : a > 0 }") < 0)
230 if (test_parse_map_equal(ctx
,
231 "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
232 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }") < 0)
234 if (test_parse_map_equal(ctx
,
235 "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
236 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
238 if (test_parse_map_equal(ctx
,
239 "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
240 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
242 if (test_parse_map_equal(ctx
,
243 "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
244 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
246 if (test_parse_map_equal(ctx
,
247 "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
248 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
254 void test_read(struct isl_ctx
*ctx
)
258 struct isl_basic_set
*bset1
, *bset2
;
259 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
261 filename
= get_filename(ctx
, "set", "omega");
263 input
= fopen(filename
, "r");
266 bset1
= isl_basic_set_read_from_file(ctx
, input
);
267 bset2
= isl_basic_set_read_from_str(ctx
, str
);
269 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
271 isl_basic_set_free(bset1
);
272 isl_basic_set_free(bset2
);
278 void test_bounded(struct isl_ctx
*ctx
)
283 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
284 bounded
= isl_set_is_bounded(set
);
288 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
289 bounded
= isl_set_is_bounded(set
);
293 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
294 bounded
= isl_set_is_bounded(set
);
299 /* Construct the basic set { [i] : 5 <= i <= N } */
300 void test_construction(struct isl_ctx
*ctx
)
305 struct isl_basic_set
*bset
;
306 struct isl_constraint
*c
;
310 dim
= isl_space_set_alloc(ctx
, 1, 1);
311 bset
= isl_basic_set_universe(isl_space_copy(dim
));
312 ls
= isl_local_space_from_space(dim
);
314 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
315 isl_int_set_si(v
, -1);
316 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
317 isl_int_set_si(v
, 1);
318 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
319 bset
= isl_basic_set_add_constraint(bset
, c
);
321 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
322 isl_int_set_si(v
, 1);
323 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
324 isl_int_set_si(v
, -5);
325 isl_constraint_set_constant(c
, v
);
326 bset
= isl_basic_set_add_constraint(bset
, c
);
328 isl_local_space_free(ls
);
329 isl_basic_set_free(bset
);
334 void test_dim(struct isl_ctx
*ctx
)
337 isl_map
*map1
, *map2
;
339 map1
= isl_map_read_from_str(ctx
,
340 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
341 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
342 map2
= isl_map_read_from_str(ctx
,
343 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
344 assert(isl_map_is_equal(map1
, map2
));
347 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
348 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
349 assert(isl_map_is_equal(map1
, map2
));
354 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
355 map1
= isl_map_read_from_str(ctx
, str
);
356 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
357 map2
= isl_map_read_from_str(ctx
, str
);
358 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
359 assert(isl_map_is_equal(map1
, map2
));
366 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
370 { &isl_val_neg
, "0", "0" },
371 { &isl_val_abs
, "0", "0" },
372 { &isl_val_2exp
, "0", "1" },
373 { &isl_val_floor
, "0", "0" },
374 { &isl_val_ceil
, "0", "0" },
375 { &isl_val_neg
, "1", "-1" },
376 { &isl_val_neg
, "-1", "1" },
377 { &isl_val_neg
, "1/2", "-1/2" },
378 { &isl_val_neg
, "-1/2", "1/2" },
379 { &isl_val_neg
, "infty", "-infty" },
380 { &isl_val_neg
, "-infty", "infty" },
381 { &isl_val_neg
, "NaN", "NaN" },
382 { &isl_val_abs
, "1", "1" },
383 { &isl_val_abs
, "-1", "1" },
384 { &isl_val_abs
, "1/2", "1/2" },
385 { &isl_val_abs
, "-1/2", "1/2" },
386 { &isl_val_abs
, "infty", "infty" },
387 { &isl_val_abs
, "-infty", "infty" },
388 { &isl_val_abs
, "NaN", "NaN" },
389 { &isl_val_floor
, "1", "1" },
390 { &isl_val_floor
, "-1", "-1" },
391 { &isl_val_floor
, "1/2", "0" },
392 { &isl_val_floor
, "-1/2", "-1" },
393 { &isl_val_floor
, "infty", "infty" },
394 { &isl_val_floor
, "-infty", "-infty" },
395 { &isl_val_floor
, "NaN", "NaN" },
396 { &isl_val_ceil
, "1", "1" },
397 { &isl_val_ceil
, "-1", "-1" },
398 { &isl_val_ceil
, "1/2", "1" },
399 { &isl_val_ceil
, "-1/2", "0" },
400 { &isl_val_ceil
, "infty", "infty" },
401 { &isl_val_ceil
, "-infty", "-infty" },
402 { &isl_val_ceil
, "NaN", "NaN" },
403 { &isl_val_2exp
, "-3", "1/8" },
404 { &isl_val_2exp
, "-1", "1/2" },
405 { &isl_val_2exp
, "1", "2" },
406 { &isl_val_2exp
, "2", "4" },
407 { &isl_val_2exp
, "3", "8" },
410 /* Perform some basic tests of unary operations on isl_val objects.
412 static int test_un_val(isl_ctx
*ctx
)
416 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
419 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
420 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
421 res
= isl_val_read_from_str(ctx
, val_un_tests
[i
].res
);
422 fn
= val_un_tests
[i
].op
;
424 if (isl_val_is_nan(res
))
425 ok
= isl_val_is_nan(v
);
427 ok
= isl_val_eq(v
, res
);
433 isl_die(ctx
, isl_error_unknown
,
434 "unexpected result", return -1);
441 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
442 __isl_take isl_val
*v2
);
444 ['+'] = { &isl_val_add
},
445 ['-'] = { &isl_val_sub
},
446 ['*'] = { &isl_val_mul
},
447 ['/'] = { &isl_val_div
},
448 ['g'] = { &isl_val_gcd
},
449 ['m'] = { &isl_val_min
},
450 ['M'] = { &isl_val_max
},
458 } val_bin_tests
[] = {
459 { "0", '+', "0", "0" },
460 { "1", '+', "0", "1" },
461 { "1", '+', "1", "2" },
462 { "1", '-', "1", "0" },
463 { "1", '*', "1", "1" },
464 { "1", '/', "1", "1" },
465 { "2", '*', "3", "6" },
466 { "2", '*', "1/2", "1" },
467 { "2", '*', "1/3", "2/3" },
468 { "2/3", '*', "3/5", "2/5" },
469 { "2/3", '*', "7/5", "14/15" },
470 { "2", '/', "1/2", "4" },
471 { "-2", '/', "-1/2", "4" },
472 { "-2", '/', "1/2", "-4" },
473 { "2", '/', "-1/2", "-4" },
474 { "2", '/', "2", "1" },
475 { "2", '/', "3", "2/3" },
476 { "2/3", '/', "5/3", "2/5" },
477 { "2/3", '/', "5/7", "14/15" },
478 { "0", '/', "0", "NaN" },
479 { "42", '/', "0", "NaN" },
480 { "-42", '/', "0", "NaN" },
481 { "infty", '/', "0", "NaN" },
482 { "-infty", '/', "0", "NaN" },
483 { "NaN", '/', "0", "NaN" },
484 { "0", '/', "NaN", "NaN" },
485 { "42", '/', "NaN", "NaN" },
486 { "-42", '/', "NaN", "NaN" },
487 { "infty", '/', "NaN", "NaN" },
488 { "-infty", '/', "NaN", "NaN" },
489 { "NaN", '/', "NaN", "NaN" },
490 { "0", '/', "infty", "0" },
491 { "42", '/', "infty", "0" },
492 { "-42", '/', "infty", "0" },
493 { "infty", '/', "infty", "NaN" },
494 { "-infty", '/', "infty", "NaN" },
495 { "NaN", '/', "infty", "NaN" },
496 { "0", '/', "-infty", "0" },
497 { "42", '/', "-infty", "0" },
498 { "-42", '/', "-infty", "0" },
499 { "infty", '/', "-infty", "NaN" },
500 { "-infty", '/', "-infty", "NaN" },
501 { "NaN", '/', "-infty", "NaN" },
502 { "1", '-', "1/3", "2/3" },
503 { "1/3", '+', "1/2", "5/6" },
504 { "1/2", '+', "1/2", "1" },
505 { "3/4", '-', "1/4", "1/2" },
506 { "1/2", '-', "1/3", "1/6" },
507 { "infty", '+', "42", "infty" },
508 { "infty", '+', "infty", "infty" },
509 { "42", '+', "infty", "infty" },
510 { "infty", '-', "infty", "NaN" },
511 { "infty", '*', "infty", "infty" },
512 { "infty", '*', "-infty", "-infty" },
513 { "-infty", '*', "infty", "-infty" },
514 { "-infty", '*', "-infty", "infty" },
515 { "0", '*', "infty", "NaN" },
516 { "1", '*', "infty", "infty" },
517 { "infty", '*', "0", "NaN" },
518 { "infty", '*', "42", "infty" },
519 { "42", '-', "infty", "-infty" },
520 { "infty", '+', "-infty", "NaN" },
521 { "4", 'g', "6", "2" },
522 { "5", 'g', "6", "1" },
523 { "42", 'm', "3", "3" },
524 { "42", 'M', "3", "42" },
525 { "3", 'm', "42", "3" },
526 { "3", 'M', "42", "42" },
527 { "42", 'm', "infty", "42" },
528 { "42", 'M', "infty", "infty" },
529 { "42", 'm', "-infty", "-infty" },
530 { "42", 'M', "-infty", "42" },
531 { "42", 'm', "NaN", "NaN" },
532 { "42", 'M', "NaN", "NaN" },
533 { "infty", 'm', "-infty", "-infty" },
534 { "infty", 'M', "-infty", "infty" },
537 /* Perform some basic tests of binary operations on isl_val objects.
539 static int test_bin_val(isl_ctx
*ctx
)
542 isl_val
*v1
, *v2
, *res
;
543 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
544 __isl_take isl_val
*v2
);
547 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
548 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
549 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
550 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
551 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
553 if (isl_val_is_nan(res
))
554 ok
= isl_val_is_nan(v1
);
556 ok
= isl_val_eq(v1
, res
);
562 isl_die(ctx
, isl_error_unknown
,
563 "unexpected result", return -1);
569 /* Perform some basic tests on isl_val objects.
571 static int test_val(isl_ctx
*ctx
)
573 if (test_un_val(ctx
) < 0)
575 if (test_bin_val(ctx
) < 0)
580 static int test_div(isl_ctx
*ctx
)
589 struct isl_basic_set
*bset
;
590 struct isl_constraint
*c
;
595 dim
= isl_space_set_alloc(ctx
, 0, 3);
596 bset
= isl_basic_set_universe(isl_space_copy(dim
));
597 ls
= isl_local_space_from_space(dim
);
599 c
= isl_equality_alloc(isl_local_space_copy(ls
));
600 isl_int_set_si(v
, -1);
601 isl_constraint_set_constant(c
, v
);
602 isl_int_set_si(v
, 1);
603 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
604 isl_int_set_si(v
, 3);
605 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
606 bset
= isl_basic_set_add_constraint(bset
, c
);
608 c
= isl_equality_alloc(isl_local_space_copy(ls
));
609 isl_int_set_si(v
, 1);
610 isl_constraint_set_constant(c
, v
);
611 isl_int_set_si(v
, -1);
612 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
613 isl_int_set_si(v
, 3);
614 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
615 bset
= isl_basic_set_add_constraint(bset
, c
);
617 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
619 assert(bset
&& bset
->n_div
== 1);
620 isl_local_space_free(ls
);
621 isl_basic_set_free(bset
);
624 dim
= isl_space_set_alloc(ctx
, 0, 3);
625 bset
= isl_basic_set_universe(isl_space_copy(dim
));
626 ls
= isl_local_space_from_space(dim
);
628 c
= isl_equality_alloc(isl_local_space_copy(ls
));
629 isl_int_set_si(v
, 1);
630 isl_constraint_set_constant(c
, v
);
631 isl_int_set_si(v
, -1);
632 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
633 isl_int_set_si(v
, 3);
634 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
635 bset
= isl_basic_set_add_constraint(bset
, c
);
637 c
= isl_equality_alloc(isl_local_space_copy(ls
));
638 isl_int_set_si(v
, -1);
639 isl_constraint_set_constant(c
, v
);
640 isl_int_set_si(v
, 1);
641 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
642 isl_int_set_si(v
, 3);
643 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
644 bset
= isl_basic_set_add_constraint(bset
, c
);
646 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
648 assert(bset
&& bset
->n_div
== 1);
649 isl_local_space_free(ls
);
650 isl_basic_set_free(bset
);
653 dim
= isl_space_set_alloc(ctx
, 0, 3);
654 bset
= isl_basic_set_universe(isl_space_copy(dim
));
655 ls
= isl_local_space_from_space(dim
);
657 c
= isl_equality_alloc(isl_local_space_copy(ls
));
658 isl_int_set_si(v
, 1);
659 isl_constraint_set_constant(c
, v
);
660 isl_int_set_si(v
, -1);
661 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
662 isl_int_set_si(v
, 3);
663 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
664 bset
= isl_basic_set_add_constraint(bset
, c
);
666 c
= isl_equality_alloc(isl_local_space_copy(ls
));
667 isl_int_set_si(v
, -3);
668 isl_constraint_set_constant(c
, v
);
669 isl_int_set_si(v
, 1);
670 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
671 isl_int_set_si(v
, 4);
672 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
673 bset
= isl_basic_set_add_constraint(bset
, c
);
675 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
677 assert(bset
&& bset
->n_div
== 1);
678 isl_local_space_free(ls
);
679 isl_basic_set_free(bset
);
682 dim
= isl_space_set_alloc(ctx
, 0, 3);
683 bset
= isl_basic_set_universe(isl_space_copy(dim
));
684 ls
= isl_local_space_from_space(dim
);
686 c
= isl_equality_alloc(isl_local_space_copy(ls
));
687 isl_int_set_si(v
, 2);
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
, 1, v
);
693 bset
= isl_basic_set_add_constraint(bset
, c
);
695 c
= isl_equality_alloc(isl_local_space_copy(ls
));
696 isl_int_set_si(v
, -1);
697 isl_constraint_set_constant(c
, v
);
698 isl_int_set_si(v
, 1);
699 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
700 isl_int_set_si(v
, 6);
701 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
702 bset
= isl_basic_set_add_constraint(bset
, c
);
704 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
706 assert(isl_basic_set_is_empty(bset
));
707 isl_local_space_free(ls
);
708 isl_basic_set_free(bset
);
711 dim
= isl_space_set_alloc(ctx
, 0, 3);
712 bset
= isl_basic_set_universe(isl_space_copy(dim
));
713 ls
= isl_local_space_from_space(dim
);
715 c
= isl_equality_alloc(isl_local_space_copy(ls
));
716 isl_int_set_si(v
, -1);
717 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
718 isl_int_set_si(v
, 3);
719 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
720 bset
= isl_basic_set_add_constraint(bset
, c
);
722 c
= isl_equality_alloc(isl_local_space_copy(ls
));
723 isl_int_set_si(v
, 1);
724 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
725 isl_int_set_si(v
, -3);
726 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
727 bset
= isl_basic_set_add_constraint(bset
, c
);
729 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
731 assert(bset
&& bset
->n_div
== 0);
732 isl_basic_set_free(bset
);
733 isl_local_space_free(ls
);
736 dim
= isl_space_set_alloc(ctx
, 0, 3);
737 bset
= isl_basic_set_universe(isl_space_copy(dim
));
738 ls
= isl_local_space_from_space(dim
);
740 c
= isl_equality_alloc(isl_local_space_copy(ls
));
741 isl_int_set_si(v
, -1);
742 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
743 isl_int_set_si(v
, 6);
744 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
745 bset
= isl_basic_set_add_constraint(bset
, c
);
747 c
= isl_equality_alloc(isl_local_space_copy(ls
));
748 isl_int_set_si(v
, 1);
749 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
750 isl_int_set_si(v
, -3);
751 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
752 bset
= isl_basic_set_add_constraint(bset
, c
);
754 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
756 assert(bset
&& bset
->n_div
== 1);
757 isl_basic_set_free(bset
);
758 isl_local_space_free(ls
);
761 /* This test is a bit tricky. We set up an equality
763 * Normalization of divs creates _two_ divs
766 * Afterwards e0 is removed again because it has coefficient -1
767 * and we end up with the original equality and div again.
768 * Perhaps we can avoid the introduction of this temporary div.
770 dim
= isl_space_set_alloc(ctx
, 0, 4);
771 bset
= isl_basic_set_universe(isl_space_copy(dim
));
772 ls
= isl_local_space_from_space(dim
);
774 c
= isl_equality_alloc(isl_local_space_copy(ls
));
775 isl_int_set_si(v
, -1);
776 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
777 isl_int_set_si(v
, -3);
778 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
779 isl_int_set_si(v
, -3);
780 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
781 isl_int_set_si(v
, 6);
782 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
783 bset
= isl_basic_set_add_constraint(bset
, c
);
785 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
787 /* Test disabled for now */
789 assert(bset && bset->n_div == 1);
791 isl_local_space_free(ls
);
792 isl_basic_set_free(bset
);
795 dim
= isl_space_set_alloc(ctx
, 0, 5);
796 bset
= isl_basic_set_universe(isl_space_copy(dim
));
797 ls
= isl_local_space_from_space(dim
);
799 c
= isl_equality_alloc(isl_local_space_copy(ls
));
800 isl_int_set_si(v
, -1);
801 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
802 isl_int_set_si(v
, -3);
803 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
804 isl_int_set_si(v
, -3);
805 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
806 isl_int_set_si(v
, 6);
807 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
808 bset
= isl_basic_set_add_constraint(bset
, c
);
810 c
= isl_equality_alloc(isl_local_space_copy(ls
));
811 isl_int_set_si(v
, -1);
812 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
813 isl_int_set_si(v
, 1);
814 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
815 isl_int_set_si(v
, 1);
816 isl_constraint_set_constant(c
, v
);
817 bset
= isl_basic_set_add_constraint(bset
, c
);
819 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
821 /* Test disabled for now */
823 assert(bset && bset->n_div == 1);
825 isl_local_space_free(ls
);
826 isl_basic_set_free(bset
);
829 dim
= isl_space_set_alloc(ctx
, 0, 4);
830 bset
= isl_basic_set_universe(isl_space_copy(dim
));
831 ls
= isl_local_space_from_space(dim
);
833 c
= isl_equality_alloc(isl_local_space_copy(ls
));
834 isl_int_set_si(v
, 1);
835 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
836 isl_int_set_si(v
, -1);
837 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
838 isl_int_set_si(v
, -2);
839 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
840 bset
= isl_basic_set_add_constraint(bset
, c
);
842 c
= isl_equality_alloc(isl_local_space_copy(ls
));
843 isl_int_set_si(v
, -1);
844 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
845 isl_int_set_si(v
, 3);
846 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
847 isl_int_set_si(v
, 2);
848 isl_constraint_set_constant(c
, v
);
849 bset
= isl_basic_set_add_constraint(bset
, c
);
851 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
853 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
855 assert(!isl_basic_set_is_empty(bset
));
857 isl_local_space_free(ls
);
858 isl_basic_set_free(bset
);
861 dim
= isl_space_set_alloc(ctx
, 0, 3);
862 bset
= isl_basic_set_universe(isl_space_copy(dim
));
863 ls
= isl_local_space_from_space(dim
);
865 c
= isl_equality_alloc(isl_local_space_copy(ls
));
866 isl_int_set_si(v
, 1);
867 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
868 isl_int_set_si(v
, -2);
869 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
870 bset
= isl_basic_set_add_constraint(bset
, c
);
872 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
874 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
876 isl_local_space_free(ls
);
877 isl_basic_set_free(bset
);
881 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
882 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
883 set
= isl_set_read_from_str(ctx
, str
);
884 set
= isl_set_compute_divs(set
);
889 str
= "{ [i,j] : 2*[i/2] + 3 * [j/4] <= 10 and 2 i = j }";
890 bset
= isl_basic_set_read_from_str(ctx
, str
);
891 n
= isl_basic_set_dim(bset
, isl_dim_div
);
892 isl_basic_set_free(bset
);
896 isl_die(ctx
, isl_error_unknown
,
897 "expecting no existentials", return -1);
899 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
900 set
= isl_set_read_from_str(ctx
, str
);
901 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
902 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
903 empty
= isl_set_is_empty(set
);
908 isl_die(ctx
, isl_error_unknown
,
909 "result not as accurate as expected", return -1);
914 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
918 struct isl_basic_set
*bset1
, *bset2
;
919 struct isl_basic_map
*bmap
;
921 filename
= get_filename(ctx
, name
, "omega");
923 input
= fopen(filename
, "r");
926 bset1
= isl_basic_set_read_from_file(ctx
, input
);
927 bmap
= isl_basic_map_read_from_file(ctx
, input
);
929 bset1
= isl_basic_set_apply(bset1
, bmap
);
931 bset2
= isl_basic_set_read_from_file(ctx
, input
);
933 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
935 isl_basic_set_free(bset1
);
936 isl_basic_set_free(bset2
);
942 void test_application(struct isl_ctx
*ctx
)
944 test_application_case(ctx
, "application");
945 test_application_case(ctx
, "application2");
948 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
952 struct isl_basic_set
*bset1
, *bset2
;
954 filename
= get_filename(ctx
, name
, "polylib");
956 input
= fopen(filename
, "r");
959 bset1
= isl_basic_set_read_from_file(ctx
, input
);
960 bset2
= isl_basic_set_read_from_file(ctx
, input
);
962 bset1
= isl_basic_set_affine_hull(bset1
);
964 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
966 isl_basic_set_free(bset1
);
967 isl_basic_set_free(bset2
);
973 int test_affine_hull(struct isl_ctx
*ctx
)
977 isl_basic_set
*bset
, *bset2
;
981 test_affine_hull_case(ctx
, "affine2");
982 test_affine_hull_case(ctx
, "affine");
983 test_affine_hull_case(ctx
, "affine3");
985 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
986 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
987 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
988 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
989 set
= isl_set_read_from_str(ctx
, str
);
990 bset
= isl_set_affine_hull(set
);
991 n
= isl_basic_set_dim(bset
, isl_dim_div
);
992 isl_basic_set_free(bset
);
994 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
997 /* Check that isl_map_affine_hull is not confused by
998 * the reordering of divs in isl_map_align_divs.
1000 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1001 "32e0 = b and 32e1 = c); "
1002 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1003 set
= isl_set_read_from_str(ctx
, str
);
1004 bset
= isl_set_affine_hull(set
);
1005 isl_basic_set_free(bset
);
1009 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1010 "32e2 = 31 + 31e0 }";
1011 set
= isl_set_read_from_str(ctx
, str
);
1012 bset
= isl_set_affine_hull(set
);
1013 str
= "{ [a] : exists e : a = 32 e }";
1014 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1015 subset
= isl_basic_set_is_subset(bset
, bset2
);
1016 isl_basic_set_free(bset
);
1017 isl_basic_set_free(bset2
);
1021 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1027 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1031 struct isl_basic_set
*bset1
, *bset2
;
1032 struct isl_set
*set
;
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 set
= isl_basic_set_union(bset1
, bset2
);
1043 bset1
= isl_set_convex_hull(set
);
1045 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1047 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1049 isl_basic_set_free(bset1
);
1050 isl_basic_set_free(bset2
);
1059 } convex_hull_tests
[] = {
1060 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1061 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1062 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1063 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1064 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1065 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1066 "i2 <= 5 and i2 >= 4; "
1067 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1068 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1069 "i2 <= 5 + i0 and i2 >= i0 }" },
1070 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1071 "{ [x, y] : 1 = 0 }" },
1074 void test_convex_hull_algo(struct isl_ctx
*ctx
, int convex
)
1077 int orig_convex
= ctx
->opt
->convex
;
1078 ctx
->opt
->convex
= convex
;
1080 test_convex_hull_case(ctx
, "convex0");
1081 test_convex_hull_case(ctx
, "convex1");
1082 test_convex_hull_case(ctx
, "convex2");
1083 test_convex_hull_case(ctx
, "convex3");
1084 test_convex_hull_case(ctx
, "convex4");
1085 test_convex_hull_case(ctx
, "convex5");
1086 test_convex_hull_case(ctx
, "convex6");
1087 test_convex_hull_case(ctx
, "convex7");
1088 test_convex_hull_case(ctx
, "convex8");
1089 test_convex_hull_case(ctx
, "convex9");
1090 test_convex_hull_case(ctx
, "convex10");
1091 test_convex_hull_case(ctx
, "convex11");
1092 test_convex_hull_case(ctx
, "convex12");
1093 test_convex_hull_case(ctx
, "convex13");
1094 test_convex_hull_case(ctx
, "convex14");
1095 test_convex_hull_case(ctx
, "convex15");
1097 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1098 isl_set
*set1
, *set2
;
1100 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1101 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1102 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1103 assert(isl_set_is_equal(set1
, set2
));
1108 ctx
->opt
->convex
= orig_convex
;
1111 void test_convex_hull(struct isl_ctx
*ctx
)
1113 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
);
1114 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
);
1117 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1121 struct isl_basic_set
*bset1
, *bset2
;
1123 filename
= get_filename(ctx
, name
, "polylib");
1125 input
= fopen(filename
, "r");
1128 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1129 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1131 bset1
= isl_basic_set_gist(bset1
, bset2
);
1133 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1135 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1137 isl_basic_set_free(bset1
);
1138 isl_basic_set_free(bset2
);
1144 static int test_gist(struct isl_ctx
*ctx
)
1147 isl_basic_set
*bset1
, *bset2
;
1148 isl_map
*map1
, *map2
;
1150 test_gist_case(ctx
, "gist1");
1152 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1153 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1154 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1155 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1156 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1157 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1158 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1159 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1160 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1161 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1162 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1163 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1164 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1165 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1166 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1167 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1168 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1169 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1170 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1171 bset1
= isl_basic_set_gist(bset1
, bset2
);
1172 assert(bset1
&& bset1
->n_div
== 0);
1173 isl_basic_set_free(bset1
);
1175 /* Check that the integer divisions of the second disjunct
1176 * do not spread to the first disjunct.
1178 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1179 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1180 "(exists (e0 = [(-1 + t1)/16], "
1181 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1182 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1183 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1184 "o0 <= 4294967295 and t1 <= -1)) }";
1185 map1
= isl_map_read_from_str(ctx
, str
);
1186 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1187 map2
= isl_map_read_from_str(ctx
, str
);
1188 map1
= isl_map_gist(map1
, map2
);
1192 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1193 isl_map_free(map1
); return -1);
1194 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1195 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1196 isl_map_free(map1
); return -1);
1202 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1204 isl_set
*set
, *set2
;
1208 set
= isl_set_read_from_str(ctx
, str
);
1209 set
= isl_set_coalesce(set
);
1210 set2
= isl_set_read_from_str(ctx
, str
);
1211 equal
= isl_set_is_equal(set
, set2
);
1212 one
= set
&& set
->n
== 1;
1219 isl_die(ctx
, isl_error_unknown
,
1220 "coalesced set not equal to input", return -1);
1221 if (check_one
&& !one
)
1222 isl_die(ctx
, isl_error_unknown
,
1223 "coalesced set should not be a union", return -1);
1228 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1233 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1234 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1236 if (test_coalesce_set(ctx
,
1237 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1238 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1239 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1240 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1241 "-10 <= y <= 0}", 1) < 0)
1243 if (test_coalesce_set(ctx
,
1244 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
1246 if (test_coalesce_set(ctx
,
1247 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
1255 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1260 /* Inputs for coalescing tests.
1261 * "str" is a string representation of the input set.
1262 * "single_disjunct" is set if we expect the result to consist of
1263 * a single disjunct.
1266 int single_disjunct
;
1268 } coalesce_tests
[] = {
1269 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1270 "y >= x & x >= 2 & 5 >= y }" },
1271 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1272 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1273 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1274 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1275 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1276 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1277 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1278 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1279 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1280 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1281 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1282 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1283 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1284 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1285 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1286 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1287 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1288 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1289 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1290 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1291 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1292 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1293 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1294 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1295 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1296 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1297 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1298 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1299 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1300 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1301 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1302 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1303 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1304 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1305 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1306 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1307 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1308 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1309 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1310 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1311 "[o0, o1, o2, o3, o4, o5, o6]] : "
1312 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1313 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1314 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1315 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1316 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1317 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1318 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1319 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1320 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1321 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1322 "o6 >= i3 + i6 - o3 and M >= 0 and "
1323 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1324 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1325 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1326 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1327 "(o0 = 0 and M >= 2 and N >= 3) or "
1328 "(M = 0 and o0 = 0 and N >= 3) }" },
1329 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1330 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1331 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1332 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1333 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1334 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1335 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1336 "(y = 3 and x = 1) }" },
1337 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1338 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1339 "i1 <= M and i3 <= M and i4 <= M) or "
1340 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1341 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1342 "i4 <= -1 + M) }" },
1343 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1344 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1345 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1346 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1347 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1348 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1349 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1350 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1351 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1352 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1353 { 0, "{ [a, b] : exists e : 2e = a and "
1354 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1355 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1356 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1357 "j >= 1 and j' <= i + j - i' and i >= 1; "
1359 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1360 "[i,j] : exists a : j = 3a }" },
1361 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1362 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1364 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1365 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1366 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1367 "c <= 6 + 8a and a >= 3; "
1368 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1369 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1370 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1371 "[x,0] : 3 <= x <= 4 }" },
1372 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1373 "[x,0] : 4 <= x <= 5 }" },
1374 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1375 "[x,0] : 3 <= x <= 5 }" },
1376 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1377 "[x,0] : 3 <= x <= 4 }" },
1378 { 1 , "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1380 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1383 /* Test the functionality of isl_set_coalesce.
1384 * That is, check that the output is always equal to the input
1385 * and in some cases that the result consists of a single disjunct.
1387 static int test_coalesce(struct isl_ctx
*ctx
)
1391 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
1392 const char *str
= coalesce_tests
[i
].str
;
1393 int check_one
= coalesce_tests
[i
].single_disjunct
;
1394 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
1398 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
1404 void test_closure(struct isl_ctx
*ctx
)
1408 isl_map
*up
, *right
;
1409 isl_map
*map
, *map2
;
1412 /* COCOA example 1 */
1413 map
= isl_map_read_from_str(ctx
,
1414 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1415 "1 <= i and i < n and 1 <= j and j < n or "
1416 "i2 = i + 1 and j2 = j - 1 and "
1417 "1 <= i and i < n and 2 <= j and j <= n }");
1418 map
= isl_map_power(map
, &exact
);
1422 /* COCOA example 1 */
1423 map
= isl_map_read_from_str(ctx
,
1424 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1425 "1 <= i and i < n and 1 <= j and j < n or "
1426 "i2 = i + 1 and j2 = j - 1 and "
1427 "1 <= i and i < n and 2 <= j and j <= n }");
1428 map
= isl_map_transitive_closure(map
, &exact
);
1430 map2
= isl_map_read_from_str(ctx
,
1431 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1432 "1 <= i and i < n and 1 <= j and j <= n and "
1433 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1434 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1435 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1436 assert(isl_map_is_equal(map
, map2
));
1440 map
= isl_map_read_from_str(ctx
,
1441 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1442 " 0 <= y and y <= n }");
1443 map
= isl_map_transitive_closure(map
, &exact
);
1444 map2
= isl_map_read_from_str(ctx
,
1445 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1446 " 0 <= y and y <= n }");
1447 assert(isl_map_is_equal(map
, map2
));
1451 /* COCOA example 2 */
1452 map
= isl_map_read_from_str(ctx
,
1453 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1454 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1455 "i2 = i + 2 and j2 = j - 2 and "
1456 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1457 map
= isl_map_transitive_closure(map
, &exact
);
1459 map2
= isl_map_read_from_str(ctx
,
1460 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1461 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1462 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1463 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1464 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1465 assert(isl_map_is_equal(map
, map2
));
1469 /* COCOA Fig.2 left */
1470 map
= isl_map_read_from_str(ctx
,
1471 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1472 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1474 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1475 "j <= 2 i - 3 and j <= n - 2 or "
1476 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1477 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1478 map
= isl_map_transitive_closure(map
, &exact
);
1482 /* COCOA Fig.2 right */
1483 map
= isl_map_read_from_str(ctx
,
1484 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1485 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1487 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1488 "j <= 2 i - 4 and j <= n - 3 or "
1489 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1490 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1491 map
= isl_map_power(map
, &exact
);
1495 /* COCOA Fig.2 right */
1496 map
= isl_map_read_from_str(ctx
,
1497 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1498 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1500 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1501 "j <= 2 i - 4 and j <= n - 3 or "
1502 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1503 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1504 map
= isl_map_transitive_closure(map
, &exact
);
1506 map2
= isl_map_read_from_str(ctx
,
1507 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1508 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1509 "j <= n and 3 + i + 2 j <= 3 n and "
1510 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1511 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1512 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1513 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1514 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1515 assert(isl_map_is_equal(map
, map2
));
1519 /* COCOA Fig.1 right */
1520 dom
= isl_set_read_from_str(ctx
,
1521 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1522 "2 x - 3 y + 3 >= 0 }");
1523 right
= isl_map_read_from_str(ctx
,
1524 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1525 up
= isl_map_read_from_str(ctx
,
1526 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1527 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1528 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1529 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1530 up
= isl_map_intersect_range(up
, dom
);
1531 map
= isl_map_union(up
, right
);
1532 map
= isl_map_transitive_closure(map
, &exact
);
1534 map2
= isl_map_read_from_str(ctx
,
1535 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1536 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1537 assert(isl_map_is_equal(map
, map2
));
1541 /* COCOA Theorem 1 counter example */
1542 map
= isl_map_read_from_str(ctx
,
1543 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1544 "i2 = 1 and j2 = j or "
1545 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1546 map
= isl_map_transitive_closure(map
, &exact
);
1550 map
= isl_map_read_from_str(ctx
,
1551 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1552 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1553 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1554 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1555 map
= isl_map_transitive_closure(map
, &exact
);
1559 /* Kelly et al 1996, fig 12 */
1560 map
= isl_map_read_from_str(ctx
,
1561 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1562 "1 <= i,j,j+1 <= n or "
1563 "j = n and j2 = 1 and i2 = i + 1 and "
1564 "1 <= i,i+1 <= n }");
1565 map
= isl_map_transitive_closure(map
, &exact
);
1567 map2
= isl_map_read_from_str(ctx
,
1568 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1569 "1 <= i <= n and i = i2 or "
1570 "1 <= i < i2 <= n and 1 <= j <= n and "
1572 assert(isl_map_is_equal(map
, map2
));
1576 /* Omega's closure4 */
1577 map
= isl_map_read_from_str(ctx
,
1578 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1579 "1 <= x,y <= 10 or "
1580 "x2 = x + 1 and y2 = y and "
1581 "1 <= x <= 20 && 5 <= y <= 15 }");
1582 map
= isl_map_transitive_closure(map
, &exact
);
1586 map
= isl_map_read_from_str(ctx
,
1587 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1588 map
= isl_map_transitive_closure(map
, &exact
);
1590 map2
= isl_map_read_from_str(ctx
,
1591 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1592 assert(isl_map_is_equal(map
, map2
));
1596 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1597 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1598 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1599 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1600 map
= isl_map_read_from_str(ctx
, str
);
1601 map
= isl_map_transitive_closure(map
, &exact
);
1603 map2
= isl_map_read_from_str(ctx
, str
);
1604 assert(isl_map_is_equal(map
, map2
));
1608 str
= "{[0] -> [1]; [2] -> [3]}";
1609 map
= isl_map_read_from_str(ctx
, str
);
1610 map
= isl_map_transitive_closure(map
, &exact
);
1612 map2
= isl_map_read_from_str(ctx
, str
);
1613 assert(isl_map_is_equal(map
, map2
));
1617 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1618 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1619 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1620 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1621 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1622 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1623 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1624 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1625 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1626 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1627 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1628 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1629 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1630 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1631 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1632 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1633 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1634 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1635 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1636 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1637 map
= isl_map_read_from_str(ctx
, str
);
1638 map
= isl_map_transitive_closure(map
, NULL
);
1643 void test_lex(struct isl_ctx
*ctx
)
1648 dim
= isl_space_set_alloc(ctx
, 0, 0);
1649 map
= isl_map_lex_le(dim
);
1650 assert(!isl_map_is_empty(map
));
1654 static int test_lexmin(struct isl_ctx
*ctx
)
1658 isl_basic_map
*bmap
;
1659 isl_map
*map
, *map2
;
1662 isl_pw_multi_aff
*pma
;
1664 str
= "[p0, p1] -> { [] -> [] : "
1665 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1666 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1667 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1668 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1669 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1670 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1671 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1672 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1673 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1674 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1675 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1676 map
= isl_map_read_from_str(ctx
, str
);
1677 map
= isl_map_lexmin(map
);
1680 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1681 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1682 set
= isl_set_read_from_str(ctx
, str
);
1683 set
= isl_set_lexmax(set
);
1684 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1685 set2
= isl_set_read_from_str(ctx
, str
);
1686 set
= isl_set_intersect(set
, set2
);
1687 assert(!isl_set_is_empty(set
));
1690 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1691 map
= isl_map_read_from_str(ctx
, str
);
1692 map
= isl_map_lexmin(map
);
1693 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1694 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1695 map2
= isl_map_read_from_str(ctx
, str
);
1696 assert(isl_map_is_equal(map
, map2
));
1700 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1701 map
= isl_map_read_from_str(ctx
, str
);
1702 map2
= isl_map_copy(map
);
1703 map
= isl_map_lexmin(map
);
1704 assert(isl_map_is_equal(map
, map2
));
1708 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1709 map
= isl_map_read_from_str(ctx
, str
);
1710 map
= isl_map_lexmin(map
);
1711 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1712 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1713 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1714 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1715 map2
= isl_map_read_from_str(ctx
, str
);
1716 assert(isl_map_is_equal(map
, map2
));
1720 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1721 " 8i' <= i and 8i' >= -7 + i }";
1722 bmap
= isl_basic_map_read_from_str(ctx
, str
);
1723 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
1724 map2
= isl_map_from_pw_multi_aff(pma
);
1725 map
= isl_map_from_basic_map(bmap
);
1726 assert(isl_map_is_equal(map
, map2
));
1730 str
= "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1731 map
= isl_map_read_from_str(ctx
, str
);
1732 map
= isl_map_lexmin(map
);
1733 str
= "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1734 map2
= isl_map_read_from_str(ctx
, str
);
1735 assert(isl_map_is_equal(map
, map2
));
1739 /* Check that empty pieces are properly combined. */
1740 str
= "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
1741 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
1742 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }";
1743 map
= isl_map_read_from_str(ctx
, str
);
1744 map
= isl_map_lexmin(map
);
1745 str
= "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
1746 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
1748 map2
= isl_map_read_from_str(ctx
, str
);
1749 assert(isl_map_is_equal(map
, map2
));
1753 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1754 " 8i' <= i and 8i' >= -7 + i }";
1755 set
= isl_set_read_from_str(ctx
, str
);
1756 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
1757 set2
= isl_set_from_pw_multi_aff(pma
);
1758 equal
= isl_set_is_equal(set
, set2
);
1764 isl_die(ctx
, isl_error_unknown
,
1765 "unexpected difference between set and "
1766 "piecewise affine expression", return -1);
1771 /* Check that isl_set_min_val and isl_set_max_val compute the correct
1772 * result on non-convex inputs.
1774 static int test_min(struct isl_ctx
*ctx
)
1781 set
= isl_set_read_from_str(ctx
, "{ [-1]; [1] }");
1782 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x] }");
1783 val
= isl_set_min_val(set
, aff
);
1784 min_ok
= isl_val_is_negone(val
);
1786 val
= isl_set_max_val(set
, aff
);
1787 max_ok
= isl_val_is_one(val
);
1792 if (min_ok
< 0 || max_ok
< 0)
1795 isl_die(ctx
, isl_error_unknown
,
1796 "unexpected minimum", return -1);
1798 isl_die(ctx
, isl_error_unknown
,
1799 "unexpected maximum", return -1);
1809 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1810 void *dep_user
, void *user
)
1812 struct must_may
*mm
= (struct must_may
*)user
;
1815 mm
->must
= isl_map_union(mm
->must
, dep
);
1817 mm
->may
= isl_map_union(mm
->may
, dep
);
1822 static int common_space(void *first
, void *second
)
1824 int depth
= *(int *)first
;
1828 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1836 map2
= isl_map_read_from_str(map
->ctx
, str
);
1837 equal
= isl_map_is_equal(map
, map2
);
1843 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
1847 equal
= map_is_equal(map
, str
);
1851 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
1852 "result not as expected", return -1);
1856 void test_dep(struct isl_ctx
*ctx
)
1861 isl_access_info
*ai
;
1868 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1869 map
= isl_map_read_from_str(ctx
, str
);
1870 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1872 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1873 map
= isl_map_read_from_str(ctx
, str
);
1874 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1876 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1877 map
= isl_map_read_from_str(ctx
, str
);
1878 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1880 flow
= isl_access_info_compute_flow(ai
);
1881 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1882 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1883 mm
.may
= isl_map_empty(dim
);
1885 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1887 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1888 " [1,10,0] -> [2,5,0] }";
1889 assert(map_is_equal(mm
.must
, str
));
1890 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1891 assert(map_is_equal(mm
.may
, str
));
1893 isl_map_free(mm
.must
);
1894 isl_map_free(mm
.may
);
1895 isl_flow_free(flow
);
1898 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1899 map
= isl_map_read_from_str(ctx
, str
);
1900 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1902 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1903 map
= isl_map_read_from_str(ctx
, str
);
1904 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1906 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1907 map
= isl_map_read_from_str(ctx
, str
);
1908 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1910 flow
= isl_access_info_compute_flow(ai
);
1911 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1912 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1913 mm
.may
= isl_map_empty(dim
);
1915 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1917 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1918 assert(map_is_equal(mm
.must
, str
));
1919 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1920 assert(map_is_equal(mm
.may
, str
));
1922 isl_map_free(mm
.must
);
1923 isl_map_free(mm
.may
);
1924 isl_flow_free(flow
);
1927 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1928 map
= isl_map_read_from_str(ctx
, str
);
1929 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1931 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1932 map
= isl_map_read_from_str(ctx
, str
);
1933 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1935 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1936 map
= isl_map_read_from_str(ctx
, str
);
1937 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1939 flow
= isl_access_info_compute_flow(ai
);
1940 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1941 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1942 mm
.may
= isl_map_empty(dim
);
1944 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1946 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1947 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1948 assert(map_is_equal(mm
.may
, str
));
1949 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1950 assert(map_is_equal(mm
.must
, str
));
1952 isl_map_free(mm
.must
);
1953 isl_map_free(mm
.may
);
1954 isl_flow_free(flow
);
1957 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1958 map
= isl_map_read_from_str(ctx
, str
);
1959 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1961 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1962 map
= isl_map_read_from_str(ctx
, str
);
1963 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1965 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1966 map
= isl_map_read_from_str(ctx
, str
);
1967 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1969 flow
= isl_access_info_compute_flow(ai
);
1970 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1971 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1972 mm
.may
= isl_map_empty(dim
);
1974 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1976 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1977 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1978 assert(map_is_equal(mm
.may
, str
));
1979 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1980 assert(map_is_equal(mm
.must
, str
));
1982 isl_map_free(mm
.must
);
1983 isl_map_free(mm
.may
);
1984 isl_flow_free(flow
);
1987 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1988 map
= isl_map_read_from_str(ctx
, str
);
1989 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1991 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1992 map
= isl_map_read_from_str(ctx
, str
);
1993 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1995 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1996 map
= isl_map_read_from_str(ctx
, str
);
1997 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1999 flow
= isl_access_info_compute_flow(ai
);
2000 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2001 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2002 mm
.may
= isl_map_empty(dim
);
2004 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2006 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2007 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2008 assert(map_is_equal(mm
.may
, str
));
2009 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2010 assert(map_is_equal(mm
.must
, str
));
2012 isl_map_free(mm
.must
);
2013 isl_map_free(mm
.may
);
2014 isl_flow_free(flow
);
2019 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2020 map
= isl_map_read_from_str(ctx
, str
);
2021 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
2023 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2024 map
= isl_map_read_from_str(ctx
, str
);
2025 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2027 flow
= isl_access_info_compute_flow(ai
);
2028 dim
= isl_space_alloc(ctx
, 0, 5, 5);
2029 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2030 mm
.may
= isl_map_empty(dim
);
2032 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2034 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
2035 assert(map_is_equal(mm
.must
, str
));
2036 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
2037 assert(map_is_equal(mm
.may
, str
));
2039 isl_map_free(mm
.must
);
2040 isl_map_free(mm
.may
);
2041 isl_flow_free(flow
);
2044 /* Check that the dependence analysis proceeds without errors.
2045 * Earlier versions of isl would break down during the analysis
2046 * due to the use of the wrong spaces.
2048 static int test_flow(isl_ctx
*ctx
)
2051 isl_union_map
*access
, *schedule
;
2052 isl_union_map
*must_dep
, *may_dep
;
2055 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
2056 access
= isl_union_map_read_from_str(ctx
, str
);
2057 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
2058 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
2059 "S2[] -> [1,0,0,0]; "
2060 "S3[] -> [-1,0,0,0] }";
2061 schedule
= isl_union_map_read_from_str(ctx
, str
);
2062 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
2063 isl_union_map_copy(access
), schedule
,
2064 &must_dep
, &may_dep
, NULL
, NULL
);
2065 isl_union_map_free(may_dep
);
2066 isl_union_map_free(must_dep
);
2071 int test_sv(isl_ctx
*ctx
)
2075 isl_union_map
*umap
;
2078 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
2079 map
= isl_map_read_from_str(ctx
, str
);
2080 sv
= isl_map_is_single_valued(map
);
2085 isl_die(ctx
, isl_error_internal
,
2086 "map not detected as single valued", return -1);
2088 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
2089 map
= isl_map_read_from_str(ctx
, str
);
2090 sv
= isl_map_is_single_valued(map
);
2095 isl_die(ctx
, isl_error_internal
,
2096 "map detected as single valued", return -1);
2098 str
= "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
2099 umap
= isl_union_map_read_from_str(ctx
, str
);
2100 sv
= isl_union_map_is_single_valued(umap
);
2101 isl_union_map_free(umap
);
2105 isl_die(ctx
, isl_error_internal
,
2106 "map not detected as single valued", return -1);
2108 str
= "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
2109 umap
= isl_union_map_read_from_str(ctx
, str
);
2110 sv
= isl_union_map_is_single_valued(umap
);
2111 isl_union_map_free(umap
);
2115 isl_die(ctx
, isl_error_internal
,
2116 "map detected as single valued", return -1);
2121 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
2125 map
= isl_map_read_from_str(ctx
, str
);
2127 assert(isl_map_is_bijective(map
));
2129 assert(!isl_map_is_bijective(map
));
2133 void test_bijective(struct isl_ctx
*ctx
)
2135 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
2136 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
2137 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
2138 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
2139 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
2140 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
2141 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
2142 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
2143 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
2144 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
2145 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
2146 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
2147 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
2150 static int test_pwqp(struct isl_ctx
*ctx
)
2154 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
2157 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2158 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2160 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
2163 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2164 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2166 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2168 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2170 isl_pw_qpolynomial_free(pwqp1
);
2172 str
= "{ [i] -> i }";
2173 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2174 str
= "{ [k] : exists a : k = 2a }";
2175 set
= isl_set_read_from_str(ctx
, str
);
2176 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2177 str
= "{ [i] -> i }";
2178 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2180 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2182 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2184 isl_pw_qpolynomial_free(pwqp1
);
2186 str
= "{ [i] -> i + [ (i + [i/3])/2 ] }";
2187 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2189 set
= isl_set_read_from_str(ctx
, str
);
2190 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2191 str
= "{ [i] -> 16 }";
2192 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2194 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2196 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2198 isl_pw_qpolynomial_free(pwqp1
);
2200 str
= "{ [i] -> ([(i)/2]) }";
2201 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2202 str
= "{ [k] : exists a : k = 2a+1 }";
2203 set
= isl_set_read_from_str(ctx
, str
);
2204 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2205 str
= "{ [i] -> -1/2 + 1/2 * i }";
2206 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2208 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2210 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2212 isl_pw_qpolynomial_free(pwqp1
);
2214 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
2215 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2216 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
2217 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2219 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2221 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2223 isl_pw_qpolynomial_free(pwqp1
);
2225 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
2226 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2227 str
= "{ [x] -> x }";
2228 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2230 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2232 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2234 isl_pw_qpolynomial_free(pwqp1
);
2236 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
2237 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2238 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2239 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
2240 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2241 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2242 isl_pw_qpolynomial_free(pwqp1
);
2244 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
2245 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2246 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2247 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2248 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
2249 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
2250 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2251 isl_pw_qpolynomial_free(pwqp1
);
2252 isl_pw_qpolynomial_free(pwqp2
);
2256 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2258 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
2259 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2260 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2261 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2262 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
2264 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2265 isl_pw_qpolynomial_free(pwqp1
);
2266 isl_pw_qpolynomial_free(pwqp2
);
2270 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2275 void test_split_periods(isl_ctx
*ctx
)
2278 isl_pw_qpolynomial
*pwqp
;
2280 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
2281 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
2282 "U >= 0; [U,V] -> U^2 : U >= 100 }";
2283 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2285 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
2288 isl_pw_qpolynomial_free(pwqp
);
2291 void test_union(isl_ctx
*ctx
)
2294 isl_union_set
*uset1
, *uset2
;
2295 isl_union_map
*umap1
, *umap2
;
2297 str
= "{ [i] : 0 <= i <= 1 }";
2298 uset1
= isl_union_set_read_from_str(ctx
, str
);
2299 str
= "{ [1] -> [0] }";
2300 umap1
= isl_union_map_read_from_str(ctx
, str
);
2302 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
2303 assert(isl_union_map_is_equal(umap1
, umap2
));
2305 isl_union_map_free(umap1
);
2306 isl_union_map_free(umap2
);
2308 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
2309 umap1
= isl_union_map_read_from_str(ctx
, str
);
2310 str
= "{ A[i]; B[i] }";
2311 uset1
= isl_union_set_read_from_str(ctx
, str
);
2313 uset2
= isl_union_map_domain(umap1
);
2315 assert(isl_union_set_is_equal(uset1
, uset2
));
2317 isl_union_set_free(uset1
);
2318 isl_union_set_free(uset2
);
2321 void test_bound(isl_ctx
*ctx
)
2324 isl_pw_qpolynomial
*pwqp
;
2325 isl_pw_qpolynomial_fold
*pwf
;
2327 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
2328 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2329 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2330 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 4);
2331 isl_pw_qpolynomial_fold_free(pwf
);
2333 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
2334 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2335 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2336 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 1);
2337 isl_pw_qpolynomial_fold_free(pwf
);
2340 void test_lift(isl_ctx
*ctx
)
2343 isl_basic_map
*bmap
;
2344 isl_basic_set
*bset
;
2346 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
2347 bset
= isl_basic_set_read_from_str(ctx
, str
);
2348 bset
= isl_basic_set_lift(bset
);
2349 bmap
= isl_basic_map_from_range(bset
);
2350 bset
= isl_basic_map_domain(bmap
);
2351 isl_basic_set_free(bset
);
2358 } subset_tests
[] = {
2360 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
2361 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
2362 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
2364 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
2365 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
2366 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
2367 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
2368 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
2369 "256e0 <= 255i and 256e0 >= -255 + 255i and "
2370 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
2371 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
2372 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
2373 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
2374 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
2375 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
2376 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
2377 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
2378 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
2379 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
2380 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
2381 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
2382 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
2383 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
2384 "4e0 <= -57 + i0 + i1)) or "
2385 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
2386 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
2387 "4e0 >= -61 + i0 + i1)) or "
2388 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
2391 static int test_subset(isl_ctx
*ctx
)
2394 isl_set
*set1
, *set2
;
2397 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
2398 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
2399 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
2400 subset
= isl_set_is_subset(set1
, set2
);
2405 if (subset
!= subset_tests
[i
].subset
)
2406 isl_die(ctx
, isl_error_unknown
,
2407 "incorrect subset result", return -1);
2414 const char *minuend
;
2415 const char *subtrahend
;
2416 const char *difference
;
2417 } subtract_domain_tests
[] = {
2418 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
2419 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
2420 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
2423 static int test_subtract(isl_ctx
*ctx
)
2426 isl_union_map
*umap1
, *umap2
;
2427 isl_union_set
*uset
;
2430 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2431 umap1
= isl_union_map_read_from_str(ctx
,
2432 subtract_domain_tests
[i
].minuend
);
2433 uset
= isl_union_set_read_from_str(ctx
,
2434 subtract_domain_tests
[i
].subtrahend
);
2435 umap2
= isl_union_map_read_from_str(ctx
,
2436 subtract_domain_tests
[i
].difference
);
2437 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
2438 equal
= isl_union_map_is_equal(umap1
, umap2
);
2439 isl_union_map_free(umap1
);
2440 isl_union_map_free(umap2
);
2444 isl_die(ctx
, isl_error_unknown
,
2445 "incorrect subtract domain result", return -1);
2451 int test_factorize(isl_ctx
*ctx
)
2454 isl_basic_set
*bset
;
2457 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2458 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2459 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2460 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2461 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2462 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2463 "3i5 >= -2i0 - i2 + 3i4 }";
2464 bset
= isl_basic_set_read_from_str(ctx
, str
);
2465 f
= isl_basic_set_factorizer(bset
);
2466 isl_basic_set_free(bset
);
2467 isl_factorizer_free(f
);
2469 isl_die(ctx
, isl_error_unknown
,
2470 "failed to construct factorizer", return -1);
2472 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2473 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2474 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2475 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2476 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2477 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2478 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2479 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2480 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2481 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2482 bset
= isl_basic_set_read_from_str(ctx
, str
);
2483 f
= isl_basic_set_factorizer(bset
);
2484 isl_basic_set_free(bset
);
2485 isl_factorizer_free(f
);
2487 isl_die(ctx
, isl_error_unknown
,
2488 "failed to construct factorizer", return -1);
2493 static int check_injective(__isl_take isl_map
*map
, void *user
)
2495 int *injective
= user
;
2497 *injective
= isl_map_is_injective(map
);
2500 if (*injective
< 0 || !*injective
)
2506 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
2507 const char *r
, const char *s
, int tilable
, int parallel
)
2511 isl_union_map
*W
, *R
, *S
;
2512 isl_union_map
*empty
;
2513 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
2514 isl_union_map
*validity
, *proximity
, *coincidence
;
2515 isl_union_map
*schedule
;
2516 isl_union_map
*test
;
2517 isl_union_set
*delta
;
2518 isl_union_set
*domain
;
2522 isl_schedule_constraints
*sc
;
2523 isl_schedule
*sched
;
2524 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
2526 D
= isl_union_set_read_from_str(ctx
, d
);
2527 W
= isl_union_map_read_from_str(ctx
, w
);
2528 R
= isl_union_map_read_from_str(ctx
, r
);
2529 S
= isl_union_map_read_from_str(ctx
, s
);
2531 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
2532 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
2534 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
2535 isl_union_map_compute_flow(isl_union_map_copy(R
),
2536 isl_union_map_copy(W
), empty
,
2537 isl_union_map_copy(S
),
2538 &dep_raw
, NULL
, NULL
, NULL
);
2539 isl_union_map_compute_flow(isl_union_map_copy(W
),
2540 isl_union_map_copy(W
),
2541 isl_union_map_copy(R
),
2542 isl_union_map_copy(S
),
2543 &dep_waw
, &dep_war
, NULL
, NULL
);
2545 dep
= isl_union_map_union(dep_waw
, dep_war
);
2546 dep
= isl_union_map_union(dep
, dep_raw
);
2547 validity
= isl_union_map_copy(dep
);
2548 coincidence
= isl_union_map_copy(dep
);
2549 proximity
= isl_union_map_copy(dep
);
2551 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
2552 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2553 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
2554 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2555 sched
= isl_schedule_constraints_compute_schedule(sc
);
2556 schedule
= isl_schedule_get_map(sched
);
2557 isl_schedule_free(sched
);
2558 isl_union_map_free(W
);
2559 isl_union_map_free(R
);
2560 isl_union_map_free(S
);
2563 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
2565 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
2566 is_complete
= isl_union_set_is_subset(D
, domain
);
2567 isl_union_set_free(D
);
2568 isl_union_set_free(domain
);
2570 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
2571 test
= isl_union_map_apply_range(test
, dep
);
2572 test
= isl_union_map_apply_range(test
, schedule
);
2574 delta
= isl_union_map_deltas(test
);
2575 if (isl_union_set_n_set(delta
) == 0) {
2579 isl_union_set_free(delta
);
2581 delta_set
= isl_set_from_union_set(delta
);
2583 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2584 for (i
= 0; i
< tilable
; ++i
)
2585 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
2586 is_tilable
= isl_set_is_subset(delta_set
, slice
);
2587 isl_set_free(slice
);
2589 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2590 for (i
= 0; i
< parallel
; ++i
)
2591 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
2592 is_parallel
= isl_set_is_subset(delta_set
, slice
);
2593 isl_set_free(slice
);
2595 origin
= isl_set_universe(isl_set_get_space(delta_set
));
2596 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
2597 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
2599 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
2600 delta_set
= isl_set_lexmin(delta_set
);
2602 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
2604 isl_set_free(origin
);
2605 isl_set_free(delta_set
);
2608 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
2609 is_injection
< 0 || is_complete
< 0)
2612 isl_die(ctx
, isl_error_unknown
,
2613 "generated schedule incomplete", return -1);
2615 isl_die(ctx
, isl_error_unknown
,
2616 "generated schedule not injective on each statement",
2619 isl_die(ctx
, isl_error_unknown
,
2620 "negative dependences in generated schedule",
2623 isl_die(ctx
, isl_error_unknown
,
2624 "generated schedule not as tilable as expected",
2627 isl_die(ctx
, isl_error_unknown
,
2628 "generated schedule not as parallel as expected",
2634 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
2635 const char *domain
, const char *validity
, const char *proximity
)
2639 isl_union_map
*prox
;
2640 isl_schedule_constraints
*sc
;
2641 isl_schedule
*schedule
;
2642 isl_union_map
*sched
;
2644 dom
= isl_union_set_read_from_str(ctx
, domain
);
2645 dep
= isl_union_map_read_from_str(ctx
, validity
);
2646 prox
= isl_union_map_read_from_str(ctx
, proximity
);
2647 sc
= isl_schedule_constraints_on_domain(dom
);
2648 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
2649 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
2650 schedule
= isl_schedule_constraints_compute_schedule(sc
);
2651 sched
= isl_schedule_get_map(schedule
);
2652 isl_schedule_free(schedule
);
2657 /* Check that a schedule can be constructed on the given domain
2658 * with the given validity and proximity constraints.
2660 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
2661 const char *validity
, const char *proximity
)
2663 isl_union_map
*sched
;
2665 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
2669 isl_union_map_free(sched
);
2673 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
2674 const char *validity
, const char *proximity
, const char *expected_sched
)
2676 isl_union_map
*sched1
, *sched2
;
2679 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
2680 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
2682 equal
= isl_union_map_is_equal(sched1
, sched2
);
2683 isl_union_map_free(sched1
);
2684 isl_union_map_free(sched2
);
2689 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
2695 /* Check that the schedule map is properly padded, even after being
2696 * reconstructed from the band forest.
2698 static int test_padded_schedule(isl_ctx
*ctx
)
2702 isl_union_map
*validity
, *proximity
;
2703 isl_schedule_constraints
*sc
;
2704 isl_schedule
*sched
;
2705 isl_union_map
*map1
, *map2
;
2706 isl_band_list
*list
;
2709 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
2710 D
= isl_union_set_read_from_str(ctx
, str
);
2711 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
2712 proximity
= isl_union_map_copy(validity
);
2713 sc
= isl_schedule_constraints_on_domain(D
);
2714 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2715 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2716 sched
= isl_schedule_constraints_compute_schedule(sc
);
2717 map1
= isl_schedule_get_map(sched
);
2718 list
= isl_schedule_get_band_forest(sched
);
2719 isl_band_list_free(list
);
2720 map2
= isl_schedule_get_map(sched
);
2721 isl_schedule_free(sched
);
2722 equal
= isl_union_map_is_equal(map1
, map2
);
2723 isl_union_map_free(map1
);
2724 isl_union_map_free(map2
);
2729 isl_die(ctx
, isl_error_unknown
,
2730 "reconstructed schedule map not the same as original",
2736 /* Input for testing of schedule construction based on
2737 * conditional constraints.
2739 * domain is the iteration domain
2740 * flow are the flow dependences, which determine the validity and
2741 * proximity constraints
2742 * condition are the conditions on the conditional validity constraints
2743 * conditional_validity are the conditional validity constraints
2744 * outer_band_n is the expected number of members in the outer band
2749 const char *condition
;
2750 const char *conditional_validity
;
2752 } live_range_tests
[] = {
2753 /* Contrived example that illustrates that we need to keep
2754 * track of tagged condition dependences and
2755 * tagged conditional validity dependences
2756 * in isl_sched_edge separately.
2757 * In particular, the conditional validity constraints on A
2758 * cannot be satisfied,
2759 * but they can be ignored because there are no corresponding
2760 * condition constraints. However, we do have an additional
2761 * conditional validity constraint that maps to the same
2762 * dependence relation
2763 * as the condition constraint on B. If we did not make a distinction
2764 * between tagged condition and tagged conditional validity
2765 * dependences, then we
2766 * could end up treating this shared dependence as an condition
2767 * constraint on A, forcing a localization of the conditions,
2768 * which is impossible.
2770 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
2771 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
2772 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
2773 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2774 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2775 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
2778 /* TACO 2013 Fig. 7 */
2779 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2780 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2781 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2782 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
2783 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
2784 "0 <= i < n and 0 <= j < n - 1 }",
2785 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
2786 "0 <= i < n and 0 <= j < j' < n;"
2787 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
2788 "0 <= i < i' < n and 0 <= j,j' < n;"
2789 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
2790 "0 <= i,j,j' < n and j < j' }",
2793 /* TACO 2013 Fig. 7, without tags */
2794 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2795 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2796 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2797 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2798 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2799 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
2800 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
2801 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
2804 /* TACO 2013 Fig. 12 */
2805 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
2806 "S3[i,3] : 0 <= i <= 1 }",
2807 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
2808 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
2809 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
2810 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
2811 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2812 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
2813 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2814 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
2815 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
2816 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
2817 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
2822 /* Test schedule construction based on conditional constraints.
2823 * In particular, check the number of members in the outer band
2824 * as an indication of whether tiling is possible or not.
2826 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
2829 isl_union_set
*domain
;
2830 isl_union_map
*condition
;
2831 isl_union_map
*flow
;
2832 isl_union_map
*validity
;
2833 isl_schedule_constraints
*sc
;
2834 isl_schedule
*schedule
;
2835 isl_band_list
*list
;
2839 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
2840 domain
= isl_union_set_read_from_str(ctx
,
2841 live_range_tests
[i
].domain
);
2842 flow
= isl_union_map_read_from_str(ctx
,
2843 live_range_tests
[i
].flow
);
2844 condition
= isl_union_map_read_from_str(ctx
,
2845 live_range_tests
[i
].condition
);
2846 validity
= isl_union_map_read_from_str(ctx
,
2847 live_range_tests
[i
].conditional_validity
);
2848 sc
= isl_schedule_constraints_on_domain(domain
);
2849 sc
= isl_schedule_constraints_set_validity(sc
,
2850 isl_union_map_copy(flow
));
2851 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
2852 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
2853 condition
, validity
);
2854 schedule
= isl_schedule_constraints_compute_schedule(sc
);
2855 list
= isl_schedule_get_band_forest(schedule
);
2856 band
= isl_band_list_get_band(list
, 0);
2857 n_member
= isl_band_n_member(band
);
2858 isl_band_free(band
);
2859 isl_band_list_free(list
);
2860 isl_schedule_free(schedule
);
2864 if (n_member
!= live_range_tests
[i
].outer_band_n
)
2865 isl_die(ctx
, isl_error_unknown
,
2866 "unexpected number of members in outer band",
2872 int test_schedule(isl_ctx
*ctx
)
2874 const char *D
, *W
, *R
, *V
, *P
, *S
;
2876 /* Handle resulting schedule with zero bands. */
2877 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
2881 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2882 W
= "{ S1[t,i] -> a[t,i] }";
2883 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2884 "S1[t,i] -> a[t-1,i+1] }";
2885 S
= "{ S1[t,i] -> [t,i] }";
2886 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2889 /* Fig. 5 of CC2008 */
2890 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2892 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2893 "j >= 2 and j <= -1 + N }";
2894 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2895 "j >= 2 and j <= -1 + N; "
2896 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2897 "j >= 2 and j <= -1 + N }";
2898 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2899 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2902 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2903 W
= "{ S1[i] -> a[i] }";
2904 R
= "{ S2[i] -> a[i+1] }";
2905 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2906 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2909 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2910 W
= "{ S1[i] -> a[i] }";
2911 R
= "{ S2[i] -> a[9-i] }";
2912 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2913 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2916 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2917 W
= "{ S1[i] -> a[i] }";
2918 R
= "[N] -> { S2[i] -> a[N-1-i] }";
2919 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2920 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2923 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2924 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2925 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2926 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2927 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2930 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2931 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2932 R
= "{ S2[i,j] -> a[i-1,j] }";
2933 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2934 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2937 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2938 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2939 R
= "{ S2[i,j] -> a[i,j-1] }";
2940 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2941 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2944 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2945 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2946 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2947 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2948 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2949 "S_0[] -> [0, 0, 0] }";
2950 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
2952 ctx
->opt
->schedule_parametric
= 0;
2953 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2955 ctx
->opt
->schedule_parametric
= 1;
2957 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2958 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2959 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2960 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2961 "S4[i] -> a[i,N] }";
2962 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2963 "S4[i] -> [4,i,0] }";
2964 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2967 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2968 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2970 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2972 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2974 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2975 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2978 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2979 " S_2[t] : t >= 0 and t <= -1 + N; "
2980 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2982 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2983 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2984 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2985 "i >= 0 and i <= -1 + N }";
2986 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2987 "i >= 0 and i <= -1 + N; "
2988 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2989 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2990 " S_0[t] -> [0, t, 0] }";
2992 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2994 ctx
->opt
->schedule_parametric
= 0;
2995 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2997 ctx
->opt
->schedule_parametric
= 1;
2999 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
3000 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
3001 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
3004 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
3005 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
3006 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
3007 "j >= 0 and j <= -1 + N; "
3008 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3009 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
3010 "j >= 0 and j <= -1 + N; "
3011 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3012 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
3013 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3016 D
= "{ S_0[i] : i >= 0 }";
3017 W
= "{ S_0[i] -> a[i] : i >= 0 }";
3018 R
= "{ S_0[i] -> a[0] : i >= 0 }";
3019 S
= "{ S_0[i] -> [0, i, 0] }";
3020 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3023 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
3024 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
3025 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
3026 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
3027 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3030 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
3031 "k <= -1 + n and k >= 0 }";
3032 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
3033 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
3034 "k <= -1 + n and k >= 0; "
3035 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
3036 "k <= -1 + n and k >= 0; "
3037 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
3038 "k <= -1 + n and k >= 0 }";
3039 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
3040 ctx
->opt
->schedule_outer_coincidence
= 1;
3041 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3043 ctx
->opt
->schedule_outer_coincidence
= 0;
3045 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
3046 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
3047 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
3048 "Stmt_for_body24[i0, i1, 1, 0]:"
3049 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
3050 "Stmt_for_body7[i0, i1, i2]:"
3051 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
3054 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
3055 "Stmt_for_body24[1, i1, i2, i3]:"
3056 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
3058 "Stmt_for_body24[0, i1, i2, i3] -> "
3059 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
3060 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
3062 "Stmt_for_body24[0, i1, i2, i3] ->"
3063 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
3064 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
3065 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
3066 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
3067 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
3068 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
3069 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
3070 "i1 <= 6 and i1 >= 0;"
3071 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
3072 "Stmt_for_body7[i0, i1, i2] -> "
3073 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
3074 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
3075 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
3076 "Stmt_for_body7[i0, i1, i2] -> "
3077 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
3078 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
3079 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
3081 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
3082 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
3083 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
3085 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3088 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
3089 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
3090 "j >= 1 and j <= 7;"
3091 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
3092 "j >= 1 and j <= 8 }";
3094 S
= "{ S_0[i, j] -> [i + j, j] }";
3095 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3096 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3098 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3100 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
3101 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
3102 "j >= 0 and j <= -1 + i }";
3103 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
3104 "i <= -1 + N and j >= 0;"
3105 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
3108 S
= "{ S_0[i, j] -> [i, j] }";
3109 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3110 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3112 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3114 /* Test both algorithms on a case with only proximity dependences. */
3115 D
= "{ S[i,j] : 0 <= i <= 10 }";
3117 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
3118 S
= "{ S[i, j] -> [j, i] }";
3119 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3120 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3122 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3123 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3126 D
= "{ A[a]; B[] }";
3128 P
= "{ A[a] -> B[] }";
3129 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3132 if (test_padded_schedule(ctx
) < 0)
3135 /* Check that check for progress is not confused by rational
3138 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
3139 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
3141 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
3142 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
3144 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3145 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3147 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3149 if (test_conditional_schedule_constraints(ctx
) < 0)
3155 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
3157 isl_union_map
*umap
;
3160 umap
= isl_union_map_read_from_str(ctx
, str
);
3161 test
= isl_union_map_plain_is_injective(umap
);
3162 isl_union_map_free(umap
);
3165 if (test
== injective
)
3168 isl_die(ctx
, isl_error_unknown
,
3169 "map not detected as injective", return -1);
3171 isl_die(ctx
, isl_error_unknown
,
3172 "map detected as injective", return -1);
3175 int test_injective(isl_ctx
*ctx
)
3179 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
3181 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
3183 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
3185 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
3187 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
3189 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
3191 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
3193 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
3196 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
3197 if (test_plain_injective(ctx
, str
, 1))
3199 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
3200 if (test_plain_injective(ctx
, str
, 0))
3206 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
3214 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
3215 equal
= isl_aff_plain_is_equal(aff
, aff2
);
3221 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
3225 equal
= aff_plain_is_equal(aff
, str
);
3229 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
3230 "result not as expected", return -1);
3235 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3236 __isl_take isl_aff
*aff2
);
3238 ['+'] = { &isl_aff_add
},
3239 ['-'] = { &isl_aff_sub
},
3240 ['*'] = { &isl_aff_mul
},
3241 ['/'] = { &isl_aff_div
},
3249 } aff_bin_tests
[] = {
3250 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
3251 "{ [i] -> [2i] }" },
3252 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
3254 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
3255 "{ [i] -> [2i] }" },
3256 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
3257 "{ [i] -> [2i] }" },
3258 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
3259 "{ [i] -> [i/2] }" },
3260 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
3262 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
3263 "{ [i] -> [NaN] }" },
3264 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
3265 "{ [i] -> [NaN] }" },
3266 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
3267 "{ [i] -> [NaN] }" },
3268 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
3269 "{ [i] -> [NaN] }" },
3270 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
3271 "{ [i] -> [NaN] }" },
3272 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
3273 "{ [i] -> [NaN] }" },
3274 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
3275 "{ [i] -> [NaN] }" },
3276 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
3277 "{ [i] -> [NaN] }" },
3278 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
3279 "{ [i] -> [NaN] }" },
3280 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
3281 "{ [i] -> [NaN] }" },
3282 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
3283 "{ [i] -> [NaN] }" },
3284 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
3285 "{ [i] -> [NaN] }" },
3288 /* Perform some basic tests of binary operations on isl_aff objects.
3290 static int test_bin_aff(isl_ctx
*ctx
)
3293 isl_aff
*aff1
, *aff2
, *res
;
3294 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3295 __isl_take isl_aff
*aff2
);
3298 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
3299 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
3300 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
3301 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
3302 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
3303 aff1
= fn(aff1
, aff2
);
3304 if (isl_aff_is_nan(res
))
3305 ok
= isl_aff_is_nan(aff1
);
3307 ok
= isl_aff_plain_is_equal(aff1
, res
);
3313 isl_die(ctx
, isl_error_unknown
,
3314 "unexpected result", return -1);
3320 int test_aff(isl_ctx
*ctx
)
3325 isl_local_space
*ls
;
3329 if (test_bin_aff(ctx
) < 0)
3332 space
= isl_space_set_alloc(ctx
, 0, 1);
3333 ls
= isl_local_space_from_space(space
);
3334 aff
= isl_aff_zero_on_domain(ls
);
3336 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3337 aff
= isl_aff_scale_down_ui(aff
, 3);
3338 aff
= isl_aff_floor(aff
);
3339 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3340 aff
= isl_aff_scale_down_ui(aff
, 2);
3341 aff
= isl_aff_floor(aff
);
3342 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3345 set
= isl_set_read_from_str(ctx
, str
);
3346 aff
= isl_aff_gist(aff
, set
);
3348 aff
= isl_aff_add_constant_si(aff
, -16);
3349 zero
= isl_aff_plain_is_zero(aff
);
3355 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3357 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
3358 aff
= isl_aff_scale_down_ui(aff
, 64);
3359 aff
= isl_aff_floor(aff
);
3360 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
3368 int test_dim_max(isl_ctx
*ctx
)
3372 isl_set
*set1
, *set2
;
3377 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
3378 set
= isl_set_read_from_str(ctx
, str
);
3379 pwaff
= isl_set_dim_max(set
, 0);
3380 set1
= isl_set_from_pw_aff(pwaff
);
3381 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
3382 set2
= isl_set_read_from_str(ctx
, str
);
3383 equal
= isl_set_is_equal(set1
, set2
);
3389 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3391 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
3392 set
= isl_set_read_from_str(ctx
, str
);
3393 pwaff
= isl_set_dim_max(set
, 0);
3394 set1
= isl_set_from_pw_aff(pwaff
);
3395 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3396 set2
= isl_set_read_from_str(ctx
, str
);
3397 equal
= isl_set_is_equal(set1
, set2
);
3403 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3405 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
3406 set
= isl_set_read_from_str(ctx
, str
);
3407 pwaff
= isl_set_dim_max(set
, 0);
3408 set1
= isl_set_from_pw_aff(pwaff
);
3409 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3410 set2
= isl_set_read_from_str(ctx
, str
);
3411 equal
= isl_set_is_equal(set1
, set2
);
3417 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3419 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
3420 "0 <= i < N and 0 <= j < M }";
3421 map
= isl_map_read_from_str(ctx
, str
);
3422 set
= isl_map_range(map
);
3424 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
3425 set1
= isl_set_from_pw_aff(pwaff
);
3426 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
3427 set2
= isl_set_read_from_str(ctx
, str
);
3428 equal
= isl_set_is_equal(set1
, set2
);
3432 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
3433 set1
= isl_set_from_pw_aff(pwaff
);
3434 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
3435 set2
= isl_set_read_from_str(ctx
, str
);
3436 if (equal
>= 0 && equal
)
3437 equal
= isl_set_is_equal(set1
, set2
);
3446 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3448 /* Check that solutions are properly merged. */
3449 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
3450 "c <= -1 + n - 4a - 2b and c >= -2b and "
3451 "4a >= -4 + n and c >= 0 }";
3452 set
= isl_set_read_from_str(ctx
, str
);
3453 pwaff
= isl_set_dim_min(set
, 2);
3454 set1
= isl_set_from_pw_aff(pwaff
);
3455 str
= "[n] -> { [(0)] : n >= 1 }";
3456 set2
= isl_set_read_from_str(ctx
, str
);
3457 equal
= isl_set_is_equal(set1
, set2
);
3464 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3466 /* Check that empty solution lie in the right space. */
3467 str
= "[n] -> { [t,a] : 1 = 0 }";
3468 set
= isl_set_read_from_str(ctx
, str
);
3469 pwaff
= isl_set_dim_max(set
, 0);
3470 set1
= isl_set_from_pw_aff(pwaff
);
3471 str
= "[n] -> { [t] : 1 = 0 }";
3472 set2
= isl_set_read_from_str(ctx
, str
);
3473 equal
= isl_set_is_equal(set1
, set2
);
3480 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3485 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
3487 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
3491 isl_pw_multi_aff
*pma2
;
3497 ctx
= isl_pw_multi_aff_get_ctx(pma
);
3498 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3499 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
3500 isl_pw_multi_aff_free(pma2
);
3505 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
3506 * represented by "str".
3508 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
3513 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
3517 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
3518 "result not as expected", return -1);
3522 /* Basic test for isl_pw_multi_aff_product.
3524 * Check that multiple pieces are properly handled.
3526 static int test_product_pma(isl_ctx
*ctx
)
3530 isl_pw_multi_aff
*pma1
, *pma2
;
3532 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
3533 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3534 str
= "{ C[] -> D[] }";
3535 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3536 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
3537 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
3538 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
3539 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
3540 isl_pw_multi_aff_free(pma1
);
3547 int test_product(isl_ctx
*ctx
)
3551 isl_union_set
*uset1
, *uset2
;
3555 set
= isl_set_read_from_str(ctx
, str
);
3556 set
= isl_set_product(set
, isl_set_copy(set
));
3557 ok
= isl_set_is_wrapping(set
);
3562 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3565 uset1
= isl_union_set_read_from_str(ctx
, str
);
3566 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
3567 str
= "{ [[] -> []] }";
3568 uset2
= isl_union_set_read_from_str(ctx
, str
);
3569 ok
= isl_union_set_is_equal(uset1
, uset2
);
3570 isl_union_set_free(uset1
);
3571 isl_union_set_free(uset2
);
3575 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3577 if (test_product_pma(ctx
) < 0)
3583 /* Check that two sets are not considered disjoint just because
3584 * they have a different set of (named) parameters.
3586 static int test_disjoint(isl_ctx
*ctx
)
3589 isl_set
*set
, *set2
;
3592 str
= "[n] -> { [[]->[]] }";
3593 set
= isl_set_read_from_str(ctx
, str
);
3594 str
= "{ [[]->[]] }";
3595 set2
= isl_set_read_from_str(ctx
, str
);
3596 disjoint
= isl_set_is_disjoint(set
, set2
);
3602 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3607 int test_equal(isl_ctx
*ctx
)
3610 isl_set
*set
, *set2
;
3614 set
= isl_set_read_from_str(ctx
, str
);
3616 set2
= isl_set_read_from_str(ctx
, str
);
3617 equal
= isl_set_is_equal(set
, set2
);
3623 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3628 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
3629 enum isl_dim_type type
, unsigned pos
, int fixed
)
3633 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
3640 isl_die(ctx
, isl_error_unknown
,
3641 "map not detected as fixed", return -1);
3643 isl_die(ctx
, isl_error_unknown
,
3644 "map detected as fixed", return -1);
3647 int test_fixed(isl_ctx
*ctx
)
3652 str
= "{ [i] -> [i] }";
3653 map
= isl_map_read_from_str(ctx
, str
);
3654 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
3656 str
= "{ [i] -> [1] }";
3657 map
= isl_map_read_from_str(ctx
, str
);
3658 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3660 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
3661 map
= isl_map_read_from_str(ctx
, str
);
3662 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3664 map
= isl_map_read_from_str(ctx
, str
);
3665 map
= isl_map_neg(map
);
3666 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3672 struct isl_vertices_test_data
{
3675 const char *vertex
[2];
3676 } vertices_tests
[] = {
3677 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
3678 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
3679 { "{ A[t, i] : t = 14 and i = 1 }",
3680 1, { "{ A[14, 1] }" } },
3683 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
3685 static int find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
3687 struct isl_vertices_test_data
*data
= user
;
3690 isl_basic_set
*bset
;
3691 isl_pw_multi_aff
*pma
;
3695 ctx
= isl_vertex_get_ctx(vertex
);
3696 bset
= isl_vertex_get_domain(vertex
);
3697 ma
= isl_vertex_get_expr(vertex
);
3698 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
3700 for (i
= 0; i
< data
->n
; ++i
) {
3701 isl_pw_multi_aff
*pma_i
;
3703 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
3704 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
3705 isl_pw_multi_aff_free(pma_i
);
3707 if (equal
< 0 || equal
)
3711 isl_pw_multi_aff_free(pma
);
3712 isl_vertex_free(vertex
);
3717 return equal
? 0 : - 1;
3720 int test_vertices(isl_ctx
*ctx
)
3724 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
3725 isl_basic_set
*bset
;
3726 isl_vertices
*vertices
;
3730 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
3731 vertices
= isl_basic_set_compute_vertices(bset
);
3732 n
= isl_vertices_get_n_vertices(vertices
);
3733 if (vertices_tests
[i
].n
!= n
)
3735 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
3736 &vertices_tests
[i
]) < 0)
3738 isl_vertices_free(vertices
);
3739 isl_basic_set_free(bset
);
3744 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
3751 int test_union_pw(isl_ctx
*ctx
)
3755 isl_union_set
*uset
;
3756 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
3758 str
= "{ [x] -> x^2 }";
3759 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
3760 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
3761 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
3762 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
3763 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
3764 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
3765 isl_union_pw_qpolynomial_free(upwqp1
);
3766 isl_union_pw_qpolynomial_free(upwqp2
);
3770 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3775 int test_output(isl_ctx
*ctx
)
3783 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
3784 pa
= isl_pw_aff_read_from_str(ctx
, str
);
3786 p
= isl_printer_to_str(ctx
);
3787 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
3788 p
= isl_printer_print_pw_aff(p
, pa
);
3789 s
= isl_printer_get_str(p
);
3790 isl_printer_free(p
);
3791 isl_pw_aff_free(pa
);
3795 equal
= !strcmp(s
, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
3800 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3805 int test_sample(isl_ctx
*ctx
)
3808 isl_basic_set
*bset1
, *bset2
;
3811 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
3812 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
3813 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
3814 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
3815 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
3816 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
3817 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
3818 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
3819 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
3820 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
3821 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
3822 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
3823 "d - 1073741821e and "
3824 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
3825 "3j >= 1 - a + b + 2e and "
3826 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
3827 "3i <= 4 - a + 4b - e and "
3828 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
3829 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
3830 "c <= -1 + a and 3i >= -2 - a + 3e and "
3831 "1073741822e <= 1073741823 - a + 1073741822b + c and "
3832 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
3833 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
3834 "1073741823e >= 1 + 1073741823b - d and "
3835 "3i >= 1073741823b + c - 1073741823e - f and "
3836 "3i >= 1 + 2b + e + 3g }";
3837 bset1
= isl_basic_set_read_from_str(ctx
, str
);
3838 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
3839 empty
= isl_basic_set_is_empty(bset2
);
3840 subset
= isl_basic_set_is_subset(bset2
, bset1
);
3841 isl_basic_set_free(bset1
);
3842 isl_basic_set_free(bset2
);
3843 if (empty
< 0 || subset
< 0)
3846 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
3848 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
3853 int test_fixed_power(isl_ctx
*ctx
)
3861 str
= "{ [i] -> [i + 1] }";
3862 map
= isl_map_read_from_str(ctx
, str
);
3863 isl_int_set_si(exp
, 23);
3864 map
= isl_map_fixed_power(map
, exp
);
3865 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
3874 int test_slice(isl_ctx
*ctx
)
3880 str
= "{ [i] -> [j] }";
3881 map
= isl_map_read_from_str(ctx
, str
);
3882 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3883 equal
= map_check_equal(map
, "{ [i] -> [i] }");
3888 str
= "{ [i] -> [j] }";
3889 map
= isl_map_read_from_str(ctx
, str
);
3890 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3891 equal
= map_check_equal(map
, "{ [i] -> [j] }");
3896 str
= "{ [i] -> [j] }";
3897 map
= isl_map_read_from_str(ctx
, str
);
3898 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3899 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
3904 str
= "{ [i] -> [j] }";
3905 map
= isl_map_read_from_str(ctx
, str
);
3906 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3907 equal
= map_check_equal(map
, "{ [0] -> [j] }");
3912 str
= "{ [i] -> [j] }";
3913 map
= isl_map_read_from_str(ctx
, str
);
3914 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3915 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
3920 str
= "{ [i] -> [j] }";
3921 map
= isl_map_read_from_str(ctx
, str
);
3922 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3923 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
3931 int test_eliminate(isl_ctx
*ctx
)
3937 str
= "{ [i] -> [j] : i = 2j }";
3938 map
= isl_map_read_from_str(ctx
, str
);
3939 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
3940 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
3948 /* Check that isl_set_dim_residue_class detects that the values of j
3949 * in the set below are all odd and that it does not detect any spurious
3952 static int test_residue_class(isl_ctx
*ctx
)
3959 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
3960 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
3961 set
= isl_set_read_from_str(ctx
, str
);
3964 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
3966 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
3967 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
3976 int test_align_parameters(isl_ctx
*ctx
)
3980 isl_multi_aff
*ma1
, *ma2
;
3983 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
3984 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
3986 space
= isl_space_params_alloc(ctx
, 1);
3987 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
3988 ma1
= isl_multi_aff_align_params(ma1
, space
);
3990 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
3991 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
3993 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
3995 isl_multi_aff_free(ma1
);
3996 isl_multi_aff_free(ma2
);
4001 isl_die(ctx
, isl_error_unknown
,
4002 "result not as expected", return -1);
4007 static int test_list(isl_ctx
*ctx
)
4009 isl_id
*a
, *b
, *c
, *d
, *id
;
4013 a
= isl_id_alloc(ctx
, "a", NULL
);
4014 b
= isl_id_alloc(ctx
, "b", NULL
);
4015 c
= isl_id_alloc(ctx
, "c", NULL
);
4016 d
= isl_id_alloc(ctx
, "d", NULL
);
4018 list
= isl_id_list_alloc(ctx
, 4);
4019 list
= isl_id_list_add(list
, a
);
4020 list
= isl_id_list_add(list
, b
);
4021 list
= isl_id_list_add(list
, c
);
4022 list
= isl_id_list_add(list
, d
);
4023 list
= isl_id_list_drop(list
, 1, 1);
4025 if (isl_id_list_n_id(list
) != 3) {
4026 isl_id_list_free(list
);
4027 isl_die(ctx
, isl_error_unknown
,
4028 "unexpected number of elements in list", return -1);
4031 id
= isl_id_list_get_id(list
, 0);
4034 id
= isl_id_list_get_id(list
, 1);
4037 id
= isl_id_list_get_id(list
, 2);
4041 isl_id_list_free(list
);
4044 isl_die(ctx
, isl_error_unknown
,
4045 "unexpected elements in list", return -1);
4050 const char *set_conversion_tests
[] = {
4051 "[N] -> { [i] : N - 1 <= 2 i <= N }",
4052 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
4053 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4054 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4057 /* Check that converting from isl_set to isl_pw_multi_aff and back
4058 * to isl_set produces the original isl_set.
4060 static int test_set_conversion(isl_ctx
*ctx
)
4064 isl_set
*set1
, *set2
;
4065 isl_pw_multi_aff
*pma
;
4068 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
4069 str
= set_conversion_tests
[i
];
4070 set1
= isl_set_read_from_str(ctx
, str
);
4071 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
4072 set2
= isl_set_from_pw_multi_aff(pma
);
4073 equal
= isl_set_is_equal(set1
, set2
);
4080 isl_die(ctx
, isl_error_unknown
, "bad conversion",
4087 /* Check that converting from isl_map to isl_pw_multi_aff and back
4088 * to isl_map produces the original isl_map.
4090 static int test_map_conversion(isl_ctx
*ctx
)
4093 isl_map
*map1
, *map2
;
4094 isl_pw_multi_aff
*pma
;
4097 str
= "{ [a, b, c, d] -> s0[a, b, e, f] : "
4098 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
4099 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
4100 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
4102 map1
= isl_map_read_from_str(ctx
, str
);
4103 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
4104 map2
= isl_map_from_pw_multi_aff(pma
);
4105 equal
= isl_map_is_equal(map1
, map2
);
4112 isl_die(ctx
, isl_error_unknown
, "bad conversion", return -1);
4117 static int test_conversion(isl_ctx
*ctx
)
4119 if (test_set_conversion(ctx
) < 0)
4121 if (test_map_conversion(ctx
) < 0)
4126 /* Check that isl_basic_map_curry does not modify input.
4128 static int test_curry(isl_ctx
*ctx
)
4131 isl_basic_map
*bmap1
, *bmap2
;
4134 str
= "{ [A[] -> B[]] -> C[] }";
4135 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
4136 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
4137 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
4138 isl_basic_map_free(bmap1
);
4139 isl_basic_map_free(bmap2
);
4144 isl_die(ctx
, isl_error_unknown
,
4145 "curried map should not be equal to original",
4155 } preimage_tests
[] = {
4156 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
4157 "{ A[j,i] -> B[i,j] }",
4158 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
4159 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4160 "{ A[a,b] -> B[a/2,b/6] }",
4161 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
4162 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4163 "{ A[a,b] -> B[a/2,b/6] }",
4164 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
4165 "exists i,j : a = 2 i and b = 6 j }" },
4166 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
4167 "[n] -> { : 0 <= n <= 100 }" },
4168 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4169 "{ A[a] -> B[2a] }",
4170 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
4171 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4172 "{ A[a] -> B[([a/2])] }",
4173 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
4174 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
4175 "{ A[a] -> B[a,a,a/3] }",
4176 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
4177 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
4178 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
4181 static int test_preimage_basic_set(isl_ctx
*ctx
)
4184 isl_basic_set
*bset1
, *bset2
;
4188 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
4189 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
4190 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
4191 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
4192 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
4193 equal
= isl_basic_set_is_equal(bset1
, bset2
);
4194 isl_basic_set_free(bset1
);
4195 isl_basic_set_free(bset2
);
4199 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4210 } preimage_domain_tests
[] = {
4211 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
4212 "{ A[j,i] -> B[i,j] }",
4213 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
4214 { "{ B[i] -> C[i]; D[i] -> E[i] }",
4215 "{ A[i] -> B[i + 1] }",
4216 "{ A[i] -> C[i + 1] }" },
4217 { "{ B[i] -> C[i]; B[i] -> E[i] }",
4218 "{ A[i] -> B[i + 1] }",
4219 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
4220 { "{ B[i] -> C[([i/2])] }",
4221 "{ A[i] -> B[2i] }",
4222 "{ A[i] -> C[i] }" },
4223 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
4224 "{ A[i] -> B[([i/5]), ([i/7])] }",
4225 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
4226 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
4227 "[N] -> { A[] -> B[([N/5])] }",
4228 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
4229 { "{ B[i] -> C[i] : exists a : i = 5 a }",
4230 "{ A[i] -> B[2i] }",
4231 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
4232 { "{ B[i] -> C[i] : exists a : i = 2 a; "
4233 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
4234 "{ A[i] -> B[2i] }",
4235 "{ A[i] -> C[2i] }" },
4238 static int test_preimage_union_map(isl_ctx
*ctx
)
4241 isl_union_map
*umap1
, *umap2
;
4245 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
4246 umap1
= isl_union_map_read_from_str(ctx
,
4247 preimage_domain_tests
[i
].map
);
4248 ma
= isl_multi_aff_read_from_str(ctx
,
4249 preimage_domain_tests
[i
].ma
);
4250 umap2
= isl_union_map_read_from_str(ctx
,
4251 preimage_domain_tests
[i
].res
);
4252 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
4253 equal
= isl_union_map_is_equal(umap1
, umap2
);
4254 isl_union_map_free(umap1
);
4255 isl_union_map_free(umap2
);
4259 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4266 static int test_preimage(isl_ctx
*ctx
)
4268 if (test_preimage_basic_set(ctx
) < 0)
4270 if (test_preimage_union_map(ctx
) < 0)
4280 } pullback_tests
[] = {
4281 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
4282 "{ A[a,b] -> C[b + 2a] }" },
4283 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
4284 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
4285 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
4286 "{ A[a] -> C[(a)/6] }" },
4287 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
4288 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
4289 "{ A[a] -> C[(2a)/3] }" },
4290 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
4291 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
4292 "{ A[i,j] -> C[i + j, i + j] }"},
4293 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
4294 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
4295 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
4298 static int test_pullback(isl_ctx
*ctx
)
4301 isl_multi_aff
*ma1
, *ma2
;
4305 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
4306 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
4307 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
4308 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
4309 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
4310 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4311 isl_multi_aff_free(ma1
);
4312 isl_multi_aff_free(ma2
);
4316 isl_die(ctx
, isl_error_unknown
, "bad pullback",
4323 /* Check that negation is printed correctly.
4325 static int test_ast(isl_ctx
*ctx
)
4327 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
4331 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4332 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4333 expr
= isl_ast_expr_add(expr1
, expr2
);
4334 expr
= isl_ast_expr_neg(expr
);
4335 str
= isl_ast_expr_to_str(expr
);
4336 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
4338 isl_ast_expr_free(expr
);
4343 isl_die(ctx
, isl_error_unknown
,
4344 "isl_ast_expr printed incorrectly", return -1);
4346 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4347 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4348 expr
= isl_ast_expr_add(expr1
, expr2
);
4349 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
4350 expr
= isl_ast_expr_sub(expr3
, expr
);
4351 str
= isl_ast_expr_to_str(expr
);
4352 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
4354 isl_ast_expr_free(expr
);
4359 isl_die(ctx
, isl_error_unknown
,
4360 "isl_ast_expr printed incorrectly", return -1);
4365 /* Check that isl_ast_build_expr_from_set returns a valid expression
4366 * for an empty set. Note that isl_ast_build_expr_from_set getting
4367 * called on an empty set probably indicates a bug in the caller.
4369 static int test_ast_build(isl_ctx
*ctx
)
4372 isl_ast_build
*build
;
4375 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4376 build
= isl_ast_build_from_context(set
);
4378 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
4379 expr
= isl_ast_build_expr_from_set(build
, set
);
4381 isl_ast_expr_free(expr
);
4382 isl_ast_build_free(build
);
4390 /* Internal data structure for before_for and after_for callbacks.
4392 * depth is the current depth
4393 * before is the number of times before_for has been called
4394 * after is the number of times after_for has been called
4396 struct isl_test_codegen_data
{
4402 /* This function is called before each for loop in the AST generated
4403 * from test_ast_gen1.
4405 * Increment the number of calls and the depth.
4406 * Check that the space returned by isl_ast_build_get_schedule_space
4407 * matches the target space of the schedule returned by
4408 * isl_ast_build_get_schedule.
4409 * Return an isl_id that is checked by the corresponding call
4412 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
4415 struct isl_test_codegen_data
*data
= user
;
4418 isl_union_map
*schedule
;
4419 isl_union_set
*uset
;
4424 ctx
= isl_ast_build_get_ctx(build
);
4426 if (data
->before
>= 3)
4427 isl_die(ctx
, isl_error_unknown
,
4428 "unexpected number of for nodes", return NULL
);
4429 if (data
->depth
>= 2)
4430 isl_die(ctx
, isl_error_unknown
,
4431 "unexpected depth", return NULL
);
4433 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
4437 schedule
= isl_ast_build_get_schedule(build
);
4438 uset
= isl_union_map_range(schedule
);
4441 if (isl_union_set_n_set(uset
) != 1) {
4442 isl_union_set_free(uset
);
4443 isl_die(ctx
, isl_error_unknown
,
4444 "expecting single range space", return NULL
);
4447 space
= isl_ast_build_get_schedule_space(build
);
4448 set
= isl_union_set_extract_set(uset
, space
);
4449 isl_union_set_free(uset
);
4450 empty
= isl_set_is_empty(set
);
4456 isl_die(ctx
, isl_error_unknown
,
4457 "spaces don't match", return NULL
);
4459 return isl_id_alloc(ctx
, name
, NULL
);
4462 /* This function is called after each for loop in the AST generated
4463 * from test_ast_gen1.
4465 * Increment the number of calls and decrement the depth.
4466 * Check that the annotation attached to the node matches
4467 * the isl_id returned by the corresponding call to before_for.
4469 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
4470 __isl_keep isl_ast_build
*build
, void *user
)
4472 struct isl_test_codegen_data
*data
= user
;
4480 if (data
->after
> data
->before
)
4481 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4482 "mismatch in number of for nodes",
4483 return isl_ast_node_free(node
));
4485 id
= isl_ast_node_get_annotation(node
);
4487 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4488 "missing annotation", return isl_ast_node_free(node
));
4490 name
= isl_id_get_name(id
);
4491 valid
= name
&& atoi(name
+ 1) == data
->depth
;
4495 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4496 "wrong annotation", return isl_ast_node_free(node
));
4501 /* Check that the before_each_for and after_each_for callbacks
4502 * are called for each for loop in the generated code,
4503 * that they are called in the right order and that the isl_id
4504 * returned from the before_each_for callback is attached to
4505 * the isl_ast_node passed to the corresponding after_each_for call.
4507 static int test_ast_gen1(isl_ctx
*ctx
)
4511 isl_union_map
*schedule
;
4512 isl_ast_build
*build
;
4514 struct isl_test_codegen_data data
;
4516 str
= "[N] -> { : N >= 10 }";
4517 set
= isl_set_read_from_str(ctx
, str
);
4518 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
4519 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
4520 schedule
= isl_union_map_read_from_str(ctx
, str
);
4525 build
= isl_ast_build_from_context(set
);
4526 build
= isl_ast_build_set_before_each_for(build
,
4527 &before_for
, &data
);
4528 build
= isl_ast_build_set_after_each_for(build
,
4530 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4531 isl_ast_build_free(build
);
4535 isl_ast_node_free(tree
);
4537 if (data
.before
!= 3 || data
.after
!= 3)
4538 isl_die(ctx
, isl_error_unknown
,
4539 "unexpected number of for nodes", return -1);
4544 /* Check that the AST generator handles domains that are integrally disjoint
4545 * but not ratinoally disjoint.
4547 static int test_ast_gen2(isl_ctx
*ctx
)
4551 isl_union_map
*schedule
;
4552 isl_union_map
*options
;
4553 isl_ast_build
*build
;
4556 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
4557 schedule
= isl_union_map_read_from_str(ctx
, str
);
4558 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4559 build
= isl_ast_build_from_context(set
);
4561 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
4562 options
= isl_union_map_read_from_str(ctx
, str
);
4563 build
= isl_ast_build_set_options(build
, options
);
4564 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4565 isl_ast_build_free(build
);
4568 isl_ast_node_free(tree
);
4573 /* Increment *user on each call.
4575 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
4576 __isl_keep isl_ast_build
*build
, void *user
)
4585 /* Test that unrolling tries to minimize the number of instances.
4586 * In particular, for the schedule given below, make sure it generates
4587 * 3 nodes (rather than 101).
4589 static int test_ast_gen3(isl_ctx
*ctx
)
4593 isl_union_map
*schedule
;
4594 isl_union_map
*options
;
4595 isl_ast_build
*build
;
4599 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
4600 schedule
= isl_union_map_read_from_str(ctx
, str
);
4601 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4603 str
= "{ [i] -> unroll[0] }";
4604 options
= isl_union_map_read_from_str(ctx
, str
);
4606 build
= isl_ast_build_from_context(set
);
4607 build
= isl_ast_build_set_options(build
, options
);
4608 build
= isl_ast_build_set_at_each_domain(build
,
4609 &count_domains
, &n_domain
);
4610 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4611 isl_ast_build_free(build
);
4615 isl_ast_node_free(tree
);
4618 isl_die(ctx
, isl_error_unknown
,
4619 "unexpected number of for nodes", return -1);
4624 /* Check that if the ast_build_exploit_nested_bounds options is set,
4625 * we do not get an outer if node in the generated AST,
4626 * while we do get such an outer if node if the options is not set.
4628 static int test_ast_gen4(isl_ctx
*ctx
)
4632 isl_union_map
*schedule
;
4633 isl_ast_build
*build
;
4635 enum isl_ast_node_type type
;
4638 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
4639 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
4641 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
4643 schedule
= isl_union_map_read_from_str(ctx
, str
);
4644 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4645 build
= isl_ast_build_from_context(set
);
4646 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4647 isl_ast_build_free(build
);
4651 type
= isl_ast_node_get_type(tree
);
4652 isl_ast_node_free(tree
);
4654 if (type
== isl_ast_node_if
)
4655 isl_die(ctx
, isl_error_unknown
,
4656 "not expecting if node", return -1);
4658 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
4660 schedule
= isl_union_map_read_from_str(ctx
, str
);
4661 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4662 build
= isl_ast_build_from_context(set
);
4663 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4664 isl_ast_build_free(build
);
4668 type
= isl_ast_node_get_type(tree
);
4669 isl_ast_node_free(tree
);
4671 if (type
!= isl_ast_node_if
)
4672 isl_die(ctx
, isl_error_unknown
,
4673 "expecting if node", return -1);
4675 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
4680 /* This function is called for each leaf in the AST generated
4681 * from test_ast_gen5.
4683 * We finalize the AST generation by extending the outer schedule
4684 * with a zero-dimensional schedule. If this results in any for loops,
4685 * then this means that we did not pass along enough information
4686 * about the outer schedule to the inner AST generation.
4688 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
4691 isl_union_map
*schedule
, *extra
;
4694 schedule
= isl_ast_build_get_schedule(build
);
4695 extra
= isl_union_map_copy(schedule
);
4696 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
4697 schedule
= isl_union_map_range_product(schedule
, extra
);
4698 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4699 isl_ast_build_free(build
);
4704 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
4705 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
4706 "code should not contain any for loop",
4707 return isl_ast_node_free(tree
));
4712 /* Check that we do not lose any information when going back and
4713 * forth between internal and external schedule.
4715 * In particular, we create an AST where we unroll the only
4716 * non-constant dimension in the schedule. We therefore do
4717 * not expect any for loops in the AST. However, older versions
4718 * of isl would not pass along enough information about the outer
4719 * schedule when performing an inner code generation from a create_leaf
4720 * callback, resulting in the inner code generation producing a for loop.
4722 static int test_ast_gen5(isl_ctx
*ctx
)
4726 isl_union_map
*schedule
, *options
;
4727 isl_ast_build
*build
;
4730 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
4731 schedule
= isl_union_map_read_from_str(ctx
, str
);
4733 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
4734 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
4735 options
= isl_union_map_read_from_str(ctx
, str
);
4737 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4738 build
= isl_ast_build_from_context(set
);
4739 build
= isl_ast_build_set_options(build
, options
);
4740 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
4741 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4742 isl_ast_build_free(build
);
4743 isl_ast_node_free(tree
);
4750 static int test_ast_gen(isl_ctx
*ctx
)
4752 if (test_ast_gen1(ctx
) < 0)
4754 if (test_ast_gen2(ctx
) < 0)
4756 if (test_ast_gen3(ctx
) < 0)
4758 if (test_ast_gen4(ctx
) < 0)
4760 if (test_ast_gen5(ctx
) < 0)
4765 /* Check if dropping output dimensions from an isl_pw_multi_aff
4768 static int test_pw_multi_aff(isl_ctx
*ctx
)
4771 isl_pw_multi_aff
*pma1
, *pma2
;
4774 str
= "{ [i,j] -> [i+j, 4i-j] }";
4775 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4776 str
= "{ [i,j] -> [4i-j] }";
4777 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4779 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
4781 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
4783 isl_pw_multi_aff_free(pma1
);
4784 isl_pw_multi_aff_free(pma2
);
4788 isl_die(ctx
, isl_error_unknown
,
4789 "expressions not equal", return -1);
4794 /* Check that we can properly parse multi piecewise affine expressions
4795 * where the piecewise affine expressions have different domains.
4797 static int test_multi_pw_aff(isl_ctx
*ctx
)
4800 isl_set
*dom
, *dom2
;
4801 isl_multi_pw_aff
*mpa1
, *mpa2
;
4806 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
4807 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
4808 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
4809 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
4810 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
4811 str
= "{ [i] -> [(i : i > 0), 2i] }";
4812 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
4814 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
4816 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
4817 dom
= isl_pw_aff_domain(pa
);
4818 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
4819 dom2
= isl_pw_aff_domain(pa
);
4820 equal_domain
= isl_set_is_equal(dom
, dom2
);
4824 isl_multi_pw_aff_free(mpa1
);
4825 isl_multi_pw_aff_free(mpa2
);
4830 isl_die(ctx
, isl_error_unknown
,
4831 "expressions not equal", return -1);
4833 if (equal_domain
< 0)
4836 isl_die(ctx
, isl_error_unknown
,
4837 "domains unexpectedly equal", return -1);
4842 /* This is a regression test for a bug where isl_basic_map_simplify
4843 * would end up in an infinite loop. In particular, we construct
4844 * an empty basic set that is not obviously empty.
4845 * isl_basic_set_is_empty marks the basic set as empty.
4846 * After projecting out i3, the variable can be dropped completely,
4847 * but isl_basic_map_simplify refrains from doing so if the basic set
4848 * is empty and would end up in an infinite loop if it didn't test
4849 * explicitly for empty basic maps in the outer loop.
4851 static int test_simplify(isl_ctx
*ctx
)
4854 isl_basic_set
*bset
;
4857 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
4858 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
4859 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
4861 bset
= isl_basic_set_read_from_str(ctx
, str
);
4862 empty
= isl_basic_set_is_empty(bset
);
4863 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
4864 isl_basic_set_free(bset
);
4868 isl_die(ctx
, isl_error_unknown
,
4869 "basic set should be empty", return -1);
4874 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
4875 * with gbr context would fail to disable the use of the shifted tableau
4876 * when transferring equalities for the input to the context, resulting
4877 * in invalid sample values.
4879 static int test_partial_lexmin(isl_ctx
*ctx
)
4882 isl_basic_set
*bset
;
4883 isl_basic_map
*bmap
;
4886 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
4887 bmap
= isl_basic_map_read_from_str(ctx
, str
);
4888 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
4889 bset
= isl_basic_set_read_from_str(ctx
, str
);
4890 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
4899 /* Check that the variable compression performed on the existentially
4900 * quantified variables inside isl_basic_set_compute_divs is not confused
4901 * by the implicit equalities among the parameters.
4903 static int test_compute_divs(isl_ctx
*ctx
)
4906 isl_basic_set
*bset
;
4909 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
4910 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
4911 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
4912 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
4913 bset
= isl_basic_set_read_from_str(ctx
, str
);
4914 set
= isl_basic_set_compute_divs(bset
);
4926 { "{ rat: [i] : 0 <= i <= 10 }",
4927 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
4928 { "{ rat: [i] : FALSE }",
4929 "{ rat: coefficients[[cst] -> [a]] }" },
4931 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
4938 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
4939 "{ rat: [i] : 0 <= i <= 10 }" },
4940 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
4942 { "{ rat: coefficients[[cst] -> [a]] }",
4943 "{ rat: [i] : FALSE }" },
4946 /* Test the basic functionality of isl_basic_set_coefficients and
4947 * isl_basic_set_solutions.
4949 static int test_dual(isl_ctx
*ctx
)
4953 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
4955 isl_basic_set
*bset1
, *bset2
;
4957 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
4958 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
4959 bset1
= isl_basic_set_coefficients(bset1
);
4960 equal
= isl_basic_set_is_equal(bset1
, bset2
);
4961 isl_basic_set_free(bset1
);
4962 isl_basic_set_free(bset2
);
4966 isl_die(ctx
, isl_error_unknown
,
4967 "incorrect dual", return -1);
4970 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
4972 isl_basic_set
*bset1
, *bset2
;
4974 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
4975 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
4976 bset1
= isl_basic_set_solutions(bset1
);
4977 equal
= isl_basic_set_is_equal(bset1
, bset2
);
4978 isl_basic_set_free(bset1
);
4979 isl_basic_set_free(bset2
);
4983 isl_die(ctx
, isl_error_unknown
,
4984 "incorrect dual", return -1);
4992 int (*fn
)(isl_ctx
*ctx
);
4994 { "dual", &test_dual
},
4995 { "dependence analysis", &test_flow
},
4996 { "val", &test_val
},
4997 { "compute divs", &test_compute_divs
},
4998 { "partial lexmin", &test_partial_lexmin
},
4999 { "simplify", &test_simplify
},
5000 { "curry", &test_curry
},
5001 { "piecewise multi affine expressions", &test_pw_multi_aff
},
5002 { "multi piecewise affine expressions", &test_multi_pw_aff
},
5003 { "conversion", &test_conversion
},
5004 { "list", &test_list
},
5005 { "align parameters", &test_align_parameters
},
5006 { "preimage", &test_preimage
},
5007 { "pullback", &test_pullback
},
5008 { "AST", &test_ast
},
5009 { "AST build", &test_ast_build
},
5010 { "AST generation", &test_ast_gen
},
5011 { "eliminate", &test_eliminate
},
5012 { "residue class", &test_residue_class
},
5013 { "div", &test_div
},
5014 { "slice", &test_slice
},
5015 { "fixed power", &test_fixed_power
},
5016 { "sample", &test_sample
},
5017 { "output", &test_output
},
5018 { "vertices", &test_vertices
},
5019 { "fixed", &test_fixed
},
5020 { "equal", &test_equal
},
5021 { "disjoint", &test_disjoint
},
5022 { "product", &test_product
},
5023 { "dim_max", &test_dim_max
},
5024 { "affine", &test_aff
},
5025 { "injective", &test_injective
},
5026 { "schedule", &test_schedule
},
5027 { "union_pw", &test_union_pw
},
5028 { "parse", &test_parse
},
5029 { "single-valued", &test_sv
},
5030 { "affine hull", &test_affine_hull
},
5031 { "coalesce", &test_coalesce
},
5032 { "factorize", &test_factorize
},
5033 { "subset", &test_subset
},
5034 { "subtract", &test_subtract
},
5035 { "lexmin", &test_lexmin
},
5036 { "min", &test_min
},
5037 { "gist", &test_gist
},
5038 { "piecewise quasi-polynomials", &test_pwqp
},
5044 struct isl_ctx
*ctx
;
5046 srcdir
= getenv("srcdir");
5049 ctx
= isl_ctx_alloc();
5050 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
5051 printf("%s\n", tests
[i
].name
);
5052 if (tests
[i
].fn(ctx
) < 0)
5058 test_split_periods(ctx
);
5060 test_bijective(ctx
);
5064 test_construction(ctx
);
5066 test_application(ctx
);
5067 test_convex_hull(ctx
);