2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
13 #include <isl_ctx_private.h>
14 #include <isl_map_private.h>
15 #include <isl_aff_private.h>
18 #include <isl_constraint_private.h>
19 #include <isl/polynomial.h>
20 #include <isl/union_map.h>
21 #include <isl_factorization.h>
22 #include <isl/schedule.h>
23 #include <isl_options_private.h>
24 #include <isl/vertices.h>
25 #include <isl/ast_build.h>
28 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
32 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
35 char *pattern
= "%s/test_inputs/%s.%s";
37 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
39 filename
= isl_alloc_array(ctx
, char, length
);
44 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
49 void test_parse_map(isl_ctx
*ctx
, const char *str
)
53 map
= isl_map_read_from_str(ctx
, str
);
58 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
63 map
= isl_map_read_from_str(ctx
, str
);
64 map2
= isl_map_read_from_str(ctx
, str2
);
65 equal
= isl_map_is_equal(map
, map2
);
72 isl_die(ctx
, isl_error_unknown
, "maps not equal",
78 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
80 isl_pw_qpolynomial
*pwqp
;
82 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
84 isl_pw_qpolynomial_free(pwqp
);
87 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
91 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
93 isl_pw_aff_free(pwaff
);
96 int test_parse(struct isl_ctx
*ctx
)
99 const char *str
, *str2
;
101 str
= "{ [i] -> [-i] }";
102 map
= isl_map_read_from_str(ctx
, str
);
106 str
= "{ A[i] -> L[([i/3])] }";
107 map
= isl_map_read_from_str(ctx
, str
);
111 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
112 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
113 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
115 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
116 str2
= "{ [x, y] : 2y >= 6 - x }";
117 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
120 if (test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
121 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
123 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
124 if (test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }",
128 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
129 map
= isl_map_read_from_str(ctx
, str
);
130 str
= "{ [new, old] -> [o0, o1] : "
131 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
132 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
133 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
134 map2
= isl_map_read_from_str(ctx
, str
);
135 assert(isl_map_is_equal(map
, map2
));
139 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
140 map
= isl_map_read_from_str(ctx
, str
);
141 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
142 map2
= isl_map_read_from_str(ctx
, str
);
143 assert(isl_map_is_equal(map
, map2
));
147 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
148 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
149 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
152 str
= "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
153 str2
= "{ [i,j] -> [min(i,j)] }";
154 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
157 str
= "{ [i,j] : i != j }";
158 str2
= "{ [i,j] : i < j or i > j }";
159 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
162 str
= "{ [i,j] : (i+1)*2 >= j }";
163 str2
= "{ [i, j] : j <= 2 + 2i }";
164 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
167 str
= "{ [i] -> [i > 0 ? 4 : 5] }";
168 str2
= "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
169 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
172 str
= "[N=2,M] -> { [i=[(M+N)/4]] }";
173 str2
= "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
174 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
177 str
= "{ [x] : x >= 0 }";
178 str2
= "{ [x] : x-0 >= 0 }";
179 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
182 str
= "{ [i] : ((i > 10)) }";
183 str2
= "{ [i] : i >= 11 }";
184 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
187 str
= "{ [i] -> [0] }";
188 str2
= "{ [i] -> [0 * i] }";
189 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
192 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
193 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
194 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
195 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
197 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : (not false) }",
198 "{ [a] -> [b] : true }") < 0)
201 if (test_parse_map_equal(ctx
, "{ [i] : i/2 <= 5 }",
202 "{ [i] : i <= 10 }") < 0)
205 if (test_parse_map_equal(ctx
, "{Sym=[n] [i] : i <= n }",
206 "[n] -> { [i] : i <= n }") < 0)
209 if (test_parse_map_equal(ctx
, "{ [*] }", "{ [a] }") < 0)
212 if (test_parse_map_equal(ctx
, "{ [i] : 2*floor(i/2) = i }",
213 "{ [i] : exists a : i = 2 a }") < 0)
216 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : a = 5 implies b = 5 }",
217 "{ [a] -> [b] : a != 5 or b = 5 }") < 0)
223 void test_read(struct isl_ctx
*ctx
)
227 struct isl_basic_set
*bset1
, *bset2
;
228 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
230 filename
= get_filename(ctx
, "set", "omega");
232 input
= fopen(filename
, "r");
235 bset1
= isl_basic_set_read_from_file(ctx
, input
);
236 bset2
= isl_basic_set_read_from_str(ctx
, str
);
238 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
240 isl_basic_set_free(bset1
);
241 isl_basic_set_free(bset2
);
247 void test_bounded(struct isl_ctx
*ctx
)
252 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
253 bounded
= isl_set_is_bounded(set
);
257 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
258 bounded
= isl_set_is_bounded(set
);
262 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
263 bounded
= isl_set_is_bounded(set
);
268 /* Construct the basic set { [i] : 5 <= i <= N } */
269 void test_construction(struct isl_ctx
*ctx
)
274 struct isl_basic_set
*bset
;
275 struct isl_constraint
*c
;
279 dim
= isl_space_set_alloc(ctx
, 1, 1);
280 bset
= isl_basic_set_universe(isl_space_copy(dim
));
281 ls
= isl_local_space_from_space(dim
);
283 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
284 isl_int_set_si(v
, -1);
285 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
286 isl_int_set_si(v
, 1);
287 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
288 bset
= isl_basic_set_add_constraint(bset
, c
);
290 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
291 isl_int_set_si(v
, 1);
292 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
293 isl_int_set_si(v
, -5);
294 isl_constraint_set_constant(c
, v
);
295 bset
= isl_basic_set_add_constraint(bset
, c
);
297 isl_local_space_free(ls
);
298 isl_basic_set_free(bset
);
303 void test_dim(struct isl_ctx
*ctx
)
306 isl_map
*map1
, *map2
;
308 map1
= isl_map_read_from_str(ctx
,
309 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
310 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
311 map2
= isl_map_read_from_str(ctx
,
312 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
313 assert(isl_map_is_equal(map1
, map2
));
316 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
317 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
318 assert(isl_map_is_equal(map1
, map2
));
323 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
324 map1
= isl_map_read_from_str(ctx
, str
);
325 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
326 map2
= isl_map_read_from_str(ctx
, str
);
327 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
328 assert(isl_map_is_equal(map1
, map2
));
335 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
339 { &isl_val_neg
, "0", "0" },
340 { &isl_val_abs
, "0", "0" },
341 { &isl_val_2exp
, "0", "1" },
342 { &isl_val_floor
, "0", "0" },
343 { &isl_val_ceil
, "0", "0" },
344 { &isl_val_neg
, "1", "-1" },
345 { &isl_val_neg
, "-1", "1" },
346 { &isl_val_neg
, "1/2", "-1/2" },
347 { &isl_val_neg
, "-1/2", "1/2" },
348 { &isl_val_neg
, "infty", "-infty" },
349 { &isl_val_neg
, "-infty", "infty" },
350 { &isl_val_neg
, "NaN", "NaN" },
351 { &isl_val_abs
, "1", "1" },
352 { &isl_val_abs
, "-1", "1" },
353 { &isl_val_abs
, "1/2", "1/2" },
354 { &isl_val_abs
, "-1/2", "1/2" },
355 { &isl_val_abs
, "infty", "infty" },
356 { &isl_val_abs
, "-infty", "infty" },
357 { &isl_val_abs
, "NaN", "NaN" },
358 { &isl_val_floor
, "1", "1" },
359 { &isl_val_floor
, "-1", "-1" },
360 { &isl_val_floor
, "1/2", "0" },
361 { &isl_val_floor
, "-1/2", "-1" },
362 { &isl_val_floor
, "infty", "infty" },
363 { &isl_val_floor
, "-infty", "-infty" },
364 { &isl_val_floor
, "NaN", "NaN" },
365 { &isl_val_ceil
, "1", "1" },
366 { &isl_val_ceil
, "-1", "-1" },
367 { &isl_val_ceil
, "1/2", "1" },
368 { &isl_val_ceil
, "-1/2", "0" },
369 { &isl_val_ceil
, "infty", "infty" },
370 { &isl_val_ceil
, "-infty", "-infty" },
371 { &isl_val_ceil
, "NaN", "NaN" },
372 { &isl_val_2exp
, "-3", "1/8" },
373 { &isl_val_2exp
, "-1", "1/2" },
374 { &isl_val_2exp
, "1", "2" },
375 { &isl_val_2exp
, "2", "4" },
376 { &isl_val_2exp
, "3", "8" },
379 /* Perform some basic tests of unary operations on isl_val objects.
381 static int test_un_val(isl_ctx
*ctx
)
385 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
388 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
389 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
390 res
= isl_val_read_from_str(ctx
, val_un_tests
[i
].res
);
391 fn
= val_un_tests
[i
].op
;
393 if (isl_val_is_nan(res
))
394 ok
= isl_val_is_nan(v
);
396 ok
= isl_val_eq(v
, res
);
402 isl_die(ctx
, isl_error_unknown
,
403 "unexpected result", return -1);
410 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
411 __isl_take isl_val
*v2
);
413 ['+'] = { &isl_val_add
},
414 ['-'] = { &isl_val_sub
},
415 ['*'] = { &isl_val_mul
},
416 ['/'] = { &isl_val_div
},
417 ['g'] = { &isl_val_gcd
},
418 ['m'] = { &isl_val_min
},
419 ['M'] = { &isl_val_max
},
427 } val_bin_tests
[] = {
428 { "0", '+', "0", "0" },
429 { "1", '+', "0", "1" },
430 { "1", '+', "1", "2" },
431 { "1", '-', "1", "0" },
432 { "1", '*', "1", "1" },
433 { "1", '/', "1", "1" },
434 { "2", '*', "3", "6" },
435 { "2", '*', "1/2", "1" },
436 { "2", '*', "1/3", "2/3" },
437 { "2/3", '*', "3/5", "2/5" },
438 { "2/3", '*', "7/5", "14/15" },
439 { "2", '/', "1/2", "4" },
440 { "-2", '/', "-1/2", "4" },
441 { "-2", '/', "1/2", "-4" },
442 { "2", '/', "-1/2", "-4" },
443 { "2", '/', "2", "1" },
444 { "2", '/', "3", "2/3" },
445 { "2/3", '/', "5/3", "2/5" },
446 { "2/3", '/', "5/7", "14/15" },
447 { "0", '/', "0", "NaN" },
448 { "42", '/', "0", "NaN" },
449 { "-42", '/', "0", "NaN" },
450 { "infty", '/', "0", "NaN" },
451 { "-infty", '/', "0", "NaN" },
452 { "NaN", '/', "0", "NaN" },
453 { "0", '/', "NaN", "NaN" },
454 { "42", '/', "NaN", "NaN" },
455 { "-42", '/', "NaN", "NaN" },
456 { "infty", '/', "NaN", "NaN" },
457 { "-infty", '/', "NaN", "NaN" },
458 { "NaN", '/', "NaN", "NaN" },
459 { "0", '/', "infty", "0" },
460 { "42", '/', "infty", "0" },
461 { "-42", '/', "infty", "0" },
462 { "infty", '/', "infty", "NaN" },
463 { "-infty", '/', "infty", "NaN" },
464 { "NaN", '/', "infty", "NaN" },
465 { "0", '/', "-infty", "0" },
466 { "42", '/', "-infty", "0" },
467 { "-42", '/', "-infty", "0" },
468 { "infty", '/', "-infty", "NaN" },
469 { "-infty", '/', "-infty", "NaN" },
470 { "NaN", '/', "-infty", "NaN" },
471 { "1", '-', "1/3", "2/3" },
472 { "1/3", '+', "1/2", "5/6" },
473 { "1/2", '+', "1/2", "1" },
474 { "3/4", '-', "1/4", "1/2" },
475 { "1/2", '-', "1/3", "1/6" },
476 { "infty", '+', "42", "infty" },
477 { "infty", '+', "infty", "infty" },
478 { "42", '+', "infty", "infty" },
479 { "infty", '-', "infty", "NaN" },
480 { "infty", '*', "infty", "infty" },
481 { "infty", '*', "-infty", "-infty" },
482 { "-infty", '*', "infty", "-infty" },
483 { "-infty", '*', "-infty", "infty" },
484 { "0", '*', "infty", "NaN" },
485 { "1", '*', "infty", "infty" },
486 { "infty", '*', "0", "NaN" },
487 { "infty", '*', "42", "infty" },
488 { "42", '-', "infty", "-infty" },
489 { "infty", '+', "-infty", "NaN" },
490 { "4", 'g', "6", "2" },
491 { "5", 'g', "6", "1" },
492 { "42", 'm', "3", "3" },
493 { "42", 'M', "3", "42" },
494 { "3", 'm', "42", "3" },
495 { "3", 'M', "42", "42" },
496 { "42", 'm', "infty", "42" },
497 { "42", 'M', "infty", "infty" },
498 { "42", 'm', "-infty", "-infty" },
499 { "42", 'M', "-infty", "42" },
500 { "42", 'm', "NaN", "NaN" },
501 { "42", 'M', "NaN", "NaN" },
502 { "infty", 'm', "-infty", "-infty" },
503 { "infty", 'M', "-infty", "infty" },
506 /* Perform some basic tests of binary operations on isl_val objects.
508 static int test_bin_val(isl_ctx
*ctx
)
511 isl_val
*v1
, *v2
, *res
;
512 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
513 __isl_take isl_val
*v2
);
516 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
517 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
518 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
519 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
520 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
522 if (isl_val_is_nan(res
))
523 ok
= isl_val_is_nan(v1
);
525 ok
= isl_val_eq(v1
, res
);
531 isl_die(ctx
, isl_error_unknown
,
532 "unexpected result", return -1);
538 /* Perform some basic tests on isl_val objects.
540 static int test_val(isl_ctx
*ctx
)
542 if (test_un_val(ctx
) < 0)
544 if (test_bin_val(ctx
) < 0)
549 static int test_div(isl_ctx
*ctx
)
558 struct isl_basic_set
*bset
;
559 struct isl_constraint
*c
;
564 dim
= isl_space_set_alloc(ctx
, 0, 3);
565 bset
= isl_basic_set_universe(isl_space_copy(dim
));
566 ls
= isl_local_space_from_space(dim
);
568 c
= isl_equality_alloc(isl_local_space_copy(ls
));
569 isl_int_set_si(v
, -1);
570 isl_constraint_set_constant(c
, v
);
571 isl_int_set_si(v
, 1);
572 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
573 isl_int_set_si(v
, 3);
574 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
575 bset
= isl_basic_set_add_constraint(bset
, c
);
577 c
= isl_equality_alloc(isl_local_space_copy(ls
));
578 isl_int_set_si(v
, 1);
579 isl_constraint_set_constant(c
, v
);
580 isl_int_set_si(v
, -1);
581 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
582 isl_int_set_si(v
, 3);
583 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
584 bset
= isl_basic_set_add_constraint(bset
, c
);
586 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
588 assert(bset
&& bset
->n_div
== 1);
589 isl_local_space_free(ls
);
590 isl_basic_set_free(bset
);
593 dim
= isl_space_set_alloc(ctx
, 0, 3);
594 bset
= isl_basic_set_universe(isl_space_copy(dim
));
595 ls
= isl_local_space_from_space(dim
);
597 c
= isl_equality_alloc(isl_local_space_copy(ls
));
598 isl_int_set_si(v
, 1);
599 isl_constraint_set_constant(c
, v
);
600 isl_int_set_si(v
, -1);
601 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
602 isl_int_set_si(v
, 3);
603 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
604 bset
= isl_basic_set_add_constraint(bset
, c
);
606 c
= isl_equality_alloc(isl_local_space_copy(ls
));
607 isl_int_set_si(v
, -1);
608 isl_constraint_set_constant(c
, v
);
609 isl_int_set_si(v
, 1);
610 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
611 isl_int_set_si(v
, 3);
612 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
613 bset
= isl_basic_set_add_constraint(bset
, c
);
615 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
617 assert(bset
&& bset
->n_div
== 1);
618 isl_local_space_free(ls
);
619 isl_basic_set_free(bset
);
622 dim
= isl_space_set_alloc(ctx
, 0, 3);
623 bset
= isl_basic_set_universe(isl_space_copy(dim
));
624 ls
= isl_local_space_from_space(dim
);
626 c
= isl_equality_alloc(isl_local_space_copy(ls
));
627 isl_int_set_si(v
, 1);
628 isl_constraint_set_constant(c
, v
);
629 isl_int_set_si(v
, -1);
630 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
631 isl_int_set_si(v
, 3);
632 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
633 bset
= isl_basic_set_add_constraint(bset
, c
);
635 c
= isl_equality_alloc(isl_local_space_copy(ls
));
636 isl_int_set_si(v
, -3);
637 isl_constraint_set_constant(c
, v
);
638 isl_int_set_si(v
, 1);
639 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
640 isl_int_set_si(v
, 4);
641 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
642 bset
= isl_basic_set_add_constraint(bset
, c
);
644 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
646 assert(bset
&& bset
->n_div
== 1);
647 isl_local_space_free(ls
);
648 isl_basic_set_free(bset
);
651 dim
= isl_space_set_alloc(ctx
, 0, 3);
652 bset
= isl_basic_set_universe(isl_space_copy(dim
));
653 ls
= isl_local_space_from_space(dim
);
655 c
= isl_equality_alloc(isl_local_space_copy(ls
));
656 isl_int_set_si(v
, 2);
657 isl_constraint_set_constant(c
, v
);
658 isl_int_set_si(v
, -1);
659 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
660 isl_int_set_si(v
, 3);
661 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
662 bset
= isl_basic_set_add_constraint(bset
, c
);
664 c
= isl_equality_alloc(isl_local_space_copy(ls
));
665 isl_int_set_si(v
, -1);
666 isl_constraint_set_constant(c
, v
);
667 isl_int_set_si(v
, 1);
668 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
669 isl_int_set_si(v
, 6);
670 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
671 bset
= isl_basic_set_add_constraint(bset
, c
);
673 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
675 assert(isl_basic_set_is_empty(bset
));
676 isl_local_space_free(ls
);
677 isl_basic_set_free(bset
);
680 dim
= isl_space_set_alloc(ctx
, 0, 3);
681 bset
= isl_basic_set_universe(isl_space_copy(dim
));
682 ls
= isl_local_space_from_space(dim
);
684 c
= isl_equality_alloc(isl_local_space_copy(ls
));
685 isl_int_set_si(v
, -1);
686 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
687 isl_int_set_si(v
, 3);
688 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
689 bset
= isl_basic_set_add_constraint(bset
, c
);
691 c
= isl_equality_alloc(isl_local_space_copy(ls
));
692 isl_int_set_si(v
, 1);
693 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
694 isl_int_set_si(v
, -3);
695 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
696 bset
= isl_basic_set_add_constraint(bset
, c
);
698 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
700 assert(bset
&& bset
->n_div
== 0);
701 isl_basic_set_free(bset
);
702 isl_local_space_free(ls
);
705 dim
= isl_space_set_alloc(ctx
, 0, 3);
706 bset
= isl_basic_set_universe(isl_space_copy(dim
));
707 ls
= isl_local_space_from_space(dim
);
709 c
= isl_equality_alloc(isl_local_space_copy(ls
));
710 isl_int_set_si(v
, -1);
711 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
712 isl_int_set_si(v
, 6);
713 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
714 bset
= isl_basic_set_add_constraint(bset
, c
);
716 c
= isl_equality_alloc(isl_local_space_copy(ls
));
717 isl_int_set_si(v
, 1);
718 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
719 isl_int_set_si(v
, -3);
720 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
721 bset
= isl_basic_set_add_constraint(bset
, c
);
723 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
725 assert(bset
&& bset
->n_div
== 1);
726 isl_basic_set_free(bset
);
727 isl_local_space_free(ls
);
730 /* This test is a bit tricky. We set up an equality
732 * Normalization of divs creates _two_ divs
735 * Afterwards e0 is removed again because it has coefficient -1
736 * and we end up with the original equality and div again.
737 * Perhaps we can avoid the introduction of this temporary div.
739 dim
= isl_space_set_alloc(ctx
, 0, 4);
740 bset
= isl_basic_set_universe(isl_space_copy(dim
));
741 ls
= isl_local_space_from_space(dim
);
743 c
= isl_equality_alloc(isl_local_space_copy(ls
));
744 isl_int_set_si(v
, -1);
745 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
746 isl_int_set_si(v
, -3);
747 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
748 isl_int_set_si(v
, -3);
749 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
750 isl_int_set_si(v
, 6);
751 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
752 bset
= isl_basic_set_add_constraint(bset
, c
);
754 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
756 /* Test disabled for now */
758 assert(bset && bset->n_div == 1);
760 isl_local_space_free(ls
);
761 isl_basic_set_free(bset
);
764 dim
= isl_space_set_alloc(ctx
, 0, 5);
765 bset
= isl_basic_set_universe(isl_space_copy(dim
));
766 ls
= isl_local_space_from_space(dim
);
768 c
= isl_equality_alloc(isl_local_space_copy(ls
));
769 isl_int_set_si(v
, -1);
770 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
771 isl_int_set_si(v
, -3);
772 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
773 isl_int_set_si(v
, -3);
774 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
775 isl_int_set_si(v
, 6);
776 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
777 bset
= isl_basic_set_add_constraint(bset
, c
);
779 c
= isl_equality_alloc(isl_local_space_copy(ls
));
780 isl_int_set_si(v
, -1);
781 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
782 isl_int_set_si(v
, 1);
783 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
784 isl_int_set_si(v
, 1);
785 isl_constraint_set_constant(c
, v
);
786 bset
= isl_basic_set_add_constraint(bset
, c
);
788 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
790 /* Test disabled for now */
792 assert(bset && bset->n_div == 1);
794 isl_local_space_free(ls
);
795 isl_basic_set_free(bset
);
798 dim
= isl_space_set_alloc(ctx
, 0, 4);
799 bset
= isl_basic_set_universe(isl_space_copy(dim
));
800 ls
= isl_local_space_from_space(dim
);
802 c
= isl_equality_alloc(isl_local_space_copy(ls
));
803 isl_int_set_si(v
, 1);
804 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
805 isl_int_set_si(v
, -1);
806 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
807 isl_int_set_si(v
, -2);
808 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
809 bset
= isl_basic_set_add_constraint(bset
, c
);
811 c
= isl_equality_alloc(isl_local_space_copy(ls
));
812 isl_int_set_si(v
, -1);
813 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
814 isl_int_set_si(v
, 3);
815 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
816 isl_int_set_si(v
, 2);
817 isl_constraint_set_constant(c
, v
);
818 bset
= isl_basic_set_add_constraint(bset
, c
);
820 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
822 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
824 assert(!isl_basic_set_is_empty(bset
));
826 isl_local_space_free(ls
);
827 isl_basic_set_free(bset
);
830 dim
= isl_space_set_alloc(ctx
, 0, 3);
831 bset
= isl_basic_set_universe(isl_space_copy(dim
));
832 ls
= isl_local_space_from_space(dim
);
834 c
= isl_equality_alloc(isl_local_space_copy(ls
));
835 isl_int_set_si(v
, 1);
836 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, 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 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
843 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
845 isl_local_space_free(ls
);
846 isl_basic_set_free(bset
);
850 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
851 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
852 set
= isl_set_read_from_str(ctx
, str
);
853 set
= isl_set_compute_divs(set
);
858 str
= "{ [i,j] : 2*[i/2] + 3 * [j/4] <= 10 and 2 i = j }";
859 bset
= isl_basic_set_read_from_str(ctx
, str
);
860 n
= isl_basic_set_dim(bset
, isl_dim_div
);
861 isl_basic_set_free(bset
);
865 isl_die(ctx
, isl_error_unknown
,
866 "expecting no existentials", return -1);
868 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
869 set
= isl_set_read_from_str(ctx
, str
);
870 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
871 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
872 empty
= isl_set_is_empty(set
);
877 isl_die(ctx
, isl_error_unknown
,
878 "result not as accurate as expected", return -1);
883 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
887 struct isl_basic_set
*bset1
, *bset2
;
888 struct isl_basic_map
*bmap
;
890 filename
= get_filename(ctx
, name
, "omega");
892 input
= fopen(filename
, "r");
895 bset1
= isl_basic_set_read_from_file(ctx
, input
);
896 bmap
= isl_basic_map_read_from_file(ctx
, input
);
898 bset1
= isl_basic_set_apply(bset1
, bmap
);
900 bset2
= isl_basic_set_read_from_file(ctx
, input
);
902 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
904 isl_basic_set_free(bset1
);
905 isl_basic_set_free(bset2
);
911 void test_application(struct isl_ctx
*ctx
)
913 test_application_case(ctx
, "application");
914 test_application_case(ctx
, "application2");
917 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
921 struct isl_basic_set
*bset1
, *bset2
;
923 filename
= get_filename(ctx
, name
, "polylib");
925 input
= fopen(filename
, "r");
928 bset1
= isl_basic_set_read_from_file(ctx
, input
);
929 bset2
= isl_basic_set_read_from_file(ctx
, input
);
931 bset1
= isl_basic_set_affine_hull(bset1
);
933 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
935 isl_basic_set_free(bset1
);
936 isl_basic_set_free(bset2
);
942 int test_affine_hull(struct isl_ctx
*ctx
)
946 isl_basic_set
*bset
, *bset2
;
950 test_affine_hull_case(ctx
, "affine2");
951 test_affine_hull_case(ctx
, "affine");
952 test_affine_hull_case(ctx
, "affine3");
954 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
955 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
956 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
957 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
958 set
= isl_set_read_from_str(ctx
, str
);
959 bset
= isl_set_affine_hull(set
);
960 n
= isl_basic_set_dim(bset
, isl_dim_div
);
961 isl_basic_set_free(bset
);
963 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
966 /* Check that isl_map_affine_hull is not confused by
967 * the reordering of divs in isl_map_align_divs.
969 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
970 "32e0 = b and 32e1 = c); "
971 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
972 set
= isl_set_read_from_str(ctx
, str
);
973 bset
= isl_set_affine_hull(set
);
974 isl_basic_set_free(bset
);
978 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
979 "32e2 = 31 + 31e0 }";
980 set
= isl_set_read_from_str(ctx
, str
);
981 bset
= isl_set_affine_hull(set
);
982 str
= "{ [a] : exists e : a = 32 e }";
983 bset2
= isl_basic_set_read_from_str(ctx
, str
);
984 subset
= isl_basic_set_is_subset(bset
, bset2
);
985 isl_basic_set_free(bset
);
986 isl_basic_set_free(bset2
);
990 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
996 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1000 struct isl_basic_set
*bset1
, *bset2
;
1001 struct isl_set
*set
;
1003 filename
= get_filename(ctx
, name
, "polylib");
1005 input
= fopen(filename
, "r");
1008 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1009 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1011 set
= isl_basic_set_union(bset1
, bset2
);
1012 bset1
= isl_set_convex_hull(set
);
1014 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1016 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1018 isl_basic_set_free(bset1
);
1019 isl_basic_set_free(bset2
);
1025 void test_convex_hull_algo(struct isl_ctx
*ctx
, int convex
)
1027 const char *str1
, *str2
;
1028 isl_set
*set1
, *set2
;
1029 int orig_convex
= ctx
->opt
->convex
;
1030 ctx
->opt
->convex
= convex
;
1032 test_convex_hull_case(ctx
, "convex0");
1033 test_convex_hull_case(ctx
, "convex1");
1034 test_convex_hull_case(ctx
, "convex2");
1035 test_convex_hull_case(ctx
, "convex3");
1036 test_convex_hull_case(ctx
, "convex4");
1037 test_convex_hull_case(ctx
, "convex5");
1038 test_convex_hull_case(ctx
, "convex6");
1039 test_convex_hull_case(ctx
, "convex7");
1040 test_convex_hull_case(ctx
, "convex8");
1041 test_convex_hull_case(ctx
, "convex9");
1042 test_convex_hull_case(ctx
, "convex10");
1043 test_convex_hull_case(ctx
, "convex11");
1044 test_convex_hull_case(ctx
, "convex12");
1045 test_convex_hull_case(ctx
, "convex13");
1046 test_convex_hull_case(ctx
, "convex14");
1047 test_convex_hull_case(ctx
, "convex15");
1049 str1
= "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1050 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1051 "(i0 = 0 and i1 = 0 and i2 = 0) }";
1052 str2
= "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
1053 set1
= isl_set_read_from_str(ctx
, str1
);
1054 set2
= isl_set_read_from_str(ctx
, str2
);
1055 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1056 assert(isl_set_is_equal(set1
, set2
));
1060 ctx
->opt
->convex
= orig_convex
;
1063 void test_convex_hull(struct isl_ctx
*ctx
)
1065 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
);
1066 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
);
1069 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1073 struct isl_basic_set
*bset1
, *bset2
;
1075 filename
= get_filename(ctx
, name
, "polylib");
1077 input
= fopen(filename
, "r");
1080 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1081 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1083 bset1
= isl_basic_set_gist(bset1
, bset2
);
1085 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1087 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1089 isl_basic_set_free(bset1
);
1090 isl_basic_set_free(bset2
);
1096 static int test_gist(struct isl_ctx
*ctx
)
1099 isl_basic_set
*bset1
, *bset2
;
1100 isl_map
*map1
, *map2
;
1102 test_gist_case(ctx
, "gist1");
1104 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1105 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1106 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1107 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1108 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1109 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1110 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1111 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1112 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1113 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1114 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1115 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1116 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1117 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1118 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1119 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1120 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1121 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1122 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1123 bset1
= isl_basic_set_gist(bset1
, bset2
);
1124 assert(bset1
&& bset1
->n_div
== 0);
1125 isl_basic_set_free(bset1
);
1127 /* Check that the integer divisions of the second disjunct
1128 * do not spread to the first disjunct.
1130 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1131 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1132 "(exists (e0 = [(-1 + t1)/16], "
1133 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1134 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1135 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1136 "o0 <= 4294967295 and t1 <= -1)) }";
1137 map1
= isl_map_read_from_str(ctx
, str
);
1138 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1139 map2
= isl_map_read_from_str(ctx
, str
);
1140 map1
= isl_map_gist(map1
, map2
);
1144 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1145 isl_map_free(map1
); return -1);
1146 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1147 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1148 isl_map_free(map1
); return -1);
1154 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1156 isl_set
*set
, *set2
;
1160 set
= isl_set_read_from_str(ctx
, str
);
1161 set
= isl_set_coalesce(set
);
1162 set2
= isl_set_read_from_str(ctx
, str
);
1163 equal
= isl_set_is_equal(set
, set2
);
1164 one
= set
&& set
->n
== 1;
1171 isl_die(ctx
, isl_error_unknown
,
1172 "coalesced set not equal to input", return -1);
1173 if (check_one
&& !one
)
1174 isl_die(ctx
, isl_error_unknown
,
1175 "coalesced set should not be a union", return -1);
1180 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1185 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1186 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1188 if (test_coalesce_set(ctx
,
1189 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1190 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1191 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1192 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1193 "-10 <= y <= 0}", 1) < 0)
1195 if (test_coalesce_set(ctx
,
1196 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1) < 0)
1198 if (test_coalesce_set(ctx
,
1199 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1) < 0)
1207 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1212 /* Inputs for coalescing tests.
1213 * "str" is a string representation of the input set.
1214 * "single_disjunct" is set if we expect the result to consist of
1215 * a single disjunct.
1218 int single_disjunct
;
1220 } coalesce_tests
[] = {
1221 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1222 "y >= x & x >= 2 & 5 >= y }" },
1223 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1224 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1225 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1226 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1227 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1228 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1229 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1230 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1231 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1232 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1233 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1234 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1235 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1236 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1237 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1238 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1239 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1240 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1241 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1242 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1243 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1244 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1245 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1246 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1247 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1248 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1249 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1250 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1251 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1252 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1253 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1254 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1255 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1256 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1257 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1258 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1259 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1260 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1261 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1262 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1263 "[o0, o1, o2, o3, o4, o5, o6]] : "
1264 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1265 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1266 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1267 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1268 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1269 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1270 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1271 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1272 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1273 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1274 "o6 >= i3 + i6 - o3 and M >= 0 and "
1275 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1276 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1277 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1278 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1279 "(o0 = 0 and M >= 2 and N >= 3) or "
1280 "(M = 0 and o0 = 0 and N >= 3) }" },
1281 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1282 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1283 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1284 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1285 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1286 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1287 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1288 "(y = 3 and x = 1) }" },
1289 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1290 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1291 "i1 <= M and i3 <= M and i4 <= M) or "
1292 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1293 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1294 "i4 <= -1 + M) }" },
1295 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1296 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1297 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1298 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1299 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1300 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1301 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1302 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1303 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1304 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1305 { 0, "{ [a, b] : exists e : 2e = a and "
1306 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1307 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1308 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1309 "j >= 1 and j' <= i + j - i' and i >= 1; "
1311 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1312 "[i,j] : exists a : j = 3a }" },
1313 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1314 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1316 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1317 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1318 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1319 "c <= 6 + 8a and a >= 3; "
1320 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1321 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1322 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1323 "[x,0] : 3 <= x <= 4 }" },
1324 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1325 "[x,0] : 4 <= x <= 5 }" },
1326 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1327 "[x,0] : 3 <= x <= 5 }" },
1328 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1329 "[x,0] : 3 <= x <= 4 }" },
1330 { 1 , "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1332 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1335 /* Test the functionality of isl_set_coalesce.
1336 * That is, check that the output is always equal to the input
1337 * and in some cases that the result consists of a single disjunct.
1339 static int test_coalesce(struct isl_ctx
*ctx
)
1343 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
1344 const char *str
= coalesce_tests
[i
].str
;
1345 int check_one
= coalesce_tests
[i
].single_disjunct
;
1346 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
1350 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
1356 void test_closure(struct isl_ctx
*ctx
)
1360 isl_map
*up
, *right
;
1361 isl_map
*map
, *map2
;
1364 /* COCOA example 1 */
1365 map
= isl_map_read_from_str(ctx
,
1366 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1367 "1 <= i and i < n and 1 <= j and j < n or "
1368 "i2 = i + 1 and j2 = j - 1 and "
1369 "1 <= i and i < n and 2 <= j and j <= n }");
1370 map
= isl_map_power(map
, &exact
);
1374 /* COCOA example 1 */
1375 map
= isl_map_read_from_str(ctx
,
1376 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1377 "1 <= i and i < n and 1 <= j and j < n or "
1378 "i2 = i + 1 and j2 = j - 1 and "
1379 "1 <= i and i < n and 2 <= j and j <= n }");
1380 map
= isl_map_transitive_closure(map
, &exact
);
1382 map2
= isl_map_read_from_str(ctx
,
1383 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1384 "1 <= i and i < n and 1 <= j and j <= n and "
1385 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1386 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1387 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1388 assert(isl_map_is_equal(map
, map2
));
1392 map
= isl_map_read_from_str(ctx
,
1393 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1394 " 0 <= y and y <= n }");
1395 map
= isl_map_transitive_closure(map
, &exact
);
1396 map2
= isl_map_read_from_str(ctx
,
1397 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1398 " 0 <= y and y <= n }");
1399 assert(isl_map_is_equal(map
, map2
));
1403 /* COCOA example 2 */
1404 map
= isl_map_read_from_str(ctx
,
1405 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1406 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1407 "i2 = i + 2 and j2 = j - 2 and "
1408 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1409 map
= isl_map_transitive_closure(map
, &exact
);
1411 map2
= isl_map_read_from_str(ctx
,
1412 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1413 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1414 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1415 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1416 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1417 assert(isl_map_is_equal(map
, map2
));
1421 /* COCOA Fig.2 left */
1422 map
= isl_map_read_from_str(ctx
,
1423 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1424 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1426 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1427 "j <= 2 i - 3 and j <= n - 2 or "
1428 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1429 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1430 map
= isl_map_transitive_closure(map
, &exact
);
1434 /* COCOA Fig.2 right */
1435 map
= isl_map_read_from_str(ctx
,
1436 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1437 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1439 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1440 "j <= 2 i - 4 and j <= n - 3 or "
1441 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1442 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1443 map
= isl_map_power(map
, &exact
);
1447 /* COCOA Fig.2 right */
1448 map
= isl_map_read_from_str(ctx
,
1449 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1450 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1452 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1453 "j <= 2 i - 4 and j <= n - 3 or "
1454 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1455 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1456 map
= isl_map_transitive_closure(map
, &exact
);
1458 map2
= isl_map_read_from_str(ctx
,
1459 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1460 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1461 "j <= n and 3 + i + 2 j <= 3 n and "
1462 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1463 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1464 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1465 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1466 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1467 assert(isl_map_is_equal(map
, map2
));
1471 /* COCOA Fig.1 right */
1472 dom
= isl_set_read_from_str(ctx
,
1473 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1474 "2 x - 3 y + 3 >= 0 }");
1475 right
= isl_map_read_from_str(ctx
,
1476 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1477 up
= isl_map_read_from_str(ctx
,
1478 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1479 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1480 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1481 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1482 up
= isl_map_intersect_range(up
, dom
);
1483 map
= isl_map_union(up
, right
);
1484 map
= isl_map_transitive_closure(map
, &exact
);
1486 map2
= isl_map_read_from_str(ctx
,
1487 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1488 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1489 assert(isl_map_is_equal(map
, map2
));
1493 /* COCOA Theorem 1 counter example */
1494 map
= isl_map_read_from_str(ctx
,
1495 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1496 "i2 = 1 and j2 = j or "
1497 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1498 map
= isl_map_transitive_closure(map
, &exact
);
1502 map
= isl_map_read_from_str(ctx
,
1503 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1504 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1505 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1506 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1507 map
= isl_map_transitive_closure(map
, &exact
);
1511 /* Kelly et al 1996, fig 12 */
1512 map
= isl_map_read_from_str(ctx
,
1513 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1514 "1 <= i,j,j+1 <= n or "
1515 "j = n and j2 = 1 and i2 = i + 1 and "
1516 "1 <= i,i+1 <= n }");
1517 map
= isl_map_transitive_closure(map
, &exact
);
1519 map2
= isl_map_read_from_str(ctx
,
1520 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1521 "1 <= i <= n and i = i2 or "
1522 "1 <= i < i2 <= n and 1 <= j <= n and "
1524 assert(isl_map_is_equal(map
, map2
));
1528 /* Omega's closure4 */
1529 map
= isl_map_read_from_str(ctx
,
1530 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1531 "1 <= x,y <= 10 or "
1532 "x2 = x + 1 and y2 = y and "
1533 "1 <= x <= 20 && 5 <= y <= 15 }");
1534 map
= isl_map_transitive_closure(map
, &exact
);
1538 map
= isl_map_read_from_str(ctx
,
1539 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1540 map
= isl_map_transitive_closure(map
, &exact
);
1542 map2
= isl_map_read_from_str(ctx
,
1543 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1544 assert(isl_map_is_equal(map
, map2
));
1548 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1549 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1550 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1551 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1552 map
= isl_map_read_from_str(ctx
, str
);
1553 map
= isl_map_transitive_closure(map
, &exact
);
1555 map2
= isl_map_read_from_str(ctx
, str
);
1556 assert(isl_map_is_equal(map
, map2
));
1560 str
= "{[0] -> [1]; [2] -> [3]}";
1561 map
= isl_map_read_from_str(ctx
, str
);
1562 map
= isl_map_transitive_closure(map
, &exact
);
1564 map2
= isl_map_read_from_str(ctx
, str
);
1565 assert(isl_map_is_equal(map
, map2
));
1569 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1570 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1571 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1572 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1573 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1574 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1575 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1576 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1577 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1578 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1579 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1580 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1581 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1582 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1583 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1584 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1585 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1586 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1587 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1588 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1589 map
= isl_map_read_from_str(ctx
, str
);
1590 map
= isl_map_transitive_closure(map
, NULL
);
1595 void test_lex(struct isl_ctx
*ctx
)
1600 dim
= isl_space_set_alloc(ctx
, 0, 0);
1601 map
= isl_map_lex_le(dim
);
1602 assert(!isl_map_is_empty(map
));
1606 static int test_lexmin(struct isl_ctx
*ctx
)
1610 isl_basic_map
*bmap
;
1611 isl_map
*map
, *map2
;
1614 isl_pw_multi_aff
*pma
;
1616 str
= "[p0, p1] -> { [] -> [] : "
1617 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1618 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1619 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1620 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1621 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1622 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1623 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1624 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1625 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1626 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1627 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1628 map
= isl_map_read_from_str(ctx
, str
);
1629 map
= isl_map_lexmin(map
);
1632 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1633 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1634 set
= isl_set_read_from_str(ctx
, str
);
1635 set
= isl_set_lexmax(set
);
1636 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1637 set2
= isl_set_read_from_str(ctx
, str
);
1638 set
= isl_set_intersect(set
, set2
);
1639 assert(!isl_set_is_empty(set
));
1642 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1643 map
= isl_map_read_from_str(ctx
, str
);
1644 map
= isl_map_lexmin(map
);
1645 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1646 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1647 map2
= isl_map_read_from_str(ctx
, str
);
1648 assert(isl_map_is_equal(map
, map2
));
1652 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1653 map
= isl_map_read_from_str(ctx
, str
);
1654 map2
= isl_map_copy(map
);
1655 map
= isl_map_lexmin(map
);
1656 assert(isl_map_is_equal(map
, map2
));
1660 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1661 map
= isl_map_read_from_str(ctx
, str
);
1662 map
= isl_map_lexmin(map
);
1663 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1664 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1665 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1666 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1667 map2
= isl_map_read_from_str(ctx
, str
);
1668 assert(isl_map_is_equal(map
, map2
));
1672 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1673 " 8i' <= i and 8i' >= -7 + i }";
1674 bmap
= isl_basic_map_read_from_str(ctx
, str
);
1675 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
1676 map2
= isl_map_from_pw_multi_aff(pma
);
1677 map
= isl_map_from_basic_map(bmap
);
1678 assert(isl_map_is_equal(map
, map2
));
1682 str
= "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1683 map
= isl_map_read_from_str(ctx
, str
);
1684 map
= isl_map_lexmin(map
);
1685 str
= "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1686 map2
= isl_map_read_from_str(ctx
, str
);
1687 assert(isl_map_is_equal(map
, map2
));
1691 /* Check that empty pieces are properly combined. */
1692 str
= "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
1693 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
1694 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }";
1695 map
= isl_map_read_from_str(ctx
, str
);
1696 map
= isl_map_lexmin(map
);
1697 str
= "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
1698 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
1700 map2
= isl_map_read_from_str(ctx
, str
);
1701 assert(isl_map_is_equal(map
, map2
));
1705 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1706 " 8i' <= i and 8i' >= -7 + i }";
1707 set
= isl_set_read_from_str(ctx
, str
);
1708 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
1709 set2
= isl_set_from_pw_multi_aff(pma
);
1710 equal
= isl_set_is_equal(set
, set2
);
1716 isl_die(ctx
, isl_error_unknown
,
1717 "unexpected difference between set and "
1718 "piecewise affine expression", return -1);
1728 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1729 void *dep_user
, void *user
)
1731 struct must_may
*mm
= (struct must_may
*)user
;
1734 mm
->must
= isl_map_union(mm
->must
, dep
);
1736 mm
->may
= isl_map_union(mm
->may
, dep
);
1741 static int common_space(void *first
, void *second
)
1743 int depth
= *(int *)first
;
1747 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1755 map2
= isl_map_read_from_str(map
->ctx
, str
);
1756 equal
= isl_map_is_equal(map
, map2
);
1762 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
1766 equal
= map_is_equal(map
, str
);
1770 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
1771 "result not as expected", return -1);
1775 void test_dep(struct isl_ctx
*ctx
)
1780 isl_access_info
*ai
;
1787 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1788 map
= isl_map_read_from_str(ctx
, str
);
1789 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1791 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1792 map
= isl_map_read_from_str(ctx
, str
);
1793 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1795 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1796 map
= isl_map_read_from_str(ctx
, str
);
1797 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1799 flow
= isl_access_info_compute_flow(ai
);
1800 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1801 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1802 mm
.may
= isl_map_empty(dim
);
1804 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1806 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1807 " [1,10,0] -> [2,5,0] }";
1808 assert(map_is_equal(mm
.must
, str
));
1809 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1810 assert(map_is_equal(mm
.may
, str
));
1812 isl_map_free(mm
.must
);
1813 isl_map_free(mm
.may
);
1814 isl_flow_free(flow
);
1817 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1818 map
= isl_map_read_from_str(ctx
, str
);
1819 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1821 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1822 map
= isl_map_read_from_str(ctx
, str
);
1823 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1825 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1826 map
= isl_map_read_from_str(ctx
, str
);
1827 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1829 flow
= isl_access_info_compute_flow(ai
);
1830 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1831 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1832 mm
.may
= isl_map_empty(dim
);
1834 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1836 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1837 assert(map_is_equal(mm
.must
, str
));
1838 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1839 assert(map_is_equal(mm
.may
, str
));
1841 isl_map_free(mm
.must
);
1842 isl_map_free(mm
.may
);
1843 isl_flow_free(flow
);
1846 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1847 map
= isl_map_read_from_str(ctx
, str
);
1848 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1850 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1851 map
= isl_map_read_from_str(ctx
, str
);
1852 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1854 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1855 map
= isl_map_read_from_str(ctx
, str
);
1856 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1858 flow
= isl_access_info_compute_flow(ai
);
1859 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1860 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1861 mm
.may
= isl_map_empty(dim
);
1863 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1865 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1866 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1867 assert(map_is_equal(mm
.may
, str
));
1868 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1869 assert(map_is_equal(mm
.must
, str
));
1871 isl_map_free(mm
.must
);
1872 isl_map_free(mm
.may
);
1873 isl_flow_free(flow
);
1876 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1877 map
= isl_map_read_from_str(ctx
, str
);
1878 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1880 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1881 map
= isl_map_read_from_str(ctx
, str
);
1882 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1884 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1885 map
= isl_map_read_from_str(ctx
, str
);
1886 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1888 flow
= isl_access_info_compute_flow(ai
);
1889 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1890 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1891 mm
.may
= isl_map_empty(dim
);
1893 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1895 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1896 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1897 assert(map_is_equal(mm
.may
, str
));
1898 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1899 assert(map_is_equal(mm
.must
, str
));
1901 isl_map_free(mm
.must
);
1902 isl_map_free(mm
.may
);
1903 isl_flow_free(flow
);
1906 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1907 map
= isl_map_read_from_str(ctx
, str
);
1908 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1910 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1911 map
= isl_map_read_from_str(ctx
, str
);
1912 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1914 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1915 map
= isl_map_read_from_str(ctx
, str
);
1916 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1918 flow
= isl_access_info_compute_flow(ai
);
1919 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1920 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1921 mm
.may
= isl_map_empty(dim
);
1923 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1925 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1926 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1927 assert(map_is_equal(mm
.may
, str
));
1928 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1929 assert(map_is_equal(mm
.must
, str
));
1931 isl_map_free(mm
.must
);
1932 isl_map_free(mm
.may
);
1933 isl_flow_free(flow
);
1938 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1939 map
= isl_map_read_from_str(ctx
, str
);
1940 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
1942 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1943 map
= isl_map_read_from_str(ctx
, str
);
1944 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1946 flow
= isl_access_info_compute_flow(ai
);
1947 dim
= isl_space_alloc(ctx
, 0, 5, 5);
1948 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1949 mm
.may
= isl_map_empty(dim
);
1951 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1953 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1954 assert(map_is_equal(mm
.must
, str
));
1955 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1956 assert(map_is_equal(mm
.may
, str
));
1958 isl_map_free(mm
.must
);
1959 isl_map_free(mm
.may
);
1960 isl_flow_free(flow
);
1963 int test_sv(isl_ctx
*ctx
)
1967 isl_union_map
*umap
;
1970 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1971 map
= isl_map_read_from_str(ctx
, str
);
1972 sv
= isl_map_is_single_valued(map
);
1977 isl_die(ctx
, isl_error_internal
,
1978 "map not detected as single valued", return -1);
1980 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1981 map
= isl_map_read_from_str(ctx
, str
);
1982 sv
= isl_map_is_single_valued(map
);
1987 isl_die(ctx
, isl_error_internal
,
1988 "map detected as single valued", return -1);
1990 str
= "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }";
1991 umap
= isl_union_map_read_from_str(ctx
, str
);
1992 sv
= isl_union_map_is_single_valued(umap
);
1993 isl_union_map_free(umap
);
1997 isl_die(ctx
, isl_error_internal
,
1998 "map not detected as single valued", return -1);
2000 str
= "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }";
2001 umap
= isl_union_map_read_from_str(ctx
, str
);
2002 sv
= isl_union_map_is_single_valued(umap
);
2003 isl_union_map_free(umap
);
2007 isl_die(ctx
, isl_error_internal
,
2008 "map detected as single valued", return -1);
2013 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
2017 map
= isl_map_read_from_str(ctx
, str
);
2019 assert(isl_map_is_bijective(map
));
2021 assert(!isl_map_is_bijective(map
));
2025 void test_bijective(struct isl_ctx
*ctx
)
2027 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
2028 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
2029 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
2030 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
2031 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
2032 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
2033 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
2034 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
2035 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
2036 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
2037 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
2038 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
2039 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
2042 static int test_pwqp(struct isl_ctx
*ctx
)
2046 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
2049 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2050 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2052 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
2055 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2056 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2058 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2060 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2062 isl_pw_qpolynomial_free(pwqp1
);
2064 str
= "{ [i] -> i }";
2065 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2066 str
= "{ [k] : exists a : k = 2a }";
2067 set
= isl_set_read_from_str(ctx
, str
);
2068 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2069 str
= "{ [i] -> i }";
2070 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2072 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2074 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2076 isl_pw_qpolynomial_free(pwqp1
);
2078 str
= "{ [i] -> i + [ (i + [i/3])/2 ] }";
2079 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2081 set
= isl_set_read_from_str(ctx
, str
);
2082 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2083 str
= "{ [i] -> 16 }";
2084 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2086 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2088 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2090 isl_pw_qpolynomial_free(pwqp1
);
2092 str
= "{ [i] -> ([(i)/2]) }";
2093 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2094 str
= "{ [k] : exists a : k = 2a+1 }";
2095 set
= isl_set_read_from_str(ctx
, str
);
2096 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2097 str
= "{ [i] -> -1/2 + 1/2 * i }";
2098 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2100 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2102 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2104 isl_pw_qpolynomial_free(pwqp1
);
2106 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
2107 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2108 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
2109 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2111 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2113 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2115 isl_pw_qpolynomial_free(pwqp1
);
2117 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
2118 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2119 str
= "{ [x] -> x }";
2120 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2122 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2124 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2126 isl_pw_qpolynomial_free(pwqp1
);
2128 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
2129 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2130 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2131 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
2132 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2133 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2134 isl_pw_qpolynomial_free(pwqp1
);
2136 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
2137 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2138 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2139 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2140 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
2141 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
2142 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2143 isl_pw_qpolynomial_free(pwqp1
);
2144 isl_pw_qpolynomial_free(pwqp2
);
2148 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2150 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
2151 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2152 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2153 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2154 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
2156 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2157 isl_pw_qpolynomial_free(pwqp1
);
2158 isl_pw_qpolynomial_free(pwqp2
);
2162 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2167 void test_split_periods(isl_ctx
*ctx
)
2170 isl_pw_qpolynomial
*pwqp
;
2172 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
2173 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
2174 "U >= 0; [U,V] -> U^2 : U >= 100 }";
2175 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2177 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
2180 isl_pw_qpolynomial_free(pwqp
);
2183 void test_union(isl_ctx
*ctx
)
2186 isl_union_set
*uset1
, *uset2
;
2187 isl_union_map
*umap1
, *umap2
;
2189 str
= "{ [i] : 0 <= i <= 1 }";
2190 uset1
= isl_union_set_read_from_str(ctx
, str
);
2191 str
= "{ [1] -> [0] }";
2192 umap1
= isl_union_map_read_from_str(ctx
, str
);
2194 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
2195 assert(isl_union_map_is_equal(umap1
, umap2
));
2197 isl_union_map_free(umap1
);
2198 isl_union_map_free(umap2
);
2200 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
2201 umap1
= isl_union_map_read_from_str(ctx
, str
);
2202 str
= "{ A[i]; B[i] }";
2203 uset1
= isl_union_set_read_from_str(ctx
, str
);
2205 uset2
= isl_union_map_domain(umap1
);
2207 assert(isl_union_set_is_equal(uset1
, uset2
));
2209 isl_union_set_free(uset1
);
2210 isl_union_set_free(uset2
);
2213 void test_bound(isl_ctx
*ctx
)
2216 isl_pw_qpolynomial
*pwqp
;
2217 isl_pw_qpolynomial_fold
*pwf
;
2219 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
2220 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2221 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2222 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 4);
2223 isl_pw_qpolynomial_fold_free(pwf
);
2225 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
2226 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2227 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2228 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 1);
2229 isl_pw_qpolynomial_fold_free(pwf
);
2232 void test_lift(isl_ctx
*ctx
)
2235 isl_basic_map
*bmap
;
2236 isl_basic_set
*bset
;
2238 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
2239 bset
= isl_basic_set_read_from_str(ctx
, str
);
2240 bset
= isl_basic_set_lift(bset
);
2241 bmap
= isl_basic_map_from_range(bset
);
2242 bset
= isl_basic_map_domain(bmap
);
2243 isl_basic_set_free(bset
);
2250 } subset_tests
[] = {
2252 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
2253 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
2254 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
2256 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
2257 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
2258 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
2259 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
2260 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
2261 "256e0 <= 255i and 256e0 >= -255 + 255i and "
2262 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
2263 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
2264 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
2265 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
2266 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
2267 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
2268 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
2271 static int test_subset(isl_ctx
*ctx
)
2274 isl_set
*set1
, *set2
;
2277 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
2278 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
2279 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
2280 subset
= isl_set_is_subset(set1
, set2
);
2285 if (subset
!= subset_tests
[i
].subset
)
2286 isl_die(ctx
, isl_error_unknown
,
2287 "incorrect subset result", return -1);
2294 const char *minuend
;
2295 const char *subtrahend
;
2296 const char *difference
;
2297 } subtract_domain_tests
[] = {
2298 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
2299 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
2300 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
2303 static int test_subtract(isl_ctx
*ctx
)
2306 isl_union_map
*umap1
, *umap2
;
2307 isl_union_set
*uset
;
2310 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2311 umap1
= isl_union_map_read_from_str(ctx
,
2312 subtract_domain_tests
[i
].minuend
);
2313 uset
= isl_union_set_read_from_str(ctx
,
2314 subtract_domain_tests
[i
].subtrahend
);
2315 umap2
= isl_union_map_read_from_str(ctx
,
2316 subtract_domain_tests
[i
].difference
);
2317 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
2318 equal
= isl_union_map_is_equal(umap1
, umap2
);
2319 isl_union_map_free(umap1
);
2320 isl_union_map_free(umap2
);
2324 isl_die(ctx
, isl_error_unknown
,
2325 "incorrect subtract domain result", return -1);
2331 int test_factorize(isl_ctx
*ctx
)
2334 isl_basic_set
*bset
;
2337 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2338 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2339 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2340 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2341 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2342 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2343 "3i5 >= -2i0 - i2 + 3i4 }";
2344 bset
= isl_basic_set_read_from_str(ctx
, str
);
2345 f
= isl_basic_set_factorizer(bset
);
2346 isl_basic_set_free(bset
);
2347 isl_factorizer_free(f
);
2349 isl_die(ctx
, isl_error_unknown
,
2350 "failed to construct factorizer", return -1);
2352 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2353 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2354 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2355 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2356 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2357 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2358 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2359 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2360 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2361 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2362 bset
= isl_basic_set_read_from_str(ctx
, str
);
2363 f
= isl_basic_set_factorizer(bset
);
2364 isl_basic_set_free(bset
);
2365 isl_factorizer_free(f
);
2367 isl_die(ctx
, isl_error_unknown
,
2368 "failed to construct factorizer", return -1);
2373 static int check_injective(__isl_take isl_map
*map
, void *user
)
2375 int *injective
= user
;
2377 *injective
= isl_map_is_injective(map
);
2380 if (*injective
< 0 || !*injective
)
2386 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
2387 const char *r
, const char *s
, int tilable
, int parallel
)
2391 isl_union_map
*W
, *R
, *S
;
2392 isl_union_map
*empty
;
2393 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
2394 isl_union_map
*validity
, *proximity
;
2395 isl_union_map
*schedule
;
2396 isl_union_map
*test
;
2397 isl_union_set
*delta
;
2398 isl_union_set
*domain
;
2402 isl_schedule
*sched
;
2403 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
2405 D
= isl_union_set_read_from_str(ctx
, d
);
2406 W
= isl_union_map_read_from_str(ctx
, w
);
2407 R
= isl_union_map_read_from_str(ctx
, r
);
2408 S
= isl_union_map_read_from_str(ctx
, s
);
2410 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
2411 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
2413 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
2414 isl_union_map_compute_flow(isl_union_map_copy(R
),
2415 isl_union_map_copy(W
), empty
,
2416 isl_union_map_copy(S
),
2417 &dep_raw
, NULL
, NULL
, NULL
);
2418 isl_union_map_compute_flow(isl_union_map_copy(W
),
2419 isl_union_map_copy(W
),
2420 isl_union_map_copy(R
),
2421 isl_union_map_copy(S
),
2422 &dep_waw
, &dep_war
, NULL
, NULL
);
2424 dep
= isl_union_map_union(dep_waw
, dep_war
);
2425 dep
= isl_union_map_union(dep
, dep_raw
);
2426 validity
= isl_union_map_copy(dep
);
2427 proximity
= isl_union_map_copy(dep
);
2429 sched
= isl_union_set_compute_schedule(isl_union_set_copy(D
),
2430 validity
, proximity
);
2431 schedule
= isl_schedule_get_map(sched
);
2432 isl_schedule_free(sched
);
2433 isl_union_map_free(W
);
2434 isl_union_map_free(R
);
2435 isl_union_map_free(S
);
2438 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
2440 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
2441 is_complete
= isl_union_set_is_subset(D
, domain
);
2442 isl_union_set_free(D
);
2443 isl_union_set_free(domain
);
2445 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
2446 test
= isl_union_map_apply_range(test
, dep
);
2447 test
= isl_union_map_apply_range(test
, schedule
);
2449 delta
= isl_union_map_deltas(test
);
2450 if (isl_union_set_n_set(delta
) == 0) {
2454 isl_union_set_free(delta
);
2456 delta_set
= isl_set_from_union_set(delta
);
2458 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2459 for (i
= 0; i
< tilable
; ++i
)
2460 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
2461 is_tilable
= isl_set_is_subset(delta_set
, slice
);
2462 isl_set_free(slice
);
2464 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2465 for (i
= 0; i
< parallel
; ++i
)
2466 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
2467 is_parallel
= isl_set_is_subset(delta_set
, slice
);
2468 isl_set_free(slice
);
2470 origin
= isl_set_universe(isl_set_get_space(delta_set
));
2471 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
2472 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
2474 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
2475 delta_set
= isl_set_lexmin(delta_set
);
2477 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
2479 isl_set_free(origin
);
2480 isl_set_free(delta_set
);
2483 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
2484 is_injection
< 0 || is_complete
< 0)
2487 isl_die(ctx
, isl_error_unknown
,
2488 "generated schedule incomplete", return -1);
2490 isl_die(ctx
, isl_error_unknown
,
2491 "generated schedule not injective on each statement",
2494 isl_die(ctx
, isl_error_unknown
,
2495 "negative dependences in generated schedule",
2498 isl_die(ctx
, isl_error_unknown
,
2499 "generated schedule not as tilable as expected",
2502 isl_die(ctx
, isl_error_unknown
,
2503 "generated schedule not as parallel as expected",
2509 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
2510 const char *domain
, const char *validity
, const char *proximity
)
2514 isl_union_map
*prox
;
2515 isl_schedule
*schedule
;
2516 isl_union_map
*sched
;
2518 dom
= isl_union_set_read_from_str(ctx
, domain
);
2519 dep
= isl_union_map_read_from_str(ctx
, validity
);
2520 prox
= isl_union_map_read_from_str(ctx
, proximity
);
2521 schedule
= isl_union_set_compute_schedule(dom
, dep
, prox
);
2522 sched
= isl_schedule_get_map(schedule
);
2523 isl_schedule_free(schedule
);
2528 /* Check that a schedule can be constructed on the given domain
2529 * with the given validity and proximity constraints.
2531 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
2532 const char *validity
, const char *proximity
)
2534 isl_union_map
*sched
;
2536 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
2540 isl_union_map_free(sched
);
2544 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
2545 const char *validity
, const char *proximity
, const char *expected_sched
)
2547 isl_union_map
*sched1
, *sched2
;
2550 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
2551 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
2553 equal
= isl_union_map_is_equal(sched1
, sched2
);
2554 isl_union_map_free(sched1
);
2555 isl_union_map_free(sched2
);
2560 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
2566 /* Check that the schedule map is properly padded, even after being
2567 * reconstructed from the band forest.
2569 static int test_padded_schedule(isl_ctx
*ctx
)
2573 isl_union_map
*validity
, *proximity
;
2574 isl_schedule
*sched
;
2575 isl_union_map
*map1
, *map2
;
2576 isl_band_list
*list
;
2579 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
2580 D
= isl_union_set_read_from_str(ctx
, str
);
2581 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
2582 proximity
= isl_union_map_copy(validity
);
2583 sched
= isl_union_set_compute_schedule(D
, validity
, proximity
);
2584 map1
= isl_schedule_get_map(sched
);
2585 list
= isl_schedule_get_band_forest(sched
);
2586 isl_band_list_free(list
);
2587 map2
= isl_schedule_get_map(sched
);
2588 isl_schedule_free(sched
);
2589 equal
= isl_union_map_is_equal(map1
, map2
);
2590 isl_union_map_free(map1
);
2591 isl_union_map_free(map2
);
2596 isl_die(ctx
, isl_error_unknown
,
2597 "reconstructed schedule map not the same as original",
2603 int test_schedule(isl_ctx
*ctx
)
2605 const char *D
, *W
, *R
, *V
, *P
, *S
;
2607 /* Handle resulting schedule with zero bands. */
2608 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
2612 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2613 W
= "{ S1[t,i] -> a[t,i] }";
2614 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2615 "S1[t,i] -> a[t-1,i+1] }";
2616 S
= "{ S1[t,i] -> [t,i] }";
2617 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2620 /* Fig. 5 of CC2008 */
2621 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
2623 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
2624 "j >= 2 and j <= -1 + N }";
2625 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
2626 "j >= 2 and j <= -1 + N; "
2627 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
2628 "j >= 2 and j <= -1 + N }";
2629 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2630 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2633 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
2634 W
= "{ S1[i] -> a[i] }";
2635 R
= "{ S2[i] -> a[i+1] }";
2636 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2637 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2640 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
2641 W
= "{ S1[i] -> a[i] }";
2642 R
= "{ S2[i] -> a[9-i] }";
2643 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2644 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2647 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
2648 W
= "{ S1[i] -> a[i] }";
2649 R
= "[N] -> { S2[i] -> a[N-1-i] }";
2650 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
2651 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
2654 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
2655 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
2656 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
2657 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
2658 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2661 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2662 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
2663 R
= "{ S2[i,j] -> a[i-1,j] }";
2664 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2665 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2668 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
2669 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
2670 R
= "{ S2[i,j] -> a[i,j-1] }";
2671 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
2672 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2675 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
2676 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
2677 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
2678 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
2679 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
2680 "S_0[] -> [0, 0, 0] }";
2681 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
2683 ctx
->opt
->schedule_parametric
= 0;
2684 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2686 ctx
->opt
->schedule_parametric
= 1;
2688 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
2689 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
2690 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
2691 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
2692 "S4[i] -> a[i,N] }";
2693 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
2694 "S4[i] -> [4,i,0] }";
2695 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
2698 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
2699 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2701 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
2703 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
2705 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
2706 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2709 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
2710 " S_2[t] : t >= 0 and t <= -1 + N; "
2711 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
2713 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
2714 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
2715 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
2716 "i >= 0 and i <= -1 + N }";
2717 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
2718 "i >= 0 and i <= -1 + N; "
2719 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
2720 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
2721 " S_0[t] -> [0, t, 0] }";
2723 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
2725 ctx
->opt
->schedule_parametric
= 0;
2726 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2728 ctx
->opt
->schedule_parametric
= 1;
2730 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
2731 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
2732 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
2735 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
2736 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
2737 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
2738 "j >= 0 and j <= -1 + N; "
2739 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2740 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
2741 "j >= 0 and j <= -1 + N; "
2742 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
2743 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
2744 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2747 D
= "{ S_0[i] : i >= 0 }";
2748 W
= "{ S_0[i] -> a[i] : i >= 0 }";
2749 R
= "{ S_0[i] -> a[0] : i >= 0 }";
2750 S
= "{ S_0[i] -> [0, i, 0] }";
2751 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2754 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
2755 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
2756 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
2757 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
2758 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2761 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
2762 "k <= -1 + n and k >= 0 }";
2763 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
2764 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
2765 "k <= -1 + n and k >= 0; "
2766 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
2767 "k <= -1 + n and k >= 0; "
2768 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
2769 "k <= -1 + n and k >= 0 }";
2770 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
2771 ctx
->opt
->schedule_outer_zero_distance
= 1;
2772 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
2774 ctx
->opt
->schedule_outer_zero_distance
= 0;
2776 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
2777 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
2778 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
2779 "Stmt_for_body24[i0, i1, 1, 0]:"
2780 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
2781 "Stmt_for_body7[i0, i1, i2]:"
2782 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
2785 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
2786 "Stmt_for_body24[1, i1, i2, i3]:"
2787 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
2789 "Stmt_for_body24[0, i1, i2, i3] -> "
2790 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
2791 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
2793 "Stmt_for_body24[0, i1, i2, i3] ->"
2794 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
2795 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
2796 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
2797 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
2798 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
2799 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
2800 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
2801 "i1 <= 6 and i1 >= 0;"
2802 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
2803 "Stmt_for_body7[i0, i1, i2] -> "
2804 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
2805 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
2806 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
2807 "Stmt_for_body7[i0, i1, i2] -> "
2808 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
2809 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
2810 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
2812 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
2813 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
2814 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
2816 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2819 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
2820 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
2821 "j >= 1 and j <= 7;"
2822 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
2823 "j >= 1 and j <= 8 }";
2825 S
= "{ S_0[i, j] -> [i + j, j] }";
2826 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
2827 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2829 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
2831 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
2832 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
2833 "j >= 0 and j <= -1 + i }";
2834 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
2835 "i <= -1 + N and j >= 0;"
2836 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
2839 S
= "{ S_0[i, j] -> [i, j] }";
2840 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
2841 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2843 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
2845 /* Test both algorithms on a case with only proximity dependences. */
2846 D
= "{ S[i,j] : 0 <= i <= 10 }";
2848 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
2849 S
= "{ S[i, j] -> [j, i] }";
2850 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
2851 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2853 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
2854 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
2857 D
= "{ A[a]; B[] }";
2859 P
= "{ A[a] -> B[] }";
2860 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
2863 if (test_padded_schedule(ctx
) < 0)
2866 /* Check that check for progress is not confused by rational
2869 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
2870 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
2872 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
2873 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
2875 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
2876 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
2878 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
2883 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
2885 isl_union_map
*umap
;
2888 umap
= isl_union_map_read_from_str(ctx
, str
);
2889 test
= isl_union_map_plain_is_injective(umap
);
2890 isl_union_map_free(umap
);
2893 if (test
== injective
)
2896 isl_die(ctx
, isl_error_unknown
,
2897 "map not detected as injective", return -1);
2899 isl_die(ctx
, isl_error_unknown
,
2900 "map detected as injective", return -1);
2903 int test_injective(isl_ctx
*ctx
)
2907 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
2909 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
2911 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
2913 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
2915 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
2917 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
2919 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
2921 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
2924 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
2925 if (test_plain_injective(ctx
, str
, 1))
2927 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
2928 if (test_plain_injective(ctx
, str
, 0))
2934 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
2942 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
2943 equal
= isl_aff_plain_is_equal(aff
, aff2
);
2949 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
2953 equal
= aff_plain_is_equal(aff
, str
);
2957 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
2958 "result not as expected", return -1);
2962 int test_aff(isl_ctx
*ctx
)
2967 isl_local_space
*ls
;
2971 space
= isl_space_set_alloc(ctx
, 0, 1);
2972 ls
= isl_local_space_from_space(space
);
2973 aff
= isl_aff_zero_on_domain(ls
);
2975 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
2976 aff
= isl_aff_scale_down_ui(aff
, 3);
2977 aff
= isl_aff_floor(aff
);
2978 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
2979 aff
= isl_aff_scale_down_ui(aff
, 2);
2980 aff
= isl_aff_floor(aff
);
2981 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
2984 set
= isl_set_read_from_str(ctx
, str
);
2985 aff
= isl_aff_gist(aff
, set
);
2987 aff
= isl_aff_add_constant_si(aff
, -16);
2988 zero
= isl_aff_plain_is_zero(aff
);
2994 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2996 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
2997 aff
= isl_aff_scale_down_ui(aff
, 64);
2998 aff
= isl_aff_floor(aff
);
2999 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
3007 int test_dim_max(isl_ctx
*ctx
)
3011 isl_set
*set1
, *set2
;
3016 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
3017 set
= isl_set_read_from_str(ctx
, str
);
3018 pwaff
= isl_set_dim_max(set
, 0);
3019 set1
= isl_set_from_pw_aff(pwaff
);
3020 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
3021 set2
= isl_set_read_from_str(ctx
, str
);
3022 equal
= isl_set_is_equal(set1
, set2
);
3028 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3030 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
3031 set
= isl_set_read_from_str(ctx
, str
);
3032 pwaff
= isl_set_dim_max(set
, 0);
3033 set1
= isl_set_from_pw_aff(pwaff
);
3034 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3035 set2
= isl_set_read_from_str(ctx
, str
);
3036 equal
= isl_set_is_equal(set1
, set2
);
3042 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3044 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
3045 set
= isl_set_read_from_str(ctx
, str
);
3046 pwaff
= isl_set_dim_max(set
, 0);
3047 set1
= isl_set_from_pw_aff(pwaff
);
3048 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3049 set2
= isl_set_read_from_str(ctx
, str
);
3050 equal
= isl_set_is_equal(set1
, set2
);
3056 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3058 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
3059 "0 <= i < N and 0 <= j < M }";
3060 map
= isl_map_read_from_str(ctx
, str
);
3061 set
= isl_map_range(map
);
3063 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
3064 set1
= isl_set_from_pw_aff(pwaff
);
3065 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
3066 set2
= isl_set_read_from_str(ctx
, str
);
3067 equal
= isl_set_is_equal(set1
, set2
);
3071 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
3072 set1
= isl_set_from_pw_aff(pwaff
);
3073 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
3074 set2
= isl_set_read_from_str(ctx
, str
);
3075 if (equal
>= 0 && equal
)
3076 equal
= isl_set_is_equal(set1
, set2
);
3085 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3087 /* Check that solutions are properly merged. */
3088 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
3089 "c <= -1 + n - 4a - 2b and c >= -2b and "
3090 "4a >= -4 + n and c >= 0 }";
3091 set
= isl_set_read_from_str(ctx
, str
);
3092 pwaff
= isl_set_dim_min(set
, 2);
3093 set1
= isl_set_from_pw_aff(pwaff
);
3094 str
= "[n] -> { [(0)] : n >= 1 }";
3095 set2
= isl_set_read_from_str(ctx
, str
);
3096 equal
= isl_set_is_equal(set1
, set2
);
3103 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3108 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
3110 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
3114 isl_pw_multi_aff
*pma2
;
3120 ctx
= isl_pw_multi_aff_get_ctx(pma
);
3121 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3122 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
3123 isl_pw_multi_aff_free(pma2
);
3128 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
3129 * represented by "str".
3131 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
3136 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
3140 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
3141 "result not as expected", return -1);
3145 /* Basic test for isl_pw_multi_aff_product.
3147 * Check that multiple pieces are properly handled.
3149 static int test_product_pma(isl_ctx
*ctx
)
3153 isl_pw_multi_aff
*pma1
, *pma2
;
3155 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
3156 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3157 str
= "{ C[] -> D[] }";
3158 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3159 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
3160 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
3161 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
3162 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
3163 isl_pw_multi_aff_free(pma1
);
3170 int test_product(isl_ctx
*ctx
)
3174 isl_union_set
*uset1
, *uset2
;
3178 set
= isl_set_read_from_str(ctx
, str
);
3179 set
= isl_set_product(set
, isl_set_copy(set
));
3180 ok
= isl_set_is_wrapping(set
);
3185 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3188 uset1
= isl_union_set_read_from_str(ctx
, str
);
3189 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
3190 str
= "{ [[] -> []] }";
3191 uset2
= isl_union_set_read_from_str(ctx
, str
);
3192 ok
= isl_union_set_is_equal(uset1
, uset2
);
3193 isl_union_set_free(uset1
);
3194 isl_union_set_free(uset2
);
3198 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3200 if (test_product_pma(ctx
) < 0)
3206 int test_equal(isl_ctx
*ctx
)
3209 isl_set
*set
, *set2
;
3213 set
= isl_set_read_from_str(ctx
, str
);
3215 set2
= isl_set_read_from_str(ctx
, str
);
3216 equal
= isl_set_is_equal(set
, set2
);
3222 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3227 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
3228 enum isl_dim_type type
, unsigned pos
, int fixed
)
3232 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
3239 isl_die(ctx
, isl_error_unknown
,
3240 "map not detected as fixed", return -1);
3242 isl_die(ctx
, isl_error_unknown
,
3243 "map detected as fixed", return -1);
3246 int test_fixed(isl_ctx
*ctx
)
3251 str
= "{ [i] -> [i] }";
3252 map
= isl_map_read_from_str(ctx
, str
);
3253 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
3255 str
= "{ [i] -> [1] }";
3256 map
= isl_map_read_from_str(ctx
, str
);
3257 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3259 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
3260 map
= isl_map_read_from_str(ctx
, str
);
3261 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3263 map
= isl_map_read_from_str(ctx
, str
);
3264 map
= isl_map_neg(map
);
3265 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3271 int test_vertices(isl_ctx
*ctx
)
3274 isl_basic_set
*bset
;
3275 isl_vertices
*vertices
;
3277 str
= "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }";
3278 bset
= isl_basic_set_read_from_str(ctx
, str
);
3279 vertices
= isl_basic_set_compute_vertices(bset
);
3280 isl_basic_set_free(bset
);
3281 isl_vertices_free(vertices
);
3285 str
= "{ A[t, i] : t = 14 and i = 1 }";
3286 bset
= isl_basic_set_read_from_str(ctx
, str
);
3287 vertices
= isl_basic_set_compute_vertices(bset
);
3288 isl_basic_set_free(bset
);
3289 isl_vertices_free(vertices
);
3296 int test_union_pw(isl_ctx
*ctx
)
3300 isl_union_set
*uset
;
3301 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
3303 str
= "{ [x] -> x^2 }";
3304 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
3305 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
3306 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
3307 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
3308 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
3309 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
3310 isl_union_pw_qpolynomial_free(upwqp1
);
3311 isl_union_pw_qpolynomial_free(upwqp2
);
3315 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3320 int test_output(isl_ctx
*ctx
)
3328 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
3329 pa
= isl_pw_aff_read_from_str(ctx
, str
);
3331 p
= isl_printer_to_str(ctx
);
3332 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
3333 p
= isl_printer_print_pw_aff(p
, pa
);
3334 s
= isl_printer_get_str(p
);
3335 isl_printer_free(p
);
3336 isl_pw_aff_free(pa
);
3340 equal
= !strcmp(s
, "(2 - x + 4*floord(x, 4) >= 0) ? (1) : 2");
3345 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3350 int test_sample(isl_ctx
*ctx
)
3353 isl_basic_set
*bset1
, *bset2
;
3356 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
3357 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
3358 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
3359 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
3360 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
3361 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
3362 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
3363 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
3364 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
3365 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
3366 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
3367 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
3368 "d - 1073741821e and "
3369 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
3370 "3j >= 1 - a + b + 2e and "
3371 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
3372 "3i <= 4 - a + 4b - e and "
3373 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
3374 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
3375 "c <= -1 + a and 3i >= -2 - a + 3e and "
3376 "1073741822e <= 1073741823 - a + 1073741822b + c and "
3377 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
3378 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
3379 "1073741823e >= 1 + 1073741823b - d and "
3380 "3i >= 1073741823b + c - 1073741823e - f and "
3381 "3i >= 1 + 2b + e + 3g }";
3382 bset1
= isl_basic_set_read_from_str(ctx
, str
);
3383 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
3384 empty
= isl_basic_set_is_empty(bset2
);
3385 subset
= isl_basic_set_is_subset(bset2
, bset1
);
3386 isl_basic_set_free(bset1
);
3387 isl_basic_set_free(bset2
);
3388 if (empty
< 0 || subset
< 0)
3391 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
3393 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
3398 int test_fixed_power(isl_ctx
*ctx
)
3406 str
= "{ [i] -> [i + 1] }";
3407 map
= isl_map_read_from_str(ctx
, str
);
3408 isl_int_set_si(exp
, 23);
3409 map
= isl_map_fixed_power(map
, exp
);
3410 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
3419 int test_slice(isl_ctx
*ctx
)
3425 str
= "{ [i] -> [j] }";
3426 map
= isl_map_read_from_str(ctx
, str
);
3427 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3428 equal
= map_check_equal(map
, "{ [i] -> [i] }");
3433 str
= "{ [i] -> [j] }";
3434 map
= isl_map_read_from_str(ctx
, str
);
3435 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3436 equal
= map_check_equal(map
, "{ [i] -> [j] }");
3441 str
= "{ [i] -> [j] }";
3442 map
= isl_map_read_from_str(ctx
, str
);
3443 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3444 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
3449 str
= "{ [i] -> [j] }";
3450 map
= isl_map_read_from_str(ctx
, str
);
3451 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3452 equal
= map_check_equal(map
, "{ [0] -> [j] }");
3457 str
= "{ [i] -> [j] }";
3458 map
= isl_map_read_from_str(ctx
, str
);
3459 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
3460 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
3465 str
= "{ [i] -> [j] }";
3466 map
= isl_map_read_from_str(ctx
, str
);
3467 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
3468 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
3476 int test_eliminate(isl_ctx
*ctx
)
3482 str
= "{ [i] -> [j] : i = 2j }";
3483 map
= isl_map_read_from_str(ctx
, str
);
3484 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
3485 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
3493 /* Check that isl_set_dim_residue_class detects that the values of j
3494 * in the set below are all odd and that it does not detect any spurious
3497 static int test_residue_class(isl_ctx
*ctx
)
3504 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
3505 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
3506 set
= isl_set_read_from_str(ctx
, str
);
3509 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
3511 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
3512 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
3521 int test_align_parameters(isl_ctx
*ctx
)
3525 isl_multi_aff
*ma1
, *ma2
;
3528 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
3529 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
3531 space
= isl_space_params_alloc(ctx
, 1);
3532 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
3533 ma1
= isl_multi_aff_align_params(ma1
, space
);
3535 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
3536 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
3538 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
3540 isl_multi_aff_free(ma1
);
3541 isl_multi_aff_free(ma2
);
3546 isl_die(ctx
, isl_error_unknown
,
3547 "result not as expected", return -1);
3552 static int test_list(isl_ctx
*ctx
)
3554 isl_id
*a
, *b
, *c
, *d
, *id
;
3558 a
= isl_id_alloc(ctx
, "a", NULL
);
3559 b
= isl_id_alloc(ctx
, "b", NULL
);
3560 c
= isl_id_alloc(ctx
, "c", NULL
);
3561 d
= isl_id_alloc(ctx
, "d", NULL
);
3563 list
= isl_id_list_alloc(ctx
, 4);
3564 list
= isl_id_list_add(list
, a
);
3565 list
= isl_id_list_add(list
, b
);
3566 list
= isl_id_list_add(list
, c
);
3567 list
= isl_id_list_add(list
, d
);
3568 list
= isl_id_list_drop(list
, 1, 1);
3570 if (isl_id_list_n_id(list
) != 3) {
3571 isl_id_list_free(list
);
3572 isl_die(ctx
, isl_error_unknown
,
3573 "unexpected number of elements in list", return -1);
3576 id
= isl_id_list_get_id(list
, 0);
3579 id
= isl_id_list_get_id(list
, 1);
3582 id
= isl_id_list_get_id(list
, 2);
3586 isl_id_list_free(list
);
3589 isl_die(ctx
, isl_error_unknown
,
3590 "unexpected elements in list", return -1);
3595 const char *set_conversion_tests
[] = {
3596 "[N] -> { [i] : N - 1 <= 2 i <= N }",
3597 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
3598 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
3599 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
3602 /* Check that converting from isl_set to isl_pw_multi_aff and back
3603 * to isl_set produces the original isl_set.
3605 static int test_set_conversion(isl_ctx
*ctx
)
3609 isl_set
*set1
, *set2
;
3610 isl_pw_multi_aff
*pma
;
3613 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
3614 str
= set_conversion_tests
[i
];
3615 set1
= isl_set_read_from_str(ctx
, str
);
3616 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
3617 set2
= isl_set_from_pw_multi_aff(pma
);
3618 equal
= isl_set_is_equal(set1
, set2
);
3625 isl_die(ctx
, isl_error_unknown
, "bad conversion",
3632 /* Check that converting from isl_map to isl_pw_multi_aff and back
3633 * to isl_map produces the original isl_map.
3635 static int test_map_conversion(isl_ctx
*ctx
)
3638 isl_map
*map1
, *map2
;
3639 isl_pw_multi_aff
*pma
;
3642 str
= "{ [a, b, c, d] -> s0[a, b, e, f] : "
3643 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
3644 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
3645 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
3647 map1
= isl_map_read_from_str(ctx
, str
);
3648 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
3649 map2
= isl_map_from_pw_multi_aff(pma
);
3650 equal
= isl_map_is_equal(map1
, map2
);
3657 isl_die(ctx
, isl_error_unknown
, "bad conversion", return -1);
3662 static int test_conversion(isl_ctx
*ctx
)
3664 if (test_set_conversion(ctx
) < 0)
3666 if (test_map_conversion(ctx
) < 0)
3671 /* Check that isl_basic_map_curry does not modify input.
3673 static int test_curry(isl_ctx
*ctx
)
3676 isl_basic_map
*bmap1
, *bmap2
;
3679 str
= "{ [A[] -> B[]] -> C[] }";
3680 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
3681 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
3682 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
3683 isl_basic_map_free(bmap1
);
3684 isl_basic_map_free(bmap2
);
3689 isl_die(ctx
, isl_error_unknown
,
3690 "curried map should not be equal to original",
3700 } preimage_tests
[] = {
3701 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
3702 "{ A[j,i] -> B[i,j] }",
3703 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
3704 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
3705 "{ A[a,b] -> B[a/2,b/6] }",
3706 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
3707 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
3708 "{ A[a,b] -> B[a/2,b/6] }",
3709 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
3710 "exists i,j : a = 2 i and b = 6 j }" },
3711 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
3712 "[n] -> { : 0 <= n <= 100 }" },
3713 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
3714 "{ A[a] -> B[2a] }",
3715 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
3716 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
3717 "{ A[a] -> B[([a/2])] }",
3718 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
3719 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
3720 "{ A[a] -> B[a,a,a/3] }",
3721 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
3722 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
3723 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
3726 static int test_preimage_basic_set(isl_ctx
*ctx
)
3729 isl_basic_set
*bset1
, *bset2
;
3733 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
3734 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
3735 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
3736 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
3737 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
3738 equal
= isl_basic_set_is_equal(bset1
, bset2
);
3739 isl_basic_set_free(bset1
);
3740 isl_basic_set_free(bset2
);
3744 isl_die(ctx
, isl_error_unknown
, "bad preimage",
3755 } preimage_domain_tests
[] = {
3756 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
3757 "{ A[j,i] -> B[i,j] }",
3758 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
3759 { "{ B[i] -> C[i]; D[i] -> E[i] }",
3760 "{ A[i] -> B[i + 1] }",
3761 "{ A[i] -> C[i + 1] }" },
3762 { "{ B[i] -> C[i]; B[i] -> E[i] }",
3763 "{ A[i] -> B[i + 1] }",
3764 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
3765 { "{ B[i] -> C[([i/2])] }",
3766 "{ A[i] -> B[2i] }",
3767 "{ A[i] -> C[i] }" },
3768 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
3769 "{ A[i] -> B[([i/5]), ([i/7])] }",
3770 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
3771 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
3772 "[N] -> { A[] -> B[([N/5])] }",
3773 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
3774 { "{ B[i] -> C[i] : exists a : i = 5 a }",
3775 "{ A[i] -> B[2i] }",
3776 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
3777 { "{ B[i] -> C[i] : exists a : i = 2 a; "
3778 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
3779 "{ A[i] -> B[2i] }",
3780 "{ A[i] -> C[2i] }" },
3783 static int test_preimage_union_map(isl_ctx
*ctx
)
3786 isl_union_map
*umap1
, *umap2
;
3790 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
3791 umap1
= isl_union_map_read_from_str(ctx
,
3792 preimage_domain_tests
[i
].map
);
3793 ma
= isl_multi_aff_read_from_str(ctx
,
3794 preimage_domain_tests
[i
].ma
);
3795 umap2
= isl_union_map_read_from_str(ctx
,
3796 preimage_domain_tests
[i
].res
);
3797 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
3798 equal
= isl_union_map_is_equal(umap1
, umap2
);
3799 isl_union_map_free(umap1
);
3800 isl_union_map_free(umap2
);
3804 isl_die(ctx
, isl_error_unknown
, "bad preimage",
3811 static int test_preimage(isl_ctx
*ctx
)
3813 if (test_preimage_basic_set(ctx
) < 0)
3815 if (test_preimage_union_map(ctx
) < 0)
3825 } pullback_tests
[] = {
3826 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
3827 "{ A[a,b] -> C[b + 2a] }" },
3828 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
3829 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
3830 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
3831 "{ A[a] -> C[(a)/6] }" },
3832 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
3833 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
3834 "{ A[a] -> C[(2a)/3] }" },
3835 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
3836 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
3837 "{ A[i,j] -> C[i + j, i + j] }"},
3838 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
3839 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
3840 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
3843 static int test_pullback(isl_ctx
*ctx
)
3846 isl_multi_aff
*ma1
, *ma2
;
3850 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
3851 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
3852 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
3853 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
3854 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
3855 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
3856 isl_multi_aff_free(ma1
);
3857 isl_multi_aff_free(ma2
);
3861 isl_die(ctx
, isl_error_unknown
, "bad pullback",
3868 /* Check that negation is printed correctly.
3870 static int test_ast(isl_ctx
*ctx
)
3872 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
3876 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
3877 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
3878 expr
= isl_ast_expr_add(expr1
, expr2
);
3879 expr
= isl_ast_expr_neg(expr
);
3880 str
= isl_ast_expr_to_str(expr
);
3881 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
3883 isl_ast_expr_free(expr
);
3888 isl_die(ctx
, isl_error_unknown
,
3889 "isl_ast_expr printed incorrectly", return -1);
3891 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
3892 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
3893 expr
= isl_ast_expr_add(expr1
, expr2
);
3894 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
3895 expr
= isl_ast_expr_sub(expr3
, expr
);
3896 str
= isl_ast_expr_to_str(expr
);
3897 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
3899 isl_ast_expr_free(expr
);
3904 isl_die(ctx
, isl_error_unknown
,
3905 "isl_ast_expr printed incorrectly", return -1);
3910 /* Internal data structure for before_for and after_for callbacks.
3912 * depth is the current depth
3913 * before is the number of times before_for has been called
3914 * after is the number of times after_for has been called
3916 struct isl_test_codegen_data
{
3922 /* This function is called before each for loop in the AST generated
3923 * from test_ast_gen1.
3925 * Increment the number of calls and the depth.
3926 * Check that the space returned by isl_ast_build_get_schedule_space
3927 * matches the target space of the schedule returned by
3928 * isl_ast_build_get_schedule.
3929 * Return an isl_id that is checked by the corresponding call
3932 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
3935 struct isl_test_codegen_data
*data
= user
;
3938 isl_union_map
*schedule
;
3939 isl_union_set
*uset
;
3944 ctx
= isl_ast_build_get_ctx(build
);
3946 if (data
->before
>= 3)
3947 isl_die(ctx
, isl_error_unknown
,
3948 "unexpected number of for nodes", return NULL
);
3949 if (data
->depth
>= 2)
3950 isl_die(ctx
, isl_error_unknown
,
3951 "unexpected depth", return NULL
);
3953 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
3957 schedule
= isl_ast_build_get_schedule(build
);
3958 uset
= isl_union_map_range(schedule
);
3961 if (isl_union_set_n_set(uset
) != 1) {
3962 isl_union_set_free(uset
);
3963 isl_die(ctx
, isl_error_unknown
,
3964 "expecting single range space", return NULL
);
3967 space
= isl_ast_build_get_schedule_space(build
);
3968 set
= isl_union_set_extract_set(uset
, space
);
3969 isl_union_set_free(uset
);
3970 empty
= isl_set_is_empty(set
);
3976 isl_die(ctx
, isl_error_unknown
,
3977 "spaces don't match", return NULL
);
3979 return isl_id_alloc(ctx
, name
, NULL
);
3982 /* This function is called after each for loop in the AST generated
3983 * from test_ast_gen1.
3985 * Increment the number of calls and decrement the depth.
3986 * Check that the annotation attached to the node matches
3987 * the isl_id returned by the corresponding call to before_for.
3989 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
3990 __isl_keep isl_ast_build
*build
, void *user
)
3992 struct isl_test_codegen_data
*data
= user
;
4000 if (data
->after
> data
->before
)
4001 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4002 "mismatch in number of for nodes",
4003 return isl_ast_node_free(node
));
4005 id
= isl_ast_node_get_annotation(node
);
4007 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4008 "missing annotation", return isl_ast_node_free(node
));
4010 name
= isl_id_get_name(id
);
4011 valid
= name
&& atoi(name
+ 1) == data
->depth
;
4015 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4016 "wrong annotation", return isl_ast_node_free(node
));
4021 /* Check that the before_each_for and after_each_for callbacks
4022 * are called for each for loop in the generated code,
4023 * that they are called in the right order and that the isl_id
4024 * returned from the before_each_for callback is attached to
4025 * the isl_ast_node passed to the corresponding after_each_for call.
4027 static int test_ast_gen1(isl_ctx
*ctx
)
4031 isl_union_map
*schedule
;
4032 isl_ast_build
*build
;
4034 struct isl_test_codegen_data data
;
4036 str
= "[N] -> { : N >= 10 }";
4037 set
= isl_set_read_from_str(ctx
, str
);
4038 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
4039 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
4040 schedule
= isl_union_map_read_from_str(ctx
, str
);
4045 build
= isl_ast_build_from_context(set
);
4046 build
= isl_ast_build_set_before_each_for(build
,
4047 &before_for
, &data
);
4048 build
= isl_ast_build_set_after_each_for(build
,
4050 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4051 isl_ast_build_free(build
);
4055 isl_ast_node_free(tree
);
4057 if (data
.before
!= 3 || data
.after
!= 3)
4058 isl_die(ctx
, isl_error_unknown
,
4059 "unexpected number of for nodes", return -1);
4064 /* Check that the AST generator handles domains that are integrally disjoint
4065 * but not ratinoally disjoint.
4067 static int test_ast_gen2(isl_ctx
*ctx
)
4071 isl_union_map
*schedule
;
4072 isl_union_map
*options
;
4073 isl_ast_build
*build
;
4076 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
4077 schedule
= isl_union_map_read_from_str(ctx
, str
);
4078 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4079 build
= isl_ast_build_from_context(set
);
4081 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
4082 options
= isl_union_map_read_from_str(ctx
, str
);
4083 build
= isl_ast_build_set_options(build
, options
);
4084 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4085 isl_ast_build_free(build
);
4088 isl_ast_node_free(tree
);
4093 /* Increment *user on each call.
4095 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
4096 __isl_keep isl_ast_build
*build
, void *user
)
4105 /* Test that unrolling tries to minimize the number of instances.
4106 * In particular, for the schedule given below, make sure it generates
4107 * 3 nodes (rather than 101).
4109 static int test_ast_gen3(isl_ctx
*ctx
)
4113 isl_union_map
*schedule
;
4114 isl_union_map
*options
;
4115 isl_ast_build
*build
;
4119 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
4120 schedule
= isl_union_map_read_from_str(ctx
, str
);
4121 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4123 str
= "{ [i] -> unroll[0] }";
4124 options
= isl_union_map_read_from_str(ctx
, str
);
4126 build
= isl_ast_build_from_context(set
);
4127 build
= isl_ast_build_set_options(build
, options
);
4128 build
= isl_ast_build_set_at_each_domain(build
,
4129 &count_domains
, &n_domain
);
4130 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4131 isl_ast_build_free(build
);
4135 isl_ast_node_free(tree
);
4138 isl_die(ctx
, isl_error_unknown
,
4139 "unexpected number of for nodes", return -1);
4144 /* Check that if the ast_build_exploit_nested_bounds options is set,
4145 * we do not get an outer if node in the generated AST,
4146 * while we do get such an outer if node if the options is not set.
4148 static int test_ast_gen4(isl_ctx
*ctx
)
4152 isl_union_map
*schedule
;
4153 isl_ast_build
*build
;
4155 enum isl_ast_node_type type
;
4158 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
4159 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
4161 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
4163 schedule
= isl_union_map_read_from_str(ctx
, str
);
4164 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4165 build
= isl_ast_build_from_context(set
);
4166 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4167 isl_ast_build_free(build
);
4171 type
= isl_ast_node_get_type(tree
);
4172 isl_ast_node_free(tree
);
4174 if (type
== isl_ast_node_if
)
4175 isl_die(ctx
, isl_error_unknown
,
4176 "not expecting if node", return -1);
4178 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
4180 schedule
= isl_union_map_read_from_str(ctx
, str
);
4181 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4182 build
= isl_ast_build_from_context(set
);
4183 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4184 isl_ast_build_free(build
);
4188 type
= isl_ast_node_get_type(tree
);
4189 isl_ast_node_free(tree
);
4191 if (type
!= isl_ast_node_if
)
4192 isl_die(ctx
, isl_error_unknown
,
4193 "expecting if node", return -1);
4195 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
4200 /* This function is called for each leaf in the AST generated
4201 * from test_ast_gen5.
4203 * We finalize the AST generation by extending the outer schedule
4204 * with a zero-dimensional schedule. If this results in any for loops,
4205 * then this means that we did not pass along enough information
4206 * about the outer schedule to the inner AST generation.
4208 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
4211 isl_union_map
*schedule
, *extra
;
4214 schedule
= isl_ast_build_get_schedule(build
);
4215 extra
= isl_union_map_copy(schedule
);
4216 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
4217 schedule
= isl_union_map_range_product(schedule
, extra
);
4218 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4219 isl_ast_build_free(build
);
4224 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
4225 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
4226 "code should not contain any for loop",
4227 return isl_ast_node_free(tree
));
4232 /* Check that we do not lose any information when going back and
4233 * forth between internal and external schedule.
4235 * In particular, we create an AST where we unroll the only
4236 * non-constant dimension in the schedule. We therefore do
4237 * not expect any for loops in the AST. However, older versions
4238 * of isl would not pass along enough information about the outer
4239 * schedule when performing an inner code generation from a create_leaf
4240 * callback, resulting in the inner code generation producing a for loop.
4242 static int test_ast_gen5(isl_ctx
*ctx
)
4246 isl_union_map
*schedule
, *options
;
4247 isl_ast_build
*build
;
4250 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
4251 schedule
= isl_union_map_read_from_str(ctx
, str
);
4253 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
4254 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
4255 options
= isl_union_map_read_from_str(ctx
, str
);
4257 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4258 build
= isl_ast_build_from_context(set
);
4259 build
= isl_ast_build_set_options(build
, options
);
4260 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
4261 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4262 isl_ast_build_free(build
);
4263 isl_ast_node_free(tree
);
4270 static int test_ast_gen(isl_ctx
*ctx
)
4272 if (test_ast_gen1(ctx
) < 0)
4274 if (test_ast_gen2(ctx
) < 0)
4276 if (test_ast_gen3(ctx
) < 0)
4278 if (test_ast_gen4(ctx
) < 0)
4280 if (test_ast_gen5(ctx
) < 0)
4285 /* Check if dropping output dimensions from an isl_pw_multi_aff
4288 static int test_pw_multi_aff(isl_ctx
*ctx
)
4291 isl_pw_multi_aff
*pma1
, *pma2
;
4294 str
= "{ [i,j] -> [i+j, 4i-j] }";
4295 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4296 str
= "{ [i,j] -> [4i-j] }";
4297 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4299 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
4301 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
4303 isl_pw_multi_aff_free(pma1
);
4304 isl_pw_multi_aff_free(pma2
);
4308 isl_die(ctx
, isl_error_unknown
,
4309 "expressions not equal", return -1);
4314 /* This is a regression test for a bug where isl_basic_map_simplify
4315 * would end up in an infinite loop. In particular, we construct
4316 * an empty basic set that is not obviously empty.
4317 * isl_basic_set_is_empty marks the basic set as empty.
4318 * After projecting out i3, the variable can be dropped completely,
4319 * but isl_basic_map_simplify refrains from doing so if the basic set
4320 * is empty and would end up in an infinite loop if it didn't test
4321 * explicitly for empty basic maps in the outer loop.
4323 static int test_simplify(isl_ctx
*ctx
)
4326 isl_basic_set
*bset
;
4329 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
4330 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
4331 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
4333 bset
= isl_basic_set_read_from_str(ctx
, str
);
4334 empty
= isl_basic_set_is_empty(bset
);
4335 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
4336 isl_basic_set_free(bset
);
4340 isl_die(ctx
, isl_error_unknown
,
4341 "basic set should be empty", return -1);
4346 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
4347 * with gbr context would fail to disable the use of the shifted tableau
4348 * when transferring equalities for the input to the context, resulting
4349 * in invalid sample values.
4351 static int test_partial_lexmin(isl_ctx
*ctx
)
4354 isl_basic_set
*bset
;
4355 isl_basic_map
*bmap
;
4358 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
4359 bmap
= isl_basic_map_read_from_str(ctx
, str
);
4360 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
4361 bset
= isl_basic_set_read_from_str(ctx
, str
);
4362 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
4371 /* Check that the variable compression performed on the existentially
4372 * quantified variables inside isl_basic_set_compute_divs is not confused
4373 * by the implicit equalities among the parameters.
4375 static int test_compute_divs(isl_ctx
*ctx
)
4378 isl_basic_set
*bset
;
4381 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
4382 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
4383 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
4384 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
4385 bset
= isl_basic_set_read_from_str(ctx
, str
);
4386 set
= isl_basic_set_compute_divs(bset
);
4396 int (*fn
)(isl_ctx
*ctx
);
4398 { "val", &test_val
},
4399 { "compute divs", &test_compute_divs
},
4400 { "partial lexmin", &test_partial_lexmin
},
4401 { "simplify", &test_simplify
},
4402 { "curry", &test_curry
},
4403 { "piecewise multi affine expressions", &test_pw_multi_aff
},
4404 { "conversion", &test_conversion
},
4405 { "list", &test_list
},
4406 { "align parameters", &test_align_parameters
},
4407 { "preimage", &test_preimage
},
4408 { "pullback", &test_pullback
},
4409 { "AST", &test_ast
},
4410 { "AST generation", &test_ast_gen
},
4411 { "eliminate", &test_eliminate
},
4412 { "residue class", &test_residue_class
},
4413 { "div", &test_div
},
4414 { "slice", &test_slice
},
4415 { "fixed power", &test_fixed_power
},
4416 { "sample", &test_sample
},
4417 { "output", &test_output
},
4418 { "vertices", &test_vertices
},
4419 { "fixed", &test_fixed
},
4420 { "equal", &test_equal
},
4421 { "product", &test_product
},
4422 { "dim_max", &test_dim_max
},
4423 { "affine", &test_aff
},
4424 { "injective", &test_injective
},
4425 { "schedule", &test_schedule
},
4426 { "union_pw", &test_union_pw
},
4427 { "parse", &test_parse
},
4428 { "single-valued", &test_sv
},
4429 { "affine hull", &test_affine_hull
},
4430 { "coalesce", &test_coalesce
},
4431 { "factorize", &test_factorize
},
4432 { "subset", &test_subset
},
4433 { "subtract", &test_subtract
},
4434 { "lexmin", &test_lexmin
},
4435 { "gist", &test_gist
},
4436 { "piecewise quasi-polynomials", &test_pwqp
},
4442 struct isl_ctx
*ctx
;
4444 srcdir
= getenv("srcdir");
4447 ctx
= isl_ctx_alloc();
4448 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
4449 printf("%s\n", tests
[i
].name
);
4450 if (tests
[i
].fn(ctx
) < 0)
4456 test_split_periods(ctx
);
4458 test_bijective(ctx
);
4462 test_construction(ctx
);
4464 test_application(ctx
);
4465 test_convex_hull(ctx
);