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>
37 #include <isl/options.h>
39 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
43 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
46 char *pattern
= "%s/test_inputs/%s.%s";
48 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
50 filename
= isl_alloc_array(ctx
, char, length
);
55 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
60 void test_parse_map(isl_ctx
*ctx
, const char *str
)
64 map
= isl_map_read_from_str(ctx
, str
);
69 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
74 map
= isl_map_read_from_str(ctx
, str
);
75 map2
= isl_map_read_from_str(ctx
, str2
);
76 equal
= isl_map_is_equal(map
, map2
);
83 isl_die(ctx
, isl_error_unknown
, "maps not equal",
89 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
91 isl_pw_qpolynomial
*pwqp
;
93 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
95 isl_pw_qpolynomial_free(pwqp
);
98 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
102 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
104 isl_pw_aff_free(pwaff
);
107 int test_parse(struct isl_ctx
*ctx
)
110 const char *str
, *str2
;
112 str
= "{ [i] -> [-i] }";
113 map
= isl_map_read_from_str(ctx
, str
);
117 str
= "{ A[i] -> L[([i/3])] }";
118 map
= isl_map_read_from_str(ctx
, str
);
122 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
123 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
124 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
126 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
127 str2
= "{ [x, y] : 2y >= 6 - x }";
128 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
131 if (test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
132 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
134 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
135 if (test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }",
139 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
140 map
= isl_map_read_from_str(ctx
, str
);
141 str
= "{ [new, old] -> [o0, o1] : "
142 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
143 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
144 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
145 map2
= isl_map_read_from_str(ctx
, str
);
146 assert(isl_map_is_equal(map
, map2
));
150 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
151 map
= isl_map_read_from_str(ctx
, str
);
152 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
153 map2
= isl_map_read_from_str(ctx
, str
);
154 assert(isl_map_is_equal(map
, map2
));
158 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
159 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
160 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
163 str
= "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
164 str2
= "{ [i,j] -> [min(i,j)] }";
165 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
168 str
= "{ [i,j] : i != j }";
169 str2
= "{ [i,j] : i < j or i > j }";
170 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
173 str
= "{ [i,j] : (i+1)*2 >= j }";
174 str2
= "{ [i, j] : j <= 2 + 2i }";
175 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
178 str
= "{ [i] -> [i > 0 ? 4 : 5] }";
179 str2
= "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
180 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
183 str
= "[N=2,M] -> { [i=[(M+N)/4]] }";
184 str2
= "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
185 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
188 str
= "{ [x] : x >= 0 }";
189 str2
= "{ [x] : x-0 >= 0 }";
190 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
193 str
= "{ [i] : ((i > 10)) }";
194 str2
= "{ [i] : i >= 11 }";
195 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
198 str
= "{ [i] -> [0] }";
199 str2
= "{ [i] -> [0 * i] }";
200 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
203 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
204 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
205 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
206 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
208 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : (not false) }",
209 "{ [a] -> [b] : true }") < 0)
212 if (test_parse_map_equal(ctx
, "{ [i] : i/2 <= 5 }",
213 "{ [i] : i <= 10 }") < 0)
216 if (test_parse_map_equal(ctx
, "{Sym=[n] [i] : i <= n }",
217 "[n] -> { [i] : i <= n }") < 0)
220 if (test_parse_map_equal(ctx
, "{ [*] }", "{ [a] }") < 0)
223 if (test_parse_map_equal(ctx
, "{ [i] : 2*floor(i/2) = i }",
224 "{ [i] : exists a : i = 2 a }") < 0)
227 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : a = 5 implies b = 5 }",
228 "{ [a] -> [b] : a != 5 or b = 5 }") < 0)
231 if (test_parse_map_equal(ctx
, "{ [a] -> [a - 1 : a > 0] }",
232 "{ [a] -> [a - 1] : a > 0 }") < 0)
234 if (test_parse_map_equal(ctx
,
235 "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
236 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }") < 0)
238 if (test_parse_map_equal(ctx
,
239 "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
240 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
242 if (test_parse_map_equal(ctx
,
243 "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
244 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
246 if (test_parse_map_equal(ctx
,
247 "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
248 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
250 if (test_parse_map_equal(ctx
,
251 "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
252 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
258 void test_read(struct isl_ctx
*ctx
)
262 struct isl_basic_set
*bset1
, *bset2
;
263 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
265 filename
= get_filename(ctx
, "set", "omega");
267 input
= fopen(filename
, "r");
270 bset1
= isl_basic_set_read_from_file(ctx
, input
);
271 bset2
= isl_basic_set_read_from_str(ctx
, str
);
273 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
275 isl_basic_set_free(bset1
);
276 isl_basic_set_free(bset2
);
282 void test_bounded(struct isl_ctx
*ctx
)
287 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
288 bounded
= isl_set_is_bounded(set
);
292 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
293 bounded
= isl_set_is_bounded(set
);
297 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
298 bounded
= isl_set_is_bounded(set
);
303 /* Construct the basic set { [i] : 5 <= i <= N } */
304 void test_construction(struct isl_ctx
*ctx
)
309 struct isl_basic_set
*bset
;
310 struct isl_constraint
*c
;
314 dim
= isl_space_set_alloc(ctx
, 1, 1);
315 bset
= isl_basic_set_universe(isl_space_copy(dim
));
316 ls
= isl_local_space_from_space(dim
);
318 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
319 isl_int_set_si(v
, -1);
320 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
321 isl_int_set_si(v
, 1);
322 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
323 bset
= isl_basic_set_add_constraint(bset
, c
);
325 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
326 isl_int_set_si(v
, 1);
327 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
328 isl_int_set_si(v
, -5);
329 isl_constraint_set_constant(c
, v
);
330 bset
= isl_basic_set_add_constraint(bset
, c
);
332 isl_local_space_free(ls
);
333 isl_basic_set_free(bset
);
338 void test_dim(struct isl_ctx
*ctx
)
341 isl_map
*map1
, *map2
;
343 map1
= isl_map_read_from_str(ctx
,
344 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
345 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
346 map2
= isl_map_read_from_str(ctx
,
347 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
348 assert(isl_map_is_equal(map1
, map2
));
351 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
352 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
353 assert(isl_map_is_equal(map1
, map2
));
358 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
359 map1
= isl_map_read_from_str(ctx
, str
);
360 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
361 map2
= isl_map_read_from_str(ctx
, str
);
362 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
363 assert(isl_map_is_equal(map1
, map2
));
370 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
374 { &isl_val_neg
, "0", "0" },
375 { &isl_val_abs
, "0", "0" },
376 { &isl_val_2exp
, "0", "1" },
377 { &isl_val_floor
, "0", "0" },
378 { &isl_val_ceil
, "0", "0" },
379 { &isl_val_neg
, "1", "-1" },
380 { &isl_val_neg
, "-1", "1" },
381 { &isl_val_neg
, "1/2", "-1/2" },
382 { &isl_val_neg
, "-1/2", "1/2" },
383 { &isl_val_neg
, "infty", "-infty" },
384 { &isl_val_neg
, "-infty", "infty" },
385 { &isl_val_neg
, "NaN", "NaN" },
386 { &isl_val_abs
, "1", "1" },
387 { &isl_val_abs
, "-1", "1" },
388 { &isl_val_abs
, "1/2", "1/2" },
389 { &isl_val_abs
, "-1/2", "1/2" },
390 { &isl_val_abs
, "infty", "infty" },
391 { &isl_val_abs
, "-infty", "infty" },
392 { &isl_val_abs
, "NaN", "NaN" },
393 { &isl_val_floor
, "1", "1" },
394 { &isl_val_floor
, "-1", "-1" },
395 { &isl_val_floor
, "1/2", "0" },
396 { &isl_val_floor
, "-1/2", "-1" },
397 { &isl_val_floor
, "infty", "infty" },
398 { &isl_val_floor
, "-infty", "-infty" },
399 { &isl_val_floor
, "NaN", "NaN" },
400 { &isl_val_ceil
, "1", "1" },
401 { &isl_val_ceil
, "-1", "-1" },
402 { &isl_val_ceil
, "1/2", "1" },
403 { &isl_val_ceil
, "-1/2", "0" },
404 { &isl_val_ceil
, "infty", "infty" },
405 { &isl_val_ceil
, "-infty", "-infty" },
406 { &isl_val_ceil
, "NaN", "NaN" },
407 { &isl_val_2exp
, "-3", "1/8" },
408 { &isl_val_2exp
, "-1", "1/2" },
409 { &isl_val_2exp
, "1", "2" },
410 { &isl_val_2exp
, "2", "4" },
411 { &isl_val_2exp
, "3", "8" },
414 /* Perform some basic tests of unary operations on isl_val objects.
416 static int test_un_val(isl_ctx
*ctx
)
420 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
423 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
424 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
425 res
= isl_val_read_from_str(ctx
, val_un_tests
[i
].res
);
426 fn
= val_un_tests
[i
].op
;
428 if (isl_val_is_nan(res
))
429 ok
= isl_val_is_nan(v
);
431 ok
= isl_val_eq(v
, res
);
437 isl_die(ctx
, isl_error_unknown
,
438 "unexpected result", return -1);
445 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
446 __isl_take isl_val
*v2
);
448 ['+'] = { &isl_val_add
},
449 ['-'] = { &isl_val_sub
},
450 ['*'] = { &isl_val_mul
},
451 ['/'] = { &isl_val_div
},
452 ['g'] = { &isl_val_gcd
},
453 ['m'] = { &isl_val_min
},
454 ['M'] = { &isl_val_max
},
462 } val_bin_tests
[] = {
463 { "0", '+', "0", "0" },
464 { "1", '+', "0", "1" },
465 { "1", '+', "1", "2" },
466 { "1", '-', "1", "0" },
467 { "1", '*', "1", "1" },
468 { "1", '/', "1", "1" },
469 { "2", '*', "3", "6" },
470 { "2", '*', "1/2", "1" },
471 { "2", '*', "1/3", "2/3" },
472 { "2/3", '*', "3/5", "2/5" },
473 { "2/3", '*', "7/5", "14/15" },
474 { "2", '/', "1/2", "4" },
475 { "-2", '/', "-1/2", "4" },
476 { "-2", '/', "1/2", "-4" },
477 { "2", '/', "-1/2", "-4" },
478 { "2", '/', "2", "1" },
479 { "2", '/', "3", "2/3" },
480 { "2/3", '/', "5/3", "2/5" },
481 { "2/3", '/', "5/7", "14/15" },
482 { "0", '/', "0", "NaN" },
483 { "42", '/', "0", "NaN" },
484 { "-42", '/', "0", "NaN" },
485 { "infty", '/', "0", "NaN" },
486 { "-infty", '/', "0", "NaN" },
487 { "NaN", '/', "0", "NaN" },
488 { "0", '/', "NaN", "NaN" },
489 { "42", '/', "NaN", "NaN" },
490 { "-42", '/', "NaN", "NaN" },
491 { "infty", '/', "NaN", "NaN" },
492 { "-infty", '/', "NaN", "NaN" },
493 { "NaN", '/', "NaN", "NaN" },
494 { "0", '/', "infty", "0" },
495 { "42", '/', "infty", "0" },
496 { "-42", '/', "infty", "0" },
497 { "infty", '/', "infty", "NaN" },
498 { "-infty", '/', "infty", "NaN" },
499 { "NaN", '/', "infty", "NaN" },
500 { "0", '/', "-infty", "0" },
501 { "42", '/', "-infty", "0" },
502 { "-42", '/', "-infty", "0" },
503 { "infty", '/', "-infty", "NaN" },
504 { "-infty", '/', "-infty", "NaN" },
505 { "NaN", '/', "-infty", "NaN" },
506 { "1", '-', "1/3", "2/3" },
507 { "1/3", '+', "1/2", "5/6" },
508 { "1/2", '+', "1/2", "1" },
509 { "3/4", '-', "1/4", "1/2" },
510 { "1/2", '-', "1/3", "1/6" },
511 { "infty", '+', "42", "infty" },
512 { "infty", '+', "infty", "infty" },
513 { "42", '+', "infty", "infty" },
514 { "infty", '-', "infty", "NaN" },
515 { "infty", '*', "infty", "infty" },
516 { "infty", '*', "-infty", "-infty" },
517 { "-infty", '*', "infty", "-infty" },
518 { "-infty", '*', "-infty", "infty" },
519 { "0", '*', "infty", "NaN" },
520 { "1", '*', "infty", "infty" },
521 { "infty", '*', "0", "NaN" },
522 { "infty", '*', "42", "infty" },
523 { "42", '-', "infty", "-infty" },
524 { "infty", '+', "-infty", "NaN" },
525 { "4", 'g', "6", "2" },
526 { "5", 'g', "6", "1" },
527 { "42", 'm', "3", "3" },
528 { "42", 'M', "3", "42" },
529 { "3", 'm', "42", "3" },
530 { "3", 'M', "42", "42" },
531 { "42", 'm', "infty", "42" },
532 { "42", 'M', "infty", "infty" },
533 { "42", 'm', "-infty", "-infty" },
534 { "42", 'M', "-infty", "42" },
535 { "42", 'm', "NaN", "NaN" },
536 { "42", 'M', "NaN", "NaN" },
537 { "infty", 'm', "-infty", "-infty" },
538 { "infty", 'M', "-infty", "infty" },
541 /* Perform some basic tests of binary operations on isl_val objects.
543 static int test_bin_val(isl_ctx
*ctx
)
546 isl_val
*v1
, *v2
, *res
;
547 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
548 __isl_take isl_val
*v2
);
551 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
552 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
553 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
554 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
555 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
557 if (isl_val_is_nan(res
))
558 ok
= isl_val_is_nan(v1
);
560 ok
= isl_val_eq(v1
, res
);
566 isl_die(ctx
, isl_error_unknown
,
567 "unexpected result", return -1);
573 /* Perform some basic tests on isl_val objects.
575 static int test_val(isl_ctx
*ctx
)
577 if (test_un_val(ctx
) < 0)
579 if (test_bin_val(ctx
) < 0)
584 static int test_div(isl_ctx
*ctx
)
593 struct isl_basic_set
*bset
;
594 struct isl_constraint
*c
;
599 dim
= isl_space_set_alloc(ctx
, 0, 3);
600 bset
= isl_basic_set_universe(isl_space_copy(dim
));
601 ls
= isl_local_space_from_space(dim
);
603 c
= isl_equality_alloc(isl_local_space_copy(ls
));
604 isl_int_set_si(v
, -1);
605 isl_constraint_set_constant(c
, v
);
606 isl_int_set_si(v
, 1);
607 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
608 isl_int_set_si(v
, 3);
609 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
610 bset
= isl_basic_set_add_constraint(bset
, c
);
612 c
= isl_equality_alloc(isl_local_space_copy(ls
));
613 isl_int_set_si(v
, 1);
614 isl_constraint_set_constant(c
, v
);
615 isl_int_set_si(v
, -1);
616 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
617 isl_int_set_si(v
, 3);
618 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
619 bset
= isl_basic_set_add_constraint(bset
, c
);
621 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
623 assert(bset
&& bset
->n_div
== 1);
624 isl_local_space_free(ls
);
625 isl_basic_set_free(bset
);
628 dim
= isl_space_set_alloc(ctx
, 0, 3);
629 bset
= isl_basic_set_universe(isl_space_copy(dim
));
630 ls
= isl_local_space_from_space(dim
);
632 c
= isl_equality_alloc(isl_local_space_copy(ls
));
633 isl_int_set_si(v
, 1);
634 isl_constraint_set_constant(c
, v
);
635 isl_int_set_si(v
, -1);
636 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
637 isl_int_set_si(v
, 3);
638 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
639 bset
= isl_basic_set_add_constraint(bset
, c
);
641 c
= isl_equality_alloc(isl_local_space_copy(ls
));
642 isl_int_set_si(v
, -1);
643 isl_constraint_set_constant(c
, v
);
644 isl_int_set_si(v
, 1);
645 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
646 isl_int_set_si(v
, 3);
647 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
648 bset
= isl_basic_set_add_constraint(bset
, c
);
650 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
652 assert(bset
&& bset
->n_div
== 1);
653 isl_local_space_free(ls
);
654 isl_basic_set_free(bset
);
657 dim
= isl_space_set_alloc(ctx
, 0, 3);
658 bset
= isl_basic_set_universe(isl_space_copy(dim
));
659 ls
= isl_local_space_from_space(dim
);
661 c
= isl_equality_alloc(isl_local_space_copy(ls
));
662 isl_int_set_si(v
, 1);
663 isl_constraint_set_constant(c
, v
);
664 isl_int_set_si(v
, -1);
665 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
666 isl_int_set_si(v
, 3);
667 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
668 bset
= isl_basic_set_add_constraint(bset
, c
);
670 c
= isl_equality_alloc(isl_local_space_copy(ls
));
671 isl_int_set_si(v
, -3);
672 isl_constraint_set_constant(c
, v
);
673 isl_int_set_si(v
, 1);
674 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
675 isl_int_set_si(v
, 4);
676 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
677 bset
= isl_basic_set_add_constraint(bset
, c
);
679 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
681 assert(bset
&& bset
->n_div
== 1);
682 isl_local_space_free(ls
);
683 isl_basic_set_free(bset
);
686 dim
= isl_space_set_alloc(ctx
, 0, 3);
687 bset
= isl_basic_set_universe(isl_space_copy(dim
));
688 ls
= isl_local_space_from_space(dim
);
690 c
= isl_equality_alloc(isl_local_space_copy(ls
));
691 isl_int_set_si(v
, 2);
692 isl_constraint_set_constant(c
, v
);
693 isl_int_set_si(v
, -1);
694 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
695 isl_int_set_si(v
, 3);
696 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
697 bset
= isl_basic_set_add_constraint(bset
, c
);
699 c
= isl_equality_alloc(isl_local_space_copy(ls
));
700 isl_int_set_si(v
, -1);
701 isl_constraint_set_constant(c
, v
);
702 isl_int_set_si(v
, 1);
703 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
704 isl_int_set_si(v
, 6);
705 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
706 bset
= isl_basic_set_add_constraint(bset
, c
);
708 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
710 assert(isl_basic_set_is_empty(bset
));
711 isl_local_space_free(ls
);
712 isl_basic_set_free(bset
);
715 dim
= isl_space_set_alloc(ctx
, 0, 3);
716 bset
= isl_basic_set_universe(isl_space_copy(dim
));
717 ls
= isl_local_space_from_space(dim
);
719 c
= isl_equality_alloc(isl_local_space_copy(ls
));
720 isl_int_set_si(v
, -1);
721 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
722 isl_int_set_si(v
, 3);
723 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
724 bset
= isl_basic_set_add_constraint(bset
, c
);
726 c
= isl_equality_alloc(isl_local_space_copy(ls
));
727 isl_int_set_si(v
, 1);
728 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
729 isl_int_set_si(v
, -3);
730 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
731 bset
= isl_basic_set_add_constraint(bset
, c
);
733 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
735 assert(bset
&& bset
->n_div
== 0);
736 isl_basic_set_free(bset
);
737 isl_local_space_free(ls
);
740 dim
= isl_space_set_alloc(ctx
, 0, 3);
741 bset
= isl_basic_set_universe(isl_space_copy(dim
));
742 ls
= isl_local_space_from_space(dim
);
744 c
= isl_equality_alloc(isl_local_space_copy(ls
));
745 isl_int_set_si(v
, -1);
746 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
747 isl_int_set_si(v
, 6);
748 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
749 bset
= isl_basic_set_add_constraint(bset
, c
);
751 c
= isl_equality_alloc(isl_local_space_copy(ls
));
752 isl_int_set_si(v
, 1);
753 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
754 isl_int_set_si(v
, -3);
755 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
756 bset
= isl_basic_set_add_constraint(bset
, c
);
758 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
760 assert(bset
&& bset
->n_div
== 1);
761 isl_basic_set_free(bset
);
762 isl_local_space_free(ls
);
765 /* This test is a bit tricky. We set up an equality
767 * Normalization of divs creates _two_ divs
770 * Afterwards e0 is removed again because it has coefficient -1
771 * and we end up with the original equality and div again.
772 * Perhaps we can avoid the introduction of this temporary div.
774 dim
= isl_space_set_alloc(ctx
, 0, 4);
775 bset
= isl_basic_set_universe(isl_space_copy(dim
));
776 ls
= isl_local_space_from_space(dim
);
778 c
= isl_equality_alloc(isl_local_space_copy(ls
));
779 isl_int_set_si(v
, -1);
780 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
781 isl_int_set_si(v
, -3);
782 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
783 isl_int_set_si(v
, -3);
784 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
785 isl_int_set_si(v
, 6);
786 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
787 bset
= isl_basic_set_add_constraint(bset
, c
);
789 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
791 /* Test disabled for now */
793 assert(bset && bset->n_div == 1);
795 isl_local_space_free(ls
);
796 isl_basic_set_free(bset
);
799 dim
= isl_space_set_alloc(ctx
, 0, 5);
800 bset
= isl_basic_set_universe(isl_space_copy(dim
));
801 ls
= isl_local_space_from_space(dim
);
803 c
= isl_equality_alloc(isl_local_space_copy(ls
));
804 isl_int_set_si(v
, -1);
805 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
806 isl_int_set_si(v
, -3);
807 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
808 isl_int_set_si(v
, -3);
809 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
810 isl_int_set_si(v
, 6);
811 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
812 bset
= isl_basic_set_add_constraint(bset
, c
);
814 c
= isl_equality_alloc(isl_local_space_copy(ls
));
815 isl_int_set_si(v
, -1);
816 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
817 isl_int_set_si(v
, 1);
818 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
819 isl_int_set_si(v
, 1);
820 isl_constraint_set_constant(c
, v
);
821 bset
= isl_basic_set_add_constraint(bset
, c
);
823 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
825 /* Test disabled for now */
827 assert(bset && bset->n_div == 1);
829 isl_local_space_free(ls
);
830 isl_basic_set_free(bset
);
833 dim
= isl_space_set_alloc(ctx
, 0, 4);
834 bset
= isl_basic_set_universe(isl_space_copy(dim
));
835 ls
= isl_local_space_from_space(dim
);
837 c
= isl_equality_alloc(isl_local_space_copy(ls
));
838 isl_int_set_si(v
, 1);
839 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
840 isl_int_set_si(v
, -1);
841 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
842 isl_int_set_si(v
, -2);
843 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
844 bset
= isl_basic_set_add_constraint(bset
, c
);
846 c
= isl_equality_alloc(isl_local_space_copy(ls
));
847 isl_int_set_si(v
, -1);
848 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
849 isl_int_set_si(v
, 3);
850 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
851 isl_int_set_si(v
, 2);
852 isl_constraint_set_constant(c
, v
);
853 bset
= isl_basic_set_add_constraint(bset
, c
);
855 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
857 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
859 assert(!isl_basic_set_is_empty(bset
));
861 isl_local_space_free(ls
);
862 isl_basic_set_free(bset
);
865 dim
= isl_space_set_alloc(ctx
, 0, 3);
866 bset
= isl_basic_set_universe(isl_space_copy(dim
));
867 ls
= isl_local_space_from_space(dim
);
869 c
= isl_equality_alloc(isl_local_space_copy(ls
));
870 isl_int_set_si(v
, 1);
871 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
872 isl_int_set_si(v
, -2);
873 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
874 bset
= isl_basic_set_add_constraint(bset
, c
);
876 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
878 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
880 isl_local_space_free(ls
);
881 isl_basic_set_free(bset
);
885 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
886 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
887 set
= isl_set_read_from_str(ctx
, str
);
888 set
= isl_set_compute_divs(set
);
893 str
= "{ [i,j] : 2*[i/2] + 3 * [j/4] <= 10 and 2 i = j }";
894 bset
= isl_basic_set_read_from_str(ctx
, str
);
895 n
= isl_basic_set_dim(bset
, isl_dim_div
);
896 isl_basic_set_free(bset
);
900 isl_die(ctx
, isl_error_unknown
,
901 "expecting no existentials", return -1);
903 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
904 set
= isl_set_read_from_str(ctx
, str
);
905 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
906 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
907 empty
= isl_set_is_empty(set
);
912 isl_die(ctx
, isl_error_unknown
,
913 "result not as accurate as expected", return -1);
918 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
922 struct isl_basic_set
*bset1
, *bset2
;
923 struct isl_basic_map
*bmap
;
925 filename
= get_filename(ctx
, name
, "omega");
927 input
= fopen(filename
, "r");
930 bset1
= isl_basic_set_read_from_file(ctx
, input
);
931 bmap
= isl_basic_map_read_from_file(ctx
, input
);
933 bset1
= isl_basic_set_apply(bset1
, bmap
);
935 bset2
= isl_basic_set_read_from_file(ctx
, input
);
937 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
939 isl_basic_set_free(bset1
);
940 isl_basic_set_free(bset2
);
946 void test_application(struct isl_ctx
*ctx
)
948 test_application_case(ctx
, "application");
949 test_application_case(ctx
, "application2");
952 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
956 struct isl_basic_set
*bset1
, *bset2
;
958 filename
= get_filename(ctx
, name
, "polylib");
960 input
= fopen(filename
, "r");
963 bset1
= isl_basic_set_read_from_file(ctx
, input
);
964 bset2
= isl_basic_set_read_from_file(ctx
, input
);
966 bset1
= isl_basic_set_affine_hull(bset1
);
968 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
970 isl_basic_set_free(bset1
);
971 isl_basic_set_free(bset2
);
977 int test_affine_hull(struct isl_ctx
*ctx
)
981 isl_basic_set
*bset
, *bset2
;
985 test_affine_hull_case(ctx
, "affine2");
986 test_affine_hull_case(ctx
, "affine");
987 test_affine_hull_case(ctx
, "affine3");
989 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
990 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
991 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
992 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
993 set
= isl_set_read_from_str(ctx
, str
);
994 bset
= isl_set_affine_hull(set
);
995 n
= isl_basic_set_dim(bset
, isl_dim_div
);
996 isl_basic_set_free(bset
);
998 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1001 /* Check that isl_map_affine_hull is not confused by
1002 * the reordering of divs in isl_map_align_divs.
1004 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1005 "32e0 = b and 32e1 = c); "
1006 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1007 set
= isl_set_read_from_str(ctx
, str
);
1008 bset
= isl_set_affine_hull(set
);
1009 isl_basic_set_free(bset
);
1013 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1014 "32e2 = 31 + 31e0 }";
1015 set
= isl_set_read_from_str(ctx
, str
);
1016 bset
= isl_set_affine_hull(set
);
1017 str
= "{ [a] : exists e : a = 32 e }";
1018 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1019 subset
= isl_basic_set_is_subset(bset
, bset2
);
1020 isl_basic_set_free(bset
);
1021 isl_basic_set_free(bset2
);
1025 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1031 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1035 struct isl_basic_set
*bset1
, *bset2
;
1036 struct isl_set
*set
;
1038 filename
= get_filename(ctx
, name
, "polylib");
1040 input
= fopen(filename
, "r");
1043 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1044 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1046 set
= isl_basic_set_union(bset1
, bset2
);
1047 bset1
= isl_set_convex_hull(set
);
1049 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1051 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1053 isl_basic_set_free(bset1
);
1054 isl_basic_set_free(bset2
);
1063 } convex_hull_tests
[] = {
1064 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1065 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1066 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1067 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1068 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1069 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1070 "i2 <= 5 and i2 >= 4; "
1071 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1072 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1073 "i2 <= 5 + i0 and i2 >= i0 }" },
1074 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1075 "{ [x, y] : 1 = 0 }" },
1078 void test_convex_hull_algo(struct isl_ctx
*ctx
, int convex
)
1081 int orig_convex
= ctx
->opt
->convex
;
1082 ctx
->opt
->convex
= convex
;
1084 test_convex_hull_case(ctx
, "convex0");
1085 test_convex_hull_case(ctx
, "convex1");
1086 test_convex_hull_case(ctx
, "convex2");
1087 test_convex_hull_case(ctx
, "convex3");
1088 test_convex_hull_case(ctx
, "convex4");
1089 test_convex_hull_case(ctx
, "convex5");
1090 test_convex_hull_case(ctx
, "convex6");
1091 test_convex_hull_case(ctx
, "convex7");
1092 test_convex_hull_case(ctx
, "convex8");
1093 test_convex_hull_case(ctx
, "convex9");
1094 test_convex_hull_case(ctx
, "convex10");
1095 test_convex_hull_case(ctx
, "convex11");
1096 test_convex_hull_case(ctx
, "convex12");
1097 test_convex_hull_case(ctx
, "convex13");
1098 test_convex_hull_case(ctx
, "convex14");
1099 test_convex_hull_case(ctx
, "convex15");
1101 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1102 isl_set
*set1
, *set2
;
1104 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1105 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1106 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1107 assert(isl_set_is_equal(set1
, set2
));
1112 ctx
->opt
->convex
= orig_convex
;
1115 void test_convex_hull(struct isl_ctx
*ctx
)
1117 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
);
1118 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
);
1121 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1125 struct isl_basic_set
*bset1
, *bset2
;
1127 filename
= get_filename(ctx
, name
, "polylib");
1129 input
= fopen(filename
, "r");
1132 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1133 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1135 bset1
= isl_basic_set_gist(bset1
, bset2
);
1137 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1139 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1141 isl_basic_set_free(bset1
);
1142 isl_basic_set_free(bset2
);
1150 const char *context
;
1153 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1154 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1155 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1156 "{ [a, b, c] : a <= 15 }" },
1157 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1158 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1161 static int test_gist(struct isl_ctx
*ctx
)
1165 isl_basic_set
*bset1
, *bset2
;
1166 isl_map
*map1
, *map2
;
1169 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1170 bset1
= isl_basic_set_read_from_str(ctx
, gist_tests
[i
].set
);
1171 bset2
= isl_basic_set_read_from_str(ctx
, gist_tests
[i
].context
);
1172 bset1
= isl_basic_set_gist(bset1
, bset2
);
1173 bset2
= isl_basic_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1174 equal
= isl_basic_set_is_equal(bset1
, bset2
);
1175 isl_basic_set_free(bset1
);
1176 isl_basic_set_free(bset2
);
1180 isl_die(ctx
, isl_error_unknown
,
1181 "incorrect gist result", return -1);
1184 test_gist_case(ctx
, "gist1");
1186 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1187 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1188 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1189 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1190 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1191 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1192 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1193 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1194 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1195 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1196 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1197 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1198 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1199 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1200 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1201 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1202 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1203 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1204 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1205 bset1
= isl_basic_set_gist(bset1
, bset2
);
1206 assert(bset1
&& bset1
->n_div
== 0);
1207 isl_basic_set_free(bset1
);
1209 /* Check that the integer divisions of the second disjunct
1210 * do not spread to the first disjunct.
1212 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1213 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1214 "(exists (e0 = [(-1 + t1)/16], "
1215 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1216 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1217 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1218 "o0 <= 4294967295 and t1 <= -1)) }";
1219 map1
= isl_map_read_from_str(ctx
, str
);
1220 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1221 map2
= isl_map_read_from_str(ctx
, str
);
1222 map1
= isl_map_gist(map1
, map2
);
1226 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1227 isl_map_free(map1
); return -1);
1228 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1229 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1230 isl_map_free(map1
); return -1);
1236 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1238 isl_set
*set
, *set2
;
1242 set
= isl_set_read_from_str(ctx
, str
);
1243 set
= isl_set_coalesce(set
);
1244 set2
= isl_set_read_from_str(ctx
, str
);
1245 equal
= isl_set_is_equal(set
, set2
);
1246 one
= set
&& set
->n
== 1;
1253 isl_die(ctx
, isl_error_unknown
,
1254 "coalesced set not equal to input", return -1);
1255 if (check_one
&& !one
)
1256 isl_die(ctx
, isl_error_unknown
,
1257 "coalesced set should not be a union", return -1);
1262 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1267 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1268 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1270 if (test_coalesce_set(ctx
,
1271 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1272 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1273 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1274 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1275 "-10 <= y <= 0}", 1) < 0)
1277 if (test_coalesce_set(ctx
,
1278 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
1280 if (test_coalesce_set(ctx
,
1281 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
1289 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1294 /* Inputs for coalescing tests.
1295 * "str" is a string representation of the input set.
1296 * "single_disjunct" is set if we expect the result to consist of
1297 * a single disjunct.
1300 int single_disjunct
;
1302 } coalesce_tests
[] = {
1303 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1304 "y >= x & x >= 2 & 5 >= y }" },
1305 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1306 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1307 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1308 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1309 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1310 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1311 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1312 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1313 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1314 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1315 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1316 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1317 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1318 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1319 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1320 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1321 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1322 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1323 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1324 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1325 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1326 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1327 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1328 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1329 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1330 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1331 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1332 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1333 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1334 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1335 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1336 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1337 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1338 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1339 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1340 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1341 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1342 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1343 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1344 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1345 "[o0, o1, o2, o3, o4, o5, o6]] : "
1346 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1347 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1348 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1349 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1350 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1351 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1352 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1353 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1354 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1355 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1356 "o6 >= i3 + i6 - o3 and M >= 0 and "
1357 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1358 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1359 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1360 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1361 "(o0 = 0 and M >= 2 and N >= 3) or "
1362 "(M = 0 and o0 = 0 and N >= 3) }" },
1363 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1364 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1365 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1366 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1367 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1368 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1369 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1370 "(y = 3 and x = 1) }" },
1371 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1372 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1373 "i1 <= M and i3 <= M and i4 <= M) or "
1374 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1375 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1376 "i4 <= -1 + M) }" },
1377 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1378 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1379 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1380 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1381 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1382 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1383 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1384 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1385 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1386 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1387 { 0, "{ [a, b] : exists e : 2e = a and "
1388 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1389 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1390 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1391 "j >= 1 and j' <= i + j - i' and i >= 1; "
1393 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1394 "[i,j] : exists a : j = 3a }" },
1395 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1396 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1398 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1399 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1400 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1401 "c <= 6 + 8a and a >= 3; "
1402 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1403 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1404 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1405 "[x,0] : 3 <= x <= 4 }" },
1406 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1407 "[x,0] : 4 <= x <= 5 }" },
1408 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1409 "[x,0] : 3 <= x <= 5 }" },
1410 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1411 "[x,0] : 3 <= x <= 4 }" },
1412 { 1 , "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1414 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1417 /* Test the functionality of isl_set_coalesce.
1418 * That is, check that the output is always equal to the input
1419 * and in some cases that the result consists of a single disjunct.
1421 static int test_coalesce(struct isl_ctx
*ctx
)
1425 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
1426 const char *str
= coalesce_tests
[i
].str
;
1427 int check_one
= coalesce_tests
[i
].single_disjunct
;
1428 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
1432 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
1438 void test_closure(struct isl_ctx
*ctx
)
1442 isl_map
*up
, *right
;
1443 isl_map
*map
, *map2
;
1446 /* COCOA example 1 */
1447 map
= isl_map_read_from_str(ctx
,
1448 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1449 "1 <= i and i < n and 1 <= j and j < n or "
1450 "i2 = i + 1 and j2 = j - 1 and "
1451 "1 <= i and i < n and 2 <= j and j <= n }");
1452 map
= isl_map_power(map
, &exact
);
1456 /* COCOA example 1 */
1457 map
= isl_map_read_from_str(ctx
,
1458 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1459 "1 <= i and i < n and 1 <= j and j < n or "
1460 "i2 = i + 1 and j2 = j - 1 and "
1461 "1 <= i and i < n and 2 <= j and j <= n }");
1462 map
= isl_map_transitive_closure(map
, &exact
);
1464 map2
= isl_map_read_from_str(ctx
,
1465 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1466 "1 <= i and i < n and 1 <= j and j <= n and "
1467 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1468 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1469 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1470 assert(isl_map_is_equal(map
, map2
));
1474 map
= isl_map_read_from_str(ctx
,
1475 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1476 " 0 <= y and y <= n }");
1477 map
= isl_map_transitive_closure(map
, &exact
);
1478 map2
= isl_map_read_from_str(ctx
,
1479 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1480 " 0 <= y and y <= n }");
1481 assert(isl_map_is_equal(map
, map2
));
1485 /* COCOA example 2 */
1486 map
= isl_map_read_from_str(ctx
,
1487 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1488 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1489 "i2 = i + 2 and j2 = j - 2 and "
1490 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1491 map
= isl_map_transitive_closure(map
, &exact
);
1493 map2
= isl_map_read_from_str(ctx
,
1494 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1495 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1496 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1497 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1498 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1499 assert(isl_map_is_equal(map
, map2
));
1503 /* COCOA Fig.2 left */
1504 map
= isl_map_read_from_str(ctx
,
1505 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1506 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1508 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1509 "j <= 2 i - 3 and j <= n - 2 or "
1510 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1511 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1512 map
= isl_map_transitive_closure(map
, &exact
);
1516 /* COCOA Fig.2 right */
1517 map
= isl_map_read_from_str(ctx
,
1518 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1519 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1521 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1522 "j <= 2 i - 4 and j <= n - 3 or "
1523 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1524 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1525 map
= isl_map_power(map
, &exact
);
1529 /* COCOA Fig.2 right */
1530 map
= isl_map_read_from_str(ctx
,
1531 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1532 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1534 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1535 "j <= 2 i - 4 and j <= n - 3 or "
1536 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1537 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1538 map
= isl_map_transitive_closure(map
, &exact
);
1540 map2
= isl_map_read_from_str(ctx
,
1541 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1542 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1543 "j <= n and 3 + i + 2 j <= 3 n and "
1544 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1545 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1546 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1547 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1548 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1549 assert(isl_map_is_equal(map
, map2
));
1553 /* COCOA Fig.1 right */
1554 dom
= isl_set_read_from_str(ctx
,
1555 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1556 "2 x - 3 y + 3 >= 0 }");
1557 right
= isl_map_read_from_str(ctx
,
1558 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1559 up
= isl_map_read_from_str(ctx
,
1560 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1561 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1562 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1563 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1564 up
= isl_map_intersect_range(up
, dom
);
1565 map
= isl_map_union(up
, right
);
1566 map
= isl_map_transitive_closure(map
, &exact
);
1568 map2
= isl_map_read_from_str(ctx
,
1569 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1570 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1571 assert(isl_map_is_equal(map
, map2
));
1575 /* COCOA Theorem 1 counter example */
1576 map
= isl_map_read_from_str(ctx
,
1577 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1578 "i2 = 1 and j2 = j or "
1579 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1580 map
= isl_map_transitive_closure(map
, &exact
);
1584 map
= isl_map_read_from_str(ctx
,
1585 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1586 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1587 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1588 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1589 map
= isl_map_transitive_closure(map
, &exact
);
1593 /* Kelly et al 1996, fig 12 */
1594 map
= isl_map_read_from_str(ctx
,
1595 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1596 "1 <= i,j,j+1 <= n or "
1597 "j = n and j2 = 1 and i2 = i + 1 and "
1598 "1 <= i,i+1 <= n }");
1599 map
= isl_map_transitive_closure(map
, &exact
);
1601 map2
= isl_map_read_from_str(ctx
,
1602 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1603 "1 <= i <= n and i = i2 or "
1604 "1 <= i < i2 <= n and 1 <= j <= n and "
1606 assert(isl_map_is_equal(map
, map2
));
1610 /* Omega's closure4 */
1611 map
= isl_map_read_from_str(ctx
,
1612 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1613 "1 <= x,y <= 10 or "
1614 "x2 = x + 1 and y2 = y and "
1615 "1 <= x <= 20 && 5 <= y <= 15 }");
1616 map
= isl_map_transitive_closure(map
, &exact
);
1620 map
= isl_map_read_from_str(ctx
,
1621 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1622 map
= isl_map_transitive_closure(map
, &exact
);
1624 map2
= isl_map_read_from_str(ctx
,
1625 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1626 assert(isl_map_is_equal(map
, map2
));
1630 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1631 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1632 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1633 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1634 map
= isl_map_read_from_str(ctx
, str
);
1635 map
= isl_map_transitive_closure(map
, &exact
);
1637 map2
= isl_map_read_from_str(ctx
, str
);
1638 assert(isl_map_is_equal(map
, map2
));
1642 str
= "{[0] -> [1]; [2] -> [3]}";
1643 map
= isl_map_read_from_str(ctx
, str
);
1644 map
= isl_map_transitive_closure(map
, &exact
);
1646 map2
= isl_map_read_from_str(ctx
, str
);
1647 assert(isl_map_is_equal(map
, map2
));
1651 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1652 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1653 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1654 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1655 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1656 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1657 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1658 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1659 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1660 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1661 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1662 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1663 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1664 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1665 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1666 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1667 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1668 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1669 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1670 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1671 map
= isl_map_read_from_str(ctx
, str
);
1672 map
= isl_map_transitive_closure(map
, NULL
);
1677 void test_lex(struct isl_ctx
*ctx
)
1682 dim
= isl_space_set_alloc(ctx
, 0, 0);
1683 map
= isl_map_lex_le(dim
);
1684 assert(!isl_map_is_empty(map
));
1688 static int test_lexmin(struct isl_ctx
*ctx
)
1692 isl_basic_map
*bmap
;
1693 isl_map
*map
, *map2
;
1696 isl_pw_multi_aff
*pma
;
1698 str
= "[p0, p1] -> { [] -> [] : "
1699 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1700 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1701 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1702 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1703 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1704 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1705 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1706 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1707 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1708 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1709 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1710 map
= isl_map_read_from_str(ctx
, str
);
1711 map
= isl_map_lexmin(map
);
1714 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1715 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1716 set
= isl_set_read_from_str(ctx
, str
);
1717 set
= isl_set_lexmax(set
);
1718 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1719 set2
= isl_set_read_from_str(ctx
, str
);
1720 set
= isl_set_intersect(set
, set2
);
1721 assert(!isl_set_is_empty(set
));
1724 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1725 map
= isl_map_read_from_str(ctx
, str
);
1726 map
= isl_map_lexmin(map
);
1727 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1728 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1729 map2
= isl_map_read_from_str(ctx
, str
);
1730 assert(isl_map_is_equal(map
, map2
));
1734 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1735 map
= isl_map_read_from_str(ctx
, str
);
1736 map2
= isl_map_copy(map
);
1737 map
= isl_map_lexmin(map
);
1738 assert(isl_map_is_equal(map
, map2
));
1742 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1743 map
= isl_map_read_from_str(ctx
, str
);
1744 map
= isl_map_lexmin(map
);
1745 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1746 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1747 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1748 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1749 map2
= isl_map_read_from_str(ctx
, str
);
1750 assert(isl_map_is_equal(map
, map2
));
1754 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1755 " 8i' <= i and 8i' >= -7 + i }";
1756 bmap
= isl_basic_map_read_from_str(ctx
, str
);
1757 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
1758 map2
= isl_map_from_pw_multi_aff(pma
);
1759 map
= isl_map_from_basic_map(bmap
);
1760 assert(isl_map_is_equal(map
, map2
));
1764 str
= "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1765 map
= isl_map_read_from_str(ctx
, str
);
1766 map
= isl_map_lexmin(map
);
1767 str
= "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1768 map2
= isl_map_read_from_str(ctx
, str
);
1769 assert(isl_map_is_equal(map
, map2
));
1773 /* Check that empty pieces are properly combined. */
1774 str
= "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
1775 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
1776 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }";
1777 map
= isl_map_read_from_str(ctx
, str
);
1778 map
= isl_map_lexmin(map
);
1779 str
= "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
1780 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
1782 map2
= isl_map_read_from_str(ctx
, str
);
1783 assert(isl_map_is_equal(map
, map2
));
1787 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1788 " 8i' <= i and 8i' >= -7 + i }";
1789 set
= isl_set_read_from_str(ctx
, str
);
1790 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
1791 set2
= isl_set_from_pw_multi_aff(pma
);
1792 equal
= isl_set_is_equal(set
, set2
);
1798 isl_die(ctx
, isl_error_unknown
,
1799 "unexpected difference between set and "
1800 "piecewise affine expression", return -1);
1805 /* Check that isl_set_min_val and isl_set_max_val compute the correct
1806 * result on non-convex inputs.
1808 static int test_min(struct isl_ctx
*ctx
)
1815 set
= isl_set_read_from_str(ctx
, "{ [-1]; [1] }");
1816 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x] }");
1817 val
= isl_set_min_val(set
, aff
);
1818 min_ok
= isl_val_is_negone(val
);
1820 val
= isl_set_max_val(set
, aff
);
1821 max_ok
= isl_val_is_one(val
);
1826 if (min_ok
< 0 || max_ok
< 0)
1829 isl_die(ctx
, isl_error_unknown
,
1830 "unexpected minimum", return -1);
1832 isl_die(ctx
, isl_error_unknown
,
1833 "unexpected maximum", return -1);
1843 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1844 void *dep_user
, void *user
)
1846 struct must_may
*mm
= (struct must_may
*)user
;
1849 mm
->must
= isl_map_union(mm
->must
, dep
);
1851 mm
->may
= isl_map_union(mm
->may
, dep
);
1856 static int common_space(void *first
, void *second
)
1858 int depth
= *(int *)first
;
1862 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1870 map2
= isl_map_read_from_str(map
->ctx
, str
);
1871 equal
= isl_map_is_equal(map
, map2
);
1877 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
1881 equal
= map_is_equal(map
, str
);
1885 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
1886 "result not as expected", return -1);
1890 void test_dep(struct isl_ctx
*ctx
)
1895 isl_access_info
*ai
;
1902 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1903 map
= isl_map_read_from_str(ctx
, str
);
1904 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1906 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1907 map
= isl_map_read_from_str(ctx
, str
);
1908 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1910 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1911 map
= isl_map_read_from_str(ctx
, str
);
1912 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1914 flow
= isl_access_info_compute_flow(ai
);
1915 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1916 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1917 mm
.may
= isl_map_empty(dim
);
1919 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1921 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1922 " [1,10,0] -> [2,5,0] }";
1923 assert(map_is_equal(mm
.must
, str
));
1924 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1925 assert(map_is_equal(mm
.may
, str
));
1927 isl_map_free(mm
.must
);
1928 isl_map_free(mm
.may
);
1929 isl_flow_free(flow
);
1932 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1933 map
= isl_map_read_from_str(ctx
, str
);
1934 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1936 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1937 map
= isl_map_read_from_str(ctx
, str
);
1938 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1940 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1941 map
= isl_map_read_from_str(ctx
, str
);
1942 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1944 flow
= isl_access_info_compute_flow(ai
);
1945 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1946 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1947 mm
.may
= isl_map_empty(dim
);
1949 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1951 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1952 assert(map_is_equal(mm
.must
, str
));
1953 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1954 assert(map_is_equal(mm
.may
, str
));
1956 isl_map_free(mm
.must
);
1957 isl_map_free(mm
.may
);
1958 isl_flow_free(flow
);
1961 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1962 map
= isl_map_read_from_str(ctx
, str
);
1963 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1965 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1966 map
= isl_map_read_from_str(ctx
, str
);
1967 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1969 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1970 map
= isl_map_read_from_str(ctx
, str
);
1971 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1973 flow
= isl_access_info_compute_flow(ai
);
1974 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1975 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1976 mm
.may
= isl_map_empty(dim
);
1978 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1980 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1981 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1982 assert(map_is_equal(mm
.may
, str
));
1983 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1984 assert(map_is_equal(mm
.must
, str
));
1986 isl_map_free(mm
.must
);
1987 isl_map_free(mm
.may
);
1988 isl_flow_free(flow
);
1991 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1992 map
= isl_map_read_from_str(ctx
, str
);
1993 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1995 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1996 map
= isl_map_read_from_str(ctx
, str
);
1997 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1999 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
2000 map
= isl_map_read_from_str(ctx
, str
);
2001 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2003 flow
= isl_access_info_compute_flow(ai
);
2004 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2005 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2006 mm
.may
= isl_map_empty(dim
);
2008 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2010 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2011 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2012 assert(map_is_equal(mm
.may
, str
));
2013 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2014 assert(map_is_equal(mm
.must
, str
));
2016 isl_map_free(mm
.must
);
2017 isl_map_free(mm
.may
);
2018 isl_flow_free(flow
);
2021 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2022 map
= isl_map_read_from_str(ctx
, str
);
2023 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2025 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2026 map
= isl_map_read_from_str(ctx
, str
);
2027 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2029 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2030 map
= isl_map_read_from_str(ctx
, str
);
2031 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2033 flow
= isl_access_info_compute_flow(ai
);
2034 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2035 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2036 mm
.may
= isl_map_empty(dim
);
2038 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2040 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2041 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2042 assert(map_is_equal(mm
.may
, str
));
2043 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2044 assert(map_is_equal(mm
.must
, str
));
2046 isl_map_free(mm
.must
);
2047 isl_map_free(mm
.may
);
2048 isl_flow_free(flow
);
2053 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2054 map
= isl_map_read_from_str(ctx
, str
);
2055 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
2057 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2058 map
= isl_map_read_from_str(ctx
, str
);
2059 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2061 flow
= isl_access_info_compute_flow(ai
);
2062 dim
= isl_space_alloc(ctx
, 0, 5, 5);
2063 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2064 mm
.may
= isl_map_empty(dim
);
2066 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2068 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
2069 assert(map_is_equal(mm
.must
, str
));
2070 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
2071 assert(map_is_equal(mm
.may
, str
));
2073 isl_map_free(mm
.must
);
2074 isl_map_free(mm
.may
);
2075 isl_flow_free(flow
);
2078 /* Check that the dependence analysis proceeds without errors.
2079 * Earlier versions of isl would break down during the analysis
2080 * due to the use of the wrong spaces.
2082 static int test_flow(isl_ctx
*ctx
)
2085 isl_union_map
*access
, *schedule
;
2086 isl_union_map
*must_dep
, *may_dep
;
2089 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
2090 access
= isl_union_map_read_from_str(ctx
, str
);
2091 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
2092 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
2093 "S2[] -> [1,0,0,0]; "
2094 "S3[] -> [-1,0,0,0] }";
2095 schedule
= isl_union_map_read_from_str(ctx
, str
);
2096 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
2097 isl_union_map_copy(access
), schedule
,
2098 &must_dep
, &may_dep
, NULL
, NULL
);
2099 isl_union_map_free(may_dep
);
2100 isl_union_map_free(must_dep
);
2109 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
2110 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
2111 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
2112 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
2113 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
2114 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
2115 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2116 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2117 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
2120 int test_sv(isl_ctx
*ctx
)
2122 isl_union_map
*umap
;
2126 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
2127 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
2128 sv
= isl_union_map_is_single_valued(umap
);
2129 isl_union_map_free(umap
);
2132 if (sv_tests
[i
].sv
&& !sv
)
2133 isl_die(ctx
, isl_error_internal
,
2134 "map not detected as single valued", return -1);
2135 if (!sv_tests
[i
].sv
&& sv
)
2136 isl_die(ctx
, isl_error_internal
,
2137 "map detected as single valued", return -1);
2143 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
2147 map
= isl_map_read_from_str(ctx
, str
);
2149 assert(isl_map_is_bijective(map
));
2151 assert(!isl_map_is_bijective(map
));
2155 void test_bijective(struct isl_ctx
*ctx
)
2157 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
2158 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
2159 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
2160 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
2161 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
2162 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
2163 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
2164 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
2165 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
2166 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
2167 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
2168 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
2169 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
2172 /* Inputs for isl_pw_qpolynomial_gist tests.
2173 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
2179 } pwqp_gist_tests
[] = {
2180 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
2181 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
2182 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
2183 "{ [i] -> -1/2 + 1/2 * i }" },
2184 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
2187 static int test_pwqp(struct isl_ctx
*ctx
)
2192 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
2195 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2196 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2198 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
2201 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2202 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2204 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2206 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2208 isl_pw_qpolynomial_free(pwqp1
);
2210 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
2211 str
= pwqp_gist_tests
[i
].pwqp
;
2212 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2213 str
= pwqp_gist_tests
[i
].set
;
2214 set
= isl_set_read_from_str(ctx
, str
);
2215 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2216 str
= pwqp_gist_tests
[i
].gist
;
2217 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2218 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2219 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
2220 isl_pw_qpolynomial_free(pwqp1
);
2225 isl_die(ctx
, isl_error_unknown
,
2226 "unexpected result", return -1);
2229 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
2230 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2231 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
2232 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2234 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2236 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2238 isl_pw_qpolynomial_free(pwqp1
);
2240 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
2241 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2242 str
= "{ [x] -> x }";
2243 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2245 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2247 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2249 isl_pw_qpolynomial_free(pwqp1
);
2251 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
2252 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2253 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2254 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
2255 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2256 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2257 isl_pw_qpolynomial_free(pwqp1
);
2259 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
2260 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2261 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2262 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2263 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
2264 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
2265 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2266 isl_pw_qpolynomial_free(pwqp1
);
2267 isl_pw_qpolynomial_free(pwqp2
);
2271 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2273 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
2274 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2275 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2276 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2277 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
2279 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2280 isl_pw_qpolynomial_free(pwqp1
);
2281 isl_pw_qpolynomial_free(pwqp2
);
2285 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2290 void test_split_periods(isl_ctx
*ctx
)
2293 isl_pw_qpolynomial
*pwqp
;
2295 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
2296 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
2297 "U >= 0; [U,V] -> U^2 : U >= 100 }";
2298 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2300 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
2303 isl_pw_qpolynomial_free(pwqp
);
2306 void test_union(isl_ctx
*ctx
)
2309 isl_union_set
*uset1
, *uset2
;
2310 isl_union_map
*umap1
, *umap2
;
2312 str
= "{ [i] : 0 <= i <= 1 }";
2313 uset1
= isl_union_set_read_from_str(ctx
, str
);
2314 str
= "{ [1] -> [0] }";
2315 umap1
= isl_union_map_read_from_str(ctx
, str
);
2317 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
2318 assert(isl_union_map_is_equal(umap1
, umap2
));
2320 isl_union_map_free(umap1
);
2321 isl_union_map_free(umap2
);
2323 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
2324 umap1
= isl_union_map_read_from_str(ctx
, str
);
2325 str
= "{ A[i]; B[i] }";
2326 uset1
= isl_union_set_read_from_str(ctx
, str
);
2328 uset2
= isl_union_map_domain(umap1
);
2330 assert(isl_union_set_is_equal(uset1
, uset2
));
2332 isl_union_set_free(uset1
);
2333 isl_union_set_free(uset2
);
2336 void test_bound(isl_ctx
*ctx
)
2339 isl_pw_qpolynomial
*pwqp
;
2340 isl_pw_qpolynomial_fold
*pwf
;
2342 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
2343 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2344 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2345 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 4);
2346 isl_pw_qpolynomial_fold_free(pwf
);
2348 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
2349 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2350 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2351 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 1);
2352 isl_pw_qpolynomial_fold_free(pwf
);
2355 void test_lift(isl_ctx
*ctx
)
2358 isl_basic_map
*bmap
;
2359 isl_basic_set
*bset
;
2361 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
2362 bset
= isl_basic_set_read_from_str(ctx
, str
);
2363 bset
= isl_basic_set_lift(bset
);
2364 bmap
= isl_basic_map_from_range(bset
);
2365 bset
= isl_basic_map_domain(bmap
);
2366 isl_basic_set_free(bset
);
2373 } subset_tests
[] = {
2375 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
2376 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
2377 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
2379 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
2380 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
2381 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
2382 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
2383 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
2384 "256e0 <= 255i and 256e0 >= -255 + 255i and "
2385 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
2386 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
2387 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
2388 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
2389 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
2390 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
2391 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
2392 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
2393 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
2394 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
2395 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
2396 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
2397 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
2398 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
2399 "4e0 <= -57 + i0 + i1)) or "
2400 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
2401 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
2402 "4e0 >= -61 + i0 + i1)) or "
2403 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
2406 static int test_subset(isl_ctx
*ctx
)
2409 isl_set
*set1
, *set2
;
2412 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
2413 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
2414 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
2415 subset
= isl_set_is_subset(set1
, set2
);
2420 if (subset
!= subset_tests
[i
].subset
)
2421 isl_die(ctx
, isl_error_unknown
,
2422 "incorrect subset result", return -1);
2429 const char *minuend
;
2430 const char *subtrahend
;
2431 const char *difference
;
2432 } subtract_domain_tests
[] = {
2433 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
2434 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
2435 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
2438 static int test_subtract(isl_ctx
*ctx
)
2441 isl_union_map
*umap1
, *umap2
;
2442 isl_union_set
*uset
;
2445 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2446 umap1
= isl_union_map_read_from_str(ctx
,
2447 subtract_domain_tests
[i
].minuend
);
2448 uset
= isl_union_set_read_from_str(ctx
,
2449 subtract_domain_tests
[i
].subtrahend
);
2450 umap2
= isl_union_map_read_from_str(ctx
,
2451 subtract_domain_tests
[i
].difference
);
2452 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
2453 equal
= isl_union_map_is_equal(umap1
, umap2
);
2454 isl_union_map_free(umap1
);
2455 isl_union_map_free(umap2
);
2459 isl_die(ctx
, isl_error_unknown
,
2460 "incorrect subtract domain result", return -1);
2466 int test_factorize(isl_ctx
*ctx
)
2469 isl_basic_set
*bset
;
2472 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2473 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2474 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2475 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2476 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2477 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2478 "3i5 >= -2i0 - i2 + 3i4 }";
2479 bset
= isl_basic_set_read_from_str(ctx
, str
);
2480 f
= isl_basic_set_factorizer(bset
);
2481 isl_basic_set_free(bset
);
2482 isl_factorizer_free(f
);
2484 isl_die(ctx
, isl_error_unknown
,
2485 "failed to construct factorizer", return -1);
2487 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2488 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2489 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2490 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2491 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2492 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2493 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2494 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2495 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2496 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2497 bset
= isl_basic_set_read_from_str(ctx
, str
);
2498 f
= isl_basic_set_factorizer(bset
);
2499 isl_basic_set_free(bset
);
2500 isl_factorizer_free(f
);
2502 isl_die(ctx
, isl_error_unknown
,
2503 "failed to construct factorizer", return -1);
2508 static int check_injective(__isl_take isl_map
*map
, void *user
)
2510 int *injective
= user
;
2512 *injective
= isl_map_is_injective(map
);
2515 if (*injective
< 0 || !*injective
)
2521 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
2522 const char *r
, const char *s
, int tilable
, int parallel
)
2526 isl_union_map
*W
, *R
, *S
;
2527 isl_union_map
*empty
;
2528 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
2529 isl_union_map
*validity
, *proximity
, *coincidence
;
2530 isl_union_map
*schedule
;
2531 isl_union_map
*test
;
2532 isl_union_set
*delta
;
2533 isl_union_set
*domain
;
2537 isl_schedule_constraints
*sc
;
2538 isl_schedule
*sched
;
2539 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
2541 D
= isl_union_set_read_from_str(ctx
, d
);
2542 W
= isl_union_map_read_from_str(ctx
, w
);
2543 R
= isl_union_map_read_from_str(ctx
, r
);
2544 S
= isl_union_map_read_from_str(ctx
, s
);
2546 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
2547 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
2549 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
2550 isl_union_map_compute_flow(isl_union_map_copy(R
),
2551 isl_union_map_copy(W
), empty
,
2552 isl_union_map_copy(S
),
2553 &dep_raw
, NULL
, NULL
, NULL
);
2554 isl_union_map_compute_flow(isl_union_map_copy(W
),
2555 isl_union_map_copy(W
),
2556 isl_union_map_copy(R
),
2557 isl_union_map_copy(S
),
2558 &dep_waw
, &dep_war
, NULL
, NULL
);
2560 dep
= isl_union_map_union(dep_waw
, dep_war
);
2561 dep
= isl_union_map_union(dep
, dep_raw
);
2562 validity
= isl_union_map_copy(dep
);
2563 coincidence
= isl_union_map_copy(dep
);
2564 proximity
= isl_union_map_copy(dep
);
2566 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
2567 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2568 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
2569 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2570 sched
= isl_schedule_constraints_compute_schedule(sc
);
2571 schedule
= isl_schedule_get_map(sched
);
2572 isl_schedule_free(sched
);
2573 isl_union_map_free(W
);
2574 isl_union_map_free(R
);
2575 isl_union_map_free(S
);
2578 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
2580 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
2581 is_complete
= isl_union_set_is_subset(D
, domain
);
2582 isl_union_set_free(D
);
2583 isl_union_set_free(domain
);
2585 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
2586 test
= isl_union_map_apply_range(test
, dep
);
2587 test
= isl_union_map_apply_range(test
, schedule
);
2589 delta
= isl_union_map_deltas(test
);
2590 if (isl_union_set_n_set(delta
) == 0) {
2594 isl_union_set_free(delta
);
2596 delta_set
= isl_set_from_union_set(delta
);
2598 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2599 for (i
= 0; i
< tilable
; ++i
)
2600 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
2601 is_tilable
= isl_set_is_subset(delta_set
, slice
);
2602 isl_set_free(slice
);
2604 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2605 for (i
= 0; i
< parallel
; ++i
)
2606 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
2607 is_parallel
= isl_set_is_subset(delta_set
, slice
);
2608 isl_set_free(slice
);
2610 origin
= isl_set_universe(isl_set_get_space(delta_set
));
2611 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
2612 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
2614 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
2615 delta_set
= isl_set_lexmin(delta_set
);
2617 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
2619 isl_set_free(origin
);
2620 isl_set_free(delta_set
);
2623 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
2624 is_injection
< 0 || is_complete
< 0)
2627 isl_die(ctx
, isl_error_unknown
,
2628 "generated schedule incomplete", return -1);
2630 isl_die(ctx
, isl_error_unknown
,
2631 "generated schedule not injective on each statement",
2634 isl_die(ctx
, isl_error_unknown
,
2635 "negative dependences in generated schedule",
2638 isl_die(ctx
, isl_error_unknown
,
2639 "generated schedule not as tilable as expected",
2642 isl_die(ctx
, isl_error_unknown
,
2643 "generated schedule not as parallel as expected",
2649 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
2650 const char *domain
, const char *validity
, const char *proximity
)
2654 isl_union_map
*prox
;
2655 isl_schedule_constraints
*sc
;
2656 isl_schedule
*schedule
;
2657 isl_union_map
*sched
;
2659 dom
= isl_union_set_read_from_str(ctx
, domain
);
2660 dep
= isl_union_map_read_from_str(ctx
, validity
);
2661 prox
= isl_union_map_read_from_str(ctx
, proximity
);
2662 sc
= isl_schedule_constraints_on_domain(dom
);
2663 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
2664 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
2665 schedule
= isl_schedule_constraints_compute_schedule(sc
);
2666 sched
= isl_schedule_get_map(schedule
);
2667 isl_schedule_free(schedule
);
2672 /* Check that a schedule can be constructed on the given domain
2673 * with the given validity and proximity constraints.
2675 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
2676 const char *validity
, const char *proximity
)
2678 isl_union_map
*sched
;
2680 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
2684 isl_union_map_free(sched
);
2688 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
2689 const char *validity
, const char *proximity
, const char *expected_sched
)
2691 isl_union_map
*sched1
, *sched2
;
2694 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
2695 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
2697 equal
= isl_union_map_is_equal(sched1
, sched2
);
2698 isl_union_map_free(sched1
);
2699 isl_union_map_free(sched2
);
2704 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
2710 /* Check that the schedule map is properly padded, even after being
2711 * reconstructed from the band forest.
2713 static int test_padded_schedule(isl_ctx
*ctx
)
2717 isl_union_map
*validity
, *proximity
;
2718 isl_schedule_constraints
*sc
;
2719 isl_schedule
*sched
;
2720 isl_union_map
*map1
, *map2
;
2721 isl_band_list
*list
;
2724 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
2725 D
= isl_union_set_read_from_str(ctx
, str
);
2726 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
2727 proximity
= isl_union_map_copy(validity
);
2728 sc
= isl_schedule_constraints_on_domain(D
);
2729 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2730 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2731 sched
= isl_schedule_constraints_compute_schedule(sc
);
2732 map1
= isl_schedule_get_map(sched
);
2733 list
= isl_schedule_get_band_forest(sched
);
2734 isl_band_list_free(list
);
2735 map2
= isl_schedule_get_map(sched
);
2736 isl_schedule_free(sched
);
2737 equal
= isl_union_map_is_equal(map1
, map2
);
2738 isl_union_map_free(map1
);
2739 isl_union_map_free(map2
);
2744 isl_die(ctx
, isl_error_unknown
,
2745 "reconstructed schedule map not the same as original",
2751 /* Input for testing of schedule construction based on
2752 * conditional constraints.
2754 * domain is the iteration domain
2755 * flow are the flow dependences, which determine the validity and
2756 * proximity constraints
2757 * condition are the conditions on the conditional validity constraints
2758 * conditional_validity are the conditional validity constraints
2759 * outer_band_n is the expected number of members in the outer band
2764 const char *condition
;
2765 const char *conditional_validity
;
2767 } live_range_tests
[] = {
2768 /* Contrived example that illustrates that we need to keep
2769 * track of tagged condition dependences and
2770 * tagged conditional validity dependences
2771 * in isl_sched_edge separately.
2772 * In particular, the conditional validity constraints on A
2773 * cannot be satisfied,
2774 * but they can be ignored because there are no corresponding
2775 * condition constraints. However, we do have an additional
2776 * conditional validity constraint that maps to the same
2777 * dependence relation
2778 * as the condition constraint on B. If we did not make a distinction
2779 * between tagged condition and tagged conditional validity
2780 * dependences, then we
2781 * could end up treating this shared dependence as an condition
2782 * constraint on A, forcing a localization of the conditions,
2783 * which is impossible.
2785 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
2786 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
2787 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
2788 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2789 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2790 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
2793 /* TACO 2013 Fig. 7 */
2794 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2795 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2796 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2797 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
2798 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
2799 "0 <= i < n and 0 <= j < n - 1 }",
2800 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
2801 "0 <= i < n and 0 <= j < j' < n;"
2802 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
2803 "0 <= i < i' < n and 0 <= j,j' < n;"
2804 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
2805 "0 <= i,j,j' < n and j < j' }",
2808 /* TACO 2013 Fig. 7, without tags */
2809 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2810 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2811 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2812 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2813 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2814 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
2815 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
2816 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
2819 /* TACO 2013 Fig. 12 */
2820 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
2821 "S3[i,3] : 0 <= i <= 1 }",
2822 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
2823 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
2824 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
2825 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
2826 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2827 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
2828 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2829 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
2830 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
2831 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
2832 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
2837 /* Test schedule construction based on conditional constraints.
2838 * In particular, check the number of members in the outer band
2839 * as an indication of whether tiling is possible or not.
2841 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
2844 isl_union_set
*domain
;
2845 isl_union_map
*condition
;
2846 isl_union_map
*flow
;
2847 isl_union_map
*validity
;
2848 isl_schedule_constraints
*sc
;
2849 isl_schedule
*schedule
;
2850 isl_band_list
*list
;
2854 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
2855 domain
= isl_union_set_read_from_str(ctx
,
2856 live_range_tests
[i
].domain
);
2857 flow
= isl_union_map_read_from_str(ctx
,
2858 live_range_tests
[i
].flow
);
2859 condition
= isl_union_map_read_from_str(ctx
,
2860 live_range_tests
[i
].condition
);
2861 validity
= isl_union_map_read_from_str(ctx
,
2862 live_range_tests
[i
].conditional_validity
);
2863 sc
= isl_schedule_constraints_on_domain(domain
);
2864 sc
= isl_schedule_constraints_set_validity(sc
,
2865 isl_union_map_copy(flow
));
2866 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
2867 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
2868 condition
, validity
);
2869 schedule
= isl_schedule_constraints_compute_schedule(sc
);
2870 list
= isl_schedule_get_band_forest(schedule
);
2871 band
= isl_band_list_get_band(list
, 0);
2872 n_member
= isl_band_n_member(band
);
2873 isl_band_free(band
);
2874 isl_band_list_free(list
);
2875 isl_schedule_free(schedule
);
2879 if (n_member
!= live_range_tests
[i
].outer_band_n
)
2880 isl_die(ctx
, isl_error_unknown
,
2881 "unexpected number of members in outer band",
2887 int test_schedule(isl_ctx
*ctx
)
2889 const char *D
, *W
, *R
, *V
, *P
, *S
;
2891 /* Handle resulting schedule with zero bands. */
2892 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
2896 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2897 W
= "{ S1[t,i] -> a[t,i] }";
2898 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2899 "S1[t,i] -> a[t-1,i+1] }";
2900 S
= "{ S1[t,i] -> [t,i] }";
2901 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2904 /* Fig. 5 of CC2008 */
2905 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2907 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2908 "j >= 2 and j <= -1 + N }";
2909 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2910 "j >= 2 and j <= -1 + N; "
2911 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2912 "j >= 2 and j <= -1 + N }";
2913 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2914 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2917 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2918 W
= "{ S1[i] -> a[i] }";
2919 R
= "{ S2[i] -> a[i+1] }";
2920 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2921 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2924 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2925 W
= "{ S1[i] -> a[i] }";
2926 R
= "{ S2[i] -> a[9-i] }";
2927 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2928 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2931 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2932 W
= "{ S1[i] -> a[i] }";
2933 R
= "[N] -> { S2[i] -> a[N-1-i] }";
2934 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2935 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2938 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2939 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2940 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2941 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2942 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2945 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2946 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2947 R
= "{ S2[i,j] -> a[i-1,j] }";
2948 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2949 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2952 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2953 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2954 R
= "{ S2[i,j] -> a[i,j-1] }";
2955 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2956 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2959 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2960 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2961 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2962 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2963 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2964 "S_0[] -> [0, 0, 0] }";
2965 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
2967 ctx
->opt
->schedule_parametric
= 0;
2968 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2970 ctx
->opt
->schedule_parametric
= 1;
2972 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2973 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2974 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2975 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2976 "S4[i] -> a[i,N] }";
2977 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2978 "S4[i] -> [4,i,0] }";
2979 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2982 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2983 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2985 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2987 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2989 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2990 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2993 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2994 " S_2[t] : t >= 0 and t <= -1 + N; "
2995 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2997 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2998 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2999 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
3000 "i >= 0 and i <= -1 + N }";
3001 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
3002 "i >= 0 and i <= -1 + N; "
3003 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
3004 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
3005 " S_0[t] -> [0, t, 0] }";
3007 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3009 ctx
->opt
->schedule_parametric
= 0;
3010 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3012 ctx
->opt
->schedule_parametric
= 1;
3014 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
3015 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
3016 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
3019 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
3020 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
3021 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
3022 "j >= 0 and j <= -1 + N; "
3023 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3024 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
3025 "j >= 0 and j <= -1 + N; "
3026 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3027 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
3028 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3031 D
= "{ S_0[i] : i >= 0 }";
3032 W
= "{ S_0[i] -> a[i] : i >= 0 }";
3033 R
= "{ S_0[i] -> a[0] : i >= 0 }";
3034 S
= "{ S_0[i] -> [0, i, 0] }";
3035 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3038 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
3039 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
3040 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
3041 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
3042 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3045 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
3046 "k <= -1 + n and k >= 0 }";
3047 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
3048 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
3049 "k <= -1 + n and k >= 0; "
3050 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
3051 "k <= -1 + n and k >= 0; "
3052 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
3053 "k <= -1 + n and k >= 0 }";
3054 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
3055 ctx
->opt
->schedule_outer_coincidence
= 1;
3056 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3058 ctx
->opt
->schedule_outer_coincidence
= 0;
3060 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
3061 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
3062 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
3063 "Stmt_for_body24[i0, i1, 1, 0]:"
3064 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
3065 "Stmt_for_body7[i0, i1, i2]:"
3066 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
3069 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
3070 "Stmt_for_body24[1, i1, i2, i3]:"
3071 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
3073 "Stmt_for_body24[0, i1, i2, i3] -> "
3074 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
3075 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
3077 "Stmt_for_body24[0, i1, i2, i3] ->"
3078 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
3079 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
3080 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
3081 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
3082 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
3083 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
3084 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
3085 "i1 <= 6 and i1 >= 0;"
3086 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
3087 "Stmt_for_body7[i0, i1, i2] -> "
3088 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
3089 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
3090 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
3091 "Stmt_for_body7[i0, i1, i2] -> "
3092 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
3093 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
3094 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
3096 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
3097 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
3098 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
3100 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3103 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
3104 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
3105 "j >= 1 and j <= 7;"
3106 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
3107 "j >= 1 and j <= 8 }";
3109 S
= "{ S_0[i, j] -> [i + j, j] }";
3110 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3111 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3113 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3115 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
3116 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
3117 "j >= 0 and j <= -1 + i }";
3118 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
3119 "i <= -1 + N and j >= 0;"
3120 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
3123 S
= "{ S_0[i, j] -> [i, j] }";
3124 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3125 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3127 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3129 /* Test both algorithms on a case with only proximity dependences. */
3130 D
= "{ S[i,j] : 0 <= i <= 10 }";
3132 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
3133 S
= "{ S[i, j] -> [j, i] }";
3134 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3135 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3137 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3138 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3141 D
= "{ A[a]; B[] }";
3143 P
= "{ A[a] -> B[] }";
3144 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3147 if (test_padded_schedule(ctx
) < 0)
3150 /* Check that check for progress is not confused by rational
3153 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
3154 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
3156 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
3157 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
3159 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3160 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3162 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3164 /* Check that we allow schedule rows that are only non-trivial
3165 * on some full-dimensional domains.
3167 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
3168 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
3169 "S1[j] -> S2[1] : 0 <= j <= 1 }";
3171 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3172 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3174 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3176 if (test_conditional_schedule_constraints(ctx
) < 0)
3182 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
3184 isl_union_map
*umap
;
3187 umap
= isl_union_map_read_from_str(ctx
, str
);
3188 test
= isl_union_map_plain_is_injective(umap
);
3189 isl_union_map_free(umap
);
3192 if (test
== injective
)
3195 isl_die(ctx
, isl_error_unknown
,
3196 "map not detected as injective", return -1);
3198 isl_die(ctx
, isl_error_unknown
,
3199 "map detected as injective", return -1);
3202 int test_injective(isl_ctx
*ctx
)
3206 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
3208 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
3210 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
3212 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
3214 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
3216 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
3218 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
3220 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
3223 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
3224 if (test_plain_injective(ctx
, str
, 1))
3226 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
3227 if (test_plain_injective(ctx
, str
, 0))
3233 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
3241 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
3242 equal
= isl_aff_plain_is_equal(aff
, aff2
);
3248 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
3252 equal
= aff_plain_is_equal(aff
, str
);
3256 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
3257 "result not as expected", return -1);
3262 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3263 __isl_take isl_aff
*aff2
);
3265 ['+'] = { &isl_aff_add
},
3266 ['-'] = { &isl_aff_sub
},
3267 ['*'] = { &isl_aff_mul
},
3268 ['/'] = { &isl_aff_div
},
3276 } aff_bin_tests
[] = {
3277 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
3278 "{ [i] -> [2i] }" },
3279 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
3281 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
3282 "{ [i] -> [2i] }" },
3283 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
3284 "{ [i] -> [2i] }" },
3285 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
3286 "{ [i] -> [i/2] }" },
3287 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
3289 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
3290 "{ [i] -> [NaN] }" },
3291 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
3292 "{ [i] -> [NaN] }" },
3293 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
3294 "{ [i] -> [NaN] }" },
3295 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
3296 "{ [i] -> [NaN] }" },
3297 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
3298 "{ [i] -> [NaN] }" },
3299 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
3300 "{ [i] -> [NaN] }" },
3301 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
3302 "{ [i] -> [NaN] }" },
3303 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
3304 "{ [i] -> [NaN] }" },
3305 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
3306 "{ [i] -> [NaN] }" },
3307 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
3308 "{ [i] -> [NaN] }" },
3309 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
3310 "{ [i] -> [NaN] }" },
3311 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
3312 "{ [i] -> [NaN] }" },
3315 /* Perform some basic tests of binary operations on isl_aff objects.
3317 static int test_bin_aff(isl_ctx
*ctx
)
3320 isl_aff
*aff1
, *aff2
, *res
;
3321 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3322 __isl_take isl_aff
*aff2
);
3325 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
3326 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
3327 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
3328 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
3329 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
3330 aff1
= fn(aff1
, aff2
);
3331 if (isl_aff_is_nan(res
))
3332 ok
= isl_aff_is_nan(aff1
);
3334 ok
= isl_aff_plain_is_equal(aff1
, res
);
3340 isl_die(ctx
, isl_error_unknown
,
3341 "unexpected result", return -1);
3347 int test_aff(isl_ctx
*ctx
)
3352 isl_local_space
*ls
;
3356 if (test_bin_aff(ctx
) < 0)
3359 space
= isl_space_set_alloc(ctx
, 0, 1);
3360 ls
= isl_local_space_from_space(space
);
3361 aff
= isl_aff_zero_on_domain(ls
);
3363 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3364 aff
= isl_aff_scale_down_ui(aff
, 3);
3365 aff
= isl_aff_floor(aff
);
3366 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3367 aff
= isl_aff_scale_down_ui(aff
, 2);
3368 aff
= isl_aff_floor(aff
);
3369 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3372 set
= isl_set_read_from_str(ctx
, str
);
3373 aff
= isl_aff_gist(aff
, set
);
3375 aff
= isl_aff_add_constant_si(aff
, -16);
3376 zero
= isl_aff_plain_is_zero(aff
);
3382 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3384 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
3385 aff
= isl_aff_scale_down_ui(aff
, 64);
3386 aff
= isl_aff_floor(aff
);
3387 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
3395 int test_dim_max(isl_ctx
*ctx
)
3399 isl_set
*set1
, *set2
;
3404 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
3405 set
= isl_set_read_from_str(ctx
, str
);
3406 pwaff
= isl_set_dim_max(set
, 0);
3407 set1
= isl_set_from_pw_aff(pwaff
);
3408 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
3409 set2
= isl_set_read_from_str(ctx
, str
);
3410 equal
= isl_set_is_equal(set1
, set2
);
3416 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3418 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
3419 set
= isl_set_read_from_str(ctx
, str
);
3420 pwaff
= isl_set_dim_max(set
, 0);
3421 set1
= isl_set_from_pw_aff(pwaff
);
3422 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3423 set2
= isl_set_read_from_str(ctx
, str
);
3424 equal
= isl_set_is_equal(set1
, set2
);
3430 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3432 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
3433 set
= isl_set_read_from_str(ctx
, str
);
3434 pwaff
= isl_set_dim_max(set
, 0);
3435 set1
= isl_set_from_pw_aff(pwaff
);
3436 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3437 set2
= isl_set_read_from_str(ctx
, str
);
3438 equal
= isl_set_is_equal(set1
, set2
);
3444 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3446 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
3447 "0 <= i < N and 0 <= j < M }";
3448 map
= isl_map_read_from_str(ctx
, str
);
3449 set
= isl_map_range(map
);
3451 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
3452 set1
= isl_set_from_pw_aff(pwaff
);
3453 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
3454 set2
= isl_set_read_from_str(ctx
, str
);
3455 equal
= isl_set_is_equal(set1
, set2
);
3459 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
3460 set1
= isl_set_from_pw_aff(pwaff
);
3461 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
3462 set2
= isl_set_read_from_str(ctx
, str
);
3463 if (equal
>= 0 && equal
)
3464 equal
= isl_set_is_equal(set1
, set2
);
3473 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3475 /* Check that solutions are properly merged. */
3476 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
3477 "c <= -1 + n - 4a - 2b and c >= -2b and "
3478 "4a >= -4 + n and c >= 0 }";
3479 set
= isl_set_read_from_str(ctx
, str
);
3480 pwaff
= isl_set_dim_min(set
, 2);
3481 set1
= isl_set_from_pw_aff(pwaff
);
3482 str
= "[n] -> { [(0)] : n >= 1 }";
3483 set2
= isl_set_read_from_str(ctx
, str
);
3484 equal
= isl_set_is_equal(set1
, set2
);
3491 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3493 /* Check that empty solution lie in the right space. */
3494 str
= "[n] -> { [t,a] : 1 = 0 }";
3495 set
= isl_set_read_from_str(ctx
, str
);
3496 pwaff
= isl_set_dim_max(set
, 0);
3497 set1
= isl_set_from_pw_aff(pwaff
);
3498 str
= "[n] -> { [t] : 1 = 0 }";
3499 set2
= isl_set_read_from_str(ctx
, str
);
3500 equal
= isl_set_is_equal(set1
, set2
);
3507 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3512 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
3514 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
3518 isl_pw_multi_aff
*pma2
;
3524 ctx
= isl_pw_multi_aff_get_ctx(pma
);
3525 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3526 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
3527 isl_pw_multi_aff_free(pma2
);
3532 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
3533 * represented by "str".
3535 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
3540 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
3544 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
3545 "result not as expected", return -1);
3549 /* Basic test for isl_pw_multi_aff_product.
3551 * Check that multiple pieces are properly handled.
3553 static int test_product_pma(isl_ctx
*ctx
)
3557 isl_pw_multi_aff
*pma1
, *pma2
;
3559 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
3560 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3561 str
= "{ C[] -> D[] }";
3562 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3563 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
3564 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
3565 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
3566 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
3567 isl_pw_multi_aff_free(pma1
);
3574 int test_product(isl_ctx
*ctx
)
3578 isl_union_set
*uset1
, *uset2
;
3582 set
= isl_set_read_from_str(ctx
, str
);
3583 set
= isl_set_product(set
, isl_set_copy(set
));
3584 ok
= isl_set_is_wrapping(set
);
3589 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3592 uset1
= isl_union_set_read_from_str(ctx
, str
);
3593 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
3594 str
= "{ [[] -> []] }";
3595 uset2
= isl_union_set_read_from_str(ctx
, str
);
3596 ok
= isl_union_set_is_equal(uset1
, uset2
);
3597 isl_union_set_free(uset1
);
3598 isl_union_set_free(uset2
);
3602 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3604 if (test_product_pma(ctx
) < 0)
3610 /* Check that two sets are not considered disjoint just because
3611 * they have a different set of (named) parameters.
3613 static int test_disjoint(isl_ctx
*ctx
)
3616 isl_set
*set
, *set2
;
3619 str
= "[n] -> { [[]->[]] }";
3620 set
= isl_set_read_from_str(ctx
, str
);
3621 str
= "{ [[]->[]] }";
3622 set2
= isl_set_read_from_str(ctx
, str
);
3623 disjoint
= isl_set_is_disjoint(set
, set2
);
3629 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3634 int test_equal(isl_ctx
*ctx
)
3637 isl_set
*set
, *set2
;
3641 set
= isl_set_read_from_str(ctx
, str
);
3643 set2
= isl_set_read_from_str(ctx
, str
);
3644 equal
= isl_set_is_equal(set
, set2
);
3650 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3655 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
3656 enum isl_dim_type type
, unsigned pos
, int fixed
)
3660 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
3667 isl_die(ctx
, isl_error_unknown
,
3668 "map not detected as fixed", return -1);
3670 isl_die(ctx
, isl_error_unknown
,
3671 "map detected as fixed", return -1);
3674 int test_fixed(isl_ctx
*ctx
)
3679 str
= "{ [i] -> [i] }";
3680 map
= isl_map_read_from_str(ctx
, str
);
3681 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
3683 str
= "{ [i] -> [1] }";
3684 map
= isl_map_read_from_str(ctx
, str
);
3685 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3687 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
3688 map
= isl_map_read_from_str(ctx
, str
);
3689 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3691 map
= isl_map_read_from_str(ctx
, str
);
3692 map
= isl_map_neg(map
);
3693 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3699 struct isl_vertices_test_data
{
3702 const char *vertex
[2];
3703 } vertices_tests
[] = {
3704 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
3705 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
3706 { "{ A[t, i] : t = 14 and i = 1 }",
3707 1, { "{ A[14, 1] }" } },
3710 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
3712 static int find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
3714 struct isl_vertices_test_data
*data
= user
;
3717 isl_basic_set
*bset
;
3718 isl_pw_multi_aff
*pma
;
3722 ctx
= isl_vertex_get_ctx(vertex
);
3723 bset
= isl_vertex_get_domain(vertex
);
3724 ma
= isl_vertex_get_expr(vertex
);
3725 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
3727 for (i
= 0; i
< data
->n
; ++i
) {
3728 isl_pw_multi_aff
*pma_i
;
3730 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
3731 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
3732 isl_pw_multi_aff_free(pma_i
);
3734 if (equal
< 0 || equal
)
3738 isl_pw_multi_aff_free(pma
);
3739 isl_vertex_free(vertex
);
3744 return equal
? 0 : - 1;
3747 int test_vertices(isl_ctx
*ctx
)
3751 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
3752 isl_basic_set
*bset
;
3753 isl_vertices
*vertices
;
3757 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
3758 vertices
= isl_basic_set_compute_vertices(bset
);
3759 n
= isl_vertices_get_n_vertices(vertices
);
3760 if (vertices_tests
[i
].n
!= n
)
3762 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
3763 &vertices_tests
[i
]) < 0)
3765 isl_vertices_free(vertices
);
3766 isl_basic_set_free(bset
);
3771 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
3778 int test_union_pw(isl_ctx
*ctx
)
3782 isl_union_set
*uset
;
3783 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
3785 str
= "{ [x] -> x^2 }";
3786 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
3787 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
3788 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
3789 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
3790 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
3791 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
3792 isl_union_pw_qpolynomial_free(upwqp1
);
3793 isl_union_pw_qpolynomial_free(upwqp2
);
3797 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3802 int test_output(isl_ctx
*ctx
)
3810 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
3811 pa
= isl_pw_aff_read_from_str(ctx
, str
);
3813 p
= isl_printer_to_str(ctx
);
3814 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
3815 p
= isl_printer_print_pw_aff(p
, pa
);
3816 s
= isl_printer_get_str(p
);
3817 isl_printer_free(p
);
3818 isl_pw_aff_free(pa
);
3822 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
3827 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3832 int test_sample(isl_ctx
*ctx
)
3835 isl_basic_set
*bset1
, *bset2
;
3838 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
3839 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
3840 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
3841 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
3842 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
3843 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
3844 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
3845 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
3846 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
3847 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
3848 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
3849 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
3850 "d - 1073741821e and "
3851 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
3852 "3j >= 1 - a + b + 2e and "
3853 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
3854 "3i <= 4 - a + 4b - e and "
3855 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
3856 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
3857 "c <= -1 + a and 3i >= -2 - a + 3e and "
3858 "1073741822e <= 1073741823 - a + 1073741822b + c and "
3859 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
3860 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
3861 "1073741823e >= 1 + 1073741823b - d and "
3862 "3i >= 1073741823b + c - 1073741823e - f and "
3863 "3i >= 1 + 2b + e + 3g }";
3864 bset1
= isl_basic_set_read_from_str(ctx
, str
);
3865 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
3866 empty
= isl_basic_set_is_empty(bset2
);
3867 subset
= isl_basic_set_is_subset(bset2
, bset1
);
3868 isl_basic_set_free(bset1
);
3869 isl_basic_set_free(bset2
);
3870 if (empty
< 0 || subset
< 0)
3873 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
3875 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
3880 int test_fixed_power(isl_ctx
*ctx
)
3888 str
= "{ [i] -> [i + 1] }";
3889 map
= isl_map_read_from_str(ctx
, str
);
3890 isl_int_set_si(exp
, 23);
3891 map
= isl_map_fixed_power(map
, exp
);
3892 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
3901 int test_slice(isl_ctx
*ctx
)
3907 str
= "{ [i] -> [j] }";
3908 map
= isl_map_read_from_str(ctx
, str
);
3909 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3910 equal
= map_check_equal(map
, "{ [i] -> [i] }");
3915 str
= "{ [i] -> [j] }";
3916 map
= isl_map_read_from_str(ctx
, str
);
3917 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3918 equal
= map_check_equal(map
, "{ [i] -> [j] }");
3923 str
= "{ [i] -> [j] }";
3924 map
= isl_map_read_from_str(ctx
, str
);
3925 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3926 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
3931 str
= "{ [i] -> [j] }";
3932 map
= isl_map_read_from_str(ctx
, str
);
3933 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3934 equal
= map_check_equal(map
, "{ [0] -> [j] }");
3939 str
= "{ [i] -> [j] }";
3940 map
= isl_map_read_from_str(ctx
, str
);
3941 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3942 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
3947 str
= "{ [i] -> [j] }";
3948 map
= isl_map_read_from_str(ctx
, str
);
3949 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3950 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
3958 int test_eliminate(isl_ctx
*ctx
)
3964 str
= "{ [i] -> [j] : i = 2j }";
3965 map
= isl_map_read_from_str(ctx
, str
);
3966 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
3967 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
3975 /* Check that isl_set_dim_residue_class detects that the values of j
3976 * in the set below are all odd and that it does not detect any spurious
3979 static int test_residue_class(isl_ctx
*ctx
)
3986 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
3987 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
3988 set
= isl_set_read_from_str(ctx
, str
);
3991 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
3993 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
3994 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
4003 int test_align_parameters(isl_ctx
*ctx
)
4007 isl_multi_aff
*ma1
, *ma2
;
4010 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
4011 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
4013 space
= isl_space_params_alloc(ctx
, 1);
4014 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
4015 ma1
= isl_multi_aff_align_params(ma1
, space
);
4017 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
4018 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
4020 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4022 isl_multi_aff_free(ma1
);
4023 isl_multi_aff_free(ma2
);
4028 isl_die(ctx
, isl_error_unknown
,
4029 "result not as expected", return -1);
4034 static int test_list(isl_ctx
*ctx
)
4036 isl_id
*a
, *b
, *c
, *d
, *id
;
4040 a
= isl_id_alloc(ctx
, "a", NULL
);
4041 b
= isl_id_alloc(ctx
, "b", NULL
);
4042 c
= isl_id_alloc(ctx
, "c", NULL
);
4043 d
= isl_id_alloc(ctx
, "d", NULL
);
4045 list
= isl_id_list_alloc(ctx
, 4);
4046 list
= isl_id_list_add(list
, a
);
4047 list
= isl_id_list_add(list
, b
);
4048 list
= isl_id_list_add(list
, c
);
4049 list
= isl_id_list_add(list
, d
);
4050 list
= isl_id_list_drop(list
, 1, 1);
4052 if (isl_id_list_n_id(list
) != 3) {
4053 isl_id_list_free(list
);
4054 isl_die(ctx
, isl_error_unknown
,
4055 "unexpected number of elements in list", return -1);
4058 id
= isl_id_list_get_id(list
, 0);
4061 id
= isl_id_list_get_id(list
, 1);
4064 id
= isl_id_list_get_id(list
, 2);
4068 isl_id_list_free(list
);
4071 isl_die(ctx
, isl_error_unknown
,
4072 "unexpected elements in list", return -1);
4077 const char *set_conversion_tests
[] = {
4078 "[N] -> { [i] : N - 1 <= 2 i <= N }",
4079 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
4080 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4081 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4082 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
4085 /* Check that converting from isl_set to isl_pw_multi_aff and back
4086 * to isl_set produces the original isl_set.
4088 static int test_set_conversion(isl_ctx
*ctx
)
4092 isl_set
*set1
, *set2
;
4093 isl_pw_multi_aff
*pma
;
4096 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
4097 str
= set_conversion_tests
[i
];
4098 set1
= isl_set_read_from_str(ctx
, str
);
4099 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
4100 set2
= isl_set_from_pw_multi_aff(pma
);
4101 equal
= isl_set_is_equal(set1
, set2
);
4108 isl_die(ctx
, isl_error_unknown
, "bad conversion",
4115 /* Check that converting from isl_map to isl_pw_multi_aff and back
4116 * to isl_map produces the original isl_map.
4118 static int test_map_conversion(isl_ctx
*ctx
)
4121 isl_map
*map1
, *map2
;
4122 isl_pw_multi_aff
*pma
;
4125 str
= "{ [a, b, c, d] -> s0[a, b, e, f] : "
4126 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
4127 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
4128 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
4130 map1
= isl_map_read_from_str(ctx
, str
);
4131 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
4132 map2
= isl_map_from_pw_multi_aff(pma
);
4133 equal
= isl_map_is_equal(map1
, map2
);
4140 isl_die(ctx
, isl_error_unknown
, "bad conversion", return -1);
4145 static int test_conversion(isl_ctx
*ctx
)
4147 if (test_set_conversion(ctx
) < 0)
4149 if (test_map_conversion(ctx
) < 0)
4154 /* Check that isl_basic_map_curry does not modify input.
4156 static int test_curry(isl_ctx
*ctx
)
4159 isl_basic_map
*bmap1
, *bmap2
;
4162 str
= "{ [A[] -> B[]] -> C[] }";
4163 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
4164 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
4165 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
4166 isl_basic_map_free(bmap1
);
4167 isl_basic_map_free(bmap2
);
4172 isl_die(ctx
, isl_error_unknown
,
4173 "curried map should not be equal to original",
4183 } preimage_tests
[] = {
4184 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
4185 "{ A[j,i] -> B[i,j] }",
4186 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
4187 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4188 "{ A[a,b] -> B[a/2,b/6] }",
4189 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
4190 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4191 "{ A[a,b] -> B[a/2,b/6] }",
4192 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
4193 "exists i,j : a = 2 i and b = 6 j }" },
4194 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
4195 "[n] -> { : 0 <= n <= 100 }" },
4196 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4197 "{ A[a] -> B[2a] }",
4198 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
4199 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4200 "{ A[a] -> B[([a/2])] }",
4201 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
4202 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
4203 "{ A[a] -> B[a,a,a/3] }",
4204 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
4205 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
4206 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
4209 static int test_preimage_basic_set(isl_ctx
*ctx
)
4212 isl_basic_set
*bset1
, *bset2
;
4216 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
4217 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
4218 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
4219 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
4220 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
4221 equal
= isl_basic_set_is_equal(bset1
, bset2
);
4222 isl_basic_set_free(bset1
);
4223 isl_basic_set_free(bset2
);
4227 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4238 } preimage_domain_tests
[] = {
4239 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
4240 "{ A[j,i] -> B[i,j] }",
4241 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
4242 { "{ B[i] -> C[i]; D[i] -> E[i] }",
4243 "{ A[i] -> B[i + 1] }",
4244 "{ A[i] -> C[i + 1] }" },
4245 { "{ B[i] -> C[i]; B[i] -> E[i] }",
4246 "{ A[i] -> B[i + 1] }",
4247 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
4248 { "{ B[i] -> C[([i/2])] }",
4249 "{ A[i] -> B[2i] }",
4250 "{ A[i] -> C[i] }" },
4251 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
4252 "{ A[i] -> B[([i/5]), ([i/7])] }",
4253 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
4254 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
4255 "[N] -> { A[] -> B[([N/5])] }",
4256 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
4257 { "{ B[i] -> C[i] : exists a : i = 5 a }",
4258 "{ A[i] -> B[2i] }",
4259 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
4260 { "{ B[i] -> C[i] : exists a : i = 2 a; "
4261 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
4262 "{ A[i] -> B[2i] }",
4263 "{ A[i] -> C[2i] }" },
4266 static int test_preimage_union_map(isl_ctx
*ctx
)
4269 isl_union_map
*umap1
, *umap2
;
4273 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
4274 umap1
= isl_union_map_read_from_str(ctx
,
4275 preimage_domain_tests
[i
].map
);
4276 ma
= isl_multi_aff_read_from_str(ctx
,
4277 preimage_domain_tests
[i
].ma
);
4278 umap2
= isl_union_map_read_from_str(ctx
,
4279 preimage_domain_tests
[i
].res
);
4280 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
4281 equal
= isl_union_map_is_equal(umap1
, umap2
);
4282 isl_union_map_free(umap1
);
4283 isl_union_map_free(umap2
);
4287 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4294 static int test_preimage(isl_ctx
*ctx
)
4296 if (test_preimage_basic_set(ctx
) < 0)
4298 if (test_preimage_union_map(ctx
) < 0)
4308 } pullback_tests
[] = {
4309 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
4310 "{ A[a,b] -> C[b + 2a] }" },
4311 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
4312 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
4313 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
4314 "{ A[a] -> C[(a)/6] }" },
4315 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
4316 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
4317 "{ A[a] -> C[(2a)/3] }" },
4318 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
4319 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
4320 "{ A[i,j] -> C[i + j, i + j] }"},
4321 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
4322 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
4323 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
4326 static int test_pullback(isl_ctx
*ctx
)
4329 isl_multi_aff
*ma1
, *ma2
;
4333 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
4334 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
4335 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
4336 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
4337 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
4338 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4339 isl_multi_aff_free(ma1
);
4340 isl_multi_aff_free(ma2
);
4344 isl_die(ctx
, isl_error_unknown
, "bad pullback",
4351 /* Check that negation is printed correctly.
4353 static int test_ast(isl_ctx
*ctx
)
4355 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
4359 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4360 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4361 expr
= isl_ast_expr_add(expr1
, expr2
);
4362 expr
= isl_ast_expr_neg(expr
);
4363 str
= isl_ast_expr_to_str(expr
);
4364 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
4366 isl_ast_expr_free(expr
);
4371 isl_die(ctx
, isl_error_unknown
,
4372 "isl_ast_expr printed incorrectly", return -1);
4374 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4375 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4376 expr
= isl_ast_expr_add(expr1
, expr2
);
4377 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
4378 expr
= isl_ast_expr_sub(expr3
, expr
);
4379 str
= isl_ast_expr_to_str(expr
);
4380 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
4382 isl_ast_expr_free(expr
);
4387 isl_die(ctx
, isl_error_unknown
,
4388 "isl_ast_expr printed incorrectly", return -1);
4393 /* Check that isl_ast_build_expr_from_set returns a valid expression
4394 * for an empty set. Note that isl_ast_build_expr_from_set getting
4395 * called on an empty set probably indicates a bug in the caller.
4397 static int test_ast_build(isl_ctx
*ctx
)
4400 isl_ast_build
*build
;
4403 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4404 build
= isl_ast_build_from_context(set
);
4406 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
4407 expr
= isl_ast_build_expr_from_set(build
, set
);
4409 isl_ast_expr_free(expr
);
4410 isl_ast_build_free(build
);
4418 /* Internal data structure for before_for and after_for callbacks.
4420 * depth is the current depth
4421 * before is the number of times before_for has been called
4422 * after is the number of times after_for has been called
4424 struct isl_test_codegen_data
{
4430 /* This function is called before each for loop in the AST generated
4431 * from test_ast_gen1.
4433 * Increment the number of calls and the depth.
4434 * Check that the space returned by isl_ast_build_get_schedule_space
4435 * matches the target space of the schedule returned by
4436 * isl_ast_build_get_schedule.
4437 * Return an isl_id that is checked by the corresponding call
4440 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
4443 struct isl_test_codegen_data
*data
= user
;
4446 isl_union_map
*schedule
;
4447 isl_union_set
*uset
;
4452 ctx
= isl_ast_build_get_ctx(build
);
4454 if (data
->before
>= 3)
4455 isl_die(ctx
, isl_error_unknown
,
4456 "unexpected number of for nodes", return NULL
);
4457 if (data
->depth
>= 2)
4458 isl_die(ctx
, isl_error_unknown
,
4459 "unexpected depth", return NULL
);
4461 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
4465 schedule
= isl_ast_build_get_schedule(build
);
4466 uset
= isl_union_map_range(schedule
);
4469 if (isl_union_set_n_set(uset
) != 1) {
4470 isl_union_set_free(uset
);
4471 isl_die(ctx
, isl_error_unknown
,
4472 "expecting single range space", return NULL
);
4475 space
= isl_ast_build_get_schedule_space(build
);
4476 set
= isl_union_set_extract_set(uset
, space
);
4477 isl_union_set_free(uset
);
4478 empty
= isl_set_is_empty(set
);
4484 isl_die(ctx
, isl_error_unknown
,
4485 "spaces don't match", return NULL
);
4487 return isl_id_alloc(ctx
, name
, NULL
);
4490 /* This function is called after each for loop in the AST generated
4491 * from test_ast_gen1.
4493 * Increment the number of calls and decrement the depth.
4494 * Check that the annotation attached to the node matches
4495 * the isl_id returned by the corresponding call to before_for.
4497 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
4498 __isl_keep isl_ast_build
*build
, void *user
)
4500 struct isl_test_codegen_data
*data
= user
;
4508 if (data
->after
> data
->before
)
4509 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4510 "mismatch in number of for nodes",
4511 return isl_ast_node_free(node
));
4513 id
= isl_ast_node_get_annotation(node
);
4515 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4516 "missing annotation", return isl_ast_node_free(node
));
4518 name
= isl_id_get_name(id
);
4519 valid
= name
&& atoi(name
+ 1) == data
->depth
;
4523 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4524 "wrong annotation", return isl_ast_node_free(node
));
4529 /* Check that the before_each_for and after_each_for callbacks
4530 * are called for each for loop in the generated code,
4531 * that they are called in the right order and that the isl_id
4532 * returned from the before_each_for callback is attached to
4533 * the isl_ast_node passed to the corresponding after_each_for call.
4535 static int test_ast_gen1(isl_ctx
*ctx
)
4539 isl_union_map
*schedule
;
4540 isl_ast_build
*build
;
4542 struct isl_test_codegen_data data
;
4544 str
= "[N] -> { : N >= 10 }";
4545 set
= isl_set_read_from_str(ctx
, str
);
4546 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
4547 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
4548 schedule
= isl_union_map_read_from_str(ctx
, str
);
4553 build
= isl_ast_build_from_context(set
);
4554 build
= isl_ast_build_set_before_each_for(build
,
4555 &before_for
, &data
);
4556 build
= isl_ast_build_set_after_each_for(build
,
4558 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4559 isl_ast_build_free(build
);
4563 isl_ast_node_free(tree
);
4565 if (data
.before
!= 3 || data
.after
!= 3)
4566 isl_die(ctx
, isl_error_unknown
,
4567 "unexpected number of for nodes", return -1);
4572 /* Check that the AST generator handles domains that are integrally disjoint
4573 * but not ratinoally disjoint.
4575 static int test_ast_gen2(isl_ctx
*ctx
)
4579 isl_union_map
*schedule
;
4580 isl_union_map
*options
;
4581 isl_ast_build
*build
;
4584 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
4585 schedule
= isl_union_map_read_from_str(ctx
, str
);
4586 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4587 build
= isl_ast_build_from_context(set
);
4589 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
4590 options
= isl_union_map_read_from_str(ctx
, str
);
4591 build
= isl_ast_build_set_options(build
, options
);
4592 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4593 isl_ast_build_free(build
);
4596 isl_ast_node_free(tree
);
4601 /* Increment *user on each call.
4603 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
4604 __isl_keep isl_ast_build
*build
, void *user
)
4613 /* Test that unrolling tries to minimize the number of instances.
4614 * In particular, for the schedule given below, make sure it generates
4615 * 3 nodes (rather than 101).
4617 static int test_ast_gen3(isl_ctx
*ctx
)
4621 isl_union_map
*schedule
;
4622 isl_union_map
*options
;
4623 isl_ast_build
*build
;
4627 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
4628 schedule
= isl_union_map_read_from_str(ctx
, str
);
4629 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4631 str
= "{ [i] -> unroll[0] }";
4632 options
= isl_union_map_read_from_str(ctx
, str
);
4634 build
= isl_ast_build_from_context(set
);
4635 build
= isl_ast_build_set_options(build
, options
);
4636 build
= isl_ast_build_set_at_each_domain(build
,
4637 &count_domains
, &n_domain
);
4638 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4639 isl_ast_build_free(build
);
4643 isl_ast_node_free(tree
);
4646 isl_die(ctx
, isl_error_unknown
,
4647 "unexpected number of for nodes", return -1);
4652 /* Check that if the ast_build_exploit_nested_bounds options is set,
4653 * we do not get an outer if node in the generated AST,
4654 * while we do get such an outer if node if the options is not set.
4656 static int test_ast_gen4(isl_ctx
*ctx
)
4660 isl_union_map
*schedule
;
4661 isl_ast_build
*build
;
4663 enum isl_ast_node_type type
;
4666 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
4667 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
4669 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
4671 schedule
= isl_union_map_read_from_str(ctx
, str
);
4672 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4673 build
= isl_ast_build_from_context(set
);
4674 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4675 isl_ast_build_free(build
);
4679 type
= isl_ast_node_get_type(tree
);
4680 isl_ast_node_free(tree
);
4682 if (type
== isl_ast_node_if
)
4683 isl_die(ctx
, isl_error_unknown
,
4684 "not expecting if node", return -1);
4686 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
4688 schedule
= isl_union_map_read_from_str(ctx
, str
);
4689 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4690 build
= isl_ast_build_from_context(set
);
4691 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4692 isl_ast_build_free(build
);
4696 type
= isl_ast_node_get_type(tree
);
4697 isl_ast_node_free(tree
);
4699 if (type
!= isl_ast_node_if
)
4700 isl_die(ctx
, isl_error_unknown
,
4701 "expecting if node", return -1);
4703 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
4708 /* This function is called for each leaf in the AST generated
4709 * from test_ast_gen5.
4711 * We finalize the AST generation by extending the outer schedule
4712 * with a zero-dimensional schedule. If this results in any for loops,
4713 * then this means that we did not pass along enough information
4714 * about the outer schedule to the inner AST generation.
4716 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
4719 isl_union_map
*schedule
, *extra
;
4722 schedule
= isl_ast_build_get_schedule(build
);
4723 extra
= isl_union_map_copy(schedule
);
4724 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
4725 schedule
= isl_union_map_range_product(schedule
, extra
);
4726 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4727 isl_ast_build_free(build
);
4732 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
4733 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
4734 "code should not contain any for loop",
4735 return isl_ast_node_free(tree
));
4740 /* Check that we do not lose any information when going back and
4741 * forth between internal and external schedule.
4743 * In particular, we create an AST where we unroll the only
4744 * non-constant dimension in the schedule. We therefore do
4745 * not expect any for loops in the AST. However, older versions
4746 * of isl would not pass along enough information about the outer
4747 * schedule when performing an inner code generation from a create_leaf
4748 * callback, resulting in the inner code generation producing a for loop.
4750 static int test_ast_gen5(isl_ctx
*ctx
)
4754 isl_union_map
*schedule
, *options
;
4755 isl_ast_build
*build
;
4758 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
4759 schedule
= isl_union_map_read_from_str(ctx
, str
);
4761 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
4762 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
4763 options
= isl_union_map_read_from_str(ctx
, str
);
4765 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4766 build
= isl_ast_build_from_context(set
);
4767 build
= isl_ast_build_set_options(build
, options
);
4768 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
4769 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4770 isl_ast_build_free(build
);
4771 isl_ast_node_free(tree
);
4778 static int test_ast_gen(isl_ctx
*ctx
)
4780 if (test_ast_gen1(ctx
) < 0)
4782 if (test_ast_gen2(ctx
) < 0)
4784 if (test_ast_gen3(ctx
) < 0)
4786 if (test_ast_gen4(ctx
) < 0)
4788 if (test_ast_gen5(ctx
) < 0)
4793 /* Check if dropping output dimensions from an isl_pw_multi_aff
4796 static int test_pw_multi_aff(isl_ctx
*ctx
)
4799 isl_pw_multi_aff
*pma1
, *pma2
;
4802 str
= "{ [i,j] -> [i+j, 4i-j] }";
4803 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4804 str
= "{ [i,j] -> [4i-j] }";
4805 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4807 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
4809 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
4811 isl_pw_multi_aff_free(pma1
);
4812 isl_pw_multi_aff_free(pma2
);
4816 isl_die(ctx
, isl_error_unknown
,
4817 "expressions not equal", return -1);
4822 /* Check that we can properly parse multi piecewise affine expressions
4823 * where the piecewise affine expressions have different domains.
4825 static int test_multi_pw_aff(isl_ctx
*ctx
)
4828 isl_set
*dom
, *dom2
;
4829 isl_multi_pw_aff
*mpa1
, *mpa2
;
4834 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
4835 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
4836 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
4837 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
4838 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
4839 str
= "{ [i] -> [(i : i > 0), 2i] }";
4840 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
4842 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
4844 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
4845 dom
= isl_pw_aff_domain(pa
);
4846 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
4847 dom2
= isl_pw_aff_domain(pa
);
4848 equal_domain
= isl_set_is_equal(dom
, dom2
);
4852 isl_multi_pw_aff_free(mpa1
);
4853 isl_multi_pw_aff_free(mpa2
);
4858 isl_die(ctx
, isl_error_unknown
,
4859 "expressions not equal", return -1);
4861 if (equal_domain
< 0)
4864 isl_die(ctx
, isl_error_unknown
,
4865 "domains unexpectedly equal", return -1);
4870 /* This is a regression test for a bug where isl_basic_map_simplify
4871 * would end up in an infinite loop. In particular, we construct
4872 * an empty basic set that is not obviously empty.
4873 * isl_basic_set_is_empty marks the basic set as empty.
4874 * After projecting out i3, the variable can be dropped completely,
4875 * but isl_basic_map_simplify refrains from doing so if the basic set
4876 * is empty and would end up in an infinite loop if it didn't test
4877 * explicitly for empty basic maps in the outer loop.
4879 static int test_simplify(isl_ctx
*ctx
)
4882 isl_basic_set
*bset
;
4885 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
4886 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
4887 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
4889 bset
= isl_basic_set_read_from_str(ctx
, str
);
4890 empty
= isl_basic_set_is_empty(bset
);
4891 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
4892 isl_basic_set_free(bset
);
4896 isl_die(ctx
, isl_error_unknown
,
4897 "basic set should be empty", return -1);
4902 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
4903 * with gbr context would fail to disable the use of the shifted tableau
4904 * when transferring equalities for the input to the context, resulting
4905 * in invalid sample values.
4907 static int test_partial_lexmin(isl_ctx
*ctx
)
4910 isl_basic_set
*bset
;
4911 isl_basic_map
*bmap
;
4914 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
4915 bmap
= isl_basic_map_read_from_str(ctx
, str
);
4916 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
4917 bset
= isl_basic_set_read_from_str(ctx
, str
);
4918 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
4927 /* Check that the variable compression performed on the existentially
4928 * quantified variables inside isl_basic_set_compute_divs is not confused
4929 * by the implicit equalities among the parameters.
4931 static int test_compute_divs(isl_ctx
*ctx
)
4934 isl_basic_set
*bset
;
4937 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
4938 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
4939 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
4940 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
4941 bset
= isl_basic_set_read_from_str(ctx
, str
);
4942 set
= isl_basic_set_compute_divs(bset
);
4954 { "{ rat: [i] : 0 <= i <= 10 }",
4955 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
4956 { "{ rat: [i] : FALSE }",
4957 "{ rat: coefficients[[cst] -> [a]] }" },
4959 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
4966 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
4967 "{ rat: [i] : 0 <= i <= 10 }" },
4968 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
4970 { "{ rat: coefficients[[cst] -> [a]] }",
4971 "{ rat: [i] : FALSE }" },
4974 /* Test the basic functionality of isl_basic_set_coefficients and
4975 * isl_basic_set_solutions.
4977 static int test_dual(isl_ctx
*ctx
)
4981 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
4983 isl_basic_set
*bset1
, *bset2
;
4985 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
4986 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
4987 bset1
= isl_basic_set_coefficients(bset1
);
4988 equal
= isl_basic_set_is_equal(bset1
, bset2
);
4989 isl_basic_set_free(bset1
);
4990 isl_basic_set_free(bset2
);
4994 isl_die(ctx
, isl_error_unknown
,
4995 "incorrect dual", return -1);
4998 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
5000 isl_basic_set
*bset1
, *bset2
;
5002 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
5003 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
5004 bset1
= isl_basic_set_solutions(bset1
);
5005 equal
= isl_basic_set_is_equal(bset1
, bset2
);
5006 isl_basic_set_free(bset1
);
5007 isl_basic_set_free(bset2
);
5011 isl_die(ctx
, isl_error_unknown
,
5012 "incorrect dual", return -1);
5020 int (*fn
)(isl_ctx
*ctx
);
5022 { "dual", &test_dual
},
5023 { "dependence analysis", &test_flow
},
5024 { "val", &test_val
},
5025 { "compute divs", &test_compute_divs
},
5026 { "partial lexmin", &test_partial_lexmin
},
5027 { "simplify", &test_simplify
},
5028 { "curry", &test_curry
},
5029 { "piecewise multi affine expressions", &test_pw_multi_aff
},
5030 { "multi piecewise affine expressions", &test_multi_pw_aff
},
5031 { "conversion", &test_conversion
},
5032 { "list", &test_list
},
5033 { "align parameters", &test_align_parameters
},
5034 { "preimage", &test_preimage
},
5035 { "pullback", &test_pullback
},
5036 { "AST", &test_ast
},
5037 { "AST build", &test_ast_build
},
5038 { "AST generation", &test_ast_gen
},
5039 { "eliminate", &test_eliminate
},
5040 { "residue class", &test_residue_class
},
5041 { "div", &test_div
},
5042 { "slice", &test_slice
},
5043 { "fixed power", &test_fixed_power
},
5044 { "sample", &test_sample
},
5045 { "output", &test_output
},
5046 { "vertices", &test_vertices
},
5047 { "fixed", &test_fixed
},
5048 { "equal", &test_equal
},
5049 { "disjoint", &test_disjoint
},
5050 { "product", &test_product
},
5051 { "dim_max", &test_dim_max
},
5052 { "affine", &test_aff
},
5053 { "injective", &test_injective
},
5054 { "schedule", &test_schedule
},
5055 { "union_pw", &test_union_pw
},
5056 { "parse", &test_parse
},
5057 { "single-valued", &test_sv
},
5058 { "affine hull", &test_affine_hull
},
5059 { "coalesce", &test_coalesce
},
5060 { "factorize", &test_factorize
},
5061 { "subset", &test_subset
},
5062 { "subtract", &test_subtract
},
5063 { "lexmin", &test_lexmin
},
5064 { "min", &test_min
},
5065 { "gist", &test_gist
},
5066 { "piecewise quasi-polynomials", &test_pwqp
},
5069 int main(int argc
, char **argv
)
5072 struct isl_ctx
*ctx
;
5073 struct isl_options
*options
;
5075 srcdir
= getenv("srcdir");
5078 options
= isl_options_new_with_defaults();
5080 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
5082 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
5083 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
5084 printf("%s\n", tests
[i
].name
);
5085 if (tests
[i
].fn(ctx
) < 0)
5091 test_split_periods(ctx
);
5093 test_bijective(ctx
);
5097 test_construction(ctx
);
5099 test_application(ctx
);
5100 test_convex_hull(ctx
);