2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
4 * Copyright 2012-2013 Ecole Normale Superieure
5 * Copyright 2014 INRIA Rocquencourt
7 * Use of this software is governed by the MIT license
9 * Written by Sven Verdoolaege, K.U.Leuven, Departement
10 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
11 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
12 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
14 * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt,
15 * B.P. 105 - 78153 Le Chesnay, France
21 #include <isl_ctx_private.h>
22 #include <isl_map_private.h>
23 #include <isl_aff_private.h>
26 #include <isl_constraint_private.h>
27 #include <isl/polynomial.h>
28 #include <isl/union_map.h>
29 #include <isl_factorization.h>
30 #include <isl/schedule.h>
31 #include <isl_options_private.h>
32 #include <isl/vertices.h>
33 #include <isl/ast_build.h>
36 #include <isl_ast_build_expr.h>
37 #include <isl/options.h>
39 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(*array))
43 static char *get_filename(isl_ctx
*ctx
, const char *name
, const char *suffix
) {
46 char *pattern
= "%s/test_inputs/%s.%s";
48 length
= strlen(pattern
) - 6 + strlen(srcdir
) + strlen(name
)
50 filename
= isl_alloc_array(ctx
, char, length
);
55 sprintf(filename
, pattern
, srcdir
, name
, suffix
);
60 void test_parse_map(isl_ctx
*ctx
, const char *str
)
64 map
= isl_map_read_from_str(ctx
, str
);
69 int test_parse_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
74 map
= isl_map_read_from_str(ctx
, str
);
75 map2
= isl_map_read_from_str(ctx
, str2
);
76 equal
= isl_map_is_equal(map
, map2
);
83 isl_die(ctx
, isl_error_unknown
, "maps not equal",
89 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
91 isl_pw_qpolynomial
*pwqp
;
93 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
95 isl_pw_qpolynomial_free(pwqp
);
98 static void test_parse_pwaff(isl_ctx
*ctx
, const char *str
)
102 pwaff
= isl_pw_aff_read_from_str(ctx
, str
);
104 isl_pw_aff_free(pwaff
);
107 int test_parse(struct isl_ctx
*ctx
)
110 const char *str
, *str2
;
112 str
= "{ [i] -> [-i] }";
113 map
= isl_map_read_from_str(ctx
, str
);
117 str
= "{ A[i] -> L[([i/3])] }";
118 map
= isl_map_read_from_str(ctx
, str
);
122 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
123 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
124 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
126 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
127 str2
= "{ [x, y] : 2y >= 6 - x }";
128 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
131 if (test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
132 "{ [x,y] : x <= y, 2*y + 3 }") < 0)
134 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
135 if (test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }",
139 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
140 map
= isl_map_read_from_str(ctx
, str
);
141 str
= "{ [new, old] -> [o0, o1] : "
142 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
143 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
144 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
145 map2
= isl_map_read_from_str(ctx
, str
);
146 assert(isl_map_is_equal(map
, map2
));
150 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
151 map
= isl_map_read_from_str(ctx
, str
);
152 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
153 map2
= isl_map_read_from_str(ctx
, str
);
154 assert(isl_map_is_equal(map
, map2
));
158 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
159 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
160 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
163 str
= "{ [i,j] -> [i] : i < j; [i,j] -> [j] : j <= i }";
164 str2
= "{ [i,j] -> [min(i,j)] }";
165 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
168 str
= "{ [i,j] : i != j }";
169 str2
= "{ [i,j] : i < j or i > j }";
170 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
173 str
= "{ [i,j] : (i+1)*2 >= j }";
174 str2
= "{ [i, j] : j <= 2 + 2i }";
175 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
178 str
= "{ [i] -> [i > 0 ? 4 : 5] }";
179 str2
= "{ [i] -> [5] : i <= 0; [i] -> [4] : i >= 1 }";
180 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
183 str
= "[N=2,M] -> { [i=[(M+N)/4]] }";
184 str2
= "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }";
185 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
188 str
= "{ [x] : x >= 0 }";
189 str2
= "{ [x] : x-0 >= 0 }";
190 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
193 str
= "{ [i] : ((i > 10)) }";
194 str2
= "{ [i] : i >= 11 }";
195 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
198 str
= "{ [i] -> [0] }";
199 str2
= "{ [i] -> [0 * i] }";
200 if (test_parse_map_equal(ctx
, str
, str2
) < 0)
203 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
204 test_parse_map(ctx
, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }");
205 test_parse_pwaff(ctx
, "{ [i] -> [i + 1] : i > 0; [a] -> [a] : a < 0 }");
206 test_parse_pwqp(ctx
, "{ [x] -> ([(x)/2] * [(x)/3]) }");
208 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : (not false) }",
209 "{ [a] -> [b] : true }") < 0)
212 if (test_parse_map_equal(ctx
, "{ [i] : i/2 <= 5 }",
213 "{ [i] : i <= 10 }") < 0)
216 if (test_parse_map_equal(ctx
, "{Sym=[n] [i] : i <= n }",
217 "[n] -> { [i] : i <= n }") < 0)
220 if (test_parse_map_equal(ctx
, "{ [*] }", "{ [a] }") < 0)
223 if (test_parse_map_equal(ctx
, "{ [i] : 2*floor(i/2) = i }",
224 "{ [i] : exists a : i = 2 a }") < 0)
227 if (test_parse_map_equal(ctx
, "{ [a] -> [b] : a = 5 implies b = 5 }",
228 "{ [a] -> [b] : a != 5 or b = 5 }") < 0)
231 if (test_parse_map_equal(ctx
, "{ [a] -> [a - 1 : a > 0] }",
232 "{ [a] -> [a - 1] : a > 0 }") < 0)
234 if (test_parse_map_equal(ctx
,
235 "{ [a] -> [a - 1 : a > 0; a : a <= 0] }",
236 "{ [a] -> [a - 1] : a > 0; [a] -> [a] : a <= 0 }") < 0)
238 if (test_parse_map_equal(ctx
,
239 "{ [a] -> [(a) * 2 : a >= 0; 0 : a < 0] }",
240 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
242 if (test_parse_map_equal(ctx
,
243 "{ [a] -> [(a * 2) : a >= 0; 0 : a < 0] }",
244 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
246 if (test_parse_map_equal(ctx
,
247 "{ [a] -> [(a * 2 : a >= 0); 0 : a < 0] }",
248 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
250 if (test_parse_map_equal(ctx
,
251 "{ [a] -> [(a * 2 : a >= 0; 0 : a < 0)] }",
252 "{ [a] -> [2a] : a >= 0; [a] -> [0] : a < 0 }") < 0)
258 void test_read(struct isl_ctx
*ctx
)
262 struct isl_basic_set
*bset1
, *bset2
;
263 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
265 filename
= get_filename(ctx
, "set", "omega");
267 input
= fopen(filename
, "r");
270 bset1
= isl_basic_set_read_from_file(ctx
, input
);
271 bset2
= isl_basic_set_read_from_str(ctx
, str
);
273 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
275 isl_basic_set_free(bset1
);
276 isl_basic_set_free(bset2
);
282 void test_bounded(struct isl_ctx
*ctx
)
287 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }");
288 bounded
= isl_set_is_bounded(set
);
292 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }");
293 bounded
= isl_set_is_bounded(set
);
297 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }");
298 bounded
= isl_set_is_bounded(set
);
303 /* Construct the basic set { [i] : 5 <= i <= N } */
304 void test_construction(struct isl_ctx
*ctx
)
309 struct isl_basic_set
*bset
;
310 struct isl_constraint
*c
;
314 dim
= isl_space_set_alloc(ctx
, 1, 1);
315 bset
= isl_basic_set_universe(isl_space_copy(dim
));
316 ls
= isl_local_space_from_space(dim
);
318 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
319 isl_int_set_si(v
, -1);
320 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
321 isl_int_set_si(v
, 1);
322 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
323 bset
= isl_basic_set_add_constraint(bset
, c
);
325 c
= isl_inequality_alloc(isl_local_space_copy(ls
));
326 isl_int_set_si(v
, 1);
327 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
328 isl_int_set_si(v
, -5);
329 isl_constraint_set_constant(c
, v
);
330 bset
= isl_basic_set_add_constraint(bset
, c
);
332 isl_local_space_free(ls
);
333 isl_basic_set_free(bset
);
338 void test_dim(struct isl_ctx
*ctx
)
341 isl_map
*map1
, *map2
;
343 map1
= isl_map_read_from_str(ctx
,
344 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
345 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
346 map2
= isl_map_read_from_str(ctx
,
347 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }");
348 assert(isl_map_is_equal(map1
, map2
));
351 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
352 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }");
353 assert(isl_map_is_equal(map1
, map2
));
358 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
359 map1
= isl_map_read_from_str(ctx
, str
);
360 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
361 map2
= isl_map_read_from_str(ctx
, str
);
362 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
363 assert(isl_map_is_equal(map1
, map2
));
370 __isl_give isl_val
*(*op
)(__isl_take isl_val
*v
);
374 { &isl_val_neg
, "0", "0" },
375 { &isl_val_abs
, "0", "0" },
376 { &isl_val_2exp
, "0", "1" },
377 { &isl_val_floor
, "0", "0" },
378 { &isl_val_ceil
, "0", "0" },
379 { &isl_val_neg
, "1", "-1" },
380 { &isl_val_neg
, "-1", "1" },
381 { &isl_val_neg
, "1/2", "-1/2" },
382 { &isl_val_neg
, "-1/2", "1/2" },
383 { &isl_val_neg
, "infty", "-infty" },
384 { &isl_val_neg
, "-infty", "infty" },
385 { &isl_val_neg
, "NaN", "NaN" },
386 { &isl_val_abs
, "1", "1" },
387 { &isl_val_abs
, "-1", "1" },
388 { &isl_val_abs
, "1/2", "1/2" },
389 { &isl_val_abs
, "-1/2", "1/2" },
390 { &isl_val_abs
, "infty", "infty" },
391 { &isl_val_abs
, "-infty", "infty" },
392 { &isl_val_abs
, "NaN", "NaN" },
393 { &isl_val_floor
, "1", "1" },
394 { &isl_val_floor
, "-1", "-1" },
395 { &isl_val_floor
, "1/2", "0" },
396 { &isl_val_floor
, "-1/2", "-1" },
397 { &isl_val_floor
, "infty", "infty" },
398 { &isl_val_floor
, "-infty", "-infty" },
399 { &isl_val_floor
, "NaN", "NaN" },
400 { &isl_val_ceil
, "1", "1" },
401 { &isl_val_ceil
, "-1", "-1" },
402 { &isl_val_ceil
, "1/2", "1" },
403 { &isl_val_ceil
, "-1/2", "0" },
404 { &isl_val_ceil
, "infty", "infty" },
405 { &isl_val_ceil
, "-infty", "-infty" },
406 { &isl_val_ceil
, "NaN", "NaN" },
407 { &isl_val_2exp
, "-3", "1/8" },
408 { &isl_val_2exp
, "-1", "1/2" },
409 { &isl_val_2exp
, "1", "2" },
410 { &isl_val_2exp
, "2", "4" },
411 { &isl_val_2exp
, "3", "8" },
412 { &isl_val_inv
, "1", "1" },
413 { &isl_val_inv
, "2", "1/2" },
414 { &isl_val_inv
, "1/2", "2" },
415 { &isl_val_inv
, "-2", "-1/2" },
416 { &isl_val_inv
, "-1/2", "-2" },
417 { &isl_val_inv
, "0", "NaN" },
418 { &isl_val_inv
, "NaN", "NaN" },
419 { &isl_val_inv
, "infty", "0" },
420 { &isl_val_inv
, "-infty", "0" },
423 /* Perform some basic tests of unary operations on isl_val objects.
425 static int test_un_val(isl_ctx
*ctx
)
429 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v
);
432 for (i
= 0; i
< ARRAY_SIZE(val_un_tests
); ++i
) {
433 v
= isl_val_read_from_str(ctx
, val_un_tests
[i
].arg
);
434 res
= isl_val_read_from_str(ctx
, val_un_tests
[i
].res
);
435 fn
= val_un_tests
[i
].op
;
437 if (isl_val_is_nan(res
))
438 ok
= isl_val_is_nan(v
);
440 ok
= isl_val_eq(v
, res
);
446 isl_die(ctx
, isl_error_unknown
,
447 "unexpected result", return -1);
454 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
455 __isl_take isl_val
*v2
);
457 ['+'] = { &isl_val_add
},
458 ['-'] = { &isl_val_sub
},
459 ['*'] = { &isl_val_mul
},
460 ['/'] = { &isl_val_div
},
461 ['g'] = { &isl_val_gcd
},
462 ['m'] = { &isl_val_min
},
463 ['M'] = { &isl_val_max
},
471 } val_bin_tests
[] = {
472 { "0", '+', "0", "0" },
473 { "1", '+', "0", "1" },
474 { "1", '+', "1", "2" },
475 { "1", '-', "1", "0" },
476 { "1", '*', "1", "1" },
477 { "1", '/', "1", "1" },
478 { "2", '*', "3", "6" },
479 { "2", '*', "1/2", "1" },
480 { "2", '*', "1/3", "2/3" },
481 { "2/3", '*', "3/5", "2/5" },
482 { "2/3", '*', "7/5", "14/15" },
483 { "2", '/', "1/2", "4" },
484 { "-2", '/', "-1/2", "4" },
485 { "-2", '/', "1/2", "-4" },
486 { "2", '/', "-1/2", "-4" },
487 { "2", '/', "2", "1" },
488 { "2", '/', "3", "2/3" },
489 { "2/3", '/', "5/3", "2/5" },
490 { "2/3", '/', "5/7", "14/15" },
491 { "0", '/', "0", "NaN" },
492 { "42", '/', "0", "NaN" },
493 { "-42", '/', "0", "NaN" },
494 { "infty", '/', "0", "NaN" },
495 { "-infty", '/', "0", "NaN" },
496 { "NaN", '/', "0", "NaN" },
497 { "0", '/', "NaN", "NaN" },
498 { "42", '/', "NaN", "NaN" },
499 { "-42", '/', "NaN", "NaN" },
500 { "infty", '/', "NaN", "NaN" },
501 { "-infty", '/', "NaN", "NaN" },
502 { "NaN", '/', "NaN", "NaN" },
503 { "0", '/', "infty", "0" },
504 { "42", '/', "infty", "0" },
505 { "-42", '/', "infty", "0" },
506 { "infty", '/', "infty", "NaN" },
507 { "-infty", '/', "infty", "NaN" },
508 { "NaN", '/', "infty", "NaN" },
509 { "0", '/', "-infty", "0" },
510 { "42", '/', "-infty", "0" },
511 { "-42", '/', "-infty", "0" },
512 { "infty", '/', "-infty", "NaN" },
513 { "-infty", '/', "-infty", "NaN" },
514 { "NaN", '/', "-infty", "NaN" },
515 { "1", '-', "1/3", "2/3" },
516 { "1/3", '+', "1/2", "5/6" },
517 { "1/2", '+', "1/2", "1" },
518 { "3/4", '-', "1/4", "1/2" },
519 { "1/2", '-', "1/3", "1/6" },
520 { "infty", '+', "42", "infty" },
521 { "infty", '+', "infty", "infty" },
522 { "42", '+', "infty", "infty" },
523 { "infty", '-', "infty", "NaN" },
524 { "infty", '*', "infty", "infty" },
525 { "infty", '*', "-infty", "-infty" },
526 { "-infty", '*', "infty", "-infty" },
527 { "-infty", '*', "-infty", "infty" },
528 { "0", '*', "infty", "NaN" },
529 { "1", '*', "infty", "infty" },
530 { "infty", '*', "0", "NaN" },
531 { "infty", '*', "42", "infty" },
532 { "42", '-', "infty", "-infty" },
533 { "infty", '+', "-infty", "NaN" },
534 { "4", 'g', "6", "2" },
535 { "5", 'g', "6", "1" },
536 { "42", 'm', "3", "3" },
537 { "42", 'M', "3", "42" },
538 { "3", 'm', "42", "3" },
539 { "3", 'M', "42", "42" },
540 { "42", 'm', "infty", "42" },
541 { "42", 'M', "infty", "infty" },
542 { "42", 'm', "-infty", "-infty" },
543 { "42", 'M', "-infty", "42" },
544 { "42", 'm', "NaN", "NaN" },
545 { "42", 'M', "NaN", "NaN" },
546 { "infty", 'm', "-infty", "-infty" },
547 { "infty", 'M', "-infty", "infty" },
550 /* Perform some basic tests of binary operations on isl_val objects.
552 static int test_bin_val(isl_ctx
*ctx
)
555 isl_val
*v1
, *v2
, *res
;
556 __isl_give isl_val
*(*fn
)(__isl_take isl_val
*v1
,
557 __isl_take isl_val
*v2
);
560 for (i
= 0; i
< ARRAY_SIZE(val_bin_tests
); ++i
) {
561 v1
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg1
);
562 v2
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].arg2
);
563 res
= isl_val_read_from_str(ctx
, val_bin_tests
[i
].res
);
564 fn
= val_bin_op
[val_bin_tests
[i
].op
].fn
;
566 if (isl_val_is_nan(res
))
567 ok
= isl_val_is_nan(v1
);
569 ok
= isl_val_eq(v1
, res
);
575 isl_die(ctx
, isl_error_unknown
,
576 "unexpected result", return -1);
582 /* Perform some basic tests on isl_val objects.
584 static int test_val(isl_ctx
*ctx
)
586 if (test_un_val(ctx
) < 0)
588 if (test_bin_val(ctx
) < 0)
593 static int test_div(isl_ctx
*ctx
)
602 struct isl_basic_set
*bset
;
603 struct isl_constraint
*c
;
608 dim
= isl_space_set_alloc(ctx
, 0, 3);
609 bset
= isl_basic_set_universe(isl_space_copy(dim
));
610 ls
= isl_local_space_from_space(dim
);
612 c
= isl_equality_alloc(isl_local_space_copy(ls
));
613 isl_int_set_si(v
, -1);
614 isl_constraint_set_constant(c
, v
);
615 isl_int_set_si(v
, 1);
616 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
617 isl_int_set_si(v
, 3);
618 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
619 bset
= isl_basic_set_add_constraint(bset
, c
);
621 c
= isl_equality_alloc(isl_local_space_copy(ls
));
622 isl_int_set_si(v
, 1);
623 isl_constraint_set_constant(c
, v
);
624 isl_int_set_si(v
, -1);
625 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
626 isl_int_set_si(v
, 3);
627 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
628 bset
= isl_basic_set_add_constraint(bset
, c
);
630 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
632 assert(bset
&& bset
->n_div
== 1);
633 isl_local_space_free(ls
);
634 isl_basic_set_free(bset
);
637 dim
= isl_space_set_alloc(ctx
, 0, 3);
638 bset
= isl_basic_set_universe(isl_space_copy(dim
));
639 ls
= isl_local_space_from_space(dim
);
641 c
= isl_equality_alloc(isl_local_space_copy(ls
));
642 isl_int_set_si(v
, 1);
643 isl_constraint_set_constant(c
, v
);
644 isl_int_set_si(v
, -1);
645 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
646 isl_int_set_si(v
, 3);
647 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
648 bset
= isl_basic_set_add_constraint(bset
, c
);
650 c
= isl_equality_alloc(isl_local_space_copy(ls
));
651 isl_int_set_si(v
, -1);
652 isl_constraint_set_constant(c
, v
);
653 isl_int_set_si(v
, 1);
654 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
655 isl_int_set_si(v
, 3);
656 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
657 bset
= isl_basic_set_add_constraint(bset
, c
);
659 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
661 assert(bset
&& bset
->n_div
== 1);
662 isl_local_space_free(ls
);
663 isl_basic_set_free(bset
);
666 dim
= isl_space_set_alloc(ctx
, 0, 3);
667 bset
= isl_basic_set_universe(isl_space_copy(dim
));
668 ls
= isl_local_space_from_space(dim
);
670 c
= isl_equality_alloc(isl_local_space_copy(ls
));
671 isl_int_set_si(v
, 1);
672 isl_constraint_set_constant(c
, v
);
673 isl_int_set_si(v
, -1);
674 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
675 isl_int_set_si(v
, 3);
676 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
677 bset
= isl_basic_set_add_constraint(bset
, c
);
679 c
= isl_equality_alloc(isl_local_space_copy(ls
));
680 isl_int_set_si(v
, -3);
681 isl_constraint_set_constant(c
, v
);
682 isl_int_set_si(v
, 1);
683 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
684 isl_int_set_si(v
, 4);
685 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
686 bset
= isl_basic_set_add_constraint(bset
, c
);
688 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
690 assert(bset
&& bset
->n_div
== 1);
691 isl_local_space_free(ls
);
692 isl_basic_set_free(bset
);
695 dim
= isl_space_set_alloc(ctx
, 0, 3);
696 bset
= isl_basic_set_universe(isl_space_copy(dim
));
697 ls
= isl_local_space_from_space(dim
);
699 c
= isl_equality_alloc(isl_local_space_copy(ls
));
700 isl_int_set_si(v
, 2);
701 isl_constraint_set_constant(c
, v
);
702 isl_int_set_si(v
, -1);
703 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
704 isl_int_set_si(v
, 3);
705 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
706 bset
= isl_basic_set_add_constraint(bset
, c
);
708 c
= isl_equality_alloc(isl_local_space_copy(ls
));
709 isl_int_set_si(v
, -1);
710 isl_constraint_set_constant(c
, v
);
711 isl_int_set_si(v
, 1);
712 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
713 isl_int_set_si(v
, 6);
714 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
715 bset
= isl_basic_set_add_constraint(bset
, c
);
717 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 1, 2);
719 assert(isl_basic_set_is_empty(bset
));
720 isl_local_space_free(ls
);
721 isl_basic_set_free(bset
);
724 dim
= isl_space_set_alloc(ctx
, 0, 3);
725 bset
= isl_basic_set_universe(isl_space_copy(dim
));
726 ls
= isl_local_space_from_space(dim
);
728 c
= isl_equality_alloc(isl_local_space_copy(ls
));
729 isl_int_set_si(v
, -1);
730 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
731 isl_int_set_si(v
, 3);
732 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
733 bset
= isl_basic_set_add_constraint(bset
, c
);
735 c
= isl_equality_alloc(isl_local_space_copy(ls
));
736 isl_int_set_si(v
, 1);
737 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
738 isl_int_set_si(v
, -3);
739 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
740 bset
= isl_basic_set_add_constraint(bset
, c
);
742 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
744 assert(bset
&& bset
->n_div
== 0);
745 isl_basic_set_free(bset
);
746 isl_local_space_free(ls
);
749 dim
= isl_space_set_alloc(ctx
, 0, 3);
750 bset
= isl_basic_set_universe(isl_space_copy(dim
));
751 ls
= isl_local_space_from_space(dim
);
753 c
= isl_equality_alloc(isl_local_space_copy(ls
));
754 isl_int_set_si(v
, -1);
755 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
756 isl_int_set_si(v
, 6);
757 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
758 bset
= isl_basic_set_add_constraint(bset
, c
);
760 c
= isl_equality_alloc(isl_local_space_copy(ls
));
761 isl_int_set_si(v
, 1);
762 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
763 isl_int_set_si(v
, -3);
764 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
765 bset
= isl_basic_set_add_constraint(bset
, c
);
767 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
769 assert(bset
&& bset
->n_div
== 1);
770 isl_basic_set_free(bset
);
771 isl_local_space_free(ls
);
774 /* This test is a bit tricky. We set up an equality
776 * Normalization of divs creates _two_ divs
779 * Afterwards e0 is removed again because it has coefficient -1
780 * and we end up with the original equality and div again.
781 * Perhaps we can avoid the introduction of this temporary div.
783 dim
= isl_space_set_alloc(ctx
, 0, 4);
784 bset
= isl_basic_set_universe(isl_space_copy(dim
));
785 ls
= isl_local_space_from_space(dim
);
787 c
= isl_equality_alloc(isl_local_space_copy(ls
));
788 isl_int_set_si(v
, -1);
789 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
790 isl_int_set_si(v
, -3);
791 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
792 isl_int_set_si(v
, -3);
793 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
794 isl_int_set_si(v
, 6);
795 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
796 bset
= isl_basic_set_add_constraint(bset
, c
);
798 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
800 /* Test disabled for now */
802 assert(bset && bset->n_div == 1);
804 isl_local_space_free(ls
);
805 isl_basic_set_free(bset
);
808 dim
= isl_space_set_alloc(ctx
, 0, 5);
809 bset
= isl_basic_set_universe(isl_space_copy(dim
));
810 ls
= isl_local_space_from_space(dim
);
812 c
= isl_equality_alloc(isl_local_space_copy(ls
));
813 isl_int_set_si(v
, -1);
814 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
815 isl_int_set_si(v
, -3);
816 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
817 isl_int_set_si(v
, -3);
818 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
819 isl_int_set_si(v
, 6);
820 isl_constraint_set_coefficient(c
, isl_dim_set
, 4, v
);
821 bset
= isl_basic_set_add_constraint(bset
, c
);
823 c
= isl_equality_alloc(isl_local_space_copy(ls
));
824 isl_int_set_si(v
, -1);
825 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
826 isl_int_set_si(v
, 1);
827 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
828 isl_int_set_si(v
, 1);
829 isl_constraint_set_constant(c
, v
);
830 bset
= isl_basic_set_add_constraint(bset
, c
);
832 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 4, 1);
834 /* Test disabled for now */
836 assert(bset && bset->n_div == 1);
838 isl_local_space_free(ls
);
839 isl_basic_set_free(bset
);
842 dim
= isl_space_set_alloc(ctx
, 0, 4);
843 bset
= isl_basic_set_universe(isl_space_copy(dim
));
844 ls
= isl_local_space_from_space(dim
);
846 c
= isl_equality_alloc(isl_local_space_copy(ls
));
847 isl_int_set_si(v
, 1);
848 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
849 isl_int_set_si(v
, -1);
850 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
851 isl_int_set_si(v
, -2);
852 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
853 bset
= isl_basic_set_add_constraint(bset
, c
);
855 c
= isl_equality_alloc(isl_local_space_copy(ls
));
856 isl_int_set_si(v
, -1);
857 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
858 isl_int_set_si(v
, 3);
859 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
860 isl_int_set_si(v
, 2);
861 isl_constraint_set_constant(c
, v
);
862 bset
= isl_basic_set_add_constraint(bset
, c
);
864 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 2);
866 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
868 assert(!isl_basic_set_is_empty(bset
));
870 isl_local_space_free(ls
);
871 isl_basic_set_free(bset
);
874 dim
= isl_space_set_alloc(ctx
, 0, 3);
875 bset
= isl_basic_set_universe(isl_space_copy(dim
));
876 ls
= isl_local_space_from_space(dim
);
878 c
= isl_equality_alloc(isl_local_space_copy(ls
));
879 isl_int_set_si(v
, 1);
880 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
881 isl_int_set_si(v
, -2);
882 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
883 bset
= isl_basic_set_add_constraint(bset
, c
);
885 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 2, 1);
887 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
889 isl_local_space_free(ls
);
890 isl_basic_set_free(bset
);
894 str
= "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and "
895 "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }";
896 set
= isl_set_read_from_str(ctx
, str
);
897 set
= isl_set_compute_divs(set
);
902 str
= "{ [i,j] : 2*[i/2] + 3 * [j/4] <= 10 and 2 i = j }";
903 bset
= isl_basic_set_read_from_str(ctx
, str
);
904 n
= isl_basic_set_dim(bset
, isl_dim_div
);
905 isl_basic_set_free(bset
);
909 isl_die(ctx
, isl_error_unknown
,
910 "expecting no existentials", return -1);
912 str
= "{ [i,j,k] : 3 + i + 2j >= 0 and 2 * [(i+2j)/4] <= k }";
913 set
= isl_set_read_from_str(ctx
, str
);
914 set
= isl_set_remove_divs_involving_dims(set
, isl_dim_set
, 0, 2);
915 set
= isl_set_fix_si(set
, isl_dim_set
, 2, -3);
916 empty
= isl_set_is_empty(set
);
921 isl_die(ctx
, isl_error_unknown
,
922 "result not as accurate as expected", return -1);
927 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
931 struct isl_basic_set
*bset1
, *bset2
;
932 struct isl_basic_map
*bmap
;
934 filename
= get_filename(ctx
, name
, "omega");
936 input
= fopen(filename
, "r");
939 bset1
= isl_basic_set_read_from_file(ctx
, input
);
940 bmap
= isl_basic_map_read_from_file(ctx
, input
);
942 bset1
= isl_basic_set_apply(bset1
, bmap
);
944 bset2
= isl_basic_set_read_from_file(ctx
, input
);
946 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
948 isl_basic_set_free(bset1
);
949 isl_basic_set_free(bset2
);
955 void test_application(struct isl_ctx
*ctx
)
957 test_application_case(ctx
, "application");
958 test_application_case(ctx
, "application2");
961 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
965 struct isl_basic_set
*bset1
, *bset2
;
967 filename
= get_filename(ctx
, name
, "polylib");
969 input
= fopen(filename
, "r");
972 bset1
= isl_basic_set_read_from_file(ctx
, input
);
973 bset2
= isl_basic_set_read_from_file(ctx
, input
);
975 bset1
= isl_basic_set_affine_hull(bset1
);
977 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
979 isl_basic_set_free(bset1
);
980 isl_basic_set_free(bset2
);
986 int test_affine_hull(struct isl_ctx
*ctx
)
990 isl_basic_set
*bset
, *bset2
;
994 test_affine_hull_case(ctx
, "affine2");
995 test_affine_hull_case(ctx
, "affine");
996 test_affine_hull_case(ctx
, "affine3");
998 str
= "[m] -> { [i0] : exists (e0, e1: e1 <= 1 + i0 and "
999 "m >= 3 and 4i0 <= 2 + m and e1 >= i0 and "
1000 "e1 >= 0 and e1 <= 2 and e1 >= 1 + 2e0 and "
1001 "2e1 <= 1 + m + 4e0 and 2e1 >= 2 - m + 4i0 - 4e0) }";
1002 set
= isl_set_read_from_str(ctx
, str
);
1003 bset
= isl_set_affine_hull(set
);
1004 n
= isl_basic_set_dim(bset
, isl_dim_div
);
1005 isl_basic_set_free(bset
);
1007 isl_die(ctx
, isl_error_unknown
, "not expecting any divs",
1010 /* Check that isl_map_affine_hull is not confused by
1011 * the reordering of divs in isl_map_align_divs.
1013 str
= "{ [a, b, c, 0] : exists (e0 = [(b)/32], e1 = [(c)/32]: "
1014 "32e0 = b and 32e1 = c); "
1015 "[a, 0, c, 0] : exists (e0 = [(c)/32]: 32e0 = c) }";
1016 set
= isl_set_read_from_str(ctx
, str
);
1017 bset
= isl_set_affine_hull(set
);
1018 isl_basic_set_free(bset
);
1022 str
= "{ [a] : exists e0, e1, e2: 32e1 = 31 + 31a + 31e0 and "
1023 "32e2 = 31 + 31e0 }";
1024 set
= isl_set_read_from_str(ctx
, str
);
1025 bset
= isl_set_affine_hull(set
);
1026 str
= "{ [a] : exists e : a = 32 e }";
1027 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1028 subset
= isl_basic_set_is_subset(bset
, bset2
);
1029 isl_basic_set_free(bset
);
1030 isl_basic_set_free(bset2
);
1034 isl_die(ctx
, isl_error_unknown
, "not as accurate as expected",
1040 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
1044 struct isl_basic_set
*bset1
, *bset2
;
1045 struct isl_set
*set
;
1047 filename
= get_filename(ctx
, name
, "polylib");
1049 input
= fopen(filename
, "r");
1052 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1053 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1055 set
= isl_basic_set_union(bset1
, bset2
);
1056 bset1
= isl_set_convex_hull(set
);
1058 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1060 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1062 isl_basic_set_free(bset1
);
1063 isl_basic_set_free(bset2
);
1072 } convex_hull_tests
[] = {
1073 { "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
1074 "(i0 = 1 and i1 = 0 and i2 = 1) or "
1075 "(i0 = 0 and i1 = 0 and i2 = 0) }",
1076 "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }" },
1077 { "[n] -> { [i0, i1, i0] : i0 <= -4 + n; "
1078 "[i0, i0, i2] : n = 6 and i0 >= 0 and i2 <= 7 - i0 and "
1079 "i2 <= 5 and i2 >= 4; "
1080 "[3, i1, 3] : n = 5 and i1 <= 2 and i1 >= 0 }",
1081 "[n] -> { [i0, i1, i2] : i2 <= -1 + n and 2i2 <= -6 + 3n - i0 and "
1082 "i2 <= 5 + i0 and i2 >= i0 }" },
1083 { "{ [x, y] : 3y <= 2x and y >= -2 + 2x and 2y >= 2 - x }",
1084 "{ [x, y] : 1 = 0 }" },
1087 void test_convex_hull_algo(struct isl_ctx
*ctx
, int convex
)
1090 int orig_convex
= ctx
->opt
->convex
;
1091 ctx
->opt
->convex
= convex
;
1093 test_convex_hull_case(ctx
, "convex0");
1094 test_convex_hull_case(ctx
, "convex1");
1095 test_convex_hull_case(ctx
, "convex2");
1096 test_convex_hull_case(ctx
, "convex3");
1097 test_convex_hull_case(ctx
, "convex4");
1098 test_convex_hull_case(ctx
, "convex5");
1099 test_convex_hull_case(ctx
, "convex6");
1100 test_convex_hull_case(ctx
, "convex7");
1101 test_convex_hull_case(ctx
, "convex8");
1102 test_convex_hull_case(ctx
, "convex9");
1103 test_convex_hull_case(ctx
, "convex10");
1104 test_convex_hull_case(ctx
, "convex11");
1105 test_convex_hull_case(ctx
, "convex12");
1106 test_convex_hull_case(ctx
, "convex13");
1107 test_convex_hull_case(ctx
, "convex14");
1108 test_convex_hull_case(ctx
, "convex15");
1110 for (i
= 0; i
< ARRAY_SIZE(convex_hull_tests
); ++i
) {
1111 isl_set
*set1
, *set2
;
1113 set1
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].set
);
1114 set2
= isl_set_read_from_str(ctx
, convex_hull_tests
[i
].hull
);
1115 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
1116 assert(isl_set_is_equal(set1
, set2
));
1121 ctx
->opt
->convex
= orig_convex
;
1124 void test_convex_hull(struct isl_ctx
*ctx
)
1126 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
);
1127 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
);
1130 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
1134 struct isl_basic_set
*bset1
, *bset2
;
1136 filename
= get_filename(ctx
, name
, "polylib");
1138 input
= fopen(filename
, "r");
1141 bset1
= isl_basic_set_read_from_file(ctx
, input
);
1142 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1144 bset1
= isl_basic_set_gist(bset1
, bset2
);
1146 bset2
= isl_basic_set_read_from_file(ctx
, input
);
1148 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
1150 isl_basic_set_free(bset1
);
1151 isl_basic_set_free(bset2
);
1159 const char *context
;
1162 { "{ [a, b, c] : a <= 15 and a >= 1 }",
1163 "{ [a, b, c] : exists (e0 = floor((-1 + a)/16): a >= 1 and "
1164 "c <= 30 and 32e0 >= -62 + 2a + 2b - c and b >= 0) }",
1165 "{ [a, b, c] : a <= 15 }" },
1166 { "{ : }", "{ : 1 = 0 }", "{ : }" },
1167 { "{ : 1 = 0 }", "{ : 1 = 0 }", "{ : }" },
1168 { "[M] -> { [x] : exists (e0 = floor((-2 + x)/3): 3e0 = -2 + x) }",
1169 "[M] -> { [3M] }" , "[M] -> { [x] : 1 = 0 }" },
1170 { "{ [m, n, a, b] : a <= 2147 + n }",
1171 "{ [m, n, a, b] : (m >= 1 and n >= 1 and a <= 2148 - m and "
1172 "b <= 2148 - n and b >= 0 and b >= 2149 - n - a) or "
1173 "(n >= 1 and a >= 0 and b <= 2148 - n - a and "
1175 "{ [m, n, ku, kl] }" },
1178 static int test_gist(struct isl_ctx
*ctx
)
1182 isl_basic_set
*bset1
, *bset2
;
1183 isl_map
*map1
, *map2
;
1186 for (i
= 0; i
< ARRAY_SIZE(gist_tests
); ++i
) {
1188 isl_set
*set1
, *set2
, *copy
;
1190 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1191 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].context
);
1192 copy
= isl_set_copy(set1
);
1193 set1
= isl_set_gist(set1
, set2
);
1194 set2
= isl_set_read_from_str(ctx
, gist_tests
[i
].gist
);
1195 equal
= isl_set_is_equal(set1
, set2
);
1198 set1
= isl_set_read_from_str(ctx
, gist_tests
[i
].set
);
1199 equal_input
= isl_set_is_equal(set1
, copy
);
1202 if (equal
< 0 || equal_input
< 0)
1205 isl_die(ctx
, isl_error_unknown
,
1206 "incorrect gist result", return -1);
1208 isl_die(ctx
, isl_error_unknown
,
1209 "gist modified input", return -1);
1212 test_gist_case(ctx
, "gist1");
1214 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
1215 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
1216 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
1217 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
1218 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
1219 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
1220 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
1221 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
1222 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
1223 bset1
= isl_basic_set_read_from_str(ctx
, str
);
1224 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
1225 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
1226 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
1227 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
1228 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
1229 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
1230 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
1231 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
1232 bset2
= isl_basic_set_read_from_str(ctx
, str
);
1233 bset1
= isl_basic_set_gist(bset1
, bset2
);
1234 assert(bset1
&& bset1
->n_div
== 0);
1235 isl_basic_set_free(bset1
);
1237 /* Check that the integer divisions of the second disjunct
1238 * do not spread to the first disjunct.
1240 str
= "[t1] -> { S_0[] -> A[o0] : (exists (e0 = [(-t1 + o0)/16]: "
1241 "16e0 = -t1 + o0 and o0 >= 0 and o0 <= 15 and t1 >= 0)) or "
1242 "(exists (e0 = [(-1 + t1)/16], "
1243 "e1 = [(-16 + t1 - 16e0)/4294967296]: "
1244 "4294967296e1 = -16 + t1 - o0 - 16e0 and "
1245 "16e0 <= -1 + t1 and 16e0 >= -16 + t1 and o0 >= 0 and "
1246 "o0 <= 4294967295 and t1 <= -1)) }";
1247 map1
= isl_map_read_from_str(ctx
, str
);
1248 str
= "[t1] -> { S_0[] -> A[o0] : t1 >= 0 and t1 <= 4294967295 }";
1249 map2
= isl_map_read_from_str(ctx
, str
);
1250 map1
= isl_map_gist(map1
, map2
);
1254 isl_die(ctx
, isl_error_unknown
, "expecting single disjunct",
1255 isl_map_free(map1
); return -1);
1256 if (isl_basic_map_dim(map1
->p
[0], isl_dim_div
) != 1)
1257 isl_die(ctx
, isl_error_unknown
, "expecting single div",
1258 isl_map_free(map1
); return -1);
1264 int test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
1266 isl_set
*set
, *set2
;
1270 set
= isl_set_read_from_str(ctx
, str
);
1271 set
= isl_set_coalesce(set
);
1272 set2
= isl_set_read_from_str(ctx
, str
);
1273 equal
= isl_set_is_equal(set
, set2
);
1274 one
= set
&& set
->n
== 1;
1281 isl_die(ctx
, isl_error_unknown
,
1282 "coalesced set not equal to input", return -1);
1283 if (check_one
&& !one
)
1284 isl_die(ctx
, isl_error_unknown
,
1285 "coalesced set should not be a union", return -1);
1290 /* Inputs for coalescing tests with unbounded wrapping.
1291 * "str" is a string representation of the input set.
1292 * "single_disjunct" is set if we expect the result to consist of
1293 * a single disjunct.
1296 int single_disjunct
;
1298 } coalesce_unbounded_tests
[] = {
1299 { 1, "{ [x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
1300 "-x - y + 1 >= 0 and -3 <= z <= 3;"
1301 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
1302 "x-z + 20 >= 0 and x+z + 20 >= 0 and "
1304 { 1, "{ [x,y] : 0 <= x,y <= 10; [5,y]: 4 <= y <= 11 }" },
1305 { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" },
1306 { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" },
1307 { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" },
1310 /* Test the functionality of isl_set_coalesce with the bounded wrapping
1311 * option turned off.
1313 int test_coalesce_unbounded_wrapping(isl_ctx
*ctx
)
1319 bounded
= isl_options_get_coalesce_bounded_wrapping(ctx
);
1320 isl_options_set_coalesce_bounded_wrapping(ctx
, 0);
1322 for (i
= 0; i
< ARRAY_SIZE(coalesce_unbounded_tests
); ++i
) {
1323 const char *str
= coalesce_unbounded_tests
[i
].str
;
1324 int check_one
= coalesce_unbounded_tests
[i
].single_disjunct
;
1325 if (test_coalesce_set(ctx
, str
, check_one
) >= 0)
1331 isl_options_set_coalesce_bounded_wrapping(ctx
, bounded
);
1336 /* Inputs for coalescing tests.
1337 * "str" is a string representation of the input set.
1338 * "single_disjunct" is set if we expect the result to consist of
1339 * a single disjunct.
1342 int single_disjunct
;
1344 } coalesce_tests
[] = {
1345 { 1, "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
1346 "y >= x & x >= 2 & 5 >= y }" },
1347 { 1, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1348 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}" },
1349 { 0, "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
1350 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}" },
1351 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1352 "y >= 0 & x >= 6 & x <= 10 & y <= x}" },
1353 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1354 "y >= 0 & x >= 7 & x <= 10 & y <= x}" },
1355 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or "
1356 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}" },
1357 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 6}" },
1358 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 7 & y <= 6}" },
1359 { 1, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 5}" },
1360 { 0, "{[x,y]: y >= 0 & x <= 5 & y <= x or y >= 0 & x = 6 & y <= 7}" },
1361 { 1, "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }" },
1362 { 0, "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}" },
1363 { 1, "[n] -> { [i] : 1 <= i and i <= n - 1 or 2 <= i and i <= n }" },
1364 { 0, "[n] -> { [[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1365 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1366 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1367 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
1368 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
1369 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
1370 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
1371 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
1372 "[[i0] -> [o0]] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
1373 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
1374 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
1375 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
1376 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
1377 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
1378 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
1379 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
1380 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
1381 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }" },
1382 { 0, "[n, m] -> { [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
1383 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
1384 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
1385 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }" },
1386 { 0, "[M, N] -> { [[i0, i1, i2, i3, i4, i5, i6] -> "
1387 "[o0, o1, o2, o3, o4, o5, o6]] : "
1388 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
1389 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
1390 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
1391 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
1392 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
1393 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
1394 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
1395 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
1396 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
1397 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
1398 "o6 >= i3 + i6 - o3 and M >= 0 and "
1399 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
1400 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }" },
1401 { 0, "[M, N] -> { [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
1402 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
1403 "(o0 = 0 and M >= 2 and N >= 3) or "
1404 "(M = 0 and o0 = 0 and N >= 3) }" },
1405 { 0, "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
1406 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
1407 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
1408 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }" },
1409 { 0, "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or (i1 = M and M >= 1) }" },
1410 { 0, "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }" },
1411 { 1, "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
1412 "(y = 3 and x = 1) }" },
1413 { 1, "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
1414 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
1415 "i1 <= M and i3 <= M and i4 <= M) or "
1416 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
1417 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
1418 "i4 <= -1 + M) }" },
1419 { 1, "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
1420 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }" },
1421 { 0, "{[x,0] : x >= 0; [x,1] : x <= 20}" },
1422 { 1, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }" },
1423 { 1, "{ [0,0]; [i,i] : 1 <= i <= 10 }" },
1424 { 0, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }" },
1425 { 1, "{ [0,0]; [i,2i] : 1 <= i <= 10 }" },
1426 { 0, "{ [0,0]; [i,2i] : 2 <= i <= 10 }" },
1427 { 0, "{ [1,0]; [i,2i] : 1 <= i <= 10 }" },
1428 { 0, "{ [0,1]; [i,2i] : 1 <= i <= 10 }" },
1429 { 0, "{ [a, b] : exists e : 2e = a and "
1430 "a >= 0 and (a <= 3 or (b <= 0 and b >= -4 + a)) }" },
1431 { 0, "{ [i, j, i', j'] : i <= 2 and j <= 2 and "
1432 "j' >= -1 + 2i + j - 2i' and i' <= -1 + i and "
1433 "j >= 1 and j' <= i + j - i' and i >= 1; "
1435 { 1, "{ [i,j] : exists a,b : i = 2a and j = 3b; "
1436 "[i,j] : exists a : j = 3a }" },
1437 { 1, "{ [a, b, c] : (c <= 7 - b and b <= 1 and b >= 0 and "
1438 "c >= 3 + b and b <= 3 + 8a and b >= -26 + 8a and "
1440 "(b <= 1 and c <= 7 and b >= 0 and c >= 4 + b and "
1441 "b <= 3 + 8a and b >= -26 + 8a and a >= 3) }" },
1442 { 1, "{ [a, 0, c] : c >= 1 and c <= 29 and c >= -1 + 8a and "
1443 "c <= 6 + 8a and a >= 3; "
1444 "[a, -1, c] : c >= 1 and c <= 30 and c >= 8a and "
1445 "c <= 7 + 8a and a >= 3 and a <= 4 }" },
1446 { 1, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1447 "[x,0] : 3 <= x <= 4 }" },
1448 { 1, "{ [x,y] : 0 <= x <= 3 and y >= 0 and x + 3y <= 6; "
1449 "[x,0] : 4 <= x <= 5 }" },
1450 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + 2y <= 4; "
1451 "[x,0] : 3 <= x <= 5 }" },
1452 { 0, "{ [x,y] : 0 <= x <= 2 and y >= 0 and x + y <= 4; "
1453 "[x,0] : 3 <= x <= 4 }" },
1454 { 1, "{ [i0, i1] : i0 <= 122 and i0 >= 1 and 128i1 >= -249 + i0 and "
1456 "[i0, 0] : i0 >= 123 and i0 <= 124 }" },
1457 { 1, "{ [0,0]; [1,1] }" },
1458 { 1, "[n] -> { [k] : 16k <= -1 + n and k >= 1; [0] : n >= 2 }" },
1459 { 1, "{ [k, ii, k - ii] : ii >= -6 + k and ii <= 6 and ii >= 1 and "
1461 "[k, 0, k] : k <= 6 and k >= 1 }" },
1462 { 1, "{ [i,j] : i = 4 j and 0 <= i <= 100;"
1463 "[i,j] : 1 <= i <= 100 and i >= 4j + 1 and i <= 4j + 2 }" },
1464 { 1, "{ [x,y] : x % 2 = 0 and y % 2 = 0; [x,x] : x % 2 = 0 }" },
1465 { 1, "[n] -> { [1] : n >= 0;"
1466 "[x] : exists (e0 = floor((x)/2): x >= 2 and "
1467 "2e0 >= -1 + x and 2e0 <= x and 2e0 <= n) }" },
1468 { 1, "[n] -> { [x, y] : exists (e0 = floor((x)/2), e1 = floor((y)/3): "
1469 "3e1 = y and x >= 2 and 2e0 >= -1 + x and "
1470 "2e0 <= x and 2e0 <= n);"
1471 "[1, y] : exists (e0 = floor((y)/3): 3e0 = y and "
1473 { 1, "[t1] -> { [i0] : (exists (e0 = floor((63t1)/64): "
1474 "128e0 >= -134 + 127t1 and t1 >= 2 and "
1475 "64e0 <= 63t1 and 64e0 >= -63 + 63t1)) or "
1477 { 1, "{ [i, i] : exists (e0 = floor((1 + 2i)/3): 3e0 <= 2i and "
1478 "3e0 >= -1 + 2i and i <= 9 and i >= 1);"
1480 { 1, "{ [t1] : exists (e0 = floor((-11 + t1)/2): 2e0 = -11 + t1 and "
1481 "t1 >= 13 and t1 <= 16);"
1482 "[t1] : t1 <= 15 and t1 >= 12 }" },
1483 { 1, "{ [x,y] : x = 3y and 0 <= y <= 2; [-3,-1] }" },
1484 { 1, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-2] }" },
1485 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-2,-2] }" },
1486 { 0, "{ [x,y] : 2x = 3y and 0 <= y <= 4; [-3,-1] }" },
1487 { 1, "{ [i] : exists j : i = 4 j and 0 <= i <= 100;"
1488 "[i] : exists j : 1 <= i <= 100 and i >= 4j + 1 and "
1490 { 1, "{ [c0] : (exists (e0 : c0 - 1 <= 3e0 <= c0)) or "
1491 "(exists (e0 : 3e0 = -2 + c0)) }" },
1494 /* Test the functionality of isl_set_coalesce.
1495 * That is, check that the output is always equal to the input
1496 * and in some cases that the result consists of a single disjunct.
1498 static int test_coalesce(struct isl_ctx
*ctx
)
1502 for (i
= 0; i
< ARRAY_SIZE(coalesce_tests
); ++i
) {
1503 const char *str
= coalesce_tests
[i
].str
;
1504 int check_one
= coalesce_tests
[i
].single_disjunct
;
1505 if (test_coalesce_set(ctx
, str
, check_one
) < 0)
1509 if (test_coalesce_unbounded_wrapping(ctx
) < 0)
1515 void test_closure(struct isl_ctx
*ctx
)
1519 isl_map
*up
, *right
;
1520 isl_map
*map
, *map2
;
1523 /* COCOA example 1 */
1524 map
= isl_map_read_from_str(ctx
,
1525 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1526 "1 <= i and i < n and 1 <= j and j < n or "
1527 "i2 = i + 1 and j2 = j - 1 and "
1528 "1 <= i and i < n and 2 <= j and j <= n }");
1529 map
= isl_map_power(map
, &exact
);
1533 /* COCOA example 1 */
1534 map
= isl_map_read_from_str(ctx
,
1535 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
1536 "1 <= i and i < n and 1 <= j and j < n or "
1537 "i2 = i + 1 and j2 = j - 1 and "
1538 "1 <= i and i < n and 2 <= j and j <= n }");
1539 map
= isl_map_transitive_closure(map
, &exact
);
1541 map2
= isl_map_read_from_str(ctx
,
1542 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1543 "1 <= i and i < n and 1 <= j and j <= n and "
1544 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1545 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
1546 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}");
1547 assert(isl_map_is_equal(map
, map2
));
1551 map
= isl_map_read_from_str(ctx
,
1552 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1553 " 0 <= y and y <= n }");
1554 map
= isl_map_transitive_closure(map
, &exact
);
1555 map2
= isl_map_read_from_str(ctx
,
1556 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1557 " 0 <= y and y <= n }");
1558 assert(isl_map_is_equal(map
, map2
));
1562 /* COCOA example 2 */
1563 map
= isl_map_read_from_str(ctx
,
1564 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1565 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1566 "i2 = i + 2 and j2 = j - 2 and "
1567 "1 <= i and i < n - 1 and 3 <= j and j <= n }");
1568 map
= isl_map_transitive_closure(map
, &exact
);
1570 map2
= isl_map_read_from_str(ctx
,
1571 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1572 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1573 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1574 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1575 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }");
1576 assert(isl_map_is_equal(map
, map2
));
1580 /* COCOA Fig.2 left */
1581 map
= isl_map_read_from_str(ctx
,
1582 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1583 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1585 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1586 "j <= 2 i - 3 and j <= n - 2 or "
1587 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1588 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1589 map
= isl_map_transitive_closure(map
, &exact
);
1593 /* COCOA Fig.2 right */
1594 map
= isl_map_read_from_str(ctx
,
1595 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1596 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1598 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1599 "j <= 2 i - 4 and j <= n - 3 or "
1600 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1601 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1602 map
= isl_map_power(map
, &exact
);
1606 /* COCOA Fig.2 right */
1607 map
= isl_map_read_from_str(ctx
,
1608 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1609 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1611 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1612 "j <= 2 i - 4 and j <= n - 3 or "
1613 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1614 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }");
1615 map
= isl_map_transitive_closure(map
, &exact
);
1617 map2
= isl_map_read_from_str(ctx
,
1618 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1619 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1620 "j <= n and 3 + i + 2 j <= 3 n and "
1621 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1622 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1623 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1624 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1625 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }");
1626 assert(isl_map_is_equal(map
, map2
));
1630 /* COCOA Fig.1 right */
1631 dom
= isl_set_read_from_str(ctx
,
1632 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1633 "2 x - 3 y + 3 >= 0 }");
1634 right
= isl_map_read_from_str(ctx
,
1635 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }");
1636 up
= isl_map_read_from_str(ctx
,
1637 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }");
1638 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1639 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1640 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1641 up
= isl_map_intersect_range(up
, dom
);
1642 map
= isl_map_union(up
, right
);
1643 map
= isl_map_transitive_closure(map
, &exact
);
1645 map2
= isl_map_read_from_str(ctx
,
1646 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1647 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }");
1648 assert(isl_map_is_equal(map
, map2
));
1652 /* COCOA Theorem 1 counter example */
1653 map
= isl_map_read_from_str(ctx
,
1654 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1655 "i2 = 1 and j2 = j or "
1656 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }");
1657 map
= isl_map_transitive_closure(map
, &exact
);
1661 map
= isl_map_read_from_str(ctx
,
1662 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1663 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1664 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1665 "1 <= i,i2 <= n and 1 <= j,j2 <= m }");
1666 map
= isl_map_transitive_closure(map
, &exact
);
1670 /* Kelly et al 1996, fig 12 */
1671 map
= isl_map_read_from_str(ctx
,
1672 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1673 "1 <= i,j,j+1 <= n or "
1674 "j = n and j2 = 1 and i2 = i + 1 and "
1675 "1 <= i,i+1 <= n }");
1676 map
= isl_map_transitive_closure(map
, &exact
);
1678 map2
= isl_map_read_from_str(ctx
,
1679 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1680 "1 <= i <= n and i = i2 or "
1681 "1 <= i < i2 <= n and 1 <= j <= n and "
1683 assert(isl_map_is_equal(map
, map2
));
1687 /* Omega's closure4 */
1688 map
= isl_map_read_from_str(ctx
,
1689 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1690 "1 <= x,y <= 10 or "
1691 "x2 = x + 1 and y2 = y and "
1692 "1 <= x <= 20 && 5 <= y <= 15 }");
1693 map
= isl_map_transitive_closure(map
, &exact
);
1697 map
= isl_map_read_from_str(ctx
,
1698 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }");
1699 map
= isl_map_transitive_closure(map
, &exact
);
1701 map2
= isl_map_read_from_str(ctx
,
1702 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }");
1703 assert(isl_map_is_equal(map
, map2
));
1707 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1708 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1709 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1710 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1711 map
= isl_map_read_from_str(ctx
, str
);
1712 map
= isl_map_transitive_closure(map
, &exact
);
1714 map2
= isl_map_read_from_str(ctx
, str
);
1715 assert(isl_map_is_equal(map
, map2
));
1719 str
= "{[0] -> [1]; [2] -> [3]}";
1720 map
= isl_map_read_from_str(ctx
, str
);
1721 map
= isl_map_transitive_closure(map
, &exact
);
1723 map2
= isl_map_read_from_str(ctx
, str
);
1724 assert(isl_map_is_equal(map
, map2
));
1728 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1729 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1730 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1731 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1732 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1733 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1734 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1735 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1736 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1737 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1738 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1739 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1740 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1741 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1742 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1743 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1744 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1745 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1746 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1747 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1748 map
= isl_map_read_from_str(ctx
, str
);
1749 map
= isl_map_transitive_closure(map
, NULL
);
1754 void test_lex(struct isl_ctx
*ctx
)
1759 dim
= isl_space_set_alloc(ctx
, 0, 0);
1760 map
= isl_map_lex_le(dim
);
1761 assert(!isl_map_is_empty(map
));
1765 static int test_lexmin(struct isl_ctx
*ctx
)
1769 isl_basic_map
*bmap
;
1770 isl_map
*map
, *map2
;
1773 isl_pw_multi_aff
*pma
;
1775 str
= "[p0, p1] -> { [] -> [] : "
1776 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1777 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1778 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1779 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1780 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1781 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1782 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1783 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1784 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1785 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1786 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1787 map
= isl_map_read_from_str(ctx
, str
);
1788 map
= isl_map_lexmin(map
);
1791 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1792 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1793 set
= isl_set_read_from_str(ctx
, str
);
1794 set
= isl_set_lexmax(set
);
1795 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1796 set2
= isl_set_read_from_str(ctx
, str
);
1797 set
= isl_set_intersect(set
, set2
);
1798 assert(!isl_set_is_empty(set
));
1801 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1802 map
= isl_map_read_from_str(ctx
, str
);
1803 map
= isl_map_lexmin(map
);
1804 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1805 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1806 map2
= isl_map_read_from_str(ctx
, str
);
1807 assert(isl_map_is_equal(map
, map2
));
1811 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1812 map
= isl_map_read_from_str(ctx
, str
);
1813 map2
= isl_map_copy(map
);
1814 map
= isl_map_lexmin(map
);
1815 assert(isl_map_is_equal(map
, map2
));
1819 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1820 map
= isl_map_read_from_str(ctx
, str
);
1821 map
= isl_map_lexmin(map
);
1822 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1823 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1824 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1825 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1826 map2
= isl_map_read_from_str(ctx
, str
);
1827 assert(isl_map_is_equal(map
, map2
));
1831 str
= "{ [i] -> [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1832 " 8i' <= i and 8i' >= -7 + i }";
1833 bmap
= isl_basic_map_read_from_str(ctx
, str
);
1834 pma
= isl_basic_map_lexmin_pw_multi_aff(isl_basic_map_copy(bmap
));
1835 map2
= isl_map_from_pw_multi_aff(pma
);
1836 map
= isl_map_from_basic_map(bmap
);
1837 assert(isl_map_is_equal(map
, map2
));
1841 str
= "{ T[a] -> S[b, c] : a = 4b-2c and c >= b }";
1842 map
= isl_map_read_from_str(ctx
, str
);
1843 map
= isl_map_lexmin(map
);
1844 str
= "{ T[a] -> S[b, c] : 2b = a and 2c = a }";
1845 map2
= isl_map_read_from_str(ctx
, str
);
1846 assert(isl_map_is_equal(map
, map2
));
1850 /* Check that empty pieces are properly combined. */
1851 str
= "[K, N] -> { [x, y] -> [a, b] : K+2<=N<=K+4 and x>=4 and "
1852 "2N-6<=x<K+N and N-1<=a<=K+N-1 and N+b-6<=a<=2N-4 and "
1853 "b<=2N-3K+a and 3b<=4N-K+1 and b>=N and a>=x+1 }";
1854 map
= isl_map_read_from_str(ctx
, str
);
1855 map
= isl_map_lexmin(map
);
1856 str
= "[K, N] -> { [x, y] -> [1 + x, N] : x >= -6 + 2N and "
1857 "x <= -5 + 2N and x >= -1 + 3K - N and x <= -2 + K + N and "
1859 map2
= isl_map_read_from_str(ctx
, str
);
1860 assert(isl_map_is_equal(map
, map2
));
1864 str
= "[i] -> { [i', j] : j = i - 8i' and i' >= 0 and i' <= 7 and "
1865 " 8i' <= i and 8i' >= -7 + i }";
1866 set
= isl_set_read_from_str(ctx
, str
);
1867 pma
= isl_set_lexmin_pw_multi_aff(isl_set_copy(set
));
1868 set2
= isl_set_from_pw_multi_aff(pma
);
1869 equal
= isl_set_is_equal(set
, set2
);
1875 isl_die(ctx
, isl_error_unknown
,
1876 "unexpected difference between set and "
1877 "piecewise affine expression", return -1);
1882 /* Check that isl_set_min_val and isl_set_max_val compute the correct
1883 * result on non-convex inputs.
1885 static int test_min(struct isl_ctx
*ctx
)
1892 set
= isl_set_read_from_str(ctx
, "{ [-1]; [1] }");
1893 aff
= isl_aff_read_from_str(ctx
, "{ [x] -> [x] }");
1894 val
= isl_set_min_val(set
, aff
);
1895 min_ok
= isl_val_is_negone(val
);
1897 val
= isl_set_max_val(set
, aff
);
1898 max_ok
= isl_val_is_one(val
);
1903 if (min_ok
< 0 || max_ok
< 0)
1906 isl_die(ctx
, isl_error_unknown
,
1907 "unexpected minimum", return -1);
1909 isl_die(ctx
, isl_error_unknown
,
1910 "unexpected maximum", return -1);
1920 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1921 void *dep_user
, void *user
)
1923 struct must_may
*mm
= (struct must_may
*)user
;
1926 mm
->must
= isl_map_union(mm
->must
, dep
);
1928 mm
->may
= isl_map_union(mm
->may
, dep
);
1933 static int common_space(void *first
, void *second
)
1935 int depth
= *(int *)first
;
1939 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1947 map2
= isl_map_read_from_str(map
->ctx
, str
);
1948 equal
= isl_map_is_equal(map
, map2
);
1954 static int map_check_equal(__isl_keep isl_map
*map
, const char *str
)
1958 equal
= map_is_equal(map
, str
);
1962 isl_die(isl_map_get_ctx(map
), isl_error_unknown
,
1963 "result not as expected", return -1);
1967 void test_dep(struct isl_ctx
*ctx
)
1972 isl_access_info
*ai
;
1979 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1980 map
= isl_map_read_from_str(ctx
, str
);
1981 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1983 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1984 map
= isl_map_read_from_str(ctx
, str
);
1985 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1987 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1988 map
= isl_map_read_from_str(ctx
, str
);
1989 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1991 flow
= isl_access_info_compute_flow(ai
);
1992 dim
= isl_space_alloc(ctx
, 0, 3, 3);
1993 mm
.must
= isl_map_empty(isl_space_copy(dim
));
1994 mm
.may
= isl_map_empty(dim
);
1996 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1998 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1999 " [1,10,0] -> [2,5,0] }";
2000 assert(map_is_equal(mm
.must
, str
));
2001 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2002 assert(map_is_equal(mm
.may
, str
));
2004 isl_map_free(mm
.must
);
2005 isl_map_free(mm
.may
);
2006 isl_flow_free(flow
);
2009 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2010 map
= isl_map_read_from_str(ctx
, str
);
2011 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2013 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2014 map
= isl_map_read_from_str(ctx
, str
);
2015 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2017 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2018 map
= isl_map_read_from_str(ctx
, str
);
2019 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2021 flow
= isl_access_info_compute_flow(ai
);
2022 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2023 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2024 mm
.may
= isl_map_empty(dim
);
2026 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2028 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
2029 assert(map_is_equal(mm
.must
, str
));
2030 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2031 assert(map_is_equal(mm
.may
, str
));
2033 isl_map_free(mm
.must
);
2034 isl_map_free(mm
.may
);
2035 isl_flow_free(flow
);
2038 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
2039 map
= isl_map_read_from_str(ctx
, str
);
2040 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2042 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2043 map
= isl_map_read_from_str(ctx
, str
);
2044 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2046 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
2047 map
= isl_map_read_from_str(ctx
, str
);
2048 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2050 flow
= isl_access_info_compute_flow(ai
);
2051 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2052 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2053 mm
.may
= isl_map_empty(dim
);
2055 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2057 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
2058 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
2059 assert(map_is_equal(mm
.may
, str
));
2060 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2061 assert(map_is_equal(mm
.must
, str
));
2063 isl_map_free(mm
.must
);
2064 isl_map_free(mm
.may
);
2065 isl_flow_free(flow
);
2068 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
2069 map
= isl_map_read_from_str(ctx
, str
);
2070 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2072 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2073 map
= isl_map_read_from_str(ctx
, str
);
2074 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2076 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
2077 map
= isl_map_read_from_str(ctx
, str
);
2078 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2080 flow
= isl_access_info_compute_flow(ai
);
2081 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2082 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2083 mm
.may
= isl_map_empty(dim
);
2085 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2087 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
2088 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
2089 assert(map_is_equal(mm
.may
, str
));
2090 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2091 assert(map_is_equal(mm
.must
, str
));
2093 isl_map_free(mm
.must
);
2094 isl_map_free(mm
.may
);
2095 isl_flow_free(flow
);
2098 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
2099 map
= isl_map_read_from_str(ctx
, str
);
2100 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
2102 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
2103 map
= isl_map_read_from_str(ctx
, str
);
2104 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2106 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
2107 map
= isl_map_read_from_str(ctx
, str
);
2108 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
2110 flow
= isl_access_info_compute_flow(ai
);
2111 dim
= isl_space_alloc(ctx
, 0, 3, 3);
2112 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2113 mm
.may
= isl_map_empty(dim
);
2115 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2117 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
2118 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
2119 assert(map_is_equal(mm
.may
, str
));
2120 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
2121 assert(map_is_equal(mm
.must
, str
));
2123 isl_map_free(mm
.must
);
2124 isl_map_free(mm
.may
);
2125 isl_flow_free(flow
);
2130 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2131 map
= isl_map_read_from_str(ctx
, str
);
2132 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
2134 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
2135 map
= isl_map_read_from_str(ctx
, str
);
2136 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
2138 flow
= isl_access_info_compute_flow(ai
);
2139 dim
= isl_space_alloc(ctx
, 0, 5, 5);
2140 mm
.must
= isl_map_empty(isl_space_copy(dim
));
2141 mm
.may
= isl_map_empty(dim
);
2143 isl_flow_foreach(flow
, collect_must_may
, &mm
);
2145 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
2146 assert(map_is_equal(mm
.must
, str
));
2147 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
2148 assert(map_is_equal(mm
.may
, str
));
2150 isl_map_free(mm
.must
);
2151 isl_map_free(mm
.may
);
2152 isl_flow_free(flow
);
2155 /* Check that the dependence analysis proceeds without errors.
2156 * Earlier versions of isl would break down during the analysis
2157 * due to the use of the wrong spaces.
2159 static int test_flow(isl_ctx
*ctx
)
2162 isl_union_map
*access
, *schedule
;
2163 isl_union_map
*must_dep
, *may_dep
;
2166 str
= "{ S0[j] -> i[]; S1[j,i] -> i[]; S2[] -> i[]; S3[] -> i[] }";
2167 access
= isl_union_map_read_from_str(ctx
, str
);
2168 str
= "{ S0[j] -> [0,j,0,0] : 0 <= j < 10; "
2169 "S1[j,i] -> [0,j,1,i] : 0 <= j < i < 10; "
2170 "S2[] -> [1,0,0,0]; "
2171 "S3[] -> [-1,0,0,0] }";
2172 schedule
= isl_union_map_read_from_str(ctx
, str
);
2173 r
= isl_union_map_compute_flow(access
, isl_union_map_copy(access
),
2174 isl_union_map_copy(access
), schedule
,
2175 &must_dep
, &may_dep
, NULL
, NULL
);
2176 isl_union_map_free(may_dep
);
2177 isl_union_map_free(must_dep
);
2186 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }", 1 },
2187 { "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }", 0 },
2188 { "{ [i] -> [3*floor(i/2) + 5*floor(i/3)] }", 1 },
2189 { "{ S1[i] -> [i] : 0 <= i <= 9; S2[i] -> [i] : 0 <= i <= 9 }", 1 },
2190 { "{ [i] -> S1[i] : 0 <= i <= 9; [i] -> S2[i] : 0 <= i <= 9 }", 0 },
2191 { "{ A[i] -> [i]; B[i] -> [i]; B[i] -> [i + 1] }", 0 },
2192 { "{ A[i] -> [i]; B[i] -> [i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2193 { "{ A[i] -> [i]; B[i] -> A[i] : i < 0; B[i] -> [i + 1] : i > 0 }", 1 },
2194 { "{ A[i] -> [i]; B[i] -> [j] : i - 1 <= j <= i }", 0 },
2197 int test_sv(isl_ctx
*ctx
)
2199 isl_union_map
*umap
;
2203 for (i
= 0; i
< ARRAY_SIZE(sv_tests
); ++i
) {
2204 umap
= isl_union_map_read_from_str(ctx
, sv_tests
[i
].map
);
2205 sv
= isl_union_map_is_single_valued(umap
);
2206 isl_union_map_free(umap
);
2209 if (sv_tests
[i
].sv
&& !sv
)
2210 isl_die(ctx
, isl_error_internal
,
2211 "map not detected as single valued", return -1);
2212 if (!sv_tests
[i
].sv
&& sv
)
2213 isl_die(ctx
, isl_error_internal
,
2214 "map detected as single valued", return -1);
2220 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
2224 map
= isl_map_read_from_str(ctx
, str
);
2226 assert(isl_map_is_bijective(map
));
2228 assert(!isl_map_is_bijective(map
));
2232 void test_bijective(struct isl_ctx
*ctx
)
2234 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
2235 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
2236 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
2237 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
2238 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
2239 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
2240 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
2241 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
2242 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
2243 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
2244 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
2245 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
2246 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
2249 /* Inputs for isl_pw_qpolynomial_gist tests.
2250 * "pwqp" is the input, "set" is the context and "gist" is the expected result.
2256 } pwqp_gist_tests
[] = {
2257 { "{ [i] -> i }", "{ [k] : exists a : k = 2a }", "{ [i] -> i }" },
2258 { "{ [i] -> i + [ (i + [i/3])/2 ] }", "{ [10] }", "{ [i] -> 16 }" },
2259 { "{ [i] -> ([(i)/2]) }", "{ [k] : exists a : k = 2a+1 }",
2260 "{ [i] -> -1/2 + 1/2 * i }" },
2261 { "{ [i] -> i^2 : i != 0 }", "{ [i] : i != 0 }", "{ [i] -> i^2 }" },
2264 static int test_pwqp(struct isl_ctx
*ctx
)
2269 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
2272 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2273 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2275 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
2278 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
2279 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2281 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2283 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2285 isl_pw_qpolynomial_free(pwqp1
);
2287 for (i
= 0; i
< ARRAY_SIZE(pwqp_gist_tests
); ++i
) {
2288 str
= pwqp_gist_tests
[i
].pwqp
;
2289 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2290 str
= pwqp_gist_tests
[i
].set
;
2291 set
= isl_set_read_from_str(ctx
, str
);
2292 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
2293 str
= pwqp_gist_tests
[i
].gist
;
2294 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2295 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2296 equal
= isl_pw_qpolynomial_is_zero(pwqp1
);
2297 isl_pw_qpolynomial_free(pwqp1
);
2302 isl_die(ctx
, isl_error_unknown
,
2303 "unexpected result", return -1);
2306 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
2307 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2308 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
2309 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2311 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2313 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2315 isl_pw_qpolynomial_free(pwqp1
);
2317 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
2318 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2319 str
= "{ [x] -> x }";
2320 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2322 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2324 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2326 isl_pw_qpolynomial_free(pwqp1
);
2328 str
= "{ [i] -> ([i/2]) : i >= 0; [i] -> ([i/3]) : i < 0 }";
2329 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2330 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2331 pwqp1
= isl_pw_qpolynomial_coalesce(pwqp1
);
2332 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
2333 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
2334 isl_pw_qpolynomial_free(pwqp1
);
2336 str
= "{ [a,b,a] -> (([(2*[a/3]+b)/5]) * ([(2*[a/3]+b)/5])) }";
2337 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2338 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2339 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2340 set
= isl_set_read_from_str(ctx
, "{ [a,b,a] }");
2341 pwqp1
= isl_pw_qpolynomial_intersect_domain(pwqp1
, set
);
2342 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2343 isl_pw_qpolynomial_free(pwqp1
);
2344 isl_pw_qpolynomial_free(pwqp2
);
2348 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2350 str
= "{ [a,b,c] -> (([(2*[a/3]+1)/5]) * ([(2*[c/3]+1)/5])) : b = 1 }";
2351 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2352 str
= "{ [a,b,c] -> (([(2*[a/3]+b)/5]) * ([(2*[c/3]+b)/5])) }";
2353 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2354 pwqp1
= isl_pw_qpolynomial_fix_val(pwqp1
, isl_dim_set
, 1,
2356 equal
= isl_pw_qpolynomial_plain_is_equal(pwqp1
, pwqp2
);
2357 isl_pw_qpolynomial_free(pwqp1
);
2358 isl_pw_qpolynomial_free(pwqp2
);
2362 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
2367 void test_split_periods(isl_ctx
*ctx
)
2370 isl_pw_qpolynomial
*pwqp
;
2372 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
2373 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
2374 "U >= 0; [U,V] -> U^2 : U >= 100 }";
2375 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2377 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
2380 isl_pw_qpolynomial_free(pwqp
);
2383 void test_union(isl_ctx
*ctx
)
2386 isl_union_set
*uset1
, *uset2
;
2387 isl_union_map
*umap1
, *umap2
;
2389 str
= "{ [i] : 0 <= i <= 1 }";
2390 uset1
= isl_union_set_read_from_str(ctx
, str
);
2391 str
= "{ [1] -> [0] }";
2392 umap1
= isl_union_map_read_from_str(ctx
, str
);
2394 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
2395 assert(isl_union_map_is_equal(umap1
, umap2
));
2397 isl_union_map_free(umap1
);
2398 isl_union_map_free(umap2
);
2400 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
2401 umap1
= isl_union_map_read_from_str(ctx
, str
);
2402 str
= "{ A[i]; B[i] }";
2403 uset1
= isl_union_set_read_from_str(ctx
, str
);
2405 uset2
= isl_union_map_domain(umap1
);
2407 assert(isl_union_set_is_equal(uset1
, uset2
));
2409 isl_union_set_free(uset1
);
2410 isl_union_set_free(uset2
);
2413 void test_bound(isl_ctx
*ctx
)
2416 isl_pw_qpolynomial
*pwqp
;
2417 isl_pw_qpolynomial_fold
*pwf
;
2419 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
2420 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2421 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2422 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 4);
2423 isl_pw_qpolynomial_fold_free(pwf
);
2425 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
2426 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
2427 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
2428 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_in
) == 1);
2429 isl_pw_qpolynomial_fold_free(pwf
);
2432 void test_lift(isl_ctx
*ctx
)
2435 isl_basic_map
*bmap
;
2436 isl_basic_set
*bset
;
2438 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
2439 bset
= isl_basic_set_read_from_str(ctx
, str
);
2440 bset
= isl_basic_set_lift(bset
);
2441 bmap
= isl_basic_map_from_range(bset
);
2442 bset
= isl_basic_map_domain(bmap
);
2443 isl_basic_set_free(bset
);
2450 } subset_tests
[] = {
2452 "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
2453 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
2454 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }", 1 },
2456 "{ [i] : exists (e0 = [(255i)/256], e1 = [(127i + 65e0)/191], "
2457 "e2 = [(3i + 61e1)/65], e3 = [(52i + 12e2)/61], "
2458 "e4 = [(2i + e3)/3], e5 = [(4i + e3)/4], e6 = [(8i + e3)/12]: "
2459 "3e4 = 2i + e3 and 4e5 = 4i + e3 and 12e6 = 8i + e3 and "
2460 "i <= 255 and 64e3 >= -45 + 67i and i >= 0 and "
2461 "256e0 <= 255i and 256e0 >= -255 + 255i and "
2462 "191e1 <= 127i + 65e0 and 191e1 >= -190 + 127i + 65e0 and "
2463 "65e2 <= 3i + 61e1 and 65e2 >= -64 + 3i + 61e1 and "
2464 "61e3 <= 52i + 12e2 and 61e3 >= -60 + 52i + 12e2) }", 1 },
2465 { "{ [i] : 0 <= i <= 10 }", "{ rat: [i] : 0 <= i <= 10 }", 1 },
2466 { "{ rat: [i] : 0 <= i <= 10 }", "{ [i] : 0 <= i <= 10 }", 0 },
2467 { "{ rat: [0] }", "{ [i] : 0 <= i <= 10 }", 1 },
2468 { "{ rat: [(1)/2] }", "{ [i] : 0 <= i <= 10 }", 0 },
2469 { "{ [t, i] : (exists (e0 = [(2 + t)/4]: 4e0 <= 2 + t and "
2470 "4e0 >= -1 + t and i >= 57 and i <= 62 and "
2471 "4e0 <= 62 + t - i and 4e0 >= -61 + t + i and "
2472 "t >= 0 and t <= 511 and 4e0 <= -57 + t + i and "
2473 "4e0 >= 58 + t - i and i >= 58 + t and i >= 62 - t)) }",
2474 "{ [i0, i1] : (exists (e0 = [(4 + i0)/4]: 4e0 <= 62 + i0 - i1 and "
2475 "4e0 >= 1 + i0 and i0 >= 0 and i0 <= 511 and "
2476 "4e0 <= -57 + i0 + i1)) or "
2477 "(exists (e0 = [(2 + i0)/4]: 4e0 <= i0 and "
2478 "4e0 >= 58 + i0 - i1 and i0 >= 2 and i0 <= 511 and "
2479 "4e0 >= -61 + i0 + i1)) or "
2480 "(i1 <= 66 - i0 and i0 >= 2 and i1 >= 59 + i0) }", 1 },
2483 static int test_subset(isl_ctx
*ctx
)
2486 isl_set
*set1
, *set2
;
2489 for (i
= 0; i
< ARRAY_SIZE(subset_tests
); ++i
) {
2490 set1
= isl_set_read_from_str(ctx
, subset_tests
[i
].set1
);
2491 set2
= isl_set_read_from_str(ctx
, subset_tests
[i
].set2
);
2492 subset
= isl_set_is_subset(set1
, set2
);
2497 if (subset
!= subset_tests
[i
].subset
)
2498 isl_die(ctx
, isl_error_unknown
,
2499 "incorrect subset result", return -1);
2506 const char *minuend
;
2507 const char *subtrahend
;
2508 const char *difference
;
2509 } subtract_domain_tests
[] = {
2510 { "{ A[i] -> B[i] }", "{ A[i] }", "{ }" },
2511 { "{ A[i] -> B[i] }", "{ B[i] }", "{ A[i] -> B[i] }" },
2512 { "{ A[i] -> B[i] }", "{ A[i] : i > 0 }", "{ A[i] -> B[i] : i <= 0 }" },
2515 static int test_subtract(isl_ctx
*ctx
)
2518 isl_union_map
*umap1
, *umap2
;
2519 isl_union_pw_multi_aff
*upma1
, *upma2
;
2520 isl_union_set
*uset
;
2523 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2524 umap1
= isl_union_map_read_from_str(ctx
,
2525 subtract_domain_tests
[i
].minuend
);
2526 uset
= isl_union_set_read_from_str(ctx
,
2527 subtract_domain_tests
[i
].subtrahend
);
2528 umap2
= isl_union_map_read_from_str(ctx
,
2529 subtract_domain_tests
[i
].difference
);
2530 umap1
= isl_union_map_subtract_domain(umap1
, uset
);
2531 equal
= isl_union_map_is_equal(umap1
, umap2
);
2532 isl_union_map_free(umap1
);
2533 isl_union_map_free(umap2
);
2537 isl_die(ctx
, isl_error_unknown
,
2538 "incorrect subtract domain result", return -1);
2541 for (i
= 0; i
< ARRAY_SIZE(subtract_domain_tests
); ++i
) {
2542 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
2543 subtract_domain_tests
[i
].minuend
);
2544 uset
= isl_union_set_read_from_str(ctx
,
2545 subtract_domain_tests
[i
].subtrahend
);
2546 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
2547 subtract_domain_tests
[i
].difference
);
2548 upma1
= isl_union_pw_multi_aff_subtract_domain(upma1
, uset
);
2549 equal
= isl_union_pw_multi_aff_plain_is_equal(upma1
, upma2
);
2550 isl_union_pw_multi_aff_free(upma1
);
2551 isl_union_pw_multi_aff_free(upma2
);
2555 isl_die(ctx
, isl_error_unknown
,
2556 "incorrect subtract domain result", return -1);
2562 int test_factorize(isl_ctx
*ctx
)
2565 isl_basic_set
*bset
;
2568 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
2569 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
2570 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
2571 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
2572 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
2573 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
2574 "3i5 >= -2i0 - i2 + 3i4 }";
2575 bset
= isl_basic_set_read_from_str(ctx
, str
);
2576 f
= isl_basic_set_factorizer(bset
);
2577 isl_basic_set_free(bset
);
2578 isl_factorizer_free(f
);
2580 isl_die(ctx
, isl_error_unknown
,
2581 "failed to construct factorizer", return -1);
2583 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
2584 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
2585 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
2586 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
2587 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
2588 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
2589 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
2590 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
2591 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
2592 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
2593 bset
= isl_basic_set_read_from_str(ctx
, str
);
2594 f
= isl_basic_set_factorizer(bset
);
2595 isl_basic_set_free(bset
);
2596 isl_factorizer_free(f
);
2598 isl_die(ctx
, isl_error_unknown
,
2599 "failed to construct factorizer", return -1);
2604 static int check_injective(__isl_take isl_map
*map
, void *user
)
2606 int *injective
= user
;
2608 *injective
= isl_map_is_injective(map
);
2611 if (*injective
< 0 || !*injective
)
2617 int test_one_schedule(isl_ctx
*ctx
, const char *d
, const char *w
,
2618 const char *r
, const char *s
, int tilable
, int parallel
)
2622 isl_union_map
*W
, *R
, *S
;
2623 isl_union_map
*empty
;
2624 isl_union_map
*dep_raw
, *dep_war
, *dep_waw
, *dep
;
2625 isl_union_map
*validity
, *proximity
, *coincidence
;
2626 isl_union_map
*schedule
;
2627 isl_union_map
*test
;
2628 isl_union_set
*delta
;
2629 isl_union_set
*domain
;
2633 isl_schedule_constraints
*sc
;
2634 isl_schedule
*sched
;
2635 int is_nonneg
, is_parallel
, is_tilable
, is_injection
, is_complete
;
2637 D
= isl_union_set_read_from_str(ctx
, d
);
2638 W
= isl_union_map_read_from_str(ctx
, w
);
2639 R
= isl_union_map_read_from_str(ctx
, r
);
2640 S
= isl_union_map_read_from_str(ctx
, s
);
2642 W
= isl_union_map_intersect_domain(W
, isl_union_set_copy(D
));
2643 R
= isl_union_map_intersect_domain(R
, isl_union_set_copy(D
));
2645 empty
= isl_union_map_empty(isl_union_map_get_space(S
));
2646 isl_union_map_compute_flow(isl_union_map_copy(R
),
2647 isl_union_map_copy(W
), empty
,
2648 isl_union_map_copy(S
),
2649 &dep_raw
, NULL
, NULL
, NULL
);
2650 isl_union_map_compute_flow(isl_union_map_copy(W
),
2651 isl_union_map_copy(W
),
2652 isl_union_map_copy(R
),
2653 isl_union_map_copy(S
),
2654 &dep_waw
, &dep_war
, NULL
, NULL
);
2656 dep
= isl_union_map_union(dep_waw
, dep_war
);
2657 dep
= isl_union_map_union(dep
, dep_raw
);
2658 validity
= isl_union_map_copy(dep
);
2659 coincidence
= isl_union_map_copy(dep
);
2660 proximity
= isl_union_map_copy(dep
);
2662 sc
= isl_schedule_constraints_on_domain(isl_union_set_copy(D
));
2663 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2664 sc
= isl_schedule_constraints_set_coincidence(sc
, coincidence
);
2665 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2666 sched
= isl_schedule_constraints_compute_schedule(sc
);
2667 schedule
= isl_schedule_get_map(sched
);
2668 isl_schedule_free(sched
);
2669 isl_union_map_free(W
);
2670 isl_union_map_free(R
);
2671 isl_union_map_free(S
);
2674 isl_union_map_foreach_map(schedule
, &check_injective
, &is_injection
);
2676 domain
= isl_union_map_domain(isl_union_map_copy(schedule
));
2677 is_complete
= isl_union_set_is_subset(D
, domain
);
2678 isl_union_set_free(D
);
2679 isl_union_set_free(domain
);
2681 test
= isl_union_map_reverse(isl_union_map_copy(schedule
));
2682 test
= isl_union_map_apply_range(test
, dep
);
2683 test
= isl_union_map_apply_range(test
, schedule
);
2685 delta
= isl_union_map_deltas(test
);
2686 if (isl_union_set_n_set(delta
) == 0) {
2690 isl_union_set_free(delta
);
2692 delta_set
= isl_set_from_union_set(delta
);
2694 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2695 for (i
= 0; i
< tilable
; ++i
)
2696 slice
= isl_set_lower_bound_si(slice
, isl_dim_set
, i
, 0);
2697 is_tilable
= isl_set_is_subset(delta_set
, slice
);
2698 isl_set_free(slice
);
2700 slice
= isl_set_universe(isl_set_get_space(delta_set
));
2701 for (i
= 0; i
< parallel
; ++i
)
2702 slice
= isl_set_fix_si(slice
, isl_dim_set
, i
, 0);
2703 is_parallel
= isl_set_is_subset(delta_set
, slice
);
2704 isl_set_free(slice
);
2706 origin
= isl_set_universe(isl_set_get_space(delta_set
));
2707 for (i
= 0; i
< isl_set_dim(origin
, isl_dim_set
); ++i
)
2708 origin
= isl_set_fix_si(origin
, isl_dim_set
, i
, 0);
2710 delta_set
= isl_set_union(delta_set
, isl_set_copy(origin
));
2711 delta_set
= isl_set_lexmin(delta_set
);
2713 is_nonneg
= isl_set_is_equal(delta_set
, origin
);
2715 isl_set_free(origin
);
2716 isl_set_free(delta_set
);
2719 if (is_nonneg
< 0 || is_parallel
< 0 || is_tilable
< 0 ||
2720 is_injection
< 0 || is_complete
< 0)
2723 isl_die(ctx
, isl_error_unknown
,
2724 "generated schedule incomplete", return -1);
2726 isl_die(ctx
, isl_error_unknown
,
2727 "generated schedule not injective on each statement",
2730 isl_die(ctx
, isl_error_unknown
,
2731 "negative dependences in generated schedule",
2734 isl_die(ctx
, isl_error_unknown
,
2735 "generated schedule not as tilable as expected",
2738 isl_die(ctx
, isl_error_unknown
,
2739 "generated schedule not as parallel as expected",
2745 static __isl_give isl_union_map
*compute_schedule(isl_ctx
*ctx
,
2746 const char *domain
, const char *validity
, const char *proximity
)
2750 isl_union_map
*prox
;
2751 isl_schedule_constraints
*sc
;
2752 isl_schedule
*schedule
;
2753 isl_union_map
*sched
;
2755 dom
= isl_union_set_read_from_str(ctx
, domain
);
2756 dep
= isl_union_map_read_from_str(ctx
, validity
);
2757 prox
= isl_union_map_read_from_str(ctx
, proximity
);
2758 sc
= isl_schedule_constraints_on_domain(dom
);
2759 sc
= isl_schedule_constraints_set_validity(sc
, dep
);
2760 sc
= isl_schedule_constraints_set_proximity(sc
, prox
);
2761 schedule
= isl_schedule_constraints_compute_schedule(sc
);
2762 sched
= isl_schedule_get_map(schedule
);
2763 isl_schedule_free(schedule
);
2768 /* Check that a schedule can be constructed on the given domain
2769 * with the given validity and proximity constraints.
2771 static int test_has_schedule(isl_ctx
*ctx
, const char *domain
,
2772 const char *validity
, const char *proximity
)
2774 isl_union_map
*sched
;
2776 sched
= compute_schedule(ctx
, domain
, validity
, proximity
);
2780 isl_union_map_free(sched
);
2784 int test_special_schedule(isl_ctx
*ctx
, const char *domain
,
2785 const char *validity
, const char *proximity
, const char *expected_sched
)
2787 isl_union_map
*sched1
, *sched2
;
2790 sched1
= compute_schedule(ctx
, domain
, validity
, proximity
);
2791 sched2
= isl_union_map_read_from_str(ctx
, expected_sched
);
2793 equal
= isl_union_map_is_equal(sched1
, sched2
);
2794 isl_union_map_free(sched1
);
2795 isl_union_map_free(sched2
);
2800 isl_die(ctx
, isl_error_unknown
, "unexpected schedule",
2806 /* Check that the schedule map is properly padded, even after being
2807 * reconstructed from the band forest.
2809 static int test_padded_schedule(isl_ctx
*ctx
)
2813 isl_union_map
*validity
, *proximity
;
2814 isl_schedule_constraints
*sc
;
2815 isl_schedule
*sched
;
2816 isl_union_map
*map1
, *map2
;
2817 isl_band_list
*list
;
2820 str
= "[N] -> { S0[i] : 0 <= i <= N; S1[i, j] : 0 <= i, j <= N }";
2821 D
= isl_union_set_read_from_str(ctx
, str
);
2822 validity
= isl_union_map_empty(isl_union_set_get_space(D
));
2823 proximity
= isl_union_map_copy(validity
);
2824 sc
= isl_schedule_constraints_on_domain(D
);
2825 sc
= isl_schedule_constraints_set_validity(sc
, validity
);
2826 sc
= isl_schedule_constraints_set_proximity(sc
, proximity
);
2827 sched
= isl_schedule_constraints_compute_schedule(sc
);
2828 map1
= isl_schedule_get_map(sched
);
2829 list
= isl_schedule_get_band_forest(sched
);
2830 isl_band_list_free(list
);
2831 map2
= isl_schedule_get_map(sched
);
2832 isl_schedule_free(sched
);
2833 equal
= isl_union_map_is_equal(map1
, map2
);
2834 isl_union_map_free(map1
);
2835 isl_union_map_free(map2
);
2840 isl_die(ctx
, isl_error_unknown
,
2841 "reconstructed schedule map not the same as original",
2847 /* Input for testing of schedule construction based on
2848 * conditional constraints.
2850 * domain is the iteration domain
2851 * flow are the flow dependences, which determine the validity and
2852 * proximity constraints
2853 * condition are the conditions on the conditional validity constraints
2854 * conditional_validity are the conditional validity constraints
2855 * outer_band_n is the expected number of members in the outer band
2860 const char *condition
;
2861 const char *conditional_validity
;
2863 } live_range_tests
[] = {
2864 /* Contrived example that illustrates that we need to keep
2865 * track of tagged condition dependences and
2866 * tagged conditional validity dependences
2867 * in isl_sched_edge separately.
2868 * In particular, the conditional validity constraints on A
2869 * cannot be satisfied,
2870 * but they can be ignored because there are no corresponding
2871 * condition constraints. However, we do have an additional
2872 * conditional validity constraint that maps to the same
2873 * dependence relation
2874 * as the condition constraint on B. If we did not make a distinction
2875 * between tagged condition and tagged conditional validity
2876 * dependences, then we
2877 * could end up treating this shared dependence as an condition
2878 * constraint on A, forcing a localization of the conditions,
2879 * which is impossible.
2881 { "{ S[i] : 0 <= 1 < 100; T[i] : 0 <= 1 < 100 }",
2882 "{ S[i] -> S[i+1] : 0 <= i < 99 }",
2883 "{ [S[i] -> B[]] -> [S[i+1] -> B[]] : 0 <= i < 99 }",
2884 "{ [S[i] -> A[]] -> [T[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2885 "[T[i] -> A[]] -> [S[i'] -> A[]] : 0 <= i', i < 100 and i != i';"
2886 "[S[i] -> A[]] -> [S[i+1] -> A[]] : 0 <= i < 99 }",
2889 /* TACO 2013 Fig. 7 */
2890 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2891 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2892 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2893 "[n] -> { [S1[i,j] -> t[]] -> [S2[i,j] -> t[]] : 0 <= i,j < n;"
2894 "[S2[i,j] -> x1[]] -> [S2[i,j+1] -> x1[]] : "
2895 "0 <= i < n and 0 <= j < n - 1 }",
2896 "[n] -> { [S2[i,j] -> t[]] -> [S1[i,j'] -> t[]] : "
2897 "0 <= i < n and 0 <= j < j' < n;"
2898 "[S2[i,j] -> t[]] -> [S1[i',j'] -> t[]] : "
2899 "0 <= i < i' < n and 0 <= j,j' < n;"
2900 "[S2[i,j] -> x1[]] -> [S2[i,j'] -> x1[]] : "
2901 "0 <= i,j,j' < n and j < j' }",
2904 /* TACO 2013 Fig. 7, without tags */
2905 { "[n] -> { S1[i,j] : 0 <= i,j < n; S2[i,j] : 0 <= i,j < n }",
2906 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2907 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2908 "[n] -> { S1[i,j] -> S2[i,j] : 0 <= i,j < n;"
2909 "S2[i,j] -> S2[i,j+1] : 0 <= i < n and 0 <= j < n - 1 }",
2910 "[n] -> { S2[i,j] -> S1[i,j'] : 0 <= i < n and 0 <= j < j' < n;"
2911 "S2[i,j] -> S1[i',j'] : 0 <= i < i' < n and 0 <= j,j' < n;"
2912 "S2[i,j] -> S2[i,j'] : 0 <= i,j,j' < n and j < j' }",
2915 /* TACO 2013 Fig. 12 */
2916 { "{ S1[i,0] : 0 <= i <= 1; S2[i,j] : 0 <= i <= 1 and 1 <= j <= 2;"
2917 "S3[i,3] : 0 <= i <= 1 }",
2918 "{ S1[i,0] -> S2[i,1] : 0 <= i <= 1;"
2919 "S2[i,1] -> S2[i,2] : 0 <= i <= 1;"
2920 "S2[i,2] -> S3[i,3] : 0 <= i <= 1 }",
2921 "{ [S1[i,0]->t[]] -> [S2[i,1]->t[]] : 0 <= i <= 1;"
2922 "[S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2923 "[S2[i,2]->t[]] -> [S3[i,3]->t[]] : 0 <= i <= 1 }",
2924 "{ [S2[i,1]->t[]] -> [S2[i,2]->t[]] : 0 <= i <= 1;"
2925 "[S2[0,j]->t[]] -> [S2[1,j']->t[]] : 1 <= j,j' <= 2;"
2926 "[S2[0,j]->t[]] -> [S1[1,0]->t[]] : 1 <= j <= 2;"
2927 "[S3[0,3]->t[]] -> [S2[1,j]->t[]] : 1 <= j <= 2;"
2928 "[S3[0,3]->t[]] -> [S1[1,0]->t[]] }",
2933 /* Test schedule construction based on conditional constraints.
2934 * In particular, check the number of members in the outer band
2935 * as an indication of whether tiling is possible or not.
2937 static int test_conditional_schedule_constraints(isl_ctx
*ctx
)
2940 isl_union_set
*domain
;
2941 isl_union_map
*condition
;
2942 isl_union_map
*flow
;
2943 isl_union_map
*validity
;
2944 isl_schedule_constraints
*sc
;
2945 isl_schedule
*schedule
;
2946 isl_band_list
*list
;
2950 for (i
= 0; i
< ARRAY_SIZE(live_range_tests
); ++i
) {
2951 domain
= isl_union_set_read_from_str(ctx
,
2952 live_range_tests
[i
].domain
);
2953 flow
= isl_union_map_read_from_str(ctx
,
2954 live_range_tests
[i
].flow
);
2955 condition
= isl_union_map_read_from_str(ctx
,
2956 live_range_tests
[i
].condition
);
2957 validity
= isl_union_map_read_from_str(ctx
,
2958 live_range_tests
[i
].conditional_validity
);
2959 sc
= isl_schedule_constraints_on_domain(domain
);
2960 sc
= isl_schedule_constraints_set_validity(sc
,
2961 isl_union_map_copy(flow
));
2962 sc
= isl_schedule_constraints_set_proximity(sc
, flow
);
2963 sc
= isl_schedule_constraints_set_conditional_validity(sc
,
2964 condition
, validity
);
2965 schedule
= isl_schedule_constraints_compute_schedule(sc
);
2966 list
= isl_schedule_get_band_forest(schedule
);
2967 band
= isl_band_list_get_band(list
, 0);
2968 n_member
= isl_band_n_member(band
);
2969 isl_band_free(band
);
2970 isl_band_list_free(list
);
2971 isl_schedule_free(schedule
);
2975 if (n_member
!= live_range_tests
[i
].outer_band_n
)
2976 isl_die(ctx
, isl_error_unknown
,
2977 "unexpected number of members in outer band",
2983 int test_schedule(isl_ctx
*ctx
)
2985 const char *D
, *W
, *R
, *V
, *P
, *S
;
2987 /* Handle resulting schedule with zero bands. */
2988 if (test_one_schedule(ctx
, "{[]}", "{}", "{}", "{[] -> []}", 0, 0) < 0)
2992 D
= "[T,N] -> { S1[t,i] : 1 <= t <= T and 2 <= i <= N - 1 }";
2993 W
= "{ S1[t,i] -> a[t,i] }";
2994 R
= "{ S1[t,i] -> a[t-1,i]; S1[t,i] -> a[t-1,i-1]; "
2995 "S1[t,i] -> a[t-1,i+1] }";
2996 S
= "{ S1[t,i] -> [t,i] }";
2997 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3000 /* Fig. 5 of CC2008 */
3001 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and j >= 2 and "
3003 W
= "[N] -> { S_0[i, j] -> a[i, j] : i >= 0 and i <= -1 + N and "
3004 "j >= 2 and j <= -1 + N }";
3005 R
= "[N] -> { S_0[i, j] -> a[j, i] : i >= 0 and i <= -1 + N and "
3006 "j >= 2 and j <= -1 + N; "
3007 "S_0[i, j] -> a[i, -1 + j] : i >= 0 and i <= -1 + N and "
3008 "j >= 2 and j <= -1 + N }";
3009 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
3010 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3013 D
= "{ S1[i] : 0 <= i <= 10; S2[i] : 0 <= i <= 9 }";
3014 W
= "{ S1[i] -> a[i] }";
3015 R
= "{ S2[i] -> a[i+1] }";
3016 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3017 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3020 D
= "{ S1[i] : 0 <= i < 10; S2[i] : 0 <= i < 10 }";
3021 W
= "{ S1[i] -> a[i] }";
3022 R
= "{ S2[i] -> a[9-i] }";
3023 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3024 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3027 D
= "[N] -> { S1[i] : 0 <= i < N; S2[i] : 0 <= i < N }";
3028 W
= "{ S1[i] -> a[i] }";
3029 R
= "[N] -> { S2[i] -> a[N-1-i] }";
3030 S
= "{ S1[i] -> [0,i]; S2[i] -> [1,i] }";
3031 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 1) < 0)
3034 D
= "{ S1[i] : 0 < i < 10; S2[i] : 0 <= i < 10 }";
3035 W
= "{ S1[i] -> a[i]; S2[i] -> b[i] }";
3036 R
= "{ S2[i] -> a[i]; S1[i] -> b[i-1] }";
3037 S
= "{ S1[i] -> [i,0]; S2[i] -> [i,1] }";
3038 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3041 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
3042 W
= "{ S1[i] -> a[0,i]; S2[i,j] -> a[i,j] }";
3043 R
= "{ S2[i,j] -> a[i-1,j] }";
3044 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
3045 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3048 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i,j] : 1 <= i,j <= N }";
3049 W
= "{ S1[i] -> a[i,0]; S2[i,j] -> a[i,j] }";
3050 R
= "{ S2[i,j] -> a[i,j-1] }";
3051 S
= "{ S1[i] -> [0,i,0]; S2[i,j] -> [1,i,j] }";
3052 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3055 D
= "[N] -> { S_0[]; S_1[i] : i >= 0 and i <= -1 + N; S_2[] }";
3056 W
= "[N] -> { S_0[] -> a[0]; S_2[] -> b[0]; "
3057 "S_1[i] -> a[1 + i] : i >= 0 and i <= -1 + N }";
3058 R
= "[N] -> { S_2[] -> a[N]; S_1[i] -> a[i] : i >= 0 and i <= -1 + N }";
3059 S
= "[N] -> { S_1[i] -> [1, i, 0]; S_2[] -> [2, 0, 1]; "
3060 "S_0[] -> [0, 0, 0] }";
3061 if (test_one_schedule(ctx
, D
, W
, R
, S
, 1, 0) < 0)
3063 ctx
->opt
->schedule_parametric
= 0;
3064 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3066 ctx
->opt
->schedule_parametric
= 1;
3068 D
= "[N] -> { S1[i] : 1 <= i <= N; S2[i] : 1 <= i <= N; "
3069 "S3[i,j] : 1 <= i,j <= N; S4[i] : 1 <= i <= N }";
3070 W
= "{ S1[i] -> a[i,0]; S2[i] -> a[0,i]; S3[i,j] -> a[i,j] }";
3071 R
= "[N] -> { S3[i,j] -> a[i-1,j]; S3[i,j] -> a[i,j-1]; "
3072 "S4[i] -> a[i,N] }";
3073 S
= "{ S1[i] -> [0,i,0]; S2[i] -> [1,i,0]; S3[i,j] -> [2,i,j]; "
3074 "S4[i] -> [4,i,0] }";
3075 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 0) < 0)
3078 D
= "[N] -> { S_0[i, j] : i >= 1 and i <= N and j >= 1 and j <= N }";
3079 W
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
3081 R
= "[N] -> { S_0[i, j] -> s[0] : i >= 1 and i <= N and j >= 1 and "
3083 "S_0[i, j] -> a[i, j] : i >= 1 and i <= N and j >= 1 and "
3085 S
= "[N] -> { S_0[i, j] -> [0, i, 0, j, 0] }";
3086 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3089 D
= "[N] -> { S_0[t] : t >= 0 and t <= -1 + N; "
3090 " S_2[t] : t >= 0 and t <= -1 + N; "
3091 " S_1[t, i] : t >= 0 and t <= -1 + N and i >= 0 and "
3093 W
= "[N] -> { S_0[t] -> a[t, 0] : t >= 0 and t <= -1 + N; "
3094 " S_2[t] -> b[t] : t >= 0 and t <= -1 + N; "
3095 " S_1[t, i] -> a[t, 1 + i] : t >= 0 and t <= -1 + N and "
3096 "i >= 0 and i <= -1 + N }";
3097 R
= "[N] -> { S_1[t, i] -> a[t, i] : t >= 0 and t <= -1 + N and "
3098 "i >= 0 and i <= -1 + N; "
3099 " S_2[t] -> a[t, N] : t >= 0 and t <= -1 + N }";
3100 S
= "[N] -> { S_2[t] -> [0, t, 2]; S_1[t, i] -> [0, t, 1, i, 0]; "
3101 " S_0[t] -> [0, t, 0] }";
3103 if (test_one_schedule(ctx
, D
, W
, R
, S
, 2, 1) < 0)
3105 ctx
->opt
->schedule_parametric
= 0;
3106 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3108 ctx
->opt
->schedule_parametric
= 1;
3110 D
= "[N] -> { S1[i,j] : 0 <= i,j < N; S2[i,j] : 0 <= i,j < N }";
3111 S
= "{ S1[i,j] -> [0,i,j]; S2[i,j] -> [1,i,j] }";
3112 if (test_one_schedule(ctx
, D
, "{}", "{}", S
, 2, 2) < 0)
3115 D
= "[M, N] -> { S_1[i] : i >= 0 and i <= -1 + M; "
3116 "S_0[i, j] : i >= 0 and i <= -1 + M and j >= 0 and j <= -1 + N }";
3117 W
= "[M, N] -> { S_0[i, j] -> a[j] : i >= 0 and i <= -1 + M and "
3118 "j >= 0 and j <= -1 + N; "
3119 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3120 R
= "[M, N] -> { S_0[i, j] -> a[0] : i >= 0 and i <= -1 + M and "
3121 "j >= 0 and j <= -1 + N; "
3122 "S_1[i] -> b[0] : i >= 0 and i <= -1 + M }";
3123 S
= "[M, N] -> { S_1[i] -> [1, i, 0]; S_0[i, j] -> [0, i, 0, j, 0] }";
3124 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3127 D
= "{ S_0[i] : i >= 0 }";
3128 W
= "{ S_0[i] -> a[i] : i >= 0 }";
3129 R
= "{ S_0[i] -> a[0] : i >= 0 }";
3130 S
= "{ S_0[i] -> [0, i, 0] }";
3131 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3134 D
= "{ S_0[i] : i >= 0; S_1[i] : i >= 0 }";
3135 W
= "{ S_0[i] -> a[i] : i >= 0; S_1[i] -> b[i] : i >= 0 }";
3136 R
= "{ S_0[i] -> b[0] : i >= 0; S_1[i] -> a[i] : i >= 0 }";
3137 S
= "{ S_1[i] -> [0, i, 1]; S_0[i] -> [0, i, 0] }";
3138 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3141 D
= "[n] -> { S_0[j, k] : j <= -1 + n and j >= 0 and "
3142 "k <= -1 + n and k >= 0 }";
3143 W
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and " "k <= -1 + n and k >= 0 }";
3144 R
= "[n] -> { S_0[j, k] -> B[j] : j <= -1 + n and j >= 0 and "
3145 "k <= -1 + n and k >= 0; "
3146 "S_0[j, k] -> B[k] : j <= -1 + n and j >= 0 and "
3147 "k <= -1 + n and k >= 0; "
3148 "S_0[j, k] -> A[k] : j <= -1 + n and j >= 0 and "
3149 "k <= -1 + n and k >= 0 }";
3150 S
= "[n] -> { S_0[j, k] -> [2, j, k] }";
3151 ctx
->opt
->schedule_outer_coincidence
= 1;
3152 if (test_one_schedule(ctx
, D
, W
, R
, S
, 0, 0) < 0)
3154 ctx
->opt
->schedule_outer_coincidence
= 0;
3156 D
= "{Stmt_for_body24[i0, i1, i2, i3]:"
3157 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 6 and i2 >= 2 and "
3158 "i2 <= 6 - i1 and i3 >= 0 and i3 <= -1 + i2;"
3159 "Stmt_for_body24[i0, i1, 1, 0]:"
3160 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 5;"
3161 "Stmt_for_body7[i0, i1, i2]:"
3162 "i0 >= 0 and i0 <= 1 and i1 >= 0 and i1 <= 7 and i2 >= 0 and "
3165 V
= "{Stmt_for_body24[0, i1, i2, i3] -> "
3166 "Stmt_for_body24[1, i1, i2, i3]:"
3167 "i3 >= 0 and i3 <= -1 + i2 and i1 >= 0 and i2 <= 6 - i1 and "
3169 "Stmt_for_body24[0, i1, i2, i3] -> "
3170 "Stmt_for_body7[1, 1 + i1 + i3, 1 + i1 + i2]:"
3171 "i3 <= -1 + i2 and i2 <= 6 - i1 and i2 >= 1 and i1 >= 0 and "
3173 "Stmt_for_body24[0, i1, i2, i3] ->"
3174 "Stmt_for_body7[1, i1, 1 + i1 + i3]:"
3175 "i3 >= 0 and i2 <= 6 - i1 and i1 >= 0 and i3 <= -1 + i2;"
3176 "Stmt_for_body7[0, i1, i2] -> Stmt_for_body7[1, i1, i2]:"
3177 "(i2 >= 1 + i1 and i2 <= 6 and i1 >= 0 and i1 <= 4) or "
3178 "(i2 >= 3 and i2 <= 7 and i1 >= 1 and i2 >= 1 + i1) or "
3179 "(i2 >= 0 and i2 <= i1 and i2 >= -7 + i1 and i1 <= 7);"
3180 "Stmt_for_body7[0, i1, 1 + i1] -> Stmt_for_body7[1, i1, 1 + i1]:"
3181 "i1 <= 6 and i1 >= 0;"
3182 "Stmt_for_body7[0, 0, 7] -> Stmt_for_body7[1, 0, 7];"
3183 "Stmt_for_body7[i0, i1, i2] -> "
3184 "Stmt_for_body24[i0, o1, -1 + i2 - o1, -1 + i1 - o1]:"
3185 "i0 >= 0 and i0 <= 1 and o1 >= 0 and i2 >= 1 + i1 and "
3186 "o1 <= -2 + i2 and i2 <= 7 and o1 <= -1 + i1;"
3187 "Stmt_for_body7[i0, i1, i2] -> "
3188 "Stmt_for_body24[i0, i1, o2, -1 - i1 + i2]:"
3189 "i0 >= 0 and i0 <= 1 and i1 >= 0 and o2 >= -i1 + i2 and "
3190 "o2 >= 1 and o2 <= 6 - i1 and i2 >= 1 + i1 }";
3192 S
= "{ Stmt_for_body24[i0, i1, i2, i3] -> "
3193 "[i0, 5i0 + i1, 6i0 + i1 + i2, 1 + 6i0 + i1 + i2 + i3, 1];"
3194 "Stmt_for_body7[i0, i1, i2] -> [0, 5i0, 6i0 + i1, 6i0 + i2, 0] }";
3196 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3199 D
= "{ S_0[i, j] : i >= 1 and i <= 10 and j >= 1 and j <= 8 }";
3200 V
= "{ S_0[i, j] -> S_0[i, 1 + j] : i >= 1 and i <= 10 and "
3201 "j >= 1 and j <= 7;"
3202 "S_0[i, j] -> S_0[1 + i, j] : i >= 1 and i <= 9 and "
3203 "j >= 1 and j <= 8 }";
3205 S
= "{ S_0[i, j] -> [i + j, j] }";
3206 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3207 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3209 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3211 /* Fig. 1 from Feautrier's "Some Efficient Solutions..." pt. 2, 1992 */
3212 D
= "[N] -> { S_0[i, j] : i >= 0 and i <= -1 + N and "
3213 "j >= 0 and j <= -1 + i }";
3214 V
= "[N] -> { S_0[i, j] -> S_0[i, 1 + j] : j <= -2 + i and "
3215 "i <= -1 + N and j >= 0;"
3216 "S_0[i, -1 + i] -> S_0[1 + i, 0] : i >= 1 and "
3219 S
= "{ S_0[i, j] -> [i, j] }";
3220 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3221 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3223 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3225 /* Test both algorithms on a case with only proximity dependences. */
3226 D
= "{ S[i,j] : 0 <= i <= 10 }";
3228 P
= "{ S[i,j] -> S[i+1,j] : 0 <= i,j <= 10 }";
3229 S
= "{ S[i, j] -> [j, i] }";
3230 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3231 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3233 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3234 if (test_special_schedule(ctx
, D
, V
, P
, S
) < 0)
3237 D
= "{ A[a]; B[] }";
3239 P
= "{ A[a] -> B[] }";
3240 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3243 if (test_padded_schedule(ctx
) < 0)
3246 /* Check that check for progress is not confused by rational
3249 D
= "[N] -> { S0[i, j] : i >= 0 and i <= N and j >= 0 and j <= N }";
3250 V
= "[N] -> { S0[i0, -1 + N] -> S0[2 + i0, 0] : i0 >= 0 and "
3252 "S0[i0, i1] -> S0[i0, 1 + i1] : i0 >= 0 and "
3253 "i0 <= N and i1 >= 0 and i1 <= -1 + N }";
3255 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3256 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3258 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3260 /* Check that we allow schedule rows that are only non-trivial
3261 * on some full-dimensional domains.
3263 D
= "{ S1[j] : 0 <= j <= 1; S0[]; S2[k] : 0 <= k <= 1 }";
3264 V
= "{ S0[] -> S1[j] : 0 <= j <= 1; S2[0] -> S0[];"
3265 "S1[j] -> S2[1] : 0 <= j <= 1 }";
3267 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_FEAUTRIER
;
3268 if (test_has_schedule(ctx
, D
, V
, P
) < 0)
3270 ctx
->opt
->schedule_algorithm
= ISL_SCHEDULE_ALGORITHM_ISL
;
3272 if (test_conditional_schedule_constraints(ctx
) < 0)
3278 int test_plain_injective(isl_ctx
*ctx
, const char *str
, int injective
)
3280 isl_union_map
*umap
;
3283 umap
= isl_union_map_read_from_str(ctx
, str
);
3284 test
= isl_union_map_plain_is_injective(umap
);
3285 isl_union_map_free(umap
);
3288 if (test
== injective
)
3291 isl_die(ctx
, isl_error_unknown
,
3292 "map not detected as injective", return -1);
3294 isl_die(ctx
, isl_error_unknown
,
3295 "map detected as injective", return -1);
3298 int test_injective(isl_ctx
*ctx
)
3302 if (test_plain_injective(ctx
, "{S[i,j] -> A[0]; T[i,j] -> B[1]}", 0))
3304 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> B[0]}", 1))
3306 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[1]}", 1))
3308 if (test_plain_injective(ctx
, "{S[] -> A[0]; T[] -> A[0]}", 0))
3310 if (test_plain_injective(ctx
, "{S[i] -> A[i,0]; T[i] -> A[i,1]}", 1))
3312 if (test_plain_injective(ctx
, "{S[i] -> A[i]; T[i] -> A[i]}", 0))
3314 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[0,1]}", 1))
3316 if (test_plain_injective(ctx
, "{S[] -> A[0,0]; T[] -> A[1,0]}", 1))
3319 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[1,0]}";
3320 if (test_plain_injective(ctx
, str
, 1))
3322 str
= "{S[] -> A[0,0]; T[] -> A[0,1]; U[] -> A[0,0]}";
3323 if (test_plain_injective(ctx
, str
, 0))
3329 static int aff_plain_is_equal(__isl_keep isl_aff
*aff
, const char *str
)
3337 aff2
= isl_aff_read_from_str(isl_aff_get_ctx(aff
), str
);
3338 equal
= isl_aff_plain_is_equal(aff
, aff2
);
3344 static int aff_check_plain_equal(__isl_keep isl_aff
*aff
, const char *str
)
3348 equal
= aff_plain_is_equal(aff
, str
);
3352 isl_die(isl_aff_get_ctx(aff
), isl_error_unknown
,
3353 "result not as expected", return -1);
3358 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3359 __isl_take isl_aff
*aff2
);
3361 ['+'] = { &isl_aff_add
},
3362 ['-'] = { &isl_aff_sub
},
3363 ['*'] = { &isl_aff_mul
},
3364 ['/'] = { &isl_aff_div
},
3372 } aff_bin_tests
[] = {
3373 { "{ [i] -> [i] }", '+', "{ [i] -> [i] }",
3374 "{ [i] -> [2i] }" },
3375 { "{ [i] -> [i] }", '-', "{ [i] -> [i] }",
3377 { "{ [i] -> [i] }", '*', "{ [i] -> [2] }",
3378 "{ [i] -> [2i] }" },
3379 { "{ [i] -> [2] }", '*', "{ [i] -> [i] }",
3380 "{ [i] -> [2i] }" },
3381 { "{ [i] -> [i] }", '/', "{ [i] -> [2] }",
3382 "{ [i] -> [i/2] }" },
3383 { "{ [i] -> [2i] }", '/', "{ [i] -> [2] }",
3385 { "{ [i] -> [i] }", '+', "{ [i] -> [NaN] }",
3386 "{ [i] -> [NaN] }" },
3387 { "{ [i] -> [i] }", '-', "{ [i] -> [NaN] }",
3388 "{ [i] -> [NaN] }" },
3389 { "{ [i] -> [i] }", '*', "{ [i] -> [NaN] }",
3390 "{ [i] -> [NaN] }" },
3391 { "{ [i] -> [2] }", '*', "{ [i] -> [NaN] }",
3392 "{ [i] -> [NaN] }" },
3393 { "{ [i] -> [i] }", '/', "{ [i] -> [NaN] }",
3394 "{ [i] -> [NaN] }" },
3395 { "{ [i] -> [2] }", '/', "{ [i] -> [NaN] }",
3396 "{ [i] -> [NaN] }" },
3397 { "{ [i] -> [NaN] }", '+', "{ [i] -> [i] }",
3398 "{ [i] -> [NaN] }" },
3399 { "{ [i] -> [NaN] }", '-', "{ [i] -> [i] }",
3400 "{ [i] -> [NaN] }" },
3401 { "{ [i] -> [NaN] }", '*', "{ [i] -> [2] }",
3402 "{ [i] -> [NaN] }" },
3403 { "{ [i] -> [NaN] }", '*', "{ [i] -> [i] }",
3404 "{ [i] -> [NaN] }" },
3405 { "{ [i] -> [NaN] }", '/', "{ [i] -> [2] }",
3406 "{ [i] -> [NaN] }" },
3407 { "{ [i] -> [NaN] }", '/', "{ [i] -> [i] }",
3408 "{ [i] -> [NaN] }" },
3411 /* Perform some basic tests of binary operations on isl_aff objects.
3413 static int test_bin_aff(isl_ctx
*ctx
)
3416 isl_aff
*aff1
, *aff2
, *res
;
3417 __isl_give isl_aff
*(*fn
)(__isl_take isl_aff
*aff1
,
3418 __isl_take isl_aff
*aff2
);
3421 for (i
= 0; i
< ARRAY_SIZE(aff_bin_tests
); ++i
) {
3422 aff1
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg1
);
3423 aff2
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].arg2
);
3424 res
= isl_aff_read_from_str(ctx
, aff_bin_tests
[i
].res
);
3425 fn
= aff_bin_op
[aff_bin_tests
[i
].op
].fn
;
3426 aff1
= fn(aff1
, aff2
);
3427 if (isl_aff_is_nan(res
))
3428 ok
= isl_aff_is_nan(aff1
);
3430 ok
= isl_aff_plain_is_equal(aff1
, res
);
3436 isl_die(ctx
, isl_error_unknown
,
3437 "unexpected result", return -1);
3444 __isl_give isl_union_pw_multi_aff
*(*fn
)(
3445 __isl_take isl_union_pw_multi_aff
*upma1
,
3446 __isl_take isl_union_pw_multi_aff
*upma2
);
3450 } upma_bin_tests
[] = {
3451 { &isl_union_pw_multi_aff_add
, "{ A[] -> [0]; B[0] -> [1] }",
3452 "{ B[x] -> [2] : x >= 0 }", "{ B[0] -> [3] }" },
3453 { &isl_union_pw_multi_aff_union_add
, "{ A[] -> [0]; B[0] -> [1] }",
3454 "{ B[x] -> [2] : x >= 0 }",
3455 "{ A[] -> [0]; B[0] -> [3]; B[x] -> [2] : x >= 1 }" },
3458 /* Perform some basic tests of binary operations on
3459 * isl_union_pw_multi_aff objects.
3461 static int test_bin_upma(isl_ctx
*ctx
)
3464 isl_union_pw_multi_aff
*upma1
, *upma2
, *res
;
3467 for (i
= 0; i
< ARRAY_SIZE(upma_bin_tests
); ++i
) {
3468 upma1
= isl_union_pw_multi_aff_read_from_str(ctx
,
3469 upma_bin_tests
[i
].arg1
);
3470 upma2
= isl_union_pw_multi_aff_read_from_str(ctx
,
3471 upma_bin_tests
[i
].arg2
);
3472 res
= isl_union_pw_multi_aff_read_from_str(ctx
,
3473 upma_bin_tests
[i
].res
);
3474 upma1
= upma_bin_tests
[i
].fn(upma1
, upma2
);
3475 ok
= isl_union_pw_multi_aff_plain_is_equal(upma1
, res
);
3476 isl_union_pw_multi_aff_free(upma1
);
3477 isl_union_pw_multi_aff_free(res
);
3481 isl_die(ctx
, isl_error_unknown
,
3482 "unexpected result", return -1);
3488 int test_aff(isl_ctx
*ctx
)
3493 isl_local_space
*ls
;
3497 if (test_bin_aff(ctx
) < 0)
3499 if (test_bin_upma(ctx
) < 0)
3502 space
= isl_space_set_alloc(ctx
, 0, 1);
3503 ls
= isl_local_space_from_space(space
);
3504 aff
= isl_aff_zero_on_domain(ls
);
3506 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3507 aff
= isl_aff_scale_down_ui(aff
, 3);
3508 aff
= isl_aff_floor(aff
);
3509 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3510 aff
= isl_aff_scale_down_ui(aff
, 2);
3511 aff
= isl_aff_floor(aff
);
3512 aff
= isl_aff_add_coefficient_si(aff
, isl_dim_in
, 0, 1);
3515 set
= isl_set_read_from_str(ctx
, str
);
3516 aff
= isl_aff_gist(aff
, set
);
3518 aff
= isl_aff_add_constant_si(aff
, -16);
3519 zero
= isl_aff_plain_is_zero(aff
);
3525 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3527 aff
= isl_aff_read_from_str(ctx
, "{ [-1] }");
3528 aff
= isl_aff_scale_down_ui(aff
, 64);
3529 aff
= isl_aff_floor(aff
);
3530 equal
= aff_check_plain_equal(aff
, "{ [-1] }");
3538 int test_dim_max(isl_ctx
*ctx
)
3542 isl_set
*set1
, *set2
;
3547 str
= "[N] -> { [i] : 0 <= i <= min(N,10) }";
3548 set
= isl_set_read_from_str(ctx
, str
);
3549 pwaff
= isl_set_dim_max(set
, 0);
3550 set1
= isl_set_from_pw_aff(pwaff
);
3551 str
= "[N] -> { [10] : N >= 10; [N] : N <= 9 and N >= 0 }";
3552 set2
= isl_set_read_from_str(ctx
, str
);
3553 equal
= isl_set_is_equal(set1
, set2
);
3559 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3561 str
= "[N] -> { [i] : 0 <= i <= max(2N,N+6) }";
3562 set
= isl_set_read_from_str(ctx
, str
);
3563 pwaff
= isl_set_dim_max(set
, 0);
3564 set1
= isl_set_from_pw_aff(pwaff
);
3565 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3566 set2
= isl_set_read_from_str(ctx
, str
);
3567 equal
= isl_set_is_equal(set1
, set2
);
3573 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3575 str
= "[N] -> { [i] : 0 <= i <= 2N or 0 <= i <= N+6 }";
3576 set
= isl_set_read_from_str(ctx
, str
);
3577 pwaff
= isl_set_dim_max(set
, 0);
3578 set1
= isl_set_from_pw_aff(pwaff
);
3579 str
= "[N] -> { [6 + N] : -6 <= N <= 5; [2N] : N >= 6 }";
3580 set2
= isl_set_read_from_str(ctx
, str
);
3581 equal
= isl_set_is_equal(set1
, set2
);
3587 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3589 str
= "[N,M] -> { [i,j] -> [([i/16]), i%16, ([j/16]), j%16] : "
3590 "0 <= i < N and 0 <= j < M }";
3591 map
= isl_map_read_from_str(ctx
, str
);
3592 set
= isl_map_range(map
);
3594 pwaff
= isl_set_dim_max(isl_set_copy(set
), 0);
3595 set1
= isl_set_from_pw_aff(pwaff
);
3596 str
= "[N,M] -> { [([(N-1)/16])] : M,N > 0 }";
3597 set2
= isl_set_read_from_str(ctx
, str
);
3598 equal
= isl_set_is_equal(set1
, set2
);
3602 pwaff
= isl_set_dim_max(isl_set_copy(set
), 3);
3603 set1
= isl_set_from_pw_aff(pwaff
);
3604 str
= "[N,M] -> { [t] : t = min(M-1,15) and M,N > 0 }";
3605 set2
= isl_set_read_from_str(ctx
, str
);
3606 if (equal
>= 0 && equal
)
3607 equal
= isl_set_is_equal(set1
, set2
);
3616 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3618 /* Check that solutions are properly merged. */
3619 str
= "[n] -> { [a, b, c] : c >= -4a - 2b and "
3620 "c <= -1 + n - 4a - 2b and c >= -2b and "
3621 "4a >= -4 + n and c >= 0 }";
3622 set
= isl_set_read_from_str(ctx
, str
);
3623 pwaff
= isl_set_dim_min(set
, 2);
3624 set1
= isl_set_from_pw_aff(pwaff
);
3625 str
= "[n] -> { [(0)] : n >= 1 }";
3626 set2
= isl_set_read_from_str(ctx
, str
);
3627 equal
= isl_set_is_equal(set1
, set2
);
3634 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3636 /* Check that empty solution lie in the right space. */
3637 str
= "[n] -> { [t,a] : 1 = 0 }";
3638 set
= isl_set_read_from_str(ctx
, str
);
3639 pwaff
= isl_set_dim_max(set
, 0);
3640 set1
= isl_set_from_pw_aff(pwaff
);
3641 str
= "[n] -> { [t] : 1 = 0 }";
3642 set2
= isl_set_read_from_str(ctx
, str
);
3643 equal
= isl_set_is_equal(set1
, set2
);
3650 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3655 /* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"?
3657 static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff
*pma
,
3661 isl_pw_multi_aff
*pma2
;
3667 ctx
= isl_pw_multi_aff_get_ctx(pma
);
3668 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3669 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma2
);
3670 isl_pw_multi_aff_free(pma2
);
3675 /* Check that "pma" is obviously equal to the isl_pw_multi_aff
3676 * represented by "str".
3678 static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff
*pma
,
3683 equal
= pw_multi_aff_plain_is_equal(pma
, str
);
3687 isl_die(isl_pw_multi_aff_get_ctx(pma
), isl_error_unknown
,
3688 "result not as expected", return -1);
3692 /* Basic test for isl_pw_multi_aff_product.
3694 * Check that multiple pieces are properly handled.
3696 static int test_product_pma(isl_ctx
*ctx
)
3700 isl_pw_multi_aff
*pma1
, *pma2
;
3702 str
= "{ A[i] -> B[1] : i < 0; A[i] -> B[2] : i >= 0 }";
3703 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3704 str
= "{ C[] -> D[] }";
3705 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
3706 pma1
= isl_pw_multi_aff_product(pma1
, pma2
);
3707 str
= "{ [A[i] -> C[]] -> [B[(1)] -> D[]] : i < 0;"
3708 "[A[i] -> C[]] -> [B[(2)] -> D[]] : i >= 0 }";
3709 equal
= pw_multi_aff_check_plain_equal(pma1
, str
);
3710 isl_pw_multi_aff_free(pma1
);
3717 int test_product(isl_ctx
*ctx
)
3721 isl_union_set
*uset1
, *uset2
;
3725 set
= isl_set_read_from_str(ctx
, str
);
3726 set
= isl_set_product(set
, isl_set_copy(set
));
3727 ok
= isl_set_is_wrapping(set
);
3732 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3735 uset1
= isl_union_set_read_from_str(ctx
, str
);
3736 uset1
= isl_union_set_product(uset1
, isl_union_set_copy(uset1
));
3737 str
= "{ [[] -> []] }";
3738 uset2
= isl_union_set_read_from_str(ctx
, str
);
3739 ok
= isl_union_set_is_equal(uset1
, uset2
);
3740 isl_union_set_free(uset1
);
3741 isl_union_set_free(uset2
);
3745 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3747 if (test_product_pma(ctx
) < 0)
3753 /* Check that two sets are not considered disjoint just because
3754 * they have a different set of (named) parameters.
3756 static int test_disjoint(isl_ctx
*ctx
)
3759 isl_set
*set
, *set2
;
3762 str
= "[n] -> { [[]->[]] }";
3763 set
= isl_set_read_from_str(ctx
, str
);
3764 str
= "{ [[]->[]] }";
3765 set2
= isl_set_read_from_str(ctx
, str
);
3766 disjoint
= isl_set_is_disjoint(set
, set2
);
3772 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3777 int test_equal(isl_ctx
*ctx
)
3780 isl_set
*set
, *set2
;
3784 set
= isl_set_read_from_str(ctx
, str
);
3786 set2
= isl_set_read_from_str(ctx
, str
);
3787 equal
= isl_set_is_equal(set
, set2
);
3793 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3798 static int test_plain_fixed(isl_ctx
*ctx
, __isl_take isl_map
*map
,
3799 enum isl_dim_type type
, unsigned pos
, int fixed
)
3803 test
= isl_map_plain_is_fixed(map
, type
, pos
, NULL
);
3810 isl_die(ctx
, isl_error_unknown
,
3811 "map not detected as fixed", return -1);
3813 isl_die(ctx
, isl_error_unknown
,
3814 "map detected as fixed", return -1);
3817 int test_fixed(isl_ctx
*ctx
)
3822 str
= "{ [i] -> [i] }";
3823 map
= isl_map_read_from_str(ctx
, str
);
3824 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 0))
3826 str
= "{ [i] -> [1] }";
3827 map
= isl_map_read_from_str(ctx
, str
);
3828 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3830 str
= "{ S_1[p1] -> [o0] : o0 = -2 and p1 >= 1 and p1 <= 7 }";
3831 map
= isl_map_read_from_str(ctx
, str
);
3832 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3834 map
= isl_map_read_from_str(ctx
, str
);
3835 map
= isl_map_neg(map
);
3836 if (test_plain_fixed(ctx
, map
, isl_dim_out
, 0, 1))
3842 struct isl_vertices_test_data
{
3845 const char *vertex
[2];
3846 } vertices_tests
[] = {
3847 { "{ A[t, i] : t = 12 and i >= 4 and i <= 12 }",
3848 2, { "{ A[12, 4] }", "{ A[12, 12] }" } },
3849 { "{ A[t, i] : t = 14 and i = 1 }",
3850 1, { "{ A[14, 1] }" } },
3853 /* Check that "vertex" corresponds to one of the vertices in data->vertex.
3855 static int find_vertex(__isl_take isl_vertex
*vertex
, void *user
)
3857 struct isl_vertices_test_data
*data
= user
;
3860 isl_basic_set
*bset
;
3861 isl_pw_multi_aff
*pma
;
3865 ctx
= isl_vertex_get_ctx(vertex
);
3866 bset
= isl_vertex_get_domain(vertex
);
3867 ma
= isl_vertex_get_expr(vertex
);
3868 pma
= isl_pw_multi_aff_alloc(isl_set_from_basic_set(bset
), ma
);
3870 for (i
= 0; i
< data
->n
; ++i
) {
3871 isl_pw_multi_aff
*pma_i
;
3873 pma_i
= isl_pw_multi_aff_read_from_str(ctx
, data
->vertex
[i
]);
3874 equal
= isl_pw_multi_aff_plain_is_equal(pma
, pma_i
);
3875 isl_pw_multi_aff_free(pma_i
);
3877 if (equal
< 0 || equal
)
3881 isl_pw_multi_aff_free(pma
);
3882 isl_vertex_free(vertex
);
3887 return equal
? 0 : - 1;
3890 int test_vertices(isl_ctx
*ctx
)
3894 for (i
= 0; i
< ARRAY_SIZE(vertices_tests
); ++i
) {
3895 isl_basic_set
*bset
;
3896 isl_vertices
*vertices
;
3900 bset
= isl_basic_set_read_from_str(ctx
, vertices_tests
[i
].set
);
3901 vertices
= isl_basic_set_compute_vertices(bset
);
3902 n
= isl_vertices_get_n_vertices(vertices
);
3903 if (vertices_tests
[i
].n
!= n
)
3905 if (isl_vertices_foreach_vertex(vertices
, &find_vertex
,
3906 &vertices_tests
[i
]) < 0)
3908 isl_vertices_free(vertices
);
3909 isl_basic_set_free(bset
);
3914 isl_die(ctx
, isl_error_unknown
, "unexpected vertices",
3921 int test_union_pw(isl_ctx
*ctx
)
3925 isl_union_set
*uset
;
3926 isl_union_pw_qpolynomial
*upwqp1
, *upwqp2
;
3928 str
= "{ [x] -> x^2 }";
3929 upwqp1
= isl_union_pw_qpolynomial_read_from_str(ctx
, str
);
3930 upwqp2
= isl_union_pw_qpolynomial_copy(upwqp1
);
3931 uset
= isl_union_pw_qpolynomial_domain(upwqp1
);
3932 upwqp1
= isl_union_pw_qpolynomial_copy(upwqp2
);
3933 upwqp1
= isl_union_pw_qpolynomial_intersect_domain(upwqp1
, uset
);
3934 equal
= isl_union_pw_qpolynomial_plain_is_equal(upwqp1
, upwqp2
);
3935 isl_union_pw_qpolynomial_free(upwqp1
);
3936 isl_union_pw_qpolynomial_free(upwqp2
);
3940 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3945 int test_output(isl_ctx
*ctx
)
3953 str
= "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }";
3954 pa
= isl_pw_aff_read_from_str(ctx
, str
);
3956 p
= isl_printer_to_str(ctx
);
3957 p
= isl_printer_set_output_format(p
, ISL_FORMAT_C
);
3958 p
= isl_printer_print_pw_aff(p
, pa
);
3959 s
= isl_printer_get_str(p
);
3960 isl_printer_free(p
);
3961 isl_pw_aff_free(pa
);
3965 equal
= !strcmp(s
, "4 * floord(x, 4) + 2 >= x ? 1 : 2");
3970 isl_die(ctx
, isl_error_unknown
, "unexpected result", return -1);
3975 int test_sample(isl_ctx
*ctx
)
3978 isl_basic_set
*bset1
, *bset2
;
3981 str
= "{ [a, b, c, d, e, f, g, h, i, j, k] : "
3982 "3i >= 1073741823b - c - 1073741823e + f and c >= 0 and "
3983 "3i >= -1 + 3221225466b + c + d - 3221225466e - f and "
3984 "2e >= a - b and 3e <= 2a and 3k <= -a and f <= -1 + a and "
3985 "3i <= 4 - a + 4b + 2c - e - 2f and 3k <= -a + c - f and "
3986 "3h >= -2 + a and 3g >= -3 - a and 3k >= -2 - a and "
3987 "3i >= -2 - a - 2c + 3e + 2f and 3h <= a + c - f and "
3988 "3h >= a + 2147483646b + 2c - 2147483646e - 2f and "
3989 "3g <= -1 - a and 3i <= 1 + c + d - f and a <= 1073741823 and "
3990 "f >= 1 - a + 1073741822b + c + d - 1073741822e and "
3991 "3i >= 1 + 2b - 2c + e + 2f + 3g and "
3992 "1073741822f <= 1073741822 - a + 1073741821b + 1073741822c +"
3993 "d - 1073741821e and "
3994 "3j <= 3 - a + 3b and 3g <= -2 - 2b + c + d - e - f and "
3995 "3j >= 1 - a + b + 2e and "
3996 "3f >= -3 + a + 3221225462b + 3c + d - 3221225465e and "
3997 "3i <= 4 - a + 4b - e and "
3998 "f <= 1073741822 + 1073741822b - 1073741822e and 3h <= a and "
3999 "f >= 0 and 2e <= 4 - a + 5b - d and 2e <= a - b + d and "
4000 "c <= -1 + a and 3i >= -2 - a + 3e and "
4001 "1073741822e <= 1073741823 - a + 1073741822b + c and "
4002 "3g >= -4 + 3221225464b + 3c + d - 3221225467e - 3f and "
4003 "3i >= -1 + 3221225466b + 3c + d - 3221225466e - 3f and "
4004 "1073741823e >= 1 + 1073741823b - d and "
4005 "3i >= 1073741823b + c - 1073741823e - f and "
4006 "3i >= 1 + 2b + e + 3g }";
4007 bset1
= isl_basic_set_read_from_str(ctx
, str
);
4008 bset2
= isl_basic_set_sample(isl_basic_set_copy(bset1
));
4009 empty
= isl_basic_set_is_empty(bset2
);
4010 subset
= isl_basic_set_is_subset(bset2
, bset1
);
4011 isl_basic_set_free(bset1
);
4012 isl_basic_set_free(bset2
);
4013 if (empty
< 0 || subset
< 0)
4016 isl_die(ctx
, isl_error_unknown
, "point not found", return -1);
4018 isl_die(ctx
, isl_error_unknown
, "bad point found", return -1);
4023 int test_fixed_power(isl_ctx
*ctx
)
4031 str
= "{ [i] -> [i + 1] }";
4032 map
= isl_map_read_from_str(ctx
, str
);
4033 isl_int_set_si(exp
, 23);
4034 map
= isl_map_fixed_power(map
, exp
);
4035 equal
= map_check_equal(map
, "{ [i] -> [i + 23] }");
4044 int test_slice(isl_ctx
*ctx
)
4050 str
= "{ [i] -> [j] }";
4051 map
= isl_map_read_from_str(ctx
, str
);
4052 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_out
, 0);
4053 equal
= map_check_equal(map
, "{ [i] -> [i] }");
4058 str
= "{ [i] -> [j] }";
4059 map
= isl_map_read_from_str(ctx
, str
);
4060 map
= isl_map_equate(map
, isl_dim_in
, 0, isl_dim_in
, 0);
4061 equal
= map_check_equal(map
, "{ [i] -> [j] }");
4066 str
= "{ [i] -> [j] }";
4067 map
= isl_map_read_from_str(ctx
, str
);
4068 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_out
, 0);
4069 equal
= map_check_equal(map
, "{ [i] -> [-i] }");
4074 str
= "{ [i] -> [j] }";
4075 map
= isl_map_read_from_str(ctx
, str
);
4076 map
= isl_map_oppose(map
, isl_dim_in
, 0, isl_dim_in
, 0);
4077 equal
= map_check_equal(map
, "{ [0] -> [j] }");
4082 str
= "{ [i] -> [j] }";
4083 map
= isl_map_read_from_str(ctx
, str
);
4084 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_out
, 0);
4085 equal
= map_check_equal(map
, "{ [i] -> [j] : i > j }");
4090 str
= "{ [i] -> [j] }";
4091 map
= isl_map_read_from_str(ctx
, str
);
4092 map
= isl_map_order_gt(map
, isl_dim_in
, 0, isl_dim_in
, 0);
4093 equal
= map_check_equal(map
, "{ [i] -> [j] : false }");
4101 int test_eliminate(isl_ctx
*ctx
)
4107 str
= "{ [i] -> [j] : i = 2j }";
4108 map
= isl_map_read_from_str(ctx
, str
);
4109 map
= isl_map_eliminate(map
, isl_dim_out
, 0, 1);
4110 equal
= map_check_equal(map
, "{ [i] -> [j] : exists a : i = 2a }");
4118 /* Check that isl_set_dim_residue_class detects that the values of j
4119 * in the set below are all odd and that it does not detect any spurious
4122 static int test_residue_class(isl_ctx
*ctx
)
4129 str
= "{ [i,j] : j = 4 i + 1 and 0 <= i <= 100; "
4130 "[i,j] : j = 4 i + 3 and 500 <= i <= 600 }";
4131 set
= isl_set_read_from_str(ctx
, str
);
4134 res
= isl_set_dim_residue_class(set
, 1, &m
, &r
);
4136 (isl_int_cmp_si(m
, 2) != 0 || isl_int_cmp_si(r
, 1) != 0))
4137 isl_die(ctx
, isl_error_unknown
, "incorrect residue class",
4146 int test_align_parameters(isl_ctx
*ctx
)
4150 isl_multi_aff
*ma1
, *ma2
;
4153 str
= "{ A[B[] -> C[]] -> D[E[] -> F[]] }";
4154 ma1
= isl_multi_aff_read_from_str(ctx
, str
);
4156 space
= isl_space_params_alloc(ctx
, 1);
4157 space
= isl_space_set_dim_name(space
, isl_dim_param
, 0, "N");
4158 ma1
= isl_multi_aff_align_params(ma1
, space
);
4160 str
= "[N] -> { A[B[] -> C[]] -> D[E[] -> F[]] }";
4161 ma2
= isl_multi_aff_read_from_str(ctx
, str
);
4163 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4165 isl_multi_aff_free(ma1
);
4166 isl_multi_aff_free(ma2
);
4171 isl_die(ctx
, isl_error_unknown
,
4172 "result not as expected", return -1);
4177 static int test_list(isl_ctx
*ctx
)
4179 isl_id
*a
, *b
, *c
, *d
, *id
;
4183 a
= isl_id_alloc(ctx
, "a", NULL
);
4184 b
= isl_id_alloc(ctx
, "b", NULL
);
4185 c
= isl_id_alloc(ctx
, "c", NULL
);
4186 d
= isl_id_alloc(ctx
, "d", NULL
);
4188 list
= isl_id_list_alloc(ctx
, 4);
4189 list
= isl_id_list_add(list
, a
);
4190 list
= isl_id_list_add(list
, b
);
4191 list
= isl_id_list_add(list
, c
);
4192 list
= isl_id_list_add(list
, d
);
4193 list
= isl_id_list_drop(list
, 1, 1);
4195 if (isl_id_list_n_id(list
) != 3) {
4196 isl_id_list_free(list
);
4197 isl_die(ctx
, isl_error_unknown
,
4198 "unexpected number of elements in list", return -1);
4201 id
= isl_id_list_get_id(list
, 0);
4204 id
= isl_id_list_get_id(list
, 1);
4207 id
= isl_id_list_get_id(list
, 2);
4211 isl_id_list_free(list
);
4214 isl_die(ctx
, isl_error_unknown
,
4215 "unexpected elements in list", return -1);
4220 const char *set_conversion_tests
[] = {
4221 "[N] -> { [i] : N - 1 <= 2 i <= N }",
4222 "[N] -> { [i] : exists a : i = 4 a and N - 1 <= i <= N }",
4223 "[N] -> { [i,j] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4224 "[N] -> { [[i]->[j]] : exists a : i = 4 a and N - 1 <= i, 2j <= N }",
4225 "[N] -> { [3*floor(N/2) + 5*floor(N/3)] }",
4228 /* Check that converting from isl_set to isl_pw_multi_aff and back
4229 * to isl_set produces the original isl_set.
4231 static int test_set_conversion(isl_ctx
*ctx
)
4235 isl_set
*set1
, *set2
;
4236 isl_pw_multi_aff
*pma
;
4239 for (i
= 0; i
< ARRAY_SIZE(set_conversion_tests
); ++i
) {
4240 str
= set_conversion_tests
[i
];
4241 set1
= isl_set_read_from_str(ctx
, str
);
4242 pma
= isl_pw_multi_aff_from_set(isl_set_copy(set1
));
4243 set2
= isl_set_from_pw_multi_aff(pma
);
4244 equal
= isl_set_is_equal(set1
, set2
);
4251 isl_die(ctx
, isl_error_unknown
, "bad conversion",
4258 /* Check that converting from isl_map to isl_pw_multi_aff and back
4259 * to isl_map produces the original isl_map.
4261 static int test_map_conversion(isl_ctx
*ctx
)
4264 isl_map
*map1
, *map2
;
4265 isl_pw_multi_aff
*pma
;
4268 str
= "{ [a, b, c, d] -> s0[a, b, e, f] : "
4269 "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], "
4270 "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and "
4271 "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and "
4273 map1
= isl_map_read_from_str(ctx
, str
);
4274 pma
= isl_pw_multi_aff_from_map(isl_map_copy(map1
));
4275 map2
= isl_map_from_pw_multi_aff(pma
);
4276 equal
= isl_map_is_equal(map1
, map2
);
4283 isl_die(ctx
, isl_error_unknown
, "bad conversion", return -1);
4288 static int test_conversion(isl_ctx
*ctx
)
4290 if (test_set_conversion(ctx
) < 0)
4292 if (test_map_conversion(ctx
) < 0)
4297 /* Check that isl_basic_map_curry does not modify input.
4299 static int test_curry(isl_ctx
*ctx
)
4302 isl_basic_map
*bmap1
, *bmap2
;
4305 str
= "{ [A[] -> B[]] -> C[] }";
4306 bmap1
= isl_basic_map_read_from_str(ctx
, str
);
4307 bmap2
= isl_basic_map_curry(isl_basic_map_copy(bmap1
));
4308 equal
= isl_basic_map_is_equal(bmap1
, bmap2
);
4309 isl_basic_map_free(bmap1
);
4310 isl_basic_map_free(bmap2
);
4315 isl_die(ctx
, isl_error_unknown
,
4316 "curried map should not be equal to original",
4326 } preimage_tests
[] = {
4327 { "{ B[i,j] : 0 <= i < 10 and 0 <= j < 100 }",
4328 "{ A[j,i] -> B[i,j] }",
4329 "{ A[j,i] : 0 <= i < 10 and 0 <= j < 100 }" },
4330 { "{ rat: B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4331 "{ A[a,b] -> B[a/2,b/6] }",
4332 "{ rat: A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 }" },
4333 { "{ B[i,j] : 0 <= i, j and 3 i + 5 j <= 100 }",
4334 "{ A[a,b] -> B[a/2,b/6] }",
4335 "{ A[a,b] : 0 <= a, b and 9 a + 5 b <= 600 and "
4336 "exists i,j : a = 2 i and b = 6 j }" },
4337 { "[n] -> { S[i] : 0 <= i <= 100 }", "[n] -> { S[n] }",
4338 "[n] -> { : 0 <= n <= 100 }" },
4339 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4340 "{ A[a] -> B[2a] }",
4341 "{ A[a] : 0 <= a < 50 and exists b : a = 2 b }" },
4342 { "{ B[i] : 0 <= i < 100 and exists a : i = 4 a }",
4343 "{ A[a] -> B[([a/2])] }",
4344 "{ A[a] : 0 <= a < 200 and exists b : [a/2] = 4 b }" },
4345 { "{ B[i,j,k] : 0 <= i,j,k <= 100 }",
4346 "{ A[a] -> B[a,a,a/3] }",
4347 "{ A[a] : 0 <= a <= 100 and exists b : a = 3 b }" },
4348 { "{ B[i,j] : j = [(i)/2] } ", "{ A[i,j] -> B[i/3,j] }",
4349 "{ A[i,j] : j = [(i)/6] and exists a : i = 3 a }" },
4352 static int test_preimage_basic_set(isl_ctx
*ctx
)
4355 isl_basic_set
*bset1
, *bset2
;
4359 for (i
= 0; i
< ARRAY_SIZE(preimage_tests
); ++i
) {
4360 bset1
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].set
);
4361 ma
= isl_multi_aff_read_from_str(ctx
, preimage_tests
[i
].ma
);
4362 bset2
= isl_basic_set_read_from_str(ctx
, preimage_tests
[i
].res
);
4363 bset1
= isl_basic_set_preimage_multi_aff(bset1
, ma
);
4364 equal
= isl_basic_set_is_equal(bset1
, bset2
);
4365 isl_basic_set_free(bset1
);
4366 isl_basic_set_free(bset2
);
4370 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4381 } preimage_domain_tests
[] = {
4382 { "{ B[i,j] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }",
4383 "{ A[j,i] -> B[i,j] }",
4384 "{ A[j,i] -> C[2i + 3j] : 0 <= i < 10 and 0 <= j < 100 }" },
4385 { "{ B[i] -> C[i]; D[i] -> E[i] }",
4386 "{ A[i] -> B[i + 1] }",
4387 "{ A[i] -> C[i + 1] }" },
4388 { "{ B[i] -> C[i]; B[i] -> E[i] }",
4389 "{ A[i] -> B[i + 1] }",
4390 "{ A[i] -> C[i + 1]; A[i] -> E[i + 1] }" },
4391 { "{ B[i] -> C[([i/2])] }",
4392 "{ A[i] -> B[2i] }",
4393 "{ A[i] -> C[i] }" },
4394 { "{ B[i,j] -> C[([i/2]), ([(i+j)/3])] }",
4395 "{ A[i] -> B[([i/5]), ([i/7])] }",
4396 "{ A[i] -> C[([([i/5])/2]), ([(([i/5])+([i/7]))/3])] }" },
4397 { "[N] -> { B[i] -> C[([N/2]), i, ([N/3])] }",
4398 "[N] -> { A[] -> B[([N/5])] }",
4399 "[N] -> { A[] -> C[([N/2]), ([N/5]), ([N/3])] }" },
4400 { "{ B[i] -> C[i] : exists a : i = 5 a }",
4401 "{ A[i] -> B[2i] }",
4402 "{ A[i] -> C[2i] : exists a : 2i = 5 a }" },
4403 { "{ B[i] -> C[i] : exists a : i = 2 a; "
4404 "B[i] -> D[i] : exists a : i = 2 a + 1 }",
4405 "{ A[i] -> B[2i] }",
4406 "{ A[i] -> C[2i] }" },
4409 static int test_preimage_union_map(isl_ctx
*ctx
)
4412 isl_union_map
*umap1
, *umap2
;
4416 for (i
= 0; i
< ARRAY_SIZE(preimage_domain_tests
); ++i
) {
4417 umap1
= isl_union_map_read_from_str(ctx
,
4418 preimage_domain_tests
[i
].map
);
4419 ma
= isl_multi_aff_read_from_str(ctx
,
4420 preimage_domain_tests
[i
].ma
);
4421 umap2
= isl_union_map_read_from_str(ctx
,
4422 preimage_domain_tests
[i
].res
);
4423 umap1
= isl_union_map_preimage_domain_multi_aff(umap1
, ma
);
4424 equal
= isl_union_map_is_equal(umap1
, umap2
);
4425 isl_union_map_free(umap1
);
4426 isl_union_map_free(umap2
);
4430 isl_die(ctx
, isl_error_unknown
, "bad preimage",
4437 static int test_preimage(isl_ctx
*ctx
)
4439 if (test_preimage_basic_set(ctx
) < 0)
4441 if (test_preimage_union_map(ctx
) < 0)
4451 } pullback_tests
[] = {
4452 { "{ B[i,j] -> C[i + 2j] }" , "{ A[a,b] -> B[b,a] }",
4453 "{ A[a,b] -> C[b + 2a] }" },
4454 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/2] }", "{ A[a] -> C[a] }" },
4455 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[2a] }", "{ A[a] -> C[a] }" },
4456 { "{ B[i] -> C[(i)/2] }", "{ A[a] -> B[(a)/3] }",
4457 "{ A[a] -> C[(a)/6] }" },
4458 { "{ B[i] -> C[2i] }", "{ A[a] -> B[5a] }", "{ A[a] -> C[10a] }" },
4459 { "{ B[i] -> C[2i] }", "{ A[a] -> B[(a)/3] }",
4460 "{ A[a] -> C[(2a)/3] }" },
4461 { "{ B[i,j] -> C[i + j] }", "{ A[a] -> B[a,a] }", "{ A[a] -> C[2a] }"},
4462 { "{ B[a] -> C[a,a] }", "{ A[i,j] -> B[i + j] }",
4463 "{ A[i,j] -> C[i + j, i + j] }"},
4464 { "{ B[i] -> C[([i/2])] }", "{ B[5] }", "{ C[2] }" },
4465 { "[n] -> { B[i,j] -> C[([i/2]) + 2j] }",
4466 "[n] -> { B[n,[n/3]] }", "[n] -> { C[([n/2]) + 2*[n/3]] }", },
4469 static int test_pullback(isl_ctx
*ctx
)
4472 isl_multi_aff
*ma1
, *ma2
;
4476 for (i
= 0; i
< ARRAY_SIZE(pullback_tests
); ++i
) {
4477 ma1
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma1
);
4478 ma
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].ma
);
4479 ma2
= isl_multi_aff_read_from_str(ctx
, pullback_tests
[i
].res
);
4480 ma1
= isl_multi_aff_pullback_multi_aff(ma1
, ma
);
4481 equal
= isl_multi_aff_plain_is_equal(ma1
, ma2
);
4482 isl_multi_aff_free(ma1
);
4483 isl_multi_aff_free(ma2
);
4487 isl_die(ctx
, isl_error_unknown
, "bad pullback",
4494 /* Check that negation is printed correctly.
4496 static int test_ast(isl_ctx
*ctx
)
4498 isl_ast_expr
*expr
, *expr1
, *expr2
, *expr3
;
4502 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4503 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4504 expr
= isl_ast_expr_add(expr1
, expr2
);
4505 expr
= isl_ast_expr_neg(expr
);
4506 str
= isl_ast_expr_to_str(expr
);
4507 ok
= str
? !strcmp(str
, "-(A + B)") : -1;
4509 isl_ast_expr_free(expr
);
4514 isl_die(ctx
, isl_error_unknown
,
4515 "isl_ast_expr printed incorrectly", return -1);
4517 expr1
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "A", NULL
));
4518 expr2
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "B", NULL
));
4519 expr
= isl_ast_expr_add(expr1
, expr2
);
4520 expr3
= isl_ast_expr_from_id(isl_id_alloc(ctx
, "C", NULL
));
4521 expr
= isl_ast_expr_sub(expr3
, expr
);
4522 str
= isl_ast_expr_to_str(expr
);
4523 ok
= str
? !strcmp(str
, "C - (A + B)") : -1;
4525 isl_ast_expr_free(expr
);
4530 isl_die(ctx
, isl_error_unknown
,
4531 "isl_ast_expr printed incorrectly", return -1);
4536 /* Check that isl_ast_build_expr_from_set returns a valid expression
4537 * for an empty set. Note that isl_ast_build_expr_from_set getting
4538 * called on an empty set probably indicates a bug in the caller.
4540 static int test_ast_build(isl_ctx
*ctx
)
4543 isl_ast_build
*build
;
4546 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4547 build
= isl_ast_build_from_context(set
);
4549 set
= isl_set_empty(isl_space_params_alloc(ctx
, 0));
4550 expr
= isl_ast_build_expr_from_set(build
, set
);
4552 isl_ast_expr_free(expr
);
4553 isl_ast_build_free(build
);
4561 /* Internal data structure for before_for and after_for callbacks.
4563 * depth is the current depth
4564 * before is the number of times before_for has been called
4565 * after is the number of times after_for has been called
4567 struct isl_test_codegen_data
{
4573 /* This function is called before each for loop in the AST generated
4574 * from test_ast_gen1.
4576 * Increment the number of calls and the depth.
4577 * Check that the space returned by isl_ast_build_get_schedule_space
4578 * matches the target space of the schedule returned by
4579 * isl_ast_build_get_schedule.
4580 * Return an isl_id that is checked by the corresponding call
4583 static __isl_give isl_id
*before_for(__isl_keep isl_ast_build
*build
,
4586 struct isl_test_codegen_data
*data
= user
;
4589 isl_union_map
*schedule
;
4590 isl_union_set
*uset
;
4595 ctx
= isl_ast_build_get_ctx(build
);
4597 if (data
->before
>= 3)
4598 isl_die(ctx
, isl_error_unknown
,
4599 "unexpected number of for nodes", return NULL
);
4600 if (data
->depth
>= 2)
4601 isl_die(ctx
, isl_error_unknown
,
4602 "unexpected depth", return NULL
);
4604 snprintf(name
, sizeof(name
), "d%d", data
->depth
);
4608 schedule
= isl_ast_build_get_schedule(build
);
4609 uset
= isl_union_map_range(schedule
);
4612 if (isl_union_set_n_set(uset
) != 1) {
4613 isl_union_set_free(uset
);
4614 isl_die(ctx
, isl_error_unknown
,
4615 "expecting single range space", return NULL
);
4618 space
= isl_ast_build_get_schedule_space(build
);
4619 set
= isl_union_set_extract_set(uset
, space
);
4620 isl_union_set_free(uset
);
4621 empty
= isl_set_is_empty(set
);
4627 isl_die(ctx
, isl_error_unknown
,
4628 "spaces don't match", return NULL
);
4630 return isl_id_alloc(ctx
, name
, NULL
);
4633 /* This function is called after each for loop in the AST generated
4634 * from test_ast_gen1.
4636 * Increment the number of calls and decrement the depth.
4637 * Check that the annotation attached to the node matches
4638 * the isl_id returned by the corresponding call to before_for.
4640 static __isl_give isl_ast_node
*after_for(__isl_take isl_ast_node
*node
,
4641 __isl_keep isl_ast_build
*build
, void *user
)
4643 struct isl_test_codegen_data
*data
= user
;
4651 if (data
->after
> data
->before
)
4652 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4653 "mismatch in number of for nodes",
4654 return isl_ast_node_free(node
));
4656 id
= isl_ast_node_get_annotation(node
);
4658 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4659 "missing annotation", return isl_ast_node_free(node
));
4661 name
= isl_id_get_name(id
);
4662 valid
= name
&& atoi(name
+ 1) == data
->depth
;
4666 isl_die(isl_ast_node_get_ctx(node
), isl_error_unknown
,
4667 "wrong annotation", return isl_ast_node_free(node
));
4672 /* Check that the before_each_for and after_each_for callbacks
4673 * are called for each for loop in the generated code,
4674 * that they are called in the right order and that the isl_id
4675 * returned from the before_each_for callback is attached to
4676 * the isl_ast_node passed to the corresponding after_each_for call.
4678 static int test_ast_gen1(isl_ctx
*ctx
)
4682 isl_union_map
*schedule
;
4683 isl_ast_build
*build
;
4685 struct isl_test_codegen_data data
;
4687 str
= "[N] -> { : N >= 10 }";
4688 set
= isl_set_read_from_str(ctx
, str
);
4689 str
= "[N] -> { A[i,j] -> S[8,i,3,j] : 0 <= i,j <= N; "
4690 "B[i,j] -> S[8,j,9,i] : 0 <= i,j <= N }";
4691 schedule
= isl_union_map_read_from_str(ctx
, str
);
4696 build
= isl_ast_build_from_context(set
);
4697 build
= isl_ast_build_set_before_each_for(build
,
4698 &before_for
, &data
);
4699 build
= isl_ast_build_set_after_each_for(build
,
4701 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4702 isl_ast_build_free(build
);
4706 isl_ast_node_free(tree
);
4708 if (data
.before
!= 3 || data
.after
!= 3)
4709 isl_die(ctx
, isl_error_unknown
,
4710 "unexpected number of for nodes", return -1);
4715 /* Check that the AST generator handles domains that are integrally disjoint
4716 * but not ratinoally disjoint.
4718 static int test_ast_gen2(isl_ctx
*ctx
)
4722 isl_union_map
*schedule
;
4723 isl_union_map
*options
;
4724 isl_ast_build
*build
;
4727 str
= "{ A[i,j] -> [i,j] : 0 <= i,j <= 1 }";
4728 schedule
= isl_union_map_read_from_str(ctx
, str
);
4729 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4730 build
= isl_ast_build_from_context(set
);
4732 str
= "{ [i,j] -> atomic[1] : i + j = 1; [i,j] -> unroll[1] : i = j }";
4733 options
= isl_union_map_read_from_str(ctx
, str
);
4734 build
= isl_ast_build_set_options(build
, options
);
4735 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4736 isl_ast_build_free(build
);
4739 isl_ast_node_free(tree
);
4744 /* Increment *user on each call.
4746 static __isl_give isl_ast_node
*count_domains(__isl_take isl_ast_node
*node
,
4747 __isl_keep isl_ast_build
*build
, void *user
)
4756 /* Test that unrolling tries to minimize the number of instances.
4757 * In particular, for the schedule given below, make sure it generates
4758 * 3 nodes (rather than 101).
4760 static int test_ast_gen3(isl_ctx
*ctx
)
4764 isl_union_map
*schedule
;
4765 isl_union_map
*options
;
4766 isl_ast_build
*build
;
4770 str
= "[n] -> { A[i] -> [i] : 0 <= i <= 100 and n <= i <= n + 2 }";
4771 schedule
= isl_union_map_read_from_str(ctx
, str
);
4772 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4774 str
= "{ [i] -> unroll[0] }";
4775 options
= isl_union_map_read_from_str(ctx
, str
);
4777 build
= isl_ast_build_from_context(set
);
4778 build
= isl_ast_build_set_options(build
, options
);
4779 build
= isl_ast_build_set_at_each_domain(build
,
4780 &count_domains
, &n_domain
);
4781 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4782 isl_ast_build_free(build
);
4786 isl_ast_node_free(tree
);
4789 isl_die(ctx
, isl_error_unknown
,
4790 "unexpected number of for nodes", return -1);
4795 /* Check that if the ast_build_exploit_nested_bounds options is set,
4796 * we do not get an outer if node in the generated AST,
4797 * while we do get such an outer if node if the options is not set.
4799 static int test_ast_gen4(isl_ctx
*ctx
)
4803 isl_union_map
*schedule
;
4804 isl_ast_build
*build
;
4806 enum isl_ast_node_type type
;
4809 enb
= isl_options_get_ast_build_exploit_nested_bounds(ctx
);
4810 str
= "[N,M] -> { A[i,j] -> [i,j] : 0 <= i <= N and 0 <= j <= M }";
4812 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 1);
4814 schedule
= isl_union_map_read_from_str(ctx
, str
);
4815 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4816 build
= isl_ast_build_from_context(set
);
4817 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4818 isl_ast_build_free(build
);
4822 type
= isl_ast_node_get_type(tree
);
4823 isl_ast_node_free(tree
);
4825 if (type
== isl_ast_node_if
)
4826 isl_die(ctx
, isl_error_unknown
,
4827 "not expecting if node", return -1);
4829 isl_options_set_ast_build_exploit_nested_bounds(ctx
, 0);
4831 schedule
= isl_union_map_read_from_str(ctx
, str
);
4832 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4833 build
= isl_ast_build_from_context(set
);
4834 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4835 isl_ast_build_free(build
);
4839 type
= isl_ast_node_get_type(tree
);
4840 isl_ast_node_free(tree
);
4842 if (type
!= isl_ast_node_if
)
4843 isl_die(ctx
, isl_error_unknown
,
4844 "expecting if node", return -1);
4846 isl_options_set_ast_build_exploit_nested_bounds(ctx
, enb
);
4851 /* This function is called for each leaf in the AST generated
4852 * from test_ast_gen5.
4854 * We finalize the AST generation by extending the outer schedule
4855 * with a zero-dimensional schedule. If this results in any for loops,
4856 * then this means that we did not pass along enough information
4857 * about the outer schedule to the inner AST generation.
4859 static __isl_give isl_ast_node
*create_leaf(__isl_take isl_ast_build
*build
,
4862 isl_union_map
*schedule
, *extra
;
4865 schedule
= isl_ast_build_get_schedule(build
);
4866 extra
= isl_union_map_copy(schedule
);
4867 extra
= isl_union_map_from_domain(isl_union_map_domain(extra
));
4868 schedule
= isl_union_map_range_product(schedule
, extra
);
4869 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4870 isl_ast_build_free(build
);
4875 if (isl_ast_node_get_type(tree
) == isl_ast_node_for
)
4876 isl_die(isl_ast_node_get_ctx(tree
), isl_error_unknown
,
4877 "code should not contain any for loop",
4878 return isl_ast_node_free(tree
));
4883 /* Check that we do not lose any information when going back and
4884 * forth between internal and external schedule.
4886 * In particular, we create an AST where we unroll the only
4887 * non-constant dimension in the schedule. We therefore do
4888 * not expect any for loops in the AST. However, older versions
4889 * of isl would not pass along enough information about the outer
4890 * schedule when performing an inner code generation from a create_leaf
4891 * callback, resulting in the inner code generation producing a for loop.
4893 static int test_ast_gen5(isl_ctx
*ctx
)
4897 isl_union_map
*schedule
, *options
;
4898 isl_ast_build
*build
;
4901 str
= "{ A[] -> [1, 1, 2]; B[i] -> [1, i, 0] : i >= 1 and i <= 2 }";
4902 schedule
= isl_union_map_read_from_str(ctx
, str
);
4904 str
= "{ [a, b, c] -> unroll[1] : exists (e0 = [(a)/4]: "
4905 "4e0 >= -1 + a - b and 4e0 <= -2 + a + b) }";
4906 options
= isl_union_map_read_from_str(ctx
, str
);
4908 set
= isl_set_universe(isl_space_params_alloc(ctx
, 0));
4909 build
= isl_ast_build_from_context(set
);
4910 build
= isl_ast_build_set_options(build
, options
);
4911 build
= isl_ast_build_set_create_leaf(build
, &create_leaf
, NULL
);
4912 tree
= isl_ast_build_ast_from_schedule(build
, schedule
);
4913 isl_ast_build_free(build
);
4914 isl_ast_node_free(tree
);
4921 static int test_ast_gen(isl_ctx
*ctx
)
4923 if (test_ast_gen1(ctx
) < 0)
4925 if (test_ast_gen2(ctx
) < 0)
4927 if (test_ast_gen3(ctx
) < 0)
4929 if (test_ast_gen4(ctx
) < 0)
4931 if (test_ast_gen5(ctx
) < 0)
4936 /* Check if dropping output dimensions from an isl_pw_multi_aff
4939 static int test_pw_multi_aff(isl_ctx
*ctx
)
4942 isl_pw_multi_aff
*pma1
, *pma2
;
4945 str
= "{ [i,j] -> [i+j, 4i-j] }";
4946 pma1
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4947 str
= "{ [i,j] -> [4i-j] }";
4948 pma2
= isl_pw_multi_aff_read_from_str(ctx
, str
);
4950 pma1
= isl_pw_multi_aff_drop_dims(pma1
, isl_dim_out
, 0, 1);
4952 equal
= isl_pw_multi_aff_plain_is_equal(pma1
, pma2
);
4954 isl_pw_multi_aff_free(pma1
);
4955 isl_pw_multi_aff_free(pma2
);
4959 isl_die(ctx
, isl_error_unknown
,
4960 "expressions not equal", return -1);
4965 /* Check that we can properly parse multi piecewise affine expressions
4966 * where the piecewise affine expressions have different domains.
4968 static int test_multi_pw_aff(isl_ctx
*ctx
)
4971 isl_set
*dom
, *dom2
;
4972 isl_multi_pw_aff
*mpa1
, *mpa2
;
4977 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [i] }");
4978 dom
= isl_set_read_from_str(ctx
, "{ [i] : i > 0 }");
4979 mpa1
= isl_multi_pw_aff_intersect_domain(mpa1
, dom
);
4980 mpa2
= isl_multi_pw_aff_read_from_str(ctx
, "{ [i] -> [2i] }");
4981 mpa2
= isl_multi_pw_aff_flat_range_product(mpa1
, mpa2
);
4982 str
= "{ [i] -> [(i : i > 0), 2i] }";
4983 mpa1
= isl_multi_pw_aff_read_from_str(ctx
, str
);
4985 equal
= isl_multi_pw_aff_plain_is_equal(mpa1
, mpa2
);
4987 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 0);
4988 dom
= isl_pw_aff_domain(pa
);
4989 pa
= isl_multi_pw_aff_get_pw_aff(mpa1
, 1);
4990 dom2
= isl_pw_aff_domain(pa
);
4991 equal_domain
= isl_set_is_equal(dom
, dom2
);
4995 isl_multi_pw_aff_free(mpa1
);
4996 isl_multi_pw_aff_free(mpa2
);
5001 isl_die(ctx
, isl_error_unknown
,
5002 "expressions not equal", return -1);
5004 if (equal_domain
< 0)
5007 isl_die(ctx
, isl_error_unknown
,
5008 "domains unexpectedly equal", return -1);
5013 /* This is a regression test for a bug where isl_basic_map_simplify
5014 * would end up in an infinite loop. In particular, we construct
5015 * an empty basic set that is not obviously empty.
5016 * isl_basic_set_is_empty marks the basic set as empty.
5017 * After projecting out i3, the variable can be dropped completely,
5018 * but isl_basic_map_simplify refrains from doing so if the basic set
5019 * is empty and would end up in an infinite loop if it didn't test
5020 * explicitly for empty basic maps in the outer loop.
5022 static int test_simplify(isl_ctx
*ctx
)
5025 isl_basic_set
*bset
;
5028 str
= "{ [i0, i1, i2, i3] : i0 >= -2 and 6i2 <= 4 + i0 + 5i1 and "
5029 "i2 <= 22 and 75i2 <= 111 + 13i0 + 60i1 and "
5030 "25i2 >= 38 + 6i0 + 20i1 and i0 <= -1 and i2 >= 20 and "
5032 bset
= isl_basic_set_read_from_str(ctx
, str
);
5033 empty
= isl_basic_set_is_empty(bset
);
5034 bset
= isl_basic_set_project_out(bset
, isl_dim_set
, 3, 1);
5035 isl_basic_set_free(bset
);
5039 isl_die(ctx
, isl_error_unknown
,
5040 "basic set should be empty", return -1);
5045 /* This is a regression test for a bug where isl_tab_basic_map_partial_lexopt
5046 * with gbr context would fail to disable the use of the shifted tableau
5047 * when transferring equalities for the input to the context, resulting
5048 * in invalid sample values.
5050 static int test_partial_lexmin(isl_ctx
*ctx
)
5053 isl_basic_set
*bset
;
5054 isl_basic_map
*bmap
;
5057 str
= "{ [1, b, c, 1 - c] -> [e] : 2e <= -c and 2e >= -3 + c }";
5058 bmap
= isl_basic_map_read_from_str(ctx
, str
);
5059 str
= "{ [a, b, c, d] : c <= 1 and 2d >= 6 - 4b - c }";
5060 bset
= isl_basic_set_read_from_str(ctx
, str
);
5061 map
= isl_basic_map_partial_lexmin(bmap
, bset
, NULL
);
5070 /* Check that the variable compression performed on the existentially
5071 * quantified variables inside isl_basic_set_compute_divs is not confused
5072 * by the implicit equalities among the parameters.
5074 static int test_compute_divs(isl_ctx
*ctx
)
5077 isl_basic_set
*bset
;
5080 str
= "[a, b, c, d, e] -> { [] : exists (e0: 2d = b and a <= 124 and "
5081 "b <= 2046 and b >= 0 and b <= 60 + 64a and 2e >= b + 2c and "
5082 "2e >= b and 2e <= 1 + b and 2e <= 1 + b + 2c and "
5083 "32768e0 >= -124 + a and 2097152e0 <= 60 + 64a - b) }";
5084 bset
= isl_basic_set_read_from_str(ctx
, str
);
5085 set
= isl_basic_set_compute_divs(bset
);
5097 { "{ rat: [i] : 0 <= i <= 10 }",
5098 "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }" },
5099 { "{ rat: [i] : FALSE }",
5100 "{ rat: coefficients[[cst] -> [a]] }" },
5102 "{ rat: coefficients[[cst] -> [0]] : cst >= 0 }" },
5109 { "{ rat: coefficients[[cst] -> [a]] : cst >= 0 and 10a + cst >= 0 }",
5110 "{ rat: [i] : 0 <= i <= 10 }" },
5111 { "{ rat: coefficients[[cst] -> [a]] : FALSE }",
5113 { "{ rat: coefficients[[cst] -> [a]] }",
5114 "{ rat: [i] : FALSE }" },
5117 /* Test the basic functionality of isl_basic_set_coefficients and
5118 * isl_basic_set_solutions.
5120 static int test_dual(isl_ctx
*ctx
)
5124 for (i
= 0; i
< ARRAY_SIZE(coef_tests
); ++i
) {
5126 isl_basic_set
*bset1
, *bset2
;
5128 bset1
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].set
);
5129 bset2
= isl_basic_set_read_from_str(ctx
, coef_tests
[i
].dual
);
5130 bset1
= isl_basic_set_coefficients(bset1
);
5131 equal
= isl_basic_set_is_equal(bset1
, bset2
);
5132 isl_basic_set_free(bset1
);
5133 isl_basic_set_free(bset2
);
5137 isl_die(ctx
, isl_error_unknown
,
5138 "incorrect dual", return -1);
5141 for (i
= 0; i
< ARRAY_SIZE(sol_tests
); ++i
) {
5143 isl_basic_set
*bset1
, *bset2
;
5145 bset1
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].set
);
5146 bset2
= isl_basic_set_read_from_str(ctx
, sol_tests
[i
].dual
);
5147 bset1
= isl_basic_set_solutions(bset1
);
5148 equal
= isl_basic_set_is_equal(bset1
, bset2
);
5149 isl_basic_set_free(bset1
);
5150 isl_basic_set_free(bset2
);
5154 isl_die(ctx
, isl_error_unknown
,
5155 "incorrect dual", return -1);
5163 int (*fn
)(isl_ctx
*ctx
);
5165 { "dual", &test_dual
},
5166 { "dependence analysis", &test_flow
},
5167 { "val", &test_val
},
5168 { "compute divs", &test_compute_divs
},
5169 { "partial lexmin", &test_partial_lexmin
},
5170 { "simplify", &test_simplify
},
5171 { "curry", &test_curry
},
5172 { "piecewise multi affine expressions", &test_pw_multi_aff
},
5173 { "multi piecewise affine expressions", &test_multi_pw_aff
},
5174 { "conversion", &test_conversion
},
5175 { "list", &test_list
},
5176 { "align parameters", &test_align_parameters
},
5177 { "preimage", &test_preimage
},
5178 { "pullback", &test_pullback
},
5179 { "AST", &test_ast
},
5180 { "AST build", &test_ast_build
},
5181 { "AST generation", &test_ast_gen
},
5182 { "eliminate", &test_eliminate
},
5183 { "residue class", &test_residue_class
},
5184 { "div", &test_div
},
5185 { "slice", &test_slice
},
5186 { "fixed power", &test_fixed_power
},
5187 { "sample", &test_sample
},
5188 { "output", &test_output
},
5189 { "vertices", &test_vertices
},
5190 { "fixed", &test_fixed
},
5191 { "equal", &test_equal
},
5192 { "disjoint", &test_disjoint
},
5193 { "product", &test_product
},
5194 { "dim_max", &test_dim_max
},
5195 { "affine", &test_aff
},
5196 { "injective", &test_injective
},
5197 { "schedule", &test_schedule
},
5198 { "union_pw", &test_union_pw
},
5199 { "parse", &test_parse
},
5200 { "single-valued", &test_sv
},
5201 { "affine hull", &test_affine_hull
},
5202 { "coalesce", &test_coalesce
},
5203 { "factorize", &test_factorize
},
5204 { "subset", &test_subset
},
5205 { "subtract", &test_subtract
},
5206 { "lexmin", &test_lexmin
},
5207 { "min", &test_min
},
5208 { "gist", &test_gist
},
5209 { "piecewise quasi-polynomials", &test_pwqp
},
5212 int main(int argc
, char **argv
)
5215 struct isl_ctx
*ctx
;
5216 struct isl_options
*options
;
5218 srcdir
= getenv("srcdir");
5221 options
= isl_options_new_with_defaults();
5223 argc
= isl_options_parse(options
, argc
, argv
, ISL_ARG_ALL
);
5225 ctx
= isl_ctx_alloc_with_options(&isl_options_args
, options
);
5226 for (i
= 0; i
< ARRAY_SIZE(tests
); ++i
) {
5227 printf("%s\n", tests
[i
].name
);
5228 if (tests
[i
].fn(ctx
) < 0)
5234 test_split_periods(ctx
);
5236 test_bijective(ctx
);
5240 test_construction(ctx
);
5242 test_application(ctx
);
5243 test_convex_hull(ctx
);