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 /* Check that the dependence analysis proceeds without errors.
2027 * Earlier versions of isl would break down during the analysis
2028 * due to the use of the wrong spaces.
2030 static int test_flow(isl_ctx
*ctx
)
2033 isl_union_map
*access
, *schedule
;
2034 isl_union_map
*must_dep
, *may_dep
;
2037 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
2038 access
= isl_union_map_read_from_str(ctx
, str
);
2039 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
2040 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
2041 "S2[] -> [1,0,0,0]; "
2042 "S3[] -> [-1,0,0,0] }";
2043 schedule
= isl_union_map_read_from_str(ctx
, str
);
2044 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
2045 isl_union_map_copy(access
), schedule
,
2046 &must_dep
, &may_dep
, NULL
, NULL
);
2047 isl_union_map_free(may_dep
);
2048 isl_union_map_free(must_dep
);
2053 int test_sv(isl_ctx
*ctx
)
2057 isl_union_map
*umap
;
2060 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
2061 map
= isl_map_read_from_str(ctx
, str
);
2062 sv
= isl_map_is_single_valued(map
);
2067 isl_die(ctx
, isl_error_internal
,
2068 "map not detected as single valued", return -1);
2070 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
2071 map
= isl_map_read_from_str(ctx
, str
);
2072 sv
= isl_map_is_single_valued(map
);
2077 isl_die(ctx
, isl_error_internal
,
2078 "map detected as single valued", return -1);
2080 str
= "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
2081 umap
= isl_union_map_read_from_str(ctx
, str
);
2082 sv
= isl_union_map_is_single_valued(umap
);
2083 isl_union_map_free(umap
);
2087 isl_die(ctx
, isl_error_internal
,
2088 "map not detected as single valued", return -1);
2090 str
= "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
2091 umap
= isl_union_map_read_from_str(ctx
, str
);
2092 sv
= isl_union_map_is_single_valued(umap
);
2093 isl_union_map_free(umap
);
2097 isl_die(ctx
, isl_error_internal
,
2098 "map detected as single valued", return -1);
2103 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
2107 map
= isl_map_read_from_str(ctx
, str
);
2109 assert(isl_map_is_bijective(map
));
2111 assert(!isl_map_is_bijective(map
));
2115 void test_bijective(struct isl_ctx
*ctx
)
2117 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
2118 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
2119 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
2120 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
2121 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
2122 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
2123 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
2124 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
2125 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
2126 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
2127 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
2128 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
2129 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
2132 static int test_pwqp(struct isl_ctx
*ctx
)
2136 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
2139 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2140 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2142 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
2145 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2146 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2148 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2150 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2152 isl_pw_qpolynomial_free(pwqp1
);
2154 str
= "{ [i] -> i }";
2155 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2156 str
= "{ [k] : exists a : k = 2a }";
2157 set
= isl_set_read_from_str(ctx
, str
);
2158 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2159 str
= "{ [i] -> i }";
2160 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2162 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2164 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2166 isl_pw_qpolynomial_free(pwqp1
);
2168 str
= "{ [i] -> i + [ (i + [i/3])/2 ] }";
2169 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2171 set
= isl_set_read_from_str(ctx
, str
);
2172 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2173 str
= "{ [i] -> 16 }";
2174 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2176 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2178 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2180 isl_pw_qpolynomial_free(pwqp1
);
2182 str
= "{ [i] -> ([(i)/2]) }";
2183 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2184 str
= "{ [k] : exists a : k = 2a+1 }";
2185 set
= isl_set_read_from_str(ctx
, str
);
2186 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2187 str
= "{ [i] -> -1/2 + 1/2 * i }";
2188 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2190 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2192 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2194 isl_pw_qpolynomial_free(pwqp1
);
2196 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
2197 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2198 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
2199 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2201 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2203 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2205 isl_pw_qpolynomial_free(pwqp1
);
2207 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
2208 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2209 str
= "{ [x] -> x }";
2210 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2212 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2214 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2216 isl_pw_qpolynomial_free(pwqp1
);
2218 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
2219 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2220 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2221 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
2222 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2223 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2224 isl_pw_qpolynomial_free(pwqp1
);
2226 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
2227 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2228 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2229 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2230 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
2231 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
2232 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2233 isl_pw_qpolynomial_free(pwqp1
);
2234 isl_pw_qpolynomial_free(pwqp2
);
2238 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2240 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
2241 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2242 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2243 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2244 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
2246 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2247 isl_pw_qpolynomial_free(pwqp1
);
2248 isl_pw_qpolynomial_free(pwqp2
);
2252 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2257 void test_split_periods(isl_ctx
*ctx
)
2260 isl_pw_qpolynomial
*pwqp
;
2262 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
2263 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
2264 "U >= 0; [U,V] -> U^2 : U >= 100 }";
2265 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2267 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
2270 isl_pw_qpolynomial_free(pwqp
);
2273 void test_union(isl_ctx
*ctx
)
2276 isl_union_set
*uset1
, *uset2
;
2277 isl_union_map
*umap1
, *umap2
;
2279 str
= "{ [i] : 0 <= i <= 1 }";
2280 uset1
= isl_union_set_read_from_str(ctx
, str
);
2281 str
= "{ [1] -> [0] }";
2282 umap1
= isl_union_map_read_from_str(ctx
, str
);
2284 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
2285 assert(isl_union_map_is_equal(umap1
, umap2
));
2287 isl_union_map_free(umap1
);
2288 isl_union_map_free(umap2
);
2290 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
2291 umap1
= isl_union_map_read_from_str(ctx
, str
);
2292 str
= "{ A[i]; B[i] }";
2293 uset1
= isl_union_set_read_from_str(ctx
, str
);
2295 uset2
= isl_union_map_domain(umap1
);
2297 assert(isl_union_set_is_equal(uset1
, uset2
));
2299 isl_union_set_free(uset1
);
2300 isl_union_set_free(uset2
);
2303 void test_bound(isl_ctx
*ctx
)
2306 isl_pw_qpolynomial
*pwqp
;
2307 isl_pw_qpolynomial_fold
*pwf
;
2309 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
2310 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2311 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2312 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 4);
2313 isl_pw_qpolynomial_fold_free(pwf
);
2315 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
2316 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2317 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2318 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 1);
2319 isl_pw_qpolynomial_fold_free(pwf
);
2322 void test_lift(isl_ctx
*ctx
)
2325 isl_basic_map
*bmap
;
2326 isl_basic_set
*bset
;
2328 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
2329 bset
= isl_basic_set_read_from_str(ctx
, str
);
2330 bset
= isl_basic_set_lift(bset
);
2331 bmap
= isl_basic_map_from_range(bset
);
2332 bset
= isl_basic_map_domain(bmap
);
2333 isl_basic_set_free(bset
);
2340 } subset_tests
[] = {
2342 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
2343 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
2344 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
2346 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
2347 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
2348 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
2349 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
2350 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
2351 "256e0 <= 255i and 256e0 >= -255 + 255i and "
2352 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
2353 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
2354 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
2355 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
2356 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
2357 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
2358 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
2359 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
2360 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
2361 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
2362 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
2363 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
2364 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
2365 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
2366 "4e0 <= -57 + i0 + i1)) or "
2367 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
2368 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
2369 "4e0 >= -61 + i0 + i1)) or "
2370 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
2373 static int test_subset(isl_ctx
*ctx
)
2376 isl_set
*set1
, *set2
;
2379 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
2380 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
2381 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
2382 subset
= isl_set_is_subset(set1
, set2
);
2387 if (subset
!= subset_tests
[i
].subset
)
2388 isl_die(ctx
, isl_error_unknown
,
2389 "incorrect subset result", return -1);
2396 const char *minuend
;
2397 const char *subtrahend
;
2398 const char *difference
;
2399 } subtract_domain_tests
[] = {
2400 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
2401 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
2402 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
2405 static int test_subtract(isl_ctx
*ctx
)
2408 isl_union_map
*umap1
, *umap2
;
2409 isl_union_set
*uset
;
2412 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2413 umap1
= isl_union_map_read_from_str(ctx
,
2414 subtract_domain_tests
[i
].minuend
);
2415 uset
= isl_union_set_read_from_str(ctx
,
2416 subtract_domain_tests
[i
].subtrahend
);
2417 umap2
= isl_union_map_read_from_str(ctx
,
2418 subtract_domain_tests
[i
].difference
);
2419 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
2420 equal
= isl_union_map_is_equal(umap1
, umap2
);
2421 isl_union_map_free(umap1
);
2422 isl_union_map_free(umap2
);
2426 isl_die(ctx
, isl_error_unknown
,
2427 "incorrect subtract domain result", return -1);
2433 int test_factorize(isl_ctx
*ctx
)
2436 isl_basic_set
*bset
;
2439 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2440 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2441 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2442 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2443 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2444 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2445 "3i5 >= -2i0 - i2 + 3i4 }";
2446 bset
= isl_basic_set_read_from_str(ctx
, str
);
2447 f
= isl_basic_set_factorizer(bset
);
2448 isl_basic_set_free(bset
);
2449 isl_factorizer_free(f
);
2451 isl_die(ctx
, isl_error_unknown
,
2452 "failed to construct factorizer", return -1);
2454 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2455 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2456 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2457 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2458 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2459 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2460 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2461 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2462 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2463 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2464 bset
= isl_basic_set_read_from_str(ctx
, str
);
2465 f
= isl_basic_set_factorizer(bset
);
2466 isl_basic_set_free(bset
);
2467 isl_factorizer_free(f
);
2469 isl_die(ctx
, isl_error_unknown
,
2470 "failed to construct factorizer", return -1);
2475 static int check_injective(__isl_take isl_map
*map
, void *user
)
2477 int *injective
= user
;
2479 *injective
= isl_map_is_injective(map
);
2482 if (*injective
< 0 || !*injective
)
2488 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
2489 const char *r
, const char *s
, int tilable
, int parallel
)
2493 isl_union_map
*W
, *R
, *S
;
2494 isl_union_map
*empty
;
2495 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
2496 isl_union_map
*validity
, *proximity
, *coincidence
;
2497 isl_union_map
*schedule
;
2498 isl_union_map
*test
;
2499 isl_union_set
*delta
;
2500 isl_union_set
*domain
;
2504 isl_schedule_constraints
*sc
;
2505 isl_schedule
*sched
;
2506 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
2508 D
= isl_union_set_read_from_str(ctx
, d
);
2509 W
= isl_union_map_read_from_str(ctx
, w
);
2510 R
= isl_union_map_read_from_str(ctx
, r
);
2511 S
= isl_union_map_read_from_str(ctx
, s
);
2513 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
2514 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
2516 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
2517 isl_union_map_compute_flow(isl_union_map_copy(R
),
2518 isl_union_map_copy(W
), empty
,
2519 isl_union_map_copy(S
),
2520 &dep_raw
, NULL
, NULL
, NULL
);
2521 isl_union_map_compute_flow(isl_union_map_copy(W
),
2522 isl_union_map_copy(W
),
2523 isl_union_map_copy(R
),
2524 isl_union_map_copy(S
),
2525 &dep_waw
, &dep_war
, NULL
, NULL
);
2527 dep
= isl_union_map_union(dep_waw
, dep_war
);
2528 dep
= isl_union_map_union(dep
, dep_raw
);
2529 validity
= isl_union_map_copy(dep
);
2530 coincidence
= isl_union_map_copy(dep
);
2531 proximity
= isl_union_map_copy(dep
);
2533 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
2534 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2535 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
2536 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2537 sched
= isl_schedule_constraints_compute_schedule(sc
);
2538 schedule
= isl_schedule_get_map(sched
);
2539 isl_schedule_free(sched
);
2540 isl_union_map_free(W
);
2541 isl_union_map_free(R
);
2542 isl_union_map_free(S
);
2545 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
2547 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
2548 is_complete
= isl_union_set_is_subset(D
, domain
);
2549 isl_union_set_free(D
);
2550 isl_union_set_free(domain
);
2552 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
2553 test
= isl_union_map_apply_range(test
, dep
);
2554 test
= isl_union_map_apply_range(test
, schedule
);
2556 delta
= isl_union_map_deltas(test
);
2557 if (isl_union_set_n_set(delta
) == 0) {
2561 isl_union_set_free(delta
);
2563 delta_set
= isl_set_from_union_set(delta
);
2565 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2566 for (i
= 0; i
< tilable
; ++i
)
2567 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
2568 is_tilable
= isl_set_is_subset(delta_set
, slice
);
2569 isl_set_free(slice
);
2571 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2572 for (i
= 0; i
< parallel
; ++i
)
2573 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
2574 is_parallel
= isl_set_is_subset(delta_set
, slice
);
2575 isl_set_free(slice
);
2577 origin
= isl_set_universe(isl_set_get_space(delta_set
));
2578 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
2579 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
2581 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
2582 delta_set
= isl_set_lexmin(delta_set
);
2584 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
2586 isl_set_free(origin
);
2587 isl_set_free(delta_set
);
2590 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
2591 is_injection
< 0 || is_complete
< 0)
2594 isl_die(ctx
, isl_error_unknown
,
2595 "generated schedule incomplete", return -1);
2597 isl_die(ctx
, isl_error_unknown
,
2598 "generated schedule not injective on each statement",
2601 isl_die(ctx
, isl_error_unknown
,
2602 "negative dependences in generated schedule",
2605 isl_die(ctx
, isl_error_unknown
,
2606 "generated schedule not as tilable as expected",
2609 isl_die(ctx
, isl_error_unknown
,
2610 "generated schedule not as parallel as expected",
2616 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
2617 const char *domain
, const char *validity
, const char *proximity
)
2621 isl_union_map
*prox
;
2622 isl_schedule_constraints
*sc
;
2623 isl_schedule
*schedule
;
2624 isl_union_map
*sched
;
2626 dom
= isl_union_set_read_from_str(ctx
, domain
);
2627 dep
= isl_union_map_read_from_str(ctx
, validity
);
2628 prox
= isl_union_map_read_from_str(ctx
, proximity
);
2629 sc
= isl_schedule_constraints_on_domain(dom
);
2630 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
2631 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
2632 schedule
= isl_schedule_constraints_compute_schedule(sc
);
2633 sched
= isl_schedule_get_map(schedule
);
2634 isl_schedule_free(schedule
);
2639 /* Check that a schedule can be constructed on the given domain
2640 * with the given validity and proximity constraints.
2642 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
2643 const char *validity
, const char *proximity
)
2645 isl_union_map
*sched
;
2647 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
2651 isl_union_map_free(sched
);
2655 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
2656 const char *validity
, const char *proximity
, const char *expected_sched
)
2658 isl_union_map
*sched1
, *sched2
;
2661 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
2662 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
2664 equal
= isl_union_map_is_equal(sched1
, sched2
);
2665 isl_union_map_free(sched1
);
2666 isl_union_map_free(sched2
);
2671 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
2677 /* Check that the schedule map is properly padded, even after being
2678 * reconstructed from the band forest.
2680 static int test_padded_schedule(isl_ctx
*ctx
)
2684 isl_union_map
*validity
, *proximity
;
2685 isl_schedule_constraints
*sc
;
2686 isl_schedule
*sched
;
2687 isl_union_map
*map1
, *map2
;
2688 isl_band_list
*list
;
2691 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
2692 D
= isl_union_set_read_from_str(ctx
, str
);
2693 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
2694 proximity
= isl_union_map_copy(validity
);
2695 sc
= isl_schedule_constraints_on_domain(D
);
2696 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2697 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2698 sched
= isl_schedule_constraints_compute_schedule(sc
);
2699 map1
= isl_schedule_get_map(sched
);
2700 list
= isl_schedule_get_band_forest(sched
);
2701 isl_band_list_free(list
);
2702 map2
= isl_schedule_get_map(sched
);
2703 isl_schedule_free(sched
);
2704 equal
= isl_union_map_is_equal(map1
, map2
);
2705 isl_union_map_free(map1
);
2706 isl_union_map_free(map2
);
2711 isl_die(ctx
, isl_error_unknown
,
2712 "reconstructed schedule map not the same as original",
2718 /* Input for testing of schedule construction based on
2719 * conditional constraints.
2721 * domain is the iteration domain
2722 * flow are the flow dependences, which determine the validity and
2723 * proximity constraints
2724 * condition are the conditions on the conditional validity constraints
2725 * conditional_validity are the conditional validity constraints
2726 * outer_band_n is the expected number of members in the outer band
2731 const char *condition
;
2732 const char *conditional_validity
;
2734 } live_range_tests
[] = {
2735 /* Contrived example that illustrates that we need to keep
2736 * track of tagged condition dependences and
2737 * tagged conditional validity dependences
2738 * in isl_sched_edge separately.
2739 * In particular, the conditional validity constraints on A
2740 * cannot be satisfied,
2741 * but they can be ignored because there are no corresponding
2742 * condition constraints. However, we do have an additional
2743 * conditional validity constraint that maps to the same
2744 * dependence relation
2745 * as the condition constraint on B. If we did not make a distinction
2746 * between tagged condition and tagged conditional validity
2747 * dependences, then we
2748 * could end up treating this shared dependence as an condition
2749 * constraint on A, forcing a localization of the conditions,
2750 * which is impossible.
2752 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
2753 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
2754 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
2755 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2756 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2757 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
2760 /* TACO 2013 Fig. 7 */
2761 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2762 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2763 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2764 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
2765 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
2766 "0 <= i < n and 0 <= j < n - 1 }",
2767 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
2768 "0 <= i < n and 0 <= j < j' < n;"
2769 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
2770 "0 <= i < i' < n and 0 <= j,j' < n;"
2771 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
2772 "0 <= i,j,j' < n and j < j' }",
2775 /* TACO 2013 Fig. 7, without tags */
2776 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2777 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2778 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2779 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2780 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2781 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
2782 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
2783 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
2786 /* TACO 2013 Fig. 12 */
2787 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
2788 "S3[i,3] : 0 <= i <= 1 }",
2789 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
2790 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
2791 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
2792 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
2793 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2794 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
2795 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2796 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
2797 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
2798 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
2799 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
2804 /* Test schedule construction based on conditional constraints.
2805 * In particular, check the number of members in the outer band
2806 * as an indication of whether tiling is possible or not.
2808 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
2811 isl_union_set
*domain
;
2812 isl_union_map
*condition
;
2813 isl_union_map
*flow
;
2814 isl_union_map
*validity
;
2815 isl_schedule_constraints
*sc
;
2816 isl_schedule
*schedule
;
2817 isl_band_list
*list
;
2821 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
2822 domain
= isl_union_set_read_from_str(ctx
,
2823 live_range_tests
[i
].domain
);
2824 flow
= isl_union_map_read_from_str(ctx
,
2825 live_range_tests
[i
].flow
);
2826 condition
= isl_union_map_read_from_str(ctx
,
2827 live_range_tests
[i
].condition
);
2828 validity
= isl_union_map_read_from_str(ctx
,
2829 live_range_tests
[i
].conditional_validity
);
2830 sc
= isl_schedule_constraints_on_domain(domain
);
2831 sc
= isl_schedule_constraints_set_validity(sc
,
2832 isl_union_map_copy(flow
));
2833 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
2834 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
2835 condition
, validity
);
2836 schedule
= isl_schedule_constraints_compute_schedule(sc
);
2837 list
= isl_schedule_get_band_forest(schedule
);
2838 band
= isl_band_list_get_band(list
, 0);
2839 n_member
= isl_band_n_member(band
);
2840 isl_band_free(band
);
2841 isl_band_list_free(list
);
2842 isl_schedule_free(schedule
);
2846 if (n_member
!= live_range_tests
[i
].outer_band_n
)
2847 isl_die(ctx
, isl_error_unknown
,
2848 "unexpected number of members in outer band",
2854 int test_schedule(isl_ctx
*ctx
)
2856 const char *D
, *W
, *R
, *V
, *P
, *S
;
2858 /* Handle resulting schedule with zero bands. */
2859 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
2863 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2864 W
= "{ S1[t,i] -> a[t,i] }";
2865 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2866 "S1[t,i] -> a[t-1,i+1] }";
2867 S
= "{ S1[t,i] -> [t,i] }";
2868 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2871 /* Fig. 5 of CC2008 */
2872 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2874 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2875 "j >= 2 and j <= -1 + N }";
2876 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2877 "j >= 2 and j <= -1 + N; "
2878 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2879 "j >= 2 and j <= -1 + N }";
2880 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2881 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2884 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2885 W
= "{ S1[i] -> a[i] }";
2886 R
= "{ S2[i] -> a[i+1] }";
2887 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2888 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2891 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2892 W
= "{ S1[i] -> a[i] }";
2893 R
= "{ S2[i] -> a[9-i] }";
2894 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2895 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2898 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2899 W
= "{ S1[i] -> a[i] }";
2900 R
= "[N] -> { S2[i] -> a[N-1-i] }";
2901 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2902 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2905 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2906 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2907 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2908 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2909 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2912 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2913 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2914 R
= "{ S2[i,j] -> a[i-1,j] }";
2915 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2916 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2919 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2920 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2921 R
= "{ S2[i,j] -> a[i,j-1] }";
2922 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2923 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2926 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2927 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2928 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2929 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2930 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2931 "S_0[] -> [0, 0, 0] }";
2932 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
2934 ctx
->opt
->schedule_parametric
= 0;
2935 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2937 ctx
->opt
->schedule_parametric
= 1;
2939 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2940 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2941 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2942 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2943 "S4[i] -> a[i,N] }";
2944 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2945 "S4[i] -> [4,i,0] }";
2946 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2949 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2950 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2952 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2954 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2956 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2957 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2960 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2961 " S_2[t] : t >= 0 and t <= -1 + N; "
2962 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2964 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2965 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2966 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2967 "i >= 0 and i <= -1 + N }";
2968 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2969 "i >= 0 and i <= -1 + N; "
2970 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2971 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2972 " S_0[t] -> [0, t, 0] }";
2974 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2976 ctx
->opt
->schedule_parametric
= 0;
2977 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2979 ctx
->opt
->schedule_parametric
= 1;
2981 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2982 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2983 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
2986 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2987 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2988 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2989 "j >= 0 and j <= -1 + N; "
2990 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2991 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2992 "j >= 0 and j <= -1 + N; "
2993 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2994 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2995 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2998 D
= "{ S_0[i] : i >= 0 }";
2999 W
= "{ S_0[i] -> a[i] : i >= 0 }";
3000 R
= "{ S_0[i] -> a[0] : i >= 0 }";
3001 S
= "{ S_0[i] -> [0, i, 0] }";
3002 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3005 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
3006 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
3007 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
3008 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
3009 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3012 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
3013 "k <= -1 + n and k >= 0 }";
3014 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
3015 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
3016 "k <= -1 + n and k >= 0; "
3017 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
3018 "k <= -1 + n and k >= 0; "
3019 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
3020 "k <= -1 + n and k >= 0 }";
3021 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
3022 ctx
->opt
->schedule_outer_coincidence
= 1;
3023 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3025 ctx
->opt
->schedule_outer_coincidence
= 0;
3027 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
3028 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
3029 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
3030 "Stmt_for_body24[i0, i1, 1, 0]:"
3031 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
3032 "Stmt_for_body7[i0, i1, i2]:"
3033 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
3036 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
3037 "Stmt_for_body24[1, i1, i2, i3]:"
3038 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
3040 "Stmt_for_body24[0, i1, i2, i3] -> "
3041 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
3042 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
3044 "Stmt_for_body24[0, i1, i2, i3] ->"
3045 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
3046 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
3047 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
3048 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
3049 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
3050 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
3051 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
3052 "i1 <= 6 and i1 >= 0;"
3053 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
3054 "Stmt_for_body7[i0, i1, i2] -> "
3055 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
3056 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
3057 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
3058 "Stmt_for_body7[i0, i1, i2] -> "
3059 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
3060 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
3061 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
3063 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
3064 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
3065 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
3067 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3070 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
3071 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
3072 "j >= 1 and j <= 7;"
3073 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
3074 "j >= 1 and j <= 8 }";
3076 S
= "{ S_0[i, j] -> [i + j, j] }";
3077 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3078 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3080 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3082 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
3083 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
3084 "j >= 0 and j <= -1 + i }";
3085 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
3086 "i <= -1 + N and j >= 0;"
3087 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
3090 S
= "{ S_0[i, j] -> [i, j] }";
3091 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3092 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3094 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3096 /* Test both algorithms on a case with only proximity dependences. */
3097 D
= "{ S[i,j] : 0 <= i <= 10 }";
3099 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
3100 S
= "{ S[i, j] -> [j, i] }";
3101 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3102 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3104 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3105 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3108 D
= "{ A[a]; B[] }";
3110 P
= "{ A[a] -> B[] }";
3111 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3114 if (test_padded_schedule(ctx
) < 0)
3117 /* Check that check for progress is not confused by rational
3120 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
3121 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
3123 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
3124 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
3126 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3127 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3129 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3131 if (test_conditional_schedule_constraints(ctx
) < 0)
3137 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
3139 isl_union_map
*umap
;
3142 umap
= isl_union_map_read_from_str(ctx
, str
);
3143 test
= isl_union_map_plain_is_injective(umap
);
3144 isl_union_map_free(umap
);
3147 if (test
== injective
)
3150 isl_die(ctx
, isl_error_unknown
,
3151 "map not detected as injective", return -1);
3153 isl_die(ctx
, isl_error_unknown
,
3154 "map detected as injective", return -1);
3157 int test_injective(isl_ctx
*ctx
)
3161 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
3163 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
3165 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
3167 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
3169 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
3171 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
3173 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
3175 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
3178 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
3179 if (test_plain_injective(ctx
, str
, 1))
3181 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
3182 if (test_plain_injective(ctx
, str
, 0))
3188 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
3196 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
3197 equal
= isl_aff_plain_is_equal(aff
, aff2
);
3203 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
3207 equal
= aff_plain_is_equal(aff
, str
);
3211 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
3212 "result not as expected", return -1);
3217 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3218 __isl_take isl_aff
*aff2
);
3220 ['+'] = { &isl_aff_add
},
3221 ['-'] = { &isl_aff_sub
},
3222 ['*'] = { &isl_aff_mul
},
3230 } aff_bin_tests
[] = {
3231 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
3232 "{ [i] -> [2i] }" },
3233 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
3235 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
3236 "{ [i] -> [2i] }" },
3237 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
3238 "{ [i] -> [2i] }" },
3239 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
3240 "{ [i] -> [NaN] }" },
3241 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
3242 "{ [i] -> [NaN] }" },
3243 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
3244 "{ [i] -> [NaN] }" },
3245 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
3246 "{ [i] -> [NaN] }" },
3247 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
3248 "{ [i] -> [NaN] }" },
3249 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
3250 "{ [i] -> [NaN] }" },
3251 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
3252 "{ [i] -> [NaN] }" },
3253 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
3254 "{ [i] -> [NaN] }" },
3257 /* Perform some basic tests of binary operations on isl_aff objects.
3259 static int test_bin_aff(isl_ctx
*ctx
)
3262 isl_aff
*aff1
, *aff2
, *res
;
3263 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3264 __isl_take isl_aff
*aff2
);
3267 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
3268 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
3269 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
3270 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
3271 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
3272 aff1
= fn(aff1
, aff2
);
3273 if (isl_aff_is_nan(res
))
3274 ok
= isl_aff_is_nan(aff1
);
3276 ok
= isl_aff_plain_is_equal(aff1
, res
);
3282 isl_die(ctx
, isl_error_unknown
,
3283 "unexpected result", return -1);
3289 int test_aff(isl_ctx
*ctx
)
3294 isl_local_space
*ls
;
3298 if (test_bin_aff(ctx
) < 0)
3301 space
= isl_space_set_alloc(ctx
, 0, 1);
3302 ls
= isl_local_space_from_space(space
);
3303 aff
= isl_aff_zero_on_domain(ls
);
3305 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3306 aff
= isl_aff_scale_down_ui(aff
, 3);
3307 aff
= isl_aff_floor(aff
);
3308 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3309 aff
= isl_aff_scale_down_ui(aff
, 2);
3310 aff
= isl_aff_floor(aff
);
3311 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3314 set
= isl_set_read_from_str(ctx
, str
);
3315 aff
= isl_aff_gist(aff
, set
);
3317 aff
= isl_aff_add_constant_si(aff
, -16);
3318 zero
= isl_aff_plain_is_zero(aff
);
3324 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3326 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
3327 aff
= isl_aff_scale_down_ui(aff
, 64);
3328 aff
= isl_aff_floor(aff
);
3329 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
3337 int test_dim_max(isl_ctx
*ctx
)
3341 isl_set
*set1
, *set2
;
3346 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
3347 set
= isl_set_read_from_str(ctx
, str
);
3348 pwaff
= isl_set_dim_max(set
, 0);
3349 set1
= isl_set_from_pw_aff(pwaff
);
3350 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
3351 set2
= isl_set_read_from_str(ctx
, str
);
3352 equal
= isl_set_is_equal(set1
, set2
);
3358 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3360 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
3361 set
= isl_set_read_from_str(ctx
, str
);
3362 pwaff
= isl_set_dim_max(set
, 0);
3363 set1
= isl_set_from_pw_aff(pwaff
);
3364 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3365 set2
= isl_set_read_from_str(ctx
, str
);
3366 equal
= isl_set_is_equal(set1
, set2
);
3372 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3374 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
3375 set
= isl_set_read_from_str(ctx
, str
);
3376 pwaff
= isl_set_dim_max(set
, 0);
3377 set1
= isl_set_from_pw_aff(pwaff
);
3378 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3379 set2
= isl_set_read_from_str(ctx
, str
);
3380 equal
= isl_set_is_equal(set1
, set2
);
3386 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3388 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
3389 "0 <= i < N and 0 <= j < M }";
3390 map
= isl_map_read_from_str(ctx
, str
);
3391 set
= isl_map_range(map
);
3393 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
3394 set1
= isl_set_from_pw_aff(pwaff
);
3395 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
3396 set2
= isl_set_read_from_str(ctx
, str
);
3397 equal
= isl_set_is_equal(set1
, set2
);
3401 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
3402 set1
= isl_set_from_pw_aff(pwaff
);
3403 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
3404 set2
= isl_set_read_from_str(ctx
, str
);
3405 if (equal
>= 0 && equal
)
3406 equal
= isl_set_is_equal(set1
, set2
);
3415 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3417 /* Check that solutions are properly merged. */
3418 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
3419 "c <= -1 + n - 4a - 2b and c >= -2b and "
3420 "4a >= -4 + n and c >= 0 }";
3421 set
= isl_set_read_from_str(ctx
, str
);
3422 pwaff
= isl_set_dim_min(set
, 2);
3423 set1
= isl_set_from_pw_aff(pwaff
);
3424 str
= "[n] -> { [(0)] : n >= 1 }";
3425 set2
= isl_set_read_from_str(ctx
, str
);
3426 equal
= isl_set_is_equal(set1
, set2
);
3433 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3435 /* Check that empty solution lie in the right space. */
3436 str
= "[n] -> { [t,a] : 1 = 0 }";
3437 set
= isl_set_read_from_str(ctx
, str
);
3438 pwaff
= isl_set_dim_max(set
, 0);
3439 set1
= isl_set_from_pw_aff(pwaff
);
3440 str
= "[n] -> { [t] : 1 = 0 }";
3441 set2
= isl_set_read_from_str(ctx
, str
);
3442 equal
= isl_set_is_equal(set1
, set2
);
3449 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3454 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
3456 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
3460 isl_pw_multi_aff
*pma2
;
3466 ctx
= isl_pw_multi_aff_get_ctx(pma
);
3467 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3468 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
3469 isl_pw_multi_aff_free(pma2
);
3474 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
3475 * represented by "str".
3477 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
3482 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
3486 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
3487 "result not as expected", return -1);
3491 /* Basic test for isl_pw_multi_aff_product.
3493 * Check that multiple pieces are properly handled.
3495 static int test_product_pma(isl_ctx
*ctx
)
3499 isl_pw_multi_aff
*pma1
, *pma2
;
3501 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
3502 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3503 str
= "{ C[] -> D[] }";
3504 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3505 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
3506 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
3507 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
3508 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
3509 isl_pw_multi_aff_free(pma1
);
3516 int test_product(isl_ctx
*ctx
)
3520 isl_union_set
*uset1
, *uset2
;
3524 set
= isl_set_read_from_str(ctx
, str
);
3525 set
= isl_set_product(set
, isl_set_copy(set
));
3526 ok
= isl_set_is_wrapping(set
);
3531 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3534 uset1
= isl_union_set_read_from_str(ctx
, str
);
3535 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
3536 str
= "{ [[] -> []] }";
3537 uset2
= isl_union_set_read_from_str(ctx
, str
);
3538 ok
= isl_union_set_is_equal(uset1
, uset2
);
3539 isl_union_set_free(uset1
);
3540 isl_union_set_free(uset2
);
3544 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3546 if (test_product_pma(ctx
) < 0)
3552 /* Check that two sets are not considered disjoint just because
3553 * they have a different set of (named) parameters.
3555 static int test_disjoint(isl_ctx
*ctx
)
3558 isl_set
*set
, *set2
;
3561 str
= "[n] -> { [[]->[]] }";
3562 set
= isl_set_read_from_str(ctx
, str
);
3563 str
= "{ [[]->[]] }";
3564 set2
= isl_set_read_from_str(ctx
, str
);
3565 disjoint
= isl_set_is_disjoint(set
, set2
);
3571 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3576 int test_equal(isl_ctx
*ctx
)
3579 isl_set
*set
, *set2
;
3583 set
= isl_set_read_from_str(ctx
, str
);
3585 set2
= isl_set_read_from_str(ctx
, str
);
3586 equal
= isl_set_is_equal(set
, set2
);
3592 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3597 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
3598 enum isl_dim_type type
, unsigned pos
, int fixed
)
3602 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
3609 isl_die(ctx
, isl_error_unknown
,
3610 "map not detected as fixed", return -1);
3612 isl_die(ctx
, isl_error_unknown
,
3613 "map detected as fixed", return -1);
3616 int test_fixed(isl_ctx
*ctx
)
3621 str
= "{ [i] -> [i] }";
3622 map
= isl_map_read_from_str(ctx
, str
);
3623 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
3625 str
= "{ [i] -> [1] }";
3626 map
= isl_map_read_from_str(ctx
, str
);
3627 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3629 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
3630 map
= isl_map_read_from_str(ctx
, str
);
3631 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3633 map
= isl_map_read_from_str(ctx
, str
);
3634 map
= isl_map_neg(map
);
3635 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3641 struct isl_vertices_test_data
{
3644 const char *vertex
[2];
3645 } vertices_tests
[] = {
3646 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
3647 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
3648 { "{ A[t, i] : t = 14 and i = 1 }",
3649 1, { "{ A[14, 1] }" } },
3652 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
3654 static int find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
3656 struct isl_vertices_test_data
*data
= user
;
3659 isl_basic_set
*bset
;
3660 isl_pw_multi_aff
*pma
;
3664 ctx
= isl_vertex_get_ctx(vertex
);
3665 bset
= isl_vertex_get_domain(vertex
);
3666 ma
= isl_vertex_get_expr(vertex
);
3667 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
3669 for (i
= 0; i
< data
->n
; ++i
) {
3670 isl_pw_multi_aff
*pma_i
;
3672 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
3673 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
3674 isl_pw_multi_aff_free(pma_i
);
3676 if (equal
< 0 || equal
)
3680 isl_pw_multi_aff_free(pma
);
3681 isl_vertex_free(vertex
);
3686 return equal
? 0 : - 1;
3689 int test_vertices(isl_ctx
*ctx
)
3693 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
3694 isl_basic_set
*bset
;
3695 isl_vertices
*vertices
;
3699 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
3700 vertices
= isl_basic_set_compute_vertices(bset
);
3701 n
= isl_vertices_get_n_vertices(vertices
);
3702 if (vertices_tests
[i
].n
!= n
)
3704 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
3705 &vertices_tests
[i
]) < 0)
3707 isl_vertices_free(vertices
);
3708 isl_basic_set_free(bset
);
3713 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
3720 int test_union_pw(isl_ctx
*ctx
)
3724 isl_union_set
*uset
;
3725 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
3727 str
= "{ [x] -> x^2 }";
3728 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
3729 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
3730 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
3731 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
3732 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
3733 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
3734 isl_union_pw_qpolynomial_free(upwqp1
);
3735 isl_union_pw_qpolynomial_free(upwqp2
);
3739 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3744 int test_output(isl_ctx
*ctx
)
3752 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
3753 pa
= isl_pw_aff_read_from_str(ctx
, str
);
3755 p
= isl_printer_to_str(ctx
);
3756 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
3757 p
= isl_printer_print_pw_aff(p
, pa
);
3758 s
= isl_printer_get_str(p
);
3759 isl_printer_free(p
);
3760 isl_pw_aff_free(pa
);
3764 equal
= !strcmp(s
, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
3769 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3774 int test_sample(isl_ctx
*ctx
)
3777 isl_basic_set
*bset1
, *bset2
;
3780 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
3781 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
3782 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
3783 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
3784 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
3785 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
3786 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
3787 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
3788 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
3789 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
3790 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
3791 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
3792 "d - 1073741821e and "
3793 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
3794 "3j >= 1 - a + b + 2e and "
3795 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
3796 "3i <= 4 - a + 4b - e and "
3797 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
3798 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
3799 "c <= -1 + a and 3i >= -2 - a + 3e and "
3800 "1073741822e <= 1073741823 - a + 1073741822b + c and "
3801 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
3802 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
3803 "1073741823e >= 1 + 1073741823b - d and "
3804 "3i >= 1073741823b + c - 1073741823e - f and "
3805 "3i >= 1 + 2b + e + 3g }";
3806 bset1
= isl_basic_set_read_from_str(ctx
, str
);
3807 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
3808 empty
= isl_basic_set_is_empty(bset2
);
3809 subset
= isl_basic_set_is_subset(bset2
, bset1
);
3810 isl_basic_set_free(bset1
);
3811 isl_basic_set_free(bset2
);
3812 if (empty
< 0 || subset
< 0)
3815 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
3817 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
3822 int test_fixed_power(isl_ctx
*ctx
)
3830 str
= "{ [i] -> [i + 1] }";
3831 map
= isl_map_read_from_str(ctx
, str
);
3832 isl_int_set_si(exp
, 23);
3833 map
= isl_map_fixed_power(map
, exp
);
3834 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
3843 int test_slice(isl_ctx
*ctx
)
3849 str
= "{ [i] -> [j] }";
3850 map
= isl_map_read_from_str(ctx
, str
);
3851 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3852 equal
= map_check_equal(map
, "{ [i] -> [i] }");
3857 str
= "{ [i] -> [j] }";
3858 map
= isl_map_read_from_str(ctx
, str
);
3859 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3860 equal
= map_check_equal(map
, "{ [i] -> [j] }");
3865 str
= "{ [i] -> [j] }";
3866 map
= isl_map_read_from_str(ctx
, str
);
3867 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3868 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
3873 str
= "{ [i] -> [j] }";
3874 map
= isl_map_read_from_str(ctx
, str
);
3875 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3876 equal
= map_check_equal(map
, "{ [0] -> [j] }");
3881 str
= "{ [i] -> [j] }";
3882 map
= isl_map_read_from_str(ctx
, str
);
3883 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3884 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
3889 str
= "{ [i] -> [j] }";
3890 map
= isl_map_read_from_str(ctx
, str
);
3891 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3892 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
3900 int test_eliminate(isl_ctx
*ctx
)
3906 str
= "{ [i] -> [j] : i = 2j }";
3907 map
= isl_map_read_from_str(ctx
, str
);
3908 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
3909 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
3917 /* Check that isl_set_dim_residue_class detects that the values of j
3918 * in the set below are all odd and that it does not detect any spurious
3921 static int test_residue_class(isl_ctx
*ctx
)
3928 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
3929 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
3930 set
= isl_set_read_from_str(ctx
, str
);
3933 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
3935 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
3936 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
3945 int test_align_parameters(isl_ctx
*ctx
)
3949 isl_multi_aff
*ma1
, *ma2
;
3952 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
3953 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
3955 space
= isl_space_params_alloc(ctx
, 1);
3956 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
3957 ma1
= isl_multi_aff_align_params(ma1
, space
);
3959 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
3960 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
3962 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
3964 isl_multi_aff_free(ma1
);
3965 isl_multi_aff_free(ma2
);
3970 isl_die(ctx
, isl_error_unknown
,
3971 "result not as expected", return -1);
3976 static int test_list(isl_ctx
*ctx
)
3978 isl_id
*a
, *b
, *c
, *d
, *id
;
3982 a
= isl_id_alloc(ctx
, "a", NULL
);
3983 b
= isl_id_alloc(ctx
, "b", NULL
);
3984 c
= isl_id_alloc(ctx
, "c", NULL
);
3985 d
= isl_id_alloc(ctx
, "d", NULL
);
3987 list
= isl_id_list_alloc(ctx
, 4);
3988 list
= isl_id_list_add(list
, a
);
3989 list
= isl_id_list_add(list
, b
);
3990 list
= isl_id_list_add(list
, c
);
3991 list
= isl_id_list_add(list
, d
);
3992 list
= isl_id_list_drop(list
, 1, 1);
3994 if (isl_id_list_n_id(list
) != 3) {
3995 isl_id_list_free(list
);
3996 isl_die(ctx
, isl_error_unknown
,
3997 "unexpected number of elements in list", return -1);
4000 id
= isl_id_list_get_id(list
, 0);
4003 id
= isl_id_list_get_id(list
, 1);
4006 id
= isl_id_list_get_id(list
, 2);
4010 isl_id_list_free(list
);
4013 isl_die(ctx
, isl_error_unknown
,
4014 "unexpected elements in list", return -1);
4019 const char *set_conversion_tests
[] = {
4020 "[N] -> { [i] : N - 1 <= 2 i <= N }",
4021 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
4022 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4023 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4026 /* Check that converting from isl_set to isl_pw_multi_aff and back
4027 * to isl_set produces the original isl_set.
4029 static int test_set_conversion(isl_ctx
*ctx
)
4033 isl_set
*set1
, *set2
;
4034 isl_pw_multi_aff
*pma
;
4037 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
4038 str
= set_conversion_tests
[i
];
4039 set1
= isl_set_read_from_str(ctx
, str
);
4040 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
4041 set2
= isl_set_from_pw_multi_aff(pma
);
4042 equal
= isl_set_is_equal(set1
, set2
);
4049 isl_die(ctx
, isl_error_unknown
, "bad conversion",
4056 /* Check that converting from isl_map to isl_pw_multi_aff and back
4057 * to isl_map produces the original isl_map.
4059 static int test_map_conversion(isl_ctx
*ctx
)
4062 isl_map
*map1
, *map2
;
4063 isl_pw_multi_aff
*pma
;
4066 str
= "{ [a, b, c, d] -> s0[a, b, e, f] : "
4067 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
4068 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
4069 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
4071 map1
= isl_map_read_from_str(ctx
, str
);
4072 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
4073 map2
= isl_map_from_pw_multi_aff(pma
);
4074 equal
= isl_map_is_equal(map1
, map2
);
4081 isl_die(ctx
, isl_error_unknown
, "bad conversion", return -1);
4086 static int test_conversion(isl_ctx
*ctx
)
4088 if (test_set_conversion(ctx
) < 0)
4090 if (test_map_conversion(ctx
) < 0)
4095 /* Check that isl_basic_map_curry does not modify input.
4097 static int test_curry(isl_ctx
*ctx
)
4100 isl_basic_map
*bmap1
, *bmap2
;
4103 str
= "{ [A[] -> B[]] -> C[] }";
4104 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
4105 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
4106 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
4107 isl_basic_map_free(bmap1
);
4108 isl_basic_map_free(bmap2
);
4113 isl_die(ctx
, isl_error_unknown
,
4114 "curried map should not be equal to original",
4124 } preimage_tests
[] = {
4125 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
4126 "{ A[j,i] -> B[i,j] }",
4127 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
4128 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4129 "{ A[a,b] -> B[a/2,b/6] }",
4130 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
4131 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4132 "{ A[a,b] -> B[a/2,b/6] }",
4133 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
4134 "exists i,j : a = 2 i and b = 6 j }" },
4135 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
4136 "[n] -> { : 0 <= n <= 100 }" },
4137 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4138 "{ A[a] -> B[2a] }",
4139 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
4140 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4141 "{ A[a] -> B[([a/2])] }",
4142 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
4143 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
4144 "{ A[a] -> B[a,a,a/3] }",
4145 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
4146 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
4147 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
4150 static int test_preimage_basic_set(isl_ctx
*ctx
)
4153 isl_basic_set
*bset1
, *bset2
;
4157 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
4158 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
4159 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
4160 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
4161 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
4162 equal
= isl_basic_set_is_equal(bset1
, bset2
);
4163 isl_basic_set_free(bset1
);
4164 isl_basic_set_free(bset2
);
4168 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4179 } preimage_domain_tests
[] = {
4180 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
4181 "{ A[j,i] -> B[i,j] }",
4182 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
4183 { "{ B[i] -> C[i]; D[i] -> E[i] }",
4184 "{ A[i] -> B[i + 1] }",
4185 "{ A[i] -> C[i + 1] }" },
4186 { "{ B[i] -> C[i]; B[i] -> E[i] }",
4187 "{ A[i] -> B[i + 1] }",
4188 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
4189 { "{ B[i] -> C[([i/2])] }",
4190 "{ A[i] -> B[2i] }",
4191 "{ A[i] -> C[i] }" },
4192 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
4193 "{ A[i] -> B[([i/5]), ([i/7])] }",
4194 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
4195 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
4196 "[N] -> { A[] -> B[([N/5])] }",
4197 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
4198 { "{ B[i] -> C[i] : exists a : i = 5 a }",
4199 "{ A[i] -> B[2i] }",
4200 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
4201 { "{ B[i] -> C[i] : exists a : i = 2 a; "
4202 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
4203 "{ A[i] -> B[2i] }",
4204 "{ A[i] -> C[2i] }" },
4207 static int test_preimage_union_map(isl_ctx
*ctx
)
4210 isl_union_map
*umap1
, *umap2
;
4214 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
4215 umap1
= isl_union_map_read_from_str(ctx
,
4216 preimage_domain_tests
[i
].map
);
4217 ma
= isl_multi_aff_read_from_str(ctx
,
4218 preimage_domain_tests
[i
].ma
);
4219 umap2
= isl_union_map_read_from_str(ctx
,
4220 preimage_domain_tests
[i
].res
);
4221 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
4222 equal
= isl_union_map_is_equal(umap1
, umap2
);
4223 isl_union_map_free(umap1
);
4224 isl_union_map_free(umap2
);
4228 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4235 static int test_preimage(isl_ctx
*ctx
)
4237 if (test_preimage_basic_set(ctx
) < 0)
4239 if (test_preimage_union_map(ctx
) < 0)
4249 } pullback_tests
[] = {
4250 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
4251 "{ A[a,b] -> C[b + 2a] }" },
4252 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
4253 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
4254 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
4255 "{ A[a] -> C[(a)/6] }" },
4256 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
4257 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
4258 "{ A[a] -> C[(2a)/3] }" },
4259 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
4260 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
4261 "{ A[i,j] -> C[i + j, i + j] }"},
4262 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
4263 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
4264 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
4267 static int test_pullback(isl_ctx
*ctx
)
4270 isl_multi_aff
*ma1
, *ma2
;
4274 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
4275 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
4276 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
4277 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
4278 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
4279 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4280 isl_multi_aff_free(ma1
);
4281 isl_multi_aff_free(ma2
);
4285 isl_die(ctx
, isl_error_unknown
, "bad pullback",
4292 /* Check that negation is printed correctly.
4294 static int test_ast(isl_ctx
*ctx
)
4296 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
4300 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4301 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4302 expr
= isl_ast_expr_add(expr1
, expr2
);
4303 expr
= isl_ast_expr_neg(expr
);
4304 str
= isl_ast_expr_to_str(expr
);
4305 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
4307 isl_ast_expr_free(expr
);
4312 isl_die(ctx
, isl_error_unknown
,
4313 "isl_ast_expr printed incorrectly", return -1);
4315 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4316 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4317 expr
= isl_ast_expr_add(expr1
, expr2
);
4318 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
4319 expr
= isl_ast_expr_sub(expr3
, expr
);
4320 str
= isl_ast_expr_to_str(expr
);
4321 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
4323 isl_ast_expr_free(expr
);
4328 isl_die(ctx
, isl_error_unknown
,
4329 "isl_ast_expr printed incorrectly", return -1);
4334 /* Internal data structure for before_for and after_for callbacks.
4336 * depth is the current depth
4337 * before is the number of times before_for has been called
4338 * after is the number of times after_for has been called
4340 struct isl_test_codegen_data
{
4346 /* This function is called before each for loop in the AST generated
4347 * from test_ast_gen1.
4349 * Increment the number of calls and the depth.
4350 * Check that the space returned by isl_ast_build_get_schedule_space
4351 * matches the target space of the schedule returned by
4352 * isl_ast_build_get_schedule.
4353 * Return an isl_id that is checked by the corresponding call
4356 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
4359 struct isl_test_codegen_data
*data
= user
;
4362 isl_union_map
*schedule
;
4363 isl_union_set
*uset
;
4368 ctx
= isl_ast_build_get_ctx(build
);
4370 if (data
->before
>= 3)
4371 isl_die(ctx
, isl_error_unknown
,
4372 "unexpected number of for nodes", return NULL
);
4373 if (data
->depth
>= 2)
4374 isl_die(ctx
, isl_error_unknown
,
4375 "unexpected depth", return NULL
);
4377 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
4381 schedule
= isl_ast_build_get_schedule(build
);
4382 uset
= isl_union_map_range(schedule
);
4385 if (isl_union_set_n_set(uset
) != 1) {
4386 isl_union_set_free(uset
);
4387 isl_die(ctx
, isl_error_unknown
,
4388 "expecting single range space", return NULL
);
4391 space
= isl_ast_build_get_schedule_space(build
);
4392 set
= isl_union_set_extract_set(uset
, space
);
4393 isl_union_set_free(uset
);
4394 empty
= isl_set_is_empty(set
);
4400 isl_die(ctx
, isl_error_unknown
,
4401 "spaces don't match", return NULL
);
4403 return isl_id_alloc(ctx
, name
, NULL
);
4406 /* This function is called after each for loop in the AST generated
4407 * from test_ast_gen1.
4409 * Increment the number of calls and decrement the depth.
4410 * Check that the annotation attached to the node matches
4411 * the isl_id returned by the corresponding call to before_for.
4413 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
4414 __isl_keep isl_ast_build
*build
, void *user
)
4416 struct isl_test_codegen_data
*data
= user
;
4424 if (data
->after
> data
->before
)
4425 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4426 "mismatch in number of for nodes",
4427 return isl_ast_node_free(node
));
4429 id
= isl_ast_node_get_annotation(node
);
4431 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4432 "missing annotation", return isl_ast_node_free(node
));
4434 name
= isl_id_get_name(id
);
4435 valid
= name
&& atoi(name
+ 1) == data
->depth
;
4439 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4440 "wrong annotation", return isl_ast_node_free(node
));
4445 /* Check that the before_each_for and after_each_for callbacks
4446 * are called for each for loop in the generated code,
4447 * that they are called in the right order and that the isl_id
4448 * returned from the before_each_for callback is attached to
4449 * the isl_ast_node passed to the corresponding after_each_for call.
4451 static int test_ast_gen1(isl_ctx
*ctx
)
4455 isl_union_map
*schedule
;
4456 isl_ast_build
*build
;
4458 struct isl_test_codegen_data data
;
4460 str
= "[N] -> { : N >= 10 }";
4461 set
= isl_set_read_from_str(ctx
, str
);
4462 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
4463 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
4464 schedule
= isl_union_map_read_from_str(ctx
, str
);
4469 build
= isl_ast_build_from_context(set
);
4470 build
= isl_ast_build_set_before_each_for(build
,
4471 &before_for
, &data
);
4472 build
= isl_ast_build_set_after_each_for(build
,
4474 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4475 isl_ast_build_free(build
);
4479 isl_ast_node_free(tree
);
4481 if (data
.before
!= 3 || data
.after
!= 3)
4482 isl_die(ctx
, isl_error_unknown
,
4483 "unexpected number of for nodes", return -1);
4488 /* Check that the AST generator handles domains that are integrally disjoint
4489 * but not ratinoally disjoint.
4491 static int test_ast_gen2(isl_ctx
*ctx
)
4495 isl_union_map
*schedule
;
4496 isl_union_map
*options
;
4497 isl_ast_build
*build
;
4500 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
4501 schedule
= isl_union_map_read_from_str(ctx
, str
);
4502 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4503 build
= isl_ast_build_from_context(set
);
4505 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
4506 options
= isl_union_map_read_from_str(ctx
, str
);
4507 build
= isl_ast_build_set_options(build
, options
);
4508 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4509 isl_ast_build_free(build
);
4512 isl_ast_node_free(tree
);
4517 /* Increment *user on each call.
4519 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
4520 __isl_keep isl_ast_build
*build
, void *user
)
4529 /* Test that unrolling tries to minimize the number of instances.
4530 * In particular, for the schedule given below, make sure it generates
4531 * 3 nodes (rather than 101).
4533 static int test_ast_gen3(isl_ctx
*ctx
)
4537 isl_union_map
*schedule
;
4538 isl_union_map
*options
;
4539 isl_ast_build
*build
;
4543 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
4544 schedule
= isl_union_map_read_from_str(ctx
, str
);
4545 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4547 str
= "{ [i] -> unroll[0] }";
4548 options
= isl_union_map_read_from_str(ctx
, str
);
4550 build
= isl_ast_build_from_context(set
);
4551 build
= isl_ast_build_set_options(build
, options
);
4552 build
= isl_ast_build_set_at_each_domain(build
,
4553 &count_domains
, &n_domain
);
4554 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4555 isl_ast_build_free(build
);
4559 isl_ast_node_free(tree
);
4562 isl_die(ctx
, isl_error_unknown
,
4563 "unexpected number of for nodes", return -1);
4568 /* Check that if the ast_build_exploit_nested_bounds options is set,
4569 * we do not get an outer if node in the generated AST,
4570 * while we do get such an outer if node if the options is not set.
4572 static int test_ast_gen4(isl_ctx
*ctx
)
4576 isl_union_map
*schedule
;
4577 isl_ast_build
*build
;
4579 enum isl_ast_node_type type
;
4582 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
4583 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
4585 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
4587 schedule
= isl_union_map_read_from_str(ctx
, str
);
4588 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4589 build
= isl_ast_build_from_context(set
);
4590 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4591 isl_ast_build_free(build
);
4595 type
= isl_ast_node_get_type(tree
);
4596 isl_ast_node_free(tree
);
4598 if (type
== isl_ast_node_if
)
4599 isl_die(ctx
, isl_error_unknown
,
4600 "not expecting if node", return -1);
4602 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
4604 schedule
= isl_union_map_read_from_str(ctx
, str
);
4605 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4606 build
= isl_ast_build_from_context(set
);
4607 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4608 isl_ast_build_free(build
);
4612 type
= isl_ast_node_get_type(tree
);
4613 isl_ast_node_free(tree
);
4615 if (type
!= isl_ast_node_if
)
4616 isl_die(ctx
, isl_error_unknown
,
4617 "expecting if node", return -1);
4619 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
4624 /* This function is called for each leaf in the AST generated
4625 * from test_ast_gen5.
4627 * We finalize the AST generation by extending the outer schedule
4628 * with a zero-dimensional schedule. If this results in any for loops,
4629 * then this means that we did not pass along enough information
4630 * about the outer schedule to the inner AST generation.
4632 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
4635 isl_union_map
*schedule
, *extra
;
4638 schedule
= isl_ast_build_get_schedule(build
);
4639 extra
= isl_union_map_copy(schedule
);
4640 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
4641 schedule
= isl_union_map_range_product(schedule
, extra
);
4642 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4643 isl_ast_build_free(build
);
4648 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
4649 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
4650 "code should not contain any for loop",
4651 return isl_ast_node_free(tree
));
4656 /* Check that we do not lose any information when going back and
4657 * forth between internal and external schedule.
4659 * In particular, we create an AST where we unroll the only
4660 * non-constant dimension in the schedule. We therefore do
4661 * not expect any for loops in the AST. However, older versions
4662 * of isl would not pass along enough information about the outer
4663 * schedule when performing an inner code generation from a create_leaf
4664 * callback, resulting in the inner code generation producing a for loop.
4666 static int test_ast_gen5(isl_ctx
*ctx
)
4670 isl_union_map
*schedule
, *options
;
4671 isl_ast_build
*build
;
4674 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
4675 schedule
= isl_union_map_read_from_str(ctx
, str
);
4677 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
4678 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
4679 options
= isl_union_map_read_from_str(ctx
, str
);
4681 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4682 build
= isl_ast_build_from_context(set
);
4683 build
= isl_ast_build_set_options(build
, options
);
4684 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
4685 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4686 isl_ast_build_free(build
);
4687 isl_ast_node_free(tree
);
4694 static int test_ast_gen(isl_ctx
*ctx
)
4696 if (test_ast_gen1(ctx
) < 0)
4698 if (test_ast_gen2(ctx
) < 0)
4700 if (test_ast_gen3(ctx
) < 0)
4702 if (test_ast_gen4(ctx
) < 0)
4704 if (test_ast_gen5(ctx
) < 0)
4709 /* Check if dropping output dimensions from an isl_pw_multi_aff
4712 static int test_pw_multi_aff(isl_ctx
*ctx
)
4715 isl_pw_multi_aff
*pma1
, *pma2
;
4718 str
= "{ [i,j] -> [i+j, 4i-j] }";
4719 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4720 str
= "{ [i,j] -> [4i-j] }";
4721 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4723 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
4725 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
4727 isl_pw_multi_aff_free(pma1
);
4728 isl_pw_multi_aff_free(pma2
);
4732 isl_die(ctx
, isl_error_unknown
,
4733 "expressions not equal", return -1);
4738 /* Check that we can properly parse multi piecewise affine expressions
4739 * where the piecewise affine expressions have different domains.
4741 static int test_multi_pw_aff(isl_ctx
*ctx
)
4744 isl_set
*dom
, *dom2
;
4745 isl_multi_pw_aff
*mpa1
, *mpa2
;
4750 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
4751 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
4752 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
4753 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
4754 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
4755 str
= "{ [i] -> [(i : i > 0), 2i] }";
4756 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
4758 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
4760 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
4761 dom
= isl_pw_aff_domain(pa
);
4762 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
4763 dom2
= isl_pw_aff_domain(pa
);
4764 equal_domain
= isl_set_is_equal(dom
, dom2
);
4768 isl_multi_pw_aff_free(mpa1
);
4769 isl_multi_pw_aff_free(mpa2
);
4774 isl_die(ctx
, isl_error_unknown
,
4775 "expressions not equal", return -1);
4777 if (equal_domain
< 0)
4780 isl_die(ctx
, isl_error_unknown
,
4781 "domains unexpectedly equal", return -1);
4786 /* This is a regression test for a bug where isl_basic_map_simplify
4787 * would end up in an infinite loop. In particular, we construct
4788 * an empty basic set that is not obviously empty.
4789 * isl_basic_set_is_empty marks the basic set as empty.
4790 * After projecting out i3, the variable can be dropped completely,
4791 * but isl_basic_map_simplify refrains from doing so if the basic set
4792 * is empty and would end up in an infinite loop if it didn't test
4793 * explicitly for empty basic maps in the outer loop.
4795 static int test_simplify(isl_ctx
*ctx
)
4798 isl_basic_set
*bset
;
4801 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
4802 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
4803 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
4805 bset
= isl_basic_set_read_from_str(ctx
, str
);
4806 empty
= isl_basic_set_is_empty(bset
);
4807 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
4808 isl_basic_set_free(bset
);
4812 isl_die(ctx
, isl_error_unknown
,
4813 "basic set should be empty", return -1);
4818 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
4819 * with gbr context would fail to disable the use of the shifted tableau
4820 * when transferring equalities for the input to the context, resulting
4821 * in invalid sample values.
4823 static int test_partial_lexmin(isl_ctx
*ctx
)
4826 isl_basic_set
*bset
;
4827 isl_basic_map
*bmap
;
4830 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
4831 bmap
= isl_basic_map_read_from_str(ctx
, str
);
4832 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
4833 bset
= isl_basic_set_read_from_str(ctx
, str
);
4834 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
4843 /* Check that the variable compression performed on the existentially
4844 * quantified variables inside isl_basic_set_compute_divs is not confused
4845 * by the implicit equalities among the parameters.
4847 static int test_compute_divs(isl_ctx
*ctx
)
4850 isl_basic_set
*bset
;
4853 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
4854 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
4855 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
4856 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
4857 bset
= isl_basic_set_read_from_str(ctx
, str
);
4858 set
= isl_basic_set_compute_divs(bset
);
4868 int (*fn
)(isl_ctx
*ctx
);
4870 { "dependence analysis", &test_flow
},
4871 { "val", &test_val
},
4872 { "compute divs", &test_compute_divs
},
4873 { "partial lexmin", &test_partial_lexmin
},
4874 { "simplify", &test_simplify
},
4875 { "curry", &test_curry
},
4876 { "piecewise multi affine expressions", &test_pw_multi_aff
},
4877 { "multi piecewise affine expressions", &test_multi_pw_aff
},
4878 { "conversion", &test_conversion
},
4879 { "list", &test_list
},
4880 { "align parameters", &test_align_parameters
},
4881 { "preimage", &test_preimage
},
4882 { "pullback", &test_pullback
},
4883 { "AST", &test_ast
},
4884 { "AST generation", &test_ast_gen
},
4885 { "eliminate", &test_eliminate
},
4886 { "residue class", &test_residue_class
},
4887 { "div", &test_div
},
4888 { "slice", &test_slice
},
4889 { "fixed power", &test_fixed_power
},
4890 { "sample", &test_sample
},
4891 { "output", &test_output
},
4892 { "vertices", &test_vertices
},
4893 { "fixed", &test_fixed
},
4894 { "equal", &test_equal
},
4895 { "disjoint", &test_disjoint
},
4896 { "product", &test_product
},
4897 { "dim_max", &test_dim_max
},
4898 { "affine", &test_aff
},
4899 { "injective", &test_injective
},
4900 { "schedule", &test_schedule
},
4901 { "union_pw", &test_union_pw
},
4902 { "parse", &test_parse
},
4903 { "single-valued", &test_sv
},
4904 { "affine hull", &test_affine_hull
},
4905 { "coalesce", &test_coalesce
},
4906 { "factorize", &test_factorize
},
4907 { "subset", &test_subset
},
4908 { "subtract", &test_subtract
},
4909 { "lexmin", &test_lexmin
},
4910 { "min", &test_min
},
4911 { "gist", &test_gist
},
4912 { "piecewise quasi-polynomials", &test_pwqp
},
4918 struct isl_ctx
*ctx
;
4920 srcdir
= getenv("srcdir");
4923 ctx
= isl_ctx_alloc();
4924 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
4925 printf("%s\n", tests
[i
].name
);
4926 if (tests
[i
].fn(ctx
) < 0)
4932 test_split_periods(ctx
);
4934 test_bijective(ctx
);
4938 test_construction(ctx
);
4940 test_application(ctx
);
4941 test_convex_hull(ctx
);