2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
6 * Use of this software is governed by the MIT license
8 * Written by Sven Verdoolaege, K.U.Leuven, Departement
9 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
10 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
11 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
12 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
18 #include <isl_ctx_private.h>
19 #include <isl_map_private.h>
20 #include <isl_aff_private.h>
23 #include <isl_constraint_private.h>
24 #include <isl/polynomial.h>
25 #include <isl/union_map.h>
26 #include <isl_factorization.h>
27 #include <isl/schedule.h>
28 #include <isl_options_private.h>
29 #include <isl/vertices.h>
30 #include <isl/ast_build.h>
34 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
38 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
41 char *pattern
= "%s/test_inputs/%s.%s";
43 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
45 filename
= isl_alloc_array(ctx
, char, length
);
50 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
55 void test_parse_map(isl_ctx
*ctx
, const char *str
)
59 map
= isl_map_read_from_str(ctx
, str
);
64 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
69 map
= isl_map_read_from_str(ctx
, str
);
70 map2
= isl_map_read_from_str(ctx
, str2
);
71 equal
= isl_map_is_equal(map
, map2
);
78 isl_die(ctx
, isl_error_unknown
, "maps not equal",
84 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
86 isl_pw_qpolynomial
*pwqp
;
88 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
90 isl_pw_qpolynomial_free(pwqp
);
93 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
97 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
99 isl_pw_aff_free(pwaff
);
102 int test_parse(struct isl_ctx
*ctx
)
105 const char *str
, *str2
;
107 str
= "{ [i] -> [-i] }";
108 map
= isl_map_read_from_str(ctx
, str
);
112 str
= "{ A[i] -> L[([i/3])] }";
113 map
= isl_map_read_from_str(ctx
, str
);
117 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
118 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
119 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
121 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
122 str2
= "{ [x, y] : 2y >= 6 - x }";
123 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
126 if (test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
127 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
129 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
130 if (test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }",
134 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
135 map
= isl_map_read_from_str(ctx
, str
);
136 str
= "{ [new, old] -> [o0, o1] : "
137 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
138 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
139 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
140 map2
= isl_map_read_from_str(ctx
, str
);
141 assert(isl_map_is_equal(map
, map2
));
145 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
146 map
= isl_map_read_from_str(ctx
, str
);
147 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
148 map2
= isl_map_read_from_str(ctx
, str
);
149 assert(isl_map_is_equal(map
, map2
));
153 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
154 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
155 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
158 str
= "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
159 str2
= "{ [i,j] -> [min(i,j)] }";
160 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
163 str
= "{ [i,j] : i != j }";
164 str2
= "{ [i,j] : i < j or i > j }";
165 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
168 str
= "{ [i,j] : (i+1)*2 >= j }";
169 str2
= "{ [i, j] : j <= 2 + 2i }";
170 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
173 str
= "{ [i] -> [i > 0 ? 4 : 5] }";
174 str2
= "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
175 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
178 str
= "[N=2,M] -> { [i=[(M+N)/4]] }";
179 str2
= "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
180 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
183 str
= "{ [x] : x >= 0 }";
184 str2
= "{ [x] : x-0 >= 0 }";
185 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
188 str
= "{ [i] : ((i > 10)) }";
189 str2
= "{ [i] : i >= 11 }";
190 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
193 str
= "{ [i] -> [0] }";
194 str2
= "{ [i] -> [0 * i] }";
195 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
198 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
199 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
200 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
201 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
203 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : (not false) }",
204 "{ [a] -> [b] : true }") < 0)
207 if (test_parse_map_equal(ctx
, "{ [i] : i/2 <= 5 }",
208 "{ [i] : i <= 10 }") < 0)
211 if (test_parse_map_equal(ctx
, "{Sym=[n] [i] : i <= n }",
212 "[n] -> { [i] : i <= n }") < 0)
215 if (test_parse_map_equal(ctx
, "{ [*] }", "{ [a] }") < 0)
218 if (test_parse_map_equal(ctx
, "{ [i] : 2*floor(i/2) = i }",
219 "{ [i] : exists a : i = 2 a }") < 0)
222 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : a = 5 implies b = 5 }",
223 "{ [a] -> [b] : a != 5 or b = 5 }") < 0)
226 if (test_parse_map_equal(ctx
, "{ [a] -> [a - 1 : a > 0] }",
227 "{ [a] -> [a - 1] : a > 0 }") < 0)
229 if (test_parse_map_equal(ctx
,
230 "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
231 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }") < 0)
233 if (test_parse_map_equal(ctx
,
234 "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
235 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
237 if (test_parse_map_equal(ctx
,
238 "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
239 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
241 if (test_parse_map_equal(ctx
,
242 "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
243 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
245 if (test_parse_map_equal(ctx
,
246 "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
247 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
253 void test_read(struct isl_ctx
*ctx
)
257 struct isl_basic_set
*bset1
, *bset2
;
258 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
260 filename
= get_filename(ctx
, "set", "omega");
262 input
= fopen(filename
, "r");
265 bset1
= isl_basic_set_read_from_file(ctx
, input
);
266 bset2
= isl_basic_set_read_from_str(ctx
, str
);
268 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
270 isl_basic_set_free(bset1
);
271 isl_basic_set_free(bset2
);
277 void test_bounded(struct isl_ctx
*ctx
)
282 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
283 bounded
= isl_set_is_bounded(set
);
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] : i <= n }");
293 bounded
= isl_set_is_bounded(set
);
298 /* Construct the basic set { [i] : 5 <= i <= N } */
299 void test_construction(struct isl_ctx
*ctx
)
304 struct isl_basic_set
*bset
;
305 struct isl_constraint
*c
;
309 dim
= isl_space_set_alloc(ctx
, 1, 1);
310 bset
= isl_basic_set_universe(isl_space_copy(dim
));
311 ls
= isl_local_space_from_space(dim
);
313 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
314 isl_int_set_si(v
, -1);
315 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
316 isl_int_set_si(v
, 1);
317 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
318 bset
= isl_basic_set_add_constraint(bset
, c
);
320 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
321 isl_int_set_si(v
, 1);
322 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
323 isl_int_set_si(v
, -5);
324 isl_constraint_set_constant(c
, v
);
325 bset
= isl_basic_set_add_constraint(bset
, c
);
327 isl_local_space_free(ls
);
328 isl_basic_set_free(bset
);
333 void test_dim(struct isl_ctx
*ctx
)
336 isl_map
*map1
, *map2
;
338 map1
= isl_map_read_from_str(ctx
,
339 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
340 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
341 map2
= isl_map_read_from_str(ctx
,
342 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
343 assert(isl_map_is_equal(map1
, map2
));
346 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
347 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
348 assert(isl_map_is_equal(map1
, map2
));
353 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
354 map1
= isl_map_read_from_str(ctx
, str
);
355 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
356 map2
= isl_map_read_from_str(ctx
, str
);
357 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
358 assert(isl_map_is_equal(map1
, map2
));
365 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
369 { &isl_val_neg
, "0", "0" },
370 { &isl_val_abs
, "0", "0" },
371 { &isl_val_2exp
, "0", "1" },
372 { &isl_val_floor
, "0", "0" },
373 { &isl_val_ceil
, "0", "0" },
374 { &isl_val_neg
, "1", "-1" },
375 { &isl_val_neg
, "-1", "1" },
376 { &isl_val_neg
, "1/2", "-1/2" },
377 { &isl_val_neg
, "-1/2", "1/2" },
378 { &isl_val_neg
, "infty", "-infty" },
379 { &isl_val_neg
, "-infty", "infty" },
380 { &isl_val_neg
, "NaN", "NaN" },
381 { &isl_val_abs
, "1", "1" },
382 { &isl_val_abs
, "-1", "1" },
383 { &isl_val_abs
, "1/2", "1/2" },
384 { &isl_val_abs
, "-1/2", "1/2" },
385 { &isl_val_abs
, "infty", "infty" },
386 { &isl_val_abs
, "-infty", "infty" },
387 { &isl_val_abs
, "NaN", "NaN" },
388 { &isl_val_floor
, "1", "1" },
389 { &isl_val_floor
, "-1", "-1" },
390 { &isl_val_floor
, "1/2", "0" },
391 { &isl_val_floor
, "-1/2", "-1" },
392 { &isl_val_floor
, "infty", "infty" },
393 { &isl_val_floor
, "-infty", "-infty" },
394 { &isl_val_floor
, "NaN", "NaN" },
395 { &isl_val_ceil
, "1", "1" },
396 { &isl_val_ceil
, "-1", "-1" },
397 { &isl_val_ceil
, "1/2", "1" },
398 { &isl_val_ceil
, "-1/2", "0" },
399 { &isl_val_ceil
, "infty", "infty" },
400 { &isl_val_ceil
, "-infty", "-infty" },
401 { &isl_val_ceil
, "NaN", "NaN" },
402 { &isl_val_2exp
, "-3", "1/8" },
403 { &isl_val_2exp
, "-1", "1/2" },
404 { &isl_val_2exp
, "1", "2" },
405 { &isl_val_2exp
, "2", "4" },
406 { &isl_val_2exp
, "3", "8" },
409 /* Perform some basic tests of unary operations on isl_val objects.
411 static int test_un_val(isl_ctx
*ctx
)
415 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
418 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
419 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
420 res
= isl_val_read_from_str(ctx
, val_un_tests
[i
].res
);
421 fn
= val_un_tests
[i
].op
;
423 if (isl_val_is_nan(res
))
424 ok
= isl_val_is_nan(v
);
426 ok
= isl_val_eq(v
, res
);
432 isl_die(ctx
, isl_error_unknown
,
433 "unexpected result", return -1);
440 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
441 __isl_take isl_val
*v2
);
443 ['+'] = { &isl_val_add
},
444 ['-'] = { &isl_val_sub
},
445 ['*'] = { &isl_val_mul
},
446 ['/'] = { &isl_val_div
},
447 ['g'] = { &isl_val_gcd
},
448 ['m'] = { &isl_val_min
},
449 ['M'] = { &isl_val_max
},
457 } val_bin_tests
[] = {
458 { "0", '+', "0", "0" },
459 { "1", '+', "0", "1" },
460 { "1", '+', "1", "2" },
461 { "1", '-', "1", "0" },
462 { "1", '*', "1", "1" },
463 { "1", '/', "1", "1" },
464 { "2", '*', "3", "6" },
465 { "2", '*', "1/2", "1" },
466 { "2", '*', "1/3", "2/3" },
467 { "2/3", '*', "3/5", "2/5" },
468 { "2/3", '*', "7/5", "14/15" },
469 { "2", '/', "1/2", "4" },
470 { "-2", '/', "-1/2", "4" },
471 { "-2", '/', "1/2", "-4" },
472 { "2", '/', "-1/2", "-4" },
473 { "2", '/', "2", "1" },
474 { "2", '/', "3", "2/3" },
475 { "2/3", '/', "5/3", "2/5" },
476 { "2/3", '/', "5/7", "14/15" },
477 { "0", '/', "0", "NaN" },
478 { "42", '/', "0", "NaN" },
479 { "-42", '/', "0", "NaN" },
480 { "infty", '/', "0", "NaN" },
481 { "-infty", '/', "0", "NaN" },
482 { "NaN", '/', "0", "NaN" },
483 { "0", '/', "NaN", "NaN" },
484 { "42", '/', "NaN", "NaN" },
485 { "-42", '/', "NaN", "NaN" },
486 { "infty", '/', "NaN", "NaN" },
487 { "-infty", '/', "NaN", "NaN" },
488 { "NaN", '/', "NaN", "NaN" },
489 { "0", '/', "infty", "0" },
490 { "42", '/', "infty", "0" },
491 { "-42", '/', "infty", "0" },
492 { "infty", '/', "infty", "NaN" },
493 { "-infty", '/', "infty", "NaN" },
494 { "NaN", '/', "infty", "NaN" },
495 { "0", '/', "-infty", "0" },
496 { "42", '/', "-infty", "0" },
497 { "-42", '/', "-infty", "0" },
498 { "infty", '/', "-infty", "NaN" },
499 { "-infty", '/', "-infty", "NaN" },
500 { "NaN", '/', "-infty", "NaN" },
501 { "1", '-', "1/3", "2/3" },
502 { "1/3", '+', "1/2", "5/6" },
503 { "1/2", '+', "1/2", "1" },
504 { "3/4", '-', "1/4", "1/2" },
505 { "1/2", '-', "1/3", "1/6" },
506 { "infty", '+', "42", "infty" },
507 { "infty", '+', "infty", "infty" },
508 { "42", '+', "infty", "infty" },
509 { "infty", '-', "infty", "NaN" },
510 { "infty", '*', "infty", "infty" },
511 { "infty", '*', "-infty", "-infty" },
512 { "-infty", '*', "infty", "-infty" },
513 { "-infty", '*', "-infty", "infty" },
514 { "0", '*', "infty", "NaN" },
515 { "1", '*', "infty", "infty" },
516 { "infty", '*', "0", "NaN" },
517 { "infty", '*', "42", "infty" },
518 { "42", '-', "infty", "-infty" },
519 { "infty", '+', "-infty", "NaN" },
520 { "4", 'g', "6", "2" },
521 { "5", 'g', "6", "1" },
522 { "42", 'm', "3", "3" },
523 { "42", 'M', "3", "42" },
524 { "3", 'm', "42", "3" },
525 { "3", 'M', "42", "42" },
526 { "42", 'm', "infty", "42" },
527 { "42", 'M', "infty", "infty" },
528 { "42", 'm', "-infty", "-infty" },
529 { "42", 'M', "-infty", "42" },
530 { "42", 'm', "NaN", "NaN" },
531 { "42", 'M', "NaN", "NaN" },
532 { "infty", 'm', "-infty", "-infty" },
533 { "infty", 'M', "-infty", "infty" },
536 /* Perform some basic tests of binary operations on isl_val objects.
538 static int test_bin_val(isl_ctx
*ctx
)
541 isl_val
*v1
, *v2
, *res
;
542 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
543 __isl_take isl_val
*v2
);
546 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
547 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
548 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
549 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
550 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
552 if (isl_val_is_nan(res
))
553 ok
= isl_val_is_nan(v1
);
555 ok
= isl_val_eq(v1
, res
);
561 isl_die(ctx
, isl_error_unknown
,
562 "unexpected result", return -1);
568 /* Perform some basic tests on isl_val objects.
570 static int test_val(isl_ctx
*ctx
)
572 if (test_un_val(ctx
) < 0)
574 if (test_bin_val(ctx
) < 0)
579 static int test_div(isl_ctx
*ctx
)
588 struct isl_basic_set
*bset
;
589 struct isl_constraint
*c
;
594 dim
= isl_space_set_alloc(ctx
, 0, 3);
595 bset
= isl_basic_set_universe(isl_space_copy(dim
));
596 ls
= isl_local_space_from_space(dim
);
598 c
= isl_equality_alloc(isl_local_space_copy(ls
));
599 isl_int_set_si(v
, -1);
600 isl_constraint_set_constant(c
, v
);
601 isl_int_set_si(v
, 1);
602 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
603 isl_int_set_si(v
, 3);
604 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
605 bset
= isl_basic_set_add_constraint(bset
, c
);
607 c
= isl_equality_alloc(isl_local_space_copy(ls
));
608 isl_int_set_si(v
, 1);
609 isl_constraint_set_constant(c
, v
);
610 isl_int_set_si(v
, -1);
611 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
612 isl_int_set_si(v
, 3);
613 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
614 bset
= isl_basic_set_add_constraint(bset
, c
);
616 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
618 assert(bset
&& bset
->n_div
== 1);
619 isl_local_space_free(ls
);
620 isl_basic_set_free(bset
);
623 dim
= isl_space_set_alloc(ctx
, 0, 3);
624 bset
= isl_basic_set_universe(isl_space_copy(dim
));
625 ls
= isl_local_space_from_space(dim
);
627 c
= isl_equality_alloc(isl_local_space_copy(ls
));
628 isl_int_set_si(v
, 1);
629 isl_constraint_set_constant(c
, v
);
630 isl_int_set_si(v
, -1);
631 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
632 isl_int_set_si(v
, 3);
633 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
634 bset
= isl_basic_set_add_constraint(bset
, c
);
636 c
= isl_equality_alloc(isl_local_space_copy(ls
));
637 isl_int_set_si(v
, -1);
638 isl_constraint_set_constant(c
, v
);
639 isl_int_set_si(v
, 1);
640 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
641 isl_int_set_si(v
, 3);
642 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
643 bset
= isl_basic_set_add_constraint(bset
, c
);
645 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
647 assert(bset
&& bset
->n_div
== 1);
648 isl_local_space_free(ls
);
649 isl_basic_set_free(bset
);
652 dim
= isl_space_set_alloc(ctx
, 0, 3);
653 bset
= isl_basic_set_universe(isl_space_copy(dim
));
654 ls
= isl_local_space_from_space(dim
);
656 c
= isl_equality_alloc(isl_local_space_copy(ls
));
657 isl_int_set_si(v
, 1);
658 isl_constraint_set_constant(c
, v
);
659 isl_int_set_si(v
, -1);
660 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
661 isl_int_set_si(v
, 3);
662 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
663 bset
= isl_basic_set_add_constraint(bset
, c
);
665 c
= isl_equality_alloc(isl_local_space_copy(ls
));
666 isl_int_set_si(v
, -3);
667 isl_constraint_set_constant(c
, v
);
668 isl_int_set_si(v
, 1);
669 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
670 isl_int_set_si(v
, 4);
671 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
672 bset
= isl_basic_set_add_constraint(bset
, c
);
674 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
676 assert(bset
&& bset
->n_div
== 1);
677 isl_local_space_free(ls
);
678 isl_basic_set_free(bset
);
681 dim
= isl_space_set_alloc(ctx
, 0, 3);
682 bset
= isl_basic_set_universe(isl_space_copy(dim
));
683 ls
= isl_local_space_from_space(dim
);
685 c
= isl_equality_alloc(isl_local_space_copy(ls
));
686 isl_int_set_si(v
, 2);
687 isl_constraint_set_constant(c
, v
);
688 isl_int_set_si(v
, -1);
689 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
690 isl_int_set_si(v
, 3);
691 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
692 bset
= isl_basic_set_add_constraint(bset
, c
);
694 c
= isl_equality_alloc(isl_local_space_copy(ls
));
695 isl_int_set_si(v
, -1);
696 isl_constraint_set_constant(c
, v
);
697 isl_int_set_si(v
, 1);
698 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
699 isl_int_set_si(v
, 6);
700 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
701 bset
= isl_basic_set_add_constraint(bset
, c
);
703 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
705 assert(isl_basic_set_is_empty(bset
));
706 isl_local_space_free(ls
);
707 isl_basic_set_free(bset
);
710 dim
= isl_space_set_alloc(ctx
, 0, 3);
711 bset
= isl_basic_set_universe(isl_space_copy(dim
));
712 ls
= isl_local_space_from_space(dim
);
714 c
= isl_equality_alloc(isl_local_space_copy(ls
));
715 isl_int_set_si(v
, -1);
716 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
717 isl_int_set_si(v
, 3);
718 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
719 bset
= isl_basic_set_add_constraint(bset
, c
);
721 c
= isl_equality_alloc(isl_local_space_copy(ls
));
722 isl_int_set_si(v
, 1);
723 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
724 isl_int_set_si(v
, -3);
725 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
726 bset
= isl_basic_set_add_constraint(bset
, c
);
728 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
730 assert(bset
&& bset
->n_div
== 0);
731 isl_basic_set_free(bset
);
732 isl_local_space_free(ls
);
735 dim
= isl_space_set_alloc(ctx
, 0, 3);
736 bset
= isl_basic_set_universe(isl_space_copy(dim
));
737 ls
= isl_local_space_from_space(dim
);
739 c
= isl_equality_alloc(isl_local_space_copy(ls
));
740 isl_int_set_si(v
, -1);
741 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
742 isl_int_set_si(v
, 6);
743 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
744 bset
= isl_basic_set_add_constraint(bset
, c
);
746 c
= isl_equality_alloc(isl_local_space_copy(ls
));
747 isl_int_set_si(v
, 1);
748 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
749 isl_int_set_si(v
, -3);
750 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
751 bset
= isl_basic_set_add_constraint(bset
, c
);
753 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
755 assert(bset
&& bset
->n_div
== 1);
756 isl_basic_set_free(bset
);
757 isl_local_space_free(ls
);
760 /* This test is a bit tricky. We set up an equality
762 * Normalization of divs creates _two_ divs
765 * Afterwards e0 is removed again because it has coefficient -1
766 * and we end up with the original equality and div again.
767 * Perhaps we can avoid the introduction of this temporary div.
769 dim
= isl_space_set_alloc(ctx
, 0, 4);
770 bset
= isl_basic_set_universe(isl_space_copy(dim
));
771 ls
= isl_local_space_from_space(dim
);
773 c
= isl_equality_alloc(isl_local_space_copy(ls
));
774 isl_int_set_si(v
, -1);
775 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
776 isl_int_set_si(v
, -3);
777 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
778 isl_int_set_si(v
, -3);
779 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
780 isl_int_set_si(v
, 6);
781 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
782 bset
= isl_basic_set_add_constraint(bset
, c
);
784 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
786 /* Test disabled for now */
788 assert(bset && bset->n_div == 1);
790 isl_local_space_free(ls
);
791 isl_basic_set_free(bset
);
794 dim
= isl_space_set_alloc(ctx
, 0, 5);
795 bset
= isl_basic_set_universe(isl_space_copy(dim
));
796 ls
= isl_local_space_from_space(dim
);
798 c
= isl_equality_alloc(isl_local_space_copy(ls
));
799 isl_int_set_si(v
, -1);
800 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
801 isl_int_set_si(v
, -3);
802 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
803 isl_int_set_si(v
, -3);
804 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
805 isl_int_set_si(v
, 6);
806 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
807 bset
= isl_basic_set_add_constraint(bset
, c
);
809 c
= isl_equality_alloc(isl_local_space_copy(ls
));
810 isl_int_set_si(v
, -1);
811 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
812 isl_int_set_si(v
, 1);
813 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
814 isl_int_set_si(v
, 1);
815 isl_constraint_set_constant(c
, v
);
816 bset
= isl_basic_set_add_constraint(bset
, c
);
818 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
820 /* Test disabled for now */
822 assert(bset && bset->n_div == 1);
824 isl_local_space_free(ls
);
825 isl_basic_set_free(bset
);
828 dim
= isl_space_set_alloc(ctx
, 0, 4);
829 bset
= isl_basic_set_universe(isl_space_copy(dim
));
830 ls
= isl_local_space_from_space(dim
);
832 c
= isl_equality_alloc(isl_local_space_copy(ls
));
833 isl_int_set_si(v
, 1);
834 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
835 isl_int_set_si(v
, -1);
836 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
837 isl_int_set_si(v
, -2);
838 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
839 bset
= isl_basic_set_add_constraint(bset
, c
);
841 c
= isl_equality_alloc(isl_local_space_copy(ls
));
842 isl_int_set_si(v
, -1);
843 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
844 isl_int_set_si(v
, 3);
845 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
846 isl_int_set_si(v
, 2);
847 isl_constraint_set_constant(c
, v
);
848 bset
= isl_basic_set_add_constraint(bset
, c
);
850 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
852 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
854 assert(!isl_basic_set_is_empty(bset
));
856 isl_local_space_free(ls
);
857 isl_basic_set_free(bset
);
860 dim
= isl_space_set_alloc(ctx
, 0, 3);
861 bset
= isl_basic_set_universe(isl_space_copy(dim
));
862 ls
= isl_local_space_from_space(dim
);
864 c
= isl_equality_alloc(isl_local_space_copy(ls
));
865 isl_int_set_si(v
, 1);
866 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
867 isl_int_set_si(v
, -2);
868 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
869 bset
= isl_basic_set_add_constraint(bset
, c
);
871 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
873 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
875 isl_local_space_free(ls
);
876 isl_basic_set_free(bset
);
880 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
881 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
882 set
= isl_set_read_from_str(ctx
, str
);
883 set
= isl_set_compute_divs(set
);
888 str
= "{ [i,j] : 2*[i/2] + 3 * [j/4] <= 10 and 2 i = j }";
889 bset
= isl_basic_set_read_from_str(ctx
, str
);
890 n
= isl_basic_set_dim(bset
, isl_dim_div
);
891 isl_basic_set_free(bset
);
895 isl_die(ctx
, isl_error_unknown
,
896 "expecting no existentials", return -1);
898 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
899 set
= isl_set_read_from_str(ctx
, str
);
900 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
901 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
902 empty
= isl_set_is_empty(set
);
907 isl_die(ctx
, isl_error_unknown
,
908 "result not as accurate as expected", return -1);
913 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
917 struct isl_basic_set
*bset1
, *bset2
;
918 struct isl_basic_map
*bmap
;
920 filename
= get_filename(ctx
, name
, "omega");
922 input
= fopen(filename
, "r");
925 bset1
= isl_basic_set_read_from_file(ctx
, input
);
926 bmap
= isl_basic_map_read_from_file(ctx
, input
);
928 bset1
= isl_basic_set_apply(bset1
, bmap
);
930 bset2
= isl_basic_set_read_from_file(ctx
, input
);
932 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
934 isl_basic_set_free(bset1
);
935 isl_basic_set_free(bset2
);
941 void test_application(struct isl_ctx
*ctx
)
943 test_application_case(ctx
, "application");
944 test_application_case(ctx
, "application2");
947 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
951 struct isl_basic_set
*bset1
, *bset2
;
953 filename
= get_filename(ctx
, name
, "polylib");
955 input
= fopen(filename
, "r");
958 bset1
= isl_basic_set_read_from_file(ctx
, input
);
959 bset2
= isl_basic_set_read_from_file(ctx
, input
);
961 bset1
= isl_basic_set_affine_hull(bset1
);
963 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
965 isl_basic_set_free(bset1
);
966 isl_basic_set_free(bset2
);
972 int test_affine_hull(struct isl_ctx
*ctx
)
976 isl_basic_set
*bset
, *bset2
;
980 test_affine_hull_case(ctx
, "affine2");
981 test_affine_hull_case(ctx
, "affine");
982 test_affine_hull_case(ctx
, "affine3");
984 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
985 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
986 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
987 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
988 set
= isl_set_read_from_str(ctx
, str
);
989 bset
= isl_set_affine_hull(set
);
990 n
= isl_basic_set_dim(bset
, isl_dim_div
);
991 isl_basic_set_free(bset
);
993 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
996 /* Check that isl_map_affine_hull is not confused by
997 * the reordering of divs in isl_map_align_divs.
999 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1000 "32e0 = b and 32e1 = c); "
1001 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1002 set
= isl_set_read_from_str(ctx
, str
);
1003 bset
= isl_set_affine_hull(set
);
1004 isl_basic_set_free(bset
);
1008 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1009 "32e2 = 31 + 31e0 }";
1010 set
= isl_set_read_from_str(ctx
, str
);
1011 bset
= isl_set_affine_hull(set
);
1012 str
= "{ [a] : exists e : a = 32 e }";
1013 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1014 subset
= isl_basic_set_is_subset(bset
, bset2
);
1015 isl_basic_set_free(bset
);
1016 isl_basic_set_free(bset2
);
1020 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1026 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1030 struct isl_basic_set
*bset1
, *bset2
;
1031 struct isl_set
*set
;
1033 filename
= get_filename(ctx
, name
, "polylib");
1035 input
= fopen(filename
, "r");
1038 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1039 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1041 set
= isl_basic_set_union(bset1
, bset2
);
1042 bset1
= isl_set_convex_hull(set
);
1044 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1046 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1048 isl_basic_set_free(bset1
);
1049 isl_basic_set_free(bset2
);
1055 void test_convex_hull_algo(struct isl_ctx
*ctx
, int convex
)
1057 const char *str1
, *str2
;
1058 isl_set
*set1
, *set2
;
1059 int orig_convex
= ctx
->opt
->convex
;
1060 ctx
->opt
->convex
= convex
;
1062 test_convex_hull_case(ctx
, "convex0");
1063 test_convex_hull_case(ctx
, "convex1");
1064 test_convex_hull_case(ctx
, "convex2");
1065 test_convex_hull_case(ctx
, "convex3");
1066 test_convex_hull_case(ctx
, "convex4");
1067 test_convex_hull_case(ctx
, "convex5");
1068 test_convex_hull_case(ctx
, "convex6");
1069 test_convex_hull_case(ctx
, "convex7");
1070 test_convex_hull_case(ctx
, "convex8");
1071 test_convex_hull_case(ctx
, "convex9");
1072 test_convex_hull_case(ctx
, "convex10");
1073 test_convex_hull_case(ctx
, "convex11");
1074 test_convex_hull_case(ctx
, "convex12");
1075 test_convex_hull_case(ctx
, "convex13");
1076 test_convex_hull_case(ctx
, "convex14");
1077 test_convex_hull_case(ctx
, "convex15");
1079 str1
= "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1080 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1081 "(i0 = 0 and i1 = 0 and i2 = 0) }";
1082 str2
= "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
1083 set1
= isl_set_read_from_str(ctx
, str1
);
1084 set2
= isl_set_read_from_str(ctx
, str2
);
1085 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1086 assert(isl_set_is_equal(set1
, set2
));
1090 ctx
->opt
->convex
= orig_convex
;
1093 void test_convex_hull(struct isl_ctx
*ctx
)
1095 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
);
1096 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
);
1099 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1103 struct isl_basic_set
*bset1
, *bset2
;
1105 filename
= get_filename(ctx
, name
, "polylib");
1107 input
= fopen(filename
, "r");
1110 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1111 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1113 bset1
= isl_basic_set_gist(bset1
, bset2
);
1115 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1117 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1119 isl_basic_set_free(bset1
);
1120 isl_basic_set_free(bset2
);
1126 static int test_gist(struct isl_ctx
*ctx
)
1129 isl_basic_set
*bset1
, *bset2
;
1130 isl_map
*map1
, *map2
;
1132 test_gist_case(ctx
, "gist1");
1134 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1135 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1136 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1137 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1138 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1139 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1140 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1141 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1142 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1143 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1144 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1145 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1146 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1147 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1148 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1149 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1150 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1151 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1152 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1153 bset1
= isl_basic_set_gist(bset1
, bset2
);
1154 assert(bset1
&& bset1
->n_div
== 0);
1155 isl_basic_set_free(bset1
);
1157 /* Check that the integer divisions of the second disjunct
1158 * do not spread to the first disjunct.
1160 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1161 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1162 "(exists (e0 = [(-1 + t1)/16], "
1163 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1164 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1165 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1166 "o0 <= 4294967295 and t1 <= -1)) }";
1167 map1
= isl_map_read_from_str(ctx
, str
);
1168 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1169 map2
= isl_map_read_from_str(ctx
, str
);
1170 map1
= isl_map_gist(map1
, map2
);
1174 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1175 isl_map_free(map1
); return -1);
1176 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1177 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1178 isl_map_free(map1
); return -1);
1184 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1186 isl_set
*set
, *set2
;
1190 set
= isl_set_read_from_str(ctx
, str
);
1191 set
= isl_set_coalesce(set
);
1192 set2
= isl_set_read_from_str(ctx
, str
);
1193 equal
= isl_set_is_equal(set
, set2
);
1194 one
= set
&& set
->n
== 1;
1201 isl_die(ctx
, isl_error_unknown
,
1202 "coalesced set not equal to input", return -1);
1203 if (check_one
&& !one
)
1204 isl_die(ctx
, isl_error_unknown
,
1205 "coalesced set should not be a union", return -1);
1210 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1215 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1216 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1218 if (test_coalesce_set(ctx
,
1219 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1220 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1221 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1222 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1223 "-10 <= y <= 0}", 1) < 0)
1225 if (test_coalesce_set(ctx
,
1226 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
1228 if (test_coalesce_set(ctx
,
1229 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
1237 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1242 /* Inputs for coalescing tests.
1243 * "str" is a string representation of the input set.
1244 * "single_disjunct" is set if we expect the result to consist of
1245 * a single disjunct.
1248 int single_disjunct
;
1250 } coalesce_tests
[] = {
1251 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1252 "y >= x & x >= 2 & 5 >= y }" },
1253 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1254 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1255 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1256 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1257 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1258 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1259 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1260 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1261 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1262 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1263 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1264 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1265 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1266 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1267 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1268 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1269 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1270 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1271 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1272 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1273 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1274 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1275 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1276 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1277 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1278 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1279 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1280 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1281 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1282 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1283 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1284 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1285 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1286 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1287 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1288 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1289 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1290 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1291 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1292 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1293 "[o0, o1, o2, o3, o4, o5, o6]] : "
1294 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1295 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1296 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1297 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1298 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1299 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1300 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1301 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1302 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1303 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1304 "o6 >= i3 + i6 - o3 and M >= 0 and "
1305 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1306 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1307 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1308 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1309 "(o0 = 0 and M >= 2 and N >= 3) or "
1310 "(M = 0 and o0 = 0 and N >= 3) }" },
1311 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1312 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1313 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1314 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1315 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1316 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1317 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1318 "(y = 3 and x = 1) }" },
1319 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1320 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1321 "i1 <= M and i3 <= M and i4 <= M) or "
1322 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1323 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1324 "i4 <= -1 + M) }" },
1325 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1326 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1327 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1328 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1329 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1330 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1331 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1332 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1333 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1334 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1335 { 0, "{ [a, b] : exists e : 2e = a and "
1336 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1337 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1338 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1339 "j >= 1 and j' <= i + j - i' and i >= 1; "
1341 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1342 "[i,j] : exists a : j = 3a }" },
1343 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1344 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1346 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1347 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1348 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1349 "c <= 6 + 8a and a >= 3; "
1350 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1351 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1352 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1353 "[x,0] : 3 <= x <= 4 }" },
1354 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1355 "[x,0] : 4 <= x <= 5 }" },
1356 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1357 "[x,0] : 3 <= x <= 5 }" },
1358 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1359 "[x,0] : 3 <= x <= 4 }" },
1360 { 1 , "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1362 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1365 /* Test the functionality of isl_set_coalesce.
1366 * That is, check that the output is always equal to the input
1367 * and in some cases that the result consists of a single disjunct.
1369 static int test_coalesce(struct isl_ctx
*ctx
)
1373 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
1374 const char *str
= coalesce_tests
[i
].str
;
1375 int check_one
= coalesce_tests
[i
].single_disjunct
;
1376 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
1380 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
1386 void test_closure(struct isl_ctx
*ctx
)
1390 isl_map
*up
, *right
;
1391 isl_map
*map
, *map2
;
1394 /* COCOA example 1 */
1395 map
= isl_map_read_from_str(ctx
,
1396 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1397 "1 <= i and i < n and 1 <= j and j < n or "
1398 "i2 = i + 1 and j2 = j - 1 and "
1399 "1 <= i and i < n and 2 <= j and j <= n }");
1400 map
= isl_map_power(map
, &exact
);
1404 /* COCOA example 1 */
1405 map
= isl_map_read_from_str(ctx
,
1406 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1407 "1 <= i and i < n and 1 <= j and j < n or "
1408 "i2 = i + 1 and j2 = j - 1 and "
1409 "1 <= i and i < n and 2 <= j and j <= n }");
1410 map
= isl_map_transitive_closure(map
, &exact
);
1412 map2
= isl_map_read_from_str(ctx
,
1413 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1414 "1 <= i and i < n and 1 <= j and j <= n and "
1415 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1416 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1417 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1418 assert(isl_map_is_equal(map
, map2
));
1422 map
= isl_map_read_from_str(ctx
,
1423 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1424 " 0 <= y and y <= n }");
1425 map
= isl_map_transitive_closure(map
, &exact
);
1426 map2
= isl_map_read_from_str(ctx
,
1427 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1428 " 0 <= y and y <= n }");
1429 assert(isl_map_is_equal(map
, map2
));
1433 /* COCOA example 2 */
1434 map
= isl_map_read_from_str(ctx
,
1435 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1436 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1437 "i2 = i + 2 and j2 = j - 2 and "
1438 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1439 map
= isl_map_transitive_closure(map
, &exact
);
1441 map2
= isl_map_read_from_str(ctx
,
1442 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1443 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1444 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1445 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1446 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1447 assert(isl_map_is_equal(map
, map2
));
1451 /* COCOA Fig.2 left */
1452 map
= isl_map_read_from_str(ctx
,
1453 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1454 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1456 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1457 "j <= 2 i - 3 and j <= n - 2 or "
1458 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1459 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1460 map
= isl_map_transitive_closure(map
, &exact
);
1464 /* COCOA Fig.2 right */
1465 map
= isl_map_read_from_str(ctx
,
1466 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1467 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1469 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1470 "j <= 2 i - 4 and j <= n - 3 or "
1471 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1472 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1473 map
= isl_map_power(map
, &exact
);
1477 /* COCOA Fig.2 right */
1478 map
= isl_map_read_from_str(ctx
,
1479 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1480 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1482 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1483 "j <= 2 i - 4 and j <= n - 3 or "
1484 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1485 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1486 map
= isl_map_transitive_closure(map
, &exact
);
1488 map2
= isl_map_read_from_str(ctx
,
1489 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1490 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1491 "j <= n and 3 + i + 2 j <= 3 n and "
1492 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1493 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1494 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1495 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1496 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1497 assert(isl_map_is_equal(map
, map2
));
1501 /* COCOA Fig.1 right */
1502 dom
= isl_set_read_from_str(ctx
,
1503 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1504 "2 x - 3 y + 3 >= 0 }");
1505 right
= isl_map_read_from_str(ctx
,
1506 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1507 up
= isl_map_read_from_str(ctx
,
1508 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1509 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1510 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1511 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1512 up
= isl_map_intersect_range(up
, dom
);
1513 map
= isl_map_union(up
, right
);
1514 map
= isl_map_transitive_closure(map
, &exact
);
1516 map2
= isl_map_read_from_str(ctx
,
1517 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1518 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1519 assert(isl_map_is_equal(map
, map2
));
1523 /* COCOA Theorem 1 counter example */
1524 map
= isl_map_read_from_str(ctx
,
1525 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1526 "i2 = 1 and j2 = j or "
1527 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1528 map
= isl_map_transitive_closure(map
, &exact
);
1532 map
= isl_map_read_from_str(ctx
,
1533 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1534 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1535 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1536 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1537 map
= isl_map_transitive_closure(map
, &exact
);
1541 /* Kelly et al 1996, fig 12 */
1542 map
= isl_map_read_from_str(ctx
,
1543 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1544 "1 <= i,j,j+1 <= n or "
1545 "j = n and j2 = 1 and i2 = i + 1 and "
1546 "1 <= i,i+1 <= n }");
1547 map
= isl_map_transitive_closure(map
, &exact
);
1549 map2
= isl_map_read_from_str(ctx
,
1550 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1551 "1 <= i <= n and i = i2 or "
1552 "1 <= i < i2 <= n and 1 <= j <= n and "
1554 assert(isl_map_is_equal(map
, map2
));
1558 /* Omega's closure4 */
1559 map
= isl_map_read_from_str(ctx
,
1560 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1561 "1 <= x,y <= 10 or "
1562 "x2 = x + 1 and y2 = y and "
1563 "1 <= x <= 20 && 5 <= y <= 15 }");
1564 map
= isl_map_transitive_closure(map
, &exact
);
1568 map
= isl_map_read_from_str(ctx
,
1569 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1570 map
= isl_map_transitive_closure(map
, &exact
);
1572 map2
= isl_map_read_from_str(ctx
,
1573 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1574 assert(isl_map_is_equal(map
, map2
));
1578 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1579 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1580 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1581 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1582 map
= isl_map_read_from_str(ctx
, str
);
1583 map
= isl_map_transitive_closure(map
, &exact
);
1585 map2
= isl_map_read_from_str(ctx
, str
);
1586 assert(isl_map_is_equal(map
, map2
));
1590 str
= "{[0] -> [1]; [2] -> [3]}";
1591 map
= isl_map_read_from_str(ctx
, str
);
1592 map
= isl_map_transitive_closure(map
, &exact
);
1594 map2
= isl_map_read_from_str(ctx
, str
);
1595 assert(isl_map_is_equal(map
, map2
));
1599 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1600 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1601 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1602 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1603 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1604 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1605 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1606 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1607 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1608 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1609 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1610 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1611 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1612 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1613 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1614 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1615 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1616 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1617 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1618 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1619 map
= isl_map_read_from_str(ctx
, str
);
1620 map
= isl_map_transitive_closure(map
, NULL
);
1625 void test_lex(struct isl_ctx
*ctx
)
1630 dim
= isl_space_set_alloc(ctx
, 0, 0);
1631 map
= isl_map_lex_le(dim
);
1632 assert(!isl_map_is_empty(map
));
1636 static int test_lexmin(struct isl_ctx
*ctx
)
1640 isl_basic_map
*bmap
;
1641 isl_map
*map
, *map2
;
1644 isl_pw_multi_aff
*pma
;
1646 str
= "[p0, p1] -> { [] -> [] : "
1647 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1648 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1649 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1650 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1651 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1652 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1653 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1654 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1655 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1656 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1657 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1658 map
= isl_map_read_from_str(ctx
, str
);
1659 map
= isl_map_lexmin(map
);
1662 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1663 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1664 set
= isl_set_read_from_str(ctx
, str
);
1665 set
= isl_set_lexmax(set
);
1666 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1667 set2
= isl_set_read_from_str(ctx
, str
);
1668 set
= isl_set_intersect(set
, set2
);
1669 assert(!isl_set_is_empty(set
));
1672 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1673 map
= isl_map_read_from_str(ctx
, str
);
1674 map
= isl_map_lexmin(map
);
1675 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1676 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1677 map2
= isl_map_read_from_str(ctx
, str
);
1678 assert(isl_map_is_equal(map
, map2
));
1682 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1683 map
= isl_map_read_from_str(ctx
, str
);
1684 map2
= isl_map_copy(map
);
1685 map
= isl_map_lexmin(map
);
1686 assert(isl_map_is_equal(map
, map2
));
1690 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1691 map
= isl_map_read_from_str(ctx
, str
);
1692 map
= isl_map_lexmin(map
);
1693 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1694 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1695 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1696 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1697 map2
= isl_map_read_from_str(ctx
, str
);
1698 assert(isl_map_is_equal(map
, map2
));
1702 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1703 " 8i' <= i and 8i' >= -7 + i }";
1704 bmap
= isl_basic_map_read_from_str(ctx
, str
);
1705 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
1706 map2
= isl_map_from_pw_multi_aff(pma
);
1707 map
= isl_map_from_basic_map(bmap
);
1708 assert(isl_map_is_equal(map
, map2
));
1712 str
= "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1713 map
= isl_map_read_from_str(ctx
, str
);
1714 map
= isl_map_lexmin(map
);
1715 str
= "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1716 map2
= isl_map_read_from_str(ctx
, str
);
1717 assert(isl_map_is_equal(map
, map2
));
1721 /* Check that empty pieces are properly combined. */
1722 str
= "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
1723 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
1724 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }";
1725 map
= isl_map_read_from_str(ctx
, str
);
1726 map
= isl_map_lexmin(map
);
1727 str
= "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
1728 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
1730 map2
= isl_map_read_from_str(ctx
, str
);
1731 assert(isl_map_is_equal(map
, map2
));
1735 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1736 " 8i' <= i and 8i' >= -7 + i }";
1737 set
= isl_set_read_from_str(ctx
, str
);
1738 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
1739 set2
= isl_set_from_pw_multi_aff(pma
);
1740 equal
= isl_set_is_equal(set
, set2
);
1746 isl_die(ctx
, isl_error_unknown
,
1747 "unexpected difference between set and "
1748 "piecewise affine expression", return -1);
1753 /* Check that isl_set_min_val and isl_set_max_val compute the correct
1754 * result on non-convex inputs.
1756 static int test_min(struct isl_ctx
*ctx
)
1763 set
= isl_set_read_from_str(ctx
, "{ [-1]; [1] }");
1764 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x] }");
1765 val
= isl_set_min_val(set
, aff
);
1766 min_ok
= isl_val_is_negone(val
);
1768 val
= isl_set_max_val(set
, aff
);
1769 max_ok
= isl_val_is_one(val
);
1774 if (min_ok
< 0 || max_ok
< 0)
1777 isl_die(ctx
, isl_error_unknown
,
1778 "unexpected minimum", return -1);
1780 isl_die(ctx
, isl_error_unknown
,
1781 "unexpected maximum", return -1);
1791 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1792 void *dep_user
, void *user
)
1794 struct must_may
*mm
= (struct must_may
*)user
;
1797 mm
->must
= isl_map_union(mm
->must
, dep
);
1799 mm
->may
= isl_map_union(mm
->may
, dep
);
1804 static int common_space(void *first
, void *second
)
1806 int depth
= *(int *)first
;
1810 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1818 map2
= isl_map_read_from_str(map
->ctx
, str
);
1819 equal
= isl_map_is_equal(map
, map2
);
1825 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
1829 equal
= map_is_equal(map
, str
);
1833 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
1834 "result not as expected", return -1);
1838 void test_dep(struct isl_ctx
*ctx
)
1843 isl_access_info
*ai
;
1850 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1851 map
= isl_map_read_from_str(ctx
, str
);
1852 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1854 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1855 map
= isl_map_read_from_str(ctx
, str
);
1856 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1858 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1859 map
= isl_map_read_from_str(ctx
, str
);
1860 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1862 flow
= isl_access_info_compute_flow(ai
);
1863 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1864 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1865 mm
.may
= isl_map_empty(dim
);
1867 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1869 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1870 " [1,10,0] -> [2,5,0] }";
1871 assert(map_is_equal(mm
.must
, str
));
1872 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1873 assert(map_is_equal(mm
.may
, str
));
1875 isl_map_free(mm
.must
);
1876 isl_map_free(mm
.may
);
1877 isl_flow_free(flow
);
1880 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1881 map
= isl_map_read_from_str(ctx
, str
);
1882 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1884 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1885 map
= isl_map_read_from_str(ctx
, str
);
1886 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1888 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1889 map
= isl_map_read_from_str(ctx
, str
);
1890 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1892 flow
= isl_access_info_compute_flow(ai
);
1893 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1894 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1895 mm
.may
= isl_map_empty(dim
);
1897 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1899 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1900 assert(map_is_equal(mm
.must
, str
));
1901 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1902 assert(map_is_equal(mm
.may
, str
));
1904 isl_map_free(mm
.must
);
1905 isl_map_free(mm
.may
);
1906 isl_flow_free(flow
);
1909 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1910 map
= isl_map_read_from_str(ctx
, str
);
1911 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1913 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1914 map
= isl_map_read_from_str(ctx
, str
);
1915 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1917 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1918 map
= isl_map_read_from_str(ctx
, str
);
1919 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1921 flow
= isl_access_info_compute_flow(ai
);
1922 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1923 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1924 mm
.may
= isl_map_empty(dim
);
1926 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1928 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1929 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1930 assert(map_is_equal(mm
.may
, str
));
1931 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1932 assert(map_is_equal(mm
.must
, str
));
1934 isl_map_free(mm
.must
);
1935 isl_map_free(mm
.may
);
1936 isl_flow_free(flow
);
1939 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1940 map
= isl_map_read_from_str(ctx
, str
);
1941 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1943 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1944 map
= isl_map_read_from_str(ctx
, str
);
1945 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1947 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1948 map
= isl_map_read_from_str(ctx
, str
);
1949 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1951 flow
= isl_access_info_compute_flow(ai
);
1952 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1953 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1954 mm
.may
= isl_map_empty(dim
);
1956 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1958 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1959 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1960 assert(map_is_equal(mm
.may
, str
));
1961 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1962 assert(map_is_equal(mm
.must
, str
));
1964 isl_map_free(mm
.must
);
1965 isl_map_free(mm
.may
);
1966 isl_flow_free(flow
);
1969 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1970 map
= isl_map_read_from_str(ctx
, str
);
1971 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1973 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1974 map
= isl_map_read_from_str(ctx
, str
);
1975 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1977 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1978 map
= isl_map_read_from_str(ctx
, str
);
1979 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1981 flow
= isl_access_info_compute_flow(ai
);
1982 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1983 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1984 mm
.may
= isl_map_empty(dim
);
1986 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1988 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1989 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1990 assert(map_is_equal(mm
.may
, str
));
1991 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1992 assert(map_is_equal(mm
.must
, str
));
1994 isl_map_free(mm
.must
);
1995 isl_map_free(mm
.may
);
1996 isl_flow_free(flow
);
2001 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2002 map
= isl_map_read_from_str(ctx
, str
);
2003 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
2005 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2006 map
= isl_map_read_from_str(ctx
, str
);
2007 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2009 flow
= isl_access_info_compute_flow(ai
);
2010 dim
= isl_space_alloc(ctx
, 0, 5, 5);
2011 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2012 mm
.may
= isl_map_empty(dim
);
2014 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2016 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
2017 assert(map_is_equal(mm
.must
, str
));
2018 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
2019 assert(map_is_equal(mm
.may
, str
));
2021 isl_map_free(mm
.must
);
2022 isl_map_free(mm
.may
);
2023 isl_flow_free(flow
);
2026 int test_sv(isl_ctx
*ctx
)
2030 isl_union_map
*umap
;
2033 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
2034 map
= isl_map_read_from_str(ctx
, str
);
2035 sv
= isl_map_is_single_valued(map
);
2040 isl_die(ctx
, isl_error_internal
,
2041 "map not detected as single valued", return -1);
2043 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
2044 map
= isl_map_read_from_str(ctx
, str
);
2045 sv
= isl_map_is_single_valued(map
);
2050 isl_die(ctx
, isl_error_internal
,
2051 "map detected as single valued", return -1);
2053 str
= "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
2054 umap
= isl_union_map_read_from_str(ctx
, str
);
2055 sv
= isl_union_map_is_single_valued(umap
);
2056 isl_union_map_free(umap
);
2060 isl_die(ctx
, isl_error_internal
,
2061 "map not detected as single valued", return -1);
2063 str
= "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
2064 umap
= isl_union_map_read_from_str(ctx
, str
);
2065 sv
= isl_union_map_is_single_valued(umap
);
2066 isl_union_map_free(umap
);
2070 isl_die(ctx
, isl_error_internal
,
2071 "map detected as single valued", return -1);
2076 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
2080 map
= isl_map_read_from_str(ctx
, str
);
2082 assert(isl_map_is_bijective(map
));
2084 assert(!isl_map_is_bijective(map
));
2088 void test_bijective(struct isl_ctx
*ctx
)
2090 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
2091 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
2092 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
2093 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
2094 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
2095 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
2096 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
2097 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
2098 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
2099 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
2100 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
2101 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
2102 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
2105 static int test_pwqp(struct isl_ctx
*ctx
)
2109 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
2112 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2113 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2115 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
2118 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2119 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2121 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2123 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2125 isl_pw_qpolynomial_free(pwqp1
);
2127 str
= "{ [i] -> i }";
2128 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2129 str
= "{ [k] : exists a : k = 2a }";
2130 set
= isl_set_read_from_str(ctx
, str
);
2131 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2132 str
= "{ [i] -> i }";
2133 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2135 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2137 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2139 isl_pw_qpolynomial_free(pwqp1
);
2141 str
= "{ [i] -> i + [ (i + [i/3])/2 ] }";
2142 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2144 set
= isl_set_read_from_str(ctx
, str
);
2145 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2146 str
= "{ [i] -> 16 }";
2147 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2149 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2151 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2153 isl_pw_qpolynomial_free(pwqp1
);
2155 str
= "{ [i] -> ([(i)/2]) }";
2156 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2157 str
= "{ [k] : exists a : k = 2a+1 }";
2158 set
= isl_set_read_from_str(ctx
, str
);
2159 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2160 str
= "{ [i] -> -1/2 + 1/2 * i }";
2161 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2163 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2165 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2167 isl_pw_qpolynomial_free(pwqp1
);
2169 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
2170 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2171 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
2172 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2174 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2176 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2178 isl_pw_qpolynomial_free(pwqp1
);
2180 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
2181 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2182 str
= "{ [x] -> x }";
2183 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2185 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2187 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2189 isl_pw_qpolynomial_free(pwqp1
);
2191 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
2192 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2193 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2194 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
2195 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2196 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2197 isl_pw_qpolynomial_free(pwqp1
);
2199 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
2200 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2201 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2202 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2203 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
2204 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
2205 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2206 isl_pw_qpolynomial_free(pwqp1
);
2207 isl_pw_qpolynomial_free(pwqp2
);
2211 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2213 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
2214 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2215 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2216 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2217 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
2219 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2220 isl_pw_qpolynomial_free(pwqp1
);
2221 isl_pw_qpolynomial_free(pwqp2
);
2225 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2230 void test_split_periods(isl_ctx
*ctx
)
2233 isl_pw_qpolynomial
*pwqp
;
2235 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
2236 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
2237 "U >= 0; [U,V] -> U^2 : U >= 100 }";
2238 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2240 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
2243 isl_pw_qpolynomial_free(pwqp
);
2246 void test_union(isl_ctx
*ctx
)
2249 isl_union_set
*uset1
, *uset2
;
2250 isl_union_map
*umap1
, *umap2
;
2252 str
= "{ [i] : 0 <= i <= 1 }";
2253 uset1
= isl_union_set_read_from_str(ctx
, str
);
2254 str
= "{ [1] -> [0] }";
2255 umap1
= isl_union_map_read_from_str(ctx
, str
);
2257 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
2258 assert(isl_union_map_is_equal(umap1
, umap2
));
2260 isl_union_map_free(umap1
);
2261 isl_union_map_free(umap2
);
2263 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
2264 umap1
= isl_union_map_read_from_str(ctx
, str
);
2265 str
= "{ A[i]; B[i] }";
2266 uset1
= isl_union_set_read_from_str(ctx
, str
);
2268 uset2
= isl_union_map_domain(umap1
);
2270 assert(isl_union_set_is_equal(uset1
, uset2
));
2272 isl_union_set_free(uset1
);
2273 isl_union_set_free(uset2
);
2276 void test_bound(isl_ctx
*ctx
)
2279 isl_pw_qpolynomial
*pwqp
;
2280 isl_pw_qpolynomial_fold
*pwf
;
2282 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
2283 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2284 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2285 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 4);
2286 isl_pw_qpolynomial_fold_free(pwf
);
2288 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
2289 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2290 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2291 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 1);
2292 isl_pw_qpolynomial_fold_free(pwf
);
2295 void test_lift(isl_ctx
*ctx
)
2298 isl_basic_map
*bmap
;
2299 isl_basic_set
*bset
;
2301 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
2302 bset
= isl_basic_set_read_from_str(ctx
, str
);
2303 bset
= isl_basic_set_lift(bset
);
2304 bmap
= isl_basic_map_from_range(bset
);
2305 bset
= isl_basic_map_domain(bmap
);
2306 isl_basic_set_free(bset
);
2313 } subset_tests
[] = {
2315 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
2316 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
2317 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
2319 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
2320 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
2321 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
2322 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
2323 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
2324 "256e0 <= 255i and 256e0 >= -255 + 255i and "
2325 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
2326 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
2327 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
2328 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
2329 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
2330 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
2331 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
2332 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
2333 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
2334 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
2335 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
2336 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
2337 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
2338 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
2339 "4e0 <= -57 + i0 + i1)) or "
2340 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
2341 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
2342 "4e0 >= -61 + i0 + i1)) or "
2343 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
2346 static int test_subset(isl_ctx
*ctx
)
2349 isl_set
*set1
, *set2
;
2352 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
2353 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
2354 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
2355 subset
= isl_set_is_subset(set1
, set2
);
2360 if (subset
!= subset_tests
[i
].subset
)
2361 isl_die(ctx
, isl_error_unknown
,
2362 "incorrect subset result", return -1);
2369 const char *minuend
;
2370 const char *subtrahend
;
2371 const char *difference
;
2372 } subtract_domain_tests
[] = {
2373 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
2374 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
2375 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
2378 static int test_subtract(isl_ctx
*ctx
)
2381 isl_union_map
*umap1
, *umap2
;
2382 isl_union_set
*uset
;
2385 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2386 umap1
= isl_union_map_read_from_str(ctx
,
2387 subtract_domain_tests
[i
].minuend
);
2388 uset
= isl_union_set_read_from_str(ctx
,
2389 subtract_domain_tests
[i
].subtrahend
);
2390 umap2
= isl_union_map_read_from_str(ctx
,
2391 subtract_domain_tests
[i
].difference
);
2392 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
2393 equal
= isl_union_map_is_equal(umap1
, umap2
);
2394 isl_union_map_free(umap1
);
2395 isl_union_map_free(umap2
);
2399 isl_die(ctx
, isl_error_unknown
,
2400 "incorrect subtract domain result", return -1);
2406 int test_factorize(isl_ctx
*ctx
)
2409 isl_basic_set
*bset
;
2412 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2413 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2414 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2415 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2416 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2417 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2418 "3i5 >= -2i0 - i2 + 3i4 }";
2419 bset
= isl_basic_set_read_from_str(ctx
, str
);
2420 f
= isl_basic_set_factorizer(bset
);
2421 isl_basic_set_free(bset
);
2422 isl_factorizer_free(f
);
2424 isl_die(ctx
, isl_error_unknown
,
2425 "failed to construct factorizer", return -1);
2427 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2428 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2429 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2430 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2431 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2432 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2433 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2434 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2435 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2436 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2437 bset
= isl_basic_set_read_from_str(ctx
, str
);
2438 f
= isl_basic_set_factorizer(bset
);
2439 isl_basic_set_free(bset
);
2440 isl_factorizer_free(f
);
2442 isl_die(ctx
, isl_error_unknown
,
2443 "failed to construct factorizer", return -1);
2448 static int check_injective(__isl_take isl_map
*map
, void *user
)
2450 int *injective
= user
;
2452 *injective
= isl_map_is_injective(map
);
2455 if (*injective
< 0 || !*injective
)
2461 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
2462 const char *r
, const char *s
, int tilable
, int parallel
)
2466 isl_union_map
*W
, *R
, *S
;
2467 isl_union_map
*empty
;
2468 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
2469 isl_union_map
*validity
, *proximity
, *coincidence
;
2470 isl_union_map
*schedule
;
2471 isl_union_map
*test
;
2472 isl_union_set
*delta
;
2473 isl_union_set
*domain
;
2477 isl_schedule_constraints
*sc
;
2478 isl_schedule
*sched
;
2479 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
2481 D
= isl_union_set_read_from_str(ctx
, d
);
2482 W
= isl_union_map_read_from_str(ctx
, w
);
2483 R
= isl_union_map_read_from_str(ctx
, r
);
2484 S
= isl_union_map_read_from_str(ctx
, s
);
2486 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
2487 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
2489 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
2490 isl_union_map_compute_flow(isl_union_map_copy(R
),
2491 isl_union_map_copy(W
), empty
,
2492 isl_union_map_copy(S
),
2493 &dep_raw
, NULL
, NULL
, NULL
);
2494 isl_union_map_compute_flow(isl_union_map_copy(W
),
2495 isl_union_map_copy(W
),
2496 isl_union_map_copy(R
),
2497 isl_union_map_copy(S
),
2498 &dep_waw
, &dep_war
, NULL
, NULL
);
2500 dep
= isl_union_map_union(dep_waw
, dep_war
);
2501 dep
= isl_union_map_union(dep
, dep_raw
);
2502 validity
= isl_union_map_copy(dep
);
2503 coincidence
= isl_union_map_copy(dep
);
2504 proximity
= isl_union_map_copy(dep
);
2506 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
2507 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2508 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
2509 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2510 sched
= isl_schedule_constraints_compute_schedule(sc
);
2511 schedule
= isl_schedule_get_map(sched
);
2512 isl_schedule_free(sched
);
2513 isl_union_map_free(W
);
2514 isl_union_map_free(R
);
2515 isl_union_map_free(S
);
2518 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
2520 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
2521 is_complete
= isl_union_set_is_subset(D
, domain
);
2522 isl_union_set_free(D
);
2523 isl_union_set_free(domain
);
2525 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
2526 test
= isl_union_map_apply_range(test
, dep
);
2527 test
= isl_union_map_apply_range(test
, schedule
);
2529 delta
= isl_union_map_deltas(test
);
2530 if (isl_union_set_n_set(delta
) == 0) {
2534 isl_union_set_free(delta
);
2536 delta_set
= isl_set_from_union_set(delta
);
2538 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2539 for (i
= 0; i
< tilable
; ++i
)
2540 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
2541 is_tilable
= isl_set_is_subset(delta_set
, slice
);
2542 isl_set_free(slice
);
2544 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2545 for (i
= 0; i
< parallel
; ++i
)
2546 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
2547 is_parallel
= isl_set_is_subset(delta_set
, slice
);
2548 isl_set_free(slice
);
2550 origin
= isl_set_universe(isl_set_get_space(delta_set
));
2551 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
2552 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
2554 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
2555 delta_set
= isl_set_lexmin(delta_set
);
2557 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
2559 isl_set_free(origin
);
2560 isl_set_free(delta_set
);
2563 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
2564 is_injection
< 0 || is_complete
< 0)
2567 isl_die(ctx
, isl_error_unknown
,
2568 "generated schedule incomplete", return -1);
2570 isl_die(ctx
, isl_error_unknown
,
2571 "generated schedule not injective on each statement",
2574 isl_die(ctx
, isl_error_unknown
,
2575 "negative dependences in generated schedule",
2578 isl_die(ctx
, isl_error_unknown
,
2579 "generated schedule not as tilable as expected",
2582 isl_die(ctx
, isl_error_unknown
,
2583 "generated schedule not as parallel as expected",
2589 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
2590 const char *domain
, const char *validity
, const char *proximity
)
2594 isl_union_map
*prox
;
2595 isl_schedule_constraints
*sc
;
2596 isl_schedule
*schedule
;
2597 isl_union_map
*sched
;
2599 dom
= isl_union_set_read_from_str(ctx
, domain
);
2600 dep
= isl_union_map_read_from_str(ctx
, validity
);
2601 prox
= isl_union_map_read_from_str(ctx
, proximity
);
2602 sc
= isl_schedule_constraints_on_domain(dom
);
2603 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
2604 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
2605 schedule
= isl_schedule_constraints_compute_schedule(sc
);
2606 sched
= isl_schedule_get_map(schedule
);
2607 isl_schedule_free(schedule
);
2612 /* Check that a schedule can be constructed on the given domain
2613 * with the given validity and proximity constraints.
2615 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
2616 const char *validity
, const char *proximity
)
2618 isl_union_map
*sched
;
2620 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
2624 isl_union_map_free(sched
);
2628 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
2629 const char *validity
, const char *proximity
, const char *expected_sched
)
2631 isl_union_map
*sched1
, *sched2
;
2634 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
2635 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
2637 equal
= isl_union_map_is_equal(sched1
, sched2
);
2638 isl_union_map_free(sched1
);
2639 isl_union_map_free(sched2
);
2644 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
2650 /* Check that the schedule map is properly padded, even after being
2651 * reconstructed from the band forest.
2653 static int test_padded_schedule(isl_ctx
*ctx
)
2657 isl_union_map
*validity
, *proximity
;
2658 isl_schedule_constraints
*sc
;
2659 isl_schedule
*sched
;
2660 isl_union_map
*map1
, *map2
;
2661 isl_band_list
*list
;
2664 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
2665 D
= isl_union_set_read_from_str(ctx
, str
);
2666 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
2667 proximity
= isl_union_map_copy(validity
);
2668 sc
= isl_schedule_constraints_on_domain(D
);
2669 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2670 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2671 sched
= isl_schedule_constraints_compute_schedule(sc
);
2672 map1
= isl_schedule_get_map(sched
);
2673 list
= isl_schedule_get_band_forest(sched
);
2674 isl_band_list_free(list
);
2675 map2
= isl_schedule_get_map(sched
);
2676 isl_schedule_free(sched
);
2677 equal
= isl_union_map_is_equal(map1
, map2
);
2678 isl_union_map_free(map1
);
2679 isl_union_map_free(map2
);
2684 isl_die(ctx
, isl_error_unknown
,
2685 "reconstructed schedule map not the same as original",
2691 /* Input for testing of schedule construction based on
2692 * conditional constraints.
2694 * domain is the iteration domain
2695 * flow are the flow dependences, which determine the validity and
2696 * proximity constraints
2697 * condition are the conditions on the conditional validity constraints
2698 * conditional_validity are the conditional validity constraints
2699 * outer_band_n is the expected number of members in the outer band
2704 const char *condition
;
2705 const char *conditional_validity
;
2707 } live_range_tests
[] = {
2708 /* Contrived example that illustrates that we need to keep
2709 * track of tagged condition dependences and
2710 * tagged conditional validity dependences
2711 * in isl_sched_edge separately.
2712 * In particular, the conditional validity constraints on A
2713 * cannot be satisfied,
2714 * but they can be ignored because there are no corresponding
2715 * condition constraints. However, we do have an additional
2716 * conditional validity constraint that maps to the same
2717 * dependence relation
2718 * as the condition constraint on B. If we did not make a distinction
2719 * between tagged condition and tagged conditional validity
2720 * dependences, then we
2721 * could end up treating this shared dependence as an condition
2722 * constraint on A, forcing a localization of the conditions,
2723 * which is impossible.
2725 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
2726 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
2727 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
2728 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2729 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2730 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
2733 /* TACO 2013 Fig. 7 */
2734 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2735 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2736 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2737 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
2738 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
2739 "0 <= i < n and 0 <= j < n - 1 }",
2740 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
2741 "0 <= i < n and 0 <= j < j' < n;"
2742 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
2743 "0 <= i < i' < n and 0 <= j,j' < n;"
2744 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
2745 "0 <= i,j,j' < n and j < j' }",
2748 /* TACO 2013 Fig. 7, without tags */
2749 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2750 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2751 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2752 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2753 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2754 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
2755 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
2756 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
2759 /* TACO 2013 Fig. 12 */
2760 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
2761 "S3[i,3] : 0 <= i <= 1 }",
2762 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
2763 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
2764 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
2765 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
2766 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2767 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
2768 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2769 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
2770 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
2771 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
2772 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
2777 /* Test schedule construction based on conditional constraints.
2778 * In particular, check the number of members in the outer band
2779 * as an indication of whether tiling is possible or not.
2781 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
2784 isl_union_set
*domain
;
2785 isl_union_map
*condition
;
2786 isl_union_map
*flow
;
2787 isl_union_map
*validity
;
2788 isl_schedule_constraints
*sc
;
2789 isl_schedule
*schedule
;
2790 isl_band_list
*list
;
2794 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
2795 domain
= isl_union_set_read_from_str(ctx
,
2796 live_range_tests
[i
].domain
);
2797 flow
= isl_union_map_read_from_str(ctx
,
2798 live_range_tests
[i
].flow
);
2799 condition
= isl_union_map_read_from_str(ctx
,
2800 live_range_tests
[i
].condition
);
2801 validity
= isl_union_map_read_from_str(ctx
,
2802 live_range_tests
[i
].conditional_validity
);
2803 sc
= isl_schedule_constraints_on_domain(domain
);
2804 sc
= isl_schedule_constraints_set_validity(sc
,
2805 isl_union_map_copy(flow
));
2806 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
2807 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
2808 condition
, validity
);
2809 schedule
= isl_schedule_constraints_compute_schedule(sc
);
2810 list
= isl_schedule_get_band_forest(schedule
);
2811 band
= isl_band_list_get_band(list
, 0);
2812 n_member
= isl_band_n_member(band
);
2813 isl_band_free(band
);
2814 isl_band_list_free(list
);
2815 isl_schedule_free(schedule
);
2819 if (n_member
!= live_range_tests
[i
].outer_band_n
)
2820 isl_die(ctx
, isl_error_unknown
,
2821 "unexpected number of members in outer band",
2827 int test_schedule(isl_ctx
*ctx
)
2829 const char *D
, *W
, *R
, *V
, *P
, *S
;
2831 /* Handle resulting schedule with zero bands. */
2832 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
2836 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2837 W
= "{ S1[t,i] -> a[t,i] }";
2838 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2839 "S1[t,i] -> a[t-1,i+1] }";
2840 S
= "{ S1[t,i] -> [t,i] }";
2841 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2844 /* Fig. 5 of CC2008 */
2845 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2847 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2848 "j >= 2 and j <= -1 + N }";
2849 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2850 "j >= 2 and j <= -1 + N; "
2851 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2852 "j >= 2 and j <= -1 + N }";
2853 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2854 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2857 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2858 W
= "{ S1[i] -> a[i] }";
2859 R
= "{ S2[i] -> a[i+1] }";
2860 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2861 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2864 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2865 W
= "{ S1[i] -> a[i] }";
2866 R
= "{ S2[i] -> a[9-i] }";
2867 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2868 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2871 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2872 W
= "{ S1[i] -> a[i] }";
2873 R
= "[N] -> { S2[i] -> a[N-1-i] }";
2874 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2875 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2878 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2879 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2880 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2881 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2882 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2885 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2886 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2887 R
= "{ S2[i,j] -> a[i-1,j] }";
2888 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2889 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2892 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2893 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2894 R
= "{ S2[i,j] -> a[i,j-1] }";
2895 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2896 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2899 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2900 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2901 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2902 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2903 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2904 "S_0[] -> [0, 0, 0] }";
2905 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
2907 ctx
->opt
->schedule_parametric
= 0;
2908 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2910 ctx
->opt
->schedule_parametric
= 1;
2912 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2913 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2914 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2915 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2916 "S4[i] -> a[i,N] }";
2917 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2918 "S4[i] -> [4,i,0] }";
2919 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2922 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2923 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2925 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2927 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2929 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2930 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2933 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2934 " S_2[t] : t >= 0 and t <= -1 + N; "
2935 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2937 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2938 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2939 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2940 "i >= 0 and i <= -1 + N }";
2941 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2942 "i >= 0 and i <= -1 + N; "
2943 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2944 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2945 " S_0[t] -> [0, t, 0] }";
2947 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2949 ctx
->opt
->schedule_parametric
= 0;
2950 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2952 ctx
->opt
->schedule_parametric
= 1;
2954 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2955 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2956 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
2959 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2960 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2961 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2962 "j >= 0 and j <= -1 + N; "
2963 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2964 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2965 "j >= 0 and j <= -1 + N; "
2966 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2967 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2968 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2971 D
= "{ S_0[i] : i >= 0 }";
2972 W
= "{ S_0[i] -> a[i] : i >= 0 }";
2973 R
= "{ S_0[i] -> a[0] : i >= 0 }";
2974 S
= "{ S_0[i] -> [0, i, 0] }";
2975 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2978 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
2979 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
2980 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
2981 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
2982 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2985 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
2986 "k <= -1 + n and k >= 0 }";
2987 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
2988 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
2989 "k <= -1 + n and k >= 0; "
2990 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
2991 "k <= -1 + n and k >= 0; "
2992 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
2993 "k <= -1 + n and k >= 0 }";
2994 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
2995 ctx
->opt
->schedule_outer_coincidence
= 1;
2996 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2998 ctx
->opt
->schedule_outer_coincidence
= 0;
3000 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
3001 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
3002 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
3003 "Stmt_for_body24[i0, i1, 1, 0]:"
3004 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
3005 "Stmt_for_body7[i0, i1, i2]:"
3006 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
3009 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
3010 "Stmt_for_body24[1, i1, i2, i3]:"
3011 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
3013 "Stmt_for_body24[0, i1, i2, i3] -> "
3014 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
3015 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
3017 "Stmt_for_body24[0, i1, i2, i3] ->"
3018 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
3019 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
3020 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
3021 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
3022 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
3023 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
3024 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
3025 "i1 <= 6 and i1 >= 0;"
3026 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
3027 "Stmt_for_body7[i0, i1, i2] -> "
3028 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
3029 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
3030 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
3031 "Stmt_for_body7[i0, i1, i2] -> "
3032 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
3033 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
3034 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
3036 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
3037 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
3038 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
3040 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3043 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
3044 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
3045 "j >= 1 and j <= 7;"
3046 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
3047 "j >= 1 and j <= 8 }";
3049 S
= "{ S_0[i, j] -> [i + j, j] }";
3050 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3051 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3053 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3055 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
3056 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
3057 "j >= 0 and j <= -1 + i }";
3058 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
3059 "i <= -1 + N and j >= 0;"
3060 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
3063 S
= "{ S_0[i, j] -> [i, j] }";
3064 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3065 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3067 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3069 /* Test both algorithms on a case with only proximity dependences. */
3070 D
= "{ S[i,j] : 0 <= i <= 10 }";
3072 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
3073 S
= "{ S[i, j] -> [j, i] }";
3074 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3075 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3077 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3078 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3081 D
= "{ A[a]; B[] }";
3083 P
= "{ A[a] -> B[] }";
3084 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3087 if (test_padded_schedule(ctx
) < 0)
3090 /* Check that check for progress is not confused by rational
3093 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
3094 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
3096 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
3097 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
3099 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3100 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3102 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3104 if (test_conditional_schedule_constraints(ctx
) < 0)
3110 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
3112 isl_union_map
*umap
;
3115 umap
= isl_union_map_read_from_str(ctx
, str
);
3116 test
= isl_union_map_plain_is_injective(umap
);
3117 isl_union_map_free(umap
);
3120 if (test
== injective
)
3123 isl_die(ctx
, isl_error_unknown
,
3124 "map not detected as injective", return -1);
3126 isl_die(ctx
, isl_error_unknown
,
3127 "map detected as injective", return -1);
3130 int test_injective(isl_ctx
*ctx
)
3134 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
3136 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
3138 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
3140 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
3142 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
3144 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
3146 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
3148 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
3151 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
3152 if (test_plain_injective(ctx
, str
, 1))
3154 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
3155 if (test_plain_injective(ctx
, str
, 0))
3161 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
3169 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
3170 equal
= isl_aff_plain_is_equal(aff
, aff2
);
3176 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
3180 equal
= aff_plain_is_equal(aff
, str
);
3184 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
3185 "result not as expected", return -1);
3190 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3191 __isl_take isl_aff
*aff2
);
3193 ['+'] = { &isl_aff_add
},
3194 ['-'] = { &isl_aff_sub
},
3195 ['*'] = { &isl_aff_mul
},
3203 } aff_bin_tests
[] = {
3204 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
3205 "{ [i] -> [2i] }" },
3206 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
3208 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
3209 "{ [i] -> [2i] }" },
3210 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
3211 "{ [i] -> [2i] }" },
3212 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
3213 "{ [i] -> [NaN] }" },
3214 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
3215 "{ [i] -> [NaN] }" },
3216 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
3217 "{ [i] -> [NaN] }" },
3218 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
3219 "{ [i] -> [NaN] }" },
3220 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
3221 "{ [i] -> [NaN] }" },
3222 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
3223 "{ [i] -> [NaN] }" },
3224 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
3225 "{ [i] -> [NaN] }" },
3226 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
3227 "{ [i] -> [NaN] }" },
3230 /* Perform some basic tests of binary operations on isl_aff objects.
3232 static int test_bin_aff(isl_ctx
*ctx
)
3235 isl_aff
*aff1
, *aff2
, *res
;
3236 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3237 __isl_take isl_aff
*aff2
);
3240 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
3241 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
3242 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
3243 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
3244 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
3245 aff1
= fn(aff1
, aff2
);
3246 if (isl_aff_is_nan(res
))
3247 ok
= isl_aff_is_nan(aff1
);
3249 ok
= isl_aff_plain_is_equal(aff1
, res
);
3255 isl_die(ctx
, isl_error_unknown
,
3256 "unexpected result", return -1);
3262 int test_aff(isl_ctx
*ctx
)
3267 isl_local_space
*ls
;
3271 if (test_bin_aff(ctx
) < 0)
3274 space
= isl_space_set_alloc(ctx
, 0, 1);
3275 ls
= isl_local_space_from_space(space
);
3276 aff
= isl_aff_zero_on_domain(ls
);
3278 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3279 aff
= isl_aff_scale_down_ui(aff
, 3);
3280 aff
= isl_aff_floor(aff
);
3281 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3282 aff
= isl_aff_scale_down_ui(aff
, 2);
3283 aff
= isl_aff_floor(aff
);
3284 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3287 set
= isl_set_read_from_str(ctx
, str
);
3288 aff
= isl_aff_gist(aff
, set
);
3290 aff
= isl_aff_add_constant_si(aff
, -16);
3291 zero
= isl_aff_plain_is_zero(aff
);
3297 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3299 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
3300 aff
= isl_aff_scale_down_ui(aff
, 64);
3301 aff
= isl_aff_floor(aff
);
3302 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
3310 int test_dim_max(isl_ctx
*ctx
)
3314 isl_set
*set1
, *set2
;
3319 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
3320 set
= isl_set_read_from_str(ctx
, str
);
3321 pwaff
= isl_set_dim_max(set
, 0);
3322 set1
= isl_set_from_pw_aff(pwaff
);
3323 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
3324 set2
= isl_set_read_from_str(ctx
, str
);
3325 equal
= isl_set_is_equal(set1
, set2
);
3331 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3333 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
3334 set
= isl_set_read_from_str(ctx
, str
);
3335 pwaff
= isl_set_dim_max(set
, 0);
3336 set1
= isl_set_from_pw_aff(pwaff
);
3337 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3338 set2
= isl_set_read_from_str(ctx
, str
);
3339 equal
= isl_set_is_equal(set1
, set2
);
3345 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3347 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
3348 set
= isl_set_read_from_str(ctx
, str
);
3349 pwaff
= isl_set_dim_max(set
, 0);
3350 set1
= isl_set_from_pw_aff(pwaff
);
3351 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3352 set2
= isl_set_read_from_str(ctx
, str
);
3353 equal
= isl_set_is_equal(set1
, set2
);
3359 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3361 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
3362 "0 <= i < N and 0 <= j < M }";
3363 map
= isl_map_read_from_str(ctx
, str
);
3364 set
= isl_map_range(map
);
3366 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
3367 set1
= isl_set_from_pw_aff(pwaff
);
3368 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
3369 set2
= isl_set_read_from_str(ctx
, str
);
3370 equal
= isl_set_is_equal(set1
, set2
);
3374 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
3375 set1
= isl_set_from_pw_aff(pwaff
);
3376 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
3377 set2
= isl_set_read_from_str(ctx
, str
);
3378 if (equal
>= 0 && equal
)
3379 equal
= isl_set_is_equal(set1
, set2
);
3388 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3390 /* Check that solutions are properly merged. */
3391 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
3392 "c <= -1 + n - 4a - 2b and c >= -2b and "
3393 "4a >= -4 + n and c >= 0 }";
3394 set
= isl_set_read_from_str(ctx
, str
);
3395 pwaff
= isl_set_dim_min(set
, 2);
3396 set1
= isl_set_from_pw_aff(pwaff
);
3397 str
= "[n] -> { [(0)] : n >= 1 }";
3398 set2
= isl_set_read_from_str(ctx
, str
);
3399 equal
= isl_set_is_equal(set1
, set2
);
3406 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3408 /* Check that empty solution lie in the right space. */
3409 str
= "[n] -> { [t,a] : 1 = 0 }";
3410 set
= isl_set_read_from_str(ctx
, str
);
3411 pwaff
= isl_set_dim_max(set
, 0);
3412 set1
= isl_set_from_pw_aff(pwaff
);
3413 str
= "[n] -> { [t] : 1 = 0 }";
3414 set2
= isl_set_read_from_str(ctx
, str
);
3415 equal
= isl_set_is_equal(set1
, set2
);
3422 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3427 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
3429 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
3433 isl_pw_multi_aff
*pma2
;
3439 ctx
= isl_pw_multi_aff_get_ctx(pma
);
3440 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3441 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
3442 isl_pw_multi_aff_free(pma2
);
3447 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
3448 * represented by "str".
3450 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
3455 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
3459 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
3460 "result not as expected", return -1);
3464 /* Basic test for isl_pw_multi_aff_product.
3466 * Check that multiple pieces are properly handled.
3468 static int test_product_pma(isl_ctx
*ctx
)
3472 isl_pw_multi_aff
*pma1
, *pma2
;
3474 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
3475 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3476 str
= "{ C[] -> D[] }";
3477 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3478 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
3479 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
3480 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
3481 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
3482 isl_pw_multi_aff_free(pma1
);
3489 int test_product(isl_ctx
*ctx
)
3493 isl_union_set
*uset1
, *uset2
;
3497 set
= isl_set_read_from_str(ctx
, str
);
3498 set
= isl_set_product(set
, isl_set_copy(set
));
3499 ok
= isl_set_is_wrapping(set
);
3504 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3507 uset1
= isl_union_set_read_from_str(ctx
, str
);
3508 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
3509 str
= "{ [[] -> []] }";
3510 uset2
= isl_union_set_read_from_str(ctx
, str
);
3511 ok
= isl_union_set_is_equal(uset1
, uset2
);
3512 isl_union_set_free(uset1
);
3513 isl_union_set_free(uset2
);
3517 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3519 if (test_product_pma(ctx
) < 0)
3525 /* Check that two sets are not considered disjoint just because
3526 * they have a different set of (named) parameters.
3528 static int test_disjoint(isl_ctx
*ctx
)
3531 isl_set
*set
, *set2
;
3534 str
= "[n] -> { [[]->[]] }";
3535 set
= isl_set_read_from_str(ctx
, str
);
3536 str
= "{ [[]->[]] }";
3537 set2
= isl_set_read_from_str(ctx
, str
);
3538 disjoint
= isl_set_is_disjoint(set
, set2
);
3544 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3549 int test_equal(isl_ctx
*ctx
)
3552 isl_set
*set
, *set2
;
3556 set
= isl_set_read_from_str(ctx
, str
);
3558 set2
= isl_set_read_from_str(ctx
, str
);
3559 equal
= isl_set_is_equal(set
, set2
);
3565 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3570 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
3571 enum isl_dim_type type
, unsigned pos
, int fixed
)
3575 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
3582 isl_die(ctx
, isl_error_unknown
,
3583 "map not detected as fixed", return -1);
3585 isl_die(ctx
, isl_error_unknown
,
3586 "map detected as fixed", return -1);
3589 int test_fixed(isl_ctx
*ctx
)
3594 str
= "{ [i] -> [i] }";
3595 map
= isl_map_read_from_str(ctx
, str
);
3596 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
3598 str
= "{ [i] -> [1] }";
3599 map
= isl_map_read_from_str(ctx
, str
);
3600 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3602 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
3603 map
= isl_map_read_from_str(ctx
, str
);
3604 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3606 map
= isl_map_read_from_str(ctx
, str
);
3607 map
= isl_map_neg(map
);
3608 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3614 int test_vertices(isl_ctx
*ctx
)
3617 isl_basic_set
*bset
;
3618 isl_vertices
*vertices
;
3620 str
= "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }";
3621 bset
= isl_basic_set_read_from_str(ctx
, str
);
3622 vertices
= isl_basic_set_compute_vertices(bset
);
3623 isl_basic_set_free(bset
);
3624 isl_vertices_free(vertices
);
3628 str
= "{ A[t, i] : t = 14 and i = 1 }";
3629 bset
= isl_basic_set_read_from_str(ctx
, str
);
3630 vertices
= isl_basic_set_compute_vertices(bset
);
3631 isl_basic_set_free(bset
);
3632 isl_vertices_free(vertices
);
3639 int test_union_pw(isl_ctx
*ctx
)
3643 isl_union_set
*uset
;
3644 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
3646 str
= "{ [x] -> x^2 }";
3647 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
3648 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
3649 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
3650 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
3651 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
3652 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
3653 isl_union_pw_qpolynomial_free(upwqp1
);
3654 isl_union_pw_qpolynomial_free(upwqp2
);
3658 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3663 int test_output(isl_ctx
*ctx
)
3671 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
3672 pa
= isl_pw_aff_read_from_str(ctx
, str
);
3674 p
= isl_printer_to_str(ctx
);
3675 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
3676 p
= isl_printer_print_pw_aff(p
, pa
);
3677 s
= isl_printer_get_str(p
);
3678 isl_printer_free(p
);
3679 isl_pw_aff_free(pa
);
3683 equal
= !strcmp(s
, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
3688 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3693 int test_sample(isl_ctx
*ctx
)
3696 isl_basic_set
*bset1
, *bset2
;
3699 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
3700 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
3701 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
3702 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
3703 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
3704 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
3705 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
3706 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
3707 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
3708 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
3709 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
3710 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
3711 "d - 1073741821e and "
3712 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
3713 "3j >= 1 - a + b + 2e and "
3714 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
3715 "3i <= 4 - a + 4b - e and "
3716 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
3717 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
3718 "c <= -1 + a and 3i >= -2 - a + 3e and "
3719 "1073741822e <= 1073741823 - a + 1073741822b + c and "
3720 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
3721 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
3722 "1073741823e >= 1 + 1073741823b - d and "
3723 "3i >= 1073741823b + c - 1073741823e - f and "
3724 "3i >= 1 + 2b + e + 3g }";
3725 bset1
= isl_basic_set_read_from_str(ctx
, str
);
3726 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
3727 empty
= isl_basic_set_is_empty(bset2
);
3728 subset
= isl_basic_set_is_subset(bset2
, bset1
);
3729 isl_basic_set_free(bset1
);
3730 isl_basic_set_free(bset2
);
3731 if (empty
< 0 || subset
< 0)
3734 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
3736 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
3741 int test_fixed_power(isl_ctx
*ctx
)
3749 str
= "{ [i] -> [i + 1] }";
3750 map
= isl_map_read_from_str(ctx
, str
);
3751 isl_int_set_si(exp
, 23);
3752 map
= isl_map_fixed_power(map
, exp
);
3753 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
3762 int test_slice(isl_ctx
*ctx
)
3768 str
= "{ [i] -> [j] }";
3769 map
= isl_map_read_from_str(ctx
, str
);
3770 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3771 equal
= map_check_equal(map
, "{ [i] -> [i] }");
3776 str
= "{ [i] -> [j] }";
3777 map
= isl_map_read_from_str(ctx
, str
);
3778 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3779 equal
= map_check_equal(map
, "{ [i] -> [j] }");
3784 str
= "{ [i] -> [j] }";
3785 map
= isl_map_read_from_str(ctx
, str
);
3786 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3787 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
3792 str
= "{ [i] -> [j] }";
3793 map
= isl_map_read_from_str(ctx
, str
);
3794 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3795 equal
= map_check_equal(map
, "{ [0] -> [j] }");
3800 str
= "{ [i] -> [j] }";
3801 map
= isl_map_read_from_str(ctx
, str
);
3802 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3803 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
3808 str
= "{ [i] -> [j] }";
3809 map
= isl_map_read_from_str(ctx
, str
);
3810 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3811 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
3819 int test_eliminate(isl_ctx
*ctx
)
3825 str
= "{ [i] -> [j] : i = 2j }";
3826 map
= isl_map_read_from_str(ctx
, str
);
3827 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
3828 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
3836 /* Check that isl_set_dim_residue_class detects that the values of j
3837 * in the set below are all odd and that it does not detect any spurious
3840 static int test_residue_class(isl_ctx
*ctx
)
3847 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
3848 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
3849 set
= isl_set_read_from_str(ctx
, str
);
3852 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
3854 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
3855 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
3864 int test_align_parameters(isl_ctx
*ctx
)
3868 isl_multi_aff
*ma1
, *ma2
;
3871 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
3872 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
3874 space
= isl_space_params_alloc(ctx
, 1);
3875 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
3876 ma1
= isl_multi_aff_align_params(ma1
, space
);
3878 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
3879 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
3881 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
3883 isl_multi_aff_free(ma1
);
3884 isl_multi_aff_free(ma2
);
3889 isl_die(ctx
, isl_error_unknown
,
3890 "result not as expected", return -1);
3895 static int test_list(isl_ctx
*ctx
)
3897 isl_id
*a
, *b
, *c
, *d
, *id
;
3901 a
= isl_id_alloc(ctx
, "a", NULL
);
3902 b
= isl_id_alloc(ctx
, "b", NULL
);
3903 c
= isl_id_alloc(ctx
, "c", NULL
);
3904 d
= isl_id_alloc(ctx
, "d", NULL
);
3906 list
= isl_id_list_alloc(ctx
, 4);
3907 list
= isl_id_list_add(list
, a
);
3908 list
= isl_id_list_add(list
, b
);
3909 list
= isl_id_list_add(list
, c
);
3910 list
= isl_id_list_add(list
, d
);
3911 list
= isl_id_list_drop(list
, 1, 1);
3913 if (isl_id_list_n_id(list
) != 3) {
3914 isl_id_list_free(list
);
3915 isl_die(ctx
, isl_error_unknown
,
3916 "unexpected number of elements in list", return -1);
3919 id
= isl_id_list_get_id(list
, 0);
3922 id
= isl_id_list_get_id(list
, 1);
3925 id
= isl_id_list_get_id(list
, 2);
3929 isl_id_list_free(list
);
3932 isl_die(ctx
, isl_error_unknown
,
3933 "unexpected elements in list", return -1);
3938 const char *set_conversion_tests
[] = {
3939 "[N] -> { [i] : N - 1 <= 2 i <= N }",
3940 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
3941 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
3942 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
3945 /* Check that converting from isl_set to isl_pw_multi_aff and back
3946 * to isl_set produces the original isl_set.
3948 static int test_set_conversion(isl_ctx
*ctx
)
3952 isl_set
*set1
, *set2
;
3953 isl_pw_multi_aff
*pma
;
3956 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
3957 str
= set_conversion_tests
[i
];
3958 set1
= isl_set_read_from_str(ctx
, str
);
3959 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
3960 set2
= isl_set_from_pw_multi_aff(pma
);
3961 equal
= isl_set_is_equal(set1
, set2
);
3968 isl_die(ctx
, isl_error_unknown
, "bad conversion",
3975 /* Check that converting from isl_map to isl_pw_multi_aff and back
3976 * to isl_map produces the original isl_map.
3978 static int test_map_conversion(isl_ctx
*ctx
)
3981 isl_map
*map1
, *map2
;
3982 isl_pw_multi_aff
*pma
;
3985 str
= "{ [a, b, c, d] -> s0[a, b, e, f] : "
3986 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
3987 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
3988 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
3990 map1
= isl_map_read_from_str(ctx
, str
);
3991 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
3992 map2
= isl_map_from_pw_multi_aff(pma
);
3993 equal
= isl_map_is_equal(map1
, map2
);
4000 isl_die(ctx
, isl_error_unknown
, "bad conversion", return -1);
4005 static int test_conversion(isl_ctx
*ctx
)
4007 if (test_set_conversion(ctx
) < 0)
4009 if (test_map_conversion(ctx
) < 0)
4014 /* Check that isl_basic_map_curry does not modify input.
4016 static int test_curry(isl_ctx
*ctx
)
4019 isl_basic_map
*bmap1
, *bmap2
;
4022 str
= "{ [A[] -> B[]] -> C[] }";
4023 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
4024 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
4025 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
4026 isl_basic_map_free(bmap1
);
4027 isl_basic_map_free(bmap2
);
4032 isl_die(ctx
, isl_error_unknown
,
4033 "curried map should not be equal to original",
4043 } preimage_tests
[] = {
4044 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
4045 "{ A[j,i] -> B[i,j] }",
4046 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
4047 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4048 "{ A[a,b] -> B[a/2,b/6] }",
4049 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
4050 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4051 "{ A[a,b] -> B[a/2,b/6] }",
4052 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
4053 "exists i,j : a = 2 i and b = 6 j }" },
4054 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
4055 "[n] -> { : 0 <= n <= 100 }" },
4056 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4057 "{ A[a] -> B[2a] }",
4058 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
4059 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4060 "{ A[a] -> B[([a/2])] }",
4061 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
4062 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
4063 "{ A[a] -> B[a,a,a/3] }",
4064 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
4065 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
4066 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
4069 static int test_preimage_basic_set(isl_ctx
*ctx
)
4072 isl_basic_set
*bset1
, *bset2
;
4076 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
4077 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
4078 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
4079 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
4080 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
4081 equal
= isl_basic_set_is_equal(bset1
, bset2
);
4082 isl_basic_set_free(bset1
);
4083 isl_basic_set_free(bset2
);
4087 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4098 } preimage_domain_tests
[] = {
4099 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
4100 "{ A[j,i] -> B[i,j] }",
4101 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
4102 { "{ B[i] -> C[i]; D[i] -> E[i] }",
4103 "{ A[i] -> B[i + 1] }",
4104 "{ A[i] -> C[i + 1] }" },
4105 { "{ B[i] -> C[i]; B[i] -> E[i] }",
4106 "{ A[i] -> B[i + 1] }",
4107 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
4108 { "{ B[i] -> C[([i/2])] }",
4109 "{ A[i] -> B[2i] }",
4110 "{ A[i] -> C[i] }" },
4111 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
4112 "{ A[i] -> B[([i/5]), ([i/7])] }",
4113 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
4114 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
4115 "[N] -> { A[] -> B[([N/5])] }",
4116 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
4117 { "{ B[i] -> C[i] : exists a : i = 5 a }",
4118 "{ A[i] -> B[2i] }",
4119 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
4120 { "{ B[i] -> C[i] : exists a : i = 2 a; "
4121 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
4122 "{ A[i] -> B[2i] }",
4123 "{ A[i] -> C[2i] }" },
4126 static int test_preimage_union_map(isl_ctx
*ctx
)
4129 isl_union_map
*umap1
, *umap2
;
4133 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
4134 umap1
= isl_union_map_read_from_str(ctx
,
4135 preimage_domain_tests
[i
].map
);
4136 ma
= isl_multi_aff_read_from_str(ctx
,
4137 preimage_domain_tests
[i
].ma
);
4138 umap2
= isl_union_map_read_from_str(ctx
,
4139 preimage_domain_tests
[i
].res
);
4140 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
4141 equal
= isl_union_map_is_equal(umap1
, umap2
);
4142 isl_union_map_free(umap1
);
4143 isl_union_map_free(umap2
);
4147 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4154 static int test_preimage(isl_ctx
*ctx
)
4156 if (test_preimage_basic_set(ctx
) < 0)
4158 if (test_preimage_union_map(ctx
) < 0)
4168 } pullback_tests
[] = {
4169 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
4170 "{ A[a,b] -> C[b + 2a] }" },
4171 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
4172 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
4173 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
4174 "{ A[a] -> C[(a)/6] }" },
4175 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
4176 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
4177 "{ A[a] -> C[(2a)/3] }" },
4178 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
4179 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
4180 "{ A[i,j] -> C[i + j, i + j] }"},
4181 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
4182 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
4183 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
4186 static int test_pullback(isl_ctx
*ctx
)
4189 isl_multi_aff
*ma1
, *ma2
;
4193 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
4194 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
4195 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
4196 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
4197 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
4198 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4199 isl_multi_aff_free(ma1
);
4200 isl_multi_aff_free(ma2
);
4204 isl_die(ctx
, isl_error_unknown
, "bad pullback",
4211 /* Check that negation is printed correctly.
4213 static int test_ast(isl_ctx
*ctx
)
4215 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
4219 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4220 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4221 expr
= isl_ast_expr_add(expr1
, expr2
);
4222 expr
= isl_ast_expr_neg(expr
);
4223 str
= isl_ast_expr_to_str(expr
);
4224 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
4226 isl_ast_expr_free(expr
);
4231 isl_die(ctx
, isl_error_unknown
,
4232 "isl_ast_expr printed incorrectly", return -1);
4234 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4235 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4236 expr
= isl_ast_expr_add(expr1
, expr2
);
4237 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
4238 expr
= isl_ast_expr_sub(expr3
, expr
);
4239 str
= isl_ast_expr_to_str(expr
);
4240 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
4242 isl_ast_expr_free(expr
);
4247 isl_die(ctx
, isl_error_unknown
,
4248 "isl_ast_expr printed incorrectly", return -1);
4253 /* Internal data structure for before_for and after_for callbacks.
4255 * depth is the current depth
4256 * before is the number of times before_for has been called
4257 * after is the number of times after_for has been called
4259 struct isl_test_codegen_data
{
4265 /* This function is called before each for loop in the AST generated
4266 * from test_ast_gen1.
4268 * Increment the number of calls and the depth.
4269 * Check that the space returned by isl_ast_build_get_schedule_space
4270 * matches the target space of the schedule returned by
4271 * isl_ast_build_get_schedule.
4272 * Return an isl_id that is checked by the corresponding call
4275 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
4278 struct isl_test_codegen_data
*data
= user
;
4281 isl_union_map
*schedule
;
4282 isl_union_set
*uset
;
4287 ctx
= isl_ast_build_get_ctx(build
);
4289 if (data
->before
>= 3)
4290 isl_die(ctx
, isl_error_unknown
,
4291 "unexpected number of for nodes", return NULL
);
4292 if (data
->depth
>= 2)
4293 isl_die(ctx
, isl_error_unknown
,
4294 "unexpected depth", return NULL
);
4296 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
4300 schedule
= isl_ast_build_get_schedule(build
);
4301 uset
= isl_union_map_range(schedule
);
4304 if (isl_union_set_n_set(uset
) != 1) {
4305 isl_union_set_free(uset
);
4306 isl_die(ctx
, isl_error_unknown
,
4307 "expecting single range space", return NULL
);
4310 space
= isl_ast_build_get_schedule_space(build
);
4311 set
= isl_union_set_extract_set(uset
, space
);
4312 isl_union_set_free(uset
);
4313 empty
= isl_set_is_empty(set
);
4319 isl_die(ctx
, isl_error_unknown
,
4320 "spaces don't match", return NULL
);
4322 return isl_id_alloc(ctx
, name
, NULL
);
4325 /* This function is called after each for loop in the AST generated
4326 * from test_ast_gen1.
4328 * Increment the number of calls and decrement the depth.
4329 * Check that the annotation attached to the node matches
4330 * the isl_id returned by the corresponding call to before_for.
4332 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
4333 __isl_keep isl_ast_build
*build
, void *user
)
4335 struct isl_test_codegen_data
*data
= user
;
4343 if (data
->after
> data
->before
)
4344 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4345 "mismatch in number of for nodes",
4346 return isl_ast_node_free(node
));
4348 id
= isl_ast_node_get_annotation(node
);
4350 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4351 "missing annotation", return isl_ast_node_free(node
));
4353 name
= isl_id_get_name(id
);
4354 valid
= name
&& atoi(name
+ 1) == data
->depth
;
4358 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4359 "wrong annotation", return isl_ast_node_free(node
));
4364 /* Check that the before_each_for and after_each_for callbacks
4365 * are called for each for loop in the generated code,
4366 * that they are called in the right order and that the isl_id
4367 * returned from the before_each_for callback is attached to
4368 * the isl_ast_node passed to the corresponding after_each_for call.
4370 static int test_ast_gen1(isl_ctx
*ctx
)
4374 isl_union_map
*schedule
;
4375 isl_ast_build
*build
;
4377 struct isl_test_codegen_data data
;
4379 str
= "[N] -> { : N >= 10 }";
4380 set
= isl_set_read_from_str(ctx
, str
);
4381 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
4382 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
4383 schedule
= isl_union_map_read_from_str(ctx
, str
);
4388 build
= isl_ast_build_from_context(set
);
4389 build
= isl_ast_build_set_before_each_for(build
,
4390 &before_for
, &data
);
4391 build
= isl_ast_build_set_after_each_for(build
,
4393 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4394 isl_ast_build_free(build
);
4398 isl_ast_node_free(tree
);
4400 if (data
.before
!= 3 || data
.after
!= 3)
4401 isl_die(ctx
, isl_error_unknown
,
4402 "unexpected number of for nodes", return -1);
4407 /* Check that the AST generator handles domains that are integrally disjoint
4408 * but not ratinoally disjoint.
4410 static int test_ast_gen2(isl_ctx
*ctx
)
4414 isl_union_map
*schedule
;
4415 isl_union_map
*options
;
4416 isl_ast_build
*build
;
4419 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
4420 schedule
= isl_union_map_read_from_str(ctx
, str
);
4421 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4422 build
= isl_ast_build_from_context(set
);
4424 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
4425 options
= isl_union_map_read_from_str(ctx
, str
);
4426 build
= isl_ast_build_set_options(build
, options
);
4427 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4428 isl_ast_build_free(build
);
4431 isl_ast_node_free(tree
);
4436 /* Increment *user on each call.
4438 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
4439 __isl_keep isl_ast_build
*build
, void *user
)
4448 /* Test that unrolling tries to minimize the number of instances.
4449 * In particular, for the schedule given below, make sure it generates
4450 * 3 nodes (rather than 101).
4452 static int test_ast_gen3(isl_ctx
*ctx
)
4456 isl_union_map
*schedule
;
4457 isl_union_map
*options
;
4458 isl_ast_build
*build
;
4462 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
4463 schedule
= isl_union_map_read_from_str(ctx
, str
);
4464 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4466 str
= "{ [i] -> unroll[0] }";
4467 options
= isl_union_map_read_from_str(ctx
, str
);
4469 build
= isl_ast_build_from_context(set
);
4470 build
= isl_ast_build_set_options(build
, options
);
4471 build
= isl_ast_build_set_at_each_domain(build
,
4472 &count_domains
, &n_domain
);
4473 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4474 isl_ast_build_free(build
);
4478 isl_ast_node_free(tree
);
4481 isl_die(ctx
, isl_error_unknown
,
4482 "unexpected number of for nodes", return -1);
4487 /* Check that if the ast_build_exploit_nested_bounds options is set,
4488 * we do not get an outer if node in the generated AST,
4489 * while we do get such an outer if node if the options is not set.
4491 static int test_ast_gen4(isl_ctx
*ctx
)
4495 isl_union_map
*schedule
;
4496 isl_ast_build
*build
;
4498 enum isl_ast_node_type type
;
4501 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
4502 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
4504 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
4506 schedule
= isl_union_map_read_from_str(ctx
, str
);
4507 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4508 build
= isl_ast_build_from_context(set
);
4509 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4510 isl_ast_build_free(build
);
4514 type
= isl_ast_node_get_type(tree
);
4515 isl_ast_node_free(tree
);
4517 if (type
== isl_ast_node_if
)
4518 isl_die(ctx
, isl_error_unknown
,
4519 "not expecting if node", return -1);
4521 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
4523 schedule
= isl_union_map_read_from_str(ctx
, str
);
4524 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4525 build
= isl_ast_build_from_context(set
);
4526 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4527 isl_ast_build_free(build
);
4531 type
= isl_ast_node_get_type(tree
);
4532 isl_ast_node_free(tree
);
4534 if (type
!= isl_ast_node_if
)
4535 isl_die(ctx
, isl_error_unknown
,
4536 "expecting if node", return -1);
4538 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
4543 /* This function is called for each leaf in the AST generated
4544 * from test_ast_gen5.
4546 * We finalize the AST generation by extending the outer schedule
4547 * with a zero-dimensional schedule. If this results in any for loops,
4548 * then this means that we did not pass along enough information
4549 * about the outer schedule to the inner AST generation.
4551 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
4554 isl_union_map
*schedule
, *extra
;
4557 schedule
= isl_ast_build_get_schedule(build
);
4558 extra
= isl_union_map_copy(schedule
);
4559 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
4560 schedule
= isl_union_map_range_product(schedule
, extra
);
4561 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4562 isl_ast_build_free(build
);
4567 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
4568 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
4569 "code should not contain any for loop",
4570 return isl_ast_node_free(tree
));
4575 /* Check that we do not lose any information when going back and
4576 * forth between internal and external schedule.
4578 * In particular, we create an AST where we unroll the only
4579 * non-constant dimension in the schedule. We therefore do
4580 * not expect any for loops in the AST. However, older versions
4581 * of isl would not pass along enough information about the outer
4582 * schedule when performing an inner code generation from a create_leaf
4583 * callback, resulting in the inner code generation producing a for loop.
4585 static int test_ast_gen5(isl_ctx
*ctx
)
4589 isl_union_map
*schedule
, *options
;
4590 isl_ast_build
*build
;
4593 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
4594 schedule
= isl_union_map_read_from_str(ctx
, str
);
4596 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
4597 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
4598 options
= isl_union_map_read_from_str(ctx
, str
);
4600 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4601 build
= isl_ast_build_from_context(set
);
4602 build
= isl_ast_build_set_options(build
, options
);
4603 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
4604 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4605 isl_ast_build_free(build
);
4606 isl_ast_node_free(tree
);
4613 static int test_ast_gen(isl_ctx
*ctx
)
4615 if (test_ast_gen1(ctx
) < 0)
4617 if (test_ast_gen2(ctx
) < 0)
4619 if (test_ast_gen3(ctx
) < 0)
4621 if (test_ast_gen4(ctx
) < 0)
4623 if (test_ast_gen5(ctx
) < 0)
4628 /* Check if dropping output dimensions from an isl_pw_multi_aff
4631 static int test_pw_multi_aff(isl_ctx
*ctx
)
4634 isl_pw_multi_aff
*pma1
, *pma2
;
4637 str
= "{ [i,j] -> [i+j, 4i-j] }";
4638 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4639 str
= "{ [i,j] -> [4i-j] }";
4640 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4642 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
4644 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
4646 isl_pw_multi_aff_free(pma1
);
4647 isl_pw_multi_aff_free(pma2
);
4651 isl_die(ctx
, isl_error_unknown
,
4652 "expressions not equal", return -1);
4657 /* Check that we can properly parse multi piecewise affine expressions
4658 * where the piecewise affine expressions have different domains.
4660 static int test_multi_pw_aff(isl_ctx
*ctx
)
4663 isl_set
*dom
, *dom2
;
4664 isl_multi_pw_aff
*mpa1
, *mpa2
;
4669 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
4670 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
4671 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
4672 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
4673 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
4674 str
= "{ [i] -> [(i : i > 0), 2i] }";
4675 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
4677 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
4679 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
4680 dom
= isl_pw_aff_domain(pa
);
4681 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
4682 dom2
= isl_pw_aff_domain(pa
);
4683 equal_domain
= isl_set_is_equal(dom
, dom2
);
4687 isl_multi_pw_aff_free(mpa1
);
4688 isl_multi_pw_aff_free(mpa2
);
4693 isl_die(ctx
, isl_error_unknown
,
4694 "expressions not equal", return -1);
4696 if (equal_domain
< 0)
4699 isl_die(ctx
, isl_error_unknown
,
4700 "domains unexpectedly equal", return -1);
4705 /* This is a regression test for a bug where isl_basic_map_simplify
4706 * would end up in an infinite loop. In particular, we construct
4707 * an empty basic set that is not obviously empty.
4708 * isl_basic_set_is_empty marks the basic set as empty.
4709 * After projecting out i3, the variable can be dropped completely,
4710 * but isl_basic_map_simplify refrains from doing so if the basic set
4711 * is empty and would end up in an infinite loop if it didn't test
4712 * explicitly for empty basic maps in the outer loop.
4714 static int test_simplify(isl_ctx
*ctx
)
4717 isl_basic_set
*bset
;
4720 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
4721 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
4722 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
4724 bset
= isl_basic_set_read_from_str(ctx
, str
);
4725 empty
= isl_basic_set_is_empty(bset
);
4726 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
4727 isl_basic_set_free(bset
);
4731 isl_die(ctx
, isl_error_unknown
,
4732 "basic set should be empty", return -1);
4737 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
4738 * with gbr context would fail to disable the use of the shifted tableau
4739 * when transferring equalities for the input to the context, resulting
4740 * in invalid sample values.
4742 static int test_partial_lexmin(isl_ctx
*ctx
)
4745 isl_basic_set
*bset
;
4746 isl_basic_map
*bmap
;
4749 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
4750 bmap
= isl_basic_map_read_from_str(ctx
, str
);
4751 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
4752 bset
= isl_basic_set_read_from_str(ctx
, str
);
4753 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
4762 /* Check that the variable compression performed on the existentially
4763 * quantified variables inside isl_basic_set_compute_divs is not confused
4764 * by the implicit equalities among the parameters.
4766 static int test_compute_divs(isl_ctx
*ctx
)
4769 isl_basic_set
*bset
;
4772 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
4773 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
4774 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
4775 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
4776 bset
= isl_basic_set_read_from_str(ctx
, str
);
4777 set
= isl_basic_set_compute_divs(bset
);
4787 int (*fn
)(isl_ctx
*ctx
);
4789 { "val", &test_val
},
4790 { "compute divs", &test_compute_divs
},
4791 { "partial lexmin", &test_partial_lexmin
},
4792 { "simplify", &test_simplify
},
4793 { "curry", &test_curry
},
4794 { "piecewise multi affine expressions", &test_pw_multi_aff
},
4795 { "multi piecewise affine expressions", &test_multi_pw_aff
},
4796 { "conversion", &test_conversion
},
4797 { "list", &test_list
},
4798 { "align parameters", &test_align_parameters
},
4799 { "preimage", &test_preimage
},
4800 { "pullback", &test_pullback
},
4801 { "AST", &test_ast
},
4802 { "AST generation", &test_ast_gen
},
4803 { "eliminate", &test_eliminate
},
4804 { "residue class", &test_residue_class
},
4805 { "div", &test_div
},
4806 { "slice", &test_slice
},
4807 { "fixed power", &test_fixed_power
},
4808 { "sample", &test_sample
},
4809 { "output", &test_output
},
4810 { "vertices", &test_vertices
},
4811 { "fixed", &test_fixed
},
4812 { "equal", &test_equal
},
4813 { "disjoint", &test_disjoint
},
4814 { "product", &test_product
},
4815 { "dim_max", &test_dim_max
},
4816 { "affine", &test_aff
},
4817 { "injective", &test_injective
},
4818 { "schedule", &test_schedule
},
4819 { "union_pw", &test_union_pw
},
4820 { "parse", &test_parse
},
4821 { "single-valued", &test_sv
},
4822 { "affine hull", &test_affine_hull
},
4823 { "coalesce", &test_coalesce
},
4824 { "factorize", &test_factorize
},
4825 { "subset", &test_subset
},
4826 { "subtract", &test_subtract
},
4827 { "lexmin", &test_lexmin
},
4828 { "min", &test_min
},
4829 { "gist", &test_gist
},
4830 { "piecewise quasi-polynomials", &test_pwqp
},
4836 struct isl_ctx
*ctx
;
4838 srcdir
= getenv("srcdir");
4841 ctx
= isl_ctx_alloc();
4842 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
4843 printf("%s\n", tests
[i
].name
);
4844 if (tests
[i
].fn(ctx
) < 0)
4850 test_split_periods(ctx
);
4852 test_bijective(ctx
);
4856 test_construction(ctx
);
4858 test_application(ctx
);
4859 test_convex_hull(ctx
);