2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
5 * Copyright 2014 INRIA Rocquencourt
7 * Use of this software is governed by the MIT license
9 * Written by Sven Verdoolaege, K.U.Leuven, Departement
10 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
11 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
12 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
14 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
15 * B.P. 105 - 78153 Le Chesnay, France
21 #include <isl_ctx_private.h>
22 #include <isl_map_private.h>
23 #include <isl_aff_private.h>
26 #include <isl_constraint_private.h>
27 #include <isl/polynomial.h>
28 #include <isl/union_map.h>
29 #include <isl_factorization.h>
30 #include <isl/schedule.h>
31 #include <isl_options_private.h>
32 #include <isl/vertices.h>
33 #include <isl/ast_build.h>
36 #include <isl_ast_build_expr.h>
38 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
42 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
45 char *pattern
= "%s/test_inputs/%s.%s";
47 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
49 filename
= isl_alloc_array(ctx
, char, length
);
54 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
59 void test_parse_map(isl_ctx
*ctx
, const char *str
)
63 map
= isl_map_read_from_str(ctx
, str
);
68 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
73 map
= isl_map_read_from_str(ctx
, str
);
74 map2
= isl_map_read_from_str(ctx
, str2
);
75 equal
= isl_map_is_equal(map
, map2
);
82 isl_die(ctx
, isl_error_unknown
, "maps not equal",
88 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
90 isl_pw_qpolynomial
*pwqp
;
92 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
94 isl_pw_qpolynomial_free(pwqp
);
97 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
101 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
103 isl_pw_aff_free(pwaff
);
106 int test_parse(struct isl_ctx
*ctx
)
109 const char *str
, *str2
;
111 str
= "{ [i] -> [-i] }";
112 map
= isl_map_read_from_str(ctx
, str
);
116 str
= "{ A[i] -> L[([i/3])] }";
117 map
= isl_map_read_from_str(ctx
, str
);
121 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
122 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
123 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
125 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
126 str2
= "{ [x, y] : 2y >= 6 - x }";
127 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
130 if (test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
131 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
133 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
134 if (test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }",
138 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
139 map
= isl_map_read_from_str(ctx
, str
);
140 str
= "{ [new, old] -> [o0, o1] : "
141 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
142 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
143 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
144 map2
= isl_map_read_from_str(ctx
, str
);
145 assert(isl_map_is_equal(map
, map2
));
149 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
150 map
= isl_map_read_from_str(ctx
, str
);
151 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
152 map2
= isl_map_read_from_str(ctx
, str
);
153 assert(isl_map_is_equal(map
, map2
));
157 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
158 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
159 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
162 str
= "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
163 str2
= "{ [i,j] -> [min(i,j)] }";
164 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
167 str
= "{ [i,j] : i != j }";
168 str2
= "{ [i,j] : i < j or i > j }";
169 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
172 str
= "{ [i,j] : (i+1)*2 >= j }";
173 str2
= "{ [i, j] : j <= 2 + 2i }";
174 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
177 str
= "{ [i] -> [i > 0 ? 4 : 5] }";
178 str2
= "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
179 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
182 str
= "[N=2,M] -> { [i=[(M+N)/4]] }";
183 str2
= "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
184 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
187 str
= "{ [x] : x >= 0 }";
188 str2
= "{ [x] : x-0 >= 0 }";
189 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
192 str
= "{ [i] : ((i > 10)) }";
193 str2
= "{ [i] : i >= 11 }";
194 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
197 str
= "{ [i] -> [0] }";
198 str2
= "{ [i] -> [0 * i] }";
199 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
202 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
203 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
204 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
205 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
207 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : (not false) }",
208 "{ [a] -> [b] : true }") < 0)
211 if (test_parse_map_equal(ctx
, "{ [i] : i/2 <= 5 }",
212 "{ [i] : i <= 10 }") < 0)
215 if (test_parse_map_equal(ctx
, "{Sym=[n] [i] : i <= n }",
216 "[n] -> { [i] : i <= n }") < 0)
219 if (test_parse_map_equal(ctx
, "{ [*] }", "{ [a] }") < 0)
222 if (test_parse_map_equal(ctx
, "{ [i] : 2*floor(i/2) = i }",
223 "{ [i] : exists a : i = 2 a }") < 0)
226 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : a = 5 implies b = 5 }",
227 "{ [a] -> [b] : a != 5 or b = 5 }") < 0)
230 if (test_parse_map_equal(ctx
, "{ [a] -> [a - 1 : a > 0] }",
231 "{ [a] -> [a - 1] : a > 0 }") < 0)
233 if (test_parse_map_equal(ctx
,
234 "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
235 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }") < 0)
237 if (test_parse_map_equal(ctx
,
238 "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
239 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
241 if (test_parse_map_equal(ctx
,
242 "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
243 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
245 if (test_parse_map_equal(ctx
,
246 "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
247 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
249 if (test_parse_map_equal(ctx
,
250 "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
251 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
257 void test_read(struct isl_ctx
*ctx
)
261 struct isl_basic_set
*bset1
, *bset2
;
262 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
264 filename
= get_filename(ctx
, "set", "omega");
266 input
= fopen(filename
, "r");
269 bset1
= isl_basic_set_read_from_file(ctx
, input
);
270 bset2
= isl_basic_set_read_from_str(ctx
, str
);
272 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
274 isl_basic_set_free(bset1
);
275 isl_basic_set_free(bset2
);
281 void test_bounded(struct isl_ctx
*ctx
)
286 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
287 bounded
= isl_set_is_bounded(set
);
291 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
292 bounded
= isl_set_is_bounded(set
);
296 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
297 bounded
= isl_set_is_bounded(set
);
302 /* Construct the basic set { [i] : 5 <= i <= N } */
303 void test_construction(struct isl_ctx
*ctx
)
308 struct isl_basic_set
*bset
;
309 struct isl_constraint
*c
;
313 dim
= isl_space_set_alloc(ctx
, 1, 1);
314 bset
= isl_basic_set_universe(isl_space_copy(dim
));
315 ls
= isl_local_space_from_space(dim
);
317 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
318 isl_int_set_si(v
, -1);
319 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
320 isl_int_set_si(v
, 1);
321 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
322 bset
= isl_basic_set_add_constraint(bset
, c
);
324 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
325 isl_int_set_si(v
, 1);
326 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
327 isl_int_set_si(v
, -5);
328 isl_constraint_set_constant(c
, v
);
329 bset
= isl_basic_set_add_constraint(bset
, c
);
331 isl_local_space_free(ls
);
332 isl_basic_set_free(bset
);
337 void test_dim(struct isl_ctx
*ctx
)
340 isl_map
*map1
, *map2
;
342 map1
= isl_map_read_from_str(ctx
,
343 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
344 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
345 map2
= isl_map_read_from_str(ctx
,
346 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
347 assert(isl_map_is_equal(map1
, map2
));
350 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
351 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
352 assert(isl_map_is_equal(map1
, map2
));
357 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
358 map1
= isl_map_read_from_str(ctx
, str
);
359 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
360 map2
= isl_map_read_from_str(ctx
, str
);
361 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
362 assert(isl_map_is_equal(map1
, map2
));
369 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
373 { &isl_val_neg
, "0", "0" },
374 { &isl_val_abs
, "0", "0" },
375 { &isl_val_2exp
, "0", "1" },
376 { &isl_val_floor
, "0", "0" },
377 { &isl_val_ceil
, "0", "0" },
378 { &isl_val_neg
, "1", "-1" },
379 { &isl_val_neg
, "-1", "1" },
380 { &isl_val_neg
, "1/2", "-1/2" },
381 { &isl_val_neg
, "-1/2", "1/2" },
382 { &isl_val_neg
, "infty", "-infty" },
383 { &isl_val_neg
, "-infty", "infty" },
384 { &isl_val_neg
, "NaN", "NaN" },
385 { &isl_val_abs
, "1", "1" },
386 { &isl_val_abs
, "-1", "1" },
387 { &isl_val_abs
, "1/2", "1/2" },
388 { &isl_val_abs
, "-1/2", "1/2" },
389 { &isl_val_abs
, "infty", "infty" },
390 { &isl_val_abs
, "-infty", "infty" },
391 { &isl_val_abs
, "NaN", "NaN" },
392 { &isl_val_floor
, "1", "1" },
393 { &isl_val_floor
, "-1", "-1" },
394 { &isl_val_floor
, "1/2", "0" },
395 { &isl_val_floor
, "-1/2", "-1" },
396 { &isl_val_floor
, "infty", "infty" },
397 { &isl_val_floor
, "-infty", "-infty" },
398 { &isl_val_floor
, "NaN", "NaN" },
399 { &isl_val_ceil
, "1", "1" },
400 { &isl_val_ceil
, "-1", "-1" },
401 { &isl_val_ceil
, "1/2", "1" },
402 { &isl_val_ceil
, "-1/2", "0" },
403 { &isl_val_ceil
, "infty", "infty" },
404 { &isl_val_ceil
, "-infty", "-infty" },
405 { &isl_val_ceil
, "NaN", "NaN" },
406 { &isl_val_2exp
, "-3", "1/8" },
407 { &isl_val_2exp
, "-1", "1/2" },
408 { &isl_val_2exp
, "1", "2" },
409 { &isl_val_2exp
, "2", "4" },
410 { &isl_val_2exp
, "3", "8" },
413 /* Perform some basic tests of unary operations on isl_val objects.
415 static int test_un_val(isl_ctx
*ctx
)
419 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
422 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
423 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
424 res
= isl_val_read_from_str(ctx
, val_un_tests
[i
].res
);
425 fn
= val_un_tests
[i
].op
;
427 if (isl_val_is_nan(res
))
428 ok
= isl_val_is_nan(v
);
430 ok
= isl_val_eq(v
, res
);
436 isl_die(ctx
, isl_error_unknown
,
437 "unexpected result", return -1);
444 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
445 __isl_take isl_val
*v2
);
447 ['+'] = { &isl_val_add
},
448 ['-'] = { &isl_val_sub
},
449 ['*'] = { &isl_val_mul
},
450 ['/'] = { &isl_val_div
},
451 ['g'] = { &isl_val_gcd
},
452 ['m'] = { &isl_val_min
},
453 ['M'] = { &isl_val_max
},
461 } val_bin_tests
[] = {
462 { "0", '+', "0", "0" },
463 { "1", '+', "0", "1" },
464 { "1", '+', "1", "2" },
465 { "1", '-', "1", "0" },
466 { "1", '*', "1", "1" },
467 { "1", '/', "1", "1" },
468 { "2", '*', "3", "6" },
469 { "2", '*', "1/2", "1" },
470 { "2", '*', "1/3", "2/3" },
471 { "2/3", '*', "3/5", "2/5" },
472 { "2/3", '*', "7/5", "14/15" },
473 { "2", '/', "1/2", "4" },
474 { "-2", '/', "-1/2", "4" },
475 { "-2", '/', "1/2", "-4" },
476 { "2", '/', "-1/2", "-4" },
477 { "2", '/', "2", "1" },
478 { "2", '/', "3", "2/3" },
479 { "2/3", '/', "5/3", "2/5" },
480 { "2/3", '/', "5/7", "14/15" },
481 { "0", '/', "0", "NaN" },
482 { "42", '/', "0", "NaN" },
483 { "-42", '/', "0", "NaN" },
484 { "infty", '/', "0", "NaN" },
485 { "-infty", '/', "0", "NaN" },
486 { "NaN", '/', "0", "NaN" },
487 { "0", '/', "NaN", "NaN" },
488 { "42", '/', "NaN", "NaN" },
489 { "-42", '/', "NaN", "NaN" },
490 { "infty", '/', "NaN", "NaN" },
491 { "-infty", '/', "NaN", "NaN" },
492 { "NaN", '/', "NaN", "NaN" },
493 { "0", '/', "infty", "0" },
494 { "42", '/', "infty", "0" },
495 { "-42", '/', "infty", "0" },
496 { "infty", '/', "infty", "NaN" },
497 { "-infty", '/', "infty", "NaN" },
498 { "NaN", '/', "infty", "NaN" },
499 { "0", '/', "-infty", "0" },
500 { "42", '/', "-infty", "0" },
501 { "-42", '/', "-infty", "0" },
502 { "infty", '/', "-infty", "NaN" },
503 { "-infty", '/', "-infty", "NaN" },
504 { "NaN", '/', "-infty", "NaN" },
505 { "1", '-', "1/3", "2/3" },
506 { "1/3", '+', "1/2", "5/6" },
507 { "1/2", '+', "1/2", "1" },
508 { "3/4", '-', "1/4", "1/2" },
509 { "1/2", '-', "1/3", "1/6" },
510 { "infty", '+', "42", "infty" },
511 { "infty", '+', "infty", "infty" },
512 { "42", '+', "infty", "infty" },
513 { "infty", '-', "infty", "NaN" },
514 { "infty", '*', "infty", "infty" },
515 { "infty", '*', "-infty", "-infty" },
516 { "-infty", '*', "infty", "-infty" },
517 { "-infty", '*', "-infty", "infty" },
518 { "0", '*', "infty", "NaN" },
519 { "1", '*', "infty", "infty" },
520 { "infty", '*', "0", "NaN" },
521 { "infty", '*', "42", "infty" },
522 { "42", '-', "infty", "-infty" },
523 { "infty", '+', "-infty", "NaN" },
524 { "4", 'g', "6", "2" },
525 { "5", 'g', "6", "1" },
526 { "42", 'm', "3", "3" },
527 { "42", 'M', "3", "42" },
528 { "3", 'm', "42", "3" },
529 { "3", 'M', "42", "42" },
530 { "42", 'm', "infty", "42" },
531 { "42", 'M', "infty", "infty" },
532 { "42", 'm', "-infty", "-infty" },
533 { "42", 'M', "-infty", "42" },
534 { "42", 'm', "NaN", "NaN" },
535 { "42", 'M', "NaN", "NaN" },
536 { "infty", 'm', "-infty", "-infty" },
537 { "infty", 'M', "-infty", "infty" },
540 /* Perform some basic tests of binary operations on isl_val objects.
542 static int test_bin_val(isl_ctx
*ctx
)
545 isl_val
*v1
, *v2
, *res
;
546 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
547 __isl_take isl_val
*v2
);
550 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
551 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
552 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
553 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
554 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
556 if (isl_val_is_nan(res
))
557 ok
= isl_val_is_nan(v1
);
559 ok
= isl_val_eq(v1
, res
);
565 isl_die(ctx
, isl_error_unknown
,
566 "unexpected result", return -1);
572 /* Perform some basic tests on isl_val objects.
574 static int test_val(isl_ctx
*ctx
)
576 if (test_un_val(ctx
) < 0)
578 if (test_bin_val(ctx
) < 0)
583 static int test_div(isl_ctx
*ctx
)
592 struct isl_basic_set
*bset
;
593 struct isl_constraint
*c
;
598 dim
= isl_space_set_alloc(ctx
, 0, 3);
599 bset
= isl_basic_set_universe(isl_space_copy(dim
));
600 ls
= isl_local_space_from_space(dim
);
602 c
= isl_equality_alloc(isl_local_space_copy(ls
));
603 isl_int_set_si(v
, -1);
604 isl_constraint_set_constant(c
, v
);
605 isl_int_set_si(v
, 1);
606 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
607 isl_int_set_si(v
, 3);
608 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
609 bset
= isl_basic_set_add_constraint(bset
, c
);
611 c
= isl_equality_alloc(isl_local_space_copy(ls
));
612 isl_int_set_si(v
, 1);
613 isl_constraint_set_constant(c
, v
);
614 isl_int_set_si(v
, -1);
615 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
616 isl_int_set_si(v
, 3);
617 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
618 bset
= isl_basic_set_add_constraint(bset
, c
);
620 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
622 assert(bset
&& bset
->n_div
== 1);
623 isl_local_space_free(ls
);
624 isl_basic_set_free(bset
);
627 dim
= isl_space_set_alloc(ctx
, 0, 3);
628 bset
= isl_basic_set_universe(isl_space_copy(dim
));
629 ls
= isl_local_space_from_space(dim
);
631 c
= isl_equality_alloc(isl_local_space_copy(ls
));
632 isl_int_set_si(v
, 1);
633 isl_constraint_set_constant(c
, v
);
634 isl_int_set_si(v
, -1);
635 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
636 isl_int_set_si(v
, 3);
637 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
638 bset
= isl_basic_set_add_constraint(bset
, c
);
640 c
= isl_equality_alloc(isl_local_space_copy(ls
));
641 isl_int_set_si(v
, -1);
642 isl_constraint_set_constant(c
, v
);
643 isl_int_set_si(v
, 1);
644 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
645 isl_int_set_si(v
, 3);
646 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
647 bset
= isl_basic_set_add_constraint(bset
, c
);
649 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
651 assert(bset
&& bset
->n_div
== 1);
652 isl_local_space_free(ls
);
653 isl_basic_set_free(bset
);
656 dim
= isl_space_set_alloc(ctx
, 0, 3);
657 bset
= isl_basic_set_universe(isl_space_copy(dim
));
658 ls
= isl_local_space_from_space(dim
);
660 c
= isl_equality_alloc(isl_local_space_copy(ls
));
661 isl_int_set_si(v
, 1);
662 isl_constraint_set_constant(c
, v
);
663 isl_int_set_si(v
, -1);
664 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
665 isl_int_set_si(v
, 3);
666 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
667 bset
= isl_basic_set_add_constraint(bset
, c
);
669 c
= isl_equality_alloc(isl_local_space_copy(ls
));
670 isl_int_set_si(v
, -3);
671 isl_constraint_set_constant(c
, v
);
672 isl_int_set_si(v
, 1);
673 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
674 isl_int_set_si(v
, 4);
675 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
676 bset
= isl_basic_set_add_constraint(bset
, c
);
678 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
680 assert(bset
&& bset
->n_div
== 1);
681 isl_local_space_free(ls
);
682 isl_basic_set_free(bset
);
685 dim
= isl_space_set_alloc(ctx
, 0, 3);
686 bset
= isl_basic_set_universe(isl_space_copy(dim
));
687 ls
= isl_local_space_from_space(dim
);
689 c
= isl_equality_alloc(isl_local_space_copy(ls
));
690 isl_int_set_si(v
, 2);
691 isl_constraint_set_constant(c
, v
);
692 isl_int_set_si(v
, -1);
693 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
694 isl_int_set_si(v
, 3);
695 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
696 bset
= isl_basic_set_add_constraint(bset
, c
);
698 c
= isl_equality_alloc(isl_local_space_copy(ls
));
699 isl_int_set_si(v
, -1);
700 isl_constraint_set_constant(c
, v
);
701 isl_int_set_si(v
, 1);
702 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
703 isl_int_set_si(v
, 6);
704 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
705 bset
= isl_basic_set_add_constraint(bset
, c
);
707 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
709 assert(isl_basic_set_is_empty(bset
));
710 isl_local_space_free(ls
);
711 isl_basic_set_free(bset
);
714 dim
= isl_space_set_alloc(ctx
, 0, 3);
715 bset
= isl_basic_set_universe(isl_space_copy(dim
));
716 ls
= isl_local_space_from_space(dim
);
718 c
= isl_equality_alloc(isl_local_space_copy(ls
));
719 isl_int_set_si(v
, -1);
720 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
721 isl_int_set_si(v
, 3);
722 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
723 bset
= isl_basic_set_add_constraint(bset
, c
);
725 c
= isl_equality_alloc(isl_local_space_copy(ls
));
726 isl_int_set_si(v
, 1);
727 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
728 isl_int_set_si(v
, -3);
729 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
730 bset
= isl_basic_set_add_constraint(bset
, c
);
732 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
734 assert(bset
&& bset
->n_div
== 0);
735 isl_basic_set_free(bset
);
736 isl_local_space_free(ls
);
739 dim
= isl_space_set_alloc(ctx
, 0, 3);
740 bset
= isl_basic_set_universe(isl_space_copy(dim
));
741 ls
= isl_local_space_from_space(dim
);
743 c
= isl_equality_alloc(isl_local_space_copy(ls
));
744 isl_int_set_si(v
, -1);
745 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
746 isl_int_set_si(v
, 6);
747 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
748 bset
= isl_basic_set_add_constraint(bset
, c
);
750 c
= isl_equality_alloc(isl_local_space_copy(ls
));
751 isl_int_set_si(v
, 1);
752 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
753 isl_int_set_si(v
, -3);
754 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
755 bset
= isl_basic_set_add_constraint(bset
, c
);
757 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
759 assert(bset
&& bset
->n_div
== 1);
760 isl_basic_set_free(bset
);
761 isl_local_space_free(ls
);
764 /* This test is a bit tricky. We set up an equality
766 * Normalization of divs creates _two_ divs
769 * Afterwards e0 is removed again because it has coefficient -1
770 * and we end up with the original equality and div again.
771 * Perhaps we can avoid the introduction of this temporary div.
773 dim
= isl_space_set_alloc(ctx
, 0, 4);
774 bset
= isl_basic_set_universe(isl_space_copy(dim
));
775 ls
= isl_local_space_from_space(dim
);
777 c
= isl_equality_alloc(isl_local_space_copy(ls
));
778 isl_int_set_si(v
, -1);
779 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
780 isl_int_set_si(v
, -3);
781 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
782 isl_int_set_si(v
, -3);
783 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
784 isl_int_set_si(v
, 6);
785 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
786 bset
= isl_basic_set_add_constraint(bset
, c
);
788 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
790 /* Test disabled for now */
792 assert(bset && bset->n_div == 1);
794 isl_local_space_free(ls
);
795 isl_basic_set_free(bset
);
798 dim
= isl_space_set_alloc(ctx
, 0, 5);
799 bset
= isl_basic_set_universe(isl_space_copy(dim
));
800 ls
= isl_local_space_from_space(dim
);
802 c
= isl_equality_alloc(isl_local_space_copy(ls
));
803 isl_int_set_si(v
, -1);
804 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
805 isl_int_set_si(v
, -3);
806 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
807 isl_int_set_si(v
, -3);
808 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
809 isl_int_set_si(v
, 6);
810 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
811 bset
= isl_basic_set_add_constraint(bset
, c
);
813 c
= isl_equality_alloc(isl_local_space_copy(ls
));
814 isl_int_set_si(v
, -1);
815 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
816 isl_int_set_si(v
, 1);
817 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
818 isl_int_set_si(v
, 1);
819 isl_constraint_set_constant(c
, v
);
820 bset
= isl_basic_set_add_constraint(bset
, c
);
822 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
824 /* Test disabled for now */
826 assert(bset && bset->n_div == 1);
828 isl_local_space_free(ls
);
829 isl_basic_set_free(bset
);
832 dim
= isl_space_set_alloc(ctx
, 0, 4);
833 bset
= isl_basic_set_universe(isl_space_copy(dim
));
834 ls
= isl_local_space_from_space(dim
);
836 c
= isl_equality_alloc(isl_local_space_copy(ls
));
837 isl_int_set_si(v
, 1);
838 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
839 isl_int_set_si(v
, -1);
840 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
841 isl_int_set_si(v
, -2);
842 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
843 bset
= isl_basic_set_add_constraint(bset
, c
);
845 c
= isl_equality_alloc(isl_local_space_copy(ls
));
846 isl_int_set_si(v
, -1);
847 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
848 isl_int_set_si(v
, 3);
849 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
850 isl_int_set_si(v
, 2);
851 isl_constraint_set_constant(c
, v
);
852 bset
= isl_basic_set_add_constraint(bset
, c
);
854 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
856 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
858 assert(!isl_basic_set_is_empty(bset
));
860 isl_local_space_free(ls
);
861 isl_basic_set_free(bset
);
864 dim
= isl_space_set_alloc(ctx
, 0, 3);
865 bset
= isl_basic_set_universe(isl_space_copy(dim
));
866 ls
= isl_local_space_from_space(dim
);
868 c
= isl_equality_alloc(isl_local_space_copy(ls
));
869 isl_int_set_si(v
, 1);
870 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
871 isl_int_set_si(v
, -2);
872 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
873 bset
= isl_basic_set_add_constraint(bset
, c
);
875 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
877 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
879 isl_local_space_free(ls
);
880 isl_basic_set_free(bset
);
884 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
885 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
886 set
= isl_set_read_from_str(ctx
, str
);
887 set
= isl_set_compute_divs(set
);
892 str
= "{ [i,j] : 2*[i/2] + 3 * [j/4] <= 10 and 2 i = j }";
893 bset
= isl_basic_set_read_from_str(ctx
, str
);
894 n
= isl_basic_set_dim(bset
, isl_dim_div
);
895 isl_basic_set_free(bset
);
899 isl_die(ctx
, isl_error_unknown
,
900 "expecting no existentials", return -1);
902 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
903 set
= isl_set_read_from_str(ctx
, str
);
904 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
905 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
906 empty
= isl_set_is_empty(set
);
911 isl_die(ctx
, isl_error_unknown
,
912 "result not as accurate as expected", return -1);
917 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
921 struct isl_basic_set
*bset1
, *bset2
;
922 struct isl_basic_map
*bmap
;
924 filename
= get_filename(ctx
, name
, "omega");
926 input
= fopen(filename
, "r");
929 bset1
= isl_basic_set_read_from_file(ctx
, input
);
930 bmap
= isl_basic_map_read_from_file(ctx
, input
);
932 bset1
= isl_basic_set_apply(bset1
, bmap
);
934 bset2
= isl_basic_set_read_from_file(ctx
, input
);
936 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
938 isl_basic_set_free(bset1
);
939 isl_basic_set_free(bset2
);
945 void test_application(struct isl_ctx
*ctx
)
947 test_application_case(ctx
, "application");
948 test_application_case(ctx
, "application2");
951 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
955 struct isl_basic_set
*bset1
, *bset2
;
957 filename
= get_filename(ctx
, name
, "polylib");
959 input
= fopen(filename
, "r");
962 bset1
= isl_basic_set_read_from_file(ctx
, input
);
963 bset2
= isl_basic_set_read_from_file(ctx
, input
);
965 bset1
= isl_basic_set_affine_hull(bset1
);
967 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
969 isl_basic_set_free(bset1
);
970 isl_basic_set_free(bset2
);
976 int test_affine_hull(struct isl_ctx
*ctx
)
980 isl_basic_set
*bset
, *bset2
;
984 test_affine_hull_case(ctx
, "affine2");
985 test_affine_hull_case(ctx
, "affine");
986 test_affine_hull_case(ctx
, "affine3");
988 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
989 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
990 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
991 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
992 set
= isl_set_read_from_str(ctx
, str
);
993 bset
= isl_set_affine_hull(set
);
994 n
= isl_basic_set_dim(bset
, isl_dim_div
);
995 isl_basic_set_free(bset
);
997 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1000 /* Check that isl_map_affine_hull is not confused by
1001 * the reordering of divs in isl_map_align_divs.
1003 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1004 "32e0 = b and 32e1 = c); "
1005 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1006 set
= isl_set_read_from_str(ctx
, str
);
1007 bset
= isl_set_affine_hull(set
);
1008 isl_basic_set_free(bset
);
1012 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1013 "32e2 = 31 + 31e0 }";
1014 set
= isl_set_read_from_str(ctx
, str
);
1015 bset
= isl_set_affine_hull(set
);
1016 str
= "{ [a] : exists e : a = 32 e }";
1017 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1018 subset
= isl_basic_set_is_subset(bset
, bset2
);
1019 isl_basic_set_free(bset
);
1020 isl_basic_set_free(bset2
);
1024 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1030 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1034 struct isl_basic_set
*bset1
, *bset2
;
1035 struct isl_set
*set
;
1037 filename
= get_filename(ctx
, name
, "polylib");
1039 input
= fopen(filename
, "r");
1042 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1043 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1045 set
= isl_basic_set_union(bset1
, bset2
);
1046 bset1
= isl_set_convex_hull(set
);
1048 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1050 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1052 isl_basic_set_free(bset1
);
1053 isl_basic_set_free(bset2
);
1062 } convex_hull_tests
[] = {
1063 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1064 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1065 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1066 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1067 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1068 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1069 "i2 <= 5 and i2 >= 4; "
1070 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1071 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1072 "i2 <= 5 + i0 and i2 >= i0 }" },
1075 void test_convex_hull_algo(struct isl_ctx
*ctx
, int convex
)
1078 int orig_convex
= ctx
->opt
->convex
;
1079 ctx
->opt
->convex
= convex
;
1081 test_convex_hull_case(ctx
, "convex0");
1082 test_convex_hull_case(ctx
, "convex1");
1083 test_convex_hull_case(ctx
, "convex2");
1084 test_convex_hull_case(ctx
, "convex3");
1085 test_convex_hull_case(ctx
, "convex4");
1086 test_convex_hull_case(ctx
, "convex5");
1087 test_convex_hull_case(ctx
, "convex6");
1088 test_convex_hull_case(ctx
, "convex7");
1089 test_convex_hull_case(ctx
, "convex8");
1090 test_convex_hull_case(ctx
, "convex9");
1091 test_convex_hull_case(ctx
, "convex10");
1092 test_convex_hull_case(ctx
, "convex11");
1093 test_convex_hull_case(ctx
, "convex12");
1094 test_convex_hull_case(ctx
, "convex13");
1095 test_convex_hull_case(ctx
, "convex14");
1096 test_convex_hull_case(ctx
, "convex15");
1098 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1099 isl_set
*set1
, *set2
;
1101 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1102 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1103 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1104 assert(isl_set_is_equal(set1
, set2
));
1109 ctx
->opt
->convex
= orig_convex
;
1112 void test_convex_hull(struct isl_ctx
*ctx
)
1114 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
);
1115 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
);
1118 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1122 struct isl_basic_set
*bset1
, *bset2
;
1124 filename
= get_filename(ctx
, name
, "polylib");
1126 input
= fopen(filename
, "r");
1129 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1130 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1132 bset1
= isl_basic_set_gist(bset1
, bset2
);
1134 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1136 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1138 isl_basic_set_free(bset1
);
1139 isl_basic_set_free(bset2
);
1147 const char *context
;
1150 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1151 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1152 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1153 "{ [a, b, c] : a <= 15 }" },
1154 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1155 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1158 static int test_gist(struct isl_ctx
*ctx
)
1162 isl_basic_set
*bset1
, *bset2
;
1163 isl_map
*map1
, *map2
;
1166 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1167 bset1
= isl_basic_set_read_from_str(ctx
, gist_tests
[i
].set
);
1168 bset2
= isl_basic_set_read_from_str(ctx
, gist_tests
[i
].context
);
1169 bset1
= isl_basic_set_gist(bset1
, bset2
);
1170 bset2
= isl_basic_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1171 equal
= isl_basic_set_is_equal(bset1
, bset2
);
1172 isl_basic_set_free(bset1
);
1173 isl_basic_set_free(bset2
);
1177 isl_die(ctx
, isl_error_unknown
,
1178 "incorrect gist result", return -1);
1181 test_gist_case(ctx
, "gist1");
1183 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1184 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1185 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1186 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1187 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1188 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1189 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1190 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1191 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1192 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1193 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1194 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1195 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1196 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1197 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1198 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1199 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1200 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1201 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1202 bset1
= isl_basic_set_gist(bset1
, bset2
);
1203 assert(bset1
&& bset1
->n_div
== 0);
1204 isl_basic_set_free(bset1
);
1206 /* Check that the integer divisions of the second disjunct
1207 * do not spread to the first disjunct.
1209 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1210 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1211 "(exists (e0 = [(-1 + t1)/16], "
1212 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1213 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1214 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1215 "o0 <= 4294967295 and t1 <= -1)) }";
1216 map1
= isl_map_read_from_str(ctx
, str
);
1217 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1218 map2
= isl_map_read_from_str(ctx
, str
);
1219 map1
= isl_map_gist(map1
, map2
);
1223 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1224 isl_map_free(map1
); return -1);
1225 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1226 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1227 isl_map_free(map1
); return -1);
1233 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1235 isl_set
*set
, *set2
;
1239 set
= isl_set_read_from_str(ctx
, str
);
1240 set
= isl_set_coalesce(set
);
1241 set2
= isl_set_read_from_str(ctx
, str
);
1242 equal
= isl_set_is_equal(set
, set2
);
1243 one
= set
&& set
->n
== 1;
1250 isl_die(ctx
, isl_error_unknown
,
1251 "coalesced set not equal to input", return -1);
1252 if (check_one
&& !one
)
1253 isl_die(ctx
, isl_error_unknown
,
1254 "coalesced set should not be a union", return -1);
1259 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1264 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1265 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1267 if (test_coalesce_set(ctx
,
1268 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1269 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1270 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1271 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1272 "-10 <= y <= 0}", 1) < 0)
1274 if (test_coalesce_set(ctx
,
1275 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
1277 if (test_coalesce_set(ctx
,
1278 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
1286 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1291 /* Inputs for coalescing tests.
1292 * "str" is a string representation of the input set.
1293 * "single_disjunct" is set if we expect the result to consist of
1294 * a single disjunct.
1297 int single_disjunct
;
1299 } coalesce_tests
[] = {
1300 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1301 "y >= x & x >= 2 & 5 >= y }" },
1302 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1303 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1304 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1305 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1306 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1307 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1308 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1309 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1310 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1311 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1312 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1313 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1314 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1315 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1316 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1317 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1318 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1319 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1320 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1321 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1322 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1323 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1324 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1325 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1326 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1327 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1328 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1329 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1330 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1331 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1332 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1333 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1334 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1335 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1336 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1337 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1338 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1339 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1340 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1341 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1342 "[o0, o1, o2, o3, o4, o5, o6]] : "
1343 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1344 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1345 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1346 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1347 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1348 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1349 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1350 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1351 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1352 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1353 "o6 >= i3 + i6 - o3 and M >= 0 and "
1354 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1355 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1356 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1357 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1358 "(o0 = 0 and M >= 2 and N >= 3) or "
1359 "(M = 0 and o0 = 0 and N >= 3) }" },
1360 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1361 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1362 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1363 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1364 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1365 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1366 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1367 "(y = 3 and x = 1) }" },
1368 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1369 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1370 "i1 <= M and i3 <= M and i4 <= M) or "
1371 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1372 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1373 "i4 <= -1 + M) }" },
1374 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1375 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1376 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1377 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1378 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1379 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1380 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1381 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1382 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1383 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1384 { 0, "{ [a, b] : exists e : 2e = a and "
1385 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1386 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1387 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1388 "j >= 1 and j' <= i + j - i' and i >= 1; "
1390 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1391 "[i,j] : exists a : j = 3a }" },
1392 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1393 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1395 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1396 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1397 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1398 "c <= 6 + 8a and a >= 3; "
1399 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1400 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1401 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1402 "[x,0] : 3 <= x <= 4 }" },
1403 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1404 "[x,0] : 4 <= x <= 5 }" },
1405 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1406 "[x,0] : 3 <= x <= 5 }" },
1407 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1408 "[x,0] : 3 <= x <= 4 }" },
1409 { 1 , "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1411 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1414 /* Test the functionality of isl_set_coalesce.
1415 * That is, check that the output is always equal to the input
1416 * and in some cases that the result consists of a single disjunct.
1418 static int test_coalesce(struct isl_ctx
*ctx
)
1422 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
1423 const char *str
= coalesce_tests
[i
].str
;
1424 int check_one
= coalesce_tests
[i
].single_disjunct
;
1425 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
1429 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
1435 void test_closure(struct isl_ctx
*ctx
)
1439 isl_map
*up
, *right
;
1440 isl_map
*map
, *map2
;
1443 /* COCOA example 1 */
1444 map
= isl_map_read_from_str(ctx
,
1445 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1446 "1 <= i and i < n and 1 <= j and j < n or "
1447 "i2 = i + 1 and j2 = j - 1 and "
1448 "1 <= i and i < n and 2 <= j and j <= n }");
1449 map
= isl_map_power(map
, &exact
);
1453 /* COCOA example 1 */
1454 map
= isl_map_read_from_str(ctx
,
1455 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1456 "1 <= i and i < n and 1 <= j and j < n or "
1457 "i2 = i + 1 and j2 = j - 1 and "
1458 "1 <= i and i < n and 2 <= j and j <= n }");
1459 map
= isl_map_transitive_closure(map
, &exact
);
1461 map2
= isl_map_read_from_str(ctx
,
1462 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1463 "1 <= i and i < n and 1 <= j and j <= n and "
1464 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1465 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1466 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1467 assert(isl_map_is_equal(map
, map2
));
1471 map
= isl_map_read_from_str(ctx
,
1472 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1473 " 0 <= y and y <= n }");
1474 map
= isl_map_transitive_closure(map
, &exact
);
1475 map2
= isl_map_read_from_str(ctx
,
1476 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1477 " 0 <= y and y <= n }");
1478 assert(isl_map_is_equal(map
, map2
));
1482 /* COCOA example 2 */
1483 map
= isl_map_read_from_str(ctx
,
1484 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1485 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1486 "i2 = i + 2 and j2 = j - 2 and "
1487 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1488 map
= isl_map_transitive_closure(map
, &exact
);
1490 map2
= isl_map_read_from_str(ctx
,
1491 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1492 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1493 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1494 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1495 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1496 assert(isl_map_is_equal(map
, map2
));
1500 /* COCOA Fig.2 left */
1501 map
= isl_map_read_from_str(ctx
,
1502 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1503 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1505 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1506 "j <= 2 i - 3 and j <= n - 2 or "
1507 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1508 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1509 map
= isl_map_transitive_closure(map
, &exact
);
1513 /* COCOA Fig.2 right */
1514 map
= isl_map_read_from_str(ctx
,
1515 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1516 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1518 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1519 "j <= 2 i - 4 and j <= n - 3 or "
1520 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1521 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1522 map
= isl_map_power(map
, &exact
);
1526 /* COCOA Fig.2 right */
1527 map
= isl_map_read_from_str(ctx
,
1528 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1529 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1531 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1532 "j <= 2 i - 4 and j <= n - 3 or "
1533 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1534 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1535 map
= isl_map_transitive_closure(map
, &exact
);
1537 map2
= isl_map_read_from_str(ctx
,
1538 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1539 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1540 "j <= n and 3 + i + 2 j <= 3 n and "
1541 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1542 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1543 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1544 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1545 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1546 assert(isl_map_is_equal(map
, map2
));
1550 /* COCOA Fig.1 right */
1551 dom
= isl_set_read_from_str(ctx
,
1552 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1553 "2 x - 3 y + 3 >= 0 }");
1554 right
= isl_map_read_from_str(ctx
,
1555 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1556 up
= isl_map_read_from_str(ctx
,
1557 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1558 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1559 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1560 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1561 up
= isl_map_intersect_range(up
, dom
);
1562 map
= isl_map_union(up
, right
);
1563 map
= isl_map_transitive_closure(map
, &exact
);
1565 map2
= isl_map_read_from_str(ctx
,
1566 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1567 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1568 assert(isl_map_is_equal(map
, map2
));
1572 /* COCOA Theorem 1 counter example */
1573 map
= isl_map_read_from_str(ctx
,
1574 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1575 "i2 = 1 and j2 = j or "
1576 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1577 map
= isl_map_transitive_closure(map
, &exact
);
1581 map
= isl_map_read_from_str(ctx
,
1582 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1583 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1584 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1585 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1586 map
= isl_map_transitive_closure(map
, &exact
);
1590 /* Kelly et al 1996, fig 12 */
1591 map
= isl_map_read_from_str(ctx
,
1592 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1593 "1 <= i,j,j+1 <= n or "
1594 "j = n and j2 = 1 and i2 = i + 1 and "
1595 "1 <= i,i+1 <= n }");
1596 map
= isl_map_transitive_closure(map
, &exact
);
1598 map2
= isl_map_read_from_str(ctx
,
1599 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1600 "1 <= i <= n and i = i2 or "
1601 "1 <= i < i2 <= n and 1 <= j <= n and "
1603 assert(isl_map_is_equal(map
, map2
));
1607 /* Omega's closure4 */
1608 map
= isl_map_read_from_str(ctx
,
1609 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1610 "1 <= x,y <= 10 or "
1611 "x2 = x + 1 and y2 = y and "
1612 "1 <= x <= 20 && 5 <= y <= 15 }");
1613 map
= isl_map_transitive_closure(map
, &exact
);
1617 map
= isl_map_read_from_str(ctx
,
1618 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1619 map
= isl_map_transitive_closure(map
, &exact
);
1621 map2
= isl_map_read_from_str(ctx
,
1622 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1623 assert(isl_map_is_equal(map
, map2
));
1627 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1628 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1629 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1630 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1631 map
= isl_map_read_from_str(ctx
, str
);
1632 map
= isl_map_transitive_closure(map
, &exact
);
1634 map2
= isl_map_read_from_str(ctx
, str
);
1635 assert(isl_map_is_equal(map
, map2
));
1639 str
= "{[0] -> [1]; [2] -> [3]}";
1640 map
= isl_map_read_from_str(ctx
, str
);
1641 map
= isl_map_transitive_closure(map
, &exact
);
1643 map2
= isl_map_read_from_str(ctx
, str
);
1644 assert(isl_map_is_equal(map
, map2
));
1648 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1649 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1650 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1651 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1652 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1653 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1654 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1655 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1656 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1657 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1658 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1659 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1660 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1661 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1662 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1663 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1664 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1665 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1666 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1667 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1668 map
= isl_map_read_from_str(ctx
, str
);
1669 map
= isl_map_transitive_closure(map
, NULL
);
1674 void test_lex(struct isl_ctx
*ctx
)
1679 dim
= isl_space_set_alloc(ctx
, 0, 0);
1680 map
= isl_map_lex_le(dim
);
1681 assert(!isl_map_is_empty(map
));
1685 static int test_lexmin(struct isl_ctx
*ctx
)
1689 isl_basic_map
*bmap
;
1690 isl_map
*map
, *map2
;
1693 isl_pw_multi_aff
*pma
;
1695 str
= "[p0, p1] -> { [] -> [] : "
1696 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1697 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1698 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1699 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1700 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1701 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1702 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1703 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1704 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1705 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1706 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1707 map
= isl_map_read_from_str(ctx
, str
);
1708 map
= isl_map_lexmin(map
);
1711 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1712 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1713 set
= isl_set_read_from_str(ctx
, str
);
1714 set
= isl_set_lexmax(set
);
1715 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1716 set2
= isl_set_read_from_str(ctx
, str
);
1717 set
= isl_set_intersect(set
, set2
);
1718 assert(!isl_set_is_empty(set
));
1721 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1722 map
= isl_map_read_from_str(ctx
, str
);
1723 map
= isl_map_lexmin(map
);
1724 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1725 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1726 map2
= isl_map_read_from_str(ctx
, str
);
1727 assert(isl_map_is_equal(map
, map2
));
1731 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1732 map
= isl_map_read_from_str(ctx
, str
);
1733 map2
= isl_map_copy(map
);
1734 map
= isl_map_lexmin(map
);
1735 assert(isl_map_is_equal(map
, map2
));
1739 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1740 map
= isl_map_read_from_str(ctx
, str
);
1741 map
= isl_map_lexmin(map
);
1742 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1743 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1744 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1745 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1746 map2
= isl_map_read_from_str(ctx
, str
);
1747 assert(isl_map_is_equal(map
, map2
));
1751 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1752 " 8i' <= i and 8i' >= -7 + i }";
1753 bmap
= isl_basic_map_read_from_str(ctx
, str
);
1754 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
1755 map2
= isl_map_from_pw_multi_aff(pma
);
1756 map
= isl_map_from_basic_map(bmap
);
1757 assert(isl_map_is_equal(map
, map2
));
1761 str
= "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1762 map
= isl_map_read_from_str(ctx
, str
);
1763 map
= isl_map_lexmin(map
);
1764 str
= "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1765 map2
= isl_map_read_from_str(ctx
, str
);
1766 assert(isl_map_is_equal(map
, map2
));
1770 /* Check that empty pieces are properly combined. */
1771 str
= "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
1772 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
1773 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }";
1774 map
= isl_map_read_from_str(ctx
, str
);
1775 map
= isl_map_lexmin(map
);
1776 str
= "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
1777 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
1779 map2
= isl_map_read_from_str(ctx
, str
);
1780 assert(isl_map_is_equal(map
, map2
));
1784 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1785 " 8i' <= i and 8i' >= -7 + i }";
1786 set
= isl_set_read_from_str(ctx
, str
);
1787 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
1788 set2
= isl_set_from_pw_multi_aff(pma
);
1789 equal
= isl_set_is_equal(set
, set2
);
1795 isl_die(ctx
, isl_error_unknown
,
1796 "unexpected difference between set and "
1797 "piecewise affine expression", return -1);
1802 /* Check that isl_set_min_val and isl_set_max_val compute the correct
1803 * result on non-convex inputs.
1805 static int test_min(struct isl_ctx
*ctx
)
1812 set
= isl_set_read_from_str(ctx
, "{ [-1]; [1] }");
1813 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x] }");
1814 val
= isl_set_min_val(set
, aff
);
1815 min_ok
= isl_val_is_negone(val
);
1817 val
= isl_set_max_val(set
, aff
);
1818 max_ok
= isl_val_is_one(val
);
1823 if (min_ok
< 0 || max_ok
< 0)
1826 isl_die(ctx
, isl_error_unknown
,
1827 "unexpected minimum", return -1);
1829 isl_die(ctx
, isl_error_unknown
,
1830 "unexpected maximum", return -1);
1840 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1841 void *dep_user
, void *user
)
1843 struct must_may
*mm
= (struct must_may
*)user
;
1846 mm
->must
= isl_map_union(mm
->must
, dep
);
1848 mm
->may
= isl_map_union(mm
->may
, dep
);
1853 static int common_space(void *first
, void *second
)
1855 int depth
= *(int *)first
;
1859 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1867 map2
= isl_map_read_from_str(map
->ctx
, str
);
1868 equal
= isl_map_is_equal(map
, map2
);
1874 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
1878 equal
= map_is_equal(map
, str
);
1882 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
1883 "result not as expected", return -1);
1887 void test_dep(struct isl_ctx
*ctx
)
1892 isl_access_info
*ai
;
1899 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1900 map
= isl_map_read_from_str(ctx
, str
);
1901 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1903 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1904 map
= isl_map_read_from_str(ctx
, str
);
1905 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1907 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1908 map
= isl_map_read_from_str(ctx
, str
);
1909 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1911 flow
= isl_access_info_compute_flow(ai
);
1912 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1913 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1914 mm
.may
= isl_map_empty(dim
);
1916 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1918 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1919 " [1,10,0] -> [2,5,0] }";
1920 assert(map_is_equal(mm
.must
, str
));
1921 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1922 assert(map_is_equal(mm
.may
, str
));
1924 isl_map_free(mm
.must
);
1925 isl_map_free(mm
.may
);
1926 isl_flow_free(flow
);
1929 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1930 map
= isl_map_read_from_str(ctx
, str
);
1931 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1933 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1934 map
= isl_map_read_from_str(ctx
, str
);
1935 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1937 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1938 map
= isl_map_read_from_str(ctx
, str
);
1939 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1941 flow
= isl_access_info_compute_flow(ai
);
1942 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1943 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1944 mm
.may
= isl_map_empty(dim
);
1946 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1948 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1949 assert(map_is_equal(mm
.must
, str
));
1950 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1951 assert(map_is_equal(mm
.may
, str
));
1953 isl_map_free(mm
.must
);
1954 isl_map_free(mm
.may
);
1955 isl_flow_free(flow
);
1958 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1959 map
= isl_map_read_from_str(ctx
, str
);
1960 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1962 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1963 map
= isl_map_read_from_str(ctx
, str
);
1964 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1966 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1967 map
= isl_map_read_from_str(ctx
, str
);
1968 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1970 flow
= isl_access_info_compute_flow(ai
);
1971 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1972 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1973 mm
.may
= isl_map_empty(dim
);
1975 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1977 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1978 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1979 assert(map_is_equal(mm
.may
, str
));
1980 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1981 assert(map_is_equal(mm
.must
, str
));
1983 isl_map_free(mm
.must
);
1984 isl_map_free(mm
.may
);
1985 isl_flow_free(flow
);
1988 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1989 map
= isl_map_read_from_str(ctx
, str
);
1990 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1992 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1993 map
= isl_map_read_from_str(ctx
, str
);
1994 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1996 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1997 map
= isl_map_read_from_str(ctx
, str
);
1998 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2000 flow
= isl_access_info_compute_flow(ai
);
2001 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2002 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2003 mm
.may
= isl_map_empty(dim
);
2005 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2007 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2008 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2009 assert(map_is_equal(mm
.may
, str
));
2010 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2011 assert(map_is_equal(mm
.must
, str
));
2013 isl_map_free(mm
.must
);
2014 isl_map_free(mm
.may
);
2015 isl_flow_free(flow
);
2018 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2019 map
= isl_map_read_from_str(ctx
, str
);
2020 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2022 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2023 map
= isl_map_read_from_str(ctx
, str
);
2024 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2026 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2027 map
= isl_map_read_from_str(ctx
, str
);
2028 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2030 flow
= isl_access_info_compute_flow(ai
);
2031 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2032 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2033 mm
.may
= isl_map_empty(dim
);
2035 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2037 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2038 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2039 assert(map_is_equal(mm
.may
, str
));
2040 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2041 assert(map_is_equal(mm
.must
, str
));
2043 isl_map_free(mm
.must
);
2044 isl_map_free(mm
.may
);
2045 isl_flow_free(flow
);
2050 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2051 map
= isl_map_read_from_str(ctx
, str
);
2052 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
2054 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2055 map
= isl_map_read_from_str(ctx
, str
);
2056 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2058 flow
= isl_access_info_compute_flow(ai
);
2059 dim
= isl_space_alloc(ctx
, 0, 5, 5);
2060 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2061 mm
.may
= isl_map_empty(dim
);
2063 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2065 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
2066 assert(map_is_equal(mm
.must
, str
));
2067 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
2068 assert(map_is_equal(mm
.may
, str
));
2070 isl_map_free(mm
.must
);
2071 isl_map_free(mm
.may
);
2072 isl_flow_free(flow
);
2075 /* Check that the dependence analysis proceeds without errors.
2076 * Earlier versions of isl would break down during the analysis
2077 * due to the use of the wrong spaces.
2079 static int test_flow(isl_ctx
*ctx
)
2082 isl_union_map
*access
, *schedule
;
2083 isl_union_map
*must_dep
, *may_dep
;
2086 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
2087 access
= isl_union_map_read_from_str(ctx
, str
);
2088 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
2089 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
2090 "S2[] -> [1,0,0,0]; "
2091 "S3[] -> [-1,0,0,0] }";
2092 schedule
= isl_union_map_read_from_str(ctx
, str
);
2093 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
2094 isl_union_map_copy(access
), schedule
,
2095 &must_dep
, &may_dep
, NULL
, NULL
);
2096 isl_union_map_free(may_dep
);
2097 isl_union_map_free(must_dep
);
2102 int test_sv(isl_ctx
*ctx
)
2106 isl_union_map
*umap
;
2109 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
2110 map
= isl_map_read_from_str(ctx
, str
);
2111 sv
= isl_map_is_single_valued(map
);
2116 isl_die(ctx
, isl_error_internal
,
2117 "map not detected as single valued", return -1);
2119 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
2120 map
= isl_map_read_from_str(ctx
, str
);
2121 sv
= isl_map_is_single_valued(map
);
2126 isl_die(ctx
, isl_error_internal
,
2127 "map detected as single valued", return -1);
2129 str
= "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
2130 umap
= isl_union_map_read_from_str(ctx
, str
);
2131 sv
= isl_union_map_is_single_valued(umap
);
2132 isl_union_map_free(umap
);
2136 isl_die(ctx
, isl_error_internal
,
2137 "map not detected as single valued", return -1);
2139 str
= "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
2140 umap
= isl_union_map_read_from_str(ctx
, str
);
2141 sv
= isl_union_map_is_single_valued(umap
);
2142 isl_union_map_free(umap
);
2146 isl_die(ctx
, isl_error_internal
,
2147 "map detected as single valued", return -1);
2152 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
2156 map
= isl_map_read_from_str(ctx
, str
);
2158 assert(isl_map_is_bijective(map
));
2160 assert(!isl_map_is_bijective(map
));
2164 void test_bijective(struct isl_ctx
*ctx
)
2166 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
2167 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
2168 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
2169 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
2170 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
2171 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
2172 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
2173 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
2174 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
2175 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
2176 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
2177 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
2178 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
2181 /* Inputs for isl_pw_qpolynomial_gist tests.
2182 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
2188 } pwqp_gist_tests
[] = {
2189 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
2190 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
2191 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
2192 "{ [i] -> -1/2 + 1/2 * i }" },
2193 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
2196 static int test_pwqp(struct isl_ctx
*ctx
)
2201 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
2204 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2205 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2207 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
2210 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2211 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2213 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2215 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2217 isl_pw_qpolynomial_free(pwqp1
);
2219 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
2220 str
= pwqp_gist_tests
[i
].pwqp
;
2221 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2222 str
= pwqp_gist_tests
[i
].set
;
2223 set
= isl_set_read_from_str(ctx
, str
);
2224 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2225 str
= pwqp_gist_tests
[i
].gist
;
2226 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2227 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2228 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
2229 isl_pw_qpolynomial_free(pwqp1
);
2234 isl_die(ctx
, isl_error_unknown
,
2235 "unexpected result", return -1);
2238 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
2239 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2240 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
2241 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2243 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2245 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2247 isl_pw_qpolynomial_free(pwqp1
);
2249 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
2250 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2251 str
= "{ [x] -> x }";
2252 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2254 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2256 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2258 isl_pw_qpolynomial_free(pwqp1
);
2260 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
2261 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2262 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2263 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
2264 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2265 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2266 isl_pw_qpolynomial_free(pwqp1
);
2268 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
2269 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2270 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2271 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2272 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
2273 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
2274 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2275 isl_pw_qpolynomial_free(pwqp1
);
2276 isl_pw_qpolynomial_free(pwqp2
);
2280 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2282 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
2283 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2284 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2285 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2286 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
2288 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2289 isl_pw_qpolynomial_free(pwqp1
);
2290 isl_pw_qpolynomial_free(pwqp2
);
2294 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2299 void test_split_periods(isl_ctx
*ctx
)
2302 isl_pw_qpolynomial
*pwqp
;
2304 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
2305 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
2306 "U >= 0; [U,V] -> U^2 : U >= 100 }";
2307 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2309 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
2312 isl_pw_qpolynomial_free(pwqp
);
2315 void test_union(isl_ctx
*ctx
)
2318 isl_union_set
*uset1
, *uset2
;
2319 isl_union_map
*umap1
, *umap2
;
2321 str
= "{ [i] : 0 <= i <= 1 }";
2322 uset1
= isl_union_set_read_from_str(ctx
, str
);
2323 str
= "{ [1] -> [0] }";
2324 umap1
= isl_union_map_read_from_str(ctx
, str
);
2326 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
2327 assert(isl_union_map_is_equal(umap1
, umap2
));
2329 isl_union_map_free(umap1
);
2330 isl_union_map_free(umap2
);
2332 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
2333 umap1
= isl_union_map_read_from_str(ctx
, str
);
2334 str
= "{ A[i]; B[i] }";
2335 uset1
= isl_union_set_read_from_str(ctx
, str
);
2337 uset2
= isl_union_map_domain(umap1
);
2339 assert(isl_union_set_is_equal(uset1
, uset2
));
2341 isl_union_set_free(uset1
);
2342 isl_union_set_free(uset2
);
2345 void test_bound(isl_ctx
*ctx
)
2348 isl_pw_qpolynomial
*pwqp
;
2349 isl_pw_qpolynomial_fold
*pwf
;
2351 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
2352 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2353 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2354 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 4);
2355 isl_pw_qpolynomial_fold_free(pwf
);
2357 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
2358 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2359 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2360 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 1);
2361 isl_pw_qpolynomial_fold_free(pwf
);
2364 void test_lift(isl_ctx
*ctx
)
2367 isl_basic_map
*bmap
;
2368 isl_basic_set
*bset
;
2370 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
2371 bset
= isl_basic_set_read_from_str(ctx
, str
);
2372 bset
= isl_basic_set_lift(bset
);
2373 bmap
= isl_basic_map_from_range(bset
);
2374 bset
= isl_basic_map_domain(bmap
);
2375 isl_basic_set_free(bset
);
2382 } subset_tests
[] = {
2384 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
2385 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
2386 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
2388 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
2389 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
2390 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
2391 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
2392 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
2393 "256e0 <= 255i and 256e0 >= -255 + 255i and "
2394 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
2395 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
2396 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
2397 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
2398 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
2399 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
2400 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
2401 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
2402 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
2403 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
2404 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
2405 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
2406 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
2407 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
2408 "4e0 <= -57 + i0 + i1)) or "
2409 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
2410 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
2411 "4e0 >= -61 + i0 + i1)) or "
2412 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
2415 static int test_subset(isl_ctx
*ctx
)
2418 isl_set
*set1
, *set2
;
2421 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
2422 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
2423 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
2424 subset
= isl_set_is_subset(set1
, set2
);
2429 if (subset
!= subset_tests
[i
].subset
)
2430 isl_die(ctx
, isl_error_unknown
,
2431 "incorrect subset result", return -1);
2438 const char *minuend
;
2439 const char *subtrahend
;
2440 const char *difference
;
2441 } subtract_domain_tests
[] = {
2442 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
2443 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
2444 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
2447 static int test_subtract(isl_ctx
*ctx
)
2450 isl_union_map
*umap1
, *umap2
;
2451 isl_union_set
*uset
;
2454 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2455 umap1
= isl_union_map_read_from_str(ctx
,
2456 subtract_domain_tests
[i
].minuend
);
2457 uset
= isl_union_set_read_from_str(ctx
,
2458 subtract_domain_tests
[i
].subtrahend
);
2459 umap2
= isl_union_map_read_from_str(ctx
,
2460 subtract_domain_tests
[i
].difference
);
2461 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
2462 equal
= isl_union_map_is_equal(umap1
, umap2
);
2463 isl_union_map_free(umap1
);
2464 isl_union_map_free(umap2
);
2468 isl_die(ctx
, isl_error_unknown
,
2469 "incorrect subtract domain result", return -1);
2475 int test_factorize(isl_ctx
*ctx
)
2478 isl_basic_set
*bset
;
2481 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2482 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2483 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2484 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2485 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2486 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2487 "3i5 >= -2i0 - i2 + 3i4 }";
2488 bset
= isl_basic_set_read_from_str(ctx
, str
);
2489 f
= isl_basic_set_factorizer(bset
);
2490 isl_basic_set_free(bset
);
2491 isl_factorizer_free(f
);
2493 isl_die(ctx
, isl_error_unknown
,
2494 "failed to construct factorizer", return -1);
2496 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2497 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2498 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2499 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2500 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2501 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2502 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2503 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2504 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2505 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2506 bset
= isl_basic_set_read_from_str(ctx
, str
);
2507 f
= isl_basic_set_factorizer(bset
);
2508 isl_basic_set_free(bset
);
2509 isl_factorizer_free(f
);
2511 isl_die(ctx
, isl_error_unknown
,
2512 "failed to construct factorizer", return -1);
2517 static int check_injective(__isl_take isl_map
*map
, void *user
)
2519 int *injective
= user
;
2521 *injective
= isl_map_is_injective(map
);
2524 if (*injective
< 0 || !*injective
)
2530 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
2531 const char *r
, const char *s
, int tilable
, int parallel
)
2535 isl_union_map
*W
, *R
, *S
;
2536 isl_union_map
*empty
;
2537 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
2538 isl_union_map
*validity
, *proximity
, *coincidence
;
2539 isl_union_map
*schedule
;
2540 isl_union_map
*test
;
2541 isl_union_set
*delta
;
2542 isl_union_set
*domain
;
2546 isl_schedule_constraints
*sc
;
2547 isl_schedule
*sched
;
2548 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
2550 D
= isl_union_set_read_from_str(ctx
, d
);
2551 W
= isl_union_map_read_from_str(ctx
, w
);
2552 R
= isl_union_map_read_from_str(ctx
, r
);
2553 S
= isl_union_map_read_from_str(ctx
, s
);
2555 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
2556 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
2558 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
2559 isl_union_map_compute_flow(isl_union_map_copy(R
),
2560 isl_union_map_copy(W
), empty
,
2561 isl_union_map_copy(S
),
2562 &dep_raw
, NULL
, NULL
, NULL
);
2563 isl_union_map_compute_flow(isl_union_map_copy(W
),
2564 isl_union_map_copy(W
),
2565 isl_union_map_copy(R
),
2566 isl_union_map_copy(S
),
2567 &dep_waw
, &dep_war
, NULL
, NULL
);
2569 dep
= isl_union_map_union(dep_waw
, dep_war
);
2570 dep
= isl_union_map_union(dep
, dep_raw
);
2571 validity
= isl_union_map_copy(dep
);
2572 coincidence
= isl_union_map_copy(dep
);
2573 proximity
= isl_union_map_copy(dep
);
2575 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
2576 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2577 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
2578 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2579 sched
= isl_schedule_constraints_compute_schedule(sc
);
2580 schedule
= isl_schedule_get_map(sched
);
2581 isl_schedule_free(sched
);
2582 isl_union_map_free(W
);
2583 isl_union_map_free(R
);
2584 isl_union_map_free(S
);
2587 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
2589 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
2590 is_complete
= isl_union_set_is_subset(D
, domain
);
2591 isl_union_set_free(D
);
2592 isl_union_set_free(domain
);
2594 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
2595 test
= isl_union_map_apply_range(test
, dep
);
2596 test
= isl_union_map_apply_range(test
, schedule
);
2598 delta
= isl_union_map_deltas(test
);
2599 if (isl_union_set_n_set(delta
) == 0) {
2603 isl_union_set_free(delta
);
2605 delta_set
= isl_set_from_union_set(delta
);
2607 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2608 for (i
= 0; i
< tilable
; ++i
)
2609 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
2610 is_tilable
= isl_set_is_subset(delta_set
, slice
);
2611 isl_set_free(slice
);
2613 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2614 for (i
= 0; i
< parallel
; ++i
)
2615 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
2616 is_parallel
= isl_set_is_subset(delta_set
, slice
);
2617 isl_set_free(slice
);
2619 origin
= isl_set_universe(isl_set_get_space(delta_set
));
2620 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
2621 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
2623 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
2624 delta_set
= isl_set_lexmin(delta_set
);
2626 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
2628 isl_set_free(origin
);
2629 isl_set_free(delta_set
);
2632 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
2633 is_injection
< 0 || is_complete
< 0)
2636 isl_die(ctx
, isl_error_unknown
,
2637 "generated schedule incomplete", return -1);
2639 isl_die(ctx
, isl_error_unknown
,
2640 "generated schedule not injective on each statement",
2643 isl_die(ctx
, isl_error_unknown
,
2644 "negative dependences in generated schedule",
2647 isl_die(ctx
, isl_error_unknown
,
2648 "generated schedule not as tilable as expected",
2651 isl_die(ctx
, isl_error_unknown
,
2652 "generated schedule not as parallel as expected",
2658 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
2659 const char *domain
, const char *validity
, const char *proximity
)
2663 isl_union_map
*prox
;
2664 isl_schedule_constraints
*sc
;
2665 isl_schedule
*schedule
;
2666 isl_union_map
*sched
;
2668 dom
= isl_union_set_read_from_str(ctx
, domain
);
2669 dep
= isl_union_map_read_from_str(ctx
, validity
);
2670 prox
= isl_union_map_read_from_str(ctx
, proximity
);
2671 sc
= isl_schedule_constraints_on_domain(dom
);
2672 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
2673 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
2674 schedule
= isl_schedule_constraints_compute_schedule(sc
);
2675 sched
= isl_schedule_get_map(schedule
);
2676 isl_schedule_free(schedule
);
2681 /* Check that a schedule can be constructed on the given domain
2682 * with the given validity and proximity constraints.
2684 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
2685 const char *validity
, const char *proximity
)
2687 isl_union_map
*sched
;
2689 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
2693 isl_union_map_free(sched
);
2697 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
2698 const char *validity
, const char *proximity
, const char *expected_sched
)
2700 isl_union_map
*sched1
, *sched2
;
2703 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
2704 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
2706 equal
= isl_union_map_is_equal(sched1
, sched2
);
2707 isl_union_map_free(sched1
);
2708 isl_union_map_free(sched2
);
2713 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
2719 /* Check that the schedule map is properly padded, even after being
2720 * reconstructed from the band forest.
2722 static int test_padded_schedule(isl_ctx
*ctx
)
2726 isl_union_map
*validity
, *proximity
;
2727 isl_schedule_constraints
*sc
;
2728 isl_schedule
*sched
;
2729 isl_union_map
*map1
, *map2
;
2730 isl_band_list
*list
;
2733 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
2734 D
= isl_union_set_read_from_str(ctx
, str
);
2735 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
2736 proximity
= isl_union_map_copy(validity
);
2737 sc
= isl_schedule_constraints_on_domain(D
);
2738 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2739 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2740 sched
= isl_schedule_constraints_compute_schedule(sc
);
2741 map1
= isl_schedule_get_map(sched
);
2742 list
= isl_schedule_get_band_forest(sched
);
2743 isl_band_list_free(list
);
2744 map2
= isl_schedule_get_map(sched
);
2745 isl_schedule_free(sched
);
2746 equal
= isl_union_map_is_equal(map1
, map2
);
2747 isl_union_map_free(map1
);
2748 isl_union_map_free(map2
);
2753 isl_die(ctx
, isl_error_unknown
,
2754 "reconstructed schedule map not the same as original",
2760 /* Input for testing of schedule construction based on
2761 * conditional constraints.
2763 * domain is the iteration domain
2764 * flow are the flow dependences, which determine the validity and
2765 * proximity constraints
2766 * condition are the conditions on the conditional validity constraints
2767 * conditional_validity are the conditional validity constraints
2768 * outer_band_n is the expected number of members in the outer band
2773 const char *condition
;
2774 const char *conditional_validity
;
2776 } live_range_tests
[] = {
2777 /* Contrived example that illustrates that we need to keep
2778 * track of tagged condition dependences and
2779 * tagged conditional validity dependences
2780 * in isl_sched_edge separately.
2781 * In particular, the conditional validity constraints on A
2782 * cannot be satisfied,
2783 * but they can be ignored because there are no corresponding
2784 * condition constraints. However, we do have an additional
2785 * conditional validity constraint that maps to the same
2786 * dependence relation
2787 * as the condition constraint on B. If we did not make a distinction
2788 * between tagged condition and tagged conditional validity
2789 * dependences, then we
2790 * could end up treating this shared dependence as an condition
2791 * constraint on A, forcing a localization of the conditions,
2792 * which is impossible.
2794 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
2795 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
2796 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
2797 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2798 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2799 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
2802 /* TACO 2013 Fig. 7 */
2803 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2804 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2805 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2806 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
2807 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
2808 "0 <= i < n and 0 <= j < n - 1 }",
2809 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
2810 "0 <= i < n and 0 <= j < j' < n;"
2811 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
2812 "0 <= i < i' < n and 0 <= j,j' < n;"
2813 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
2814 "0 <= i,j,j' < n and j < j' }",
2817 /* TACO 2013 Fig. 7, without tags */
2818 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2819 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2820 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2821 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2822 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2823 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
2824 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
2825 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
2828 /* TACO 2013 Fig. 12 */
2829 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
2830 "S3[i,3] : 0 <= i <= 1 }",
2831 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
2832 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
2833 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
2834 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
2835 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2836 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
2837 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2838 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
2839 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
2840 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
2841 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
2846 /* Test schedule construction based on conditional constraints.
2847 * In particular, check the number of members in the outer band
2848 * as an indication of whether tiling is possible or not.
2850 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
2853 isl_union_set
*domain
;
2854 isl_union_map
*condition
;
2855 isl_union_map
*flow
;
2856 isl_union_map
*validity
;
2857 isl_schedule_constraints
*sc
;
2858 isl_schedule
*schedule
;
2859 isl_band_list
*list
;
2863 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
2864 domain
= isl_union_set_read_from_str(ctx
,
2865 live_range_tests
[i
].domain
);
2866 flow
= isl_union_map_read_from_str(ctx
,
2867 live_range_tests
[i
].flow
);
2868 condition
= isl_union_map_read_from_str(ctx
,
2869 live_range_tests
[i
].condition
);
2870 validity
= isl_union_map_read_from_str(ctx
,
2871 live_range_tests
[i
].conditional_validity
);
2872 sc
= isl_schedule_constraints_on_domain(domain
);
2873 sc
= isl_schedule_constraints_set_validity(sc
,
2874 isl_union_map_copy(flow
));
2875 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
2876 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
2877 condition
, validity
);
2878 schedule
= isl_schedule_constraints_compute_schedule(sc
);
2879 list
= isl_schedule_get_band_forest(schedule
);
2880 band
= isl_band_list_get_band(list
, 0);
2881 n_member
= isl_band_n_member(band
);
2882 isl_band_free(band
);
2883 isl_band_list_free(list
);
2884 isl_schedule_free(schedule
);
2888 if (n_member
!= live_range_tests
[i
].outer_band_n
)
2889 isl_die(ctx
, isl_error_unknown
,
2890 "unexpected number of members in outer band",
2896 int test_schedule(isl_ctx
*ctx
)
2898 const char *D
, *W
, *R
, *V
, *P
, *S
;
2900 /* Handle resulting schedule with zero bands. */
2901 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
2905 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2906 W
= "{ S1[t,i] -> a[t,i] }";
2907 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2908 "S1[t,i] -> a[t-1,i+1] }";
2909 S
= "{ S1[t,i] -> [t,i] }";
2910 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2913 /* Fig. 5 of CC2008 */
2914 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2916 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2917 "j >= 2 and j <= -1 + N }";
2918 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2919 "j >= 2 and j <= -1 + N; "
2920 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2921 "j >= 2 and j <= -1 + N }";
2922 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2923 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2926 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2927 W
= "{ S1[i] -> a[i] }";
2928 R
= "{ S2[i] -> a[i+1] }";
2929 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2930 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2933 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2934 W
= "{ S1[i] -> a[i] }";
2935 R
= "{ S2[i] -> a[9-i] }";
2936 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2937 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2940 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2941 W
= "{ S1[i] -> a[i] }";
2942 R
= "[N] -> { S2[i] -> a[N-1-i] }";
2943 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2944 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2947 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2948 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2949 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2950 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2951 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2954 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2955 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2956 R
= "{ S2[i,j] -> a[i-1,j] }";
2957 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2958 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2961 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2962 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2963 R
= "{ S2[i,j] -> a[i,j-1] }";
2964 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2965 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2968 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2969 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2970 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2971 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2972 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2973 "S_0[] -> [0, 0, 0] }";
2974 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
2976 ctx
->opt
->schedule_parametric
= 0;
2977 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2979 ctx
->opt
->schedule_parametric
= 1;
2981 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2982 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2983 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2984 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2985 "S4[i] -> a[i,N] }";
2986 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2987 "S4[i] -> [4,i,0] }";
2988 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2991 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2992 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2994 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2996 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2998 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2999 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3002 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
3003 " S_2[t] : t >= 0 and t <= -1 + N; "
3004 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
3006 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
3007 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
3008 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
3009 "i >= 0 and i <= -1 + N }";
3010 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
3011 "i >= 0 and i <= -1 + N; "
3012 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
3013 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
3014 " S_0[t] -> [0, t, 0] }";
3016 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3018 ctx
->opt
->schedule_parametric
= 0;
3019 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3021 ctx
->opt
->schedule_parametric
= 1;
3023 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
3024 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
3025 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
3028 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
3029 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
3030 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
3031 "j >= 0 and j <= -1 + N; "
3032 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3033 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
3034 "j >= 0 and j <= -1 + N; "
3035 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3036 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
3037 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3040 D
= "{ S_0[i] : i >= 0 }";
3041 W
= "{ S_0[i] -> a[i] : i >= 0 }";
3042 R
= "{ S_0[i] -> a[0] : i >= 0 }";
3043 S
= "{ S_0[i] -> [0, i, 0] }";
3044 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3047 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
3048 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
3049 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
3050 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
3051 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3054 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
3055 "k <= -1 + n and k >= 0 }";
3056 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
3057 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
3058 "k <= -1 + n and k >= 0; "
3059 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
3060 "k <= -1 + n and k >= 0; "
3061 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
3062 "k <= -1 + n and k >= 0 }";
3063 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
3064 ctx
->opt
->schedule_outer_coincidence
= 1;
3065 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3067 ctx
->opt
->schedule_outer_coincidence
= 0;
3069 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
3070 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
3071 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
3072 "Stmt_for_body24[i0, i1, 1, 0]:"
3073 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
3074 "Stmt_for_body7[i0, i1, i2]:"
3075 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
3078 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
3079 "Stmt_for_body24[1, i1, i2, i3]:"
3080 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
3082 "Stmt_for_body24[0, i1, i2, i3] -> "
3083 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
3084 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
3086 "Stmt_for_body24[0, i1, i2, i3] ->"
3087 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
3088 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
3089 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
3090 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
3091 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
3092 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
3093 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
3094 "i1 <= 6 and i1 >= 0;"
3095 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
3096 "Stmt_for_body7[i0, i1, i2] -> "
3097 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
3098 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
3099 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
3100 "Stmt_for_body7[i0, i1, i2] -> "
3101 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
3102 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
3103 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
3105 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
3106 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
3107 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
3109 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3112 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
3113 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
3114 "j >= 1 and j <= 7;"
3115 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
3116 "j >= 1 and j <= 8 }";
3118 S
= "{ S_0[i, j] -> [i + j, j] }";
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
;
3124 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
3125 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
3126 "j >= 0 and j <= -1 + i }";
3127 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
3128 "i <= -1 + N and j >= 0;"
3129 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
3132 S
= "{ S_0[i, j] -> [i, j] }";
3133 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3134 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3136 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3138 /* Test both algorithms on a case with only proximity dependences. */
3139 D
= "{ S[i,j] : 0 <= i <= 10 }";
3141 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
3142 S
= "{ S[i, j] -> [j, i] }";
3143 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3144 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3146 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3147 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3150 D
= "{ A[a]; B[] }";
3152 P
= "{ A[a] -> B[] }";
3153 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3156 if (test_padded_schedule(ctx
) < 0)
3159 /* Check that check for progress is not confused by rational
3162 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
3163 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
3165 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
3166 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
3168 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3169 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3171 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3173 if (test_conditional_schedule_constraints(ctx
) < 0)
3179 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
3181 isl_union_map
*umap
;
3184 umap
= isl_union_map_read_from_str(ctx
, str
);
3185 test
= isl_union_map_plain_is_injective(umap
);
3186 isl_union_map_free(umap
);
3189 if (test
== injective
)
3192 isl_die(ctx
, isl_error_unknown
,
3193 "map not detected as injective", return -1);
3195 isl_die(ctx
, isl_error_unknown
,
3196 "map detected as injective", return -1);
3199 int test_injective(isl_ctx
*ctx
)
3203 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
3205 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
3207 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
3209 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
3211 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
3213 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
3215 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
3217 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
3220 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
3221 if (test_plain_injective(ctx
, str
, 1))
3223 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
3224 if (test_plain_injective(ctx
, str
, 0))
3230 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
3238 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
3239 equal
= isl_aff_plain_is_equal(aff
, aff2
);
3245 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
3249 equal
= aff_plain_is_equal(aff
, str
);
3253 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
3254 "result not as expected", return -1);
3259 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3260 __isl_take isl_aff
*aff2
);
3262 ['+'] = { &isl_aff_add
},
3263 ['-'] = { &isl_aff_sub
},
3264 ['*'] = { &isl_aff_mul
},
3265 ['/'] = { &isl_aff_div
},
3273 } aff_bin_tests
[] = {
3274 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
3275 "{ [i] -> [2i] }" },
3276 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
3278 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
3279 "{ [i] -> [2i] }" },
3280 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
3281 "{ [i] -> [2i] }" },
3282 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
3283 "{ [i] -> [i/2] }" },
3284 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
3286 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
3287 "{ [i] -> [NaN] }" },
3288 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
3289 "{ [i] -> [NaN] }" },
3290 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
3291 "{ [i] -> [NaN] }" },
3292 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
3293 "{ [i] -> [NaN] }" },
3294 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
3295 "{ [i] -> [NaN] }" },
3296 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
3297 "{ [i] -> [NaN] }" },
3298 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
3299 "{ [i] -> [NaN] }" },
3300 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
3301 "{ [i] -> [NaN] }" },
3302 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
3303 "{ [i] -> [NaN] }" },
3304 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
3305 "{ [i] -> [NaN] }" },
3306 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
3307 "{ [i] -> [NaN] }" },
3308 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
3309 "{ [i] -> [NaN] }" },
3312 /* Perform some basic tests of binary operations on isl_aff objects.
3314 static int test_bin_aff(isl_ctx
*ctx
)
3317 isl_aff
*aff1
, *aff2
, *res
;
3318 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3319 __isl_take isl_aff
*aff2
);
3322 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
3323 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
3324 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
3325 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
3326 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
3327 aff1
= fn(aff1
, aff2
);
3328 if (isl_aff_is_nan(res
))
3329 ok
= isl_aff_is_nan(aff1
);
3331 ok
= isl_aff_plain_is_equal(aff1
, res
);
3337 isl_die(ctx
, isl_error_unknown
,
3338 "unexpected result", return -1);
3344 int test_aff(isl_ctx
*ctx
)
3349 isl_local_space
*ls
;
3353 if (test_bin_aff(ctx
) < 0)
3356 space
= isl_space_set_alloc(ctx
, 0, 1);
3357 ls
= isl_local_space_from_space(space
);
3358 aff
= isl_aff_zero_on_domain(ls
);
3360 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3361 aff
= isl_aff_scale_down_ui(aff
, 3);
3362 aff
= isl_aff_floor(aff
);
3363 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3364 aff
= isl_aff_scale_down_ui(aff
, 2);
3365 aff
= isl_aff_floor(aff
);
3366 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3369 set
= isl_set_read_from_str(ctx
, str
);
3370 aff
= isl_aff_gist(aff
, set
);
3372 aff
= isl_aff_add_constant_si(aff
, -16);
3373 zero
= isl_aff_plain_is_zero(aff
);
3379 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3381 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
3382 aff
= isl_aff_scale_down_ui(aff
, 64);
3383 aff
= isl_aff_floor(aff
);
3384 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
3392 int test_dim_max(isl_ctx
*ctx
)
3396 isl_set
*set1
, *set2
;
3401 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
3402 set
= isl_set_read_from_str(ctx
, str
);
3403 pwaff
= isl_set_dim_max(set
, 0);
3404 set1
= isl_set_from_pw_aff(pwaff
);
3405 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
3406 set2
= isl_set_read_from_str(ctx
, str
);
3407 equal
= isl_set_is_equal(set1
, set2
);
3413 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3415 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
3416 set
= isl_set_read_from_str(ctx
, str
);
3417 pwaff
= isl_set_dim_max(set
, 0);
3418 set1
= isl_set_from_pw_aff(pwaff
);
3419 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3420 set2
= isl_set_read_from_str(ctx
, str
);
3421 equal
= isl_set_is_equal(set1
, set2
);
3427 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3429 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
3430 set
= isl_set_read_from_str(ctx
, str
);
3431 pwaff
= isl_set_dim_max(set
, 0);
3432 set1
= isl_set_from_pw_aff(pwaff
);
3433 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3434 set2
= isl_set_read_from_str(ctx
, str
);
3435 equal
= isl_set_is_equal(set1
, set2
);
3441 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3443 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
3444 "0 <= i < N and 0 <= j < M }";
3445 map
= isl_map_read_from_str(ctx
, str
);
3446 set
= isl_map_range(map
);
3448 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
3449 set1
= isl_set_from_pw_aff(pwaff
);
3450 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
3451 set2
= isl_set_read_from_str(ctx
, str
);
3452 equal
= isl_set_is_equal(set1
, set2
);
3456 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
3457 set1
= isl_set_from_pw_aff(pwaff
);
3458 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
3459 set2
= isl_set_read_from_str(ctx
, str
);
3460 if (equal
>= 0 && equal
)
3461 equal
= isl_set_is_equal(set1
, set2
);
3470 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3472 /* Check that solutions are properly merged. */
3473 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
3474 "c <= -1 + n - 4a - 2b and c >= -2b and "
3475 "4a >= -4 + n and c >= 0 }";
3476 set
= isl_set_read_from_str(ctx
, str
);
3477 pwaff
= isl_set_dim_min(set
, 2);
3478 set1
= isl_set_from_pw_aff(pwaff
);
3479 str
= "[n] -> { [(0)] : n >= 1 }";
3480 set2
= isl_set_read_from_str(ctx
, str
);
3481 equal
= isl_set_is_equal(set1
, set2
);
3488 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3490 /* Check that empty solution lie in the right space. */
3491 str
= "[n] -> { [t,a] : 1 = 0 }";
3492 set
= isl_set_read_from_str(ctx
, str
);
3493 pwaff
= isl_set_dim_max(set
, 0);
3494 set1
= isl_set_from_pw_aff(pwaff
);
3495 str
= "[n] -> { [t] : 1 = 0 }";
3496 set2
= isl_set_read_from_str(ctx
, str
);
3497 equal
= isl_set_is_equal(set1
, set2
);
3504 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3509 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
3511 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
3515 isl_pw_multi_aff
*pma2
;
3521 ctx
= isl_pw_multi_aff_get_ctx(pma
);
3522 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3523 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
3524 isl_pw_multi_aff_free(pma2
);
3529 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
3530 * represented by "str".
3532 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
3537 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
3541 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
3542 "result not as expected", return -1);
3546 /* Basic test for isl_pw_multi_aff_product.
3548 * Check that multiple pieces are properly handled.
3550 static int test_product_pma(isl_ctx
*ctx
)
3554 isl_pw_multi_aff
*pma1
, *pma2
;
3556 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
3557 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3558 str
= "{ C[] -> D[] }";
3559 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3560 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
3561 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
3562 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
3563 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
3564 isl_pw_multi_aff_free(pma1
);
3571 int test_product(isl_ctx
*ctx
)
3575 isl_union_set
*uset1
, *uset2
;
3579 set
= isl_set_read_from_str(ctx
, str
);
3580 set
= isl_set_product(set
, isl_set_copy(set
));
3581 ok
= isl_set_is_wrapping(set
);
3586 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3589 uset1
= isl_union_set_read_from_str(ctx
, str
);
3590 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
3591 str
= "{ [[] -> []] }";
3592 uset2
= isl_union_set_read_from_str(ctx
, str
);
3593 ok
= isl_union_set_is_equal(uset1
, uset2
);
3594 isl_union_set_free(uset1
);
3595 isl_union_set_free(uset2
);
3599 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3601 if (test_product_pma(ctx
) < 0)
3607 /* Check that two sets are not considered disjoint just because
3608 * they have a different set of (named) parameters.
3610 static int test_disjoint(isl_ctx
*ctx
)
3613 isl_set
*set
, *set2
;
3616 str
= "[n] -> { [[]->[]] }";
3617 set
= isl_set_read_from_str(ctx
, str
);
3618 str
= "{ [[]->[]] }";
3619 set2
= isl_set_read_from_str(ctx
, str
);
3620 disjoint
= isl_set_is_disjoint(set
, set2
);
3626 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3631 int test_equal(isl_ctx
*ctx
)
3634 isl_set
*set
, *set2
;
3638 set
= isl_set_read_from_str(ctx
, str
);
3640 set2
= isl_set_read_from_str(ctx
, str
);
3641 equal
= isl_set_is_equal(set
, set2
);
3647 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3652 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
3653 enum isl_dim_type type
, unsigned pos
, int fixed
)
3657 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
3664 isl_die(ctx
, isl_error_unknown
,
3665 "map not detected as fixed", return -1);
3667 isl_die(ctx
, isl_error_unknown
,
3668 "map detected as fixed", return -1);
3671 int test_fixed(isl_ctx
*ctx
)
3676 str
= "{ [i] -> [i] }";
3677 map
= isl_map_read_from_str(ctx
, str
);
3678 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
3680 str
= "{ [i] -> [1] }";
3681 map
= isl_map_read_from_str(ctx
, str
);
3682 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3684 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
3685 map
= isl_map_read_from_str(ctx
, str
);
3686 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3688 map
= isl_map_read_from_str(ctx
, str
);
3689 map
= isl_map_neg(map
);
3690 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3696 struct isl_vertices_test_data
{
3699 const char *vertex
[2];
3700 } vertices_tests
[] = {
3701 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
3702 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
3703 { "{ A[t, i] : t = 14 and i = 1 }",
3704 1, { "{ A[14, 1] }" } },
3707 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
3709 static int find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
3711 struct isl_vertices_test_data
*data
= user
;
3714 isl_basic_set
*bset
;
3715 isl_pw_multi_aff
*pma
;
3719 ctx
= isl_vertex_get_ctx(vertex
);
3720 bset
= isl_vertex_get_domain(vertex
);
3721 ma
= isl_vertex_get_expr(vertex
);
3722 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
3724 for (i
= 0; i
< data
->n
; ++i
) {
3725 isl_pw_multi_aff
*pma_i
;
3727 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
3728 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
3729 isl_pw_multi_aff_free(pma_i
);
3731 if (equal
< 0 || equal
)
3735 isl_pw_multi_aff_free(pma
);
3736 isl_vertex_free(vertex
);
3741 return equal
? 0 : - 1;
3744 int test_vertices(isl_ctx
*ctx
)
3748 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
3749 isl_basic_set
*bset
;
3750 isl_vertices
*vertices
;
3754 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
3755 vertices
= isl_basic_set_compute_vertices(bset
);
3756 n
= isl_vertices_get_n_vertices(vertices
);
3757 if (vertices_tests
[i
].n
!= n
)
3759 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
3760 &vertices_tests
[i
]) < 0)
3762 isl_vertices_free(vertices
);
3763 isl_basic_set_free(bset
);
3768 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
3775 int test_union_pw(isl_ctx
*ctx
)
3779 isl_union_set
*uset
;
3780 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
3782 str
= "{ [x] -> x^2 }";
3783 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
3784 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
3785 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
3786 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
3787 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
3788 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
3789 isl_union_pw_qpolynomial_free(upwqp1
);
3790 isl_union_pw_qpolynomial_free(upwqp2
);
3794 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3799 int test_output(isl_ctx
*ctx
)
3807 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
3808 pa
= isl_pw_aff_read_from_str(ctx
, str
);
3810 p
= isl_printer_to_str(ctx
);
3811 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
3812 p
= isl_printer_print_pw_aff(p
, pa
);
3813 s
= isl_printer_get_str(p
);
3814 isl_printer_free(p
);
3815 isl_pw_aff_free(pa
);
3819 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
3824 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3829 int test_sample(isl_ctx
*ctx
)
3832 isl_basic_set
*bset1
, *bset2
;
3835 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
3836 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
3837 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
3838 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
3839 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
3840 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
3841 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
3842 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
3843 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
3844 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
3845 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
3846 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
3847 "d - 1073741821e and "
3848 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
3849 "3j >= 1 - a + b + 2e and "
3850 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
3851 "3i <= 4 - a + 4b - e and "
3852 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
3853 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
3854 "c <= -1 + a and 3i >= -2 - a + 3e and "
3855 "1073741822e <= 1073741823 - a + 1073741822b + c and "
3856 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
3857 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
3858 "1073741823e >= 1 + 1073741823b - d and "
3859 "3i >= 1073741823b + c - 1073741823e - f and "
3860 "3i >= 1 + 2b + e + 3g }";
3861 bset1
= isl_basic_set_read_from_str(ctx
, str
);
3862 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
3863 empty
= isl_basic_set_is_empty(bset2
);
3864 subset
= isl_basic_set_is_subset(bset2
, bset1
);
3865 isl_basic_set_free(bset1
);
3866 isl_basic_set_free(bset2
);
3867 if (empty
< 0 || subset
< 0)
3870 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
3872 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
3877 int test_fixed_power(isl_ctx
*ctx
)
3885 str
= "{ [i] -> [i + 1] }";
3886 map
= isl_map_read_from_str(ctx
, str
);
3887 isl_int_set_si(exp
, 23);
3888 map
= isl_map_fixed_power(map
, exp
);
3889 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
3898 int test_slice(isl_ctx
*ctx
)
3904 str
= "{ [i] -> [j] }";
3905 map
= isl_map_read_from_str(ctx
, str
);
3906 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3907 equal
= map_check_equal(map
, "{ [i] -> [i] }");
3912 str
= "{ [i] -> [j] }";
3913 map
= isl_map_read_from_str(ctx
, str
);
3914 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3915 equal
= map_check_equal(map
, "{ [i] -> [j] }");
3920 str
= "{ [i] -> [j] }";
3921 map
= isl_map_read_from_str(ctx
, str
);
3922 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3923 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
3928 str
= "{ [i] -> [j] }";
3929 map
= isl_map_read_from_str(ctx
, str
);
3930 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3931 equal
= map_check_equal(map
, "{ [0] -> [j] }");
3936 str
= "{ [i] -> [j] }";
3937 map
= isl_map_read_from_str(ctx
, str
);
3938 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3939 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
3944 str
= "{ [i] -> [j] }";
3945 map
= isl_map_read_from_str(ctx
, str
);
3946 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3947 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
3955 int test_eliminate(isl_ctx
*ctx
)
3961 str
= "{ [i] -> [j] : i = 2j }";
3962 map
= isl_map_read_from_str(ctx
, str
);
3963 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
3964 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
3972 /* Check that isl_set_dim_residue_class detects that the values of j
3973 * in the set below are all odd and that it does not detect any spurious
3976 static int test_residue_class(isl_ctx
*ctx
)
3983 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
3984 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
3985 set
= isl_set_read_from_str(ctx
, str
);
3988 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
3990 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
3991 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
4000 int test_align_parameters(isl_ctx
*ctx
)
4004 isl_multi_aff
*ma1
, *ma2
;
4007 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
4008 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
4010 space
= isl_space_params_alloc(ctx
, 1);
4011 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
4012 ma1
= isl_multi_aff_align_params(ma1
, space
);
4014 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
4015 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
4017 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4019 isl_multi_aff_free(ma1
);
4020 isl_multi_aff_free(ma2
);
4025 isl_die(ctx
, isl_error_unknown
,
4026 "result not as expected", return -1);
4031 static int test_list(isl_ctx
*ctx
)
4033 isl_id
*a
, *b
, *c
, *d
, *id
;
4037 a
= isl_id_alloc(ctx
, "a", NULL
);
4038 b
= isl_id_alloc(ctx
, "b", NULL
);
4039 c
= isl_id_alloc(ctx
, "c", NULL
);
4040 d
= isl_id_alloc(ctx
, "d", NULL
);
4042 list
= isl_id_list_alloc(ctx
, 4);
4043 list
= isl_id_list_add(list
, a
);
4044 list
= isl_id_list_add(list
, b
);
4045 list
= isl_id_list_add(list
, c
);
4046 list
= isl_id_list_add(list
, d
);
4047 list
= isl_id_list_drop(list
, 1, 1);
4049 if (isl_id_list_n_id(list
) != 3) {
4050 isl_id_list_free(list
);
4051 isl_die(ctx
, isl_error_unknown
,
4052 "unexpected number of elements in list", return -1);
4055 id
= isl_id_list_get_id(list
, 0);
4058 id
= isl_id_list_get_id(list
, 1);
4061 id
= isl_id_list_get_id(list
, 2);
4065 isl_id_list_free(list
);
4068 isl_die(ctx
, isl_error_unknown
,
4069 "unexpected elements in list", return -1);
4074 const char *set_conversion_tests
[] = {
4075 "[N] -> { [i] : N - 1 <= 2 i <= N }",
4076 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
4077 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4078 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4081 /* Check that converting from isl_set to isl_pw_multi_aff and back
4082 * to isl_set produces the original isl_set.
4084 static int test_set_conversion(isl_ctx
*ctx
)
4088 isl_set
*set1
, *set2
;
4089 isl_pw_multi_aff
*pma
;
4092 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
4093 str
= set_conversion_tests
[i
];
4094 set1
= isl_set_read_from_str(ctx
, str
);
4095 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
4096 set2
= isl_set_from_pw_multi_aff(pma
);
4097 equal
= isl_set_is_equal(set1
, set2
);
4104 isl_die(ctx
, isl_error_unknown
, "bad conversion",
4111 /* Check that converting from isl_map to isl_pw_multi_aff and back
4112 * to isl_map produces the original isl_map.
4114 static int test_map_conversion(isl_ctx
*ctx
)
4117 isl_map
*map1
, *map2
;
4118 isl_pw_multi_aff
*pma
;
4121 str
= "{ [a, b, c, d] -> s0[a, b, e, f] : "
4122 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
4123 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
4124 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
4126 map1
= isl_map_read_from_str(ctx
, str
);
4127 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
4128 map2
= isl_map_from_pw_multi_aff(pma
);
4129 equal
= isl_map_is_equal(map1
, map2
);
4136 isl_die(ctx
, isl_error_unknown
, "bad conversion", return -1);
4141 static int test_conversion(isl_ctx
*ctx
)
4143 if (test_set_conversion(ctx
) < 0)
4145 if (test_map_conversion(ctx
) < 0)
4150 /* Check that isl_basic_map_curry does not modify input.
4152 static int test_curry(isl_ctx
*ctx
)
4155 isl_basic_map
*bmap1
, *bmap2
;
4158 str
= "{ [A[] -> B[]] -> C[] }";
4159 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
4160 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
4161 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
4162 isl_basic_map_free(bmap1
);
4163 isl_basic_map_free(bmap2
);
4168 isl_die(ctx
, isl_error_unknown
,
4169 "curried map should not be equal to original",
4179 } preimage_tests
[] = {
4180 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
4181 "{ A[j,i] -> B[i,j] }",
4182 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
4183 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4184 "{ A[a,b] -> B[a/2,b/6] }",
4185 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
4186 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4187 "{ A[a,b] -> B[a/2,b/6] }",
4188 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
4189 "exists i,j : a = 2 i and b = 6 j }" },
4190 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
4191 "[n] -> { : 0 <= n <= 100 }" },
4192 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4193 "{ A[a] -> B[2a] }",
4194 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
4195 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4196 "{ A[a] -> B[([a/2])] }",
4197 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
4198 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
4199 "{ A[a] -> B[a,a,a/3] }",
4200 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
4201 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
4202 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
4205 static int test_preimage_basic_set(isl_ctx
*ctx
)
4208 isl_basic_set
*bset1
, *bset2
;
4212 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
4213 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
4214 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
4215 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
4216 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
4217 equal
= isl_basic_set_is_equal(bset1
, bset2
);
4218 isl_basic_set_free(bset1
);
4219 isl_basic_set_free(bset2
);
4223 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4234 } preimage_domain_tests
[] = {
4235 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
4236 "{ A[j,i] -> B[i,j] }",
4237 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
4238 { "{ B[i] -> C[i]; D[i] -> E[i] }",
4239 "{ A[i] -> B[i + 1] }",
4240 "{ A[i] -> C[i + 1] }" },
4241 { "{ B[i] -> C[i]; B[i] -> E[i] }",
4242 "{ A[i] -> B[i + 1] }",
4243 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
4244 { "{ B[i] -> C[([i/2])] }",
4245 "{ A[i] -> B[2i] }",
4246 "{ A[i] -> C[i] }" },
4247 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
4248 "{ A[i] -> B[([i/5]), ([i/7])] }",
4249 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
4250 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
4251 "[N] -> { A[] -> B[([N/5])] }",
4252 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
4253 { "{ B[i] -> C[i] : exists a : i = 5 a }",
4254 "{ A[i] -> B[2i] }",
4255 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
4256 { "{ B[i] -> C[i] : exists a : i = 2 a; "
4257 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
4258 "{ A[i] -> B[2i] }",
4259 "{ A[i] -> C[2i] }" },
4262 static int test_preimage_union_map(isl_ctx
*ctx
)
4265 isl_union_map
*umap1
, *umap2
;
4269 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
4270 umap1
= isl_union_map_read_from_str(ctx
,
4271 preimage_domain_tests
[i
].map
);
4272 ma
= isl_multi_aff_read_from_str(ctx
,
4273 preimage_domain_tests
[i
].ma
);
4274 umap2
= isl_union_map_read_from_str(ctx
,
4275 preimage_domain_tests
[i
].res
);
4276 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
4277 equal
= isl_union_map_is_equal(umap1
, umap2
);
4278 isl_union_map_free(umap1
);
4279 isl_union_map_free(umap2
);
4283 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4290 static int test_preimage(isl_ctx
*ctx
)
4292 if (test_preimage_basic_set(ctx
) < 0)
4294 if (test_preimage_union_map(ctx
) < 0)
4304 } pullback_tests
[] = {
4305 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
4306 "{ A[a,b] -> C[b + 2a] }" },
4307 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
4308 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
4309 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
4310 "{ A[a] -> C[(a)/6] }" },
4311 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
4312 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
4313 "{ A[a] -> C[(2a)/3] }" },
4314 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
4315 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
4316 "{ A[i,j] -> C[i + j, i + j] }"},
4317 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
4318 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
4319 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
4322 static int test_pullback(isl_ctx
*ctx
)
4325 isl_multi_aff
*ma1
, *ma2
;
4329 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
4330 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
4331 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
4332 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
4333 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
4334 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4335 isl_multi_aff_free(ma1
);
4336 isl_multi_aff_free(ma2
);
4340 isl_die(ctx
, isl_error_unknown
, "bad pullback",
4347 /* Check that negation is printed correctly.
4349 static int test_ast(isl_ctx
*ctx
)
4351 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
4355 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4356 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4357 expr
= isl_ast_expr_add(expr1
, expr2
);
4358 expr
= isl_ast_expr_neg(expr
);
4359 str
= isl_ast_expr_to_str(expr
);
4360 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
4362 isl_ast_expr_free(expr
);
4367 isl_die(ctx
, isl_error_unknown
,
4368 "isl_ast_expr printed incorrectly", return -1);
4370 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4371 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4372 expr
= isl_ast_expr_add(expr1
, expr2
);
4373 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
4374 expr
= isl_ast_expr_sub(expr3
, expr
);
4375 str
= isl_ast_expr_to_str(expr
);
4376 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
4378 isl_ast_expr_free(expr
);
4383 isl_die(ctx
, isl_error_unknown
,
4384 "isl_ast_expr printed incorrectly", return -1);
4389 /* Check that isl_ast_build_expr_from_set returns a valid expression
4390 * for an empty set. Note that isl_ast_build_expr_from_set getting
4391 * called on an empty set probably indicates a bug in the caller.
4393 static int test_ast_build(isl_ctx
*ctx
)
4396 isl_ast_build
*build
;
4399 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4400 build
= isl_ast_build_from_context(set
);
4402 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
4403 expr
= isl_ast_build_expr_from_set(build
, set
);
4405 isl_ast_expr_free(expr
);
4406 isl_ast_build_free(build
);
4414 /* Internal data structure for before_for and after_for callbacks.
4416 * depth is the current depth
4417 * before is the number of times before_for has been called
4418 * after is the number of times after_for has been called
4420 struct isl_test_codegen_data
{
4426 /* This function is called before each for loop in the AST generated
4427 * from test_ast_gen1.
4429 * Increment the number of calls and the depth.
4430 * Check that the space returned by isl_ast_build_get_schedule_space
4431 * matches the target space of the schedule returned by
4432 * isl_ast_build_get_schedule.
4433 * Return an isl_id that is checked by the corresponding call
4436 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
4439 struct isl_test_codegen_data
*data
= user
;
4442 isl_union_map
*schedule
;
4443 isl_union_set
*uset
;
4448 ctx
= isl_ast_build_get_ctx(build
);
4450 if (data
->before
>= 3)
4451 isl_die(ctx
, isl_error_unknown
,
4452 "unexpected number of for nodes", return NULL
);
4453 if (data
->depth
>= 2)
4454 isl_die(ctx
, isl_error_unknown
,
4455 "unexpected depth", return NULL
);
4457 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
4461 schedule
= isl_ast_build_get_schedule(build
);
4462 uset
= isl_union_map_range(schedule
);
4465 if (isl_union_set_n_set(uset
) != 1) {
4466 isl_union_set_free(uset
);
4467 isl_die(ctx
, isl_error_unknown
,
4468 "expecting single range space", return NULL
);
4471 space
= isl_ast_build_get_schedule_space(build
);
4472 set
= isl_union_set_extract_set(uset
, space
);
4473 isl_union_set_free(uset
);
4474 empty
= isl_set_is_empty(set
);
4480 isl_die(ctx
, isl_error_unknown
,
4481 "spaces don't match", return NULL
);
4483 return isl_id_alloc(ctx
, name
, NULL
);
4486 /* This function is called after each for loop in the AST generated
4487 * from test_ast_gen1.
4489 * Increment the number of calls and decrement the depth.
4490 * Check that the annotation attached to the node matches
4491 * the isl_id returned by the corresponding call to before_for.
4493 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
4494 __isl_keep isl_ast_build
*build
, void *user
)
4496 struct isl_test_codegen_data
*data
= user
;
4504 if (data
->after
> data
->before
)
4505 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4506 "mismatch in number of for nodes",
4507 return isl_ast_node_free(node
));
4509 id
= isl_ast_node_get_annotation(node
);
4511 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4512 "missing annotation", return isl_ast_node_free(node
));
4514 name
= isl_id_get_name(id
);
4515 valid
= name
&& atoi(name
+ 1) == data
->depth
;
4519 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4520 "wrong annotation", return isl_ast_node_free(node
));
4525 /* Check that the before_each_for and after_each_for callbacks
4526 * are called for each for loop in the generated code,
4527 * that they are called in the right order and that the isl_id
4528 * returned from the before_each_for callback is attached to
4529 * the isl_ast_node passed to the corresponding after_each_for call.
4531 static int test_ast_gen1(isl_ctx
*ctx
)
4535 isl_union_map
*schedule
;
4536 isl_ast_build
*build
;
4538 struct isl_test_codegen_data data
;
4540 str
= "[N] -> { : N >= 10 }";
4541 set
= isl_set_read_from_str(ctx
, str
);
4542 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
4543 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
4544 schedule
= isl_union_map_read_from_str(ctx
, str
);
4549 build
= isl_ast_build_from_context(set
);
4550 build
= isl_ast_build_set_before_each_for(build
,
4551 &before_for
, &data
);
4552 build
= isl_ast_build_set_after_each_for(build
,
4554 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4555 isl_ast_build_free(build
);
4559 isl_ast_node_free(tree
);
4561 if (data
.before
!= 3 || data
.after
!= 3)
4562 isl_die(ctx
, isl_error_unknown
,
4563 "unexpected number of for nodes", return -1);
4568 /* Check that the AST generator handles domains that are integrally disjoint
4569 * but not ratinoally disjoint.
4571 static int test_ast_gen2(isl_ctx
*ctx
)
4575 isl_union_map
*schedule
;
4576 isl_union_map
*options
;
4577 isl_ast_build
*build
;
4580 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
4581 schedule
= isl_union_map_read_from_str(ctx
, str
);
4582 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4583 build
= isl_ast_build_from_context(set
);
4585 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
4586 options
= isl_union_map_read_from_str(ctx
, str
);
4587 build
= isl_ast_build_set_options(build
, options
);
4588 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4589 isl_ast_build_free(build
);
4592 isl_ast_node_free(tree
);
4597 /* Increment *user on each call.
4599 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
4600 __isl_keep isl_ast_build
*build
, void *user
)
4609 /* Test that unrolling tries to minimize the number of instances.
4610 * In particular, for the schedule given below, make sure it generates
4611 * 3 nodes (rather than 101).
4613 static int test_ast_gen3(isl_ctx
*ctx
)
4617 isl_union_map
*schedule
;
4618 isl_union_map
*options
;
4619 isl_ast_build
*build
;
4623 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
4624 schedule
= isl_union_map_read_from_str(ctx
, str
);
4625 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4627 str
= "{ [i] -> unroll[0] }";
4628 options
= isl_union_map_read_from_str(ctx
, str
);
4630 build
= isl_ast_build_from_context(set
);
4631 build
= isl_ast_build_set_options(build
, options
);
4632 build
= isl_ast_build_set_at_each_domain(build
,
4633 &count_domains
, &n_domain
);
4634 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4635 isl_ast_build_free(build
);
4639 isl_ast_node_free(tree
);
4642 isl_die(ctx
, isl_error_unknown
,
4643 "unexpected number of for nodes", return -1);
4648 /* Check that if the ast_build_exploit_nested_bounds options is set,
4649 * we do not get an outer if node in the generated AST,
4650 * while we do get such an outer if node if the options is not set.
4652 static int test_ast_gen4(isl_ctx
*ctx
)
4656 isl_union_map
*schedule
;
4657 isl_ast_build
*build
;
4659 enum isl_ast_node_type type
;
4662 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
4663 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
4665 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
4667 schedule
= isl_union_map_read_from_str(ctx
, str
);
4668 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4669 build
= isl_ast_build_from_context(set
);
4670 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4671 isl_ast_build_free(build
);
4675 type
= isl_ast_node_get_type(tree
);
4676 isl_ast_node_free(tree
);
4678 if (type
== isl_ast_node_if
)
4679 isl_die(ctx
, isl_error_unknown
,
4680 "not expecting if node", return -1);
4682 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
4684 schedule
= isl_union_map_read_from_str(ctx
, str
);
4685 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4686 build
= isl_ast_build_from_context(set
);
4687 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4688 isl_ast_build_free(build
);
4692 type
= isl_ast_node_get_type(tree
);
4693 isl_ast_node_free(tree
);
4695 if (type
!= isl_ast_node_if
)
4696 isl_die(ctx
, isl_error_unknown
,
4697 "expecting if node", return -1);
4699 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
4704 /* This function is called for each leaf in the AST generated
4705 * from test_ast_gen5.
4707 * We finalize the AST generation by extending the outer schedule
4708 * with a zero-dimensional schedule. If this results in any for loops,
4709 * then this means that we did not pass along enough information
4710 * about the outer schedule to the inner AST generation.
4712 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
4715 isl_union_map
*schedule
, *extra
;
4718 schedule
= isl_ast_build_get_schedule(build
);
4719 extra
= isl_union_map_copy(schedule
);
4720 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
4721 schedule
= isl_union_map_range_product(schedule
, extra
);
4722 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4723 isl_ast_build_free(build
);
4728 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
4729 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
4730 "code should not contain any for loop",
4731 return isl_ast_node_free(tree
));
4736 /* Check that we do not lose any information when going back and
4737 * forth between internal and external schedule.
4739 * In particular, we create an AST where we unroll the only
4740 * non-constant dimension in the schedule. We therefore do
4741 * not expect any for loops in the AST. However, older versions
4742 * of isl would not pass along enough information about the outer
4743 * schedule when performing an inner code generation from a create_leaf
4744 * callback, resulting in the inner code generation producing a for loop.
4746 static int test_ast_gen5(isl_ctx
*ctx
)
4750 isl_union_map
*schedule
, *options
;
4751 isl_ast_build
*build
;
4754 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
4755 schedule
= isl_union_map_read_from_str(ctx
, str
);
4757 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
4758 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
4759 options
= isl_union_map_read_from_str(ctx
, str
);
4761 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4762 build
= isl_ast_build_from_context(set
);
4763 build
= isl_ast_build_set_options(build
, options
);
4764 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
4765 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4766 isl_ast_build_free(build
);
4767 isl_ast_node_free(tree
);
4774 static int test_ast_gen(isl_ctx
*ctx
)
4776 if (test_ast_gen1(ctx
) < 0)
4778 if (test_ast_gen2(ctx
) < 0)
4780 if (test_ast_gen3(ctx
) < 0)
4782 if (test_ast_gen4(ctx
) < 0)
4784 if (test_ast_gen5(ctx
) < 0)
4789 /* Check if dropping output dimensions from an isl_pw_multi_aff
4792 static int test_pw_multi_aff(isl_ctx
*ctx
)
4795 isl_pw_multi_aff
*pma1
, *pma2
;
4798 str
= "{ [i,j] -> [i+j, 4i-j] }";
4799 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4800 str
= "{ [i,j] -> [4i-j] }";
4801 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4803 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
4805 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
4807 isl_pw_multi_aff_free(pma1
);
4808 isl_pw_multi_aff_free(pma2
);
4812 isl_die(ctx
, isl_error_unknown
,
4813 "expressions not equal", return -1);
4818 /* Check that we can properly parse multi piecewise affine expressions
4819 * where the piecewise affine expressions have different domains.
4821 static int test_multi_pw_aff(isl_ctx
*ctx
)
4824 isl_set
*dom
, *dom2
;
4825 isl_multi_pw_aff
*mpa1
, *mpa2
;
4830 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
4831 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
4832 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
4833 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
4834 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
4835 str
= "{ [i] -> [(i : i > 0), 2i] }";
4836 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
4838 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
4840 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
4841 dom
= isl_pw_aff_domain(pa
);
4842 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
4843 dom2
= isl_pw_aff_domain(pa
);
4844 equal_domain
= isl_set_is_equal(dom
, dom2
);
4848 isl_multi_pw_aff_free(mpa1
);
4849 isl_multi_pw_aff_free(mpa2
);
4854 isl_die(ctx
, isl_error_unknown
,
4855 "expressions not equal", return -1);
4857 if (equal_domain
< 0)
4860 isl_die(ctx
, isl_error_unknown
,
4861 "domains unexpectedly equal", return -1);
4866 /* This is a regression test for a bug where isl_basic_map_simplify
4867 * would end up in an infinite loop. In particular, we construct
4868 * an empty basic set that is not obviously empty.
4869 * isl_basic_set_is_empty marks the basic set as empty.
4870 * After projecting out i3, the variable can be dropped completely,
4871 * but isl_basic_map_simplify refrains from doing so if the basic set
4872 * is empty and would end up in an infinite loop if it didn't test
4873 * explicitly for empty basic maps in the outer loop.
4875 static int test_simplify(isl_ctx
*ctx
)
4878 isl_basic_set
*bset
;
4881 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
4882 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
4883 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
4885 bset
= isl_basic_set_read_from_str(ctx
, str
);
4886 empty
= isl_basic_set_is_empty(bset
);
4887 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
4888 isl_basic_set_free(bset
);
4892 isl_die(ctx
, isl_error_unknown
,
4893 "basic set should be empty", return -1);
4898 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
4899 * with gbr context would fail to disable the use of the shifted tableau
4900 * when transferring equalities for the input to the context, resulting
4901 * in invalid sample values.
4903 static int test_partial_lexmin(isl_ctx
*ctx
)
4906 isl_basic_set
*bset
;
4907 isl_basic_map
*bmap
;
4910 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
4911 bmap
= isl_basic_map_read_from_str(ctx
, str
);
4912 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
4913 bset
= isl_basic_set_read_from_str(ctx
, str
);
4914 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
4923 /* Check that the variable compression performed on the existentially
4924 * quantified variables inside isl_basic_set_compute_divs is not confused
4925 * by the implicit equalities among the parameters.
4927 static int test_compute_divs(isl_ctx
*ctx
)
4930 isl_basic_set
*bset
;
4933 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
4934 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
4935 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
4936 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
4937 bset
= isl_basic_set_read_from_str(ctx
, str
);
4938 set
= isl_basic_set_compute_divs(bset
);
4950 { "{ rat: [i] : 0 <= i <= 10 }",
4951 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
4952 { "{ rat: [i] : FALSE }",
4953 "{ rat: coefficients[[cst] -> [a]] }" },
4955 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
4962 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
4963 "{ rat: [i] : 0 <= i <= 10 }" },
4964 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
4966 { "{ rat: coefficients[[cst] -> [a]] }",
4967 "{ rat: [i] : FALSE }" },
4970 /* Test the basic functionality of isl_basic_set_coefficients and
4971 * isl_basic_set_solutions.
4973 static int test_dual(isl_ctx
*ctx
)
4977 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
4979 isl_basic_set
*bset1
, *bset2
;
4981 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
4982 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
4983 bset1
= isl_basic_set_coefficients(bset1
);
4984 equal
= isl_basic_set_is_equal(bset1
, bset2
);
4985 isl_basic_set_free(bset1
);
4986 isl_basic_set_free(bset2
);
4990 isl_die(ctx
, isl_error_unknown
,
4991 "incorrect dual", return -1);
4994 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
4996 isl_basic_set
*bset1
, *bset2
;
4998 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
4999 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
5000 bset1
= isl_basic_set_solutions(bset1
);
5001 equal
= isl_basic_set_is_equal(bset1
, bset2
);
5002 isl_basic_set_free(bset1
);
5003 isl_basic_set_free(bset2
);
5007 isl_die(ctx
, isl_error_unknown
,
5008 "incorrect dual", return -1);
5016 int (*fn
)(isl_ctx
*ctx
);
5018 { "dual", &test_dual
},
5019 { "dependence analysis", &test_flow
},
5020 { "val", &test_val
},
5021 { "compute divs", &test_compute_divs
},
5022 { "partial lexmin", &test_partial_lexmin
},
5023 { "simplify", &test_simplify
},
5024 { "curry", &test_curry
},
5025 { "piecewise multi affine expressions", &test_pw_multi_aff
},
5026 { "multi piecewise affine expressions", &test_multi_pw_aff
},
5027 { "conversion", &test_conversion
},
5028 { "list", &test_list
},
5029 { "align parameters", &test_align_parameters
},
5030 { "preimage", &test_preimage
},
5031 { "pullback", &test_pullback
},
5032 { "AST", &test_ast
},
5033 { "AST build", &test_ast_build
},
5034 { "AST generation", &test_ast_gen
},
5035 { "eliminate", &test_eliminate
},
5036 { "residue class", &test_residue_class
},
5037 { "div", &test_div
},
5038 { "slice", &test_slice
},
5039 { "fixed power", &test_fixed_power
},
5040 { "sample", &test_sample
},
5041 { "output", &test_output
},
5042 { "vertices", &test_vertices
},
5043 { "fixed", &test_fixed
},
5044 { "equal", &test_equal
},
5045 { "disjoint", &test_disjoint
},
5046 { "product", &test_product
},
5047 { "dim_max", &test_dim_max
},
5048 { "affine", &test_aff
},
5049 { "injective", &test_injective
},
5050 { "schedule", &test_schedule
},
5051 { "union_pw", &test_union_pw
},
5052 { "parse", &test_parse
},
5053 { "single-valued", &test_sv
},
5054 { "affine hull", &test_affine_hull
},
5055 { "coalesce", &test_coalesce
},
5056 { "factorize", &test_factorize
},
5057 { "subset", &test_subset
},
5058 { "subtract", &test_subtract
},
5059 { "lexmin", &test_lexmin
},
5060 { "min", &test_min
},
5061 { "gist", &test_gist
},
5062 { "piecewise quasi-polynomials", &test_pwqp
},
5068 struct isl_ctx
*ctx
;
5070 srcdir
= getenv("srcdir");
5073 ctx
= isl_ctx_alloc();
5074 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
5075 printf("%s\n", tests
[i
].name
);
5076 if (tests
[i
].fn(ctx
) < 0)
5082 test_split_periods(ctx
);
5084 test_bijective(ctx
);
5088 test_construction(ctx
);
5090 test_application(ctx
);
5091 test_convex_hull(ctx
);